Skip to content

Commit a3cacd5

Browse files
authored
Merge branch 'master' into chore/link-workspace-version-edition
2 parents 3c7e69b + 37aa175 commit a3cacd5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

libp2p/src/tutorials/ping.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@
205205
//! ## Idle connection timeout
206206
//!
207207
//! Now, for this example in particular, we need set the idle connection timeout.
208-
//! Otherwise, the connection will be closed immediately.
208+
//! The default connection timeout is 10 seconds.
209209
//!
210210
//! Whether you need to set this in your application too depends on your usecase.
211211
//! Typically, connections are kept alive if they are "in use" by a certain protocol.
212212
//! The ping protocol however is only an "auxiliary" kind of protocol.
213-
//! Thus, without any other behaviour in place, we would not be able to observe the pings.
213+
//! Thus, without any other behaviour in place, we would not be able to observe any pings after 10s.
214214
//!
215215
//! ```rust
216216
//! use std::{error::Error, time::Duration};
@@ -232,6 +232,9 @@
232232
//! yamux::Config::default,
233233
//! )?
234234
//! .with_behaviour(|_| ping::Behaviour::default())?
235+
//! .with_swarm_config(|cfg| {
236+
//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX))
237+
//! }) // Allows us to observe pings indefinitely.
235238
//! .build();
236239
//!
237240
//! Ok(())
@@ -284,6 +287,9 @@
284287
//! yamux::Config::default,
285288
//! )?
286289
//! .with_behaviour(|_| ping::Behaviour::default())?
290+
//! .with_swarm_config(|cfg| {
291+
//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX))
292+
//! }) // Allows us to observe pings indefinitely.
287293
//! .build();
288294
//!
289295
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned
@@ -329,6 +335,9 @@
329335
//! yamux::Config::default,
330336
//! )?
331337
//! .with_behaviour(|_| ping::Behaviour::default())?
338+
//! .with_swarm_config(|cfg| {
339+
//! cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX))
340+
//! }) // Allows us to observe pings indefinitely.
332341
//! .build();
333342
//!
334343
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned

0 commit comments

Comments
 (0)