Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocols/relay/src/v2: Refactor error handling #7

Merged
merged 6 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions misc/metrics/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ enum EventType {
ReservationReqDenied,
ReservationReqDenyFailed,
ReservationTimedOut,
CircuitReqReceiveFailed,
CircuitReqDenied,
CircuitReqDenyFailed,
CircuitReqOutboundConnectFailed,
CircuitReqAccepted,
CircuitReqAcceptFailed,
CircuitClosed,
Expand All @@ -79,7 +81,13 @@ impl From<&libp2p_relay::v2::relay::Event> for EventType {
libp2p_relay::v2::relay::Event::ReservationTimedOut { .. } => {
EventType::ReservationTimedOut
}
libp2p_relay::v2::relay::Event::CircuitReqReceiveFailed { .. } => {
EventType::CircuitReqReceiveFailed
}
libp2p_relay::v2::relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
libp2p_relay::v2::relay::Event::CircuitReqOutboundConnectFailed { .. } => {
EventType::CircuitReqOutboundConnectFailed
}
libp2p_relay::v2::relay::Event::CircuitReqDenyFailed { .. } => {
EventType::CircuitReqDenyFailed
}
Expand Down
26 changes: 20 additions & 6 deletions protocols/relay/src/v2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
mod handler;
pub mod transport;

use crate::v2::protocol::{self, inbound_stop};
use crate::v2::protocol::{self, inbound_stop, outbound_hop};
use bytes::Bytes;
use futures::channel::mpsc::Receiver;
use futures::channel::oneshot;
Expand All @@ -36,6 +36,7 @@ use libp2p_core::{Multiaddr, PeerId};
use libp2p_swarm::dial_opts::DialOpts;
use libp2p_swarm::{
NegotiatedSubstream, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
ProtocolsHandlerUpgrErr,
};
use std::collections::{hash_map, HashMap, VecDeque};
use std::io::{Error, IoSlice};
Expand All @@ -57,23 +58,27 @@ pub enum Event {
relay_peer_id: PeerId,
/// Indicates whether the request replaces an existing reservation.
renewal: bool,
error: ProtocolsHandlerUpgrErr<outbound_hop::ReservationFailedReason>,
},
OutboundCircuitEstablished {
relay_peer_id: PeerId,
limit: Option<protocol::Limit>,
},
OutboundCircuitReqFailed {
relay_peer_id: PeerId,
error: ProtocolsHandlerUpgrErr<outbound_hop::CircuitFailedReason>,
},
/// An inbound circuit has been established.
InboundCircuitEstablished {
src_peer_id: PeerId,
limit: Option<protocol::Limit>,
},
/// An inbound circuit request has been denied.
InboundCircuitReqDenied {
src_peer_id: PeerId,
InboundCircuitReqFailed {
relay_peer_id: PeerId,
error: ProtocolsHandlerUpgrErr<void::Void>,
},
/// An inbound circuit request has been denied.
InboundCircuitReqDenied { src_peer_id: PeerId },
/// Denying an inbound circuit request failed.
InboundCircuitReqDenyFailed {
src_peer_id: PeerId,
Expand Down Expand Up @@ -167,10 +172,11 @@ impl NetworkBehaviour for Client {
renewal,
limit,
}),
handler::Event::ReservationReqFailed { renewal } => {
handler::Event::ReservationReqFailed { renewal, error } => {
self.queued_actions.push_back(Event::ReservationReqFailed {
relay_peer_id: event_source,
renewal,
error,
})
}
handler::Event::OutboundCircuitEstablished { limit } => {
Expand All @@ -180,15 +186,23 @@ impl NetworkBehaviour for Client {
limit,
})
}
handler::Event::OutboundCircuitReqFailed {} => {
handler::Event::OutboundCircuitReqFailed { error } => {
self.queued_actions
.push_back(Event::OutboundCircuitReqFailed {
relay_peer_id: event_source,
error,
})
}
handler::Event::InboundCircuitEstablished { src_peer_id, limit } => self
.queued_actions
.push_back(Event::InboundCircuitEstablished { src_peer_id, limit }),
handler::Event::InboundCircuitReqFailed { error } => {
self.queued_actions
.push_back(Event::InboundCircuitReqFailed {
relay_peer_id: event_source,
error,
})
}
handler::Event::InboundCircuitReqDenied { src_peer_id } => self
.queued_actions
.push_back(Event::InboundCircuitReqDenied { src_peer_id }),
Expand Down
Loading