Skip to content

Commit

Permalink
relay: remove unneeded inbound_hop::UpgradeError.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Jan 10, 2023
1 parent 3a0db97 commit c2eda37
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
3 changes: 2 additions & 1 deletion protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions protocols/relay/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 13 additions & 9 deletions protocols/relay/src/behaviour/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -178,7 +182,7 @@ pub enum Event {
CircuitReqDenyFailed {
circuit_id: Option<CircuitId>,
dst_peer_id: PeerId,
error: inbound_hop::UpgradeError,
error: inbound_hop::FatalUpgradeError,
},
/// An inbound cirucit request has been accepted.
CircuitReqAccepted {
Expand All @@ -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.
Expand Down Expand Up @@ -428,12 +432,12 @@ pub struct Handler {

/// Futures accepting an inbound circuit request.
circuit_accept_futures:
Futures<Result<CircuitParts, (CircuitId, PeerId, inbound_hop::UpgradeError)>>,
Futures<Result<CircuitParts, (CircuitId, PeerId, inbound_hop::FatalUpgradeError)>>,
/// Futures deying an inbound circuit request.
circuit_deny_futures: Futures<(
Option<CircuitId>,
PeerId,
Result<(), inbound_hop::UpgradeError>,
Result<(), inbound_hop::FatalUpgradeError>,
)>,
/// Tracks substreams lend out to other [`Handler`]s.
///
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<T> = FuturesUnordered<BoxFuture<'static, T>>;
Expand Down
28 changes: 7 additions & 21 deletions protocols/relay/src/protocol/inbound_hop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl upgrade::UpgradeInfo for Upgrade {

impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
type Output = Req;
type Error = UpgradeError;
type Error = FatalUpgradeError;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;

fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
Expand Down Expand Up @@ -79,9 +79,7 @@ impl upgrade::InboundUpgrade<NegotiatedSubstream> 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)
Expand All @@ -90,18 +88,6 @@ impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
}
}

#[derive(Debug, Error)]
pub enum UpgradeError {
#[error("Fatal")]
Fatal(#[from] FatalUpgradeError),
}

impl From<prost_codec::Error> for UpgradeError {
fn from(error: prost_codec::Error) -> Self {
Self::Fatal(error.into())
}
}

#[derive(Debug, Error)]
pub enum FatalUpgradeError {
#[error(transparent)]
Expand Down Expand Up @@ -131,7 +117,7 @@ pub struct ReservationReq {
}

impl ReservationReq {
pub async fn accept(self, addrs: Vec<Multiaddr>) -> Result<(), UpgradeError> {
pub async fn accept(self, addrs: Vec<Multiaddr>) -> Result<(), FatalUpgradeError> {
let msg = HopMessage {
r#type: hop_message::Type::Status.into(),
peer: None,
Expand All @@ -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,
Expand All @@ -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?;
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c2eda37

Please sign in to comment.