diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 286bf85b6a2..5d911ebd6bd 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -10,7 +10,8 @@ - Update to `libp2p-core` `v0.39.0`. - Update to `libp2p-swarm` `v0.42.0`. Update to the `libp2p_swarm::handler::ConnectionEvent` `DialTimeout` introduction and consequential changes. - With that introduce `behaviour::OutboundError` and `client::InboundError`. See [PR XXXX]. + With that introduce `behaviour::OutboundError` and `client::InboundError`. + Remove unneeded `inbound_hop::UpgradeError` as all `inbound_hop` upgrade errors are Fatal. See [PR 3307]. [PR 3238]: https://github.com/libp2p/rust-libp2p/pull/3238 diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 24315fe237a..c2f5e39be68 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -136,14 +136,14 @@ pub enum Event { /// Accepting an inbound reservation request failed. ReservationReqAcceptFailed { src_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An inbound reservation request has been denied. ReservationReqDenied { src_peer_id: PeerId }, /// Denying an inbound reservation request has failed. ReservationReqDenyFailed { src_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An inbound reservation has timed out. ReservationTimedOut { src_peer_id: PeerId }, @@ -160,7 +160,7 @@ pub enum Event { CircuitReqDenyFailed { src_peer_id: PeerId, dst_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An inbound cirucit request has been accepted. CircuitReqAccepted { @@ -177,7 +177,7 @@ pub enum Event { CircuitReqAcceptFailed { src_peer_id: PeerId, dst_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An inbound circuit has closed. CircuitClosed { diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 60fe0d2f3dc..9f0f8373fc2 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -155,11 +155,15 @@ pub enum Event { renewed: bool, }, /// Accepting an inbound reservation request failed. - ReservationReqAcceptFailed { error: inbound_hop::UpgradeError }, + ReservationReqAcceptFailed { + error: inbound_hop::FatalUpgradeError, + }, /// An inbound reservation request has been denied. ReservationReqDenied {}, /// Denying an inbound reservation request has failed. - ReservationReqDenyFailed { error: inbound_hop::UpgradeError }, + ReservationReqDenyFailed { + error: inbound_hop::FatalUpgradeError, + }, /// An inbound reservation has timed out. ReservationTimedOut {}, /// An inbound circuit request has been received. @@ -178,7 +182,7 @@ pub enum Event { CircuitReqDenyFailed { circuit_id: Option, dst_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An inbound cirucit request has been accepted. CircuitReqAccepted { @@ -189,7 +193,7 @@ pub enum Event { CircuitReqAcceptFailed { circuit_id: CircuitId, dst_peer_id: PeerId, - error: inbound_hop::UpgradeError, + error: inbound_hop::FatalUpgradeError, }, /// An outbound substream for an inbound circuit request has been /// negotiated. @@ -428,12 +432,12 @@ pub struct Handler { /// Futures accepting an inbound circuit request. circuit_accept_futures: - Futures>, + Futures>, /// Futures deying an inbound circuit request. circuit_deny_futures: Futures<( Option, PeerId, - Result<(), inbound_hop::UpgradeError>, + Result<(), inbound_hop::FatalUpgradeError>, )>, /// Tracks substreams lend out to other [`Handler`]s. /// @@ -528,7 +532,7 @@ impl Handler { )); return; } - upgrade::UpgradeError::Apply(inbound_hop::UpgradeError::Fatal(error)) => { + upgrade::UpgradeError::Apply(error) => { self.pending_error = Some(upgrade::UpgradeError::Apply(EitherError::A(error))); return; } @@ -606,8 +610,8 @@ impl Handler { } enum ReservationRequestFuture { - Accepting(BoxFuture<'static, Result<(), inbound_hop::UpgradeError>>), - Denying(BoxFuture<'static, Result<(), inbound_hop::UpgradeError>>), + Accepting(BoxFuture<'static, Result<(), inbound_hop::FatalUpgradeError>>), + Denying(BoxFuture<'static, Result<(), inbound_hop::FatalUpgradeError>>), } type Futures = FuturesUnordered>; diff --git a/protocols/relay/src/protocol/inbound_hop.rs b/protocols/relay/src/protocol/inbound_hop.rs index dec290e0e6c..11882b752c4 100644 --- a/protocols/relay/src/protocol/inbound_hop.rs +++ b/protocols/relay/src/protocol/inbound_hop.rs @@ -47,7 +47,7 @@ impl upgrade::UpgradeInfo for Upgrade { impl upgrade::InboundUpgrade for Upgrade { type Output = Req; - type Error = UpgradeError; + type Error = FatalUpgradeError; type Future = BoxFuture<'static, Result>; fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future { @@ -79,9 +79,7 @@ impl upgrade::InboundUpgrade for Upgrade { .map_err(|_| FatalUpgradeError::ParsePeerId)?; Req::Connect(CircuitReq { dst, substream }) } - hop_message::Type::Status => { - return Err(FatalUpgradeError::UnexpectedTypeStatus.into()) - } + hop_message::Type::Status => return Err(FatalUpgradeError::UnexpectedTypeStatus), }; Ok(req) @@ -90,18 +88,6 @@ impl upgrade::InboundUpgrade for Upgrade { } } -#[derive(Debug, Error)] -pub enum UpgradeError { - #[error("Fatal")] - Fatal(#[from] FatalUpgradeError), -} - -impl From for UpgradeError { - fn from(error: prost_codec::Error) -> Self { - Self::Fatal(error.into()) - } -} - #[derive(Debug, Error)] pub enum FatalUpgradeError { #[error(transparent)] @@ -131,7 +117,7 @@ pub struct ReservationReq { } impl ReservationReq { - pub async fn accept(self, addrs: Vec) -> Result<(), UpgradeError> { + pub async fn accept(self, addrs: Vec) -> Result<(), FatalUpgradeError> { let msg = HopMessage { r#type: hop_message::Type::Status.into(), peer: None, @@ -158,7 +144,7 @@ impl ReservationReq { self.send(msg).await } - pub async fn deny(self, status: Status) -> Result<(), UpgradeError> { + pub async fn deny(self, status: Status) -> Result<(), FatalUpgradeError> { let msg = HopMessage { r#type: hop_message::Type::Status.into(), peer: None, @@ -170,7 +156,7 @@ impl ReservationReq { self.send(msg).await } - async fn send(mut self, msg: HopMessage) -> Result<(), UpgradeError> { + async fn send(mut self, msg: HopMessage) -> Result<(), FatalUpgradeError> { self.substream.send(msg).await?; self.substream.flush().await?; self.substream.close().await?; @@ -189,7 +175,7 @@ impl CircuitReq { self.dst } - pub async fn accept(mut self) -> Result<(NegotiatedSubstream, Bytes), UpgradeError> { + pub async fn accept(mut self) -> Result<(NegotiatedSubstream, Bytes), FatalUpgradeError> { let msg = HopMessage { r#type: hop_message::Type::Status.into(), peer: None, @@ -214,7 +200,7 @@ impl CircuitReq { Ok((io, read_buffer.freeze())) } - pub async fn deny(mut self, status: Status) -> Result<(), UpgradeError> { + pub async fn deny(mut self, status: Status) -> Result<(), FatalUpgradeError> { let msg = HopMessage { r#type: hop_message::Type::Status.into(), peer: None,