chore(relay): move server example to examples/

Related: #3111.

Pull-Request: #3663.
This commit is contained in:
Thomas Eizinger
2023-03-23 22:38:56 +01:00
committed by GitHub
parent d652c014af
commit fd0983567c
5 changed files with 38 additions and 21 deletions

16
Cargo.lock generated
View File

@ -2715,20 +2715,16 @@ version = "0.15.1"
dependencies = [ dependencies = [
"asynchronous-codec", "asynchronous-codec",
"bytes", "bytes",
"clap 4.1.11",
"either", "either",
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"futures-timer", "futures-timer",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identify",
"libp2p-identity", "libp2p-identity",
"libp2p-noise",
"libp2p-ping", "libp2p-ping",
"libp2p-plaintext", "libp2p-plaintext",
"libp2p-swarm", "libp2p-swarm",
"libp2p-tcp",
"libp2p-yamux", "libp2p-yamux",
"log", "log",
"quick-protobuf", "quick-protobuf",
@ -4054,6 +4050,18 @@ version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 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]] [[package]]
name = "rendezvous-example" name = "rendezvous-example"
version = "0.1.0" version = "0.1.0"

View File

@ -10,6 +10,7 @@ members = [
"examples/ipfs-kad", "examples/ipfs-kad",
"examples/ipfs-private", "examples/ipfs-private",
"examples/ping-example", "examples/ping-example",
"examples/relay-server",
"examples/rendezvous", "examples/rendezvous",
"identity", "identity",
"interop-tests", "interop-tests",

View File

@ -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"] }

View File

@ -22,17 +22,16 @@
use clap::Parser; use clap::Parser;
use futures::executor::block_on; use futures::executor::block_on;
use futures::stream::StreamExt; use futures::stream::StreamExt;
use libp2p_core::multiaddr::Protocol; use libp2p::{
use libp2p_core::upgrade; core::multiaddr::Protocol,
use libp2p_core::{Multiaddr, Transport}; core::upgrade,
use libp2p_identify as identify; core::{Multiaddr, Transport},
use libp2p_identity as identity; identify, identity,
use libp2p_identity::PeerId; identity::PeerId,
use libp2p_noise as noise; noise, ping, relay,
use libp2p_ping as ping; swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent},
use libp2p_relay as relay; tcp,
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}; };
use libp2p_tcp as tcp;
use std::error::Error; use std::error::Error;
use std::net::{Ipv4Addr, Ipv6Addr}; use std::net::{Ipv4Addr, Ipv6Addr};
@ -55,7 +54,7 @@ fn main() -> Result<(), Box<dyn Error>> {
noise::NoiseAuthenticated::xx(&local_key) noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."), .expect("Signing libp2p-noise static DH keypair failed."),
) )
.multiplex(libp2p_yamux::YamuxConfig::default()) .multiplex(libp2p::yamux::YamuxConfig::default())
.boxed(); .boxed();
let behaviour = Behaviour { let behaviour = Behaviour {
@ -94,7 +93,6 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
#[derive(NetworkBehaviour)] #[derive(NetworkBehaviour)]
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
struct Behaviour { struct Behaviour {
relay: relay::Behaviour, relay: relay::Behaviour,
ping: ping::Behaviour, ping: ping::Behaviour,

View File

@ -29,14 +29,10 @@ thiserror = "1.0"
void = "1" void = "1"
[dev-dependencies] [dev-dependencies]
clap = { version = "4.1.11", features = ["derive"] }
env_logger = "0.10.0" env_logger = "0.10.0"
libp2p-identify = { path = "../../protocols/identify" }
libp2p-noise = { path = "../../transports/noise" }
libp2p-ping = { path = "../../protocols/ping" } libp2p-ping = { path = "../../protocols/ping" }
libp2p-plaintext = { path = "../../transports/plaintext" } libp2p-plaintext = { path = "../../transports/plaintext" }
libp2p-swarm = { path = "../../swarm", features = ["macros"] } libp2p-swarm = { path = "../../swarm", features = ["macros"] }
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
libp2p-yamux = { path = "../../muxers/yamux" } libp2p-yamux = { path = "../../muxers/yamux" }
quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" }