@@ -231,6 +231,10 @@ struct CBlockReject {
231231 * and we're no longer holding the node's locks.
232232 */
233233struct CNodeState {
234+ // ! The peer's address
235+ CService address;
236+ // ! Whether we have a fully established connection.
237+ bool fCurrentlyConnected ;
234238 // ! Accumulated misbehaviour score for this peer.
235239 int nMisbehavior;
236240 // ! Whether this peer should be disconnected and banned (unless whitelisted).
@@ -255,6 +259,7 @@ struct CNodeState {
255259 bool fPreferredDownload ;
256260
257261 CNodeState () {
262+ fCurrentlyConnected = false ;
258263 nMisbehavior = 0 ;
259264 fShouldBan = false ;
260265 pindexBestKnownBlock = NULL ;
@@ -298,6 +303,7 @@ void InitializeNode(NodeId nodeid, const CNode *pnode) {
298303 LOCK (cs_main);
299304 CNodeState &state = mapNodeState.insert (std::make_pair (nodeid, CNodeState ())).first ->second ;
300305 state.name = pnode->addrName ;
306+ state.address = pnode->addr ;
301307}
302308
303309void FinalizeNode (NodeId nodeid) {
@@ -307,6 +313,10 @@ void FinalizeNode(NodeId nodeid) {
307313 if (state->fSyncStarted )
308314 nSyncStarted--;
309315
316+ if (state->nMisbehavior == 0 && state->fCurrentlyConnected ) {
317+ AddressCurrentlyConnected (state->address );
318+ }
319+
310320 BOOST_FOREACH (const QueuedBlock& entry, state->vBlocksInFlight )
311321 mapBlocksInFlight.erase (entry.hash );
312322 EraseOrphansFor (nodeid);
@@ -3563,6 +3573,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
35633573 else if (strCommand == " verack" )
35643574 {
35653575 pfrom->SetRecvVersion (min (pfrom->nVersion , PROTOCOL_VERSION));
3576+
3577+ // Mark this node as currently connected, so we update its timestamp later.
3578+ if (pfrom->fNetworkNode ) {
3579+ LOCK (cs_main);
3580+ State (pfrom->GetId ())->fCurrentlyConnected = true ;
3581+ }
35663582 }
35673583
35683584
@@ -4207,11 +4223,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42074223 }
42084224
42094225
4210- // Update the last seen time for this node's address
4211- if (pfrom->fNetworkNode )
4212- if (strCommand == " version" || strCommand == " addr" || strCommand == " inv" || strCommand == " getdata" || strCommand == " ping" )
4213- AddressCurrentlyConnected (pfrom->addr );
4214-
42154226
42164227 return true ;
42174228}
0 commit comments