mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-29 18:51:22 +00:00
swarm/src/toggle: Ignore listen upgr errors when disabled (#1945)
* swarm/src/toggle: Ignore listen upgr errors when disabled A disabled `ToggleProtoHandler` can receive listen upgrade errors in the following two cases: 1. Protocol negotiation on an incoming stream failed with no protocol being agreed on. 2. When combining `ProtocolsHandler` implementations a single `ProtocolsHandler` might be notified of an inbound upgrade error unrelated to its own upgrade logic. For example when nesting a `ToggleProtoHandler` in a `ProtocolsHandlerSelect` the former might receive an inbound upgrade error even when disabled. `ToggleProtoHandler` should ignore the error in both of these cases. * *: Prepare libp2p-swarm v0.27.2 release
This commit is contained in:
parent
d94d53abbb
commit
c897df3f34
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
- Use `libp2p-swarm-derive`, the former `libp2p-core-derive`.
|
- Use `libp2p-swarm-derive`, the former `libp2p-core-derive`.
|
||||||
|
|
||||||
- Update `libp2p-gossipsub` and `libp2p-request-response`.
|
- Update `libp2p-gossipsub`, `libp2p-request-response` and `libp2p-swarm`.
|
||||||
|
|
||||||
## Version 0.34.0 [2021-01-12]
|
## Version 0.34.0 [2021-01-12]
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ libp2p-ping = { version = "0.27.0", path = "protocols/ping", optional = true }
|
|||||||
libp2p-plaintext = { version = "0.27.0", path = "transports/plaintext", optional = true }
|
libp2p-plaintext = { version = "0.27.0", path = "transports/plaintext", optional = true }
|
||||||
libp2p-pnet = { version = "0.20.0", path = "transports/pnet", optional = true }
|
libp2p-pnet = { version = "0.20.0", path = "transports/pnet", optional = true }
|
||||||
libp2p-request-response = { version = "0.9.1", path = "protocols/request-response", optional = true }
|
libp2p-request-response = { version = "0.9.1", path = "protocols/request-response", optional = true }
|
||||||
libp2p-swarm = { version = "0.27.1", path = "swarm" }
|
libp2p-swarm = { version = "0.27.2", path = "swarm" }
|
||||||
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
|
libp2p-swarm-derive = { version = "0.22.0", path = "swarm-derive" }
|
||||||
libp2p-uds = { version = "0.27.0", path = "transports/uds", optional = true }
|
libp2p-uds = { version = "0.27.0", path = "transports/uds", optional = true }
|
||||||
libp2p-wasm-ext = { version = "0.27.0", path = "transports/wasm-ext", optional = true }
|
libp2p-wasm-ext = { version = "0.27.0", path = "transports/wasm-ext", optional = true }
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
# 0.27.2 [2021-02-04]
|
||||||
|
|
||||||
|
- Have `ToggleProtoHandler` ignore listen upgrade errors when disabled.
|
||||||
|
[PR 1945](https://github.com/libp2p/rust-libp2p/pull/1945/files).
|
||||||
|
|
||||||
# 0.27.1 [2021-01-27]
|
# 0.27.1 [2021-01-27]
|
||||||
|
|
||||||
- Make `OneShotHandler`s `max_dial_negotiate` limit configurable.
|
- Make `OneShotHandler`s `max_dial_negotiate` limit configurable.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libp2p-swarm"
|
name = "libp2p-swarm"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "The libp2p swarm"
|
description = "The libp2p swarm"
|
||||||
version = "0.27.1"
|
version = "0.27.2"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/libp2p/rust-libp2p"
|
repository = "https://github.com/libp2p/rust-libp2p"
|
||||||
|
@ -271,6 +271,21 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn inject_listen_upgrade_error(&mut self, info: Self::InboundOpenInfo, err: ProtocolsHandlerUpgrErr<<Self::InboundProtocol as InboundUpgradeSend>::Error>) {
|
fn inject_listen_upgrade_error(&mut self, info: Self::InboundOpenInfo, err: ProtocolsHandlerUpgrErr<<Self::InboundProtocol as InboundUpgradeSend>::Error>) {
|
||||||
|
let (inner, info) = match (self.inner.as_mut(), info) {
|
||||||
|
(Some(inner), Either::Left(info)) => (inner, info),
|
||||||
|
// Ignore listen upgrade errors in disabled state.
|
||||||
|
(None, Either::Right(())) => return,
|
||||||
|
(Some(_), Either::Right(())) => panic!(
|
||||||
|
"Unexpected `Either::Right` inbound info through \
|
||||||
|
`inject_listen_upgrade_error` in enabled state.",
|
||||||
|
),
|
||||||
|
(None, Either::Left(_)) => panic!(
|
||||||
|
"Unexpected `Either::Left` inbound info through \
|
||||||
|
`inject_listen_upgrade_error` in disabled state.",
|
||||||
|
),
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
let err = match err {
|
let err = match err {
|
||||||
ProtocolsHandlerUpgrErr::Timeout => ProtocolsHandlerUpgrErr::Timeout,
|
ProtocolsHandlerUpgrErr::Timeout => ProtocolsHandlerUpgrErr::Timeout,
|
||||||
ProtocolsHandlerUpgrErr::Timer => ProtocolsHandlerUpgrErr::Timer,
|
ProtocolsHandlerUpgrErr::Timer => ProtocolsHandlerUpgrErr::Timer,
|
||||||
@ -280,13 +295,8 @@ where
|
|||||||
EitherError::B(v) => void::unreachable(v)
|
EitherError::B(v) => void::unreachable(v)
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
if let Either::Left(info) = info {
|
|
||||||
self.inner.as_mut()
|
inner.inject_listen_upgrade_error(info, err)
|
||||||
.expect("Can't receive an inbound substream if disabled; QED")
|
|
||||||
.inject_listen_upgrade_error(info, err)
|
|
||||||
} else {
|
|
||||||
panic!("Unexpected Either::Right on enabled `inject_listen_upgrade_error`.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connection_keep_alive(&self) -> KeepAlive {
|
fn connection_keep_alive(&self) -> KeepAlive {
|
||||||
@ -307,3 +317,32 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::protocols_handler::DummyProtocolsHandler;
|
||||||
|
|
||||||
|
/// A disabled [`ToggleProtoHandler`] can receive listen upgrade errors in
|
||||||
|
/// the following two cases:
|
||||||
|
///
|
||||||
|
/// 1. Protocol negotiation on an incoming stream failed with no protocol
|
||||||
|
/// being agreed on.
|
||||||
|
///
|
||||||
|
/// 2. When combining [`ProtocolsHandler`] implementations a single
|
||||||
|
/// [`ProtocolsHandler`] might be notified of an inbound upgrade error
|
||||||
|
/// unrelated to its own upgrade logic. For example when nesting a
|
||||||
|
/// [`ToggleProtoHandler`] in a
|
||||||
|
/// [`ProtocolsHandlerSelect`](crate::protocols_handler::ProtocolsHandlerSelect)
|
||||||
|
/// the former might receive an inbound upgrade error even when disabled.
|
||||||
|
///
|
||||||
|
/// [`ToggleProtoHandler`] should ignore the error in both of these cases.
|
||||||
|
#[test]
|
||||||
|
fn ignore_listen_upgrade_error_when_disabled() {
|
||||||
|
let mut handler = ToggleProtoHandler::<DummyProtocolsHandler> {
|
||||||
|
inner: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
handler.inject_listen_upgrade_error(Either::Right(()), ProtocolsHandlerUpgrErr::Timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user