Browse Source

dry

cl-refactor
subtly 10 years ago
parent
commit
242d22e67d
  1. 15
      libp2p/Host.cpp
  2. 5
      libp2p/Host.h

15
libp2p/Host.cpp

@ -226,12 +226,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io
return;
}
unsigned pendingCount = 0;
{
Guard l(x_pendingNodeConns);
pendingCount = m_pendingPeerConns.size();
}
if (peerCount() + pendingCount > 9 * m_idealPeerCount)
if (peerSlotsAvailable(Ingress))
{
ps->disconnect(TooManyPeers);
return;
@ -276,12 +271,7 @@ void Host::onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e)
clog(NetNote) << "p2p.host.peers.events.peerAdded " << _n << p->endpoint;
}
}
unsigned pendingCount = 0;
{
Guard l(x_pendingNodeConns);
pendingCount = m_pendingPeerConns.size();
}
if (peerCount() + pendingCount < m_idealPeerCount)
if (peerSlotsAvailable(Egress))
connect(p);
}
}
@ -588,6 +578,7 @@ void Host::run(boost::system::error_code const&)
// is always live and to ensure reputation and fallback timers are properly
// updated. // disconnectLatePeers();
// todo: update peerSlotsAvailable()
unsigned pendingCount = 0;
{
Guard l(x_pendingNodeConns);

5
libp2p/Host.h

@ -162,6 +162,8 @@ protected:
void restoreNetwork(bytesConstRef _b);
private:
enum PeerSlotRatio { Egress = 1, Ingress = 9 };
bool havePeerSession(NodeId _id) { RecursiveGuard l(x_sessions); return m_sessions.count(_id) ? !!m_sessions[_id].lock() : false; }
/// Determines and sets m_tcpPublic to publicly advertised address.
@ -169,6 +171,9 @@ private:
void connect(std::shared_ptr<Peer> const& _p);
/// Returns true if pending and connected peer count is less than maximum
bool peerSlotsAvailable(PeerSlotRatio _type) { Guard l(x_pendingNodeConns); return peerCount() + m_pendingPeerConns.size() > _type * m_idealPeerCount; }
/// Ping the peers to update the latency information and disconnect peers which have timed out.
void keepAlivePeers();

Loading…
Cancel
Save