Browse Source

Fix deadlock.

cl-refactor
Gav Wood 10 years ago
parent
commit
86804fedf1
  1. 14
      libethereum/BlockChain.cpp
  2. 6
      libp2p/NodeTable.cpp
  3. 6
      libp2p/RLPxHandshake.cpp

14
libethereum/BlockChain.cpp

@ -965,24 +965,24 @@ bool BlockChain::isKnown(h256 const& _hash) const
if (_hash == m_genesisHash) if (_hash == m_genesisHash)
return true; return true;
BlockInfo bi;
{ {
ReadGuard l(x_blocks); ReadGuard l(x_blocks);
auto it = m_blocks.find(_hash); auto it = m_blocks.find(_hash);
if (it != m_blocks.end()) if (it != m_blocks.end())
{ bi = BlockInfo(it->second, CheckNothing, _hash);
noteUsed(_hash);
BlockInfo bi(it->second, CheckNothing, _hash);
return bi.number <= m_lastBlockNumber; // TODO: m_lastBlockNumber
}
} }
if (!bi)
{
string d; string d;
m_blocksDB->Get(m_readOptions, toSlice(_hash), &d); m_blocksDB->Get(m_readOptions, toSlice(_hash), &d);
if (!d.size()) if (!d.size())
return false; return false;
bi = BlockInfo(bytesConstRef(&d), CheckNothing, _hash);
}
BlockInfo bi(bytesConstRef(&d), CheckNothing, _hash);
return bi.number <= m_lastBlockNumber; // TODO: m_lastBlockNumber return bi.number <= m_lastBlockNumber; // TODO: m_lastBlockNumber
} }

6
libp2p/NodeTable.cpp

@ -382,7 +382,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
// h256 + Signature + type + RLP (smallest possible packet is empty neighbours packet which is 3 bytes) // h256 + Signature + type + RLP (smallest possible packet is empty neighbours packet which is 3 bytes)
if (_packet.size() < h256::size + Signature::size + 1 + 3) if (_packet.size() < h256::size + Signature::size + 1 + 3)
{ {
clog(NodeTableWarn) << "Invalid message size from " << _from.address().to_string() << ":" << _from.port(); clog(NodeTableTriviaSummary) << "Invalid message size from " << _from.address().to_string() << ":" << _from.port();
return; return;
} }
@ -390,7 +390,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
h256 hashSigned(sha3(hashedBytes)); h256 hashSigned(sha3(hashedBytes));
if (!_packet.cropped(0, h256::size).contentsEqual(hashSigned.asBytes())) if (!_packet.cropped(0, h256::size).contentsEqual(hashSigned.asBytes()))
{ {
clog(NodeTableWarn) << "Invalid message hash from " << _from.address().to_string() << ":" << _from.port(); clog(NodeTableTriviaSummary) << "Invalid message hash from " << _from.address().to_string() << ":" << _from.port();
return; return;
} }
@ -402,7 +402,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes
Public nodeid(dev::recover(*(Signature const*)sigBytes.data(), sha3(signedBytes))); Public nodeid(dev::recover(*(Signature const*)sigBytes.data(), sha3(signedBytes)));
if (!nodeid) if (!nodeid)
{ {
clog(NodeTableWarn) << "Invalid message signature from " << _from.address().to_string() << ":" << _from.port(); clog(NodeTableTriviaSummary) << "Invalid message signature from " << _from.address().to_string() << ":" << _from.port();
return; return;
} }

6
libp2p/RLPxHandshake.cpp

@ -249,7 +249,7 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
bytesRef frame(&m_handshakeInBuffer); bytesRef frame(&m_handshakeInBuffer);
if (!m_io->authAndDecryptFrame(frame)) if (!m_io->authAndDecryptFrame(frame))
{ {
clog(NetWarn) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: decrypt failed"; clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: decrypt failed";
m_nextState = Error; m_nextState = Error;
transition(); transition();
return; return;
@ -258,13 +258,13 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
PacketType packetType = (PacketType)(frame[0] == 0x80 ? 0x0 : frame[0]); PacketType packetType = (PacketType)(frame[0] == 0x80 ? 0x0 : frame[0]);
if (packetType != 0) if (packetType != 0)
{ {
clog(NetWarn) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: invalid packet type"; clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: invalid packet type";
m_nextState = Error; m_nextState = Error;
transition(); transition();
return; return;
} }
clog(NetNote) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: success. starting session."; clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: success. starting session.";
RLP rlp(frame.cropped(1), RLP::ThrowOnFail | RLP::FailIfTooSmall); RLP rlp(frame.cropped(1), RLP::ThrowOnFail | RLP::FailIfTooSmall);
m_host->startPeerSession(m_remote, rlp, m_io, m_socket->remoteEndpoint()); m_host->startPeerSession(m_remote, rlp, m_io, m_socket->remoteEndpoint());
} }

Loading…
Cancel
Save