@@ -462,6 +462,7 @@ class PeerManagerImpl final : public PeerManager
462
462
void Misbehaving (const NodeId pnode, const int howmuch, const std::string& message) override ;
463
463
void ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
464
464
const std::chrono::microseconds time_received, const std::atomic<bool >& interruptMsgProc) override ;
465
+ void UpdateLastBlockAnnounceTime (NodeId node, int64_t time_in_seconds) override ;
465
466
466
467
private:
467
468
/* * Consider evicting an outbound peer based on the amount of time they've been behind our tip */
@@ -580,6 +581,16 @@ class PeerManagerImpl final : public PeerManager
580
581
*/
581
582
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY (m_peer_mutex);
582
583
584
+ /* * Map maintaining per-node state. */
585
+ std::map<NodeId, CNodeState> mapNodeState GUARDED_BY (cs_main);
586
+
587
+ /* * Get a pointer to a const CNodeState, used when not mutating the CNodeState object. */
588
+ const CNodeState* State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
589
+ /* * Get a pointer to a mutable CNodeState. */
590
+ CNodeState* State (NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
591
+
592
+ uint32_t GetFetchFlags (const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
593
+
583
594
std::atomic<std::chrono::microseconds> m_next_inv_to_inbounds{0us};
584
595
585
596
/* * Number of nodes with fSyncStarted. */
@@ -815,16 +826,19 @@ namespace {
815
826
816
827
namespace {
817
828
818
- /* * Map maintaining per-node state. */
819
- static std::map<NodeId, CNodeState> mapNodeState GUARDED_BY (cs_main);
820
-
821
- static CNodeState *State (NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
822
- std::map<NodeId, CNodeState>::iterator it = mapNodeState.find (pnode);
829
+ const CNodeState* PeerManagerImpl::State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
830
+ {
831
+ std::map<NodeId, CNodeState>::const_iterator it = mapNodeState.find (pnode);
823
832
if (it == mapNodeState.end ())
824
833
return nullptr ;
825
834
return &it->second ;
826
835
}
827
836
837
+ CNodeState* PeerManagerImpl::State (NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
838
+ {
839
+ return const_cast <CNodeState*>(std::as_const (*this ).State (pnode));
840
+ }
841
+
828
842
/* *
829
843
* Whether the peer supports the address. For example, a peer that does not
830
844
* implement BIP155 cannot receive Tor v3 addresses because it requires
@@ -1214,9 +1228,7 @@ void PeerManagerImpl::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid,
1214
1228
m_txrequest.ReceivedInv (nodeid, gtxid, preferred, current_time + delay);
1215
1229
}
1216
1230
1217
- // This function is used for testing the stale tip eviction logic, see
1218
- // denialofservice_tests.cpp
1219
- void UpdateLastBlockAnnounceTime (NodeId node, int64_t time_in_seconds)
1231
+ void PeerManagerImpl::UpdateLastBlockAnnounceTime (NodeId node, int64_t time_in_seconds)
1220
1232
{
1221
1233
LOCK (cs_main);
1222
1234
CNodeState *state = State (node);
@@ -1342,7 +1354,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
1342
1354
{
1343
1355
{
1344
1356
LOCK (cs_main);
1345
- CNodeState* state = State (nodeid);
1357
+ const CNodeState* state = State (nodeid);
1346
1358
if (state == nullptr )
1347
1359
return false ;
1348
1360
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock ->nHeight : -1 ;
@@ -2122,7 +2134,8 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
2122
2134
}
2123
2135
}
2124
2136
2125
- static uint32_t GetFetchFlags (const CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
2137
+ uint32_t PeerManagerImpl::GetFetchFlags (const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
2138
+ {
2126
2139
uint32_t nFetchFlags = 0 ;
2127
2140
if (State (pfrom.GetId ())->fHaveWitness ) {
2128
2141
nFetchFlags |= MSG_WITNESS_FLAG;
0 commit comments