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

*: Remove use of development_transport in examples and tests #3056

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
- Introduce [`libp2p-tls` `v0.1.0`](transports/tls/CHANGELOG.md#010). See [PR 2945].
- Update individual crates.
- Update to [`libp2p-tcp` `v0.38.0`](transports/tcp/CHANGELOG.md#0380).
- Deprecate `development_transport` and `tokio_development_transport`. See [PR 3056].

[PR 3001]: https://github.com/libp2p/rust-libp2p/pull/3001
[PR 2945]: https://github.com/libp2p/rust-libp2p/pull/2945
[PR 3056]: https://github.com/libp2p/rust-libp2p/pull/3056

# 0.49.0

Expand Down
11 changes: 8 additions & 3 deletions examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ use futures::{
select,
};
use libp2p::{
core::{upgrade::Version, Transport},
floodsub::{self, Floodsub, FloodsubEvent},
identity,
mdns::{Mdns, MdnsConfig, MdnsEvent},
noise,
swarm::SwarmEvent,
Multiaddr, NetworkBehaviour, PeerId, Swarm,
tcp, yamux, Multiaddr, NetworkBehaviour, PeerId, Swarm,
};
use std::error::Error;

Expand All @@ -72,8 +74,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

// Set up an encrypted DNS-enabled TCP Transport over the Mplex and Yamux protocols
let transport = libp2p::development_transport(local_key).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

// Create a Floodsub topic
let floodsub_topic = floodsub::Topic::new("chat");
Expand Down
13 changes: 9 additions & 4 deletions examples/distributed-key-value-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ use libp2p::kad::{
Quorum, Record,
};
use libp2p::{
development_transport, identity,
core::{upgrade::Version, Transport},
identity,
mdns::{Mdns, MdnsConfig, MdnsEvent},
noise,
swarm::SwarmEvent,
NetworkBehaviour, PeerId, Swarm,
tcp, yamux, NetworkBehaviour, PeerId, Swarm,
};
use std::error::Error;

Expand All @@ -63,8 +65,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

// Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol.
let transport = development_transport(local_key).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

// We create a custom network behaviour that combines Kademlia and mDNS.
#[derive(NetworkBehaviour)]
Expand Down
11 changes: 9 additions & 2 deletions examples/file-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ use async_std::io;
use async_std::task::spawn;
use clap::Parser;
use futures::prelude::*;
use libp2p::core::{Multiaddr, PeerId};
use libp2p::core::{upgrade::Version, Multiaddr, PeerId, Transport};
use libp2p::multiaddr::Protocol;
use libp2p::noise;
use libp2p::tcp;
use libp2p::yamux;
use std::error::Error;
use std::io::Write;
use std::path::PathBuf;
Expand Down Expand Up @@ -252,7 +255,11 @@ mod network {
// Build the Swarm, connecting the lower layer transport logic with the
// higher layer network behaviour logic.
let swarm = SwarmBuilder::new(
libp2p::development_transport(id_keys).await?,
tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys)?)
.multiplex(yamux::YamuxConfig::default())
.boxed(),
ComposedBehaviour {
kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)),
request_response: RequestResponse::new(
Expand Down
12 changes: 10 additions & 2 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@
use async_std::io;
use env_logger::{Builder, Env};
use futures::{prelude::*, select};
use libp2p::core::upgrade::Version;
use libp2p::core::Transport;
use libp2p::gossipsub::MessageId;
use libp2p::gossipsub::{
GossipsubEvent, GossipsubMessage, IdentTopic as Topic, MessageAuthenticity, ValidationMode,
};
use libp2p::noise;
use libp2p::tcp;
use libp2p::yamux;
use libp2p::{gossipsub, identity, swarm::SwarmEvent, Multiaddr, PeerId};
use std::collections::hash_map::DefaultHasher;
use std::error::Error;
Expand All @@ -68,8 +73,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

// Set up an encrypted TCP Transport over the Mplex and Yamux protocols
let transport = libp2p::development_transport(local_key.clone()).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();

// Create a Gossipsub topic
let topic = Topic::new("test-net");
Expand Down
13 changes: 9 additions & 4 deletions examples/ipfs-kad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ use futures::StreamExt;
use libp2p::kad::record::store::MemoryStore;
use libp2p::kad::{GetClosestPeersError, Kademlia, KademliaConfig, KademliaEvent, QueryResult};
use libp2p::{
development_transport, identity,
core::upgrade::Version,
core::Transport,
identity, noise,
swarm::{Swarm, SwarmEvent},
Multiaddr, PeerId,
tcp, yamux, Multiaddr, PeerId,
};
use std::{env, error::Error, str::FromStr, time::Duration};

Expand All @@ -49,8 +51,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

// Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol
let transport = development_transport(local_key).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

// Create a swarm to manage peers and events.
let mut swarm = {
Expand Down
10 changes: 8 additions & 2 deletions examples/mdns-passive-discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

use futures::StreamExt;
use libp2p::{
core::{upgrade::Version, Transport},
identity,
mdns::{Mdns, MdnsConfig, MdnsEvent},
noise,
swarm::{Swarm, SwarmEvent},
PeerId,
tcp, yamux, PeerId,
};
use std::error::Error;

Expand All @@ -37,7 +39,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {:?}", peer_id);

// Create a transport.
let transport = libp2p::development_transport(id_keys).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

// Create an MDNS network behaviour.
let behaviour = Mdns::new(MdnsConfig::default())?;
Expand Down
11 changes: 9 additions & 2 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@

use futures::prelude::*;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::{identity, ping, Multiaddr, NetworkBehaviour, PeerId};
use libp2p::{
core::{upgrade::Version, Transport},
identity, noise, ping, tcp, yamux, Multiaddr, NetworkBehaviour, PeerId,
};
use libp2p_swarm::keep_alive;
use std::error::Error;

Expand All @@ -52,7 +55,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let transport = libp2p::development_transport(local_key).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

let mut swarm = Swarm::new(transport, Behaviour::default(), local_peer_id);

Expand Down
11 changes: 9 additions & 2 deletions misc/metrics/examples/metrics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ use futures::stream::StreamExt;
use libp2p::core::Multiaddr;
use libp2p::metrics::{Metrics, Recorder};
use libp2p::swarm::SwarmEvent;
use libp2p::{identity, ping, NetworkBehaviour, PeerId, Swarm};
use libp2p::{
core::{upgrade::Version, Transport},
identity, noise, ping, tcp, yamux, NetworkBehaviour, PeerId, Swarm,
};
use libp2p_swarm::keep_alive;
use log::info;
use prometheus_client::registry::Registry;
Expand All @@ -71,7 +74,11 @@ fn main() -> Result<(), Box<dyn Error>> {
info!("Local peer id: {:?}", local_peer_id);

let mut swarm = Swarm::new(
block_on(libp2p::development_transport(local_key))?,
tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed(),
Behaviour::default(),
local_peer_id,
);
Expand Down
11 changes: 10 additions & 1 deletion protocols/autonat/examples/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
use clap::Parser;
use futures::prelude::*;
use libp2p::autonat;
use libp2p::core::Transport;
use libp2p::identify;
use libp2p::multiaddr::Protocol;
use libp2p::noise;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::tcp;
use libp2p::yamux;
use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId};
use libp2p_core::upgrade::Version;
use std::error::Error;
use std::net::Ipv4Addr;
use std::time::Duration;
Expand Down Expand Up @@ -63,7 +68,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let transport = libp2p::development_transport(local_key.clone()).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

let behaviour = Behaviour::new(local_key.public());

Expand Down
11 changes: 10 additions & 1 deletion protocols/autonat/examples/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ use futures::prelude::*;
use libp2p::autonat;
use libp2p::identify;
use libp2p::multiaddr::Protocol;
use libp2p::noise;
use libp2p::swarm::{Swarm, SwarmEvent};
use libp2p::tcp;
use libp2p::yamux;
use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId};
use libp2p_core::upgrade::Version;
use libp2p_core::Transport;
use std::error::Error;
use std::net::Ipv4Addr;

Expand All @@ -53,7 +58,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let transport = libp2p::development_transport(local_key.clone()).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

let behaviour = Behaviour::new(local_key.public());

Expand Down
12 changes: 9 additions & 3 deletions protocols/autonat/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
use futures::{channel::oneshot, Future, FutureExt, StreamExt};
use futures_timer::Delay;
use libp2p::{
development_transport,
core::upgrade::Version,
core::Transport,
identity::Keypair,
noise,
swarm::{AddressScore, Swarm, SwarmEvent},
Multiaddr, PeerId,
tcp, yamux, Multiaddr, PeerId,
};
use libp2p_autonat::{
Behaviour, Config, Event, NatStatus, OutboundProbeError, OutboundProbeEvent, ResponseError,
Expand All @@ -38,7 +40,11 @@ const TEST_REFRESH_INTERVAL: Duration = Duration::from_secs(2);
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
let keypair = Keypair::generate_ed25519();
let local_id = PeerId::from_public_key(&keypair.public());
let transport = development_transport(keypair).await.unwrap();
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();
let behaviour = Behaviour::new(local_id, config);
Swarm::new(transport, behaviour, local_id)
}
Expand Down
12 changes: 9 additions & 3 deletions protocols/autonat/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ use futures_timer::Delay;
use libp2p::core::{ConnectedPoint, Endpoint};
use libp2p::swarm::DialError;
use libp2p::{
development_transport,
core::upgrade::Version,
core::Transport,
identity::Keypair,
multiaddr::Protocol,
noise,
swarm::{AddressScore, Swarm, SwarmEvent},
Multiaddr, PeerId,
tcp, yamux, Multiaddr, PeerId,
};
use libp2p_autonat::{
Behaviour, Config, Event, InboundProbeError, InboundProbeEvent, ResponseError,
Expand All @@ -37,7 +39,11 @@ use std::{num::NonZeroU32, time::Duration};
async fn init_swarm(config: Config) -> Swarm<Behaviour> {
let keypair = Keypair::generate_ed25519();
let local_id = PeerId::from_public_key(&keypair.public());
let transport = development_transport(keypair).await.unwrap();
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();
let behaviour = Behaviour::new(local_id, config);
Swarm::new(transport, behaviour, local_id)
}
Expand Down
11 changes: 9 additions & 2 deletions protocols/identify/examples/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
//! and will send each other identify info which is then printed to the console.

use futures::prelude::*;
use libp2p::{identify, identity, Multiaddr, PeerId};
use libp2p::{
core::{upgrade::Version, Transport},
identify, identity, noise, tcp, yamux, Multiaddr, PeerId,
};
use libp2p_swarm::{Swarm, SwarmEvent};
use std::error::Error;

Expand All @@ -47,7 +50,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);

let transport = libp2p::development_transport(local_key.clone()).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

// Create a identify network behaviour.
let behaviour = identify::Behaviour::new(identify::Config::new(
Expand Down
10 changes: 8 additions & 2 deletions protocols/mdns/tests/use-async-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

use futures::StreamExt;
use libp2p::{
core::{upgrade::Version, Transport},
identity,
mdns::{Mdns, MdnsConfig, MdnsEvent},
noise,
swarm::{Swarm, SwarmEvent},
PeerId,
tcp, yamux, PeerId,
};
use std::error::Error;
use std::time::Duration;
Expand Down Expand Up @@ -60,7 +62,11 @@ async fn test_expired_async_std() -> Result<(), Box<dyn Error>> {
async fn create_swarm(config: MdnsConfig) -> Result<Swarm<Mdns>, Box<dyn Error>> {
let id_keys = identity::Keypair::generate_ed25519();
let peer_id = PeerId::from(id_keys.public());
let transport = libp2p::development_transport(id_keys).await?;
let transport = tcp::TcpTransport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();
let behaviour = Mdns::new(config)?;
let mut swarm = Swarm::new(transport, behaviour, peer_id);
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
Expand Down
Loading