@@ -432,32 +432,6 @@ static void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUS
432
432
nPreferredDownload += state->fPreferredDownload ;
433
433
}
434
434
435
- static void PushNodeVersion (CNode& pnode, CConnman& connman, int64_t nTime)
436
- {
437
- // Note that pnode->GetLocalServices() is a reflection of the local
438
- // services we were offering when the CNode object was created for this
439
- // peer.
440
- ServiceFlags nLocalNodeServices = pnode.GetLocalServices ();
441
- uint64_t nonce = pnode.GetLocalNonce ();
442
- int nNodeStartingHeight = pnode.GetMyStartingHeight ();
443
- NodeId nodeid = pnode.GetId ();
444
- CAddress addr = pnode.addr ;
445
-
446
- CAddress addrYou = addr.IsRoutable () && !IsProxy (addr) && addr.IsAddrV1Compatible () ?
447
- addr :
448
- CAddress (CService (), addr.nServices );
449
- CAddress addrMe = CAddress (CService (), nLocalNodeServices);
450
-
451
- connman.PushMessage (&pnode, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t )nLocalNodeServices, nTime, addrYou, addrMe,
452
- nonce, strSubVersion, nNodeStartingHeight, ::g_relay_txes && pnode.m_tx_relay != nullptr ));
453
-
454
- if (fLogIPs ) {
455
- LogPrint (BCLog::NET, " send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n " , PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString (), addrYou.ToString (), nodeid);
456
- } else {
457
- LogPrint (BCLog::NET, " send version message: version %d, blocks=%d, us=%s, peer=%d\n " , PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString (), nodeid);
458
- }
459
- }
460
-
461
435
// Returns a bool indicating whether we requested this block.
462
436
// Also used if a block was /not/ received and timed out or started with another peer
463
437
static bool MarkBlockAsReceived (const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
@@ -708,6 +682,32 @@ static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vec
708
682
709
683
} // namespace
710
684
685
+ void PeerManager::PushNodeVersion (CNode& pnode, int64_t nTime)
686
+ {
687
+ // Note that pnode->GetLocalServices() is a reflection of the local
688
+ // services we were offering when the CNode object was created for this
689
+ // peer.
690
+ ServiceFlags nLocalNodeServices = pnode.GetLocalServices ();
691
+ uint64_t nonce = pnode.GetLocalNonce ();
692
+ int nNodeStartingHeight = pnode.GetMyStartingHeight ();
693
+ NodeId nodeid = pnode.GetId ();
694
+ CAddress addr = pnode.addr ;
695
+
696
+ CAddress addrYou = addr.IsRoutable () && !IsProxy (addr) && addr.IsAddrV1Compatible () ?
697
+ addr :
698
+ CAddress (CService (), addr.nServices );
699
+ CAddress addrMe = CAddress (CService (), nLocalNodeServices);
700
+
701
+ m_connman.PushMessage (&pnode, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t )nLocalNodeServices, nTime, addrYou, addrMe,
702
+ nonce, strSubVersion, nNodeStartingHeight, ::g_relay_txes && pnode.m_tx_relay != nullptr ));
703
+
704
+ if (fLogIPs ) {
705
+ LogPrint (BCLog::NET, " send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n " , PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString (), addrYou.ToString (), nodeid);
706
+ } else {
707
+ LogPrint (BCLog::NET, " send version message: version %d, blocks=%d, us=%s, peer=%d\n " , PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString (), nodeid);
708
+ }
709
+ }
710
+
711
711
void PeerManager::AddTxAnnouncement (const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time)
712
712
{
713
713
AssertLockHeld (::cs_main); // For m_txrequest
@@ -759,7 +759,7 @@ void PeerManager::InitializeNode(CNode *pnode) {
759
759
m_peer_map.emplace_hint (m_peer_map.end (), nodeid, std::move (peer));
760
760
}
761
761
if (!pnode->IsInboundConn ()) {
762
- PushNodeVersion (*pnode, m_connman, GetTime ());
762
+ PushNodeVersion (*pnode, GetTime ());
763
763
}
764
764
}
765
765
@@ -2312,9 +2312,9 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2312
2312
SeenLocal (addrMe);
2313
2313
}
2314
2314
2315
- // Be shy and don't send version until we hear
2316
- if (pfrom. IsInboundConn ())
2317
- PushNodeVersion (pfrom, m_connman , GetAdjustedTime ());
2315
+ // Inbound peers send us their version message when they connect.
2316
+ // We send our version message in response.
2317
+ if (pfrom. IsInboundConn ()) PushNodeVersion (pfrom, GetAdjustedTime ());
2318
2318
2319
2319
// Change version
2320
2320
const int greatest_common_version = std::min (nVersion, PROTOCOL_VERSION);
0 commit comments