diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index e57397f04..870442a36 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -2124,10 +2124,10 @@ void Main::refreshWhispers() QString msg; if (m.from()) // Good message. - msg = QString("%1->%2: %3").arg(m.from() ? m.from().abridged().c_str() : "?").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); + msg = QString("{%1 -> %2} %3").arg(m.from() ? m.from().abridged().c_str() : "???").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); else if (m) // Maybe message. - msg = QString("%1->%2: %3 (?)").arg(m.from() ? m.from().abridged().c_str() : "?").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); + msg = QString("{%1 -> %2} %3 (?)").arg(m.from() ? m.from().abridged().c_str() : "???").arg(m.to() ? m.to().abridged().c_str() : "*").arg(toHex(m.payload()).c_str()); time_t ex = e.expiry(); QString t(ctime(&ex)); diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index fafb7d48a..b2d56c7d1 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -651,23 +651,26 @@ void Host::prunePeers() { RecursiveGuard l(x_peers); // We'll keep at most twice as many as is ideal, halfing what counts as "too young to kill" until we get there. - for (unsigned old = 15000; m_peers.size() > m_idealPeerCount * 2 && old > 100; old /= 2) - while (m_peers.size() > m_idealPeerCount) + set dc; + for (unsigned old = 15000; m_peers.size() - dc.size() > m_idealPeerCount * 2 && old > 100; old /= 2) + if (m_peers.size() - dc.size() > m_idealPeerCount) { // look for worst peer to kick off // first work out how many are old enough to kick off. shared_ptr worst; unsigned agedPeers = 0; for (auto i: m_peers) - if (auto p = i.second.lock()) - if (/*(m_mode != NodeMode::Host || p->m_caps != 0x01) &&*/ chrono::steady_clock::now() > p->m_connect + chrono::milliseconds(old)) // don't throw off new peers; peer-servers should never kick off other peer-servers. - { - ++agedPeers; - if ((!worst || p->rating() < worst->rating() || (p->rating() == worst->rating() && p->m_connect > worst->m_connect))) // kill older ones - worst = p; - } + if (!dc.count(i.first)) + if (auto p = i.second.lock()) + if (/*(m_mode != NodeMode::Host || p->m_caps != 0x01) &&*/ chrono::steady_clock::now() > p->m_connect + chrono::milliseconds(old)) // don't throw off new peers; peer-servers should never kick off other peer-servers. + { + ++agedPeers; + if ((!worst || p->rating() < worst->rating() || (p->rating() == worst->rating() && p->m_connect > worst->m_connect))) // kill older ones + worst = p; + } if (!worst || agedPeers <= m_idealPeerCount) break; + dc.insert(worst->id()); worst->disconnect(TooManyPeers); } diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index beb6f161d..c4385df5f 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -475,7 +475,6 @@ void Session::drop(DisconnectReason _reason) { if (m_dropped) return; - cerr << (void*)this << " dropped" << endl; if (m_socket.is_open()) try {