Skip to content

Commit

Permalink
Move autonatv2 to autonat
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Dec 29, 2023
1 parent 9a85209 commit 4399bab
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 99 deletions.
41 changes: 11 additions & 30 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ members = [
"muxers/test-harness",
"muxers/yamux",
"protocols/autonat",
"protocols/autonatv2",
"protocols/dcutr",
"protocols/floodsub",
"protocols/gossipsub",
Expand Down Expand Up @@ -63,7 +62,7 @@ members = [
"transports/websocket",
"transports/webtransport-websys",
"transports/websocket-websys",
"wasm-tests/webtransport-tests",
"wasm-tests/webtransport-tests", "examples/autonatv2",
]
resolver = "2"

Expand All @@ -75,7 +74,7 @@ asynchronous-codec = { version = "0.7.0" }
futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" }
libp2p = { version = "0.53.2", path = "libp2p" }
libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" }
libp2p-autonat = { version = "0.13.0", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" }
libp2p-core = { version = "0.41.2", path = "core" }
libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" }
Expand Down
12 changes: 12 additions & 0 deletions examples/autonatv2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "autonatv2"
version = "0.1.0"
edition = "2021"
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[lints]
workspace = true
3 changes: 3 additions & 0 deletions examples/autonatv2/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
31 changes: 23 additions & 8 deletions protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,54 @@ name = "libp2p-autonat"
edition = "2021"
rust-version = { workspace = true }
description = "NAT and firewall detection for libp2p"
version = "0.12.0"
version = "0.13.0"
authors = ["David Craven <[email protected]>", "Elena Frank <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]


[dependencies]
async-trait = "0.1"
asynchronous-codec = { workspace = true }
bytes = { version = "1", optional = true }
either = { version = "1.9.0", optional = true }
futures = "0.3"
futures-bounded = { workspace = true, optional = true }
futures-timer = "3.0"
instant = "0.1"
libp2p-core = { workspace = true }
libp2p-swarm = { workspace = true }
libp2p-request-response = { workspace = true }
libp2p-identity = { workspace = true }
libp2p-request-response = { workspace = true, optional = true }
libp2p-swarm = { workspace = true }
quick-protobuf = "0.8"
quick-protobuf-codec = { workspace = true }
rand = "0.8"
rand_core = { version = "0.6", optional = true }
thiserror = { version = "1.0.52", optional = true }
tracing = "0.1.37"
quick-protobuf-codec = { workspace = true }
asynchronous-codec = { workspace = true }
void = { version = "1", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "sync"]}
async-std = { version = "1.10", features = ["attributes"] }
libp2p-swarm-test = { path = "../../swarm-test" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
libp2p-identify = { workspace = true }
libp2p-swarm = { workspace = true, features = ["macros"]}

[features]
default = ["v1", "v2"]
v1 = ["dep:libp2p-request-response"]
v2 = ["dep:bytes", "dep:either", "dep:futures-bounded", "dep:thiserror", "dep:void", "dep:rand_core"]

[lints]
workspace = true

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]

[lints]
workspace = true
10 changes: 10 additions & 0 deletions protocols/autonat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
#[cfg(feature = "v1")]
pub mod v1;

#[cfg(feature = "v2")]
pub mod v2;

#[cfg(feature = "v1")]

Check failure on line 7 in protocols/autonat/src/lib.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/protocols/autonat/src/lib.rs
#[deprecated(since = "0.13.0", note = "Please use `v1` module instead.")]
pub use v1::*;


File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use rand::prelude::*;
use rand_core::OsRng;
use std::fmt::{Debug, Display, Formatter};

use crate::client::handler::dial_request::InternalError;
use crate::{global_only::IpExt, protocol::DialRequest};
use crate::v2::client::handler::dial_request::InternalError;
use crate::v2::{global_only::IpExt, protocol::DialRequest};

use super::handler::{
dial_back,
Expand Down Expand Up @@ -254,7 +254,7 @@ where
}
},
}
let event = crate::client::Event {
let event = crate::v2::client::Event {
tested_addr,
bytes_sent: data_amount,
server: server.unwrap_or(peer_id),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use libp2p_swarm::{
};
use void::Void;

use crate::{protocol, Nonce, DIAL_BACK_PROTOCOL_NAME};
use crate::v2::{protocol, Nonce, DIAL_BACK_PROTOCOL_NAME};

pub struct Handler {
inbound: FuturesSet<io::Result<Nonce>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use std::{
time::Duration,
};

use crate::client::behaviour::Error;
use crate::{
use crate::v2::{
client::behaviour::Error,
generated::structs::{mod_DialResponse::ResponseStatus, DialStatus},
protocol::{
Coder, DialDataRequest, DialDataResponse, DialRequest, DialResponse, Request, Response,
Expand Down Expand Up @@ -268,7 +268,7 @@ async fn start_stream_handle(
&mut checked_addr_idx,
)
.await
.map_err(crate::client::behaviour::Error::from);
.map_err(crate::v2::client::behaviour::Error::from);
InternalStatusUpdate {
tested_addr: checked_addr_idx.and_then(|idx| addrs.get(idx).cloned()),
bytes_sent: data_amount,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use libp2p_core::Multiaddr;
use quick_protobuf_codec::Codec;
use rand::Rng;

use crate::{generated::structs as proto, Nonce};
use crate::v2::{generated::structs as proto, Nonce};

const REQUEST_MAX_SIZE: usize = 4104;
pub(super) const DATA_LEN_LOWER_BOUND: usize = 30_000u32 as usize;
Expand Down Expand Up @@ -310,10 +310,10 @@ impl DialBack {

#[cfg(test)]
mod tests {
use crate::generated::structs::{
use crate::v2::generated::structs::{
mod_Message::OneOfmsg, DialDataResponse as GenDialDataResponse, Message,
};
use crate::protocol::{Coder, DialDataResponse, Request};
use crate::v2::protocol::{Coder, DialDataResponse, Request};
use futures::io::Cursor;

use rand::{thread_rng, Rng};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
task::{Context, Poll},
};

use crate::server::handler::dial_request::DialBackStatus;
use crate::v2::server::handler::dial_request::DialBackStatus;
use either::Either;
use libp2p_core::{transport::PortUse, Endpoint, Multiaddr};
use libp2p_identity::PeerId;
Expand All @@ -15,7 +15,7 @@ use libp2p_swarm::{
use libp2p_swarm::{dial_opts::PeerCondition, ConnectionClosed};
use rand_core::{OsRng, RngCore};

use crate::server::handler::{
use crate::v2::server::handler::{
dial_back,
dial_request::{self, DialBackCommand},
Handler,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use libp2p_swarm::{
SubstreamProtocol,
};

use crate::{protocol::dial_back, DIAL_BACK_PROTOCOL_NAME};
use crate::v2::{protocol::dial_back, DIAL_BACK_PROTOCOL_NAME};

use super::dial_request::{DialBackCommand, DialBackStatus as DialBackRes};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use libp2p_swarm::{
};
use rand_core::RngCore;

use crate::{
use crate::v2::{
generated::structs::{mod_DialResponse::ResponseStatus, DialStatus},
protocol::{Coder, DialDataRequest, DialRequest, DialResponse, Request, Response},
server::behaviour::StatusUpdate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libp2p_autonatv2::client::{self, Config};
use libp2p_autonatv2::server;
use libp2p_autonat::v2::client::{self, Config};
use libp2p_autonat::v2::server;
use libp2p_core::transport::TransportError;
use libp2p_core::Multiaddr;
use libp2p_swarm::{
Expand Down Expand Up @@ -430,7 +430,7 @@ async fn dial_back_to_not_supporting() {

async fn new_server() -> Swarm<CombinedServer> {
let mut node = Swarm::new_ephemeral(|identity| CombinedServer {
autonat: libp2p_autonatv2::server::Behaviour::default(),
autonat: libp2p_autonat::v2::server::Behaviour::default(),
identify: libp2p_identify::Behaviour::new(libp2p_identify::Config::new(
"/libp2p-test/1.0.0".into(),
identity.public().clone(),
Expand All @@ -443,7 +443,7 @@ async fn new_server() -> Swarm<CombinedServer> {

async fn new_client() -> Swarm<CombinedClient> {
let mut node = Swarm::new_ephemeral(|identity| CombinedClient {
autonat: libp2p_autonatv2::client::Behaviour::new(
autonat: libp2p_autonat::v2::client::Behaviour::new(
OsRng,
Config::default().with_recheck_interval(Duration::from_millis(100)),
),
Expand All @@ -459,14 +459,14 @@ async fn new_client() -> Swarm<CombinedClient> {
#[derive(libp2p_swarm::NetworkBehaviour)]
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
struct CombinedServer {
autonat: libp2p_autonatv2::server::Behaviour,
autonat: libp2p_autonat::v2::server::Behaviour,
identify: libp2p_identify::Behaviour,
}

#[derive(libp2p_swarm::NetworkBehaviour)]
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
struct CombinedClient {
autonat: libp2p_autonatv2::client::Behaviour,
autonat: libp2p_autonat::v2::client::Behaviour,
identify: libp2p_identify::Behaviour,
}

Expand Down
Loading

0 comments on commit 4399bab

Please sign in to comment.