diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index 301f2ee3d82..673bbb7c45c 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -134,7 +134,10 @@ pub struct Handler { /// A pending fatal error that results in the connection being closed. pending_error: Option< ConnectionHandlerUpgrErr< - EitherError, + EitherError< + protocol::inbound::InboundUpgradeError, + protocol::outbound::OutboundUpgradeError, + >, >, >, /// Queue of events to return when polled. @@ -148,7 +151,7 @@ pub struct Handler { >, /// Inbound connect, accepted by the behaviour, pending completion. inbound_connect: - Option, protocol::inbound::UpgradeError>>>, + Option, protocol::inbound::InboundUpgradeError>>>, keep_alive: KeepAlive, } @@ -302,7 +305,10 @@ impl ConnectionHandler for Handler { type InEvent = Command; type OutEvent = Event; type Error = ConnectionHandlerUpgrErr< - EitherError, + EitherError< + protocol::inbound::InboundUpgradeError, + protocol::outbound::OutboundUpgradeError, + >, >; type InboundProtocol = upgrade::EitherUpgrade; type OutboundProtocol = protocol::outbound::Upgrade; diff --git a/protocols/dcutr/src/lib.rs b/protocols/dcutr/src/lib.rs index 738af5300b1..4ce15ffed74 100644 --- a/protocols/dcutr/src/lib.rs +++ b/protocols/dcutr/src/lib.rs @@ -26,13 +26,28 @@ pub mod behaviour; mod handler; mod protocol; - -pub use protocol::{ - inbound::UpgradeError as InboundUpgradeError, outbound::UpgradeError as OutboundUpgradeError, - PROTOCOL_NAME, -}; - #[allow(clippy::derive_partial_eq_without_eq)] mod message_proto { include!(concat!(env!("OUT_DIR"), "/holepunch.pb.rs")); } + +pub use protocol::PROTOCOL_NAME; +pub mod inbound { + pub use crate::protocol::inbound::InboundUpgradeError as UpgradeError; // TODO: Rename the inner error once `cargo-semver-checks` supports it: https://github.com/obi1kenobi/cargo-semver-checks/issues/152 +} + +pub mod outbound { + pub use crate::protocol::outbound::OutboundUpgradeError as UpgradeError; // TODO: Rename the inner error once `cargo-semver-checks` supports it: https://github.com/obi1kenobi/cargo-semver-checks/issues/152 +} + +#[deprecated( + since = "0.8.1", + note = "Use `libp2p_dcutr::inbound::UpgradeError` instead.`" +)] +pub type InboundUpgradeError = inbound::UpgradeError; + +#[deprecated( + since = "0.8.1", + note = "Use `libp2p_dcutr::outbound::UpgradeError` instead.`" +)] +pub type OutboundUpgradeError = outbound::UpgradeError; diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index 3b964881f51..78a8cc0e0fe 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -40,7 +40,7 @@ impl upgrade::UpgradeInfo for Upgrade { impl upgrade::InboundUpgrade for Upgrade { type Output = PendingConnect; - type Error = UpgradeError; + type Error = InboundUpgradeError; type Future = BoxFuture<'static, Result>; fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future { @@ -50,11 +50,13 @@ impl upgrade::InboundUpgrade for Upgrade { ); async move { - let HolePunch { r#type, obs_addrs } = - substream.next().await.ok_or(UpgradeError::StreamClosed)??; + let HolePunch { r#type, obs_addrs } = substream + .next() + .await + .ok_or(InboundUpgradeError::StreamClosed)??; let obs_addrs = if obs_addrs.is_empty() { - return Err(UpgradeError::NoAddresses); + return Err(InboundUpgradeError::NoAddresses); } else { obs_addrs .into_iter() @@ -65,14 +67,15 @@ impl upgrade::InboundUpgrade for Upgrade { Err(_) => true, }) .collect::, _>>() - .map_err(|_| UpgradeError::InvalidAddrs)? + .map_err(|_| InboundUpgradeError::InvalidAddrs)? }; - let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?; + let r#type = + hole_punch::Type::from_i32(r#type).ok_or(InboundUpgradeError::ParseTypeField)?; match r#type { hole_punch::Type::Connect => {} - hole_punch::Type::Sync => return Err(UpgradeError::UnexpectedTypeSync), + hole_punch::Type::Sync => return Err(InboundUpgradeError::UnexpectedTypeSync), } Ok(PendingConnect { @@ -93,7 +96,7 @@ impl PendingConnect { pub async fn accept( mut self, local_obs_addrs: Vec, - ) -> Result, UpgradeError> { + ) -> Result, InboundUpgradeError> { let msg = HolePunch { r#type: hole_punch::Type::Connect.into(), obs_addrs: local_obs_addrs.into_iter().map(|a| a.to_vec()).collect(), @@ -104,11 +107,12 @@ impl PendingConnect { .substream .next() .await - .ok_or(UpgradeError::StreamClosed)??; + .ok_or(InboundUpgradeError::StreamClosed)??; - let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?; + let r#type = + hole_punch::Type::from_i32(r#type).ok_or(InboundUpgradeError::ParseTypeField)?; match r#type { - hole_punch::Type::Connect => return Err(UpgradeError::UnexpectedTypeConnect), + hole_punch::Type::Connect => return Err(InboundUpgradeError::UnexpectedTypeConnect), hole_punch::Type::Sync => {} } @@ -117,7 +121,7 @@ impl PendingConnect { } #[derive(Debug, Error)] -pub enum UpgradeError { +pub enum InboundUpgradeError { #[error(transparent)] Codec(#[from] prost_codec::Error), #[error("Stream closed")] diff --git a/protocols/dcutr/src/protocol/outbound.rs b/protocols/dcutr/src/protocol/outbound.rs index ca2a340aecb..58dba144e0e 100644 --- a/protocols/dcutr/src/protocol/outbound.rs +++ b/protocols/dcutr/src/protocol/outbound.rs @@ -50,7 +50,7 @@ impl Upgrade { impl upgrade::OutboundUpgrade for Upgrade { type Output = Connect; - type Error = UpgradeError; + type Error = OutboundUpgradeError; type Future = BoxFuture<'static, Result>; fn upgrade_outbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future { @@ -69,19 +69,22 @@ impl upgrade::OutboundUpgrade for Upgrade { let sent_time = Instant::now(); - let HolePunch { r#type, obs_addrs } = - substream.next().await.ok_or(UpgradeError::StreamClosed)??; + let HolePunch { r#type, obs_addrs } = substream + .next() + .await + .ok_or(OutboundUpgradeError::StreamClosed)??; let rtt = sent_time.elapsed(); - let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?; + let r#type = + hole_punch::Type::from_i32(r#type).ok_or(OutboundUpgradeError::ParseTypeField)?; match r#type { hole_punch::Type::Connect => {} - hole_punch::Type::Sync => return Err(UpgradeError::UnexpectedTypeSync), + hole_punch::Type::Sync => return Err(OutboundUpgradeError::UnexpectedTypeSync), } let obs_addrs = if obs_addrs.is_empty() { - return Err(UpgradeError::NoAddresses); + return Err(OutboundUpgradeError::NoAddresses); } else { obs_addrs .into_iter() @@ -92,7 +95,7 @@ impl upgrade::OutboundUpgrade for Upgrade { Err(_) => true, }) .collect::, _>>() - .map_err(|_| UpgradeError::InvalidAddrs)? + .map_err(|_| OutboundUpgradeError::InvalidAddrs)? }; let msg = HolePunch { @@ -115,7 +118,7 @@ pub struct Connect { } #[derive(Debug, Error)] -pub enum UpgradeError { +pub enum OutboundUpgradeError { #[error(transparent)] Codec(#[from] prost_codec::Error), #[error("Stream closed")]