{
/// Error during the negotiation process.
diff --git a/core/src/upgrade/pending.rs b/core/src/upgrade/pending.rs
index 5e3c65422f1..c4841d8d5d7 100644
--- a/core/src/upgrade/pending.rs
+++ b/core/src/upgrade/pending.rs
@@ -19,13 +19,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
-use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
+use std::{convert::Infallible, iter};
+
use futures::future;
-use std::convert::Infallible;
-use std::iter;
-/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] that always
-/// returns a pending upgrade.
+use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
+
+/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and
+/// [`OutboundUpgrade`] that always returns a pending upgrade.
#[derive(Debug, Copy, Clone)]
pub struct PendingUpgrade {
protocol_name: P,
diff --git a/core/src/upgrade/ready.rs b/core/src/upgrade/ready.rs
index 13270aa8b6d..f77b8c2ef96 100644
--- a/core/src/upgrade/ready.rs
+++ b/core/src/upgrade/ready.rs
@@ -19,12 +19,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
-use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
+use std::{convert::Infallible, iter};
+
use futures::future;
-use std::convert::Infallible;
-use std::iter;
-/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and [`OutboundUpgrade`] that directly yields the substream.
+use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
+
+/// Implementation of [`UpgradeInfo`], [`InboundUpgrade`] and
+/// [`OutboundUpgrade`] that directly yields the substream.
#[derive(Debug, Copy, Clone)]
pub struct ReadyUpgrade
{
protocol_name: P,
diff --git a/core/src/upgrade/select.rs b/core/src/upgrade/select.rs
index 037045a2f29..d3beea96b50 100644
--- a/core/src/upgrade/select.rs
+++ b/core/src/upgrade/select.rs
@@ -18,17 +18,24 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
-use crate::either::EitherFuture;
-use crate::upgrade::{
- InboundConnectionUpgrade, InboundUpgrade, OutboundConnectionUpgrade, OutboundUpgrade,
- UpgradeInfo,
-};
+use std::iter::{Chain, Map};
+
use either::Either;
use futures::future;
-use std::iter::{Chain, Map};
-/// Upgrade that combines two upgrades into one. Supports all the protocols supported by either
-/// sub-upgrade.
+use crate::{
+ either::EitherFuture,
+ upgrade::{
+ InboundConnectionUpgrade,
+ InboundUpgrade,
+ OutboundConnectionUpgrade,
+ OutboundUpgrade,
+ UpgradeInfo,
+ },
+};
+
+/// Upgrade that combines two upgrades into one. Supports all the protocols
+/// supported by either sub-upgrade.
///
/// The protocols supported by the first element have a higher priority.
#[derive(Debug, Clone)]
diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs
index d8bec6f2b59..b9733e38322 100644
--- a/core/tests/transport_upgrade.rs
+++ b/core/tests/transport_upgrade.rs
@@ -18,18 +18,19 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
+use std::{io, pin::Pin};
+
use futures::prelude::*;
-use libp2p_core::transport::{DialOpts, ListenerId, MemoryTransport, PortUse, Transport};
-use libp2p_core::upgrade::{
- self, InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo,
+use libp2p_core::{
+ transport::{DialOpts, ListenerId, MemoryTransport, PortUse, Transport},
+ upgrade::{self, InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo},
+ Endpoint,
};
-use libp2p_core::Endpoint;
use libp2p_identity as identity;
use libp2p_mplex::MplexConfig;
use libp2p_noise as noise;
use multiaddr::{Multiaddr, Protocol};
use rand::random;
-use std::{io, pin::Pin};
#[derive(Clone)]
struct HelloUpgrade {}
diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs
index def66c4823b..ed4e81c7e63 100644
--- a/examples/autonat/src/bin/autonat_client.rs
+++ b/examples/autonat/src/bin/autonat_client.rs
@@ -20,15 +20,21 @@
#![doc = include_str!("../../README.md")]
+use std::{error::Error, net::Ipv4Addr, time::Duration};
+
use clap::Parser;
use futures::StreamExt;
-use libp2p::core::multiaddr::Protocol;
-use libp2p::core::Multiaddr;
-use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
-use libp2p::{autonat, identify, identity, noise, tcp, yamux, PeerId};
-use std::error::Error;
-use std::net::Ipv4Addr;
-use std::time::Duration;
+use libp2p::{
+ autonat,
+ core::{multiaddr::Protocol, Multiaddr},
+ identify,
+ identity,
+ noise,
+ swarm::{NetworkBehaviour, SwarmEvent},
+ tcp,
+ yamux,
+ PeerId,
+};
use tracing_subscriber::EnvFilter;
#[derive(Debug, Parser)]
diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs
index 389cc0fa26f..23873fbba97 100644
--- a/examples/autonat/src/bin/autonat_server.rs
+++ b/examples/autonat/src/bin/autonat_server.rs
@@ -20,14 +20,20 @@
#![doc = include_str!("../../README.md")]
+use std::{error::Error, net::Ipv4Addr, time::Duration};
+
use clap::Parser;
use futures::StreamExt;
-use libp2p::core::{multiaddr::Protocol, Multiaddr};
-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 libp2p::{
+ autonat,
+ core::{multiaddr::Protocol, Multiaddr},
+ identify,
+ identity,
+ noise,
+ swarm::{NetworkBehaviour, SwarmEvent},
+ tcp,
+ yamux,
+};
use tracing_subscriber::EnvFilter;
#[derive(Debug, Parser)]
diff --git a/examples/autonatv2/src/bin/autonatv2_client.rs b/examples/autonatv2/src/bin/autonatv2_client.rs
index de902514dd8..e901074a2e7 100644
--- a/examples/autonatv2/src/bin/autonatv2_client.rs
+++ b/examples/autonatv2/src/bin/autonatv2_client.rs
@@ -4,11 +4,15 @@ use clap::Parser;
use libp2p::{
autonat,
futures::StreamExt,
- identify, identity,
+ identify,
+ identity,
multiaddr::Protocol,
noise,
swarm::{dial_opts::DialOpts, NetworkBehaviour, SwarmEvent},
- tcp, yamux, Multiaddr, SwarmBuilder,
+ tcp,
+ yamux,
+ Multiaddr,
+ SwarmBuilder,
};
use rand::rngs::OsRng;
use tracing_subscriber::EnvFilter;
@@ -73,7 +77,10 @@ async fn main() -> Result<(), Box> {
bytes_sent,
result: Ok(()),
})) => {
- println!("Tested {tested_addr} with {server}. Sent {bytes_sent} bytes for verification. Everything Ok and verified.");
+ println!(
+ "Tested {tested_addr} with {server}. Sent {bytes_sent} bytes for \
+ verification. Everything Ok and verified."
+ );
}
SwarmEvent::Behaviour(BehaviourEvent::Autonat(autonat::v2::client::Event {
server,
@@ -81,7 +88,10 @@ async fn main() -> Result<(), Box> {
bytes_sent,
result: Err(e),
})) => {
- println!("Tested {tested_addr} with {server}. Sent {bytes_sent} bytes for verification. Failed with {e:?}.");
+ println!(
+ "Tested {tested_addr} with {server}. Sent {bytes_sent} bytes for \
+ verification. Failed with {e:?}."
+ );
}
SwarmEvent::ExternalAddrConfirmed { address } => {
println!("External address confirmed: {address}");
diff --git a/examples/autonatv2/src/bin/autonatv2_server.rs b/examples/autonatv2/src/bin/autonatv2_server.rs
index 849ed3b3b0a..555be51ea43 100644
--- a/examples/autonatv2/src/bin/autonatv2_server.rs
+++ b/examples/autonatv2/src/bin/autonatv2_server.rs
@@ -5,11 +5,15 @@ use clap::Parser;
use libp2p::{
autonat,
futures::StreamExt,
- identify, identity,
+ identify,
+ identity,
multiaddr::Protocol,
noise,
swarm::{NetworkBehaviour, SwarmEvent},
- tcp, yamux, Multiaddr, SwarmBuilder,
+ tcp,
+ yamux,
+ Multiaddr,
+ SwarmBuilder,
};
use rand::rngs::OsRng;
diff --git a/examples/browser-webrtc/src/lib.rs b/examples/browser-webrtc/src/lib.rs
index 9499ccbd158..e2d884cb445 100644
--- a/examples/browser-webrtc/src/lib.rs
+++ b/examples/browser-webrtc/src/lib.rs
@@ -1,13 +1,11 @@
#![cfg(target_arch = "wasm32")]
+use std::{io, time::Duration};
+
use futures::StreamExt;
use js_sys::Date;
-use libp2p::core::Multiaddr;
-use libp2p::ping;
-use libp2p::swarm::SwarmEvent;
+use libp2p::{core::Multiaddr, ping, swarm::SwarmEvent};
use libp2p_webrtc_websys as webrtc_websys;
-use std::io;
-use std::time::Duration;
use wasm_bindgen::prelude::*;
use web_sys::{Document, HtmlElement};
diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs
index 7f06b0d0d99..ec6be0c066d 100644
--- a/examples/browser-webrtc/src/main.rs
+++ b/examples/browser-webrtc/src/main.rs
@@ -1,23 +1,27 @@
#![allow(non_upper_case_globals)]
+use std::{
+ net::{Ipv4Addr, SocketAddr},
+ time::Duration,
+};
+
use anyhow::Result;
-use axum::extract::{Path, State};
-use axum::http::header::CONTENT_TYPE;
-use axum::http::StatusCode;
-use axum::response::{Html, IntoResponse};
-use axum::{http::Method, routing::get, Router};
+use axum::{
+ extract::{Path, State},
+ http::{header::CONTENT_TYPE, Method, StatusCode},
+ response::{Html, IntoResponse},
+ routing::get,
+ Router,
+};
use futures::StreamExt;
use libp2p::{
- core::muxing::StreamMuxerBox,
- core::Transport,
+ core::{muxing::StreamMuxerBox, Transport},
multiaddr::{Multiaddr, Protocol},
ping,
swarm::SwarmEvent,
};
use libp2p_webrtc as webrtc;
use rand::thread_rng;
-use std::net::{Ipv4Addr, SocketAddr};
-use std::time::Duration;
use tokio::net::TcpListener;
use tower_http::cors::{Any, CorsLayer};
@@ -127,7 +131,8 @@ struct Libp2pEndpoint(Multiaddr);
/// Serves the index.html file for our client.
///
/// Our server listens on a random UDP port for the WebRTC transport.
-/// To allow the client to connect, we replace the `__LIBP2P_ENDPOINT__` placeholder with the actual address.
+/// To allow the client to connect, we replace the `__LIBP2P_ENDPOINT__`
+/// placeholder with the actual address.
async fn get_index(
State(Libp2pEndpoint(libp2p_endpoint)): State,
) -> Result, StatusCode> {
diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs
index c785d301c2f..83cf649dd5f 100644
--- a/examples/chat/src/main.rs
+++ b/examples/chat/src/main.rs
@@ -20,12 +20,22 @@
#![doc = include_str!("../README.md")]
+use std::{
+ collections::hash_map::DefaultHasher,
+ error::Error,
+ hash::{Hash, Hasher},
+ time::Duration,
+};
+
use futures::stream::StreamExt;
-use libp2p::{gossipsub, mdns, noise, swarm::NetworkBehaviour, swarm::SwarmEvent, tcp, yamux};
-use std::collections::hash_map::DefaultHasher;
-use std::error::Error;
-use std::hash::{Hash, Hasher};
-use std::time::Duration;
+use libp2p::{
+ gossipsub,
+ mdns,
+ noise,
+ swarm::{NetworkBehaviour, SwarmEvent},
+ tcp,
+ yamux,
+};
use tokio::{io, io::AsyncBufReadExt, select};
use tracing_subscriber::EnvFilter;
@@ -51,7 +61,8 @@ async fn main() -> Result<(), Box> {
)?
.with_quic()
.with_behaviour(|key| {
- // To content-address message, we can take the hash of message and use it as an ID.
+ // To content-address message, we can take the hash of message and use it as an
+ // ID.
let message_id_fn = |message: &gossipsub::Message| {
let mut s = DefaultHasher::new();
message.data.hash(&mut s);
@@ -61,7 +72,8 @@ async fn main() -> Result<(), Box> {
// Set a custom gossipsub configuration
let gossipsub_config = gossipsub::ConfigBuilder::default()
.heartbeat_interval(Duration::from_secs(10)) // This is set to aid debugging by not cluttering the log space
- .validation_mode(gossipsub::ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
+ .validation_mode(gossipsub::ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message
+ // signing)
.message_id_fn(message_id_fn) // content-address messages. No two messages of the same content will be propagated.
.build()
.map_err(|msg| io::Error::new(io::ErrorKind::Other, msg))?; // Temporary hack because `build` does not return a proper `std::error::Error`.
diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs
index 630d4b2b1f3..c3990b05a2f 100644
--- a/examples/dcutr/src/main.rs
+++ b/examples/dcutr/src/main.rs
@@ -20,16 +20,23 @@
#![doc = include_str!("../README.md")]
+use std::{error::Error, str::FromStr, time::Duration};
+
use clap::Parser;
use futures::{executor::block_on, future::FutureExt, stream::StreamExt};
use libp2p::{
core::multiaddr::{Multiaddr, Protocol},
- dcutr, identify, identity, noise, ping, relay,
+ dcutr,
+ identify,
+ identity,
+ noise,
+ ping,
+ relay,
swarm::{NetworkBehaviour, SwarmEvent},
- tcp, yamux, PeerId,
+ tcp,
+ yamux,
+ PeerId,
};
-use std::str::FromStr;
-use std::{error::Error, time::Duration};
use tracing_subscriber::EnvFilter;
#[derive(Debug, Parser)]
@@ -136,8 +143,9 @@ async fn main() -> Result<(), Box> {
}
});
- // Connect to the relay server. Not for the reservation or relayed connection, but to (a) learn
- // our local public address and (b) enable a freshly started relay to learn its public address.
+ // Connect to the relay server. Not for the reservation or relayed connection,
+ // but to (a) learn our local public address and (b) enable a freshly
+ // started relay to learn its public address.
swarm.dial(opts.relay_address.clone()).unwrap();
block_on(async {
let mut learned_observed_addr = false;
diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs
index 6b7947b7eb3..10934601c93 100644
--- a/examples/distributed-key-value-store/src/main.rs
+++ b/examples/distributed-key-value-store/src/main.rs
@@ -20,17 +20,18 @@
#![doc = include_str!("../README.md")]
+use std::{error::Error, time::Duration};
+
use futures::stream::StreamExt;
-use libp2p::kad;
-use libp2p::kad::store::MemoryStore;
-use libp2p::kad::Mode;
use libp2p::{
- mdns, noise,
+ kad,
+ kad::{store::MemoryStore, Mode},
+ mdns,
+ noise,
swarm::{NetworkBehaviour, SwarmEvent},
- tcp, yamux,
+ tcp,
+ yamux,
};
-use std::error::Error;
-use std::time::Duration;
use tokio::{
io::{self, AsyncBufReadExt},
select,
diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs
index 5f6be83dc11..1e3b80a330c 100644
--- a/examples/file-sharing/src/main.rs
+++ b/examples/file-sharing/src/main.rs
@@ -22,15 +22,12 @@
mod network;
-use clap::Parser;
-use tokio::task::spawn;
+use std::{error::Error, io::Write, path::PathBuf};
-use futures::prelude::*;
-use futures::StreamExt;
+use clap::Parser;
+use futures::{prelude::*, StreamExt};
use libp2p::{core::Multiaddr, multiaddr::Protocol};
-use std::error::Error;
-use std::io::Write;
-use std::path::PathBuf;
+use tokio::task::spawn;
use tracing_subscriber::EnvFilter;
#[tokio::main]
diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs
index a74afd1c0da..103e1cbe9e2 100644
--- a/examples/file-sharing/src/network.rs
+++ b/examples/file-sharing/src/network.rs
@@ -1,27 +1,33 @@
-use futures::channel::{mpsc, oneshot};
-use futures::prelude::*;
-use futures::StreamExt;
+use std::{
+ collections::{hash_map, HashMap, HashSet},
+ error::Error,
+ time::Duration,
+};
+use futures::{
+ channel::{mpsc, oneshot},
+ prelude::*,
+ StreamExt,
+};
use libp2p::{
core::Multiaddr,
- identity, kad,
+ identity,
+ kad,
multiaddr::Protocol,
noise,
request_response::{self, OutboundRequestId, ProtocolSupport, ResponseChannel},
swarm::{NetworkBehaviour, Swarm, SwarmEvent},
- tcp, yamux, PeerId,
+ tcp,
+ yamux,
+ PeerId,
+ StreamProtocol,
};
-
-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:
///
-/// - The network client to interact with the network layer from anywhere
-/// within your application.
+/// - The network client to interact with the network layer from anywhere within
+/// your application.
///
/// - The network event stream, e.g. for incoming requests.
///
diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs
index 22474061da6..55d093c0399 100644
--- a/examples/identify/src/main.rs
+++ b/examples/identify/src/main.rs
@@ -20,9 +20,10 @@
#![doc = include_str!("../README.md")]
+use std::{error::Error, time::Duration};
+
use futures::StreamExt;
use libp2p::{core::multiaddr::Multiaddr, identify, noise, swarm::SwarmEvent, tcp, yamux};
-use std::{error::Error, time::Duration};
use tracing_subscriber::EnvFilter;
#[tokio::main]
diff --git a/examples/ipfs-kad/src/main.rs b/examples/ipfs-kad/src/main.rs
index 95921d6fa35..9acec089a56 100644
--- a/examples/ipfs-kad/src/main.rs
+++ b/examples/ipfs-kad/src/main.rs
@@ -20,15 +20,25 @@
#![doc = include_str!("../README.md")]
-use std::num::NonZeroUsize;
-use std::ops::Add;
-use std::time::{Duration, Instant};
+use std::{
+ num::NonZeroUsize,
+ ops::Add,
+ time::{Duration, Instant},
+};
use anyhow::{bail, Result};
use clap::Parser;
use futures::StreamExt;
-use libp2p::swarm::{StreamProtocol, SwarmEvent};
-use libp2p::{bytes::BufMut, identity, kad, noise, tcp, yamux, PeerId};
+use libp2p::{
+ bytes::BufMut,
+ identity,
+ kad,
+ noise,
+ swarm::{StreamProtocol, SwarmEvent},
+ tcp,
+ yamux,
+ PeerId,
+};
use tracing_subscriber::EnvFilter;
const BOOTNODES: [&str; 4] = [
diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs
index a57bfd465e0..24727ec80bf 100644
--- a/examples/ipfs-private/src/main.rs
+++ b/examples/ipfs-private/src/main.rs
@@ -20,23 +20,29 @@
#![doc = include_str!("../README.md")]
+use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration};
+
use either::Either;
use futures::prelude::*;
use libp2p::{
core::transport::upgrade::Version,
- gossipsub, identify,
+ gossipsub,
+ identify,
multiaddr::Protocol,
- noise, ping,
+ noise,
+ ping,
pnet::{PnetConfig, PreSharedKey},
swarm::{NetworkBehaviour, SwarmEvent},
- tcp, yamux, Multiaddr, Transport,
+ tcp,
+ yamux,
+ Multiaddr,
+ Transport,
};
-use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration};
use tokio::{io, io::AsyncBufReadExt, select};
use tracing_subscriber::EnvFilter;
-/// Get the current ipfs repo path, either from the IPFS_PATH environment variable or
-/// from the default $HOME/.ipfs
+/// Get the current ipfs repo path, either from the IPFS_PATH environment
+/// variable or from the default $HOME/.ipfs
fn get_ipfs_path() -> Box {
env::var("IPFS_PATH")
.map(|ipfs_path| Path::new(&ipfs_path).into())
@@ -58,8 +64,9 @@ fn get_psk(path: &Path) -> std::io::Result