diff --git a/Cargo.lock b/Cargo.lock index a8793ec..ba8637a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -346,7 +346,7 @@ dependencies = [ [[package]] name = "boot-node" -version = "0.4.0" +version = "0.5.0" dependencies = [ "camino", "clap", @@ -1359,6 +1359,7 @@ dependencies = [ "getrandom", "instant", "libp2p-allow-block-list", + "libp2p-autonat", "libp2p-connection-limits", "libp2p-core", "libp2p-dcutr", @@ -1397,6 +1398,27 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-autonat" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95151726170e41b591735bf95c42b888fe4aa14f65216a9fbf0edcc04510586" +dependencies = [ + "async-trait", + "asynchronous-codec 0.6.2", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-request-response", + "libp2p-swarm", + "quick-protobuf", + "quick-protobuf-codec 0.2.0", + "rand", + "tracing", +] + [[package]] name = "libp2p-connection-limits" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 211b0c8..dc151a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "examples/dcutr", "examples/chat"] [package] name = "boot-node" -version = "0.4.0" +version = "0.5.0" authors = ["Calimero Limited "] edition = "2021" repository = "https://github.com/calimero-network/boot-node" @@ -15,6 +15,7 @@ clap = { version = "4.5.4", features = ["derive", "env"] } eyre = "0.6.12" futures-util = "0.3.30" libp2p = { version = "0.53.2", features = [ + "autonat", "identify", "kad", "macros", diff --git a/src/main.rs b/src/main.rs index f430010..333fba8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ use std::net::Ipv4Addr; use clap::Parser; use libp2p::futures::prelude::*; use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; -use libp2p::{identify, identity, kad, ping, relay, rendezvous, Multiaddr, StreamProtocol, Swarm}; +use libp2p::{ + autonat, identify, identity, kad, ping, relay, rendezvous, Multiaddr, StreamProtocol, Swarm, +}; use tracing::info; use tracing_subscriber::prelude::*; use tracing_subscriber::EnvFilter; @@ -13,11 +15,12 @@ const CALIMERO_KAD_PROTO_NAME: StreamProtocol = StreamProtocol::new("/calimero/k #[derive(NetworkBehaviour)] struct Behaviour { + autonat: autonat::Behaviour, identify: identify::Behaviour, kad: kad::Behaviour, ping: ping::Behaviour, - rendezvous: rendezvous::server::Behaviour, relay: relay::Behaviour, + rendezvous: rendezvous::server::Behaviour, } #[derive(Debug, Parser)] @@ -61,6 +64,7 @@ async fn main() -> eyre::Result<()> { )? .with_quic() .with_behaviour(|keypair| Behaviour { + autonat: autonat::Behaviour::new(peer_id.clone(), Default::default()), identify: identify::Behaviour::new(identify::Config::new( PROTOCOL_VERSION.to_owned(), keypair.public(), @@ -127,6 +131,9 @@ async fn handle_swarm_event(swarm: &mut Swarm, event: SwarmEvent, event: BehaviourEvent) { match event { + BehaviourEvent::Autonat(event) => { + info!("AutoNat event: {event:?}"); + } BehaviourEvent::Identify(event) => { info!("Identify event: {event:?}"); match event { @@ -143,12 +150,12 @@ async fn handle_swarm_behaviour_event(swarm: &mut Swarm, event: Behav BehaviourEvent::Kad(event) => { info!("Kad event: {event:?}"); } - BehaviourEvent::Rendezvous(event) => { - info!("Rendezvous event: {event:?}"); - } BehaviourEvent::Relay(event) => { info!("Relay event: {event:?}"); } + BehaviourEvent::Rendezvous(event) => { + info!("Rendezvous event: {event:?}"); + } _ => {} } }