Skip to content

Commit 49c10a9

Browse files
committed
[log] Add connection type to log statement
In addition to adding more specificity to the log statement about the type of connection, this change also consolidates two statements into one. Previously, the second one should have never been hit, since block-relay connections would match the "!IsInboundConn()" condition and return early.
1 parent 7737603 commit 49c10a9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/net.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,26 @@ void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNet
488488
}
489489
}
490490

491+
std::string CNode::ConnectionTypeAsString() const
492+
{
493+
switch (m_conn_type) {
494+
case ConnectionType::INBOUND:
495+
return "inbound";
496+
case ConnectionType::MANUAL:
497+
return "manual";
498+
case ConnectionType::FEELER:
499+
return "feeler";
500+
case ConnectionType::OUTBOUND_FULL_RELAY:
501+
return "outbound-full-relay";
502+
case ConnectionType::BLOCK_RELAY:
503+
return "block-relay-only";
504+
case ConnectionType::ADDR_FETCH:
505+
return "addr-fetch";
506+
} // no default case, so the compiler can warn about missing cases
507+
508+
assert(false);
509+
}
510+
491511
std::string CNode::GetAddrName() const {
492512
LOCK(cs_addrName);
493513
return addrName;

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,8 @@ class CNode
11451145
std::string GetAddrName() const;
11461146
//! Sets the addrName only if it was not previously set
11471147
void MaybeSetAddrName(const std::string& addrNameIn);
1148+
1149+
std::string ConnectionTypeAsString() const;
11481150
};
11491151

11501152
/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */

src/net_processing.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,11 +3521,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
35213521
// Making nodes which are behind NAT and can only make outgoing connections ignore
35223522
// the getaddr message mitigates the attack.
35233523
if (!pfrom.IsInboundConn()) {
3524-
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId());
3525-
return;
3526-
}
3527-
if (!pfrom.RelayAddrsWithConn()) {
3528-
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
3524+
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from %s connection. peer=%d\n", pfrom.ConnectionTypeAsString(), pfrom.GetId());
35293525
return;
35303526
}
35313527

0 commit comments

Comments
 (0)