@@ -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, !m_ignore_incoming_txs && 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
@@ -1124,13 +1124,15 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para
1124
1124
}
1125
1125
1126
1126
PeerManager::PeerManager (const CChainParams& chainparams, CConnman& connman, BanMan* banman,
1127
- CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool)
1127
+ CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool,
1128
+ bool ignore_incoming_txs)
1128
1129
: m_chainparams(chainparams),
1129
1130
m_connman(connman),
1130
1131
m_banman(banman),
1131
1132
m_chainman(chainman),
1132
1133
m_mempool(pool),
1133
- m_stale_tip_check_time(0 )
1134
+ m_stale_tip_check_time(0 ),
1135
+ m_ignore_incoming_txs(ignore_incoming_txs)
1134
1136
{
1135
1137
// Initialize global variables that cannot be constructed at startup.
1136
1138
recentRejects.reset (new CRollingBloomFilter (120000 , 0.000001 ));
@@ -2312,9 +2314,9 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2312
2314
SeenLocal (addrMe);
2313
2315
}
2314
2316
2315
- // Be shy and don't send version until we hear
2316
- if (pfrom. IsInboundConn ())
2317
- PushNodeVersion (pfrom, m_connman , GetAdjustedTime ());
2317
+ // Inbound peers send us their version message when they connect.
2318
+ // We send our version message in response.
2319
+ if (pfrom. IsInboundConn ()) PushNodeVersion (pfrom, GetAdjustedTime ());
2318
2320
2319
2321
// Change version
2320
2322
const int greatest_common_version = std::min (nVersion, PROTOCOL_VERSION);
@@ -2624,7 +2626,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2624
2626
2625
2627
// We won't accept tx inv's if we're in blocks-only mode, or this is a
2626
2628
// block-relay-only peer
2627
- bool fBlocksOnly = !g_relay_txes || (pfrom.m_tx_relay == nullptr );
2629
+ bool fBlocksOnly = m_ignore_incoming_txs || (pfrom.m_tx_relay == nullptr );
2628
2630
2629
2631
// Allow peers with relay permission to send data other than blocks in blocks only mode
2630
2632
if (pfrom.HasPermission (PF_RELAY)) {
@@ -2901,7 +2903,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2901
2903
// Stop processing the transaction early if
2902
2904
// 1) We are in blocks only mode and peer has no relay permission
2903
2905
// 2) This peer is a block-relay-only peer
2904
- if ((!g_relay_txes && !pfrom.HasPermission (PF_RELAY)) || (pfrom.m_tx_relay == nullptr ))
2906
+ if ((m_ignore_incoming_txs && !pfrom.HasPermission (PF_RELAY)) || (pfrom.m_tx_relay == nullptr ))
2905
2907
{
2906
2908
LogPrint (BCLog::NET, " transaction sent in violation of protocol peer=%d\n " , pfrom.GetId ());
2907
2909
pfrom.fDisconnect = true ;
0 commit comments