Browse Source

Merge pull request #2510 from subtly/netFix

Host Fixes (slow shutdown)
cl-refactor
Gav Wood 9 years ago
parent
commit
af97cd40e1
  1. 19
      libp2p/Host.cpp
  2. 2
      libp2p/Host.h
  3. 2
      test/TestHelper.h

19
libp2p/Host.cpp

@ -399,19 +399,22 @@ void Host::runAcceptor()
auto socket = make_shared<RLPXSocket>(new bi::tcp::socket(m_ioService)); auto socket = make_shared<RLPXSocket>(new bi::tcp::socket(m_ioService));
m_tcp4Acceptor.async_accept(socket->ref(), [=](boost::system::error_code ec) m_tcp4Acceptor.async_accept(socket->ref(), [=](boost::system::error_code ec)
{ {
if (peerCount() > 9 * m_idealPeerCount) m_accepting = false;
if (ec || !m_run)
{
socket->close();
return;
}
if (peerCount() > Ingress * m_idealPeerCount)
{ {
clog(NetConnect) << "Dropping incoming connect due to maximum peer count (9 * ideal peer count): " << socket->remoteEndpoint(); clog(NetConnect) << "Dropping incoming connect due to maximum peer count (" << Ingress << " * ideal peer count): " << socket->remoteEndpoint();
socket->close(); socket->close();
if (ec.value() < 1) if (ec.value() < 1)
runAcceptor(); runAcceptor();
return; return;
} }
// if no error code
bool success = false; bool success = false;
if (!ec)
{
try try
{ {
// incoming connection; we don't yet know nodeid // incoming connection; we don't yet know nodeid
@ -428,13 +431,9 @@ void Host::runAcceptor()
{ {
clog(NetWarn) << "ERROR: " << _e.what(); clog(NetWarn) << "ERROR: " << _e.what();
} }
}
if (!success) if (!success)
socket->ref().close(); socket->ref().close();
m_accepting = false;
if (ec.value() < 1)
runAcceptor(); runAcceptor();
}); });
} }
@ -627,7 +626,7 @@ void Host::run(boost::system::error_code const&)
m_nodeTable->processEvents(); m_nodeTable->processEvents();
// cleanup zombies // cleanup zombies
DEV_GUARDED(x_connecting); DEV_GUARDED(x_connecting)
m_connecting.remove_if([](std::weak_ptr<RLPXHandshake> h){ return h.expired(); }); m_connecting.remove_if([](std::weak_ptr<RLPXHandshake> h){ return h.expired(); });
DEV_GUARDED(x_timers) DEV_GUARDED(x_timers)
m_timers.remove_if([](std::shared_ptr<boost::asio::deadline_timer> t) m_timers.remove_if([](std::shared_ptr<boost::asio::deadline_timer> t)

2
libp2p/Host.h

@ -212,7 +212,7 @@ protected:
void restoreNetwork(bytesConstRef _b); void restoreNetwork(bytesConstRef _b);
private: private:
enum PeerSlotRatio { Egress = 2, Ingress = 9 }; enum PeerSlotRatio { Egress = 1, Ingress = 4 };
bool havePeerSession(NodeId const& _id) { return !!peerSession(_id); } bool havePeerSession(NodeId const& _id) { return !!peerSession(_id); }

2
test/TestHelper.h

@ -224,7 +224,7 @@ public:
bool inputLimits = false; bool inputLimits = false;
bool bigData = false; bool bigData = false;
bool wallet = false; bool wallet = false;
bool nonetwork = true; bool nonetwork = false;
bool nodag = true; bool nodag = true;
/// @} /// @}

Loading…
Cancel
Save