[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.
pull/679/head
John Newbery 4 years ago
parent 5174b534da
commit eefe194718

@ -290,8 +290,6 @@ namespace {
struct CNodeState { struct CNodeState {
//! The peer's address //! The peer's address
const CService address; const CService address;
//! Whether we have a fully established connection.
bool fCurrentlyConnected;
//! The best known block we know this peer has announced. //! The best known block we know this peer has announced.
const CBlockIndex *pindexBestKnownBlock; const CBlockIndex *pindexBestKnownBlock;
//! The hash of the last unknown block this peer has announced. //! The hash of the last unknown block this peer has announced.
@ -390,7 +388,6 @@ struct CNodeState {
CNodeState(CAddress addrIn, bool is_inbound, bool is_manual) CNodeState(CAddress addrIn, bool is_inbound, bool is_manual)
: address(addrIn), m_is_inbound(is_inbound), m_is_manual_connection(is_manual) : address(addrIn), m_is_inbound(is_inbound), m_is_manual_connection(is_manual)
{ {
fCurrentlyConnected = false;
pindexBestKnownBlock = nullptr; pindexBestKnownBlock = nullptr;
hashLastUnknownBlock.SetNull(); hashLastUnknownBlock.SetNull();
pindexLastCommonBlock = nullptr; pindexLastCommonBlock = nullptr;
@ -855,8 +852,9 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
if (state->fSyncStarted) if (state->fSyncStarted)
nSyncStarted--; nSyncStarted--;
if (misbehavior == 0 && state->fCurrentlyConnected && !node.IsBlockOnlyConn()) { if (node.fSuccessfullyConnected && misbehavior == 0 &&
// Note: we avoid changing visible addrman state for block-relay-only peers !node.IsBlockOnlyConn() && !node.IsInboundConn()) {
// Only change visible addrman state for outbound, full-relay peers
fUpdateConnectionTime = true; fUpdateConnectionTime = true;
} }
@ -2486,9 +2484,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
if (pfrom.fSuccessfullyConnected) return; if (pfrom.fSuccessfullyConnected) return;
if (!pfrom.IsInboundConn()) { if (!pfrom.IsInboundConn()) {
// Mark this node as currently connected, so we update its timestamp later.
LOCK(cs_main);
State(pfrom.GetId())->fCurrentlyConnected = true;
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n", LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
pfrom.nVersion.load(), pfrom.nStartingHeight, pfrom.nVersion.load(), pfrom.nStartingHeight,
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""), pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""),

Loading…
Cancel
Save