@@ -558,7 +558,6 @@ void CNode::CloseSocketDisconnect()
558
558
fDisconnect = true ;
559
559
LOCK (m_sock_mutex);
560
560
if (m_sock) {
561
- LogDebug (BCLog::NET, " disconnecting peer=%d\n " , id);
562
561
m_sock.reset ();
563
562
}
564
563
m_i2p_sam_session.reset ();
@@ -696,6 +695,13 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
696
695
return true ;
697
696
}
698
697
698
+ std::string CNode::DisconnectMsg (bool log_ip) const
699
+ {
700
+ return strprintf (" disconnecting peer=%d%s" ,
701
+ GetId (),
702
+ log_ip ? strprintf (" peeraddr=%s" , addr.ToStringAddrPort ()) : " " );
703
+ }
704
+
699
705
V1Transport::V1Transport (const NodeId node_id) noexcept
700
706
: m_magic_bytes{Params ().MessageStart ()}, m_node_id{node_id}
701
707
{
@@ -1635,7 +1641,7 @@ std::pair<size_t, bool> CConnman::SocketSendData(CNode& node) const
1635
1641
// error
1636
1642
int nErr = WSAGetLastError ();
1637
1643
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) {
1638
- LogDebug (BCLog::NET, " socket send error for peer=%d : %s\n " , node.GetId ( ), NetworkErrorString (nErr));
1644
+ LogDebug (BCLog::NET, " socket send error, %s : %s\n " , node.DisconnectMsg ( fLogIPs ), NetworkErrorString (nErr));
1639
1645
node.CloseSocketDisconnect ();
1640
1646
}
1641
1647
}
@@ -1879,7 +1885,7 @@ void CConnman::DisconnectNodes()
1879
1885
// Disconnect any connected nodes
1880
1886
for (CNode* pnode : m_nodes) {
1881
1887
if (!pnode->fDisconnect ) {
1882
- LogDebug (BCLog::NET, " Network not active, dropping peer=%d \n " , pnode->GetId ( ));
1888
+ LogDebug (BCLog::NET, " Network not active, %s \n " , pnode->DisconnectMsg ( fLogIPs ));
1883
1889
pnode->fDisconnect = true ;
1884
1890
}
1885
1891
}
@@ -1972,25 +1978,37 @@ bool CConnman::InactivityCheck(const CNode& node) const
1972
1978
if (!ShouldRunInactivityChecks (node, now)) return false ;
1973
1979
1974
1980
if (last_recv.count () == 0 || last_send.count () == 0 ) {
1975
- LogDebug (BCLog::NET, " socket no message in first %i seconds, %d %d peer=%d\n " , count_seconds (m_peer_connect_timeout), last_recv.count () != 0 , last_send.count () != 0 , node.GetId ());
1981
+ LogDebug (BCLog::NET,
1982
+ " socket no message in first %i seconds, %d %d, %s\n " ,
1983
+ count_seconds (m_peer_connect_timeout),
1984
+ last_recv.count () != 0 ,
1985
+ last_send.count () != 0 ,
1986
+ node.DisconnectMsg (fLogIPs )
1987
+ );
1976
1988
return true ;
1977
1989
}
1978
1990
1979
1991
if (now > last_send + TIMEOUT_INTERVAL) {
1980
- LogDebug (BCLog::NET, " socket sending timeout: %is peer=%d\n " , count_seconds (now - last_send), node.GetId ());
1992
+ LogDebug (BCLog::NET,
1993
+ " socket sending timeout: %is, %s\n " , count_seconds (now - last_send),
1994
+ node.DisconnectMsg (fLogIPs )
1995
+ );
1981
1996
return true ;
1982
1997
}
1983
1998
1984
1999
if (now > last_recv + TIMEOUT_INTERVAL) {
1985
- LogDebug (BCLog::NET, " socket receive timeout: %is peer=%d\n " , count_seconds (now - last_recv), node.GetId ());
2000
+ LogDebug (BCLog::NET,
2001
+ " socket receive timeout: %is, %s\n " , count_seconds (now - last_recv),
2002
+ node.DisconnectMsg (fLogIPs )
2003
+ );
1986
2004
return true ;
1987
2005
}
1988
2006
1989
2007
if (!node.fSuccessfullyConnected ) {
1990
2008
if (node.m_transport ->GetInfo ().transport_type == TransportProtocolType::DETECTING) {
1991
- LogDebug (BCLog::NET, " V2 handshake timeout peer=%d \n " , node.GetId ( ));
2009
+ LogDebug (BCLog::NET, " V2 handshake timeout, %s \n " , node.DisconnectMsg ( fLogIPs ));
1992
2010
} else {
1993
- LogDebug (BCLog::NET, " version handshake timeout peer=%d \n " , node.GetId ( ));
2011
+ LogDebug (BCLog::NET, " version handshake timeout, %s \n " , node.DisconnectMsg ( fLogIPs ));
1994
2012
}
1995
2013
return true ;
1996
2014
}
@@ -2118,6 +2136,10 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
2118
2136
{
2119
2137
bool notify = false ;
2120
2138
if (!pnode->ReceiveMsgBytes ({pchBuf, (size_t )nBytes}, notify)) {
2139
+ LogDebug (BCLog::NET,
2140
+ " receiving message bytes failed, %s\n " ,
2141
+ pnode->DisconnectMsg (fLogIPs )
2142
+ );
2121
2143
pnode->CloseSocketDisconnect ();
2122
2144
}
2123
2145
RecordBytesRecv (nBytes);
@@ -2130,7 +2152,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
2130
2152
{
2131
2153
// socket closed gracefully
2132
2154
if (!pnode->fDisconnect ) {
2133
- LogDebug (BCLog::NET, " socket closed for peer=%d \n " , pnode->GetId ( ));
2155
+ LogDebug (BCLog::NET, " socket closed, %s \n " , pnode->DisconnectMsg ( fLogIPs ));
2134
2156
}
2135
2157
pnode->CloseSocketDisconnect ();
2136
2158
}
@@ -2141,7 +2163,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
2141
2163
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
2142
2164
{
2143
2165
if (!pnode->fDisconnect ) {
2144
- LogDebug (BCLog::NET, " socket recv error for peer=%d : %s\n " , pnode->GetId ( ), NetworkErrorString (nErr));
2166
+ LogDebug (BCLog::NET, " socket recv error, %s : %s\n " , pnode->DisconnectMsg ( fLogIPs ), NetworkErrorString (nErr));
2145
2167
}
2146
2168
pnode->CloseSocketDisconnect ();
2147
2169
}
@@ -3411,6 +3433,7 @@ void CConnman::StopNodes()
3411
3433
std::vector<CNode*> nodes;
3412
3434
WITH_LOCK (m_nodes_mutex, nodes.swap (m_nodes));
3413
3435
for (CNode* pnode : nodes) {
3436
+ LogDebug (BCLog::NET, " %s\n " , pnode->DisconnectMsg (fLogIPs ));
3414
3437
pnode->CloseSocketDisconnect ();
3415
3438
DeleteNode (pnode);
3416
3439
}
0 commit comments