Skip to content

Commit

Permalink
feat(gossipsub): remove KeepAlive::Until
Browse files Browse the repository at this point in the history
Related: #3844.

Pull-Request: #4642.
  • Loading branch information
leonzchang authored Oct 20, 2023
1 parent b1b46d1 commit fafa6bc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 37 deletions.
2 changes: 2 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.46.0 - unreleased

- Remove deprecated `gossipsub::Config::idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`.
See [PR 4642](https://github.com/libp2p/rust-libp2p/pull/4642).
- Return typed error from config builder.
See [PR 4445].

Expand Down
10 changes: 2 additions & 8 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3313,10 +3313,7 @@ where
_: &Multiaddr,
_: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> {
Ok(Handler::new(
self.config.protocol_config(),
self.config.idle_timeout(),
))
Ok(Handler::new(self.config.protocol_config()))
}

#[allow(deprecated)]
Expand All @@ -3327,10 +3324,7 @@ where
_: &Multiaddr,
_: Endpoint,
) -> Result<THandler<Self>, ConnectionDenied> {
Ok(Handler::new(
self.config.protocol_config(),
self.config.idle_timeout(),
))
Ok(Handler::new(self.config.protocol_config()))
}

fn on_connection_handler_event(
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ where
for connection_id in peer_connections.connections.clone() {
active_connections = active_connections.checked_sub(1).unwrap();

let dummy_handler = Handler::new(ProtocolConfig::default(), Duration::ZERO);
let dummy_handler = Handler::new(ProtocolConfig::default());

gs.on_swarm_event(FromSwarm::ConnectionClosed(ConnectionClosed {
peer_id: *peer_id,
Expand Down
21 changes: 0 additions & 21 deletions protocols/gossipsub/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub struct Config {
heartbeat_interval: Duration,
fanout_ttl: Duration,
check_explicit_peers_ticks: u64,
idle_timeout: Duration,
duplicate_cache_time: Duration,
validate_messages: bool,
message_id_fn: Arc<dyn Fn(&Message) -> MessageId + Send + Sync + 'static>,
Expand Down Expand Up @@ -184,16 +183,6 @@ impl Config {
self.protocol.max_transmit_size
}

/// The time a connection is maintained to a peer without being in the mesh and without
/// send/receiving a message from. Connections that idle beyond this timeout are disconnected.
/// Default is 120 seconds.
#[deprecated(
note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead."
)]
pub fn idle_timeout(&self) -> Duration {
self.idle_timeout
}

/// Duplicates are prevented by storing message id's of known messages in an LRU time cache.
/// This settings sets the time period that messages are stored in the cache. Duplicates can be
/// received if duplicate messages are sent at a time greater than this setting apart. The
Expand Down Expand Up @@ -410,7 +399,6 @@ impl Default for ConfigBuilder {
heartbeat_interval: Duration::from_secs(1),
fanout_ttl: Duration::from_secs(60),
check_explicit_peers_ticks: 300,
idle_timeout: Duration::from_secs(120),
duplicate_cache_time: Duration::from_secs(60),
validate_messages: false,
message_id_fn: Arc::new(|message| {
Expand Down Expand Up @@ -605,14 +593,6 @@ impl ConfigBuilder {
self
}

/// The time a connection is maintained to a peer without being in the mesh and without
/// send/receiving a message from. Connections that idle beyond this timeout are disconnected.
/// Default is 120 seconds.
pub fn idle_timeout(&mut self, idle_timeout: Duration) -> &mut Self {
self.config.idle_timeout = idle_timeout;
self
}

/// Duplicates are prevented by storing message id's of known messages in an LRU time cache.
/// This settings sets the time period that messages are stored in the cache. Duplicates can be
/// received if duplicate messages are sent at a time greater than this setting apart. The
Expand Down Expand Up @@ -884,7 +864,6 @@ impl std::fmt::Debug for Config {
let _ = builder.field("heartbeat_initial_delay", &self.heartbeat_initial_delay);
let _ = builder.field("heartbeat_interval", &self.heartbeat_interval);
let _ = builder.field("fanout_ttl", &self.fanout_ttl);
let _ = builder.field("idle_timeout", &self.idle_timeout);
let _ = builder.field("duplicate_cache_time", &self.duplicate_cache_time);
let _ = builder.field("validate_messages", &self.validate_messages);
let _ = builder.field("allow_self_origin", &self.allow_self_origin);
Expand Down
9 changes: 2 additions & 7 deletions protocols/gossipsub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use smallvec::SmallVec;
use std::{
pin::Pin,
task::{Context, Poll},
time::Duration,
};
use void::Void;

Expand Down Expand Up @@ -119,9 +118,6 @@ pub struct EnabledHandler {

last_io_activity: Instant,

/// The amount of time we keep an idle connection alive.
idle_timeout: Duration,

/// Keeps track of whether this connection is for a peer in the mesh. This is used to make
/// decisions about the keep alive state for this connection.
in_mesh: bool,
Expand Down Expand Up @@ -164,7 +160,7 @@ enum OutboundSubstreamState {

impl Handler {
/// Builds a new [`Handler`].
pub fn new(protocol_config: ProtocolConfig, idle_timeout: Duration) -> Self {
pub fn new(protocol_config: ProtocolConfig) -> Self {
Handler::Enabled(EnabledHandler {
listen_protocol: protocol_config,
inbound_substream: None,
Expand All @@ -176,7 +172,6 @@ impl Handler {
peer_kind: None,
peer_kind_sent: false,
last_io_activity: Instant::now(),
idle_timeout,
in_mesh: false,
})
}
Expand Down Expand Up @@ -445,7 +440,7 @@ impl ConnectionHandler for Handler {
}

#[allow(deprecated)]
KeepAlive::Until(handler.last_io_activity + handler.idle_timeout)
KeepAlive::No
}
Handler::Disabled(_) => KeepAlive::No,
}
Expand Down

0 comments on commit fafa6bc

Please sign in to comment.