@@ -219,9 +219,7 @@ struct Peer {
219
219
* to serve, but still advertises NODE_NETWORK because it will eventually
220
220
* fulfill this role after IBD completes. P2P code is written in such a
221
221
* way that it can gracefully handle peers who don't make good on their
222
- * service advertisements.
223
- *
224
- * TODO: remove redundant CNode::nLocalServices*/
222
+ * service advertisements. */
225
223
const ServiceFlags m_our_services;
226
224
/* * Services this peer offered to us. */
227
225
std::atomic<ServiceFlags> m_their_services{NODE_NONE};
@@ -867,6 +865,7 @@ class PeerManagerImpl final : public PeerManager
867
865
*
868
866
* May disconnect from the peer in the case of a bad request.
869
867
*
868
+ * @param[in] node The node that we received the request from
870
869
* @param[in] peer The peer that we received the request from
871
870
* @param[in] filter_type The filter type the request is for. Must be basic filters.
872
871
* @param[in] start_height The start height for the request
@@ -876,7 +875,7 @@ class PeerManagerImpl final : public PeerManager
876
875
* @param[out] filter_index The filter index, if the request can be serviced.
877
876
* @return True if the request can be serviced.
878
877
*/
879
- bool PrepareBlockFilterRequest (CNode& peer,
878
+ bool PrepareBlockFilterRequest (CNode& node, Peer& peer,
880
879
BlockFilterType filter_type, uint32_t start_height,
881
880
const uint256& stop_hash, uint32_t max_height_diff,
882
881
const CBlockIndex*& stop_index,
@@ -887,30 +886,33 @@ class PeerManagerImpl final : public PeerManager
887
886
*
888
887
* May disconnect from the peer in the case of a bad request.
889
888
*
889
+ * @param[in] node The node that we received the request from
890
890
* @param[in] peer The peer that we received the request from
891
891
* @param[in] vRecv The raw message received
892
892
*/
893
- void ProcessGetCFilters (CNode& peer, CDataStream& vRecv);
893
+ void ProcessGetCFilters (CNode& node, Peer& peer, CDataStream& vRecv);
894
894
895
895
/* *
896
896
* Handle a cfheaders request.
897
897
*
898
898
* May disconnect from the peer in the case of a bad request.
899
899
*
900
+ * @param[in] node The node that we received the request from
900
901
* @param[in] peer The peer that we received the request from
901
902
* @param[in] vRecv The raw message received
902
903
*/
903
- void ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv);
904
+ void ProcessGetCFHeaders (CNode& node, Peer& peer, CDataStream& vRecv);
904
905
905
906
/* *
906
907
* Handle a getcfcheckpt request.
907
908
*
908
909
* May disconnect from the peer in the case of a bad request.
909
910
*
911
+ * @param[in] node The node that we received the request from
910
912
* @param[in] peer The peer that we received the request from
911
913
* @param[in] vRecv The raw message received
912
914
*/
913
- void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv);
915
+ void ProcessGetCFCheckPt (CNode& node, Peer& peer, CDataStream& vRecv);
914
916
915
917
/* * Checks if address relay is permitted with peer. If needed, initializes
916
918
* the m_addr_known bloom filter and sets m_addr_relay_enabled to true.
@@ -1278,10 +1280,7 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
1278
1280
1279
1281
void PeerManagerImpl::PushNodeVersion (CNode& pnode, const Peer& peer)
1280
1282
{
1281
- // Note that pnode->GetLocalServices() is a reflection of the local
1282
- // services we were offering when the CNode object was created for this
1283
- // peer.
1284
- uint64_t my_services{pnode.GetLocalServices ()};
1283
+ uint64_t my_services{peer.m_our_services };
1285
1284
const int64_t nTime{count_seconds (GetTime<std::chrono::seconds>())};
1286
1285
uint64_t nonce = pnode.GetLocalNonce ();
1287
1286
const int nNodeStartingHeight{m_best_height};
@@ -2016,7 +2015,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
2016
2015
}
2017
2016
// Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
2018
2017
if (!pfrom.HasPermission (NetPermissionFlags::NoBan) && (
2019
- (((pfrom. GetLocalServices () & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((pfrom. GetLocalServices () & NODE_NETWORK) != NODE_NETWORK) && (m_chainman.ActiveChain ().Tip ()->nHeight - pindex->nHeight > (int )NODE_NETWORK_LIMITED_MIN_BLOCKS + 2 /* add two blocks buffer extension for possible races */ ) )
2018
+ (((peer. m_our_services & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((peer. m_our_services & NODE_NETWORK) != NODE_NETWORK) && (m_chainman.ActiveChain ().Tip ()->nHeight - pindex->nHeight > (int )NODE_NETWORK_LIMITED_MIN_BLOCKS + 2 /* add two blocks buffer extension for possible races */ ) )
2020
2019
)) {
2021
2020
LogPrint (BCLog::NET, " Ignore block request below NODE_NETWORK_LIMITED threshold, disconnect peer=%d\n " , pfrom.GetId ());
2022
2021
// disconnect node and prevent it from stalling (would otherwise wait for the missing block)
@@ -2597,19 +2596,19 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2597
2596
}
2598
2597
}
2599
2598
2600
- bool PeerManagerImpl::PrepareBlockFilterRequest (CNode& peer,
2599
+ bool PeerManagerImpl::PrepareBlockFilterRequest (CNode& node, Peer& peer,
2601
2600
BlockFilterType filter_type, uint32_t start_height,
2602
2601
const uint256& stop_hash, uint32_t max_height_diff,
2603
2602
const CBlockIndex*& stop_index,
2604
2603
BlockFilterIndex*& filter_index)
2605
2604
{
2606
2605
const bool supported_filter_type =
2607
2606
(filter_type == BlockFilterType::BASIC &&
2608
- (peer.GetLocalServices () & NODE_COMPACT_FILTERS));
2607
+ (peer.m_our_services & NODE_COMPACT_FILTERS));
2609
2608
if (!supported_filter_type) {
2610
2609
LogPrint (BCLog::NET, " peer %d requested unsupported block filter type: %d\n " ,
2611
- peer .GetId (), static_cast <uint8_t >(filter_type));
2612
- peer .fDisconnect = true ;
2610
+ node .GetId (), static_cast <uint8_t >(filter_type));
2611
+ node .fDisconnect = true ;
2613
2612
return false ;
2614
2613
}
2615
2614
@@ -2620,8 +2619,8 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
2620
2619
// Check that the stop block exists and the peer would be allowed to fetch it.
2621
2620
if (!stop_index || !BlockRequestAllowed (stop_index)) {
2622
2621
LogPrint (BCLog::NET, " peer %d requested invalid block hash: %s\n " ,
2623
- peer .GetId (), stop_hash.ToString ());
2624
- peer .fDisconnect = true ;
2622
+ node .GetId (), stop_hash.ToString ());
2623
+ node .fDisconnect = true ;
2625
2624
return false ;
2626
2625
}
2627
2626
}
@@ -2630,14 +2629,14 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
2630
2629
if (start_height > stop_height) {
2631
2630
LogPrint (BCLog::NET, " peer %d sent invalid getcfilters/getcfheaders with " /* Continued */
2632
2631
" start height %d and stop height %d\n " ,
2633
- peer .GetId (), start_height, stop_height);
2634
- peer .fDisconnect = true ;
2632
+ node .GetId (), start_height, stop_height);
2633
+ node .fDisconnect = true ;
2635
2634
return false ;
2636
2635
}
2637
2636
if (stop_height - start_height >= max_height_diff) {
2638
2637
LogPrint (BCLog::NET, " peer %d requested too many cfilters/cfheaders: %d / %d\n " ,
2639
- peer .GetId (), stop_height - start_height + 1 , max_height_diff);
2640
- peer .fDisconnect = true ;
2638
+ node .GetId (), stop_height - start_height + 1 , max_height_diff);
2639
+ node .fDisconnect = true ;
2641
2640
return false ;
2642
2641
}
2643
2642
@@ -2650,7 +2649,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
2650
2649
return true ;
2651
2650
}
2652
2651
2653
- void PeerManagerImpl::ProcessGetCFilters (CNode& peer, CDataStream& vRecv)
2652
+ void PeerManagerImpl::ProcessGetCFilters (CNode& node,Peer& peer, CDataStream& vRecv)
2654
2653
{
2655
2654
uint8_t filter_type_ser;
2656
2655
uint32_t start_height;
@@ -2662,7 +2661,7 @@ void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
2662
2661
2663
2662
const CBlockIndex* stop_index;
2664
2663
BlockFilterIndex* filter_index;
2665
- if (!PrepareBlockFilterRequest (peer, filter_type, start_height, stop_hash,
2664
+ if (!PrepareBlockFilterRequest (node, peer, filter_type, start_height, stop_hash,
2666
2665
MAX_GETCFILTERS_SIZE, stop_index, filter_index)) {
2667
2666
return ;
2668
2667
}
@@ -2675,13 +2674,13 @@ void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
2675
2674
}
2676
2675
2677
2676
for (const auto & filter : filters) {
2678
- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2677
+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
2679
2678
.Make (NetMsgType::CFILTER, filter);
2680
- m_connman.PushMessage (&peer , std::move (msg));
2679
+ m_connman.PushMessage (&node , std::move (msg));
2681
2680
}
2682
2681
}
2683
2682
2684
- void PeerManagerImpl::ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv)
2683
+ void PeerManagerImpl::ProcessGetCFHeaders (CNode& node, Peer& peer, CDataStream& vRecv)
2685
2684
{
2686
2685
uint8_t filter_type_ser;
2687
2686
uint32_t start_height;
@@ -2693,7 +2692,7 @@ void PeerManagerImpl::ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv)
2693
2692
2694
2693
const CBlockIndex* stop_index;
2695
2694
BlockFilterIndex* filter_index;
2696
- if (!PrepareBlockFilterRequest (peer, filter_type, start_height, stop_hash,
2695
+ if (!PrepareBlockFilterRequest (node, peer, filter_type, start_height, stop_hash,
2697
2696
MAX_GETCFHEADERS_SIZE, stop_index, filter_index)) {
2698
2697
return ;
2699
2698
}
@@ -2716,16 +2715,16 @@ void PeerManagerImpl::ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv)
2716
2715
return ;
2717
2716
}
2718
2717
2719
- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2718
+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
2720
2719
.Make (NetMsgType::CFHEADERS,
2721
2720
filter_type_ser,
2722
2721
stop_index->GetBlockHash (),
2723
2722
prev_header,
2724
2723
filter_hashes);
2725
- m_connman.PushMessage (&peer , std::move (msg));
2724
+ m_connman.PushMessage (&node , std::move (msg));
2726
2725
}
2727
2726
2728
- void PeerManagerImpl::ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv)
2727
+ void PeerManagerImpl::ProcessGetCFCheckPt (CNode& node, Peer& peer, CDataStream& vRecv)
2729
2728
{
2730
2729
uint8_t filter_type_ser;
2731
2730
uint256 stop_hash;
@@ -2736,7 +2735,7 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
2736
2735
2737
2736
const CBlockIndex* stop_index;
2738
2737
BlockFilterIndex* filter_index;
2739
- if (!PrepareBlockFilterRequest (peer, filter_type, /* start_height=*/ 0 , stop_hash,
2738
+ if (!PrepareBlockFilterRequest (node, peer, filter_type, /* start_height=*/ 0 , stop_hash,
2740
2739
/* max_height_diff=*/ std::numeric_limits<uint32_t >::max (),
2741
2740
stop_index, filter_index)) {
2742
2741
return ;
@@ -2757,12 +2756,12 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
2757
2756
}
2758
2757
}
2759
2758
2760
- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2759
+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
2761
2760
.Make (NetMsgType::CFCHECKPT,
2762
2761
filter_type_ser,
2763
2762
stop_index->GetBlockHash (),
2764
2763
headers);
2765
- m_connman.PushMessage (&peer , std::move (msg));
2764
+ m_connman.PushMessage (&node , std::move (msg));
2766
2765
}
2767
2766
2768
2767
void PeerManagerImpl::ProcessBlock (CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing)
@@ -2898,7 +2897,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
2898
2897
// - fRelay=true or we're offering NODE_BLOOM to this peer
2899
2898
// (NODE_BLOOM means that the peer may turn on tx relay later)
2900
2899
if (!pfrom.IsBlockOnlyConn () &&
2901
- (fRelay || (pfrom. GetLocalServices () & NODE_BLOOM))) {
2900
+ (fRelay || (peer-> m_our_services & NODE_BLOOM))) {
2902
2901
auto * const tx_relay = peer->SetTxRelay ();
2903
2902
{
2904
2903
LOCK (tx_relay->m_bloom_filter_mutex );
@@ -4092,7 +4091,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4092
4091
}
4093
4092
4094
4093
if (msg_type == NetMsgType::MEMPOOL) {
4095
- if (!(pfrom. GetLocalServices () & NODE_BLOOM) && !pfrom.HasPermission (NetPermissionFlags::Mempool))
4094
+ if (!(peer-> m_our_services & NODE_BLOOM) && !pfrom.HasPermission (NetPermissionFlags::Mempool))
4096
4095
{
4097
4096
if (!pfrom.HasPermission (NetPermissionFlags::NoBan))
4098
4097
{
@@ -4195,7 +4194,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4195
4194
}
4196
4195
4197
4196
if (msg_type == NetMsgType::FILTERLOAD) {
4198
- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4197
+ if (!(peer-> m_our_services & NODE_BLOOM)) {
4199
4198
LogPrint (BCLog::NET, " filterload received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
4200
4199
pfrom.fDisconnect = true ;
4201
4200
return ;
@@ -4220,7 +4219,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4220
4219
}
4221
4220
4222
4221
if (msg_type == NetMsgType::FILTERADD) {
4223
- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4222
+ if (!(peer-> m_our_services & NODE_BLOOM)) {
4224
4223
LogPrint (BCLog::NET, " filteradd received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
4225
4224
pfrom.fDisconnect = true ;
4226
4225
return ;
@@ -4248,7 +4247,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4248
4247
}
4249
4248
4250
4249
if (msg_type == NetMsgType::FILTERCLEAR) {
4251
- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4250
+ if (!(peer-> m_our_services & NODE_BLOOM)) {
4252
4251
LogPrint (BCLog::NET, " filterclear received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
4253
4252
pfrom.fDisconnect = true ;
4254
4253
return ;
@@ -4279,17 +4278,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4279
4278
}
4280
4279
4281
4280
if (msg_type == NetMsgType::GETCFILTERS) {
4282
- ProcessGetCFilters (pfrom, vRecv);
4281
+ ProcessGetCFilters (pfrom, *peer, vRecv);
4283
4282
return ;
4284
4283
}
4285
4284
4286
4285
if (msg_type == NetMsgType::GETCFHEADERS) {
4287
- ProcessGetCFHeaders (pfrom, vRecv);
4286
+ ProcessGetCFHeaders (pfrom, *peer, vRecv);
4288
4287
return ;
4289
4288
}
4290
4289
4291
4290
if (msg_type == NetMsgType::GETCFCHECKPT) {
4292
- ProcessGetCFCheckPt (pfrom, vRecv);
4291
+ ProcessGetCFCheckPt (pfrom, *peer, vRecv);
4293
4292
return ;
4294
4293
}
4295
4294
0 commit comments