From ca07ce4d6455583794558c076e2719660abb46b2 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 26 Aug 2022 07:08:33 +0200 Subject: [PATCH 1/4] swarm/behaviour: Remove deprecated NetworkBehaviourEventProcess (#2840) Removes the `NetworkBehaviourEventProcess` and all its associated logic. See deprecation pull request https://github.com/libp2p/rust-libp2p/pull/2784. Find rational in https://github.com/libp2p/rust-libp2p/pull/2751. --- CHANGELOG.md | 22 ++++++++++ Cargo.toml | 30 +++++++------- misc/metrics/CHANGELOG.md | 14 +++++++ misc/metrics/Cargo.toml | 16 ++++---- protocols/autonat/CHANGELOG.md | 6 +++ protocols/autonat/Cargo.toml | 6 +-- protocols/dcutr/CHANGELOG.md | 4 ++ protocols/dcutr/Cargo.toml | 4 +- protocols/floodsub/CHANGELOG.md | 4 ++ protocols/floodsub/Cargo.toml | 4 +- protocols/gossipsub/CHANGELOG.md | 4 ++ protocols/gossipsub/Cargo.toml | 4 +- protocols/identify/CHANGELOG.md | 4 ++ protocols/identify/Cargo.toml | 4 +- protocols/kad/CHANGELOG.md | 4 ++ protocols/kad/Cargo.toml | 4 +- protocols/mdns/CHANGELOG.md | 4 ++ protocols/mdns/Cargo.toml | 4 +- protocols/ping/CHANGELOG.md | 4 ++ protocols/ping/Cargo.toml | 4 +- protocols/relay/CHANGELOG.md | 4 ++ protocols/relay/Cargo.toml | 4 +- protocols/rendezvous/CHANGELOG.md | 4 ++ protocols/rendezvous/Cargo.toml | 4 +- protocols/request-response/CHANGELOG.md | 4 ++ protocols/request-response/Cargo.toml | 4 +- swarm-derive/CHANGELOG.md | 4 ++ swarm-derive/Cargo.toml | 2 +- swarm-derive/src/lib.rs | 53 ++----------------------- swarm-derive/tests/test.rs | 35 ---------------- swarm/CHANGELOG.md | 7 ++++ swarm/Cargo.toml | 2 +- swarm/src/behaviour.rs | 18 --------- swarm/src/behaviour/either.rs | 17 -------- swarm/src/behaviour/toggle.rs | 14 ------- swarm/src/lib.rs | 2 - 36 files changed, 145 insertions(+), 183 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edbbc8fb1d80..b9d574ea35f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,28 @@ # `libp2p` facade crate +# 0.48.0 [unreleased] + +- Update to [`libp2p-dcutr` `v0.6.0`](protocols/dcutr/CHANGELOG.md#060). + +- Update to [`libp2p-rendezvous` `v0.9.0`](protocols/rendezvous/CHANGELOG.md#090). + +- Update to [`libp2p-ping` `v0.39.0`](protocols/ping/CHANGELOG.md#0390). + +- Update to [`libp2p-identify` `v0.39.0`](protocols/identify/CHANGELOG.md#0390). + +- Update to [`libp2p-floodsub` `v0.39.0`](protocols/floodsub/CHANGELOG.md#0390). + +- Update to [`libp2p-relay` `v0.12.0`](protocols/relay/CHANGELOG.md#0120). + +- Update to [`libp2p-metrics` `v0.9.0`](misc/metrics/CHANGELOG.md#090). + +- Update to [`libp2p-kad` `v0.40.0`](protocols/kad/CHANGELOG.md#0400). + +- Update to [`libp2p-autonat` `v0.7.0`](protocols/autonat/CHANGELOG.md#070). + +- Update to [`libp2p-request-response` `v0.21.0`](protocols/request-response/CHANGELOG.md#0210). + # 0.47.0 - Update to [`libp2p-dcutr` `v0.5.0`](protocols/dcutr/CHANGELOG.md#050). diff --git a/Cargo.toml b/Cargo.toml index 75867ddbf4f8..b64c2f68756b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p" edition = "2021" rust-version = "1.60.0" description = "Peer-to-peer networking library" -version = "0.47.0" +version = "0.48.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -77,23 +77,23 @@ 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-autonat = { version = "0.6.0", path = "protocols/autonat", optional = true } +libp2p-autonat = { version = "0.7.0", path = "protocols/autonat", optional = true } libp2p-core = { version = "0.35.0", path = "core", default-features = false } -libp2p-dcutr = { version = "0.5.0", path = "protocols/dcutr", optional = true } -libp2p-floodsub = { version = "0.38.0", path = "protocols/floodsub", optional = true } -libp2p-identify = { version = "0.38.0", path = "protocols/identify", optional = true } -libp2p-kad = { version = "0.39.0", path = "protocols/kad", optional = true } -libp2p-metrics = { version = "0.8.0", path = "misc/metrics", optional = true } +libp2p-dcutr = { version = "0.6.0", path = "protocols/dcutr", optional = true } +libp2p-floodsub = { version = "0.39.0", path = "protocols/floodsub", optional = true } +libp2p-identify = { version = "0.39.0", path = "protocols/identify", optional = true } +libp2p-kad = { version = "0.40.0", path = "protocols/kad", optional = true } +libp2p-metrics = { version = "0.9.0", path = "misc/metrics", optional = true } libp2p-mplex = { version = "0.35.0", path = "muxers/mplex", optional = true } libp2p-noise = { version = "0.38.0", path = "transports/noise", optional = true } -libp2p-ping = { version = "0.38.0", path = "protocols/ping", optional = true } +libp2p-ping = { version = "0.39.0", path = "protocols/ping", optional = true } libp2p-plaintext = { version = "0.35.0", path = "transports/plaintext", optional = true } libp2p-pnet = { version = "0.22.0", path = "transports/pnet", optional = true } -libp2p-relay = { version = "0.11.0", path = "protocols/relay", optional = true } -libp2p-rendezvous = { version = "0.8.0", path = "protocols/rendezvous", optional = true } -libp2p-request-response = { version = "0.20.0", path = "protocols/request-response", optional = true } -libp2p-swarm = { version = "0.38.0", path = "swarm" } -libp2p-swarm-derive = { version = "0.29.0", path = "swarm-derive" } +libp2p-relay = { version = "0.12.0", path = "protocols/relay", optional = true } +libp2p-rendezvous = { version = "0.9.0", path = "protocols/rendezvous", optional = true } +libp2p-request-response = { version = "0.21.0", path = "protocols/request-response", optional = true } +libp2p-swarm = { version = "0.39.0", path = "swarm" } +libp2p-swarm-derive = { version = "0.30.0", path = "swarm-derive" } libp2p-uds = { version = "0.34.0", path = "transports/uds", optional = true } libp2p-wasm-ext = { version = "0.35.0", path = "transports/wasm-ext", default-features = false, optional = true } libp2p-yamux = { version = "0.39.0", path = "muxers/yamux", optional = true } @@ -106,12 +106,12 @@ smallvec = "1.6.1" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] libp2p-deflate = { version = "0.35.0", path = "transports/deflate", optional = true } libp2p-dns = { version = "0.35.0", path = "transports/dns", optional = true, default-features = false } -libp2p-mdns = { version = "0.39.0", path = "protocols/mdns", optional = true } +libp2p-mdns = { version = "0.40.0", path = "protocols/mdns", optional = true } libp2p-tcp = { version = "0.35.0", path = "transports/tcp", default-features = false, optional = true } libp2p-websocket = { version = "0.37.0", path = "transports/websocket", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] -libp2p-gossipsub = { version = "0.40.0", path = "protocols/gossipsub", optional = true } +libp2p-gossipsub = { version = "0.41.0", path = "protocols/gossipsub", optional = true } [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index 8618e0b71306..72007e39c8b7 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -1,3 +1,17 @@ +# 0.9.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + +- Update to `libp2p-dcutr` `v0.6.0`. + +- Update to `libp2p-ping` `v0.39.0`. + +- Update to `libp2p-identify` `v0.39.0`. + +- Update to `libp2p-relay` `v0.12.0`. + +- Update to `libp2p-kad` `v0.40.0`. + # 0.8.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 4bfeb7aa481d..fe2e4f3ec853 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-metrics" edition = "2021" rust-version = "1.56.1" description = "Metrics for libp2p" -version = "0.8.0" +version = "0.9.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -20,16 +20,16 @@ dcutr = ["libp2p-dcutr"] [dependencies] libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-dcutr = { version = "0.5.0", path = "../../protocols/dcutr", optional = true } -libp2p-identify = { version = "0.38.0", path = "../../protocols/identify", optional = true } -libp2p-kad = { version = "0.39.0", path = "../../protocols/kad", optional = true } -libp2p-ping = { version = "0.38.0", path = "../../protocols/ping", optional = true } -libp2p-relay = { version = "0.11.0", path = "../../protocols/relay", optional = true } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-dcutr = { version = "0.6.0", path = "../../protocols/dcutr", optional = true } +libp2p-identify = { version = "0.39.0", path = "../../protocols/identify", optional = true } +libp2p-kad = { version = "0.40.0", path = "../../protocols/kad", optional = true } +libp2p-ping = { version = "0.39.0", path = "../../protocols/ping", optional = true } +libp2p-relay = { version = "0.12.0", path = "../../protocols/relay", optional = true } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } prometheus-client = "0.18.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] -libp2p-gossipsub = { version = "0.40.0", path = "../../protocols/gossipsub", optional = true } +libp2p-gossipsub = { version = "0.41.0", path = "../../protocols/gossipsub", optional = true } [dev-dependencies] log = "0.4.0" diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index 5856a6a3c824..f6c4b9d619c0 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.7.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + +- Update to `libp2p-request-response` `v0.21.0`. + # 0.6.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 6ec668e4fdc7..e6818a748177 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-autonat" edition = "2021" rust-version = "1.56.1" description = "NAT and firewall detection for libp2p" -version = "0.6.0" +version = "0.7.0" authors = ["David Craven ", "Elena Frank "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -19,8 +19,8 @@ futures = "0.3" futures-timer = "3.0" instant = "0.1" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } -libp2p-request-response = { version = "0.20.0", path = "../request-response" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } +libp2p-request-response = { version = "0.21.0", path = "../request-response" } log = "0.4" rand = "0.8" prost = "0.11" diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index 8c8837d0d028..a572d84bcf0d 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.6.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.5.1 - Make default features of `libp2p-core` optional. See [PR 2836]. diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index c82b5e5274f6..08d2815c6d9f 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-dcutr" edition = "2021" rust-version = "1.56.1" description = "Direct connection upgrade through relay" -version = "0.5.1" +version = "0.6.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -18,7 +18,7 @@ futures = "0.3.1" futures-timer = "3.0" instant = "0.1.11" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4" prost-codec = { version = "0.2", path = "../../misc/prost-codec" } prost = "0.11" diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 2e02a7ded1f2..cbe061e69594 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.39.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.38.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 8c2631e5ce8a..2b9ef8ee4026 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-floodsub" edition = "2021" rust-version = "1.56.1" description = "Floodsub protocol for libp2p" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,7 +15,7 @@ cuckoofilter = "0.5.0" fnv = "1.0" futures = "0.3.1" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4" prost = "0.11" rand = "0.7" diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 2c55be28e854..dad834937954 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.41.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.40.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 42b21e41a976..c551d59cb144 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-gossipsub" edition = "2021" rust-version = "1.56.1" description = "Gossipsub protocol for libp2p" -version = "0.40.0" +version = "0.41.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } bytes = "1.0" byteorder = "1.3.4" diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 8821bca3507b..47af0838ae88 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.39.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.38.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 9db09cd1bf25..d0bc65379ad5 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-identify" edition = "2021" rust-version = "1.56.1" description = "Nodes identifcation protocol for libp2p" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,7 +15,7 @@ asynchronous-codec = "0.6" futures = "0.3.1" futures-timer = "3.0.2" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4.1" lru = "0.7.2" prost-codec = { version = "0.2", path = "../../misc/prost-codec" } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 09f2035ef2bf..4fef2057008c 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.40.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.39.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index d1910dccbbb2..bf7d0957bd36 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = "1.56.1" description = "Kademlia protocol for libp2p" -version = "0.39.0" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -19,7 +19,7 @@ asynchronous-codec = "0.6" futures = "0.3.1" log = "0.4" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } prost = "0.11" rand = "0.7.2" sha2 = "0.10.0" diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index c6541f7eccc7..a6b05044fa5b 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.40.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.39.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index bb060c9ed1f5..306f052cc690 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-mdns" edition = "2021" rust-version = "1.56.1" -version = "0.39.0" +version = "0.40.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -18,7 +18,7 @@ futures = "0.3.13" if-watch = "1.1.1" lazy_static = "1.4.0" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index d163839733a1..cf1f2fedf429 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.39.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.38.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 14984332db73..568f8f83aacb 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-ping" edition = "2021" rust-version = "1.56.1" description = "Ping protocol for libp2p" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,7 +15,7 @@ futures = "0.3.1" futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 537abff7edca..e02a3ef8b828 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.12.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.11.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 4a7396f938b0..ee059d02d505 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-relay" edition = "2021" rust-version = "1.56.1" description = "Communications relaying for libp2p" -version = "0.11.0" +version = "0.12.0" authors = ["Parity Technologies ", "Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -18,7 +18,7 @@ futures = "0.3.1" futures-timer = "3" instant = "0.1.11" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4" pin-project = "1" prost-codec = { version = "0.2", path = "../../misc/prost-codec" } diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 728a1538c9eb..f2ba00df1643 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.9.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.8.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 833fee1f19d4..a21dd3004473 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-rendezvous" edition = "2021" rust-version = "1.56.1" description = "Rendezvous protocol for libp2p" -version = "0.8.0" +version = "0.9.0" authors = ["The COMIT guys "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] asynchronous-codec = "0.6" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } prost = "0.11" void = "1" log = "0.4" diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 0008f1a1d013..aef9f49f72ff 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.21.0 [unreleased] + +- Update to `libp2p-swarm` `v0.39.0`. + # 0.20.0 - Update to `libp2p-swarm` `v0.38.0`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 91f95484f733..c2649de6012b 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-request-response" edition = "2021" rust-version = "1.56.1" description = "Generic Request/Response Protocols" -version = "0.20.0" +version = "0.21.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,7 @@ bytes = "1" futures = "0.3.1" instant = "0.1.11" libp2p-core = { version = "0.35.0", path = "../../core", default-features = false } -libp2p-swarm = { version = "0.38.0", path = "../../swarm" } +libp2p-swarm = { version = "0.39.0", path = "../../swarm" } log = "0.4.11" rand = "0.7" smallvec = "1.6.1" diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index f9056f6093aa..5cf840c331c8 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 - [unreleased] + +- Remove support for removed `NetworkBehaviourEventProcess`. + # 0.29.0 - Generate `NetworkBehaviour::OutEvent` if not provided through `#[behaviour(out_event = diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 05ed063257d5..89ee54447fc3 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm-derive" edition = "2021" rust-version = "1.56.1" description = "Procedural macros of libp2p-core" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index 51305e381902..0369a67c5ea4 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -48,7 +48,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let (_, ty_generics, where_clause) = ast.generics.split_for_impl(); let multiaddr = quote! {::libp2p::core::Multiaddr}; let trait_to_impl = quote! {::libp2p::swarm::NetworkBehaviour}; - let net_behv_event_proc = quote! {::libp2p::swarm::NetworkBehaviourEventProcess}; let either_ident = quote! {::libp2p::core::either::EitherOutput}; let network_behaviour_action = quote! {::libp2p::swarm::NetworkBehaviourAction}; let into_connection_handler = quote! {::libp2p::swarm::IntoConnectionHandler}; @@ -71,28 +70,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { quote! {<#(#lf,)* #(#tp,)* #(#cst,)*>} }; - // Whether or not we require the `NetworkBehaviourEventProcess` trait to be implemented. - let event_process = { - let mut event_process = false; - - for meta_items in ast.attrs.iter().filter_map(get_meta_items) { - for meta_item in meta_items { - match meta_item { - syn::NestedMeta::Meta(syn::Meta::NameValue(ref m)) - if m.path.is_ident("event_process") => - { - if let syn::Lit::Bool(ref b) = m.lit { - event_process = b.value - } - } - _ => (), - } - } - } - - event_process - }; - // The fields of the struct we are interested in (no ignored fields). let data_struct_fields = data_struct .fields @@ -121,9 +98,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { }) .next(); - match (user_provided_out_event_name, event_process) { + match user_provided_out_event_name { // User provided `OutEvent`. - (Some(name), false) => { + Some(name) => { let definition = None; let from_clauses = data_struct_fields .iter() @@ -135,7 +112,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { (name, definition, from_clauses) } // User did not provide `OutEvent`. Generate it. - (None, false) => { + None => { let name: syn::Type = syn::parse_str(&(ast.ident.to_string() + "Event")).unwrap(); let definition = { let fields = data_struct_fields @@ -170,22 +147,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let from_clauses = vec![]; (name, definition, from_clauses) } - // User uses `NetworkBehaviourEventProcess`. - (name, true) => { - let definition = None; - let from_clauses = data_struct_fields - .iter() - .map(|field| { - let ty = &field.ty; - quote! {Self: #net_behv_event_proc<<#ty as #trait_to_impl>::OutEvent>} - }) - .collect::>(); - ( - name.unwrap_or_else(|| syn::parse_str("()").unwrap()), - definition, - from_clauses, - ) - } } }; @@ -545,13 +506,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { out_handler.unwrap_or(quote! {()}) // TODO: See test `empty`. }; - let generate_event_match_arm = if event_process { - quote! { - std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(event)) => { - #net_behv_event_proc::inject_event(self, event) - } - } - } else { + let generate_event_match_arm = { // If the `NetworkBehaviour`'s `OutEvent` is generated by the derive macro, wrap the sub // `NetworkBehaviour` `OutEvent` in the variant of the generated `OutEvent`. If the // `NetworkBehaviour`'s `OutEvent` is provided by the user, use the corresponding `From` diff --git a/swarm-derive/tests/test.rs b/swarm-derive/tests/test.rs index f4a313198a95..61c95cd8aaac 100644 --- a/swarm-derive/tests/test.rs +++ b/swarm-derive/tests/test.rs @@ -460,41 +460,6 @@ fn mixed_field_order() { } } -#[test] -fn event_process() { - #[allow(dead_code)] - #[derive(NetworkBehaviour)] - #[behaviour(event_process = true)] - struct Foo { - ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, - } - - impl libp2p::swarm::NetworkBehaviourEventProcess for Foo { - fn inject_event(&mut self, _: libp2p::identify::IdentifyEvent) {} - } - - impl libp2p::swarm::NetworkBehaviourEventProcess for Foo { - fn inject_event(&mut self, _: libp2p::ping::PingEvent) {} - } - - #[allow(dead_code, unreachable_code)] - fn bar() { - require_net_behaviour::(); - - let mut _swarm: libp2p::Swarm = unimplemented!(); - - let _ = async { - loop { - match _swarm.select_next_some().await { - SwarmEvent::Behaviour(()) => break, - _ => {} - } - } - }; - } -} - #[test] fn generated_out_event_derive_debug() { #[allow(dead_code)] diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 61175ae0762b..75add0d524a0 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.39.0 - [unreleased] + +- Remove deprecated `NetworkBehaviourEventProcess`. See [libp2p-swarm v0.38.0 changelog entry] for + migration path. + +[libp2p-swarm v0.38.0 changelog entry]: https://github.com/libp2p/rust-libp2p/blob/master/swarm/CHANGELOG.md#0380 + # 0.38.0 - Deprecate `NetworkBehaviourEventProcess`. When deriving `NetworkBehaviour` on a custom `struct` users diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index e2829f800931..6f4a87adb0d0 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = "1.56.1" description = "The libp2p swarm" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index c0ac597680cb..9c4a10b56cd6 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -321,24 +321,6 @@ pub trait PollParameters { fn local_peer_id(&self) -> &PeerId; } -/// When deriving [`NetworkBehaviour`] this trait must by default be implemented for all the -/// possible event types generated by the inner behaviours. -/// -/// You can opt out of this behaviour through `#[behaviour(event_process = false)]`. See the -/// documentation of [`NetworkBehaviour`] for details. -#[deprecated( - since = "0.38.0", - note = "Use `#[behaviour(out_event = \"MyBehaviourEvent\")]` instead. See \ - https://github.com/libp2p/rust-libp2p/blob/master/swarm/CHANGELOG.md#0380 \ - for instructions on how to migrate. Will be removed with \ - https://github.com/libp2p/rust-libp2p/pull/2751." -)] -pub trait NetworkBehaviourEventProcess { - /// Called when one of the fields of the type you're deriving `NetworkBehaviour` on generates - /// an event. - fn inject_event(&mut self, event: TEvent); -} - /// An action that a [`NetworkBehaviour`] can trigger in the [`Swarm`] /// in whose context it is executing. /// diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index fc4c50e63ef2..6bb1d95a5199 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -19,8 +19,6 @@ // DEALINGS IN THE SOFTWARE. use crate::handler::{either::IntoEitherHandler, ConnectionHandler, IntoConnectionHandler}; -#[allow(deprecated)] -pub use crate::NetworkBehaviourEventProcess; use crate::{DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use either::Either; use libp2p_core::{ @@ -235,18 +233,3 @@ where Poll::Ready(event) } } - -#[allow(deprecated)] -impl NetworkBehaviourEventProcess - for Either -where - TBehaviourLeft: NetworkBehaviourEventProcess, - TBehaviourRight: NetworkBehaviourEventProcess, -{ - fn inject_event(&mut self, event: TEvent) { - match self { - Either::Left(a) => a.inject_event(event), - Either::Right(b) => b.inject_event(event), - } - } -} diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 64ebdf779e5c..07a15d56da9b 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -23,8 +23,6 @@ use crate::handler::{ KeepAlive, SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper}; -#[allow(deprecated)] -pub use crate::NetworkBehaviourEventProcess; use crate::{DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use either::Either; use libp2p_core::{ @@ -232,18 +230,6 @@ where } } -#[allow(deprecated)] -impl NetworkBehaviourEventProcess for Toggle -where - TBehaviour: NetworkBehaviourEventProcess, -{ - fn inject_event(&mut self, event: TEvent) { - if let Some(inner) = self.inner.as_mut() { - inner.inject_event(event); - } - } -} - /// Implementation of `IntoConnectionHandler` that can be in the disabled state. pub struct ToggleIntoConnectionHandler { inner: Option, diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 38df855cff51..230de4631dbd 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -63,8 +63,6 @@ pub mod behaviour; pub mod dial_opts; pub mod handler; -#[allow(deprecated)] -pub use behaviour::NetworkBehaviourEventProcess; pub use behaviour::{ CloseConnection, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, }; From a3dec471c046127e8e0d88bc89a881affb56a76c Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 26 Aug 2022 09:02:14 +0200 Subject: [PATCH 2/4] docs/coding-guidelines: Document limit on number of tasks (#2839) Add guideline to limit number of tasks being spawned. --- docs/coding-guidelines.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/coding-guidelines.md b/docs/coding-guidelines.md index a208dd2768c4..70a1ef53009e 100644 --- a/docs/coding-guidelines.md +++ b/docs/coding-guidelines.md @@ -10,6 +10,7 @@ - [Bound everything](#bound-everything) - [Channels](#channels) - [Local queues](#local-queues) + - [Tasks](#tasks) - [Further reading](#further-reading) - [No premature optimizations](#no-premature-optimizations) - [Keep things sequential unless proven to be slow](#keep-things-sequential-unless-proven-to-be-slow) @@ -201,6 +202,19 @@ growth and high latencies. Note that rust-libp2p fails at this guideline, i.e. still has many unbounded local queues. +### Tasks + +Bound the number of +[tasks](https://docs.rs/futures/latest/futures/task/index.html) being spawned. +As an example, say we spawn one task per incoming request received from a +socket. If the number of pending requests is not bounded by some limit, a +misbehaving or malicious remote peer can send requests at a higher rate than the +local node can respond at. This results in unbounded growth in the number of +requests, and thus unbounded growth in the number of tasks and used memory. + +Simply put, rust-libp2p spawns one task per connection but limits the overall +number of connections, thus adhering to this guideline. + ### Further reading - https://en.wikipedia.org/wiki/Bufferbloat From 247b5536d44329b712d4ffe9096238217365f717 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Sun, 28 Aug 2022 10:51:49 +0200 Subject: [PATCH 3/4] swarm-derive/: Remove support for custom poll method (#2841) With the removal of `NetworkBehaviourEventProcess` there is no more need for a custom poll method. --- CHANGELOG.md | 2 + swarm-derive/CHANGELOG.md | 8 +++- swarm-derive/src/lib.rs | 28 +------------ swarm-derive/tests/test.rs | 81 +------------------------------------- swarm/src/behaviour.rs | 4 -- 5 files changed, 12 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d574ea35f6..20766d4dc19c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ # 0.48.0 [unreleased] +- Update to [`libp2p-swarm-derive` `v0.30.0`](swarm-derive/CHANGELOG.md#0300). + - Update to [`libp2p-dcutr` `v0.6.0`](protocols/dcutr/CHANGELOG.md#060). - Update to [`libp2p-rendezvous` `v0.9.0`](protocols/rendezvous/CHANGELOG.md#090). diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 5cf840c331c8..4dc5a9769cb8 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,6 +1,12 @@ # 0.30.0 - [unreleased] -- Remove support for removed `NetworkBehaviourEventProcess`. +- Remove support for removed `NetworkBehaviourEventProcess`. See [PR 2840]. + +- Remove support for custom `poll` method on `NetworkBehaviour` via `#[behaviour(poll_method = + "poll")]`. See [PR 2841]. + +[PR 2840]: https://github.com/libp2p/rust-libp2p/pull/2840 +[PR 2841]: https://github.com/libp2p/rust-libp2p/pull/2841 # 0.29.0 diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index 0369a67c5ea4..d1e49ef361a8 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -23,7 +23,7 @@ use heck::ToUpperCamelCase; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Ident}; +use syn::{parse_macro_input, Data, DataStruct, DeriveInput}; /// Generates a delegating `NetworkBehaviour` implementation for the struct this is used for. See /// the trait documentation for better description. @@ -433,29 +433,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { out_handler.unwrap_or(quote! {()}) // TODO: See test `empty`. }; - // The method to use to poll. - // If we find a `#[behaviour(poll_method = "poll")]` attribute on the struct, we call - // `self.poll()` at the end of the polling. - let poll_method = { - let mut poll_method = quote! {std::task::Poll::Pending}; - for meta_items in ast.attrs.iter().filter_map(get_meta_items) { - for meta_item in meta_items { - match meta_item { - syn::NestedMeta::Meta(syn::Meta::NameValue(ref m)) - if m.path.is_ident("poll_method") => - { - if let syn::Lit::Str(ref s) = m.lit { - let ident: Ident = syn::parse_str(&s.value()).unwrap(); - poll_method = quote! {#name::#ident(self, cx, poll_params)}; - } - } - _ => (), - } - } - } - poll_method - }; - // List of statements to put in `poll()`. // // We poll each child one by one and wrap around the output. @@ -638,8 +615,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { fn poll(&mut self, cx: &mut std::task::Context, poll_params: &mut impl #poll_parameters) -> std::task::Poll<#network_behaviour_action> { use libp2p::futures::prelude::*; #(#poll_stmts)* - let f: std::task::Poll<#network_behaviour_action> = #poll_method; - f + std::task::Poll::Pending } } }; diff --git a/swarm-derive/tests/test.rs b/swarm-derive/tests/test.rs index 61c95cd8aaac..d7b058d21693 100644 --- a/swarm-derive/tests/test.rs +++ b/swarm-derive/tests/test.rs @@ -128,38 +128,7 @@ fn three_fields_non_last_ignored() { } #[test] -fn custom_polling() { - #[allow(dead_code)] - #[derive(NetworkBehaviour)] - #[behaviour(poll_method = "foo")] - struct Foo { - ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, - } - - impl Foo { - fn foo( - &mut self, - _: &mut std::task::Context, - _: &mut impl libp2p::swarm::PollParameters, - ) -> std::task::Poll< - libp2p::swarm::NetworkBehaviourAction< - ::OutEvent, - ::ConnectionHandler, - >, - > { - std::task::Poll::Pending - } - } - - #[allow(dead_code)] - fn foo() { - require_net_behaviour::(); - } -} - -#[test] -fn custom_event_no_polling() { +fn custom_event() { #[allow(dead_code)] #[derive(NetworkBehaviour)] #[behaviour(out_event = "MyEvent")] @@ -191,54 +160,6 @@ fn custom_event_no_polling() { } } -#[test] -fn custom_event_and_polling() { - #[allow(dead_code)] - #[derive(NetworkBehaviour)] - #[behaviour(poll_method = "foo", out_event = "MyEvent")] - struct Foo { - ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, - } - - enum MyEvent { - Ping(libp2p::ping::PingEvent), - Identify(libp2p::identify::IdentifyEvent), - } - - impl From for MyEvent { - fn from(event: libp2p::ping::PingEvent) -> Self { - MyEvent::Ping(event) - } - } - - impl From for MyEvent { - fn from(event: libp2p::identify::IdentifyEvent) -> Self { - MyEvent::Identify(event) - } - } - - impl Foo { - fn foo( - &mut self, - _: &mut std::task::Context, - _: &mut impl libp2p::swarm::PollParameters, - ) -> std::task::Poll< - libp2p::swarm::NetworkBehaviourAction< - ::OutEvent, - ::ConnectionHandler, - >, - > { - std::task::Poll::Pending - } - } - - #[allow(dead_code)] - fn foo() { - require_net_behaviour::(); - } -} - #[test] fn custom_event_mismatching_field_names() { #[allow(dead_code)] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 9c4a10b56cd6..acda2cedc273 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -118,10 +118,6 @@ pub(crate) type THandlerOutEvent = /// } /// ``` /// -/// Optionally one can provide a custom `poll` function through the `#[behaviour(poll_method = -/// "poll")]` attribute. This function must have the same signature as the [`NetworkBehaviour#poll`] -/// function and will be called last within the generated [`NetworkBehaviour`] implementation. -/// /// Struct members that don't implement [`NetworkBehaviour`] must be annotated with /// `#[behaviour(ignore)]`. /// From 6855ab943bd7427a2135b46ad3d08f48fbf10872 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 29 Aug 2022 07:39:47 +0200 Subject: [PATCH 4/4] swarm-derive/: Remove support for ignoring fields on struct (#2842) With the removal of `NetworkBehaviourEventProcess` there is no more need for ignoring fields. --- examples/chat.rs | 6 --- swarm-derive/CHANGELOG.md | 5 +++ swarm-derive/src/lib.rs | 81 ++++++++++++++++---------------------- swarm-derive/tests/test.rs | 48 ---------------------- swarm/src/behaviour.rs | 35 ---------------- 5 files changed, 40 insertions(+), 135 deletions(-) diff --git a/examples/chat.rs b/examples/chat.rs index d64684285677..ee5527bfca72 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -85,11 +85,6 @@ async fn main() -> Result<(), Box> { struct MyBehaviour { floodsub: Floodsub, mdns: Mdns, - - // Struct fields which do not implement NetworkBehaviour need to be ignored - #[behaviour(ignore)] - #[allow(dead_code)] - ignored_member: bool, } #[allow(clippy::large_enum_variant)] @@ -117,7 +112,6 @@ async fn main() -> Result<(), Box> { let mut behaviour = MyBehaviour { floodsub: Floodsub::new(local_peer_id), mdns, - ignored_member: false, }; behaviour.floodsub.subscribe(floodsub_topic.clone()); diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index 4dc5a9769cb8..fdf01f04814b 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -8,6 +8,11 @@ [PR 2840]: https://github.com/libp2p/rust-libp2p/pull/2840 [PR 2841]: https://github.com/libp2p/rust-libp2p/pull/2841 +- Remove support for non-`NetworkBehaviour` fields on main `struct` via `#[behaviour(ignore)]`. See + [PR 2842]. + +[PR 2842]: https://github.com/libp2p/rust-libp2p/pull/2842 + # 0.29.0 - Generate `NetworkBehaviour::OutEvent` if not provided through `#[behaviour(out_event = diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index d1e49ef361a8..3e3bf5b80672 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -70,13 +70,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { quote! {<#(#lf,)* #(#tp,)* #(#cst,)*>} }; - // The fields of the struct we are interested in (no ignored fields). - let data_struct_fields = data_struct - .fields - .iter() - .filter(|f| !is_ignored(f)) - .collect::>(); - let (out_event_name, out_event_definition, out_event_from_clauses) = { // If we find a `#[behaviour(out_event = "Foo")]` attribute on the // struct, we set `Foo` as the out event. If not, the `OutEvent` is @@ -102,7 +95,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // User provided `OutEvent`. Some(name) => { let definition = None; - let from_clauses = data_struct_fields + let from_clauses = data_struct + .fields .iter() .map(|field| { let ty = &field.ty; @@ -115,7 +109,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { None => { let name: syn::Type = syn::parse_str(&(ast.ident.to_string() + "Event")).unwrap(); let definition = { - let fields = data_struct_fields + let fields = data_struct + .fields .iter() .map(|field| { let variant: syn::Variant = syn::parse_str( @@ -152,7 +147,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the `where ...` clause of the trait implementation. let where_clause = { - let additional = data_struct_fields + let additional = data_struct + .fields .iter() .map(|field| { let ty = &field.ty; @@ -174,7 +170,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `addresses_of_peer()`. let addresses_of_peer_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -185,7 +182,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_connection_established()`. let inject_connection_established_stmts = { - data_struct_fields.iter().enumerate().map(move |(field_n, field)| { + data_struct.fields.iter().enumerate().map(move |(field_n, field)| { match field.ident { Some(ref i) => quote!{ self.#i.inject_connection_established(peer_id, connection_id, endpoint, errors, other_established); }, None => quote!{ self.#field_n.inject_connection_established(peer_id, connection_id, endpoint, errors, other_established); }, @@ -195,7 +192,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_address_change()`. let inject_address_change_stmts = { - data_struct_fields.iter().enumerate().map(move |(field_n, field)| { + data_struct.fields.iter().enumerate().map(move |(field_n, field)| { match field.ident { Some(ref i) => quote!{ self.#i.inject_address_change(peer_id, connection_id, old, new); }, None => quote!{ self.#field_n.inject_address_change(peer_id, connection_id, old, new); }, @@ -205,7 +202,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_connection_closed()`. let inject_connection_closed_stmts = { - data_struct_fields + data_struct.fields .iter() .enumerate() // The outmost handler belongs to the last behaviour. @@ -234,7 +231,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_dial_failure()`. let inject_dial_failure_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() // The outmost handler belongs to the last behaviour. @@ -268,7 +266,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_listen_failure()`. let inject_listen_failure_stmts = { - data_struct_fields + data_struct.fields .iter() .enumerate() .rev() @@ -296,7 +294,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_new_listener()`. let inject_new_listener_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -307,7 +306,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_new_listen_addr()`. let inject_new_listen_addr_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -318,7 +318,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_expired_listen_addr()`. let inject_expired_listen_addr_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -329,7 +330,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_new_external_addr()`. let inject_new_external_addr_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -340,7 +342,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_expired_external_addr()`. let inject_expired_external_addr_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -351,7 +354,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_listener_error()`. let inject_listener_error_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -362,7 +366,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_listener_closed()`. let inject_listener_closed_stmts = { - data_struct_fields + data_struct + .fields .iter() .enumerate() .map(move |(field_n, field)| match field.ident { @@ -375,14 +380,14 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // // The event type is a construction of nested `#either_ident`s of the events of the children. // We call `inject_event` on the corresponding child. - let inject_node_event_stmts = data_struct_fields.iter().enumerate().enumerate().map(|(enum_n, (field_n, field))| { + let inject_node_event_stmts = data_struct.fields.iter().enumerate().enumerate().map(|(enum_n, (field_n, field))| { let mut elem = if enum_n != 0 { quote!{ #either_ident::Second(ev) } } else { quote!{ ev } }; - for _ in 0 .. data_struct_fields.len() - 1 - enum_n { + for _ in 0 .. data_struct.fields.len() - 1 - enum_n { elem = quote!{ #either_ident::First(#elem) }; } @@ -395,7 +400,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // The [`ConnectionHandler`] associated type. let connection_handler_ty = { let mut ph_ty = None; - for field in data_struct_fields.iter() { + for field in data_struct.fields.iter() { let ty = &field.ty; let field_info = quote! { <#ty as #trait_to_impl>::ConnectionHandler }; match ph_ty { @@ -412,7 +417,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let new_handler = { let mut out_handler = None; - for (field_n, field) in data_struct_fields.iter().enumerate() { + for (field_n, field) in data_struct.fields.iter().enumerate() { let field_name = match field.ident { Some(ref i) => quote! { self.#i }, None => quote! { self.#field_n }, @@ -436,7 +441,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // List of statements to put in `poll()`. // // We poll each child one by one and wrap around the output. - let poll_stmts = data_struct_fields.iter().enumerate().map(|(field_n, field)| { + let poll_stmts = data_struct.fields.iter().enumerate().map(|(field_n, field)| { let field = field .ident .clone() @@ -447,7 +452,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { } else { quote!{ event } }; - for _ in 0 .. data_struct_fields.len() - 1 - field_n { + for _ in 0 .. data_struct.fields.len() - 1 - field_n { wrapped_event = quote!{ #either_ident::First(#wrapped_event) }; } @@ -458,7 +463,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let provided_handler_and_new_handlers = { let mut out_handler = None; - for (f_n, f) in data_struct_fields.iter().enumerate() { + for (f_n, f) in data_struct.fields.iter().enumerate() { let f_name = match f.ident { Some(ref i) => quote! { self.#i }, None => quote! { self.#f_n }, @@ -637,19 +642,3 @@ fn get_meta_items(attr: &syn::Attribute) -> Option> { None } } - -/// Returns true if a field is marked as ignored by the user. -fn is_ignored(field: &syn::Field) -> bool { - for meta_items in field.attrs.iter().filter_map(get_meta_items) { - for meta_item in meta_items { - match meta_item { - syn::NestedMeta::Meta(syn::Meta::Path(ref m)) if m.is_ident("ignore") => { - return true; - } - _ => (), - } - } - } - - false -} diff --git a/swarm-derive/tests/test.rs b/swarm-derive/tests/test.rs index d7b058d21693..dcddb3a6a3fc 100644 --- a/swarm-derive/tests/test.rs +++ b/swarm-derive/tests/test.rs @@ -83,8 +83,6 @@ fn three_fields() { ping: libp2p::ping::Ping, identify: libp2p::identify::Identify, kad: libp2p::kad::Kademlia, - #[behaviour(ignore)] - foo: String, } #[allow(dead_code)] @@ -103,30 +101,6 @@ fn three_fields() { } } -#[test] -fn three_fields_non_last_ignored() { - #[allow(dead_code)] - #[derive(NetworkBehaviour)] - struct Foo { - ping: libp2p::ping::Ping, - #[behaviour(ignore)] - identify: String, - kad: libp2p::kad::Kademlia, - } - - #[allow(dead_code)] - #[allow(unreachable_code)] - fn foo() { - let _out_event: ::OutEvent = unimplemented!(); - match _out_event { - FooEvent::Ping(libp2p::ping::Event { .. }) => {} - FooEvent::Kad(event) => { - let _: libp2p::kad::KademliaEvent = event; - } - } - } -} - #[test] fn custom_event() { #[allow(dead_code)] @@ -359,28 +333,6 @@ fn custom_event_with_either() { } } -#[test] -fn mixed_field_order() { - struct Foo {} - - #[derive(NetworkBehaviour)] - pub struct Behaviour { - #[behaviour(ignore)] - _foo: Foo, - _ping: libp2p::ping::Ping, - #[behaviour(ignore)] - _foo2: Foo, - _identify: libp2p::identify::Identify, - #[behaviour(ignore)] - _foo3: Foo, - } - - #[allow(dead_code)] - fn behaviour() { - require_net_behaviour::(); - } -} - #[test] fn generated_out_event_derive_debug() { #[allow(dead_code)] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index acda2cedc273..a5bf0e06f060 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -117,41 +117,6 @@ pub(crate) type THandlerOutEvent = /// } /// } /// ``` -/// -/// Struct members that don't implement [`NetworkBehaviour`] must be annotated with -/// `#[behaviour(ignore)]`. -/// -/// ``` rust -/// # use libp2p::identify::{Identify, IdentifyEvent}; -/// # use libp2p::ping::{Ping, PingEvent}; -/// # use libp2p::NetworkBehaviour; -/// #[derive(NetworkBehaviour)] -/// #[behaviour(out_event = "Event")] -/// struct MyBehaviour { -/// identify: Identify, -/// ping: Ping, -/// -/// #[behaviour(ignore)] -/// some_string: String, -/// } -/// # -/// # enum Event { -/// # Identify(IdentifyEvent), -/// # Ping(PingEvent), -/// # } -/// # -/// # impl From for Event { -/// # fn from(event: IdentifyEvent) -> Self { -/// # Self::Identify(event) -/// # } -/// # } -/// # -/// # impl From for Event { -/// # fn from(event: PingEvent) -> Self { -/// # Self::Ping(event) -/// # } -/// # } -/// ``` pub trait NetworkBehaviour: 'static { /// Handler for all the protocols the network behaviour supports. type ConnectionHandler: IntoConnectionHandler;