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 5 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
43 changes: 29 additions & 14 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 @@ -169,15 +174,15 @@ impl NetworkBehaviour for Client {
limit,
},
)),
handler::Event::ReservationReqFailed { renewal } => {
self.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Event::ReservationReqFailed {
relay_peer_id: event_source,
renewal,
},
))
}
handler::Event::ReservationReqFailed { renewal, error } => self
.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Event::ReservationReqFailed {
relay_peer_id: event_source,
renewal,
error,
},
)),
handler::Event::OutboundCircuitEstablished { limit } => {
self.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Expand All @@ -187,11 +192,12 @@ impl NetworkBehaviour for Client {
},
))
}
handler::Event::OutboundCircuitReqFailed {} => {
handler::Event::OutboundCircuitReqFailed { error } => {
self.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Event::OutboundCircuitReqFailed {
relay_peer_id: event_source,
error,
},
))
}
Expand All @@ -200,6 +206,15 @@ impl NetworkBehaviour for Client {
.push_back(NetworkBehaviourAction::GenerateEvent(
Event::InboundCircuitEstablished { src_peer_id, limit },
)),
handler::Event::InboundCircuitReqFailed { error } => {
self.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Event::InboundCircuitReqFailed {
relay_peer_id: event_source,
error,
},
))
}
handler::Event::InboundCircuitReqDenied { src_peer_id } => self
.queued_actions
.push_back(NetworkBehaviourAction::GenerateEvent(
Expand Down
Loading