Skip to content

Commit 53e5370

Browse files
feat: don't report inbound stream upgrade errors to handler
When an inbound stream upgrade fails, there isn't a whole lot we can do about that in the handler. In fact, for several errors, we wouldn't even know which specific handler to target, for example, `NegotiationFailed`. Similiarly, in case of an IO error during the upgrade, we don't know which handler the stream was eventually meant to be for. Pull-Request: #3605.
1 parent 2130923 commit 53e5370

File tree

21 files changed

+89
-552
lines changed

21 files changed

+89
-552
lines changed

misc/metrics/src/relay.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ enum EventType {
5454
ReservationReqDenied,
5555
ReservationReqDenyFailed,
5656
ReservationTimedOut,
57-
CircuitReqReceiveFailed,
5857
CircuitReqDenied,
5958
CircuitReqDenyFailed,
6059
CircuitReqOutboundConnectFailed,
@@ -75,9 +74,6 @@ impl From<&libp2p_relay::Event> for EventType {
7574
EventType::ReservationReqDenyFailed
7675
}
7776
libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut,
78-
libp2p_relay::Event::CircuitReqReceiveFailed { .. } => {
79-
EventType::CircuitReqReceiveFailed
80-
}
8177
libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied,
8278
libp2p_relay::Event::CircuitReqOutboundConnectFailed { .. } => {
8379
EventType::CircuitReqOutboundConnectFailed

protocols/dcutr/src/handler/relayed.rs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,45 +212,12 @@ impl Handler {
212212
<Self as ConnectionHandler>::InboundProtocol,
213213
>,
214214
) {
215-
match error {
216-
ConnectionHandlerUpgrErr::Timeout => {
217-
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
218-
Event::InboundNegotiationFailed {
219-
error: ConnectionHandlerUpgrErr::Timeout,
220-
},
221-
));
222-
}
223-
ConnectionHandlerUpgrErr::Timer => {
224-
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
225-
Event::InboundNegotiationFailed {
226-
error: ConnectionHandlerUpgrErr::Timer,
227-
},
228-
));
229-
}
230-
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
231-
// The remote merely doesn't support the DCUtR protocol.
232-
// This is no reason to close the connection, which may
233-
// successfully communicate with other protocols already.
234-
self.keep_alive = KeepAlive::No;
235-
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
236-
Event::InboundNegotiationFailed {
237-
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
238-
NegotiationError::Failed,
239-
)),
240-
},
241-
));
242-
}
243-
_ => {
244-
// Anything else is considered a fatal error or misbehaviour of
245-
// the remote peer and results in closing the connection.
246-
self.pending_error = Some(error.map_upgrade_err(|e| {
247-
e.map_err(|e| match e {
248-
Either::Left(e) => Either::Left(e),
249-
Either::Right(v) => void::unreachable(v),
250-
})
251-
}));
252-
}
253-
}
215+
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(
216+
match error {
217+
Either::Left(e) => Either::Left(e),
218+
Either::Right(v) => void::unreachable(v),
219+
},
220+
)));
254221
}
255222

256223
fn on_dial_upgrade_error(

protocols/gossipsub/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl ConnectionHandler for Handler {
526526
handler.on_fully_negotiated_outbound(fully_negotiated_outbound)
527527
}
528528
ConnectionEvent::DialUpgradeError(DialUpgradeError {
529-
error: ConnectionHandlerUpgrErr::Timeout | ConnectionHandlerUpgrErr::Timer,
529+
error: ConnectionHandlerUpgrErr::Timeout,
530530
..
531531
}) => {
532532
log::debug!("Dial upgrade error: Protocol negotiation timeout");

protocols/perf/src/client/handler.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,7 @@ impl ConnectionHandler for Handler {
150150
}));
151151
}
152152
ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => {
153-
match error {
154-
ConnectionHandlerUpgrErr::Timeout => {}
155-
ConnectionHandlerUpgrErr::Timer => {}
156-
ConnectionHandlerUpgrErr::Upgrade(error) => match error {
157-
libp2p_core::UpgradeError::Select(_) => {}
158-
libp2p_core::UpgradeError::Apply(v) => void::unreachable(v),
159-
},
160-
}
153+
void::unreachable(error)
161154
}
162155
}
163156
}

protocols/perf/src/server/handler.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use libp2p_swarm::{
3030
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
3131
ListenUpgradeError,
3232
},
33-
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, StreamProtocol,
34-
SubstreamProtocol,
33+
ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, SubstreamProtocol,
3534
};
3635
use log::error;
3736
use void::Void;
@@ -106,14 +105,7 @@ impl ConnectionHandler for Handler {
106105
}
107106
ConnectionEvent::AddressChange(_) => {}
108107
ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => {
109-
match error {
110-
ConnectionHandlerUpgrErr::Timeout => {}
111-
ConnectionHandlerUpgrErr::Timer => {}
112-
ConnectionHandlerUpgrErr::Upgrade(error) => match error {
113-
libp2p_core::UpgradeError::Select(_) => {}
114-
libp2p_core::UpgradeError::Apply(v) => void::unreachable(v),
115-
},
116-
}
108+
void::unreachable(error)
117109
}
118110
}
119111
}

protocols/relay/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
- Hide internals of `Connection` and expose only `AsyncRead` and `AsyncWrite`.
77
See [PR 3829].
88

9+
- Remove `Event::CircuitReqReceiveFailed` and `Event::InboundCircuitReqFailed` variants.
10+
These variants are no longer constructed.
11+
See [PR 3605].
12+
13+
[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
914
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
1015
[PR 3829]: https://github.com/libp2p/rust-libp2p/pull/3829
1116

protocols/relay/src/behaviour.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ pub enum Event {
150150
},
151151
/// An inbound reservation has timed out.
152152
ReservationTimedOut { src_peer_id: PeerId },
153-
CircuitReqReceiveFailed {
154-
src_peer_id: PeerId,
155-
error: ConnectionHandlerUpgrErr<void::Void>,
156-
},
157153
/// An inbound circuit request has been denied.
158154
CircuitReqDenied {
159155
src_peer_id: PeerId,
@@ -537,15 +533,6 @@ impl NetworkBehaviour for Behaviour {
537533
};
538534
self.queued_actions.push_back(action.into());
539535
}
540-
handler::Event::CircuitReqReceiveFailed { error } => {
541-
self.queued_actions.push_back(
542-
ToSwarm::GenerateEvent(Event::CircuitReqReceiveFailed {
543-
src_peer_id: event_source,
544-
error,
545-
})
546-
.into(),
547-
);
548-
}
549536
handler::Event::CircuitReqDenied {
550537
circuit_id,
551538
dst_peer_id,

protocols/relay/src/behaviour/handler.rs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ pub enum Event {
163163
inbound_circuit_req: inbound_hop::CircuitReq,
164164
endpoint: ConnectedPoint,
165165
},
166-
/// Receiving an inbound circuit request failed.
167-
CircuitReqReceiveFailed {
168-
error: ConnectionHandlerUpgrErr<void::Void>,
169-
},
170166
/// An inbound circuit request has been denied.
171167
CircuitReqDenied {
172168
circuit_id: Option<CircuitId>,
@@ -252,10 +248,6 @@ impl fmt::Debug for Event {
252248
.debug_struct("Event::CircuitReqReceived")
253249
.field("endpoint", endpoint)
254250
.finish(),
255-
Event::CircuitReqReceiveFailed { error } => f
256-
.debug_struct("Event::CircuitReqReceiveFailed")
257-
.field("error", error)
258-
.finish(),
259251
Event::CircuitReqDenied {
260252
circuit_id,
261253
dst_peer_id,
@@ -471,41 +463,16 @@ impl Handler {
471463

472464
fn on_listen_upgrade_error(
473465
&mut self,
474-
ListenUpgradeError { error, .. }: ListenUpgradeError<
466+
ListenUpgradeError {
467+
error: inbound_hop::UpgradeError::Fatal(error),
468+
..
469+
}: ListenUpgradeError<
475470
<Self as ConnectionHandler>::InboundOpenInfo,
476471
<Self as ConnectionHandler>::InboundProtocol,
477472
>,
478473
) {
479-
let non_fatal_error = match error {
480-
ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout,
481-
ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer,
482-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
483-
upgrade::NegotiationError::Failed,
484-
)) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
485-
upgrade::NegotiationError::Failed,
486-
)),
487-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
488-
upgrade::NegotiationError::ProtocolError(e),
489-
)) => {
490-
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
491-
upgrade::UpgradeError::Select(upgrade::NegotiationError::ProtocolError(e)),
492-
));
493-
return;
494-
}
495-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Apply(
496-
inbound_hop::UpgradeError::Fatal(error),
497-
)) => {
498-
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
499-
upgrade::UpgradeError::Apply(Either::Left(error)),
500-
));
501-
return;
502-
}
503-
};
504-
505-
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
506-
Event::CircuitReqReceiveFailed {
507-
error: non_fatal_error,
508-
},
474+
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
475+
upgrade::UpgradeError::Apply(Either::Left(error)),
509476
));
510477
}
511478

@@ -524,10 +491,6 @@ impl Handler {
524491
ConnectionHandlerUpgrErr::Timeout,
525492
proto::Status::CONNECTION_FAILED,
526493
),
527-
ConnectionHandlerUpgrErr::Timer => (
528-
ConnectionHandlerUpgrErr::Timer,
529-
proto::Status::CONNECTION_FAILED,
530-
),
531494
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
532495
upgrade::NegotiationError::Failed,
533496
)) => {

protocols/relay/src/priv_client.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ pub enum Event {
7979
src_peer_id: PeerId,
8080
limit: Option<protocol::Limit>,
8181
},
82-
InboundCircuitReqFailed {
83-
relay_peer_id: PeerId,
84-
error: ConnectionHandlerUpgrErr<void::Void>,
85-
},
8682
/// An inbound circuit request has been denied.
8783
InboundCircuitReqDenied { src_peer_id: PeerId },
8884
/// Denying an inbound circuit request failed.
@@ -282,10 +278,6 @@ impl NetworkBehaviour for Behaviour {
282278
handler::Event::InboundCircuitEstablished { src_peer_id, limit } => {
283279
Event::InboundCircuitEstablished { src_peer_id, limit }
284280
}
285-
handler::Event::InboundCircuitReqFailed { error } => Event::InboundCircuitReqFailed {
286-
relay_peer_id: event_source,
287-
error,
288-
},
289281
handler::Event::InboundCircuitReqDenied { src_peer_id } => {
290282
Event::InboundCircuitReqDenied { src_peer_id }
291283
}

protocols/relay/src/priv_client/handler.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ pub enum Event {
9797
src_peer_id: PeerId,
9898
limit: Option<protocol::Limit>,
9999
},
100-
/// An inbound circuit request has failed.
101-
InboundCircuitReqFailed {
102-
error: ConnectionHandlerUpgrErr<void::Void>,
103-
},
104100
/// An inbound circuit request has been denied.
105101
InboundCircuitReqDenied { src_peer_id: PeerId },
106102
/// Denying an inbound circuit request failed.
@@ -295,41 +291,16 @@ impl Handler {
295291

296292
fn on_listen_upgrade_error(
297293
&mut self,
298-
ListenUpgradeError { error, .. }: ListenUpgradeError<
294+
ListenUpgradeError {
295+
error: inbound_stop::UpgradeError::Fatal(error),
296+
..
297+
}: ListenUpgradeError<
299298
<Self as ConnectionHandler>::InboundOpenInfo,
300299
<Self as ConnectionHandler>::InboundProtocol,
301300
>,
302301
) {
303-
let non_fatal_error = match error {
304-
ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout,
305-
ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer,
306-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
307-
upgrade::NegotiationError::Failed,
308-
)) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
309-
upgrade::NegotiationError::Failed,
310-
)),
311-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
312-
upgrade::NegotiationError::ProtocolError(e),
313-
)) => {
314-
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
315-
upgrade::UpgradeError::Select(upgrade::NegotiationError::ProtocolError(e)),
316-
));
317-
return;
318-
}
319-
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Apply(
320-
inbound_stop::UpgradeError::Fatal(error),
321-
)) => {
322-
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
323-
upgrade::UpgradeError::Apply(Either::Left(error)),
324-
));
325-
return;
326-
}
327-
};
328-
329-
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
330-
Event::InboundCircuitReqFailed {
331-
error: non_fatal_error,
332-
},
302+
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(
303+
upgrade::UpgradeError::Apply(Either::Left(error)),
333304
));
334305
}
335306

@@ -347,7 +318,6 @@ impl Handler {
347318
OutboundOpenInfo::Reserve { mut to_listener } => {
348319
let non_fatal_error = match error {
349320
ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout,
350-
ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer,
351321
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
352322
upgrade::NegotiationError::Failed,
353323
)) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
@@ -410,7 +380,6 @@ impl Handler {
410380
OutboundOpenInfo::Connect { send_back } => {
411381
let non_fatal_error = match error {
412382
ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout,
413-
ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer,
414383
ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(
415384
upgrade::NegotiationError::Failed,
416385
)) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select(

0 commit comments

Comments
 (0)