From 67750db42c76bfb870e45ff46c3a59bad7cd8095 Mon Sep 17 00:00:00 2001 From: leonzchang Date: Thu, 12 Oct 2023 13:22:19 +0800 Subject: [PATCH] remove stream tracking code in protocols --- Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- protocols/kad/CHANGELOG.md | 2 ++ protocols/kad/Cargo.toml | 2 +- protocols/kad/src/handler.rs | 18 +----------------- protocols/perf/CHANGELOG.md | 2 ++ protocols/perf/Cargo.toml | 2 +- protocols/perf/src/client/handler.rs | 17 +---------------- protocols/relay/CHANGELOG.md | 2 ++ protocols/relay/Cargo.toml | 7 +++++-- protocols/relay/src/behaviour/handler.rs | 1 - protocols/relay/src/priv_client/handler.rs | 5 +---- 12 files changed, 22 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5f852759208..ced0e2ae7521 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2672,7 +2672,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.44.6" +version = "0.44.7" dependencies = [ "arrayvec", "async-std", @@ -2830,7 +2830,7 @@ dependencies = [ [[package]] name = "libp2p-perf" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "async-trait", @@ -2947,7 +2947,7 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.16.1" +version = "0.16.2" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 0ae72008d0ee..31f98e5ef42f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,19 +84,19 @@ libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.1", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.2", path = "protocols/identify" } libp2p-identity = { version = "0.2.5" } -libp2p-kad = { version = "0.44.6", path = "protocols/kad" } +libp2p-kad = { version = "0.44.7", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-memory-connection-limits = { version = "0.1.0", path = "misc/memory-connection-limits" } libp2p-metrics = { version = "0.13.1", path = "misc/metrics" } libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" } libp2p-muxer-test-harness = { path = "muxers/test-harness" } libp2p-noise = { version = "0.43.1", path = "transports/noise" } -libp2p-perf = { version = "0.2.0", path = "protocols/perf" } +libp2p-perf = { version = "0.2.1", path = "protocols/perf" } libp2p-ping = { version = "0.43.2", path = "protocols/ping" } libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" } libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } libp2p-quic = { version = "0.9.3", path = "transports/quic" } -libp2p-relay = { version = "0.16.1", path = "protocols/relay" } +libp2p-relay = { version = "0.16.2", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-upnp = { version = "0.1.1", path = "protocols/upnp" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 7e90c78371f6..7ce6e6ffdd8f 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.44.7 - unreleased + ## 0.44.6 - unreleased - Rename `Kademlia` symbols to follow naming convention. See [PR 4547]. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index f97f4ba03adb..d8c9c9b07eb1 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = { workspace = true } description = "Kademlia protocol for libp2p" -version = "0.44.6" +version = "0.44.7" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 0df4da6bdc71..5c695b7287c3 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -79,9 +79,6 @@ pub struct Handler { /// List of active inbound substreams with the state they are in. inbound_substreams: SelectAll, - /// Until when to keep the connection alive. - keep_alive: KeepAlive, - /// The connected endpoint of the connection that the handler /// is associated with. endpoint: ConnectedPoint, @@ -491,8 +488,6 @@ impl Handler { } } - let keep_alive = KeepAlive::Until(Instant::now() + idle_timeout); - Handler { protocol_config, mode, @@ -504,7 +499,6 @@ impl Handler { outbound_substreams: Default::default(), num_requested_outbound_streams: 0, pending_messages: Default::default(), - keep_alive, protocol_status: ProtocolStatus::Unknown, remote_supported_protocols: Default::default(), connection_id, @@ -718,7 +712,7 @@ impl ConnectionHandler for Handler { } fn connection_keep_alive(&self) -> KeepAlive { - self.keep_alive + KeepAlive::No } fn poll( @@ -760,16 +754,6 @@ impl ConnectionHandler for Handler { }); } - let no_streams = self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty(); - self.keep_alive = match (no_streams, self.keep_alive) { - // No open streams. Preserve the existing idle timeout. - (true, k @ KeepAlive::Until(_)) => k, - // No open streams. Set idle timeout. - (true, _) => KeepAlive::Until(Instant::now() + self.idle_timeout), - // Keep alive for open streams. - (false, _) => KeepAlive::Yes, - }; - Poll::Pending } diff --git a/protocols/perf/CHANGELOG.md b/protocols/perf/CHANGELOG.md index e46a94e981ac..066c48802cc0 100644 --- a/protocols/perf/CHANGELOG.md +++ b/protocols/perf/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.2.1 - unreleased + ## 0.2.0 - Raise MSRV to 1.65. diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index c61deb37c29b..5e9ecad52025 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-perf" edition = "2021" rust-version = { workspace = true } description = "libp2p perf protocol implementation" -version = "0.2.0" +version = "0.2.1" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index 8a6df43d1981..dbd20e4b1643 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -64,8 +64,6 @@ pub struct Handler { requested_streams: VecDeque, outbound: FuturesUnordered>>, - - keep_alive: KeepAlive, } impl Handler { @@ -74,7 +72,6 @@ impl Handler { queued_events: Default::default(), requested_streams: Default::default(), outbound: Default::default(), - keep_alive: KeepAlive::Yes, } } } @@ -158,7 +155,7 @@ impl ConnectionHandler for Handler { } fn connection_keep_alive(&self) -> KeepAlive { - self.keep_alive + KeepAlive::No } fn poll( @@ -186,18 +183,6 @@ impl ConnectionHandler for Handler { } } - if self.outbound.is_empty() { - match self.keep_alive { - KeepAlive::Yes => { - self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10)); - } - KeepAlive::Until(_) => {} - KeepAlive::No => panic!("Handler never sets KeepAlive::No."), - } - } else { - self.keep_alive = KeepAlive::Yes - } - Poll::Pending } } diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 6af89e25d712..84b77039b02c 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.16.2 - unreleased + ## 0.16.1 - Export `RateLimiter` type. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 03799a8c77cf..7bf6e0f7adeb 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -3,8 +3,11 @@ name = "libp2p-relay" edition = "2021" rust-version = { workspace = true } description = "Communications relaying for libp2p" -version = "0.16.1" -authors = ["Parity Technologies ", "Max Inden "] +version = "0.16.2" +authors = [ + "Parity Technologies ", + "Max Inden ", +] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 895228e807b8..7dbc7e8baa94 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -879,7 +879,6 @@ impl ConnectionHandler for Handler { if self.reservation_request_future.is_none() && self.circuit_accept_futures.is_empty() && self.circuit_deny_futures.is_empty() - && self.alive_lend_out_substreams.is_empty() && self.circuits.is_empty() && self.active_reservation.is_none() { diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 25488ac3041c..0bf738e75832 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -489,10 +489,7 @@ impl ConnectionHandler for Handler { } // Update keep-alive handling. - if matches!(self.reservation, Reservation::None) - && self.alive_lend_out_substreams.is_empty() - && self.circuit_deny_futs.is_empty() - { + if matches!(self.reservation, Reservation::None) && self.circuit_deny_futs.is_empty() { match self.keep_alive { KeepAlive::Yes => { self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));