diff --git a/Cargo.lock b/Cargo.lock index 2eeaab5bb83..3784ff96a21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2476,7 +2476,7 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.15.0" +version = "0.16.0" dependencies = [ "async-trait", "asynchronous-codec", diff --git a/Cargo.toml b/Cargo.toml index e51faa159be..6802a028202 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ edition = "2021" [workspace.dependencies] libp2p = { version = "0.56.0", path = "libp2p" } libp2p-allow-block-list = { version = "0.6.0", path = "misc/allow-block-list" } -libp2p-autonat = { version = "0.15.0", path = "protocols/autonat" } +libp2p-autonat = { version = "0.16.0", path = "protocols/autonat" } libp2p-connection-limits = { version = "0.6.0", path = "misc/connection-limits" } libp2p-core = { version = "0.43.1", path = "core" } libp2p-dcutr = { version = "0.14.0", path = "protocols/dcutr" } diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index 1ef95957e92..0beeddbdabc 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.16.0 +- Fix `DialBackError` visibility so downstream could differentiate between `NoConnection` and `StreamFailed`. + See [PR 6168](https://github.com/libp2p/rust-libp2p/pull/6168). ## 0.15.0 - Fix infinity loop on wrong `nonce` when performing `dial_back`. diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 9a2f227d412..a7e0fb98c1c 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-autonat" edition.workspace = true rust-version = { workspace = true } description = "NAT and firewall detection for libp2p" -version = "0.15.0" +version = "0.16.0" authors = [ "David Craven ", "Elena Frank ", diff --git a/protocols/autonat/src/v2/client.rs b/protocols/autonat/src/v2/client.rs index 11ddb792839..816fbfbc71c 100644 --- a/protocols/autonat/src/v2/client.rs +++ b/protocols/autonat/src/v2/client.rs @@ -2,3 +2,4 @@ mod behaviour; mod handler; pub use behaviour::{Behaviour, Config, Event}; +pub use handler::dial_request::DialBackError; diff --git a/protocols/autonat/src/v2/client/behaviour.rs b/protocols/autonat/src/v2/client/behaviour.rs index 8e238fc9be4..5b8dbbb8df3 100644 --- a/protocols/autonat/src/v2/client/behaviour.rs +++ b/protocols/autonat/src/v2/client/behaviour.rs @@ -1,6 +1,6 @@ use std::{ collections::{HashMap, VecDeque}, - fmt::{Debug, Display, Formatter}, + fmt::Debug, task::{Context, Poll}, time::Duration, }; @@ -239,7 +239,7 @@ where tested_addr, bytes_sent, server: peer_id, - result: result.map_err(|e| Error { inner: e }), + result, })); } @@ -374,22 +374,6 @@ impl Default for Behaviour { } } -pub struct Error { - pub(crate) inner: dial_request::DialBackError, -} - -impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(&self.inner, f) - } -} - -impl Debug for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Debug::fmt(&self.inner, f) - } -} - #[derive(Debug)] pub struct Event { /// The address that was selected for testing. @@ -402,7 +386,7 @@ pub struct Event { pub server: PeerId, /// The result of the test. If the test was successful, this is `Ok(())`. /// Otherwise it's an error. - pub result: Result<(), Error>, + pub result: Result<(), dial_request::DialBackError>, } struct ConnectionInfo { diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index bafdd9d818c..d8848e99551 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -62,8 +62,10 @@ impl From for Error { #[derive(thiserror::Error, Debug)] pub enum DialBackError { + /// Tells that the client is actually behind NAT for this connection. #[error("server failed to establish a connection")] NoConnection, + /// Can't tell new information as dialing back couldn't be finished for a lower level reason. #[error("dial back stream failed")] StreamFailed, }