Browse Source

ensure required peers

cl-refactor
subtly 10 years ago
parent
commit
e9c00ab2f9
  1. 32
      libp2p/Host.cpp

32
libp2p/Host.cpp

@ -619,25 +619,35 @@ void Host::run(boost::system::error_code const&)
// updated. // disconnectLatePeers(); // updated. // disconnectLatePeers();
// todo: update peerSlotsAvailable() // todo: update peerSlotsAvailable()
unsigned pendingCount = 0;
DEV_GUARDED(x_pendingNodeConns)
pendingCount = m_pendingPeerConns.size();
int openSlots = m_idealPeerCount - peerCount() - pendingCount;
if (openSlots > 0)
{
list<shared_ptr<Peer>> toConnect; list<shared_ptr<Peer>> toConnect;
unsigned reqConn = 0;
{ {
RecursiveGuard l(x_sessions); RecursiveGuard l(x_sessions);
for (auto p: m_peers) for (auto const& p: m_peers)
if (p.second->shouldReconnect() && !havePeerSession(p.second->id) && (!m_netPrefs.pin || p.second->required)) {
bool haveSession = havePeerSession(p.second->id);
bool required = p.second->required;
if (haveSession && required)
reqConn++;
else if (!haveSession && p.second->shouldReconnect() && (!m_netPrefs.pin || required))
toConnect.push_back(p.second); toConnect.push_back(p.second);
} }
}
for (auto p: toConnect) for (auto p: toConnect)
if (openSlots--) if (p->required && reqConn++ < m_idealPeerCount)
connect(p);
unsigned pendingCount = 0;
DEV_GUARDED(x_pendingNodeConns)
pendingCount = m_pendingPeerConns.size();
int openSlots = m_idealPeerCount - peerCount() - pendingCount + reqConn;
if (openSlots > 0 && !m_netPrefs.pin)
{
for (auto p: toConnect)
if (!p->required && openSlots--)
connect(p); connect(p);
else
break;
m_nodeTable->discover(); m_nodeTable->discover();
} }

Loading…
Cancel
Save