Skip to content

Commit 4c40837

Browse files
committed
Merge bitcoin/bitcoin#27412: logging, net: add ASN from peers on logs
0076bed logging: log ASN when using `-asmap` (brunoerg) 9836c76 net: add `GetMappedAS` in `CConnman` (brunoerg) Pull request description: When using `-asmap`, you can check the ASN assigned to the peers only with the RPC command `getpeerinfo` (check `mapped_as` field), however, it's not possible to check it in logs (e.g. see in logs the ASN of the peers when a new outbound peer has been connected). This PR includes the peers' ASN in debug output when using `-asmap`. Obs: Open this primarily to chase some Concept ACK, I've been using this on my node to facilitate to track the peers' ASN especially when reading the logs. ACKs for top commit: Sjors: tACK 0076bed jamesob: ACK 0076bed ([`jamesob/ackr/27412.1.brunoerg.logging_net_add_asn_from`](https://github.com/jamesob/bitcoin/tree/ackr/27412.1.brunoerg.logging_net_add_asn_from)) achow101: ACK 0076bed Tree-SHA512: c19cd11e8ab49962021f390459aadf6d33d221ae9a2c3df331a25d6865a8df470e2c8828f6e5219b8a887d6ab5b3450d34be9e26c00cca4d223b4ca64d51111b
2 parents 395b932 + 0076bed commit 4c40837

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/net.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,11 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
26142614
return nNum;
26152615
}
26162616

2617+
uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
2618+
{
2619+
return m_netgroupman.GetMappedAS(addr);
2620+
}
2621+
26172622
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
26182623
{
26192624
vstats.clear();
@@ -2622,7 +2627,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
26222627
for (CNode* pnode : m_nodes) {
26232628
vstats.emplace_back();
26242629
pnode->CopyStats(vstats.back());
2625-
vstats.back().m_mapped_as = m_netgroupman.GetMappedAS(pnode->addr);
2630+
vstats.back().m_mapped_as = GetMappedAS(pnode->addr);
26262631
}
26272632
}
26282633

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ class CConnman
851851
bool AddConnection(const std::string& address, ConnectionType conn_type) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
852852

853853
size_t GetNodeCount(ConnectionDirection) const;
854+
uint32_t GetMappedAS(const CNetAddr& addr) const;
854855
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
855856
bool DisconnectNode(const std::string& node);
856857
bool DisconnectNode(const CSubNet& subnet);

src/net_processing.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,10 +3362,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
33623362
if (fLogIPs)
33633363
remoteAddr = ", peeraddr=" + pfrom.addr.ToStringAddrPort();
33643364

3365-
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s\n",
3365+
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3366+
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s%s\n",
33663367
cleanSubVer, pfrom.nVersion,
33673368
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
3368-
remoteAddr);
3369+
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
33693370

33703371
int64_t nTimeOffset = nTime - GetTime();
33713372
pfrom.nTimeOffset = nTimeOffset;
@@ -3405,9 +3406,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34053406
}
34063407

34073408
if (!pfrom.IsInboundConn()) {
3408-
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
3409+
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3410+
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s%s (%s)\n",
34093411
pfrom.nVersion.load(), peer->m_starting_height,
34103412
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : ""),
3413+
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""),
34113414
pfrom.ConnectionTypeAsString());
34123415
}
34133416

0 commit comments

Comments
 (0)