fix(kad): reduce noise of "remote supports our protocol" log

This PR changes the logging of the Kademlia connection handler related to the remote Kademlia mode changes:
- Downgrade log level for the remote kademlia protocol report from `info` to `debug`.
- Introduce connection_id for the handler to improve logging.

Pull-Request: #4278.
This commit is contained in:
shamil-gadelshin
2023-08-07 16:31:15 +07:00
committed by GitHub
parent 72fd50ae6c
commit e65155281e
8 changed files with 36 additions and 10 deletions

View File

@ -2,8 +2,11 @@
- Implement common traits on `RoutingUpdate`.
See [PR 4270].
- Reduce noise of "remote supports our protocol" log.
See [PR 4278].
[PR 4270]: https://github.com/libp2p/rust-libp2p/pull/4270
[PR 4278]: https://github.com/libp2p/rust-libp2p/pull/4278
## 0.44.3

View File

@ -2081,6 +2081,7 @@ where
connected_point,
peer,
self.mode,
connection_id,
))
}
@ -2103,6 +2104,7 @@ where
connected_point,
peer,
self.mode,
connection_id,
))
}

View File

@ -35,7 +35,7 @@ use libp2p_swarm::handler::{
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
};
use libp2p_swarm::{
ConnectionHandler, ConnectionHandlerEvent, KeepAlive, Stream, StreamUpgradeError,
ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, Stream, StreamUpgradeError,
SubstreamProtocol, SupportedProtocols,
};
use log::trace;
@ -94,6 +94,9 @@ pub struct KademliaHandler {
protocol_status: ProtocolStatus,
remote_supported_protocols: SupportedProtocols,
/// The ID of this connection.
connection_id: ConnectionId,
}
/// The states of protocol confirmation that a connection
@ -474,6 +477,7 @@ impl KademliaHandler {
endpoint: ConnectedPoint,
remote_peer_id: PeerId,
mode: Mode,
connection_id: ConnectionId,
) -> Self {
match &endpoint {
ConnectedPoint::Dialer { .. } => {
@ -504,6 +508,7 @@ impl KademliaHandler {
keep_alive,
protocol_status: ProtocolStatus::Unknown,
remote_supported_protocols: Default::default(),
connection_id,
}
}
@ -803,17 +808,19 @@ impl ConnectionHandler for KademliaHandler {
match (remote_supports_our_kademlia_protocols, self.protocol_status) {
(true, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {}
(true, _) => {
log::info!(
"Remote {} now supports our kademlia protocol",
self.remote_peer_id
log::debug!(
"Remote {} now supports our kademlia protocol on connection {}",
self.remote_peer_id,
self.connection_id,
);
self.protocol_status = ProtocolStatus::Confirmed;
}
(false, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {
log::info!(
"Remote {} no longer supports our kademlia protocol",
self.remote_peer_id
log::debug!(
"Remote {} no longer supports our kademlia protocol on connection {}",
self.remote_peer_id,
self.connection_id,
);
self.protocol_status = ProtocolStatus::NotSupported;