mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
[net] remove fUpdateConnectionTime from FinalizeNode
PeerManager can just call directly into CAddrMan::Connected() now.
This commit is contained in:
parent
7c4cc67c0c
commit
3fc06d3d7b
4 changed files with 19 additions and 25 deletions
|
@ -2621,11 +2621,7 @@ void CConnman::StopNodes()
|
|||
void CConnman::DeleteNode(CNode* pnode)
|
||||
{
|
||||
assert(pnode);
|
||||
bool fUpdateConnectionTime = false;
|
||||
m_msgproc->FinalizeNode(*pnode, fUpdateConnectionTime);
|
||||
if (fUpdateConnectionTime) {
|
||||
addrman.Connected(pnode->addr);
|
||||
}
|
||||
m_msgproc->FinalizeNode(*pnode);
|
||||
delete pnode;
|
||||
}
|
||||
|
||||
|
|
|
@ -770,7 +770,7 @@ public:
|
|||
virtual void InitializeNode(CNode* pnode) = 0;
|
||||
|
||||
/** Handle removal of a peer (clear state) */
|
||||
virtual void FinalizeNode(const CNode& node, bool& update_connection_time) = 0;
|
||||
virtual void FinalizeNode(const CNode& node) = 0;
|
||||
|
||||
/**
|
||||
* Process protocol messages received from a given node
|
||||
|
|
|
@ -238,7 +238,7 @@ public:
|
|||
|
||||
/** Implement NetEventsInterface */
|
||||
void InitializeNode(CNode* pnode) override;
|
||||
void FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) override;
|
||||
void FinalizeNode(const CNode& node) override;
|
||||
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
|
||||
bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
|
||||
|
||||
|
@ -969,12 +969,12 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
|
|||
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
|
||||
}
|
||||
|
||||
void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime)
|
||||
void PeerManagerImpl::FinalizeNode(const CNode& node)
|
||||
{
|
||||
NodeId nodeid = node.GetId();
|
||||
fUpdateConnectionTime = false;
|
||||
LOCK(cs_main);
|
||||
int misbehavior{0};
|
||||
{
|
||||
LOCK(cs_main);
|
||||
{
|
||||
// We remove the PeerRef from g_peer_map here, but we don't always
|
||||
// destruct the Peer. Sometimes another thread is still holding a
|
||||
|
@ -991,12 +991,6 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
|
|||
if (state->fSyncStarted)
|
||||
nSyncStarted--;
|
||||
|
||||
if (node.fSuccessfullyConnected && misbehavior == 0 &&
|
||||
!node.IsBlockOnlyConn() && !node.IsInboundConn()) {
|
||||
// Only change visible addrman state for outbound, full-relay peers
|
||||
fUpdateConnectionTime = true;
|
||||
}
|
||||
|
||||
for (const QueuedBlock& entry : state->vBlocksInFlight) {
|
||||
mapBlocksInFlight.erase(entry.hash);
|
||||
}
|
||||
|
@ -1021,6 +1015,14 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
|
|||
assert(m_wtxid_relay_peers == 0);
|
||||
assert(m_txrequest.Size() == 0);
|
||||
}
|
||||
} // cs_main
|
||||
if (node.fSuccessfullyConnected && misbehavior == 0 &&
|
||||
!node.IsBlockOnlyConn() && !node.IsInboundConn()) {
|
||||
// Only change visible addrman state for full outbound peers. We don't
|
||||
// call Connected() for feeler connections since they don't have
|
||||
// fSuccessfullyConnected set.
|
||||
m_addrman.Connected(node.addr);
|
||||
}
|
||||
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid);
|
||||
}
|
||||
|
||||
|
|
|
@ -117,8 +117,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
|||
BOOST_CHECK(dummyNode1.fDisconnect == true);
|
||||
SetMockTime(0);
|
||||
|
||||
bool dummy;
|
||||
peerLogic->FinalizeNode(dummyNode1, dummy);
|
||||
peerLogic->FinalizeNode(dummyNode1);
|
||||
}
|
||||
|
||||
static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &peerLogic, CConnmanTest* connman)
|
||||
|
@ -199,9 +198,8 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
|||
BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
|
||||
BOOST_CHECK(vNodes.back()->fDisconnect == false);
|
||||
|
||||
bool dummy;
|
||||
for (const CNode *node : vNodes) {
|
||||
peerLogic->FinalizeNode(*node, dummy);
|
||||
peerLogic->FinalizeNode(*node);
|
||||
}
|
||||
|
||||
connman->ClearNodes();
|
||||
|
@ -249,9 +247,8 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
|||
BOOST_CHECK(banman->IsDiscouraged(addr1)); // Expect both 1 and 2
|
||||
BOOST_CHECK(banman->IsDiscouraged(addr2)); // to be discouraged now
|
||||
|
||||
bool dummy;
|
||||
peerLogic->FinalizeNode(dummyNode1, dummy);
|
||||
peerLogic->FinalizeNode(dummyNode2, dummy);
|
||||
peerLogic->FinalizeNode(dummyNode1);
|
||||
peerLogic->FinalizeNode(dummyNode2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||
|
@ -279,8 +276,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
|||
}
|
||||
BOOST_CHECK(banman->IsDiscouraged(addr));
|
||||
|
||||
bool dummy;
|
||||
peerLogic->FinalizeNode(dummyNode, dummy);
|
||||
peerLogic->FinalizeNode(dummyNode);
|
||||
}
|
||||
|
||||
class TxOrphanageTest : public TxOrphanage
|
||||
|
|
Loading…
Add table
Reference in a new issue