|
|
@ -238,6 +238,10 @@ struct CBlockReject { |
|
|
|
* and we're no longer holding the node's locks. |
|
|
|
* and we're no longer holding the node's locks. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
struct CNodeState { |
|
|
|
struct CNodeState { |
|
|
|
|
|
|
|
//! The peer's address
|
|
|
|
|
|
|
|
CService address; |
|
|
|
|
|
|
|
//! Whether we have a fully established connection.
|
|
|
|
|
|
|
|
bool fCurrentlyConnected; |
|
|
|
//! Accumulated misbehaviour score for this peer.
|
|
|
|
//! Accumulated misbehaviour score for this peer.
|
|
|
|
int nMisbehavior; |
|
|
|
int nMisbehavior; |
|
|
|
//! Whether this peer should be disconnected and banned (unless whitelisted).
|
|
|
|
//! Whether this peer should be disconnected and banned (unless whitelisted).
|
|
|
@ -262,6 +266,7 @@ struct CNodeState { |
|
|
|
bool fPreferredDownload; |
|
|
|
bool fPreferredDownload; |
|
|
|
|
|
|
|
|
|
|
|
CNodeState() { |
|
|
|
CNodeState() { |
|
|
|
|
|
|
|
fCurrentlyConnected = false; |
|
|
|
nMisbehavior = 0; |
|
|
|
nMisbehavior = 0; |
|
|
|
fShouldBan = false; |
|
|
|
fShouldBan = false; |
|
|
|
pindexBestKnownBlock = NULL; |
|
|
|
pindexBestKnownBlock = NULL; |
|
|
@ -305,6 +310,7 @@ void InitializeNode(NodeId nodeid, const CNode *pnode) { |
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
|
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; |
|
|
|
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; |
|
|
|
state.name = pnode->addrName; |
|
|
|
state.name = pnode->addrName; |
|
|
|
|
|
|
|
state.address = pnode->addr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FinalizeNode(NodeId nodeid) { |
|
|
|
void FinalizeNode(NodeId nodeid) { |
|
|
@ -314,6 +320,10 @@ void FinalizeNode(NodeId nodeid) { |
|
|
|
if (state->fSyncStarted) |
|
|
|
if (state->fSyncStarted) |
|
|
|
nSyncStarted--; |
|
|
|
nSyncStarted--; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state->nMisbehavior == 0 && state->fCurrentlyConnected) { |
|
|
|
|
|
|
|
AddressCurrentlyConnected(state->address); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight) |
|
|
|
BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight) |
|
|
|
mapBlocksInFlight.erase(entry.hash); |
|
|
|
mapBlocksInFlight.erase(entry.hash); |
|
|
|
EraseOrphansFor(nodeid); |
|
|
|
EraseOrphansFor(nodeid); |
|
|
@ -3628,6 +3638,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
else if (strCommand == "verack") |
|
|
|
else if (strCommand == "verack") |
|
|
|
{ |
|
|
|
{ |
|
|
|
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); |
|
|
|
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mark this node as currently connected, so we update its timestamp later.
|
|
|
|
|
|
|
|
if (pfrom->fNetworkNode) { |
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
State(pfrom->GetId())->fCurrentlyConnected = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -4272,11 +4288,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the last seen time for this node's address
|
|
|
|
|
|
|
|
if (pfrom->fNetworkNode) |
|
|
|
|
|
|
|
if (strCommand == "version" || strCommand == "addr" || strCommand == "inv" || strCommand == "getdata" || strCommand == "ping") |
|
|
|
|
|
|
|
AddressCurrentlyConnected(pfrom->addr); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|