mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-13 19:31:20 +00:00
fix(tcp): remove correct listener inTransport::remove_listener
(#3387)
`libp2p_tcp::Transport::remove_listener` previously removed the first listener that *did not match* the provided `ListenerId`. This small fix brings it inline with other implementations.
This commit is contained in:
parent
ab59af4d46
commit
d344406235
@ -1,6 +1,9 @@
|
|||||||
# 0.39.0 [unreleased]
|
# 0.39.0 [unreleased]
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.39.0`.
|
- Update to `libp2p-core` `v0.39.0`.
|
||||||
|
- Fix a bug where we removed any other listener in `Transport::remove_listener` except for the one with the provided `ListenerId`. See [PR 3387].
|
||||||
|
|
||||||
|
[PR 3387]: https://github.com/libp2p/rust-libp2p/pull/3387
|
||||||
|
|
||||||
# 0.38.0
|
# 0.38.0
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn remove_listener(&mut self, id: ListenerId) -> bool {
|
fn remove_listener(&mut self, id: ListenerId) -> bool {
|
||||||
if let Some(index) = self.listeners.iter().position(|l| l.listener_id != id) {
|
if let Some(index) = self.listeners.iter().position(|l| l.listener_id == id) {
|
||||||
self.listeners.remove(index);
|
self.listeners.remove(index);
|
||||||
self.pending_events
|
self.pending_events
|
||||||
.push_back(TransportEvent::ListenerClosed {
|
.push_back(TransportEvent::ListenerClosed {
|
||||||
@ -1335,4 +1335,31 @@ mod tests {
|
|||||||
.address_translation(&quic_addr, &tcp_observed_addr)
|
.address_translation(&quic_addr, &tcp_observed_addr)
|
||||||
.is_none());
|
.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_remove_listener() {
|
||||||
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
|
async fn cycle_listeners<T: Provider>() -> bool {
|
||||||
|
let mut tcp = Transport::<T>::default().boxed();
|
||||||
|
let listener_id = tcp
|
||||||
|
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
tcp.remove_listener(listener_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "async-io")]
|
||||||
|
{
|
||||||
|
assert!(async_std::task::block_on(cycle_listeners::<async_io::Tcp>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
|
{
|
||||||
|
let rt = ::tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_io()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
assert!(rt.block_on(cycle_listeners::<tokio::Tcp>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user