diff --git a/Cargo.lock b/Cargo.lock index 8ed539e5d2e..af3ceb9eb0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,7 +2698,6 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "instant", "libp2p-core", "libp2p-identify", "libp2p-identity", @@ -2714,6 +2713,7 @@ dependencies = [ "tracing", "tracing-subscriber", "void", + "web-time 1.1.0", ] [[package]] diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 76d0970ca13..def66c4823b 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -19,7 +19,6 @@ // DEALINGS IN THE SOFTWARE. #![doc = include_str!("../../README.md")] -#![allow(deprecated)] use clap::Parser; use futures::StreamExt; diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index 9b6ccfef92c..389cc0fa26f 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -19,7 +19,6 @@ // DEALINGS IN THE SOFTWARE. #![doc = include_str!("../../README.md")] -#![allow(deprecated)] use clap::Parser; use futures::StreamExt; diff --git a/misc/server/src/behaviour.rs b/misc/server/src/behaviour.rs index a6d08689dfb..36b18c9798d 100644 --- a/misc/server/src/behaviour.rs +++ b/misc/server/src/behaviour.rs @@ -1,5 +1,3 @@ -#![allow(deprecated)] - use libp2p::autonat; use libp2p::identify; use libp2p::kad; @@ -26,7 +24,7 @@ pub(crate) struct Behaviour { ping: ping::Behaviour, identify: identify::Behaviour, pub(crate) kademlia: Toggle>, - autonat: Toggle, + autonat: Toggle, } impl Behaviour { @@ -59,7 +57,7 @@ impl Behaviour { .into(); let autonat = if enable_autonat { - Some(autonat::v1::Behaviour::new( + Some(autonat::Behaviour::new( PeerId::from(pub_key.clone()), Default::default(), )) diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index 2ffc6d5d27c..c0e51cdf53e 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,21 +1,16 @@ -## 0.14.0-alpha +## 0.13.0 +- Due to the refactor of `Transport` it's no longer required to create a seperate transport for +AutoNAT where port reuse is disabled. This information is now passed by the behaviour. + See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568). - Introduce the new AutoNATv2 protocol. It's split into a client and a server part, represented in their respective modules Features: - Since the server now always dials back over a newly allocated port, this made refactor(*): Transport redesign #4568 necessary; the client can be sure of the reachability state for other peers, even if the connection to the server was made through a hole punch. - The server can now test addresses different from the observed address (i.e., the connection to the server was made through a `p2p-circuit`). To mitigate against DDoS attacks, the client has to send more data to the server than the dial-back costs. See [PR 5526]. -- Deprecate the now unnecessary first version of AutoNAT. See [PR 5526]. - [PR 5526]: https://github.com/libp2p/rust-libp2p/pull/5526 -## 0.13.0 - -- Due to the refactor of `Transport` it's no longer required to create a seperate transport for -AutoNAT where port reuse is disabled. This information is now passed by the behaviour. - See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568). - ## 0.12.1 diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 5e975b33795..31214545384 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -12,14 +12,14 @@ categories = ["network-programming", "asynchronous"] [dependencies] -async-trait = "0.1" +async-trait = { version = "0.1", optional = true } asynchronous-codec = { workspace = true } bytes = { version = "1", optional = true } either = { version = "1.9.0", optional = true } futures = { workspace = true } futures-bounded = { workspace = true, optional = true } futures-timer = "3.0" -instant = "0.1" +web-time = { workspace = true, optional = true } libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-request-response = { workspace = true, optional = true } @@ -42,7 +42,7 @@ libp2p-swarm = { workspace = true, features = ["macros"]} [features] default = ["v1", "v2"] -v1 = ["dep:libp2p-request-response"] +v1 = ["dep:libp2p-request-response", "dep:web-time", "dep:async-trait"] v2 = ["dep:bytes", "dep:either", "dep:futures-bounded", "dep:thiserror", "dep:void", "dep:rand_core"] [lints] diff --git a/protocols/autonat/src/lib.rs b/protocols/autonat/src/lib.rs index a6fc66b28d1..4056b84389a 100644 --- a/protocols/autonat/src/lib.rs +++ b/protocols/autonat/src/lib.rs @@ -5,5 +5,4 @@ pub mod v1; pub mod v2; #[cfg(feature = "v1")] -#[allow(deprecated)] pub use v1::*; diff --git a/protocols/autonat/src/v1.rs b/protocols/autonat/src/v1.rs index 07b08310871..c60e4805f40 100644 --- a/protocols/autonat/src/v1.rs +++ b/protocols/autonat/src/v1.rs @@ -19,9 +19,12 @@ // DEALINGS IN THE SOFTWARE. //! Implementation of the [AutoNAT](https://github.com/libp2p/specs/blob/master/autonat/README.md) protocol. +//! +//! ## Eventual Deprecation +//! This version of the protocol will eventually be deprecated in favor of [v2](crate::v2). +//! We recommend using v2 for new projects. #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![cfg_attr(not(test), deprecated(note = "Please use `v2` module instead."))] pub(crate) mod behaviour; pub(crate) mod protocol; diff --git a/protocols/autonat/src/v1/behaviour.rs b/protocols/autonat/src/v1/behaviour.rs index 6e2c36a467f..7a717baed8d 100644 --- a/protocols/autonat/src/v1/behaviour.rs +++ b/protocols/autonat/src/v1/behaviour.rs @@ -28,7 +28,6 @@ pub use as_client::{OutboundProbeError, OutboundProbeEvent}; use as_server::AsServer; pub use as_server::{InboundProbeError, InboundProbeEvent}; use futures_timer::Delay; -use instant::Instant; use libp2p_core::transport::PortUse; use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; @@ -46,6 +45,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; +use web_time::Instant; /// Config for the [`Behaviour`]. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/protocols/autonat/src/v1/behaviour/as_client.rs b/protocols/autonat/src/v1/behaviour/as_client.rs index 668f3b93719..8960163ccb3 100644 --- a/protocols/autonat/src/v1/behaviour/as_client.rs +++ b/protocols/autonat/src/v1/behaviour/as_client.rs @@ -26,7 +26,6 @@ use super::{ }; use futures::FutureExt; use futures_timer::Delay; -use instant::Instant; use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, OutboundFailure, OutboundRequestId}; @@ -37,6 +36,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; +use web_time::Instant; /// Outbound probe failed or was aborted. #[derive(Debug)] diff --git a/protocols/autonat/src/v1/behaviour/as_server.rs b/protocols/autonat/src/v1/behaviour/as_server.rs index e309023bc75..3ecdd3ac26e 100644 --- a/protocols/autonat/src/v1/behaviour/as_server.rs +++ b/protocols/autonat/src/v1/behaviour/as_server.rs @@ -21,7 +21,6 @@ use super::{ Action, AutoNatCodec, Config, DialRequest, DialResponse, Event, HandleInnerEvent, ProbeId, ResponseError, }; -use instant::Instant; use libp2p_core::{multiaddr::Protocol, Multiaddr}; use libp2p_identity::PeerId; use libp2p_request_response::{ @@ -35,6 +34,7 @@ use std::{ collections::{HashMap, HashSet, VecDeque}, num::NonZeroU8, }; +use web_time::Instant; /// Inbound probe failed. #[derive(Debug)] diff --git a/protocols/autonat/tests/test_client.rs b/protocols/autonat/tests/test_client.rs index 2b1460cac85..7509d3ef425 100644 --- a/protocols/autonat/tests/test_client.rs +++ b/protocols/autonat/tests/test_client.rs @@ -17,7 +17,6 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#![allow(deprecated)] use async_std::task::JoinHandle; use libp2p_autonat::{ diff --git a/protocols/autonat/tests/test_server.rs b/protocols/autonat/tests/test_server.rs index a01c5901b8e..fd97b1a9132 100644 --- a/protocols/autonat/tests/test_server.rs +++ b/protocols/autonat/tests/test_server.rs @@ -17,7 +17,6 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#![allow(deprecated)] use libp2p_autonat::{ Behaviour, Config, Event, InboundProbeError, InboundProbeEvent, ResponseError,