mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 03:18:09 -03:00
net: add LogIP() helper, use in net_processing
This commit is contained in:
parent
937ef9eb40
commit
1d01ad4d73
3 changed files with 16 additions and 7 deletions
|
@ -695,11 +695,16 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string CNode::LogIP(bool log_ip) const
|
||||
{
|
||||
return log_ip ? strprintf(" peeraddr=%s", addr.ToStringAddrPort()) : "";
|
||||
}
|
||||
|
||||
std::string CNode::DisconnectMsg(bool log_ip) const
|
||||
{
|
||||
return strprintf("disconnecting peer=%d%s",
|
||||
GetId(),
|
||||
log_ip ? strprintf(" peeraddr=%s", addr.ToStringAddrPort()) : "");
|
||||
LogIP(log_ip));
|
||||
}
|
||||
|
||||
V1Transport::V1Transport(const NodeId node_id) noexcept
|
||||
|
|
|
@ -947,6 +947,14 @@ public:
|
|||
|
||||
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
|
||||
|
||||
/**
|
||||
* Helper function to optionally log the IP address.
|
||||
*
|
||||
* @param[in] log_ip whether to include the IP address
|
||||
* @return " peeraddr=..." or ""
|
||||
*/
|
||||
std::string LogIP(bool log_ip) const;
|
||||
|
||||
/**
|
||||
* Helper function to log disconnects.
|
||||
*
|
||||
|
|
|
@ -3568,15 +3568,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
m_addrman.Good(pfrom.addr);
|
||||
}
|
||||
|
||||
std::string remoteAddr;
|
||||
if (fLogIPs)
|
||||
remoteAddr = ", peeraddr=" + pfrom.addr.ToStringAddrPort();
|
||||
|
||||
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
|
||||
LogDebug(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s%s\n",
|
||||
cleanSubVer, pfrom.nVersion,
|
||||
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
|
||||
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
pfrom.LogIP(fLogIPs), (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
|
||||
peer->m_time_offset = NodeSeconds{std::chrono::seconds{nTime}} - Now<NodeSeconds>();
|
||||
if (!pfrom.IsInboundConn()) {
|
||||
|
@ -3620,7 +3616,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
pfrom.ConnectionTypeAsString(),
|
||||
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
|
||||
pfrom.nVersion.load(), peer->m_starting_height,
|
||||
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : ""),
|
||||
pfrom.GetId(), pfrom.LogIP(fLogIPs),
|
||||
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue