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

feat(relay): don't close connections upon errors in relay server #4718

Merged
merged 17 commits into from
Nov 1, 2023
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
5 changes: 5 additions & 0 deletions misc/metrics/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ impl From<&libp2p_relay::Event> for EventType {
fn from(event: &libp2p_relay::Event) -> Self {
match event {
libp2p_relay::Event::ReservationReqAccepted { .. } => EventType::ReservationReqAccepted,
#[allow(deprecated)]
libp2p_relay::Event::ReservationReqAcceptFailed { .. } => {
EventType::ReservationReqAcceptFailed
}
libp2p_relay::Event::ReservationReqDenied { .. } => EventType::ReservationReqDenied,
#[allow(deprecated)]
libp2p_relay::Event::ReservationReqDenyFailed { .. } => {
EventType::ReservationReqDenyFailed
}
libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut,
libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
#[allow(deprecated)]
libp2p_relay::Event::CircuitReqOutboundConnectFailed { .. } => {
EventType::CircuitReqOutboundConnectFailed
}
#[allow(deprecated)]
libp2p_relay::Event::CircuitReqDenyFailed { .. } => EventType::CircuitReqDenyFailed,
libp2p_relay::Event::CircuitReqAccepted { .. } => EventType::CircuitReqAccepted,
#[allow(deprecated)]
libp2p_relay::Event::CircuitReqAcceptFailed { .. } => EventType::CircuitReqAcceptFailed,
libp2p_relay::Event::CircuitClosed { .. } => EventType::CircuitClosed,
}
Expand Down
7 changes: 7 additions & 0 deletions protocols/relay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## 0.17.0 - unreleased

- Don't close connections on protocol failures within the relay-server.
To achieve this, error handling was restructured:
- `libp2p::relay::outbound::stop::FatalUpgradeError` has been removed.
- `libp2p::relay::outbound::stop::{Error, ProtocolViolation}` have been introduced.
- Several variants of `libp2p::relay::Event` have been deprecated.

See [PR 4718](https://github.com/libp2p/rust-libp2p/pull/4718).
- Fix a rare race condition when making a reservation on a relay that could lead to a failed reservation.
See [PR 4747](https://github.com/libp2p/rust-lib2pp/pulls/4747).
- Propagate errors of relay client to the listener / dialer.
Expand Down
32 changes: 26 additions & 6 deletions protocols/relay/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use libp2p_identity::PeerId;
use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm};
use libp2p_swarm::{
dummy, ConnectionDenied, ConnectionId, ExternalAddresses, NetworkBehaviour, NotifyHandler,
StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm,
THandler, THandlerInEvent, THandlerOutEvent, ToSwarm,
};
use std::collections::{hash_map, HashMap, HashSet, VecDeque};
use std::num::NonZeroU32;
Expand Down Expand Up @@ -169,16 +169,22 @@ pub enum Event {
renewed: bool,
},
/// Accepting an inbound reservation request failed.
#[deprecated(
note = "Will be removed in favor of logging them internally, see <https://github.com/libp2p/rust-libp2p/issues/4757> for details."
)]
ReservationReqAcceptFailed {
src_peer_id: PeerId,
error: inbound_hop::UpgradeError,
error: inbound_hop::Error,
},
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
/// An inbound reservation request has been denied.
ReservationReqDenied { src_peer_id: PeerId },
/// Denying an inbound reservation request has failed.
#[deprecated(
note = "Will be removed in favor of logging them internally, see <https://github.com/libp2p/rust-libp2p/issues/4757> for details."
)]
ReservationReqDenyFailed {
src_peer_id: PeerId,
error: inbound_hop::UpgradeError,
error: inbound_hop::Error,
},
/// An inbound reservation has timed out.
ReservationTimedOut { src_peer_id: PeerId },
Expand All @@ -188,27 +194,36 @@ pub enum Event {
dst_peer_id: PeerId,
},
/// Denying an inbound circuit request failed.
#[deprecated(
note = "Will be removed in favor of logging them internally, see <https://github.com/libp2p/rust-libp2p/issues/4757> for details."
)]
CircuitReqDenyFailed {
src_peer_id: PeerId,
dst_peer_id: PeerId,
error: inbound_hop::UpgradeError,
error: inbound_hop::Error,
},
/// An inbound cirucit request has been accepted.
CircuitReqAccepted {
src_peer_id: PeerId,
dst_peer_id: PeerId,
},
/// An outbound connect for an inbound cirucit request failed.
#[deprecated(
note = "Will be removed in favor of logging them internally, see <https://github.com/libp2p/rust-libp2p/issues/4757> for details."
)]
CircuitReqOutboundConnectFailed {
src_peer_id: PeerId,
dst_peer_id: PeerId,
error: StreamUpgradeError<outbound_stop::CircuitFailedReason>,
error: outbound_stop::Error,
},
/// Accepting an inbound circuit request failed.
#[deprecated(
note = "Will be removed in favor of logging them internally, see <https://github.com/libp2p/rust-libp2p/issues/4757> for details."
)]
CircuitReqAcceptFailed {
src_peer_id: PeerId,
dst_peer_id: PeerId,
error: inbound_hop::UpgradeError,
error: inbound_hop::Error,
},
/// An inbound circuit has closed.
CircuitClosed {
Expand Down Expand Up @@ -455,6 +470,7 @@ impl NetworkBehaviour for Behaviour {
));
}
handler::Event::ReservationReqAcceptFailed { error } => {
#[allow(deprecated)]
self.queued_actions.push_back(ToSwarm::GenerateEvent(
Event::ReservationReqAcceptFailed {
src_peer_id: event_source,
Expand All @@ -470,6 +486,7 @@ impl NetworkBehaviour for Behaviour {
));
}
handler::Event::ReservationReqDenyFailed { error } => {
#[allow(deprecated)]
self.queued_actions.push_back(ToSwarm::GenerateEvent(
Event::ReservationReqDenyFailed {
src_peer_id: event_source,
Expand Down Expand Up @@ -592,6 +609,7 @@ impl NetworkBehaviour for Behaviour {
self.circuits.remove(circuit_id);
}

#[allow(deprecated)]
self.queued_actions.push_back(ToSwarm::GenerateEvent(
Event::CircuitReqDenyFailed {
src_peer_id: event_source,
Expand Down Expand Up @@ -637,6 +655,7 @@ impl NetworkBehaviour for Behaviour {
status,
}),
});
#[allow(deprecated)]
self.queued_actions.push_back(ToSwarm::GenerateEvent(
Event::CircuitReqOutboundConnectFailed {
src_peer_id,
Expand All @@ -662,6 +681,7 @@ impl NetworkBehaviour for Behaviour {
error,
} => {
self.circuits.remove(circuit_id);
#[allow(deprecated)]
self.queued_actions.push_back(ToSwarm::GenerateEvent(
Event::CircuitReqAcceptFailed {
src_peer_id: event_source,
Expand Down
Loading