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

chore(autonat): move example to examples/ #3662

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"