diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index b071e717731..3fb25aa6222 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -60,6 +60,7 @@ async fn main() -> Result<(), Box> { yamux::Config::default, )? .with_behaviour(|key| Behaviour::new(key.public()))? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.listen_on( diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index d1c0c005861..44a53f0d17f 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -27,6 +27,7 @@ use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{autonat, identify, identity, noise, tcp, yamux}; use std::error::Error; use std::net::Ipv4Addr; +use std::time::Duration; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -52,6 +53,7 @@ async fn main() -> Result<(), Box> { yamux::Config::default, )? .with_behaviour(|key| Behaviour::new(key.public()))? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.listen_on( diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 91beaa02c67..51df670f8a7 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -28,8 +28,8 @@ use libp2p::{ swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, PeerId, }; -use std::error::Error; use std::str::FromStr; +use std::{error::Error, time::Duration}; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -105,6 +105,7 @@ async fn main() -> Result<(), Box> { )), dcutr: dcutr::Behaviour::new(keypair.public().to_peer_id()), })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 1843520838b..404333f3d20 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -31,6 +31,7 @@ use libp2p::{ tcp, yamux, }; use std::error::Error; +use std::time::Duration; use tracing_subscriber::EnvFilter; #[async_std::main] @@ -65,6 +66,7 @@ async fn main() -> Result<(), Box> { )?, }) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm.behaviour_mut().kademlia.set_mode(Some(Mode::Server)); diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index ad5418193a4..59625fc39ea 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -15,6 +15,7 @@ use libp2p::StreamProtocol; use serde::{Deserialize, Serialize}; use std::collections::{hash_map, HashMap, HashSet}; use std::error::Error; +use std::time::Duration; /// Creates the network components, namely: /// @@ -58,6 +59,7 @@ pub(crate) async fn new( request_response::Config::default(), ), })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); swarm diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 3c40addbcf8..916317a5a43 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -22,7 +22,7 @@ use futures::StreamExt; use libp2p::{core::multiaddr::Multiaddr, identify, noise, swarm::SwarmEvent, tcp, yamux}; -use std::error::Error; +use std::{error::Error, time::Duration}; use tracing_subscriber::EnvFilter; #[async_std::main] @@ -44,6 +44,7 @@ async fn main() -> Result<(), Box> { key.public(), )) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); // Tell the swarm to listen on all interfaces and a random, OS-assigned diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 12bd985cdf0..a57bfd465e0 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -31,7 +31,7 @@ use libp2p::{ swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Multiaddr, Transport, }; -use std::{env, error::Error, fs, path::Path, str::FromStr}; +use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; use tokio::{io, io::AsyncBufReadExt, select}; use tracing_subscriber::EnvFilter; @@ -151,6 +151,7 @@ async fn main() -> Result<(), Box> { ping: ping::Behaviour::new(ping::Config::new()), }) })? + .with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60))) .build(); println!("Subscribing to {gossipsub_topic:?}");