Skip to content

Commit

Permalink
chore(autonat): move example to examples/
Browse files Browse the repository at this point in the history
Related: #3111.

Pull-Request: #3662.
  • Loading branch information
thomaseizinger committed Mar 23, 2023
1 parent 3f99c31 commit d652c01
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 43 deletions.
16 changes: 11 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"core",
"examples/chat-example",
"examples/autonat",
"examples/dcutr",
"examples/distributed-key-value-store",
"examples/file-sharing",
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions examples/autonat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"

0 comments on commit d652c01

Please sign in to comment.