diff --git a/Cargo.lock b/Cargo.lock index 257d03dc90e..636ee1e161a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2715,20 +2715,16 @@ version = "0.15.1" dependencies = [ "asynchronous-codec", "bytes", - "clap 4.1.11", "either", "env_logger 0.10.0", "futures", "futures-timer", "instant", "libp2p-core", - "libp2p-identify", "libp2p-identity", - "libp2p-noise", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", - "libp2p-tcp", "libp2p-yamux", "log", "quick-protobuf", @@ -4054,6 +4050,18 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "relay-server-example" +version = "0.1.0" +dependencies = [ + "async-std", + "async-trait", + "clap 4.1.11", + "env_logger 0.10.0", + "futures", + "libp2p", +] + [[package]] name = "rendezvous-example" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index dc28b91b3e3..739a366a073 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "examples/ipfs-kad", "examples/ipfs-private", "examples/ping-example", + "examples/relay-server", "examples/rendezvous", "identity", "interop-tests", diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml new file mode 100644 index 00000000000..f42753ad977 --- /dev/null +++ b/examples/relay-server/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "relay-server-example" +version = "0.1.0" +edition = "2021" +publish = false +license = "MIT" + +[dependencies] +clap = { version = "4.1.11", features = ["derive"] } +async-std = { version = "1.12", features = ["attributes"] } +async-trait = "0.1" +env_logger = "0.10.0" +futures = "0.3.27" +libp2p = { path = "../../libp2p", features = ["async-std", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay"] } diff --git a/protocols/relay/examples/relay.rs b/examples/relay-server/src/main.rs similarity index 89% rename from protocols/relay/examples/relay.rs rename to examples/relay-server/src/main.rs index 1d6e1dd015f..583b6695708 100644 --- a/protocols/relay/examples/relay.rs +++ b/examples/relay-server/src/main.rs @@ -22,17 +22,16 @@ use clap::Parser; use futures::executor::block_on; use futures::stream::StreamExt; -use libp2p_core::multiaddr::Protocol; -use libp2p_core::upgrade; -use libp2p_core::{Multiaddr, Transport}; -use libp2p_identify as identify; -use libp2p_identity as identity; -use libp2p_identity::PeerId; -use libp2p_noise as noise; -use libp2p_ping as ping; -use libp2p_relay as relay; -use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}; -use libp2p_tcp as tcp; +use libp2p::{ + core::multiaddr::Protocol, + core::upgrade, + core::{Multiaddr, Transport}, + identify, identity, + identity::PeerId, + noise, ping, relay, + swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}, + tcp, +}; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; @@ -55,7 +54,7 @@ fn main() -> Result<(), Box> { noise::NoiseAuthenticated::xx(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), ) - .multiplex(libp2p_yamux::YamuxConfig::default()) + .multiplex(libp2p::yamux::YamuxConfig::default()) .boxed(); let behaviour = Behaviour { @@ -94,7 +93,6 @@ fn main() -> Result<(), Box> { } #[derive(NetworkBehaviour)] -#[behaviour(prelude = "libp2p_swarm::derive_prelude")] struct Behaviour { relay: relay::Behaviour, ping: ping::Behaviour, diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index e7ec57233d6..6dfb561e621 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -29,14 +29,10 @@ thiserror = "1.0" void = "1" [dev-dependencies] -clap = { version = "4.1.11", features = ["derive"] } env_logger = "0.10.0" -libp2p-identify = { path = "../../protocols/identify" } -libp2p-noise = { path = "../../transports/noise" } libp2p-ping = { path = "../../protocols/ping" } libp2p-plaintext = { path = "../../transports/plaintext" } libp2p-swarm = { path = "../../swarm", features = ["macros"] } -libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] } libp2p-yamux = { path = "../../muxers/yamux" } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }