Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tutorial): import dependencies via meta crate #4949

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions libp2p/src/tutorials/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! edition = "2021"
//!
//! [dependencies]
//! libp2p = { version = "0.52", features = ["tcp", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] }
//! libp2p = { version = "0.52", features = ["tcp", "tls", "dns", "async-std", "noise", "yamux", "websocket", "ping", "macros"] }
//! futures = "0.3.21"
//! async-std = { version = "1.12.0", features = ["attributes"] }
//! tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down Expand Up @@ -95,7 +95,6 @@
//! trait.
//!
//! ```rust
//! use libp2p::{identity, PeerId};
//! use std::error::Error;
//! use tracing_subscriber::EnvFilter;
//!
Expand All @@ -106,9 +105,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?;
//!
//! Ok(())
Expand Down Expand Up @@ -138,8 +137,7 @@
//! With the above in mind, let's extend our example, creating a [`ping::Behaviour`](crate::ping::Behaviour) at the end:
//!
//! ```rust
//! use libp2p::swarm::NetworkBehaviour;
//! use libp2p::{identity, ping, PeerId};
//! use libp2p::ping;
//! use tracing_subscriber::EnvFilter;
//! use std::error::Error;
//!
Expand All @@ -150,9 +148,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?
//! .with_behaviour(|_| ping::Behaviour::default())?;
//!
Expand All @@ -168,8 +166,7 @@
//! to the [`Transport`] as well as events from the [`Transport`] to the [`NetworkBehaviour`].
//!
//! ```rust
//! use libp2p::swarm::NetworkBehaviour;
//! use libp2p::{identity, ping, PeerId};
//! use libp2p::ping;
//! use std::error::Error;
//! use tracing_subscriber::EnvFilter;
//!
Expand All @@ -180,9 +177,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?
//! .with_behaviour(|_| ping::Behaviour::default())?
//! .build();
Expand All @@ -202,8 +199,7 @@
//! Thus, without any other behaviour in place, we would not be able to observe the pings.
//!
//! ```rust
//! use libp2p::swarm::NetworkBehaviour;
//! use libp2p::{identity, ping, PeerId};
//! use libp2p::ping;
//! use std::error::Error;
//! use std::time::Duration;
//! use tracing_subscriber::EnvFilter;
Expand All @@ -215,9 +211,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?
//! .with_behaviour(|_| ping::Behaviour::default())?
//! .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.
Expand Down Expand Up @@ -254,7 +250,7 @@
//! remote peer.
//!
//! ```rust
//! use libp2p::{identity, ping, Multiaddr, PeerId};
//! use libp2p::{ping, Multiaddr};
//! use std::error::Error;
//! use std::time::Duration;
//! use tracing_subscriber::EnvFilter;
Expand All @@ -266,9 +262,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?
//! .with_behaviour(|_| ping::Behaviour::default())?
//! .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.
Expand Down Expand Up @@ -298,8 +294,8 @@
//!
//! ```no_run
//! use futures::prelude::*;
//! use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
//! use libp2p::{identity, ping, Multiaddr, PeerId};
//! use libp2p::swarm::SwarmEvent;
//! use libp2p::{ping, Multiaddr};
//! use std::error::Error;
//! use std::time::Duration;
//! use tracing_subscriber::EnvFilter;
Expand All @@ -311,9 +307,9 @@
//! let mut swarm = libp2p::SwarmBuilder::with_new_identity()
//! .with_async_std()
//! .with_tcp(
//! libp2p_tcp::Config::default(),
//! libp2p_tls::Config::new,
//! libp2p_yamux::Config::default,
//! libp2p::tcp::Config::default(),
//! libp2p::tls::Config::new,
//! libp2p::yamux::Config::default,
//! )?
//! .with_behaviour(|_| ping::Behaviour::default())?
//! .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(30))) // Allows us to observe pings for 30 seconds.
Expand Down