From 75685f91e16528c78788676c49f2ada94e7aae77 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Oct 2014 01:21:43 +0200 Subject: [PATCH] More fixes. --- libdevcore/Common.cpp | 2 +- libp2p/Host.cpp | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index fd1868539..b67e3e62c 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -27,7 +27,7 @@ using namespace dev; namespace dev { -char const* Version = "0.7.1"; +char const* Version = "0.7.2"; } diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index b13adef5a..5a6358b43 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -109,10 +109,7 @@ void Host::start() determinePublic(m_netPrefs.publicIP, m_netPrefs.upnp); ensureAccepting(); - m_nodesList.clear(); - m_ready.reset(); - - if (!m_public.address().is_unspecified()) + if (!m_public.address().is_unspecified() && (m_nodes.empty() || m_nodes[m_nodesList[0]]->id != id())) noteNode(id(), m_public, Origin::Perfect, false); m_lastPeersRequest = chrono::steady_clock::time_point::min(); @@ -351,6 +348,7 @@ void Host::populateAddresses() shared_ptr Host::noteNode(NodeId _id, bi::tcp::endpoint const& _a, Origin _o, bool _ready, NodeId _oldId) { RecursiveGuard l(x_peers); + cnote << "Node:" << _id.abridged() << _a << (_ready ? "ready" : "used") << _oldId.abridged() << (m_nodes.count(_id) ? "[have]" : "[NEW]"); unsigned i; if (!m_nodes.count(_id)) { @@ -389,6 +387,9 @@ shared_ptr Host::noteNode(NodeId _id, bi::tcp::endpoint const& _a, Origin m_private += i; else m_private -= i; + + cnote << m_nodes[_id]->index << ":" << m_ready; + return m_nodes[_id]; } @@ -548,7 +549,7 @@ void Host::growPeers() if (morePeers > 0) { auto toTry = m_ready; - if (m_netPrefs.localNetworking) + if (!m_netPrefs.localNetworking) toTry -= m_private; set ns; for (auto i: toTry) @@ -656,16 +657,19 @@ bytes Host::saveNodes() const for (auto const& i: m_nodes) { Node const& n = *(i.second); - nodes.appendList(10); - if (n.address.address().is_v4()) - nodes << n.address.address().to_v4().to_bytes(); - else - nodes << n.address.address().to_v6().to_bytes(); - nodes << n.address.port() << n.id << (int)n.idOrigin - << std::chrono::duration_cast(n.lastConnected.time_since_epoch()).count() - << std::chrono::duration_cast(n.lastAttempted.time_since_epoch()).count() - << n.failedAttempts << n.lastDisconnect << n.score << n.rating; - count++; + if (n.id != id() && !isPrivateAddress(n.address.address())) + { + nodes.appendList(10); + if (n.address.address().is_v4()) + nodes << n.address.address().to_v4().to_bytes(); + else + nodes << n.address.address().to_v6().to_bytes(); + nodes << n.address.port() << n.id << (int)n.idOrigin + << std::chrono::duration_cast(n.lastConnected.time_since_epoch()).count() + << std::chrono::duration_cast(n.lastAttempted.time_since_epoch()).count() + << n.failedAttempts << n.lastDisconnect << n.score << n.rating; + count++; + } } } RLPStream ret(3);