From 7ee79d03d8ac24f68b0a82f45c3e6b7b638dab7a Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Tue, 1 Aug 2023 17:37:53 +0700 Subject: [PATCH 1/8] kad: Change connection handler logging. - downgrade log level for the remote kademlia protocol report - introduce connection_id for the handler to improve logging --- protocols/kad/src/behaviour.rs | 2 ++ protocols/kad/src/handler.rs | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index c0a11a100ec..1d1db9276c5 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -2081,6 +2081,7 @@ where connected_point, peer, self.mode, + connection_id, )) } @@ -2103,6 +2104,7 @@ where connected_point, peer, self.mode, + connection_id, )) } diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 948f14f30eb..e9095f7da30 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -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 current connection ID from the behaviour. + 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. {:?}", + 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. {:?}", + self.remote_peer_id, + self.connection_id, ); self.protocol_status = ProtocolStatus::NotSupported; From a0fcc67b01e71bf9ac0e988c1f3552318cbda76c Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Tue, 1 Aug 2023 21:20:21 +0700 Subject: [PATCH 2/8] kad: Update change log for reducing log noise. - update comments --- protocols/kad/CHANGELOG.md | 3 +++ protocols/kad/src/handler.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index c729e5ea0f9..6d23d8e61bf 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -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 diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index e9095f7da30..af4fca3f03e 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -95,7 +95,7 @@ pub struct KademliaHandler { remote_supported_protocols: SupportedProtocols, - /// The current connection ID from the behaviour. + /// The ID of this connection. connection_id: ConnectionId, } From 97a882a3f44a689221c1561ab1faf7f4d008456e Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Wed, 2 Aug 2023 13:11:11 +0700 Subject: [PATCH 3/8] feat(swarm): Implement Display for ConnectionId --- swarm/src/connection.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 6646967f590..3796d9a027d 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -53,6 +53,7 @@ use libp2p_core::upgrade::{NegotiationError, ProtocolError}; use libp2p_core::Endpoint; use libp2p_identity::PeerId; use std::collections::HashSet; +use std::fmt::{Display, Formatter}; use std::future::Future; use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; @@ -82,6 +83,12 @@ impl ConnectionId { } } +impl Display for ConnectionId { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + /// Information about a successfully established connection. #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct Connected { From 65a06102bb26ef4ec68dc5854c47b3ed9ad02a8d Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Wed, 2 Aug 2023 13:11:35 +0700 Subject: [PATCH 4/8] fix(kad): Update handler logging. --- protocols/kad/src/handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index af4fca3f03e..d695420ec2b 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -809,7 +809,7 @@ impl ConnectionHandler for KademliaHandler { (true, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => {} (true, _) => { log::debug!( - "Remote {} now supports our kademlia protocol. {:?}", + "Remote {} now supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, ); @@ -818,7 +818,7 @@ impl ConnectionHandler for KademliaHandler { } (false, ProtocolStatus::Confirmed | ProtocolStatus::Reported) => { log::debug!( - "Remote {} no longer supports our kademlia protocol. {:?}", + "Remote {} no longer supports our kademlia protocol on connection {}", self.remote_peer_id, self.connection_id, ); From 608bf81e69e785fcf294714f9e3fcac79cda16e9 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Thu, 3 Aug 2023 19:01:32 +0700 Subject: [PATCH 5/8] feat(swarm): bump swarm version to 0.43.3 - update change log --- swarm/CHANGELOG.md | 7 +++++++ swarm/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 1d4108ac92c..9f028f8ac75 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.3 - unreleased + +- Implement `Display` for `ConnectionId` + See [PR 4278]. + +[PR 4278]: https://github.com/libp2p/rust-libp2p/pull/4278 + ## 0.43.2 - Display the cause of a `ListenError::Denied`. See [PR 4232] diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 752491cda7e..37d16d31497 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.43.2" +version = "0.43.3" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" From 4086247a85adbd14fe28daf3dec1f727d53ec0d0 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 3 Aug 2023 16:00:55 +0200 Subject: [PATCH 6/8] Update swarm/CHANGELOG.md --- swarm/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 9f028f8ac75..6a9808dd554 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.43.3 - unreleased -- Implement `Display` for `ConnectionId` +- Implement `Display` for `ConnectionId`. See [PR 4278]. [PR 4278]: https://github.com/libp2p/rust-libp2p/pull/4278 From 108c1555245c247346767ca57f397919b2ecafe1 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Mon, 7 Aug 2023 12:36:30 +0700 Subject: [PATCH 7/8] fix: update Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 57bca1723d4..151372cf1ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3149,7 +3149,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.43.2" +version = "0.43.3" dependencies = [ "async-std", "either", From 1ea7b865b4fb6d56d6ccf8ea5cad4092376ccc2a Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Mon, 7 Aug 2023 13:01:17 +0700 Subject: [PATCH 8/8] fix: update Cargo.toml - update swarm version to 0.43.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0a23bc54815..d7e8be3b8c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,7 @@ libp2p-quic = { version = "0.9.0-alpha", path = "transports/quic" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } -libp2p-swarm = { version = "0.43.2", path = "swarm" } +libp2p-swarm = { version = "0.43.3", path = "swarm" } libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } libp2p-tcp = { version = "0.40.0", path = "transports/tcp" }