mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
misc/multistream-select: Interpretation of EOF as Failed negotiation (#1823)
Treat EOF error as [`NegotiationError::Failed`], not as [`NegotiationError::ProtocolError`], allowing dropping or closing an I/O stream as a permissible way to "gracefully" fail a negotiation. This is e.g. important when a listener rejects a protocol with [`Message::NotAvailable`] and the dialer does not have alternative protocols to propose. Then the dialer will stop the negotiation and drop the corresponding stream. As a listener this EOF should be interpreted as a failed negotiation.
This commit is contained in:
@ -85,9 +85,8 @@ fn no_protocol_found() {
|
||||
let protos = vec![b"/proto1", b"/proto2"];
|
||||
let io = match listener_select_proto(connec, protos).await {
|
||||
Ok((_, io)) => io,
|
||||
// We don't explicitly check for `Failed` because the client might close the connection when it
|
||||
// realizes that we have no protocol in common.
|
||||
Err(_) => return,
|
||||
Err(NegotiationError::Failed) => return,
|
||||
Err(NegotiationError::ProtocolError(e)) => panic!("Unexpected protocol error {}", e),
|
||||
};
|
||||
match io.complete().await {
|
||||
Err(NegotiationError::Failed) => {},
|
||||
|
Reference in New Issue
Block a user