Browse Source

Slightly more error resistant.

cl-refactor
Gav Wood 11 years ago
parent
commit
69aed5087e
  1. 54
      libethereum/PeerNetwork.cpp

54
libethereum/PeerNetwork.cpp

@ -341,33 +341,41 @@ void PeerSession::doRead()
dropped(); dropped();
else else
{ {
m_incoming.resize(m_incoming.size() + length); try
memcpy(m_incoming.data() + m_incoming.size() - length, m_data.data(), length);
while (m_incoming.size() > 8)
{ {
if (m_incoming[0] != 0x22 || m_incoming[1] != 0x40 || m_incoming[2] != 0x08 || m_incoming[3] != 0x91) m_incoming.resize(m_incoming.size() + length);
memcpy(m_incoming.data() + m_incoming.size() - length, m_data.data(), length);
while (m_incoming.size() > 8)
{ {
cout << "*** Out of alignment: skipping: " << hex << showbase << (int)m_incoming[0] << endl; if (m_incoming[0] != 0x22 || m_incoming[1] != 0x40 || m_incoming[2] != 0x08 || m_incoming[3] != 0x91)
memmove(m_incoming.data(), m_incoming.data() + 1, m_incoming.size() - 1); {
m_incoming.resize(m_incoming.size() - 1); cout << "*** Out of alignment: skipping: " << hex << showbase << (int)m_incoming[0] << endl;
} memmove(m_incoming.data(), m_incoming.data() + 1, m_incoming.size() - 1);
else m_incoming.resize(m_incoming.size() - 1);
{ }
uint32_t len = fromBigEndian<uint32_t>(bytesConstRef(m_incoming.data() + 4, 4)); else
// cout << "Received packet of " << len << " bytes" << endl; {
if (m_incoming.size() - 8 < len) uint32_t len = fromBigEndian<uint32_t>(bytesConstRef(m_incoming.data() + 4, 4));
break; // cout << "Received packet of " << len << " bytes" << endl;
if (m_incoming.size() - 8 < len)
// enough has come in. break;
RLP r(bytesConstRef(m_incoming.data() + 8, len));
if (!interpret(r)) // enough has come in.
// error RLP r(bytesConstRef(m_incoming.data() + 8, len));
break; if (!interpret(r))
memmove(m_incoming.data(), m_incoming.data() + len + 8, m_incoming.size() - (len + 8)); // error
m_incoming.resize(m_incoming.size() - (len + 8)); break;
memmove(m_incoming.data(), m_incoming.data() + len + 8, m_incoming.size() - (len + 8));
m_incoming.resize(m_incoming.size() - (len + 8));
}
} }
doRead();
}
catch (std::exception const& _e)
{
cout << std::setw(2) << m_socket.native_handle() << " | ERROR: " << _e.what() << endl;
dropped();
} }
doRead();
} }
}); });
} }

Loading…
Cancel
Save