chore(autonat): move example to examples/

Related: #3111.

Pull-Request: #3662.
This commit is contained in:
Thomas Eizinger 2023-03-23 22:10:52 +01:00 committed by GitHub
parent 3f99c31bb3
commit d652c014af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 43 deletions

16
Cargo.lock generated
View File

@ -445,6 +445,17 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "autonat-example"
version = "0.1.0"
dependencies = [
"async-std",
"clap 4.1.11",
"env_logger 0.10.0",
"futures",
"libp2p",
]
[[package]]
name = "base-x"
version = "0.2.11"
@ -2213,20 +2224,15 @@ version = "0.10.1"
dependencies = [
"async-std",
"async-trait",
"clap 4.1.11",
"env_logger 0.10.0",
"futures",
"futures-timer",
"instant",
"libp2p-core",
"libp2p-identify",
"libp2p-identity",
"libp2p-noise",
"libp2p-request-response",
"libp2p-swarm",
"libp2p-swarm-test",
"libp2p-tcp",
"libp2p-yamux",
"log",
"quick-protobuf",
"rand 0.8.5",

View File

@ -2,6 +2,7 @@
members = [
"core",
"examples/chat-example",
"examples/autonat",
"examples/dcutr",
"examples/distributed-key-value-store",
"examples/file-sharing",

View File

@ -7,7 +7,7 @@ A set of examples showcasing how to use rust-libp2p.
## Individual libp2p features
- [Chat](./chat-example) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols.
- [Chat](./autonat) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols.
- [Distributed key-value store](./distributed-key-value-store) A basic key value store demonstrating libp2p and the mDNS and Kademlia protocol.
- [File sharing application](./file-sharing) Basic file sharing application with peers either providing or locating and getting files by name.

View File

@ -0,0 +1,13 @@
[package]
name = "autonat-example"
version = "0.1.0"
edition = "2021"
publish = false
license = "MIT"
[dependencies]
async-std = { version = "1.12", features = ["attributes"] }
clap = { version = "4.1.11", features = ["derive"] }
env_logger = "0.10.0"
futures = "0.3.27"
libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] }

View File

@ -25,22 +25,16 @@
//!
//! To run this example, follow the instructions in `examples/server` to start a server, then run in a new terminal:
//! ```sh
//! cargo run --example client -- --server-address <server-addr> --server-peer-id <server-peer-id> --listen-port <port>
//! cargo run --bin autonat_client -- --server-address <server-addr> --server-peer-id <server-peer-id> --listen-port <port>
//! ```
//! The `listen-port` parameter is optional and allows to set a fixed port at which the local client should listen.
use clap::Parser;
use futures::prelude::*;
use libp2p_autonat as autonat;
use libp2p_core::multiaddr::Protocol;
use libp2p_core::{upgrade::Version, Multiaddr, Transport};
use libp2p_identify as identify;
use libp2p_identity as identity;
use libp2p_identity::PeerId;
use libp2p_noise as noise;
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use libp2p::core::multiaddr::Protocol;
use libp2p::core::{upgrade::Version, Multiaddr, Transport};
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p::{autonat, identify, identity, noise, tcp, yamux, PeerId};
use std::error::Error;
use std::net::Ipv4Addr;
use std::time::Duration;
@ -99,7 +93,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "Event", prelude = "libp2p_swarm::derive_prelude")]
struct Behaviour {
identify: identify::Behaviour,
auto_nat: autonat::Behaviour,

View File

@ -22,21 +22,15 @@
//!
//! To start the server run:
//! ```sh
//! cargo run --example server -- --listen-port <port>
//! cargo run --bin autonat_server -- --listen-port <port>
//! ```
//! The `listen-port` parameter is optional and allows to set a fixed port at which the local peer should listen.
use clap::Parser;
use futures::prelude::*;
use libp2p_autonat as autonat;
use libp2p_core::{multiaddr::Protocol, upgrade::Version, Multiaddr, Transport};
use libp2p_identify as identify;
use libp2p_identity as identity;
use libp2p_identity::PeerId;
use libp2p_noise as noise;
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use libp2p::core::{multiaddr::Protocol, upgrade::Version, Multiaddr, Transport};
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p::{autonat, identify, identity, noise, tcp, yamux, PeerId};
use std::error::Error;
use std::net::Ipv4Addr;
@ -83,7 +77,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "Event", prelude = "libp2p_swarm::derive_prelude")]
struct Behaviour {
identify: identify::Behaviour,
auto_nat: autonat::Behaviour,

View File

@ -25,13 +25,7 @@ quick-protobuf = "0.8"
[dev-dependencies]
async-std = { version = "1.10", features = ["attributes"] }
clap = { version = "4.1.11", features = ["derive"] }
env_logger = "0.10"
libp2p-identify = { path = "../identify" }
libp2p-noise = { path = "../../transports/noise" }
libp2p-swarm = { path = "../../swarm", features = ["async-std", "macros"] }
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
libp2p-yamux = { path = "../../muxers/yamux" }
libp2p-swarm-test = { path = "../../swarm-test" }
# Passing arguments to the docsrs builder in order to properly document cfg's.
@ -40,11 +34,3 @@ libp2p-swarm-test = { path = "../../swarm-test" }
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]
[[example]]
name = "client"
path = "examples/autonat_client.rs"
[[example]]
name = "server"
path = "examples/autonat_server.rs"