Browse Source

Code review. Fix inverted peer slot check.

cl-refactor
subtly 10 years ago
parent
commit
c72b218d88
  1. 6
      libp2p/Host.cpp
  2. 2
      libp2p/Host.h
  3. 2
      libp2p/NodeTable.cpp

6
libp2p/Host.cpp

@ -226,7 +226,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io
return; return;
} }
if (peerSlotsAvailable(Ingress)) if (!peerSlotsAvailable(Ingress))
{ {
ps->disconnect(TooManyPeers); ps->disconnect(TooManyPeers);
return; return;
@ -580,10 +580,8 @@ void Host::run(boost::system::error_code const&)
// todo: update peerSlotsAvailable() // todo: update peerSlotsAvailable()
unsigned pendingCount = 0; unsigned pendingCount = 0;
{ ETH_GUARDED(x_pendingNodeConns)
Guard l(x_pendingNodeConns);
pendingCount = m_pendingPeerConns.size(); pendingCount = m_pendingPeerConns.size();
}
int openSlots = m_idealPeerCount - peerCount() - pendingCount; int openSlots = m_idealPeerCount - peerCount() - pendingCount;
if (openSlots > 0) if (openSlots > 0)
{ {

2
libp2p/Host.h

@ -162,7 +162,7 @@ protected:
void restoreNetwork(bytesConstRef _b); void restoreNetwork(bytesConstRef _b);
private: private:
enum PeerSlotRatio { Egress = 1, Ingress = 9 }; enum PeerSlotRatio { Egress = 2, Ingress = 9 };
bool havePeerSession(NodeId _id) { RecursiveGuard l(x_sessions); return m_sessions.count(_id) ? !!m_sessions[_id].lock() : false; } bool havePeerSession(NodeId _id) { RecursiveGuard l(x_sessions); return m_sessions.count(_id) ? !!m_sessions[_id].lock() : false; }

2
libp2p/NodeTable.cpp

@ -83,7 +83,7 @@ shared_ptr<NodeEntry> NodeTable::addNode(Public const& _pubk, NodeIPEndpoint con
shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relation) shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node, NodeRelation _relation)
{ {
if (_relation) if (_relation == Known)
{ {
shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint)); shared_ptr<NodeEntry> ret(new NodeEntry(m_node, _node.id, _node.endpoint));
ret->pending = false; ret->pending = false;

Loading…
Cancel
Save