From 55d83c40fa0a5c6a111c95aaf71209119031891b Mon Sep 17 00:00:00 2001 From: subtly Date: Wed, 11 Mar 2015 14:36:08 +0100 Subject: [PATCH 1/2] fix for -warning in cryptopp.cpp. add mutex to host iteration of peers for connect. only try to connect to as many peers as is necessary. update unit test. --- libdevcrypto/CryptoPP.cpp | 3 +-- libp2p/Host.cpp | 20 ++++++++++++++------ test/peer.cpp | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libdevcrypto/CryptoPP.cpp b/libdevcrypto/CryptoPP.cpp index 11e4c1472..79fd62262 100644 --- a/libdevcrypto/CryptoPP.cpp +++ b/libdevcrypto/CryptoPP.cpp @@ -319,8 +319,7 @@ void Secp256k1::agree(Secret const& _s, Public const& _r, h256& o_s) assert(d.AgreedValueLength() == sizeof(o_s)); byte remote[65] = {0x04}; memcpy(&remote[1], _r.data(), 64); - bool result = d.Agree(o_s.data(), _s.data(), remote); - assert(result); + d.Agree(o_s.data(), _s.data(), remote); } void Secp256k1::exportPublicKey(CryptoPP::DL_PublicKey_EC const& _k, Public& o_p) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 8f4f8a69d..19df5ee2e 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -550,14 +550,22 @@ void Host::run(boost::system::error_code const&) // is always live and to ensure reputation and fallback timers are properly // updated. // disconnectLatePeers(); - if (peerCount() < m_idealPeerCount) + auto openSlots = m_idealPeerCount - peerCount(); + if (openSlots > 0) { - for (auto p: m_peers) - if (p.second->shouldReconnect()) - { - connect(p.second); + list> toConnect; + { + RecursiveGuard l(x_sessions); + for (auto p: m_peers) + if (p.second->shouldReconnect()) + toConnect.push_back(p.second); + } + + for (auto p: toConnect) + if (openSlots--) + connect(p); + else break; - } m_nodeTable->discover(); } diff --git a/test/peer.cpp b/test/peer.cpp index 0fe3fd1ed..14712d4f1 100644 --- a/test/peer.cpp +++ b/test/peer.cpp @@ -63,6 +63,7 @@ BOOST_AUTO_TEST_CASE(save_nodes) for (auto i:{0,1,2,3,4,5}) { Host* h = new Host("Test", NetworkPreferences(30300 + i, "127.0.0.1", true, true)); + h->setIdealPeerCount(10); // starting host is required so listenport is available h->start(); while (!h->isStarted()) From 150772e778a480359fd6943ee773a5d14ec123d7 Mon Sep 17 00:00:00 2001 From: subtly Date: Wed, 11 Mar 2015 15:44:06 +0100 Subject: [PATCH 2/2] buildbot commit --- libethereum/Client.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libethereum/Client.h b/libethereum/Client.h index 9cbfd7989..2c8db2aed 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -46,7 +46,6 @@ namespace dev { - namespace eth {