Browse Source

Merge pull request #2088 from subtly/netFix

Net fixes: rlp exception in handshake, peer disconnect during read
cl-refactor
Gav Wood 10 years ago
parent
commit
cfe709a495
  1. 13
      libp2p/RLPxHandshake.cpp
  2. 6
      libp2p/Session.cpp
  3. 3
      test/libp2p/peer.cpp

13
libp2p/RLPxHandshake.cpp

@ -265,8 +265,17 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
}
clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: success. starting session.";
RLP rlp(frame.cropped(1), RLP::ThrowOnFail | RLP::FailIfTooSmall);
m_host->startPeerSession(m_remote, rlp, m_io, m_socket->remoteEndpoint());
try
{
RLP rlp(frame.cropped(1), RLP::ThrowOnFail | RLP::FailIfTooSmall);
m_host->startPeerSession(m_remote, rlp, m_io, m_socket->remoteEndpoint());
}
catch (std::exception const& _e)
{
clog(NetWarn) << "Handshake causing an exception:" << _e.what();
m_nextState = Error;
transition();
}
}
});
}

6
libp2p/Session.cpp

@ -447,8 +447,12 @@ void Session::doRead()
clog(NetWarn) << "Error reading: " << ec.message();
drop(TCPError);
}
else if (ec && length == 0)
else if (ec && length < tlen)
{
clog(NetWarn) << "Error reading - Abrupt peer disconnect: " << ec.message();
drop(TCPError);
return;
}
else
{
if (!m_io->authAndDecryptFrame(bytesRef(m_data.data(), tlen)))

3
test/libp2p/peer.cpp

@ -116,6 +116,9 @@ BOOST_AUTO_TEST_CASE(saveNodes)
BOOST_REQUIRE(i.itemCount() == 4 || i.itemCount() == 11);
BOOST_REQUIRE(i[0].size() == 4 || i[0].size() == 16);
}
for (auto host: hosts)
delete host;
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save