aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2022-02-20 15:20:15 +0100
committerdergoegge <n.goeggi@gmail.com>2022-04-20 13:33:07 +0200
commita292df283a596efe7e1d40c33a6d614d70ed564d (patch)
treeb271d4c3d422fc17a0904723b8fcd6c9079c7e69 /src/net_processing.cpp
parent37ecaf3e7a028486a0a1c9b717e8eb4214215805 (diff)
[net processing] Move mapNodeState into PeerManagerImpl
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index e0173a73dc..57fa3b1fad 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -462,6 +462,7 @@ public:
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override;
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
+ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) override;
private:
/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
@@ -580,6 +581,16 @@ private:
*/
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
+ /** Map maintaining per-node state. */
+ std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
+
+ /** Get a pointer to a const CNodeState, used when not mutating the CNodeState object. */
+ const CNodeState* State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+ /** Get a pointer to a mutable CNodeState. */
+ CNodeState* State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+
+ uint32_t GetFetchFlags(const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+
std::atomic<std::chrono::microseconds> m_next_inv_to_inbounds{0us};
/** Number of nodes with fSyncStarted. */
@@ -815,16 +826,19 @@ namespace {
namespace {
-/** Map maintaining per-node state. */
-static std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
-
-static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
- std::map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode);
+const CNodeState* PeerManagerImpl::State(NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
+{
+ std::map<NodeId, CNodeState>::const_iterator it = mapNodeState.find(pnode);
if (it == mapNodeState.end())
return nullptr;
return &it->second;
}
+CNodeState* PeerManagerImpl::State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
+{
+ return const_cast<CNodeState*>(std::as_const(*this).State(pnode));
+}
+
/**
* Whether the peer supports the address. For example, a peer that does not
* implement BIP155 cannot receive Tor v3 addresses because it requires
@@ -1214,9 +1228,7 @@ void PeerManagerImpl::AddTxAnnouncement(const CNode& node, const GenTxid& gtxid,
m_txrequest.ReceivedInv(nodeid, gtxid, preferred, current_time + delay);
}
-// This function is used for testing the stale tip eviction logic, see
-// denialofservice_tests.cpp
-void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
+void PeerManagerImpl::UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
{
LOCK(cs_main);
CNodeState *state = State(node);
@@ -1342,7 +1354,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
{
{
LOCK(cs_main);
- CNodeState* state = State(nodeid);
+ const CNodeState* state = State(nodeid);
if (state == nullptr)
return false;
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
@@ -2122,7 +2134,8 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
}
}
-static uint32_t GetFetchFlags(const CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
+uint32_t PeerManagerImpl::GetFetchFlags(const CNode& pfrom) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
+{
uint32_t nFetchFlags = 0;
if (State(pfrom.GetId())->fHaveWitness) {
nFetchFlags |= MSG_WITNESS_FLAG;