@@ -422,58 +422,6 @@ static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
422
422
return &it->second ;
423
423
}
424
424
425
- /* *
426
- * Data structure for an individual peer. This struct is not protected by
427
- * cs_main since it does not contain validation-critical data.
428
- *
429
- * Memory is owned by shared pointers and this object is destructed when
430
- * the refcount drops to zero.
431
- *
432
- * TODO: move most members from CNodeState to this structure.
433
- * TODO: move remaining application-layer data members from CNode to this structure.
434
- */
435
- struct Peer {
436
- /* * Same id as the CNode object for this peer */
437
- const NodeId m_id{0 };
438
-
439
- /* * Protects misbehavior data members */
440
- Mutex m_misbehavior_mutex;
441
- /* * Accumulated misbehavior score for this peer */
442
- int m_misbehavior_score GUARDED_BY (m_misbehavior_mutex){0 };
443
- /* * Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
444
- bool m_should_discourage GUARDED_BY (m_misbehavior_mutex){false };
445
-
446
- /* * Set of txids to reconsider once their parent transactions have been accepted **/
447
- std::set<uint256> m_orphan_work_set GUARDED_BY (g_cs_orphans);
448
-
449
- /* * Protects m_getdata_requests **/
450
- Mutex m_getdata_requests_mutex;
451
- /* * Work queue of items requested by this peer **/
452
- std::deque<CInv> m_getdata_requests GUARDED_BY (m_getdata_requests_mutex);
453
-
454
- explicit Peer (NodeId id) : m_id(id) {}
455
- };
456
-
457
- using PeerRef = std::shared_ptr<Peer>;
458
-
459
- /* *
460
- * Map of all Peer objects, keyed by peer id. This map is protected
461
- * by the global g_peer_mutex. Once a shared pointer reference is
462
- * taken, the lock may be released. Individual fields are protected by
463
- * their own locks.
464
- */
465
- Mutex g_peer_mutex;
466
- static std::map<NodeId, PeerRef> g_peer_map GUARDED_BY (g_peer_mutex);
467
-
468
- /* * Get a shared pointer to the Peer object.
469
- * May return nullptr if the Peer object can't be found. */
470
- static PeerRef GetPeerRef (NodeId id)
471
- {
472
- LOCK (g_peer_mutex);
473
- auto it = g_peer_map.find (id);
474
- return it != g_peer_map.end () ? it->second : nullptr ;
475
- }
476
-
477
425
static void UpdatePreferredDownload (const CNode& node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
478
426
{
479
427
nPreferredDownload -= state->fPreferredDownload ;
@@ -807,8 +755,8 @@ void PeerManager::InitializeNode(CNode *pnode) {
807
755
}
808
756
{
809
757
PeerRef peer = std::make_shared<Peer>(nodeid);
810
- LOCK (g_peer_mutex );
811
- g_peer_map .emplace_hint (g_peer_map .end (), nodeid, std::move (peer));
758
+ LOCK (m_peer_mutex );
759
+ m_peer_map .emplace_hint (m_peer_map .end (), nodeid, std::move (peer));
812
760
}
813
761
if (!pnode->IsInboundConn ()) {
814
762
PushNodeVersion (*pnode, m_connman, GetTime ());
@@ -845,8 +793,8 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
845
793
PeerRef peer = GetPeerRef (nodeid);
846
794
assert (peer != nullptr );
847
795
misbehavior = WITH_LOCK (peer->m_misbehavior_mutex , return peer->m_misbehavior_score );
848
- LOCK (g_peer_mutex );
849
- g_peer_map .erase (nodeid);
796
+ LOCK (m_peer_mutex );
797
+ m_peer_map .erase (nodeid);
850
798
}
851
799
CNodeState *state = State (nodeid);
852
800
assert (state != nullptr );
@@ -887,6 +835,13 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
887
835
LogPrint (BCLog::NET, " Cleared nodestate for peer=%d\n " , nodeid);
888
836
}
889
837
838
+ PeerRef PeerManager::GetPeerRef (NodeId id)
839
+ {
840
+ LOCK (m_peer_mutex);
841
+ auto it = m_peer_map.find (id);
842
+ return it != m_peer_map.end () ? it->second : nullptr ;
843
+ }
844
+
890
845
bool PeerManager::GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats) {
891
846
{
892
847
LOCK (cs_main);
0 commit comments