[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.
pull/764/head
Amiti Uttarwar 4 years ago
parent 77376034d4
commit 49c10a9ca4

@ -488,6 +488,26 @@ void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNet
} }
} }
std::string CNode::ConnectionTypeAsString() const
{
switch (m_conn_type) {
case ConnectionType::INBOUND:
return "inbound";
case ConnectionType::MANUAL:
return "manual";
case ConnectionType::FEELER:
return "feeler";
case ConnectionType::OUTBOUND_FULL_RELAY:
return "outbound-full-relay";
case ConnectionType::BLOCK_RELAY:
return "block-relay-only";
case ConnectionType::ADDR_FETCH:
return "addr-fetch";
} // no default case, so the compiler can warn about missing cases
assert(false);
}
std::string CNode::GetAddrName() const { std::string CNode::GetAddrName() const {
LOCK(cs_addrName); LOCK(cs_addrName);
return addrName; return addrName;

@ -1145,6 +1145,8 @@ public:
std::string GetAddrName() const; std::string GetAddrName() const;
//! Sets the addrName only if it was not previously set //! Sets the addrName only if it was not previously set
void MaybeSetAddrName(const std::string& addrNameIn); void MaybeSetAddrName(const std::string& addrNameIn);
std::string ConnectionTypeAsString() const;
}; };
/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */ /** Return a timestamp in the future (in microseconds) for exponentially distributed events. */

@ -3521,11 +3521,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
// Making nodes which are behind NAT and can only make outgoing connections ignore // Making nodes which are behind NAT and can only make outgoing connections ignore
// the getaddr message mitigates the attack. // the getaddr message mitigates the attack.
if (!pfrom.IsInboundConn()) { if (!pfrom.IsInboundConn()) {
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom.GetId()); LogPrint(BCLog::NET, "Ignoring \"getaddr\" from %s connection. peer=%d\n", pfrom.ConnectionTypeAsString(), pfrom.GetId());
return;
}
if (!pfrom.RelayAddrsWithConn()) {
LogPrint(BCLog::NET, "Ignoring \"getaddr\" from block-relay-only connection. peer=%d\n", pfrom.GetId());
return; return;
} }

Loading…
Cancel
Save