mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
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.
This commit is contained in:
@ -161,30 +161,14 @@ where
|
||||
}
|
||||
fn on_listen_upgrade_error(
|
||||
&mut self,
|
||||
ListenUpgradeError { info, error }: ListenUpgradeError<
|
||||
ListenUpgradeError { error, .. }: ListenUpgradeError<
|
||||
<Self as ConnectionHandler>::InboundOpenInfo,
|
||||
<Self as ConnectionHandler>::InboundProtocol,
|
||||
>,
|
||||
) {
|
||||
match error {
|
||||
ConnectionHandlerUpgrErr::Timeout => {
|
||||
self.pending_events.push_back(Event::InboundTimeout(info))
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
||||
// The local peer merely doesn't support the protocol(s) requested.
|
||||
// This is no reason to close the connection, which may
|
||||
// successfully communicate with other protocols already.
|
||||
// An event is reported to permit user code to react to the fact that
|
||||
// the local peer does not support the requested protocol(s).
|
||||
self.pending_events
|
||||
.push_back(Event::InboundUnsupportedProtocols(info));
|
||||
}
|
||||
_ => {
|
||||
// Anything else is considered a fatal error or misbehaviour of
|
||||
// the remote peer and results in closing the connection.
|
||||
self.pending_error = Some(error);
|
||||
}
|
||||
}
|
||||
self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(
|
||||
error,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,11 +198,6 @@ where
|
||||
OutboundTimeout(RequestId),
|
||||
/// An outbound request failed to negotiate a mutually supported protocol.
|
||||
OutboundUnsupportedProtocols(RequestId),
|
||||
/// An inbound request timed out while waiting for the request
|
||||
/// or sending the response.
|
||||
InboundTimeout(RequestId),
|
||||
/// An inbound request failed to negotiate a mutually supported protocol.
|
||||
InboundUnsupportedProtocols(RequestId),
|
||||
}
|
||||
|
||||
impl<TCodec: Codec> fmt::Debug for Event<TCodec> {
|
||||
@ -255,14 +234,6 @@ impl<TCodec: Codec> fmt::Debug for Event<TCodec> {
|
||||
.debug_tuple("Event::OutboundUnsupportedProtocols")
|
||||
.field(request_id)
|
||||
.finish(),
|
||||
Event::InboundTimeout(request_id) => f
|
||||
.debug_tuple("Event::InboundTimeout")
|
||||
.field(request_id)
|
||||
.finish(),
|
||||
Event::InboundUnsupportedProtocols(request_id) => f
|
||||
.debug_tuple("Event::InboundUnsupportedProtocols")
|
||||
.field(request_id)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -857,20 +857,6 @@ where
|
||||
error: OutboundFailure::Timeout,
|
||||
}));
|
||||
}
|
||||
handler::Event::InboundTimeout(request_id) => {
|
||||
// Note: `Event::InboundTimeout` is emitted both for timing
|
||||
// out to receive the request and for timing out sending the response. In the former
|
||||
// case the request is never added to `pending_outbound_responses` and thus one can
|
||||
// not assert the request_id to be present before removing it.
|
||||
self.remove_pending_outbound_response(&peer, connection, request_id);
|
||||
|
||||
self.pending_events
|
||||
.push_back(ToSwarm::GenerateEvent(Event::InboundFailure {
|
||||
peer,
|
||||
request_id,
|
||||
error: InboundFailure::Timeout,
|
||||
}));
|
||||
}
|
||||
handler::Event::OutboundUnsupportedProtocols(request_id) => {
|
||||
let removed = self.remove_pending_inbound_response(&peer, connection, &request_id);
|
||||
debug_assert!(
|
||||
@ -885,17 +871,6 @@ where
|
||||
error: OutboundFailure::UnsupportedProtocols,
|
||||
}));
|
||||
}
|
||||
handler::Event::InboundUnsupportedProtocols(request_id) => {
|
||||
// Note: No need to call `self.remove_pending_outbound_response`,
|
||||
// `Event::Request` was never emitted for this request and
|
||||
// thus request was never added to `pending_outbound_responses`.
|
||||
self.pending_events
|
||||
.push_back(ToSwarm::GenerateEvent(Event::InboundFailure {
|
||||
peer,
|
||||
request_id,
|
||||
error: InboundFailure::UnsupportedProtocols,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user