Before this change the code used to count references to CNode
objects manually via CNode::nRefCount
. Unneeded CNode
s were scheduled for deletion by putting them in CConnman::m_nodes_disconnected
and were deleted after their reference count reached zero. Deleting consists of calling PeerManager::FinalizeNode()
and destroying the CNode
object.
Replace this scheme with std::shared_ptr
. This simplifies the code and removes:
CNode::nRefCount
CNode::GetRefCount()
CNode::AddRef()
CNode::Release()
CConnman::m_nodes_disconnected
CConnman::NodesSnapshot
Now creating a snapshot of CConnman::m_nodes
is done by simply copying it (under the mutex).
Call PeerManager::FinalizeNode()
from the destructor of CNode
, which is called when the reference count reaches 0.
This has some history in #28222 and #10738. See below #32015 (comment) and #32015 (comment).