mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-22 14:21:33 +00:00
swarm/: Patch reporting on banned peer connections (#2350)
Don't report events of a connection to the `NetworkBehaviour`, if connection has been established while the remote peer was banned. Among other guarantees this upholds that `NetworkBehaviour::inject_event` is never called without a previous `NetworkBehaviour::inject_connection_established` for said connection. Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
24
CHANGELOG.md
24
CHANGELOG.md
@ -42,10 +42,32 @@
|
||||
|
||||
# `libp2p` facade crate
|
||||
|
||||
## Version 0.41.1 [unreleased]
|
||||
## Version 0.42.0 [unreleased]
|
||||
|
||||
- Update individual crates.
|
||||
- `libp2p-core`
|
||||
- `libp2p-deflate`
|
||||
- `libp2p-dns`
|
||||
- `libp2p-floodsub`
|
||||
- `libp2p-gossipsub`
|
||||
- `libp2p-identify`
|
||||
- `libp2p-kad`
|
||||
- `libp2p-mdns`
|
||||
- `libp2p-metrics`
|
||||
- `libp2p-mplex`
|
||||
- `libp2p-noise`
|
||||
- `libp2p-ping`
|
||||
- `libp2p-plaintext`
|
||||
- `libp2p-relay`
|
||||
- `libp2p-rendezvous`
|
||||
- `libp2p-request-response`
|
||||
- `libp2p-swarm-derive`
|
||||
- `libp2p-swarm`
|
||||
- `libp2p-tcp`
|
||||
- `libp2p-uds`
|
||||
- `libp2p-wasm-ext`
|
||||
- `libp2p-websocket`
|
||||
- `libp2p-yamux`
|
||||
- `libp2p-mdns` (breaking compatibility with previous versions)
|
||||
|
||||
## Version 0.41.0 [2021-11-16]
|
||||
|
38
Cargo.toml
38
Cargo.toml
@ -2,7 +2,7 @@
|
||||
name = "libp2p"
|
||||
edition = "2018"
|
||||
description = "Peer-to-peer networking library"
|
||||
version = "0.41.1"
|
||||
version = "0.42.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -71,25 +71,25 @@ futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` featu
|
||||
getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature
|
||||
instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature
|
||||
lazy_static = "1.2"
|
||||
libp2p-core = { version = "0.30.0", path = "core", default-features = false }
|
||||
libp2p-floodsub = { version = "0.32.0", path = "protocols/floodsub", optional = true }
|
||||
libp2p-core = { version = "0.31.0", path = "core", default-features = false }
|
||||
libp2p-floodsub = { version = "0.33.0", path = "protocols/floodsub", optional = true }
|
||||
libp2p-gossipsub = { version = "0.35.0", path = "./protocols/gossipsub", optional = true }
|
||||
libp2p-identify = { version = "0.32.0", path = "protocols/identify", optional = true }
|
||||
libp2p-kad = { version = "0.33.0", path = "protocols/kad", optional = true }
|
||||
libp2p-identify = { version = "0.33.0", path = "protocols/identify", optional = true }
|
||||
libp2p-kad = { version = "0.34.0", path = "protocols/kad", optional = true }
|
||||
libp2p-metrics = { version = "0.3.0", path = "misc/metrics", optional = true }
|
||||
libp2p-mplex = { version = "0.30.1", path = "muxers/mplex", optional = true }
|
||||
libp2p-noise = { version = "0.33.0", path = "transports/noise", optional = true }
|
||||
libp2p-ping = { version = "0.32.0", path = "protocols/ping", optional = true }
|
||||
libp2p-plaintext = { version = "0.30.0", path = "transports/plaintext", optional = true }
|
||||
libp2p-mplex = { version = "0.31.0", path = "muxers/mplex", optional = true }
|
||||
libp2p-noise = { version = "0.34.0", path = "transports/noise", optional = true }
|
||||
libp2p-ping = { version = "0.33.0", path = "protocols/ping", optional = true }
|
||||
libp2p-plaintext = { version = "0.31.0", path = "transports/plaintext", optional = true }
|
||||
libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true }
|
||||
libp2p-relay = { version = "0.5.0", path = "protocols/relay", optional = true }
|
||||
libp2p-rendezvous = { version = "0.2.0", path = "protocols/rendezvous", optional = true }
|
||||
libp2p-request-response = { version = "0.14.0", path = "protocols/request-response", optional = true }
|
||||
libp2p-swarm = { version = "0.32.0", path = "swarm" }
|
||||
libp2p-relay = { version = "0.6.0", path = "protocols/relay", optional = true }
|
||||
libp2p-rendezvous = { version = "0.3.0", path = "protocols/rendezvous", optional = true }
|
||||
libp2p-request-response = { version = "0.15.0", path = "protocols/request-response", optional = true }
|
||||
libp2p-swarm = { version = "0.33.0", path = "swarm" }
|
||||
libp2p-swarm-derive = { version = "0.26.1", path = "swarm-derive" }
|
||||
libp2p-uds = { version = "0.30.0", path = "transports/uds", optional = true }
|
||||
libp2p-wasm-ext = { version = "0.30.0", path = "transports/wasm-ext", default-features = false, optional = true }
|
||||
libp2p-yamux = { version = "0.34.0", path = "muxers/yamux", optional = true }
|
||||
libp2p-wasm-ext = { version = "0.31.0", path = "transports/wasm-ext", default-features = false, optional = true }
|
||||
libp2p-yamux = { version = "0.35.0", path = "muxers/yamux", optional = true }
|
||||
multiaddr = { version = "0.13.0" }
|
||||
parking_lot = "0.11.0"
|
||||
pin-project = "1.0.0"
|
||||
@ -97,11 +97,11 @@ rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature
|
||||
smallvec = "1.6.1"
|
||||
|
||||
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
|
||||
libp2p-deflate = { version = "0.30.0", path = "transports/deflate", optional = true }
|
||||
libp2p-dns = { version = "0.30.0", path = "transports/dns", optional = true, default-features = false }
|
||||
libp2p-deflate = { version = "0.31.0", path = "transports/deflate", optional = true }
|
||||
libp2p-dns = { version = "0.31.0", path = "transports/dns", optional = true, default-features = false }
|
||||
libp2p-mdns = { version = "0.34.0", path = "protocols/mdns", optional = true }
|
||||
libp2p-tcp = { version = "0.30.0", path = "transports/tcp", default-features = false, optional = true }
|
||||
libp2p-websocket = { version = "0.32.0", path = "transports/websocket", optional = true }
|
||||
libp2p-tcp = { version = "0.31.0", path = "transports/tcp", default-features = false, optional = true }
|
||||
libp2p-websocket = { version = "0.33.0", path = "transports/websocket", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
async-std = { version = "1.6.2", features = ["attributes"] }
|
||||
|
@ -1,3 +1,10 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Report concrete connection IDs in `NetworkEvent::ConnectionEstablished` and
|
||||
`NetworkEvent::ConnectionClosed` (see [PR 2350]).
|
||||
|
||||
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350/
|
||||
|
||||
# 0.30.1 [2021-11-16]
|
||||
|
||||
- Use `instant` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-core"
|
||||
edition = "2018"
|
||||
description = "Core traits and structs of libp2p"
|
||||
version = "0.30.1"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
|
@ -45,7 +45,7 @@ use std::{
|
||||
collections::{hash_map, HashMap},
|
||||
convert::TryFrom as _,
|
||||
fmt,
|
||||
num::{NonZeroU32, NonZeroU8},
|
||||
num::NonZeroU8,
|
||||
pin::Pin,
|
||||
task::Context,
|
||||
task::Poll,
|
||||
@ -156,7 +156,10 @@ where
|
||||
/// A new connection has been established.
|
||||
ConnectionEstablished {
|
||||
connection: EstablishedConnection<'a, THandlerInEvent<THandler>>,
|
||||
num_established: NonZeroU32,
|
||||
/// List of other connections to the same peer.
|
||||
///
|
||||
/// Note: Does not include the connection reported through this event.
|
||||
other_established_connection_ids: Vec<ConnectionId>,
|
||||
/// [`Some`] when the new connection is an outgoing connection.
|
||||
/// Addresses are dialed in parallel. Contains the addresses and errors
|
||||
/// of dial attempts that failed before the one successful dial.
|
||||
@ -183,8 +186,8 @@ where
|
||||
error: Option<ConnectionError<THandlerError<THandler>>>,
|
||||
/// A reference to the pool that used to manage the connection.
|
||||
pool: &'a mut Pool<THandler, TTrans>,
|
||||
/// The remaining number of established connections to the same peer.
|
||||
num_established: u32,
|
||||
/// The remaining established connections to the same peer.
|
||||
remaining_established_connection_ids: Vec<ConnectionId>,
|
||||
handler: THandler::Handler,
|
||||
},
|
||||
|
||||
@ -693,15 +696,16 @@ where
|
||||
let EstablishedConnectionInfo { endpoint, .. } =
|
||||
connections.remove(&id).expect("Connection to be present");
|
||||
self.counters.dec_established(&endpoint);
|
||||
let num_established = u32::try_from(connections.len()).unwrap();
|
||||
if num_established == 0 {
|
||||
let remaining_established_connection_ids: Vec<ConnectionId> =
|
||||
connections.keys().cloned().collect();
|
||||
if remaining_established_connection_ids.is_empty() {
|
||||
self.established.remove(&peer_id);
|
||||
}
|
||||
return Poll::Ready(PoolEvent::ConnectionClosed {
|
||||
id,
|
||||
connected: Connected { endpoint, peer_id },
|
||||
error,
|
||||
num_established,
|
||||
remaining_established_connection_ids,
|
||||
pool: self,
|
||||
handler,
|
||||
});
|
||||
@ -849,8 +853,7 @@ where
|
||||
|
||||
// Add the connection to the pool.
|
||||
let conns = self.established.entry(peer_id).or_default();
|
||||
let num_established = NonZeroU32::new(u32::try_from(conns.len() + 1).unwrap())
|
||||
.expect("n + 1 is always non-zero; qed");
|
||||
let other_established_connection_ids = conns.keys().cloned().collect();
|
||||
self.counters.inc_established(&endpoint);
|
||||
|
||||
let (command_sender, command_receiver) =
|
||||
@ -883,7 +886,7 @@ where
|
||||
Some(PoolConnection::Established(connection)) => {
|
||||
return Poll::Ready(PoolEvent::ConnectionEstablished {
|
||||
connection,
|
||||
num_established,
|
||||
other_established_connection_ids,
|
||||
concurrent_dial_errors,
|
||||
})
|
||||
}
|
||||
|
@ -396,11 +396,11 @@ where
|
||||
Poll::Pending => return Poll::Pending,
|
||||
Poll::Ready(PoolEvent::ConnectionEstablished {
|
||||
connection,
|
||||
num_established,
|
||||
other_established_connection_ids,
|
||||
concurrent_dial_errors,
|
||||
}) => NetworkEvent::ConnectionEstablished {
|
||||
connection,
|
||||
num_established,
|
||||
other_established_connection_ids,
|
||||
concurrent_dial_errors,
|
||||
},
|
||||
Poll::Ready(PoolEvent::PendingOutboundConnectionError {
|
||||
@ -435,13 +435,13 @@ where
|
||||
id,
|
||||
connected,
|
||||
error,
|
||||
num_established,
|
||||
remaining_established_connection_ids,
|
||||
handler,
|
||||
..
|
||||
}) => NetworkEvent::ConnectionClosed {
|
||||
id,
|
||||
connected,
|
||||
num_established,
|
||||
remaining_established_connection_ids,
|
||||
error,
|
||||
handler,
|
||||
},
|
||||
|
@ -29,7 +29,7 @@ use crate::{
|
||||
transport::{Transport, TransportError},
|
||||
Multiaddr, PeerId,
|
||||
};
|
||||
use std::{fmt, num::NonZeroU32};
|
||||
use std::fmt;
|
||||
|
||||
/// Event that can happen on the `Network`.
|
||||
pub enum NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler>
|
||||
@ -100,9 +100,10 @@ where
|
||||
ConnectionEstablished {
|
||||
/// The newly established connection.
|
||||
connection: EstablishedConnection<'a, TInEvent>,
|
||||
/// The total number of established connections to the same peer,
|
||||
/// including the one that has just been opened.
|
||||
num_established: NonZeroU32,
|
||||
/// List of other connections to the same peer.
|
||||
///
|
||||
/// Note: Does not include the connection reported through this event.
|
||||
other_established_connection_ids: Vec<ConnectionId>,
|
||||
/// [`Some`] when the new connection is an outgoing connection.
|
||||
/// Addresses are dialed in parallel. Contains the addresses and errors
|
||||
/// of dial attempts that failed before the one successful dial.
|
||||
@ -128,8 +129,8 @@ where
|
||||
connected: Connected,
|
||||
/// The error that occurred.
|
||||
error: Option<ConnectionError<<THandler::Handler as ConnectionHandler>::Error>>,
|
||||
/// The remaining number of established connections to the same peer.
|
||||
num_established: u32,
|
||||
/// List of remaining established connections to the same peer.
|
||||
remaining_established_connection_ids: Vec<ConnectionId>,
|
||||
handler: THandler::Handler,
|
||||
},
|
||||
|
||||
|
@ -16,12 +16,12 @@ kad = ["libp2p-kad"]
|
||||
ping = ["libp2p-ping"]
|
||||
|
||||
[dependencies]
|
||||
libp2p-core = { version = "0.30.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core" }
|
||||
libp2p-gossipsub = { version = "0.35.0", path = "../../protocols/gossipsub", optional = true }
|
||||
libp2p-identify = { version = "0.32.0", path = "../../protocols/identify", optional = true }
|
||||
libp2p-kad = { version = "0.33.0", path = "../../protocols/kad", optional = true }
|
||||
libp2p-ping = { version = "0.32.0", path = "../../protocols/ping", optional = true }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-identify = { version = "0.33.0", path = "../../protocols/identify", optional = true }
|
||||
libp2p-kad = { version = "0.34.0", path = "../../protocols/kad", optional = true }
|
||||
libp2p-ping = { version = "0.33.0", path = "../../protocols/ping", optional = true }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
open-metrics-client = "0.13.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -11,5 +11,5 @@ categories = ["network-programming", "asynchronous"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
libp2p-core = { path = "../../core", default-features = false }
|
||||
libp2p-core = { path = "../../core", default-features = false, version = "0.31.0"}
|
||||
num_cpus = "1.8"
|
||||
|
@ -1,4 +1,6 @@
|
||||
# 0.30.1 [unreleased]
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
- Add `fn set_protocol_name(&mut self, protocol_name: &'static [u8])` to MplexConfig
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-mplex"
|
||||
edition = "2018"
|
||||
description = "Mplex multiplexing protocol for libp2p"
|
||||
version = "0.30.1"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
bytes = "1"
|
||||
futures = "0.3.1"
|
||||
asynchronous-codec = "0.6"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4"
|
||||
nohash-hasher = "0.2"
|
||||
parking_lot = "0.11"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.35.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.34.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-yamux"
|
||||
edition = "2018"
|
||||
description = "Yamux multiplexing protocol for libp2p"
|
||||
version = "0.34.0"
|
||||
version = "0.35.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
parking_lot = "0.11"
|
||||
thiserror = "1.0"
|
||||
yamux = "0.9.0"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.33.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.32.0 [2021-11-16]
|
||||
|
||||
- Update dependencies.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-floodsub"
|
||||
edition = "2018"
|
||||
description = "Floodsub protocol for libp2p"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"]
|
||||
cuckoofilter = "0.5.0"
|
||||
fnv = "1.0"
|
||||
futures = "0.3.1"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4"
|
||||
prost = "0.9"
|
||||
rand = "0.7"
|
||||
|
@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
bytes = "1.0"
|
||||
byteorder = "1.3.4"
|
||||
fnv = "1.0.7"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.33.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.32.0 [2021-11-16]
|
||||
|
||||
- Use `futures-timer` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-identify"
|
||||
edition = "2018"
|
||||
description = "Nodes identifcation protocol for libp2p"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -12,8 +12,8 @@ categories = ["network-programming", "asynchronous"]
|
||||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
futures-timer = "3.0.2"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4.1"
|
||||
lru = "0.6"
|
||||
prost = "0.9"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.34.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.33.0 [2021-11-16]
|
||||
|
||||
- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-kad"
|
||||
edition = "2018"
|
||||
description = "Kademlia protocol for libp2p"
|
||||
version = "0.33.0"
|
||||
version = "0.34.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -17,8 +17,8 @@ fnv = "1.0"
|
||||
asynchronous-codec = "0.6"
|
||||
futures = "0.3.1"
|
||||
log = "0.4"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
prost = "0.9"
|
||||
rand = "0.7.2"
|
||||
sha2 = "0.9.1"
|
||||
|
@ -1,5 +1,7 @@
|
||||
# 0.34.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
- Use a random alphanumeric string instead of the local peer ID for mDNS peer
|
||||
name (see [PR 2311]).
|
||||
|
||||
|
@ -16,8 +16,8 @@ dns-parser = "0.8.0"
|
||||
futures = "0.3.13"
|
||||
if-watch = "0.2.0"
|
||||
lazy_static = "1.4.0"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4.14"
|
||||
rand = "0.8.3"
|
||||
smallvec = "1.6.1"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.33.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.32.0 [2021-11-16]
|
||||
|
||||
- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-ping"
|
||||
edition = "2018"
|
||||
description = "Ping protocol for libp2p"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"]
|
||||
futures = "0.3.1"
|
||||
futures-timer = "3.0.2"
|
||||
instant = "0.1.11"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4.1"
|
||||
rand = "0.7.2"
|
||||
void = "1.0"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.6.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.5.0 [2021-11-16]
|
||||
|
||||
- Use `instant` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-relay"
|
||||
edition = "2018"
|
||||
description = "Communications relaying for libp2p"
|
||||
version = "0.5.0"
|
||||
version = "0.6.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -15,8 +15,8 @@ bytes = "1"
|
||||
futures = "0.3.1"
|
||||
futures-timer = "3"
|
||||
instant = "0.1.11"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4"
|
||||
pin-project = "1"
|
||||
prost = "0.9"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.3.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.2.0 [2021-11-16]
|
||||
|
||||
- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-rendezvous"
|
||||
edition = "2018"
|
||||
description = "Rendezvous protocol for libp2p"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["The COMIT guys <hello@comit.network>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
asynchronous-codec = "0.6"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
prost = "0.9"
|
||||
void = "1"
|
||||
log = "0.4"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.15.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.14.0 [2021-11-16]
|
||||
|
||||
- Use `instant` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-request-response"
|
||||
edition = "2018"
|
||||
description = "Generic Request/Response Protocols"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -14,8 +14,8 @@ async-trait = "0.1"
|
||||
bytes = "1"
|
||||
futures = "0.3.1"
|
||||
instant = "0.1.11"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.32.0", path = "../../swarm" }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
libp2p-swarm = { version = "0.33.0", path = "../../swarm" }
|
||||
log = "0.4.11"
|
||||
lru = "0.7"
|
||||
rand = "0.7"
|
||||
|
@ -1,3 +1,11 @@
|
||||
# 0.33.0 [unreleased]
|
||||
|
||||
- Patch reporting on banned peers and their non-banned and banned connections (see [PR 2350]).
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350
|
||||
|
||||
# 0.32.0 [2021-11-16]
|
||||
|
||||
- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-swarm"
|
||||
edition = "2018"
|
||||
description = "The libp2p swarm"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
[dependencies]
|
||||
either = "1.6.0"
|
||||
futures = "0.3.1"
|
||||
libp2p-core = { version = "0.30.0", path = "../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../core", default-features = false }
|
||||
log = "0.4"
|
||||
rand = "0.7"
|
||||
smallvec = "1.6.1"
|
||||
|
221
swarm/src/lib.rs
221
swarm/src/lib.rs
@ -97,6 +97,7 @@ use smallvec::SmallVec;
|
||||
use std::collections::HashSet;
|
||||
use std::num::{NonZeroU32, NonZeroU8, NonZeroUsize};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
error, fmt, io,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
@ -275,6 +276,12 @@ where
|
||||
/// List of nodes for which we deny any incoming connection.
|
||||
banned_peers: HashSet<PeerId>,
|
||||
|
||||
/// Connections for which we withhold any reporting. These belong to banned peers.
|
||||
///
|
||||
/// Note: Connections to a peer that are established at the time of banning that peer
|
||||
/// are not added here. Instead they are simply closed.
|
||||
banned_peer_connections: HashSet<ConnectionId>,
|
||||
|
||||
/// Pending event to be delivered to connection handlers
|
||||
/// (or dropped if the peer disconnected) before the `behaviour`
|
||||
/// can be polled again.
|
||||
@ -540,6 +547,10 @@ where
|
||||
pub fn ban_peer_id(&mut self, peer_id: PeerId) {
|
||||
if self.banned_peers.insert(peer_id) {
|
||||
if let Some(peer) = self.network.peer(peer_id).into_connected() {
|
||||
// Note that established connections to the now banned peer are closed but not
|
||||
// added to [`Swarm::banned_peer_connections`]. They have been previously reported
|
||||
// as open to the behaviour and need be reported as closed once closing the
|
||||
// connection finishes.
|
||||
peer.disconnect();
|
||||
}
|
||||
}
|
||||
@ -603,8 +614,12 @@ where
|
||||
Poll::Pending => network_not_ready = true,
|
||||
Poll::Ready(NetworkEvent::ConnectionEvent { connection, event }) => {
|
||||
let peer = connection.peer_id();
|
||||
let connection = connection.id();
|
||||
this.behaviour.inject_event(peer, connection, event);
|
||||
let conn_id = connection.id();
|
||||
if this.banned_peer_connections.contains(&conn_id) {
|
||||
log::debug!("Ignoring event from banned peer: {} {:?}.", peer, conn_id);
|
||||
} else {
|
||||
this.behaviour.inject_event(peer, conn_id, event);
|
||||
}
|
||||
}
|
||||
Poll::Ready(NetworkEvent::AddressChange {
|
||||
connection,
|
||||
@ -612,22 +627,27 @@ where
|
||||
old_endpoint,
|
||||
}) => {
|
||||
let peer = connection.peer_id();
|
||||
let connection = connection.id();
|
||||
let conn_id = connection.id();
|
||||
if !this.banned_peer_connections.contains(&conn_id) {
|
||||
this.behaviour.inject_address_change(
|
||||
&peer,
|
||||
&connection,
|
||||
&conn_id,
|
||||
&old_endpoint,
|
||||
&new_endpoint,
|
||||
);
|
||||
}
|
||||
}
|
||||
Poll::Ready(NetworkEvent::ConnectionEstablished {
|
||||
connection,
|
||||
num_established,
|
||||
other_established_connection_ids,
|
||||
concurrent_dial_errors,
|
||||
}) => {
|
||||
let peer_id = connection.peer_id();
|
||||
let endpoint = connection.endpoint().clone();
|
||||
if this.banned_peers.contains(&peer_id) {
|
||||
// Mark the connection for the banned peer as banned, thus withholding any
|
||||
// future events from the connection to the behaviour.
|
||||
this.banned_peer_connections.insert(connection.id());
|
||||
this.network
|
||||
.peer(peer_id)
|
||||
.into_connected()
|
||||
@ -635,6 +655,11 @@ where
|
||||
.disconnect();
|
||||
return Poll::Ready(SwarmEvent::BannedPeer { peer_id, endpoint });
|
||||
} else {
|
||||
let num_established = NonZeroU32::new(
|
||||
u32::try_from(other_established_connection_ids.len() + 1).unwrap(),
|
||||
)
|
||||
.expect("n + 1 is always non-zero; qed");
|
||||
|
||||
log::debug!(
|
||||
"Connection established: {:?} {:?}; Total (peer): {}.",
|
||||
connection.peer_id(),
|
||||
@ -651,7 +676,13 @@ where
|
||||
&endpoint,
|
||||
failed_addresses.as_ref(),
|
||||
);
|
||||
if num_established.get() == 1 {
|
||||
// The peer is not banned, but there could be previous banned connections
|
||||
// if the peer was just unbanned. Check if this is the first non-banned
|
||||
// connection.
|
||||
let first_non_banned = other_established_connection_ids
|
||||
.into_iter()
|
||||
.all(|conn_id| this.banned_peer_connections.contains(&conn_id));
|
||||
if first_non_banned {
|
||||
this.behaviour.inject_connected(&peer_id);
|
||||
}
|
||||
return Poll::Ready(SwarmEvent::ConnectionEstablished {
|
||||
@ -666,7 +697,7 @@ where
|
||||
id,
|
||||
connected,
|
||||
error,
|
||||
num_established,
|
||||
remaining_established_connection_ids,
|
||||
handler,
|
||||
}) => {
|
||||
if let Some(error) = error.as_ref() {
|
||||
@ -676,14 +707,26 @@ where
|
||||
}
|
||||
let peer_id = connected.peer_id;
|
||||
let endpoint = connected.endpoint;
|
||||
let num_established =
|
||||
u32::try_from(remaining_established_connection_ids.len()).unwrap();
|
||||
let conn_was_reported = !this.banned_peer_connections.remove(&id);
|
||||
if conn_was_reported {
|
||||
this.behaviour.inject_connection_closed(
|
||||
&peer_id,
|
||||
&id,
|
||||
&endpoint,
|
||||
handler.into_protocols_handler(),
|
||||
);
|
||||
if num_established == 0 {
|
||||
this.behaviour.inject_disconnected(&peer_id);
|
||||
|
||||
// This connection was reported as open to the behaviour. Check if this is
|
||||
// the last non-banned connection for the peer.
|
||||
let last_non_banned = remaining_established_connection_ids
|
||||
.into_iter()
|
||||
.all(|conn_id| this.banned_peer_connections.contains(&conn_id));
|
||||
|
||||
if last_non_banned {
|
||||
this.behaviour.inject_disconnected(&peer_id)
|
||||
}
|
||||
}
|
||||
return Poll::Ready(SwarmEvent::ConnectionClosed {
|
||||
peer_id,
|
||||
@ -1253,6 +1296,7 @@ where
|
||||
listened_addrs: SmallVec::new(),
|
||||
external_addrs: Addresses::default(),
|
||||
banned_peers: HashSet::new(),
|
||||
banned_peer_connections: HashSet::new(),
|
||||
pending_event: None,
|
||||
substream_upgrade_protocol_override: self.substream_upgrade_protocol_override,
|
||||
}
|
||||
@ -1450,15 +1494,6 @@ mod tests {
|
||||
TBehaviour: NetworkBehaviour,
|
||||
<<TBehaviour::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent: Clone,
|
||||
{
|
||||
for s in &[swarm1, swarm2] {
|
||||
if s.behaviour.inject_connection_established.len() > 0 {
|
||||
assert_eq!(s.behaviour.inject_connected.len(), 1);
|
||||
} else {
|
||||
assert_eq!(s.behaviour.inject_connected.len(), 0);
|
||||
}
|
||||
assert!(s.behaviour.inject_connection_closed.is_empty());
|
||||
assert!(s.behaviour.inject_disconnected.is_empty());
|
||||
}
|
||||
[swarm1, swarm2]
|
||||
.iter()
|
||||
.all(|s| s.behaviour.inject_connection_established.len() == num_connections)
|
||||
@ -1473,10 +1508,6 @@ mod tests {
|
||||
TBehaviour: NetworkBehaviour,
|
||||
<<TBehaviour::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent: Clone
|
||||
{
|
||||
for s in &[swarm1, swarm2] {
|
||||
assert_eq!(s.behaviour.inject_connection_established.len(), 0);
|
||||
assert_eq!(s.behaviour.inject_connected.len(), 0);
|
||||
}
|
||||
[swarm1, swarm2]
|
||||
.iter()
|
||||
.all(|s| s.behaviour.inject_connection_closed.len() == num_connections)
|
||||
@ -1490,7 +1521,12 @@ mod tests {
|
||||
///
|
||||
/// The test expects both behaviours to be notified via pairs of
|
||||
/// inject_connected / inject_disconnected as well as
|
||||
/// inject_connection_established / inject_connection_closed calls.
|
||||
/// inject_connection_established / inject_connection_closed calls
|
||||
/// while unbanned.
|
||||
///
|
||||
/// While the ban is in effect, further dials occur. For these connections no
|
||||
/// `inject_connected`, `inject_connection_established`, `inject_disconnected`,
|
||||
/// `inject_connection_closed` calls should be registered.
|
||||
#[test]
|
||||
fn test_connect_disconnect_ban() {
|
||||
// Since the test does not try to open any substreams, we can
|
||||
@ -1505,52 +1541,97 @@ mod tests {
|
||||
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
|
||||
swarm1.listen_on(addr1.clone().into()).unwrap();
|
||||
swarm2.listen_on(addr2.clone().into()).unwrap();
|
||||
swarm1.listen_on(addr1.clone()).unwrap();
|
||||
swarm2.listen_on(addr2.clone()).unwrap();
|
||||
|
||||
let swarm1_id = *swarm1.local_peer_id();
|
||||
|
||||
let mut banned = false;
|
||||
let mut unbanned = false;
|
||||
enum Stage {
|
||||
/// Waiting for the peers to connect. Banning has not occurred.
|
||||
Connecting,
|
||||
/// Ban occurred.
|
||||
Banned,
|
||||
// Ban is in place and a dial is ongoing.
|
||||
BannedDial,
|
||||
// Mid-ban dial was registered and the peer was unbanned.
|
||||
Unbanned,
|
||||
// There are dial attempts ongoing for the no longer banned peers.
|
||||
Reconnecting,
|
||||
}
|
||||
|
||||
let num_connections = 10;
|
||||
|
||||
for _ in 0..num_connections {
|
||||
swarm1.dial(addr2.clone()).unwrap();
|
||||
}
|
||||
let mut state = State::Connecting;
|
||||
|
||||
executor::block_on(future::poll_fn(move |cx| {
|
||||
loop {
|
||||
let mut s1_expected_conns = num_connections;
|
||||
let mut s2_expected_conns = num_connections;
|
||||
|
||||
let mut stage = Stage::Connecting;
|
||||
|
||||
executor::block_on(future::poll_fn(move |cx| loop {
|
||||
let poll1 = Swarm::poll_next_event(Pin::new(&mut swarm1), cx);
|
||||
let poll2 = Swarm::poll_next_event(Pin::new(&mut swarm2), cx);
|
||||
match state {
|
||||
State::Connecting => {
|
||||
if swarms_connected(&swarm1, &swarm2, num_connections) {
|
||||
if banned {
|
||||
return Poll::Ready(());
|
||||
}
|
||||
swarm2.ban_peer_id(swarm1_id.clone());
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
banned = true;
|
||||
state = State::Disconnecting;
|
||||
match stage {
|
||||
Stage::Connecting => {
|
||||
if swarm1.behaviour.assert_connected(s1_expected_conns, 1)
|
||||
&& swarm2.behaviour.assert_connected(s2_expected_conns, 1)
|
||||
{
|
||||
// Setup to test that already established connections are correctly closed
|
||||
// and reported as such after the peer is banned.
|
||||
swarm2.ban_peer_id(swarm1_id);
|
||||
stage = Stage::Banned;
|
||||
}
|
||||
}
|
||||
State::Disconnecting => {
|
||||
if swarms_disconnected(&swarm1, &swarm2, num_connections) {
|
||||
if unbanned {
|
||||
return Poll::Ready(());
|
||||
Stage::Banned => {
|
||||
if swarm1.behaviour.assert_disconnected(s1_expected_conns, 1)
|
||||
&& swarm2.behaviour.assert_disconnected(s2_expected_conns, 1)
|
||||
{
|
||||
// Setup to test that new connections of banned peers are not reported.
|
||||
swarm1.dial(addr2.clone()).unwrap();
|
||||
s1_expected_conns += 1;
|
||||
stage = Stage::BannedDial;
|
||||
}
|
||||
// Unban the first peer and reconnect.
|
||||
swarm2.unban_peer_id(swarm1_id.clone());
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
unbanned = true;
|
||||
}
|
||||
Stage::BannedDial => {
|
||||
if swarm2.network_info().num_peers() == 1 {
|
||||
// The banned connection was established. Check that it was not reported to
|
||||
// the behaviour of the banning swarm.
|
||||
assert_eq!(
|
||||
swarm2.behaviour.inject_connection_established.len(), s2_expected_conns,
|
||||
"No additional closed connections should be reported for the banned peer"
|
||||
);
|
||||
|
||||
// Setup to test that the banned connection is not reported upon closing
|
||||
// even if the peer is unbanned.
|
||||
swarm2.unban_peer_id(swarm1_id);
|
||||
stage = Stage::Unbanned;
|
||||
}
|
||||
}
|
||||
Stage::Unbanned => {
|
||||
if swarm2.network_info().num_peers() == 0 {
|
||||
// The banned connection has closed. Check that it was not reported.
|
||||
assert_eq!(
|
||||
swarm2.behaviour.inject_connection_closed.len(), s2_expected_conns,
|
||||
"No additional closed connections should be reported for the banned peer"
|
||||
);
|
||||
assert!(swarm2.banned_peer_connections.is_empty());
|
||||
|
||||
// Setup to test that a ban lifted does not affect future connections.
|
||||
for _ in 0..num_connections {
|
||||
swarm2.dial(addr1.clone()).unwrap();
|
||||
swarm1.dial(addr2.clone()).unwrap();
|
||||
}
|
||||
state = State::Connecting;
|
||||
s1_expected_conns += num_connections;
|
||||
s2_expected_conns += num_connections;
|
||||
stage = Stage::Reconnecting;
|
||||
}
|
||||
}
|
||||
Stage::Reconnecting => {
|
||||
if swarm1.behaviour.inject_connection_established.len() == s1_expected_conns
|
||||
&& swarm2.behaviour.assert_connected(s2_expected_conns, 2)
|
||||
{
|
||||
return Poll::Ready(());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1558,7 +1639,6 @@ mod tests {
|
||||
if poll1.is_pending() && poll2.is_pending() {
|
||||
return Poll::Pending;
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
@ -1582,8 +1662,8 @@ mod tests {
|
||||
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
|
||||
swarm1.listen_on(addr1.clone().into()).unwrap();
|
||||
swarm2.listen_on(addr2.clone().into()).unwrap();
|
||||
swarm1.listen_on(addr1.clone()).unwrap();
|
||||
swarm2.listen_on(addr2.clone()).unwrap();
|
||||
|
||||
let swarm1_id = *swarm1.local_peer_id();
|
||||
|
||||
@ -1605,10 +1685,8 @@ mod tests {
|
||||
return Poll::Ready(());
|
||||
}
|
||||
swarm2
|
||||
.disconnect_peer_id(swarm1_id.clone())
|
||||
.disconnect_peer_id(swarm1_id)
|
||||
.expect("Error disconnecting");
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
state = State::Disconnecting;
|
||||
}
|
||||
}
|
||||
@ -1618,8 +1696,6 @@ mod tests {
|
||||
return Poll::Ready(());
|
||||
}
|
||||
reconnected = true;
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
for _ in 0..num_connections {
|
||||
swarm2.dial(addr1.clone()).unwrap();
|
||||
}
|
||||
@ -1655,8 +1731,8 @@ mod tests {
|
||||
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
|
||||
swarm1.listen_on(addr1.clone().into()).unwrap();
|
||||
swarm2.listen_on(addr2.clone().into()).unwrap();
|
||||
swarm1.listen_on(addr1.clone()).unwrap();
|
||||
swarm2.listen_on(addr2.clone()).unwrap();
|
||||
|
||||
let swarm1_id = *swarm1.local_peer_id();
|
||||
|
||||
@ -1679,12 +1755,10 @@ mod tests {
|
||||
}
|
||||
swarm2.behaviour.inner().next_action.replace(
|
||||
NetworkBehaviourAction::CloseConnection {
|
||||
peer_id: swarm1_id.clone(),
|
||||
peer_id: swarm1_id,
|
||||
connection: CloseConnection::All,
|
||||
},
|
||||
);
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
state = State::Disconnecting;
|
||||
}
|
||||
}
|
||||
@ -1694,8 +1768,6 @@ mod tests {
|
||||
return Poll::Ready(());
|
||||
}
|
||||
reconnected = true;
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
for _ in 0..num_connections {
|
||||
swarm2.dial(addr1.clone()).unwrap();
|
||||
}
|
||||
@ -1731,8 +1803,8 @@ mod tests {
|
||||
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
|
||||
|
||||
swarm1.listen_on(addr1.clone().into()).unwrap();
|
||||
swarm2.listen_on(addr2.clone().into()).unwrap();
|
||||
swarm1.listen_on(addr1.clone()).unwrap();
|
||||
swarm2.listen_on(addr2.clone()).unwrap();
|
||||
|
||||
let swarm1_id = *swarm1.local_peer_id();
|
||||
|
||||
@ -1756,22 +1828,23 @@ mod tests {
|
||||
.1;
|
||||
swarm2.behaviour.inner().next_action.replace(
|
||||
NetworkBehaviourAction::CloseConnection {
|
||||
peer_id: swarm1_id.clone(),
|
||||
peer_id: swarm1_id,
|
||||
connection: CloseConnection::One(conn_id),
|
||||
},
|
||||
);
|
||||
Some(conn_id)
|
||||
};
|
||||
swarm1.behaviour.reset();
|
||||
swarm2.behaviour.reset();
|
||||
state = State::Disconnecting;
|
||||
}
|
||||
}
|
||||
State::Disconnecting => {
|
||||
for s in &[&swarm1, &swarm2] {
|
||||
assert_eq!(s.behaviour.inject_disconnected.len(), 0);
|
||||
assert_eq!(s.behaviour.inject_connection_established.len(), 0);
|
||||
assert_eq!(s.behaviour.inject_connected.len(), 0);
|
||||
assert_eq!(
|
||||
s.behaviour.inject_connection_established.len(),
|
||||
num_connections
|
||||
);
|
||||
assert_eq!(s.behaviour.inject_connected.len(), 1);
|
||||
}
|
||||
if [&swarm1, &swarm2]
|
||||
.iter()
|
||||
|
@ -91,7 +91,7 @@ where
|
||||
|
||||
/// A `CallTraceBehaviour` is a `NetworkBehaviour` that tracks
|
||||
/// invocations of callback methods and their arguments, wrapping
|
||||
/// around an inner behaviour.
|
||||
/// around an inner behaviour. It ensures certain invariants are met.
|
||||
pub struct CallTraceBehaviour<TInner>
|
||||
where
|
||||
TInner: NetworkBehaviour,
|
||||
@ -144,6 +144,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn reset(&mut self) {
|
||||
self.addresses_of_peer = Vec::new();
|
||||
self.inject_connected = Vec::new();
|
||||
@ -163,6 +164,40 @@ where
|
||||
pub fn inner(&mut self) -> &mut TInner {
|
||||
&mut self.inner
|
||||
}
|
||||
|
||||
/// Checks that when the expected number of closed connection notifications are received, a
|
||||
/// given number of expected disconnections have been received as well.
|
||||
///
|
||||
/// Returns if the first condition is met.
|
||||
pub fn assert_disconnected(
|
||||
&self,
|
||||
expected_closed_connections: usize,
|
||||
expected_disconnections: usize,
|
||||
) -> bool {
|
||||
if self.inject_connection_closed.len() == expected_closed_connections {
|
||||
assert_eq!(self.inject_disconnected.len(), expected_disconnections);
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// Checks that when the expected number of established connection notifications are received,
|
||||
/// a given number of expected connections have been received as well.
|
||||
///
|
||||
/// Returns if the first condition is met.
|
||||
pub fn assert_connected(
|
||||
&self,
|
||||
expected_established_connections: usize,
|
||||
expected_connections: usize,
|
||||
) -> bool {
|
||||
if self.inject_connection_established.len() == expected_established_connections {
|
||||
assert_eq!(self.inject_connected.len(), expected_connections);
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<TInner> NetworkBehaviour for CallTraceBehaviour<TInner>
|
||||
@ -184,6 +219,12 @@ where
|
||||
}
|
||||
|
||||
fn inject_connected(&mut self, peer: &PeerId) {
|
||||
assert!(
|
||||
self.inject_connection_established
|
||||
.iter()
|
||||
.any(|(peer_id, _, _)| peer_id == peer),
|
||||
"`inject_connected` is called after at least one `inject_connection_established`."
|
||||
);
|
||||
self.inject_connected.push(peer.clone());
|
||||
self.inner.inject_connected(peer);
|
||||
}
|
||||
@ -201,7 +242,13 @@ where
|
||||
}
|
||||
|
||||
fn inject_disconnected(&mut self, peer: &PeerId) {
|
||||
self.inject_disconnected.push(peer.clone());
|
||||
assert!(
|
||||
self.inject_connection_closed
|
||||
.iter()
|
||||
.any(|(peer_id, _, _)| peer_id == peer),
|
||||
"`inject_disconnected` is called after at least one `inject_connection_closed`."
|
||||
);
|
||||
self.inject_disconnected.push(*peer);
|
||||
self.inner.inject_disconnected(peer);
|
||||
}
|
||||
|
||||
@ -212,8 +259,13 @@ where
|
||||
e: &ConnectedPoint,
|
||||
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
|
||||
) {
|
||||
self.inject_connection_closed
|
||||
.push((p.clone(), c.clone(), e.clone()));
|
||||
let connection = (p.clone(), c.clone(), e.clone());
|
||||
assert!(
|
||||
self.inject_connection_established.contains(&connection),
|
||||
"`inject_connection_closed` is called only for connections for \
|
||||
which `inject_connection_established` was called first."
|
||||
);
|
||||
self.inject_connection_closed.push(connection);
|
||||
self.inner.inject_connection_closed(p, c, e, handler);
|
||||
}
|
||||
|
||||
@ -223,6 +275,20 @@ where
|
||||
c: ConnectionId,
|
||||
e: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
|
||||
) {
|
||||
assert!(
|
||||
self.inject_connection_established
|
||||
.iter()
|
||||
.any(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id),
|
||||
"`inject_event` is called for reported connections."
|
||||
);
|
||||
assert!(
|
||||
!self
|
||||
.inject_connection_closed
|
||||
.iter()
|
||||
.any(|(peer_id, conn_id, _)| *peer_id == p && c == *conn_id),
|
||||
"`inject_event` is never called for closed connections."
|
||||
);
|
||||
|
||||
self.inject_event.push((p.clone(), c.clone(), e.clone()));
|
||||
self.inner.inject_event(p, c, e);
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-deflate"
|
||||
edition = "2018"
|
||||
description = "Deflate encryption protocol for libp2p"
|
||||
version = "0.30.0"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
flate2 = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-dns"
|
||||
edition = "2018"
|
||||
description = "DNS transport implementation for libp2p"
|
||||
version = "0.30.0"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4.1"
|
||||
futures = "0.3.1"
|
||||
trust-dns-resolver = { version = "0.20", default-features = false, features = ["system-config"] }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.34.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.33.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "libp2p-noise"
|
||||
description = "Cryptographic handshake protocol using the noise framework."
|
||||
version = "0.33.0"
|
||||
version = "0.34.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -12,7 +12,7 @@ bytes = "1"
|
||||
curve25519-dalek = "3.0.0"
|
||||
futures = "0.3.1"
|
||||
lazy_static = "1.2"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4"
|
||||
prost = "0.9"
|
||||
rand = "0.8.3"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-plaintext"
|
||||
edition = "2018"
|
||||
description = "Plaintext encryption dummy protocol for libp2p"
|
||||
version = "0.30.0"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
bytes = "1"
|
||||
futures = "0.3.1"
|
||||
asynchronous-codec = "0.6"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4.8"
|
||||
prost = "0.9"
|
||||
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-tcp"
|
||||
edition = "2018"
|
||||
description = "TCP/IP transport protocol for libp2p"
|
||||
version = "0.30.0"
|
||||
version = "0.31.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -17,7 +17,7 @@ if-watch = { version = "0.2.0", optional = true }
|
||||
if-addrs = { version = "0.6.4", optional = true }
|
||||
ipnet = "2.0.0"
|
||||
libc = "0.2.80"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4.11"
|
||||
socket2 = { version = "0.4.0", features = ["all"] }
|
||||
tokio-crate = { package = "tokio", version = "1.0.1", default-features = false, features = ["net"], optional = true }
|
||||
|
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies]
|
||||
async-std = { version = "1.6.2", optional = true }
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4.1"
|
||||
futures = "0.3.1"
|
||||
tokio = { version = "1.0.1", default-features = false, features = ["net"], optional = true }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.31.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# 0.30.0 [2021-11-01]
|
||||
|
||||
- Make default features of `libp2p-core` optional.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libp2p-wasm-ext"
|
||||
version = "0.30.0"
|
||||
version = "0.31.0"
|
||||
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Allows passing in an external transport in a WASM environment"
|
||||
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
js-sys = "0.3.50"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
parity-send-wrapper = "0.1.0"
|
||||
wasm-bindgen = "0.2.42"
|
||||
wasm-bindgen-futures = "0.4.4"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.33.0 [unreleased]
|
||||
|
||||
- Update dependencies.
|
||||
|
||||
# v0.32.0 [2021-11-16]
|
||||
|
||||
- Handle websocket CLOSE with reason code (see [PR 2085]).
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-websocket"
|
||||
edition = "2018"
|
||||
description = "WebSocket transport for libp2p"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
futures-rustls = "0.22"
|
||||
either = "1.5.3"
|
||||
futures = "0.3.1"
|
||||
libp2p-core = { version = "0.30.0", path = "../../core", default-features = false }
|
||||
libp2p-core = { version = "0.31.0", path = "../../core", default-features = false }
|
||||
log = "0.4.8"
|
||||
quicksink = "0.1"
|
||||
rw-stream-sink = "0.2.0"
|
||||
|
Reference in New Issue
Block a user