Skip to content

Commit eefe194

Browse files
committed
[net] Consolidate logic around calling CAddrMan::Connected()
Currently, the logic around whether we called CAddrMan::Connected() for a peer is spread between verack processing (where we discard inbound peers) and FinalizeNode (where we discard misbehaving and block-relay-only peers). Consolidate that logic to a single place. Also remove the CNode.fCurrentlyConnected bool, which is now redundant. We can rely on CNode.fSuccessfullyConnected, since the two bools were only ever flipped to true in the same place.
1 parent 5174b53 commit eefe194

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ namespace {
290290
struct CNodeState {
291291
//! The peer's address
292292
const CService address;
293-
//! Whether we have a fully established connection.
294-
bool fCurrentlyConnected;
295293
//! The best known block we know this peer has announced.
296294
const CBlockIndex *pindexBestKnownBlock;
297295
//! The hash of the last unknown block this peer has announced.
@@ -390,7 +388,6 @@ struct CNodeState {
390388
CNodeState(CAddress addrIn, bool is_inbound, bool is_manual)
391389
: address(addrIn), m_is_inbound(is_inbound), m_is_manual_connection(is_manual)
392390
{
393-
fCurrentlyConnected = false;
394391
pindexBestKnownBlock = nullptr;
395392
hashLastUnknownBlock.SetNull();
396393
pindexLastCommonBlock = nullptr;
@@ -855,8 +852,9 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
855852
if (state->fSyncStarted)
856853
nSyncStarted--;
857854

858-
if (misbehavior == 0 && state->fCurrentlyConnected && !node.IsBlockOnlyConn()) {
859-
// Note: we avoid changing visible addrman state for block-relay-only peers
855+
if (node.fSuccessfullyConnected && misbehavior == 0 &&
856+
!node.IsBlockOnlyConn() && !node.IsInboundConn()) {
857+
// Only change visible addrman state for outbound, full-relay peers
860858
fUpdateConnectionTime = true;
861859
}
862860

@@ -2486,9 +2484,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24862484
if (pfrom.fSuccessfullyConnected) return;
24872485

24882486
if (!pfrom.IsInboundConn()) {
2489-
// Mark this node as currently connected, so we update its timestamp later.
2490-
LOCK(cs_main);
2491-
State(pfrom.GetId())->fCurrentlyConnected = true;
24922487
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
24932488
pfrom.nVersion.load(), pfrom.nStartingHeight,
24942489
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""),

0 commit comments

Comments
 (0)