aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-04-20 17:12:48 -0400
committerAndrew Chow <github@achow101.com>2023-04-20 17:20:29 -0400
commit4c40837a454996c9f704ebf060efd6b249f2e362 (patch)
treec71341b43861d22a9c67f5d9cf6385b534ddbcbd
parent395b9328071f7764373605e12c47e08b87ffb4df (diff)
parent0076bed45eb2b42111fa3f4c95181393c685a42e (diff)
Merge bitcoin/bitcoin#27412: logging, net: add ASN from peers on logs
0076bed45eb2b42111fa3f4c95181393c685a42e logging: log ASN when using `-asmap` (brunoerg) 9836c76ae048698e4f7dab21e3be37313e8392ae 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 0076bed45eb2b42111fa3f4c95181393c685a42e jamesob: ACK 0076bed45eb2b42111fa3f4c95181393c685a42e ([`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 0076bed45eb2b42111fa3f4c95181393c685a42e Tree-SHA512: c19cd11e8ab49962021f390459aadf6d33d221ae9a2c3df331a25d6865a8df470e2c8828f6e5219b8a887d6ab5b3450d34be9e26c00cca4d223b4ca64d51111b
-rw-r--r--src/net.cpp7
-rw-r--r--src/net.h1
-rw-r--r--src/net_processing.cpp9
3 files changed, 13 insertions, 4 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 903fedb2fb..f56de6d605 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2614,6 +2614,11 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
return nNum;
}
+uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
+{
+ return m_netgroupman.GetMappedAS(addr);
+}
+
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
{
vstats.clear();
@@ -2622,7 +2627,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
for (CNode* pnode : m_nodes) {
vstats.emplace_back();
pnode->CopyStats(vstats.back());
- vstats.back().m_mapped_as = m_netgroupman.GetMappedAS(pnode->addr);
+ vstats.back().m_mapped_as = GetMappedAS(pnode->addr);
}
}
diff --git a/src/net.h b/src/net.h
index 9b939aea5c..908b16f35e 100644
--- a/src/net.h
+++ b/src/net.h
@@ -851,6 +851,7 @@ public:
bool AddConnection(const std::string& address, ConnectionType conn_type) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
size_t GetNodeCount(ConnectionDirection) const;
+ uint32_t GetMappedAS(const CNetAddr& addr) const;
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
bool DisconnectNode(const std::string& node);
bool DisconnectNode(const CSubNet& subnet);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 68bd91297c..c9d75c7fbf 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3362,10 +3362,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (fLogIPs)
remoteAddr = ", peeraddr=" + pfrom.addr.ToStringAddrPort();
- LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s\n",
+ const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
+ LogPrint(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);
+ remoteAddr, (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
int64_t nTimeOffset = nTime - GetTime();
pfrom.nTimeOffset = nTimeOffset;
@@ -3405,9 +3406,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
}
if (!pfrom.IsInboundConn()) {
- LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
+ const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
+ LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s%s (%s)\n",
pfrom.nVersion.load(), peer->m_starting_height,
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : ""),
+ (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""),
pfrom.ConnectionTypeAsString());
}