|
|
@ -1063,7 +1063,7 @@ void CConnman::ThreadSocketHandler()
|
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesCopy)
|
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesCopy)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (pnode->fDisconnect ||
|
|
|
|
if (pnode->fDisconnect ||
|
|
|
|
(pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty()))
|
|
|
|
(pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// remove from vNodes
|
|
|
|
// remove from vNodes
|
|
|
|
vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
|
|
|
|
vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
|
|
|
@ -2482,46 +2482,10 @@ int CConnman::GetBestHeight() const
|
|
|
|
return nBestHeight.load(std::memory_order_acquire);
|
|
|
|
return nBestHeight.load(std::memory_order_acquire);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CNode::Fuzz(int nChance)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!fSuccessfullyConnected) return; // Don't fuzz initial handshake
|
|
|
|
|
|
|
|
if (GetRand(nChance) != 0) return; // Fuzz 1 of every nChance messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (GetRand(3))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
// xor a random byte with a random value:
|
|
|
|
|
|
|
|
if (!ssSend.empty()) {
|
|
|
|
|
|
|
|
CDataStream::size_type pos = GetRand(ssSend.size());
|
|
|
|
|
|
|
|
ssSend[pos] ^= (unsigned char)(GetRand(256));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
// delete a random byte:
|
|
|
|
|
|
|
|
if (!ssSend.empty()) {
|
|
|
|
|
|
|
|
CDataStream::size_type pos = GetRand(ssSend.size());
|
|
|
|
|
|
|
|
ssSend.erase(ssSend.begin()+pos);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
// insert a random byte at a random position
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CDataStream::size_type pos = GetRand(ssSend.size());
|
|
|
|
|
|
|
|
char ch = (char)GetRand(256);
|
|
|
|
|
|
|
|
ssSend.insert(ssSend.begin()+pos, ch);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chance of more than one change half the time:
|
|
|
|
|
|
|
|
// (more changes exponentially less likely):
|
|
|
|
|
|
|
|
Fuzz(2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
|
|
|
|
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
|
|
|
|
unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; }
|
|
|
|
unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; }
|
|
|
|
|
|
|
|
|
|
|
|
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string& addrNameIn, bool fInboundIn) :
|
|
|
|
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string& addrNameIn, bool fInboundIn) :
|
|
|
|
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
|
|
|
|
|
|
|
|
addr(addrIn),
|
|
|
|
addr(addrIn),
|
|
|
|
fInbound(fInboundIn),
|
|
|
|
fInbound(fInboundIn),
|
|
|
|
id(idIn),
|
|
|
|
id(idIn),
|
|
|
|