@@ -219,9 +219,7 @@ struct Peer {
219219 * to serve, but still advertises NODE_NETWORK because it will eventually
220220 * fulfill this role after IBD completes. P2P code is written in such a
221221 * 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. */
225223 const ServiceFlags m_our_services;
226224 /* * Services this peer offered to us. */
227225 std::atomic<ServiceFlags> m_their_services{NODE_NONE};
@@ -867,6 +865,7 @@ class PeerManagerImpl final : public PeerManager
867865 *
868866 * May disconnect from the peer in the case of a bad request.
869867 *
868+ * @param[in] node The node that we received the request from
870869 * @param[in] peer The peer that we received the request from
871870 * @param[in] filter_type The filter type the request is for. Must be basic filters.
872871 * @param[in] start_height The start height for the request
@@ -876,7 +875,7 @@ class PeerManagerImpl final : public PeerManager
876875 * @param[out] filter_index The filter index, if the request can be serviced.
877876 * @return True if the request can be serviced.
878877 */
879- bool PrepareBlockFilterRequest (CNode& peer,
878+ bool PrepareBlockFilterRequest (CNode& node, Peer& peer,
880879 BlockFilterType filter_type, uint32_t start_height,
881880 const uint256& stop_hash, uint32_t max_height_diff,
882881 const CBlockIndex*& stop_index,
@@ -887,30 +886,33 @@ class PeerManagerImpl final : public PeerManager
887886 *
888887 * May disconnect from the peer in the case of a bad request.
889888 *
889+ * @param[in] node The node that we received the request from
890890 * @param[in] peer The peer that we received the request from
891891 * @param[in] vRecv The raw message received
892892 */
893- void ProcessGetCFilters (CNode& peer, CDataStream& vRecv);
893+ void ProcessGetCFilters (CNode& node, Peer& peer, CDataStream& vRecv);
894894
895895 /* *
896896 * Handle a cfheaders request.
897897 *
898898 * May disconnect from the peer in the case of a bad request.
899899 *
900+ * @param[in] node The node that we received the request from
900901 * @param[in] peer The peer that we received the request from
901902 * @param[in] vRecv The raw message received
902903 */
903- void ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv);
904+ void ProcessGetCFHeaders (CNode& node, Peer& peer, CDataStream& vRecv);
904905
905906 /* *
906907 * Handle a getcfcheckpt request.
907908 *
908909 * May disconnect from the peer in the case of a bad request.
909910 *
911+ * @param[in] node The node that we received the request from
910912 * @param[in] peer The peer that we received the request from
911913 * @param[in] vRecv The raw message received
912914 */
913- void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv);
915+ void ProcessGetCFCheckPt (CNode& node, Peer& peer, CDataStream& vRecv);
914916
915917 /* * Checks if address relay is permitted with peer. If needed, initializes
916918 * 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
12781280
12791281void PeerManagerImpl::PushNodeVersion (CNode& pnode, const Peer& peer)
12801282{
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 };
12851284 const int64_t nTime{count_seconds (GetTime<std::chrono::seconds>())};
12861285 uint64_t nonce = pnode.GetLocalNonce ();
12871286 const int nNodeStartingHeight{m_best_height};
@@ -2016,7 +2015,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
20162015 }
20172016 // Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
20182017 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 */ ) )
20202019 )) {
20212020 LogPrint (BCLog::NET, " Ignore block request below NODE_NETWORK_LIMITED threshold, disconnect peer=%d\n " , pfrom.GetId ());
20222021 // 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)
25972596 }
25982597}
25992598
2600- bool PeerManagerImpl::PrepareBlockFilterRequest (CNode& peer,
2599+ bool PeerManagerImpl::PrepareBlockFilterRequest (CNode& node, Peer& peer,
26012600 BlockFilterType filter_type, uint32_t start_height,
26022601 const uint256& stop_hash, uint32_t max_height_diff,
26032602 const CBlockIndex*& stop_index,
26042603 BlockFilterIndex*& filter_index)
26052604{
26062605 const bool supported_filter_type =
26072606 (filter_type == BlockFilterType::BASIC &&
2608- (peer.GetLocalServices () & NODE_COMPACT_FILTERS));
2607+ (peer.m_our_services & NODE_COMPACT_FILTERS));
26092608 if (!supported_filter_type) {
26102609 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 ;
26132612 return false ;
26142613 }
26152614
@@ -2620,8 +2619,8 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
26202619 // Check that the stop block exists and the peer would be allowed to fetch it.
26212620 if (!stop_index || !BlockRequestAllowed (stop_index)) {
26222621 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 ;
26252624 return false ;
26262625 }
26272626 }
@@ -2630,14 +2629,14 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
26302629 if (start_height > stop_height) {
26312630 LogPrint (BCLog::NET, " peer %d sent invalid getcfilters/getcfheaders with " /* Continued */
26322631 " 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 ;
26352634 return false ;
26362635 }
26372636 if (stop_height - start_height >= max_height_diff) {
26382637 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 ;
26412640 return false ;
26422641 }
26432642
@@ -2650,7 +2649,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
26502649 return true ;
26512650}
26522651
2653- void PeerManagerImpl::ProcessGetCFilters (CNode& peer, CDataStream& vRecv)
2652+ void PeerManagerImpl::ProcessGetCFilters (CNode& node,Peer& peer, CDataStream& vRecv)
26542653{
26552654 uint8_t filter_type_ser;
26562655 uint32_t start_height;
@@ -2662,7 +2661,7 @@ void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
26622661
26632662 const CBlockIndex* stop_index;
26642663 BlockFilterIndex* filter_index;
2665- if (!PrepareBlockFilterRequest (peer, filter_type, start_height, stop_hash,
2664+ if (!PrepareBlockFilterRequest (node, peer, filter_type, start_height, stop_hash,
26662665 MAX_GETCFILTERS_SIZE, stop_index, filter_index)) {
26672666 return ;
26682667 }
@@ -2675,13 +2674,13 @@ void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
26752674 }
26762675
26772676 for (const auto & filter : filters) {
2678- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2677+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
26792678 .Make (NetMsgType::CFILTER, filter);
2680- m_connman.PushMessage (&peer , std::move (msg));
2679+ m_connman.PushMessage (&node , std::move (msg));
26812680 }
26822681}
26832682
2684- void PeerManagerImpl::ProcessGetCFHeaders (CNode& peer, CDataStream& vRecv)
2683+ void PeerManagerImpl::ProcessGetCFHeaders (CNode& node, Peer& peer, CDataStream& vRecv)
26852684{
26862685 uint8_t filter_type_ser;
26872686 uint32_t start_height;
@@ -2693,7 +2692,7 @@ void PeerManagerImpl::ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv)
26932692
26942693 const CBlockIndex* stop_index;
26952694 BlockFilterIndex* filter_index;
2696- if (!PrepareBlockFilterRequest (peer, filter_type, start_height, stop_hash,
2695+ if (!PrepareBlockFilterRequest (node, peer, filter_type, start_height, stop_hash,
26972696 MAX_GETCFHEADERS_SIZE, stop_index, filter_index)) {
26982697 return ;
26992698 }
@@ -2716,16 +2715,16 @@ void PeerManagerImpl::ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv)
27162715 return ;
27172716 }
27182717
2719- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2718+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
27202719 .Make (NetMsgType::CFHEADERS,
27212720 filter_type_ser,
27222721 stop_index->GetBlockHash (),
27232722 prev_header,
27242723 filter_hashes);
2725- m_connman.PushMessage (&peer , std::move (msg));
2724+ m_connman.PushMessage (&node , std::move (msg));
27262725}
27272726
2728- void PeerManagerImpl::ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv)
2727+ void PeerManagerImpl::ProcessGetCFCheckPt (CNode& node, Peer& peer, CDataStream& vRecv)
27292728{
27302729 uint8_t filter_type_ser;
27312730 uint256 stop_hash;
@@ -2736,7 +2735,7 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
27362735
27372736 const CBlockIndex* stop_index;
27382737 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,
27402739 /* max_height_diff=*/ std::numeric_limits<uint32_t >::max (),
27412740 stop_index, filter_index)) {
27422741 return ;
@@ -2757,12 +2756,12 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
27572756 }
27582757 }
27592758
2760- CSerializedNetMsg msg = CNetMsgMaker (peer .GetCommonVersion ())
2759+ CSerializedNetMsg msg = CNetMsgMaker (node .GetCommonVersion ())
27612760 .Make (NetMsgType::CFCHECKPT,
27622761 filter_type_ser,
27632762 stop_index->GetBlockHash (),
27642763 headers);
2765- m_connman.PushMessage (&peer , std::move (msg));
2764+ m_connman.PushMessage (&node , std::move (msg));
27662765}
27672766
27682767void 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,
28982897 // - fRelay=true or we're offering NODE_BLOOM to this peer
28992898 // (NODE_BLOOM means that the peer may turn on tx relay later)
29002899 if (!pfrom.IsBlockOnlyConn () &&
2901- (fRelay || (pfrom. GetLocalServices () & NODE_BLOOM))) {
2900+ (fRelay || (peer-> m_our_services & NODE_BLOOM))) {
29022901 auto * const tx_relay = peer->SetTxRelay ();
29032902 {
29042903 LOCK (tx_relay->m_bloom_filter_mutex );
@@ -4092,7 +4091,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
40924091 }
40934092
40944093 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))
40964095 {
40974096 if (!pfrom.HasPermission (NetPermissionFlags::NoBan))
40984097 {
@@ -4195,7 +4194,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
41954194 }
41964195
41974196 if (msg_type == NetMsgType::FILTERLOAD) {
4198- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4197+ if (!(peer-> m_our_services & NODE_BLOOM)) {
41994198 LogPrint (BCLog::NET, " filterload received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
42004199 pfrom.fDisconnect = true ;
42014200 return ;
@@ -4220,7 +4219,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42204219 }
42214220
42224221 if (msg_type == NetMsgType::FILTERADD) {
4223- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4222+ if (!(peer-> m_our_services & NODE_BLOOM)) {
42244223 LogPrint (BCLog::NET, " filteradd received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
42254224 pfrom.fDisconnect = true ;
42264225 return ;
@@ -4248,7 +4247,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42484247 }
42494248
42504249 if (msg_type == NetMsgType::FILTERCLEAR) {
4251- if (!(pfrom. GetLocalServices () & NODE_BLOOM)) {
4250+ if (!(peer-> m_our_services & NODE_BLOOM)) {
42524251 LogPrint (BCLog::NET, " filterclear received despite not offering bloom services from peer=%d; disconnecting\n " , pfrom.GetId ());
42534252 pfrom.fDisconnect = true ;
42544253 return ;
@@ -4279,17 +4278,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42794278 }
42804279
42814280 if (msg_type == NetMsgType::GETCFILTERS) {
4282- ProcessGetCFilters (pfrom, vRecv);
4281+ ProcessGetCFilters (pfrom, *peer, vRecv);
42834282 return ;
42844283 }
42854284
42864285 if (msg_type == NetMsgType::GETCFHEADERS) {
4287- ProcessGetCFHeaders (pfrom, vRecv);
4286+ ProcessGetCFHeaders (pfrom, *peer, vRecv);
42884287 return ;
42894288 }
42904289
42914290 if (msg_type == NetMsgType::GETCFCHECKPT) {
4292- ProcessGetCFCheckPt (pfrom, vRecv);
4291+ ProcessGetCFCheckPt (pfrom, *peer, vRecv);
42934292 return ;
42944293 }
42954294
0 commit comments