Skip to content

Commit a0c887a

Browse files
achow101vijaydasmp
authored andcommitted
Merge 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
1 parent 22b91be commit a0c887a

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
@@ -4708,6 +4708,11 @@ size_t CConnman::GetMaxOutboundOnionNodeCount()
47084708
return m_max_outbound_onion;
47094709
}
47104710

4711+
uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
4712+
{
4713+
return m_netgroupman.GetMappedAS(addr);
4714+
}
4715+
47114716
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
47124717
{
47134718
vstats.clear();
@@ -4719,7 +4724,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
47194724
}
47204725
vstats.emplace_back();
47214726
pnode->CopyStats(vstats.back());
4722-
vstats.back().m_mapped_as = m_netgroupman.GetMappedAS(pnode->addr);
4727+
vstats.back().m_mapped_as = GetMappedAS(pnode->addr);
47234728
}
47244729
}
47254730

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ friend class CNode;
15011501
size_t GetNodeCount(ConnectionDirection) const;
15021502
size_t GetMaxOutboundNodeCount();
15031503
size_t GetMaxOutboundOnionNodeCount();
1504+
uint32_t GetMappedAS(const CNetAddr& addr) const;
15041505
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
15051506
bool DisconnectNode(const std::string& node);
15061507
bool DisconnectNode(const CSubNet& subnet);

src/net_processing.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,10 +3741,11 @@ void PeerManagerImpl::ProcessMessage(
37413741
if (fLogIPs)
37423742
remoteAddr = ", peeraddr=" + pfrom.addr.ToStringAddrPort();
37433743

3744-
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s\n",
3744+
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3745+
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s%s\n",
37453746
cleanSubVer, pfrom.nVersion,
37463747
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
3747-
remoteAddr);
3748+
remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
37483749

37493750
int64_t nTimeOffset = nTime - GetTime();
37503751
pfrom.nTimeOffset = nTimeOffset;
@@ -3780,7 +3781,9 @@ void PeerManagerImpl::ProcessMessage(
37803781
// Log succesful connections unconditionally for outbound, but not for inbound as those
37813782
// can be triggered by an attacker at high rate.
37823783
if (!pfrom.IsInboundConn() || LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) {
3783-
LogPrintf("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s\n",
3784+
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3785+
LogPrintf("New %s %s %s peer connected: version: %d, blocks=%d, peer=%d%s\n",
3786+
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""),
37843787
pfrom.ConnectionTypeAsString(),
37853788
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
37863789
pfrom.nVersion.load(), peer->m_starting_height,

0 commit comments

Comments
 (0)