Browse Source

less tolerant connection errors

cl-refactor
subtly 10 years ago
parent
commit
1744a32547
  1. 10
      libp2p/Host.cpp
  2. 5
      libp2p/Session.cpp

10
libp2p/Host.cpp

@ -182,10 +182,8 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io
} }
else else
p = m_peers[_id]; p = m_peers[_id];
p->m_lastDisconnect = NoDisconnect;
if (p->isOffline()) if (p->isOffline())
p->m_lastConnected = std::chrono::system_clock::now(); p->m_lastConnected = std::chrono::system_clock::now();
p->m_failedAttempts = 0;
p->endpoint.tcp.address(_endpoint.address()); p->endpoint.tcp.address(_endpoint.address());
auto protocolVersion = _rlp[0].toInt<unsigned>(); auto protocolVersion = _rlp[0].toInt<unsigned>();
@ -484,12 +482,14 @@ void Host::connect(std::shared_ptr<Peer> const& _p)
auto socket = make_shared<RLPXSocket>(new bi::tcp::socket(m_ioService)); auto socket = make_shared<RLPXSocket>(new bi::tcp::socket(m_ioService));
socket->ref().async_connect(_p->peerEndpoint(), [=](boost::system::error_code const& ec) socket->ref().async_connect(_p->peerEndpoint(), [=](boost::system::error_code const& ec)
{ {
_p->m_lastAttempted = std::chrono::system_clock::now();
_p->m_failedAttempts++;
if (ec) if (ec)
{ {
clog(NetConnect) << "Connection refused to node" << _p->id.abridged() << "@" << _p->peerEndpoint() << "(" << ec.message() << ")"; clog(NetConnect) << "Connection refused to node" << _p->id.abridged() << "@" << _p->peerEndpoint() << "(" << ec.message() << ")";
// Manually set error (session not present)
_p->m_lastDisconnect = TCPError; _p->m_lastDisconnect = TCPError;
_p->m_lastAttempted = std::chrono::system_clock::now();
_p->m_failedAttempts++;
} }
else else
{ {
@ -500,8 +500,6 @@ void Host::connect(std::shared_ptr<Peer> const& _p)
m_connecting.push_back(handshake); m_connecting.push_back(handshake);
} }
// preempt setting failedAttempts; this value is cleared upon success
_p->m_failedAttempts++;
handshake->start(); handshake->start();
} }

5
libp2p/Session.cpp

@ -358,9 +358,7 @@ void Session::drop(DisconnectReason _reason)
} }
catch (...) {} catch (...) {}
if (m_peer) if (m_peer->m_lastDisconnect == NoDisconnect && (_reason == ClientQuit || _reason == DisconnectRequested))
{
if (_reason != m_peer->m_lastDisconnect || _reason == NoDisconnect || _reason == ClientQuit || _reason == DisconnectRequested)
m_peer->m_failedAttempts = 0; m_peer->m_failedAttempts = 0;
m_peer->m_lastDisconnect = _reason; m_peer->m_lastDisconnect = _reason;
if (_reason == BadProtocol) if (_reason == BadProtocol)
@ -368,7 +366,6 @@ void Session::drop(DisconnectReason _reason)
m_peer->m_rating /= 2; m_peer->m_rating /= 2;
m_peer->m_score /= 2; m_peer->m_score /= 2;
} }
}
m_dropped = true; m_dropped = true;
} }

Loading…
Cancel
Save