mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
[net processing] Add RemovePeer()
This allows us to avoid repeated locking in FinalizeNode()
This commit is contained in:
parent
a20ab22786
commit
3025ca9e77
@ -790,11 +790,9 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
int misbehavior{0};
|
int misbehavior{0};
|
||||||
{
|
{
|
||||||
PeerRef peer = GetPeerRef(nodeid);
|
PeerRef peer = RemovePeer(nodeid);
|
||||||
assert(peer != nullptr);
|
assert(peer != nullptr);
|
||||||
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
||||||
LOCK(m_peer_mutex);
|
|
||||||
m_peer_map.erase(nodeid);
|
|
||||||
}
|
}
|
||||||
CNodeState *state = State(nodeid);
|
CNodeState *state = State(nodeid);
|
||||||
assert(state != nullptr);
|
assert(state != nullptr);
|
||||||
@ -842,6 +840,18 @@ PeerRef PeerManager::GetPeerRef(NodeId id) const
|
|||||||
return it != m_peer_map.end() ? it->second : nullptr;
|
return it != m_peer_map.end() ? it->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PeerRef PeerManager::RemovePeer(NodeId id)
|
||||||
|
{
|
||||||
|
PeerRef ret;
|
||||||
|
LOCK(m_peer_mutex);
|
||||||
|
auto it = m_peer_map.find(id);
|
||||||
|
if (it != m_peer_map.end()) {
|
||||||
|
ret = std::move(it->second);
|
||||||
|
m_peer_map.erase(it);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
|
bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
@ -143,6 +143,10 @@ private:
|
|||||||
* May return an empty shared_ptr if the Peer object can't be found. */
|
* May return an empty shared_ptr if the Peer object can't be found. */
|
||||||
PeerRef GetPeerRef(NodeId id) const;
|
PeerRef GetPeerRef(NodeId id) const;
|
||||||
|
|
||||||
|
/** Get a shared pointer to the Peer object and remove it from m_peer_map.
|
||||||
|
* May return an empty shared_ptr if the Peer object can't be found. */
|
||||||
|
PeerRef RemovePeer(NodeId id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Potentially mark a node discouraged based on the contents of a BlockValidationState object
|
* Potentially mark a node discouraged based on the contents of a BlockValidationState object
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user