diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 439ba2746db..c8bc4a846df 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3666,16 +3666,22 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, return; } + auto new_peer_msg = [&]() { + const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)}; + return strprintf("New %s peer connected: transport: %s, version: %d, blocks=%d peer=%d%s%s\n", + pfrom.ConnectionTypeAsString(), + TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type), + pfrom.nVersion.load(), peer->m_starting_height, + pfrom.GetId(), pfrom.LogIP(fLogIPs), + (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : "")); + }; + // Log successful connections unconditionally for outbound, but not for inbound as those // can be triggered by an attacker at high rate. - if (!pfrom.IsInboundConn() || LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) { - const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)}; - LogInfo("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s%s\n", - pfrom.ConnectionTypeAsString(), - TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type), - pfrom.nVersion.load(), peer->m_starting_height, - pfrom.GetId(), pfrom.LogIP(fLogIPs), - (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : "")); + if (pfrom.IsInboundConn()) { + LogDebug(BCLog::NET, "%s", new_peer_msg()); + } else { + LogInfo("%s", new_peer_msg()); } if (pfrom.GetCommonVersion() >= SHORT_IDS_BLOCKS_VERSION) {