mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
net: expose transport types/session IDs of connections in RPC and logs
Co-authored-by: Dhruv Mehta <856960+dhruv@users.noreply.github.com>
This commit is contained in:
29
src/net.cpp
29
src/net.cpp
@@ -667,6 +667,9 @@ void CNode::CopyStats(CNodeStats& stats)
|
||||
LOCK(cs_vRecv);
|
||||
X(mapRecvBytesPerMsgType);
|
||||
X(nRecvBytes);
|
||||
Transport::Info info = m_transport->GetInfo();
|
||||
stats.m_transport_type = info.transport_type;
|
||||
if (info.session_id) stats.m_session_id = HexStr(*info.session_id);
|
||||
}
|
||||
X(m_permission_flags);
|
||||
|
||||
@@ -734,6 +737,11 @@ V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noex
|
||||
Reset();
|
||||
}
|
||||
|
||||
Transport::Info V1Transport::GetInfo() const noexcept
|
||||
{
|
||||
return {.transport_type = TransportProtocolType::V1, .session_id = {}};
|
||||
}
|
||||
|
||||
int V1Transport::readHeader(Span<const uint8_t> msg_bytes)
|
||||
{
|
||||
AssertLockHeld(m_recv_mutex);
|
||||
@@ -1582,6 +1590,27 @@ size_t V2Transport::GetSendMemoryUsage() const noexcept
|
||||
return sizeof(m_send_buffer) + memusage::DynamicUsage(m_send_buffer);
|
||||
}
|
||||
|
||||
Transport::Info V2Transport::GetInfo() const noexcept
|
||||
{
|
||||
AssertLockNotHeld(m_recv_mutex);
|
||||
LOCK(m_recv_mutex);
|
||||
if (m_recv_state == RecvState::V1) return m_v1_fallback.GetInfo();
|
||||
|
||||
Transport::Info info;
|
||||
|
||||
// Do not report v2 and session ID until the version packet has been received
|
||||
// and verified (confirming that the other side very likely has the same keys as us).
|
||||
if (m_recv_state != RecvState::KEY_MAYBE_V1 && m_recv_state != RecvState::KEY &&
|
||||
m_recv_state != RecvState::GARB_GARBTERM && m_recv_state != RecvState::VERSION) {
|
||||
info.transport_type = TransportProtocolType::V2;
|
||||
info.session_id = uint256(MakeUCharSpan(m_cipher.GetSessionID()));
|
||||
} else {
|
||||
info.transport_type = TransportProtocolType::DETECTING;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
std::pair<size_t, bool> CConnman::SocketSendData(CNode& node) const
|
||||
{
|
||||
auto it = node.vSendMsg.begin();
|
||||
|
||||
Reference in New Issue
Block a user