From e9952ea9e348fcc607dac0607ab532cc16208066 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Wed, 1 Jul 2020 15:36:20 +0200 Subject: [PATCH 01/11] Prepare releases. (#1640) * Prepare releases. * Re-export libp2p-request-response from libp2p crate. * Clean up changelogs. * Restore upper bounds. * Version 0.21 for the root crate. * Stricter lower bound in libp2p-websocket version in root crate. * Update misc/peer-id-generator/Cargo.toml Co-authored-by: Toralf Wittner * Update release date. * Update misc/peer-id-generator/Cargo.toml Co-authored-by: Toralf Wittner Co-authored-by: Toralf Wittner --- CHANGELOG.md | 12 +++++++ Cargo.toml | 42 ++++++++++++------------- core/CHANGELOG.md | 5 ++- core/Cargo.toml | 2 +- misc/core-derive/Cargo.toml | 2 +- misc/multiaddr/CHANGELOG.md | 2 +- misc/multistream-select/CHANGELOG.md | 2 +- misc/peer-id-generator/Cargo.toml | 2 +- muxers/mplex/CHANGELOG.md | 5 +++ muxers/mplex/Cargo.toml | 4 +-- muxers/yamux/CHANGELOG.md | 9 ++++-- muxers/yamux/Cargo.toml | 4 +-- protocols/deflate/CHANGELOG.md | 6 +++- protocols/deflate/Cargo.toml | 4 +-- protocols/floodsub/CHANGELOG.md | 6 +++- protocols/floodsub/Cargo.toml | 6 ++-- protocols/gossipsub/CHANGELOG.md | 8 +++-- protocols/gossipsub/Cargo.toml | 6 ++-- protocols/identify/CHANGELOG.md | 6 +++- protocols/identify/Cargo.toml | 6 ++-- protocols/kad/CHANGELOG.md | 7 +++-- protocols/kad/Cargo.toml | 6 ++-- protocols/mdns/CHANGELOG.md | 6 +++- protocols/mdns/Cargo.toml | 6 ++-- protocols/noise/CHANGELOG.md | 6 ++++ protocols/noise/Cargo.toml | 4 +-- protocols/ping/CHANGELOG.md | 6 +++- protocols/ping/Cargo.toml | 6 ++-- protocols/plaintext/CHANGELOG.md | 6 +++- protocols/plaintext/Cargo.toml | 4 +-- protocols/request-response/CHANGELOG.md | 2 +- protocols/request-response/Cargo.toml | 4 +-- protocols/secio/CHANGELOG.md | 8 ++++- protocols/secio/Cargo.toml | 4 +-- src/lib.rs | 4 +++ swarm/CHANGELOG.md | 4 ++- swarm/Cargo.toml | 4 +-- transports/dns/CHANGELOG.md | 4 +++ transports/dns/Cargo.toml | 4 +-- transports/tcp/CHANGELOG.md | 6 +++- transports/tcp/Cargo.toml | 4 +-- transports/uds/CHANGELOG.md | 8 ++++- transports/uds/Cargo.toml | 4 +-- transports/wasm-ext/CHANGELOG.md | 6 ++++ transports/wasm-ext/Cargo.toml | 4 +-- transports/websocket/CHANGELOG.md | 4 +++ transports/websocket/Cargo.toml | 4 +-- 47 files changed, 186 insertions(+), 88 deletions(-) create mode 100644 transports/dns/CHANGELOG.md create mode 100644 transports/wasm-ext/CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3e9f51..a5158f8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ - [`libp2p-core` CHANGELOG](core/CHANGELOG.md) - [`libp2p-deflate` CHANGELOG](protocols/deflate/CHANGELOG.md) +- [`libp2p-dns` CHANGELOG](transports/dns/CHANGELOG.md) - [`libp2p-floodsub` CHANGELOG](protocols/floodsub/CHANGELOG.md) - [`libp2p-gossipsub` CHANGELOG](protocols/gossipsub/CHANGELOG.md) - [`libp2p-identify` CHANGELOG](protocols/identify/CHANGELOG.md) @@ -15,11 +16,22 @@ - [`libp2p-swarm` CHANGELOG](swarm/CHANGELOG.md) - [`libp2p-tcp` CHANGELOG](transports/tcp/CHANGELOG.md) - [`libp2p-uds` CHANGELOG](transports/uds/CHANGELOG.md) +- [`libp2p-wasm-ext` CHANGELOG](transports/wasm-ext/CHANGELOG.md) - [`libp2p-websocket` CHANGELOG](transports/websocket/CHANGELOG.md) - [`libp2p-yamux` CHANGELOG](muxers/yamux/CHANGELOG.md) - [`multistream-select` CHANGELOG](misc/multistream-select/CHANGELOG.md) - [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md) +# Version 0.21.0 (2020-07-01) + +- Conditional compilation fixes for the `wasm32-wasi` target + ([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)). + +- New `libp2p-request-response` crate + ([PR 1596](https://github.com/libp2p/rust-libp2p/pull/1596)). + +- Updated libp2p dependencies. + # Version 0.19.1 (2020-05-25) - Temporarily pin all `async-std` dependencies to `< 1.6`. diff --git a/Cargo.toml b/Cargo.toml index 88605fb2..2986c6a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.20.1" +version = "0.21.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -61,23 +61,23 @@ all-features = true bytes = "0.5" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.19.2", path = "core" } -libp2p-core-derive = { version = "0.19.1", path = "misc/core-derive" } -libp2p-floodsub = { version = "0.19.1", path = "protocols/floodsub", optional = true } -libp2p-gossipsub = { version = "0.19.3", path = "./protocols/gossipsub", optional = true } -libp2p-identify = { version = "0.19.2", path = "protocols/identify", optional = true } -libp2p-kad = { version = "0.20.1", path = "protocols/kad", optional = true } -libp2p-mplex = { version = "0.19.2", path = "muxers/mplex", optional = true } -libp2p-noise = { version = "0.19.1", path = "protocols/noise", optional = true } -libp2p-ping = { version = "0.19.3", path = "protocols/ping", optional = true } -libp2p-plaintext = { version = "0.19.1", path = "protocols/plaintext", optional = true } +libp2p-core = { version = "0.20.0", path = "core" } +libp2p-core-derive = { version = "0.20.0", path = "misc/core-derive" } +libp2p-floodsub = { version = "0.20.0", path = "protocols/floodsub", optional = true } +libp2p-gossipsub = { version = "0.20.0", path = "./protocols/gossipsub", optional = true } +libp2p-identify = { version = "0.20.0", path = "protocols/identify", optional = true } +libp2p-kad = { version = "0.21.0", path = "protocols/kad", optional = true } +libp2p-mplex = { version = "0.20.0", path = "muxers/mplex", optional = true } +libp2p-noise = { version = "0.20.0", path = "protocols/noise", optional = true } +libp2p-ping = { version = "0.20.0", path = "protocols/ping", optional = true } +libp2p-plaintext = { version = "0.20.0", path = "protocols/plaintext", optional = true } libp2p-pnet = { version = "0.19.1", path = "protocols/pnet", optional = true } libp2p-request-response = { version = "0.1.0", path = "protocols/request-response", optional = true } -libp2p-secio = { version = "0.19.2", path = "protocols/secio", default-features = false, optional = true } -libp2p-swarm = { version = "0.19.1", path = "swarm" } -libp2p-uds = { version = "0.19.2", path = "transports/uds", optional = true } -libp2p-wasm-ext = { version = "0.19.0", path = "transports/wasm-ext", optional = true } -libp2p-yamux = { version = "0.19.1", path = "muxers/yamux", optional = true } +libp2p-secio = { version = "0.20.0", path = "protocols/secio", default-features = false, optional = true } +libp2p-swarm = { version = "0.20.0", path = "swarm" } +libp2p-uds = { version = "0.20.0", path = "transports/uds", optional = true } +libp2p-wasm-ext = { version = "0.20.0", path = "transports/wasm-ext", optional = true } +libp2p-yamux = { version = "0.20.0", path = "muxers/yamux", optional = true } multiaddr = { package = "parity-multiaddr", version = "0.9.1", path = "misc/multiaddr" } multihash = "0.11.0" parking_lot = "0.10.0" @@ -86,11 +86,11 @@ smallvec = "1.0" wasm-timer = "0.2.4" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] -libp2p-deflate = { version = "0.19.2", path = "protocols/deflate", optional = true } -libp2p-dns = { version = "0.19.0", path = "transports/dns", optional = true } -libp2p-mdns = { version = "0.19.2", path = "protocols/mdns", optional = true } -libp2p-tcp = { version = "0.19.2", path = "transports/tcp", optional = true } -libp2p-websocket = { version = "0.20.0", path = "transports/websocket", optional = true } +libp2p-deflate = { version = "0.20.0", path = "protocols/deflate", optional = true } +libp2p-dns = { version = "0.20.0", path = "transports/dns", optional = true } +libp2p-mdns = { version = "0.20.0", path = "protocols/mdns", optional = true } +libp2p-tcp = { version = "0.20.0", path = "transports/tcp", optional = true } +libp2p-websocket = { version = "0.20.1", path = "transports/websocket", optional = true } [dev-dependencies] async-std = "1.6.2" diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 48d04a6f..2b8b6763 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,7 @@ -# 0.20.0 [????-??-??] +# 0.20.0 [2020-07-01] + +- Conditional compilation fixes for the `wasm32-wasi` target + ([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)). - Rename `StreamMuxer::poll_inbound` to `poll_event` and change the return value to `StreamMuxerEvent`. This new `StreamMuxerEvent` makes diff --git a/core/Cargo.toml b/core/Cargo.toml index 05311f95..137cb86c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/misc/core-derive/Cargo.toml b/misc/core-derive/Cargo.toml index 41ac18b1..5552eac0 100644 --- a/misc/core-derive/Cargo.toml +++ b/misc/core-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core-derive" edition = "2018" description = "Procedural macros of libp2p-core" -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/misc/multiaddr/CHANGELOG.md b/misc/multiaddr/CHANGELOG.md index b73ac170..8ae781cd 100644 --- a/misc/multiaddr/CHANGELOG.md +++ b/misc/multiaddr/CHANGELOG.md @@ -1,3 +1,3 @@ # 0.9.1 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/misc/multistream-select/CHANGELOG.md b/misc/multistream-select/CHANGELOG.md index 30ee6e2f..b5f4967b 100644 --- a/misc/multistream-select/CHANGELOG.md +++ b/misc/multistream-select/CHANGELOG.md @@ -1,3 +1,3 @@ # 0.8.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/misc/peer-id-generator/Cargo.toml b/misc/peer-id-generator/Cargo.toml index 1813bcbd..1c23bf1f 100644 --- a/misc/peer-id-generator/Cargo.toml +++ b/misc/peer-id-generator/Cargo.toml @@ -11,5 +11,5 @@ categories = ["network-programming", "asynchronous"] publish = false [dependencies] -libp2p-core = { version = "0.19.0", path = "../../core" } +libp2p-core = { path = "../../core" } num_cpus = "1.8" diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index 8b19702a..16b0a7ef 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.20.0 [2020-07-01] + +- Update `libp2p-core`, i.e. `StreamMuxer::poll_inbound` has been renamed + to `poll_event` and returns a `StreamMuxerEvent`. + # 0.19.2 [2020-06-22] - Deprecated method `Multiplex::is_remote_acknowledged` has been removed diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 8791e9d0..936bc0bd 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-mplex" edition = "2018" description = "Mplex multiplexing protocol for libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,7 +14,7 @@ bytes = "0.5" fnv = "1.0" futures = "0.3.1" futures_codec = "0.4" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4" parking_lot = "0.10" unsigned-varint = { version = "0.4", features = ["futures-codec"] } diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 6c20cb21..422e1524 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,4 +1,9 @@ +# 0.20.0 [2020-07-01] + +- Update `libp2p-core`, i.e. `StreamMuxer::poll_inbound` has been renamed + to `poll_event` and returns a `StreamMuxerEvent`. + # 0.19.1 [2020-06-22] -Deprecated method `Yamux::is_remote_acknowledged` has been removed -as part of [PR 1616](https://github.com/libp2p/rust-libp2p/pull/1616). +- Deprecated method `Yamux::is_remote_acknowledged` has been removed + as part of [PR 1616](https://github.com/libp2p/rust-libp2p/pull/1616). diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index c1f80c7c..5d472e38 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-yamux" edition = "2018" description = "Yamux multiplexing protocol for libp2p" -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] 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.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } parking_lot = "0.10" thiserror = "1.0" yamux = "0.4.5" diff --git a/protocols/deflate/CHANGELOG.md b/protocols/deflate/CHANGELOG.md index 7bb1e881..d9b606ea 100644 --- a/protocols/deflate/CHANGELOG.md +++ b/protocols/deflate/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/deflate/Cargo.toml b/protocols/deflate/Cargo.toml index c3983d24..b96a7495 100644 --- a/protocols/deflate/Cargo.toml +++ b/protocols/deflate/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-deflate" edition = "2018" description = "Deflate encryption protocol for libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] 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.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } flate2 = "1.0" [dev-dependencies] diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 0d5b7cf2..c39adc29 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.1 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 4f605aec..f293c500 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-floodsub" edition = "2018" description = "Floodsub protocol for libp2p" -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"] cuckoofilter = "0.3.2" fnv = "1.0" futures = "0.3.1" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } prost = "0.6.1" rand = "0.7" smallvec = "1.0" diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 28578ba2..d2a5c025 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,7 +1,11 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.3 [2020-06-23] -Maintenance release fixing linter warnings. +- Maintenance release fixing linter warnings. # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 183686d2..165d1737 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-gossipsub" edition = "2018" description = "Gossipsub protocol for libp2p" -version = "0.19.3" +version = "0.20.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } bytes = "0.5.4" byteorder = "1.3.2" fnv = "1.0.6" diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 7bb1e881..d9b606ea 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index e1d7415e..043a3bda 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-identify" edition = "2018" description = "Nodes identifcation protocol for libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } log = "0.4.1" prost = "0.6.1" smallvec = "1.0" diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 04a50300..44cb3f18 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,4 +1,7 @@ -# 0.21.0 [????-??-??] +# 0.21.0 [2020-07-01] + +- Remove `KademliaEvent::Discovered` + ([PR 1632](https://github.com/libp2p/rust-libp2p/pull/1632)) - More control and insight for k-buckets ([PR 1628](https://github.com/libp2p/rust-libp2p/pull/1628)). @@ -12,7 +15,7 @@ # 0.20.1 [2020-06-23] -Maintenance release ([PR 1623](https://github.com/libp2p/rust-libp2p/pull/1623)). +- Maintenance release ([PR 1623](https://github.com/libp2p/rust-libp2p/pull/1623)). # 0.20.0 [2020-06-22] diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 26431d43..272a4279 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.20.1" +version = "0.21.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,8 +17,8 @@ fnv = "1.0" futures_codec = "0.4" futures = "0.3.1" log = "0.4" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } multihash = "0.11.0" prost = "0.6.1" rand = "0.7.2" diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 7bb1e881..d9b606ea 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index ec538b49..cb7de95e 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-mdns" edition = "2018" -version = "0.19.2" +version = "0.20.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -16,8 +16,8 @@ dns-parser = "0.8" either = "1.5.3" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } log = "0.4" net2 = "0.2" rand = "0.7" diff --git a/protocols/noise/CHANGELOG.md b/protocols/noise/CHANGELOG.md index 76abe1b2..3e1511fb 100644 --- a/protocols/noise/CHANGELOG.md +++ b/protocols/noise/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. +- Conditional compilation fixes for the `wasm32-wasi` target + ([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)). + # 0.19.1 [2020-06-22] - Re-add noise upgrades for IK and IX diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index 4936b793..918ed631 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-noise" description = "Cryptographic handshake protocol using the noise framework." -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ edition = "2018" curve25519-dalek = "2.0.0" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4" prost = "0.6.1" rand = "0.7.2" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index f760124a..d7cc7e2f 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,6 +1,10 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.3 [2020-06-22] -Updated dependencies. +- Updated dependencies. # 0.19.2 [2020-06-18] diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index c243f57f..695199b9 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-ping" edition = "2018" description = "Ping protocol for libp2p" -version = "0.19.3" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" diff --git a/protocols/plaintext/CHANGELOG.md b/protocols/plaintext/CHANGELOG.md index 0d5b7cf2..c39adc29 100644 --- a/protocols/plaintext/CHANGELOG.md +++ b/protocols/plaintext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.1 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 2304ca75..a1b9e6a9 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-plaintext" edition = "2018" description = "Plaintext encryption dummy protocol for libp2p" -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "0.5" futures = "0.3.1" futures_codec = "0.4.0" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.8" prost = "0.6.1" rw-stream-sink = "0.2.0" diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 49462a2f..84e59dad 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,4 +1,4 @@ # 0.1.0 -Initial release. +- Initial release. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 023b83dc..ae4df0a3 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -12,8 +12,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-trait = "0.1" futures = "0.3.1" -libp2p-core = { version = "0.19.2", path = "../../core" } -libp2p-swarm = { version = "0.19.1", path = "../../swarm" } +libp2p-core = { version = "0.20.0", path = "../../core" } +libp2p-swarm = { version = "0.20.0", path = "../../swarm" } smallvec = "1.4" wasm-timer = "0.2" diff --git a/protocols/secio/CHANGELOG.md b/protocols/secio/CHANGELOG.md index 7bb1e881..8f9fce13 100644 --- a/protocols/secio/CHANGELOG.md +++ b/protocols/secio/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. +- Conditional compilation fixes for the `wasm32-wasi` target + ([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)). + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index aaf31383..17825796 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-secio" edition = "2018" description = "Secio encryption protocol for libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,7 @@ ctr = "0.3" futures = "0.3.1" hmac = "0.7.0" lazy_static = "1.2.0" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.6" prost = "0.6.1" pin-project = "0.4.17" diff --git a/src/lib.rs b/src/lib.rs index eb68a331..c6e7b6c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -243,6 +243,10 @@ pub use libp2p_yamux as yamux; #[cfg_attr(docsrs, doc(cfg(feature = "pnet")))] #[doc(inline)] pub use libp2p_pnet as pnet; +#[cfg(feature = "request-response")] +#[cfg_attr(docsrs, doc(cfg(feature = "request-response")))] +#[doc(inline)] +pub use libp2p_request_response as request_response; mod transport_ext; diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index f3059907..66333f6e 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,4 +1,6 @@ -# 0.20.0 [????-??-??] +# 0.20.0 [2020-07-01] + +- Updated the `libp2p-core` dependency. - Add `ProtocolsHandler::inject_listen_upgrade_error`, the inbound analogue of `ProtocolsHandler::inject_dial_upgrade_error`, with an diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index d02ffff7..37727f52 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.19.1" +version = "0.20.0" authors = ["Parity Technologies "] 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.19.2", path = "../core" } +libp2p-core = { version = "0.20.0", path = "../core" } log = "0.4" rand = "0.7" smallvec = "1.0" diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md new file mode 100644 index 00000000..72ff0bd5 --- /dev/null +++ b/transports/dns/CHANGELOG.md @@ -0,0 +1,4 @@ +# 0.20.0 [2020-07-01] + +- Dependency and documentation updates. + diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index acd122f1..49c3f732 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-dns" edition = "2018" description = "DNS transport implementation for libp2p" -version = "0.19.0" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,6 +10,6 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.19.0", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index 7bb1e881..d9b606ea 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 6c771d87..e5328209 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-tcp" edition = "2018" description = "TCP/IP transport protocol for libp2p" -version = "0.19.2" +version = "0.20.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" get_if_addrs = "0.5.3" ipnet = "2.0.0" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.1" socket2 = "0.3.12" tokio = { version = "0.2", default-features = false, features = ["tcp"], optional = true } diff --git a/transports/uds/CHANGELOG.md b/transports/uds/CHANGELOG.md index 7bb1e881..8f9fce13 100644 --- a/transports/uds/CHANGELOG.md +++ b/transports/uds/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. +- Conditional compilation fixes for the `wasm32-wasi` target + ([PR 1633](https://github.com/libp2p/rust-libp2p/pull/1633)). + # 0.19.2 [2020-06-22] -Updated dependencies. +- Updated dependencies. diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index f72fe8b8..9ffe5434 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-uds" edition = "2018" description = "Unix domain sockets transport for libp2p" -version = "0.19.2" +version = "0.20.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -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.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" tokio = { version = "0.2", default-features = false, features = ["uds"], optional = true } diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md new file mode 100644 index 00000000..5ab89252 --- /dev/null +++ b/transports/wasm-ext/CHANGELOG.md @@ -0,0 +1,6 @@ +# 0.20.0 [2020-07-01] + +- Updated dependencies. +- Support `/dns` in the websocket implementation + ([PR 1626](https://github.com/libp2p/rust-libp2p/pull/1626)) + diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index c04d00b7..ddfa8030 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-wasm-ext" -version = "0.19.0" +version = "0.20.0" authors = ["Pierre Krieger "] 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.19" -libp2p-core = { version = "0.19.0", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } parity-send-wrapper = "0.1.0" wasm-bindgen = "0.2.42" wasm-bindgen-futures = "0.4.4" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 9af3da88..3b931fd0 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.1 [2020-07-01] + +- Updated dependencies. + # 0.20.0 [2020-06-22] - Updated `soketto` dependency which caused some smaller diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 04905a07..2b99414a 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.20.0" +version = "0.20.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] async-tls = "0.7.0" either = "1.5.3" futures = "0.3.1" -libp2p-core = { version = "0.19.2", path = "../../core" } +libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.8" quicksink = "0.1" rustls = "0.17.0" From 568a0180901834d6e9fa4eed8ad45ec7ffecca0e Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Thu, 2 Jul 2020 10:38:00 +0200 Subject: [PATCH 02/11] Re-release websockets 0.20.1 as 0.21. (#1642) * Re-release websockets 0.20.1 as 0.21. * CI --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- transports/websocket/CHANGELOG.md | 4 ++-- transports/websocket/Cargo.toml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5158f8a..d3eaaf10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ - [`multistream-select` CHANGELOG](misc/multistream-select/CHANGELOG.md) - [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md) +# Version 0.21.1 (2020-07-02) + +- Bump `libp2p-websockets` lower bound. + # Version 0.21.0 (2020-07-01) - Conditional compilation fixes for the `wasm32-wasi` target diff --git a/Cargo.toml b/Cargo.toml index 2986c6a9..9363e738 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.21.0" +version = "0.21.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -90,7 +90,7 @@ libp2p-deflate = { version = "0.20.0", path = "protocols/deflate", optional = tr libp2p-dns = { version = "0.20.0", path = "transports/dns", optional = true } libp2p-mdns = { version = "0.20.0", path = "protocols/mdns", optional = true } libp2p-tcp = { version = "0.20.0", path = "transports/tcp", optional = true } -libp2p-websocket = { version = "0.20.1", path = "transports/websocket", optional = true } +libp2p-websocket = { version = "0.21.0", path = "transports/websocket", optional = true } [dev-dependencies] async-std = "1.6.2" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 3b931fd0..b62469db 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,6 +1,6 @@ -# 0.20.1 [2020-07-01] +# 0.21.0 [2020-07-02] -- Updated dependencies. +- Update `libp2p-core`. # 0.20.0 [2020-06-22] diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 2b99414a..1f741760 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.20.1" +version = "0.21.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" From d645ccb0df0afad4030447b6fd2ba805f74e3eb4 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 6 Jul 2020 10:21:03 +0200 Subject: [PATCH 03/11] Improve the code of the WebSocket browser binding (#1644) * Improve the code of the WebSocket browser binding * Bump version * Set release date. Co-authored-by: Roman S. Borschel --- transports/wasm-ext/CHANGELOG.md | 4 ++ transports/wasm-ext/Cargo.toml | 2 +- transports/wasm-ext/src/lib.rs | 10 ++-- transports/wasm-ext/src/websockets.js | 75 +++++++++++++++------------ 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md index 5ab89252..1c87dc21 100644 --- a/transports/wasm-ext/CHANGELOG.md +++ b/transports/wasm-ext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.1 [2020-07-06] + +- Improve the code quality of the `websockets.js` binding with the browser's `WebSocket` API. + # 0.20.0 [2020-07-01] - Updated dependencies. diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index ddfa8030..324fee2a 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-wasm-ext" -version = "0.20.0" +version = "0.20.1" authors = ["Pierre Krieger "] edition = "2018" description = "Allows passing in an external transport in a WASM environment" diff --git a/transports/wasm-ext/src/lib.rs b/transports/wasm-ext/src/lib.rs index 1d4334ec..2ce0f440 100644 --- a/transports/wasm-ext/src/lib.rs +++ b/transports/wasm-ext/src/lib.rs @@ -72,14 +72,17 @@ pub mod ffi { #[wasm_bindgen(method, catch)] pub fn listen_on(this: &Transport, multiaddr: &str) -> Result; - /// Returns a `Readable​Stream​`. + /// Returns an iterator of JavaScript `Promise`s that resolve to `ArrayBuffer` objects + /// (or resolve to null, see below). These `ArrayBuffer` objects contain the data that the + /// remote has sent to us. If the remote closes the connection, the iterator must produce + /// a `Promise` that resolves to `null`. #[wasm_bindgen(method, getter)] pub fn read(this: &Connection) -> js_sys::Iterator; /// Writes data to the connection. Returns a `Promise` that resolves when the connection is /// ready for writing again. /// - /// If the `Promise` returns an error, the writing side of the connection is considered + /// If the `Promise` produces an error, the writing side of the connection is considered /// unrecoverable and the connection should be closed as soon as possible. /// /// Guaranteed to only be called after the previous write promise has resolved. @@ -95,7 +98,8 @@ pub mod ffi { #[wasm_bindgen(method)] pub fn close(this: &Connection); - /// List of addresses we have started listening on. Must be an array of strings of multiaddrs. + /// List of addresses we have started listening on. Must be an array of strings of + /// multiaddrs. #[wasm_bindgen(method, getter)] pub fn new_addrs(this: &ListenEvent) -> Option>; diff --git a/transports/wasm-ext/src/websockets.js b/transports/wasm-ext/src/websockets.js index babf10f9..7b5fcbf1 100644 --- a/transports/wasm-ext/src/websockets.js +++ b/transports/wasm-ext/src/websockets.js @@ -30,7 +30,6 @@ export const websocket_transport = () => { } /// Turns a string multiaddress into a WebSockets string URL. -// TODO: support dns addresses as well const multiaddr_to_ws = (addr) => { let parsed = addr.match(/^\/(ip4|ip6|dns4|dns6|dns)\/(.*?)\/tcp\/(.*?)\/(ws|wss|x-parity-ws\/(.*)|x-parity-wss\/(.*))$/); if (parsed != null) { @@ -54,43 +53,64 @@ const multiaddr_to_ws = (addr) => { // Attempt to dial a multiaddress. const dial = (addr) => { let ws = new WebSocket(multiaddr_to_ws(addr)); + ws.binaryType = "arraybuffer"; let reader = read_queue(); - return new Promise((resolve, reject) => { - // TODO: handle ws.onerror properly after dialing has happened - ws.onerror = (ev) => reject(ev); - ws.onmessage = (ev) => reader.inject_blob(ev.data); - ws.onclose = () => reader.inject_eof(); - ws.onopen = () => resolve({ + return new Promise((open_resolve, open_reject) => { + ws.onerror = (ev) => { + // If `open_resolve` has been called earlier, calling `open_reject` seems to be + // silently ignored. It is easier to unconditionally call `open_reject` rather than + // check in which state the connection is, which would be error-prone. + open_reject(ev); + // Injecting an EOF is how we report to the reading side that the connection has been + // closed. Injecting multiple EOFs is harmless. + reader.inject_eof(); + }; + ws.onclose = (ev) => { + // Same remarks as above. + open_reject(ev); + reader.inject_eof(); + }; + + // We inject all incoming messages into the queue unconditionally. The caller isn't + // supposed to access this queue unless the connection is open. + ws.onmessage = (ev) => reader.inject_array_buffer(ev.data); + + ws.onopen = () => open_resolve({ read: (function*() { while(ws.readyState == 1) { yield reader.next(); } })(), write: (data) => { if (ws.readyState == 1) { ws.send(data); - return promise_when_ws_finished(ws); + return promise_when_send_finished(ws); } else { return Promise.reject("WebSocket is closed"); } }, - shutdown: () => {}, - close: () => ws.close() + shutdown: () => ws.close(), + close: () => {} }); }); } -// Takes a WebSocket object and returns a Promise that resolves when bufferedAmount is 0. -const promise_when_ws_finished = (ws) => { - if (ws.bufferedAmount == 0) { - return Promise.resolve(); - } - +// Takes a WebSocket object and returns a Promise that resolves when bufferedAmount is low enough +// to allow more data to be sent. +const promise_when_send_finished = (ws) => { return new Promise((resolve, reject) => { - setTimeout(function check() { - if (ws.bufferedAmount == 0) { + function check() { + if (ws.readyState != 1) { + reject("WebSocket is closed"); + return; + } + + // We put an arbitrary threshold of 8 kiB of buffered data. + if (ws.bufferedAmount < 8 * 1024) { resolve(); } else { setTimeout(check, 100); } - }, 2); + } + + check(); }) } @@ -108,29 +128,20 @@ const read_queue = () => { return { // Inserts a new Blob in the queue. - inject_blob: (blob) => { + inject_array_buffer: (buffer) => { if (state.resolve != null) { - var resolve = state.resolve; + state.resolve(buffer); state.resolve = null; - - var reader = new FileReader(); - reader.addEventListener("loadend", () => resolve(reader.result)); - reader.readAsArrayBuffer(blob); } else { - state.queue.push(new Promise((resolve, reject) => { - var reader = new FileReader(); - reader.addEventListener("loadend", () => resolve(reader.result)); - reader.readAsArrayBuffer(blob); - })); + state.queue.push(Promise.resolve(buffer)); } }, // Inserts an EOF message in the queue. inject_eof: () => { if (state.resolve != null) { - var resolve = state.resolve; + state.resolve(null); state.resolve = null; - resolve(null); } else { state.queue.push(Promise.resolve(null)); } From c4a5497d2dd5203b4ff155f6ea442a5287e5e38a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 8 Jul 2020 19:32:47 +1000 Subject: [PATCH 04/11] Allow users to opt out of the `NetworkBehaviourEventProcess` mechanism (#1630) * Allow users to opt-out of the NetworkBehaviourEventProcess mechanism * Add CHANGELOG entry * Prepare release. Co-authored-by: Roman Borschel Co-authored-by: Roman S. Borschel --- CHANGELOG.md | 1 + misc/core-derive/CHANGELOG.md | 6 +++ misc/core-derive/Cargo.toml | 2 +- misc/core-derive/src/lib.rs | 80 ++++++++++++++++++++++++---------- misc/core-derive/tests/test.rs | 43 ++++++++++++++++++ swarm/CHANGELOG.md | 4 ++ swarm/Cargo.toml | 2 +- swarm/src/behaviour.rs | 34 ++++++++++----- 8 files changed, 137 insertions(+), 35 deletions(-) create mode 100644 misc/core-derive/CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index d3eaaf10..ee75100c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [`libp2p-yamux` CHANGELOG](muxers/yamux/CHANGELOG.md) - [`multistream-select` CHANGELOG](misc/multistream-select/CHANGELOG.md) - [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md) +- [`libp2p-core-derive` CHANGELOG](misc/core-derive/CHANGELOG.md) # Version 0.21.1 (2020-07-02) diff --git a/misc/core-derive/CHANGELOG.md b/misc/core-derive/CHANGELOG.md new file mode 100644 index 00000000..15f337b5 --- /dev/null +++ b/misc/core-derive/CHANGELOG.md @@ -0,0 +1,6 @@ +# 0.20.1 [2020-07-08] + +- Allow users to opt out of the `NetworkBehaviourEventProcess` +mechanism through `#[behaviour(event_process = false)]`. This is +useful if users want to process all events while polling the +swarm through `SwarmEvent::Behaviour`. diff --git a/misc/core-derive/Cargo.toml b/misc/core-derive/Cargo.toml index 5552eac0..a3ed9aad 100644 --- a/misc/core-derive/Cargo.toml +++ b/misc/core-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core-derive" edition = "2018" description = "Procedural macros of libp2p-core" -version = "0.20.0" +version = "0.20.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/misc/core-derive/src/lib.rs b/misc/core-derive/src/lib.rs index 7ce859fe..c100b516 100644 --- a/misc/core-derive/src/lib.rs +++ b/misc/core-derive/src/lib.rs @@ -70,28 +70,24 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { quote!{<#(#lf,)* #(#tp,)* #(#cst,)*>} }; - // Build the `where ...` clause of the trait implementation. - let where_clause = { - let additional = data_struct.fields.iter() - .filter(|x| !is_ignored(x)) - .flat_map(|field| { - let ty = &field.ty; - vec![ - quote!{#ty: #trait_to_impl}, - quote!{Self: #net_behv_event_proc<<#ty as #trait_to_impl>::OutEvent>}, - ] - }) - .collect::>(); + // Whether or not we require the `NetworkBehaviourEventProcess` trait to be implemented. + let event_process = { + let mut event_process = true; // Default to true for backwards compatibility - if let Some(where_clause) = where_clause { - if where_clause.predicates.trailing_punct() { - Some(quote!{#where_clause #(#additional),*}) - } else { - Some(quote!{#where_clause, #(#additional),*}) + 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 + } + } + _ => () + } } - } else { - Some(quote!{where #(#additional),*}) } + + event_process }; // The final out event. @@ -115,6 +111,34 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { out }; + // Build the `where ...` clause of the trait implementation. + let where_clause = { + let additional = data_struct.fields.iter() + .filter(|x| !is_ignored(x)) + .flat_map(|field| { + let ty = &field.ty; + vec![ + quote!{#ty: #trait_to_impl}, + if event_process { + quote!{Self: #net_behv_event_proc<<#ty as #trait_to_impl>::OutEvent>} + } else { + quote!{#out_event: From< <#ty as #trait_to_impl>::OutEvent >} + } + ] + }) + .collect::>(); + + if let Some(where_clause) = where_clause { + if where_clause.predicates.trailing_punct() { + Some(quote!{#where_clause #(#additional),*}) + } else { + Some(quote!{#where_clause, #(#additional),*}) + } + } else { + Some(quote!{where #(#additional),*}) + } + }; + // Build the list of statements to put in the body of `addresses_of_peer()`. let addresses_of_peer_stmts = { data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| { @@ -395,12 +419,24 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { wrapped_event = quote!{ #either_ident::First(#wrapped_event) }; } + 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 { + quote! { + std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(event)) => { + return std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(event.into())) + } + } + }; + Some(quote!{ loop { match #field_name.poll(cx, poll_params) { - std::task::Poll::Ready(#network_behaviour_action::GenerateEvent(event)) => { - #net_behv_event_proc::inject_event(self, event) - } + #generate_event_match_arm std::task::Poll::Ready(#network_behaviour_action::DialAddress { address }) => { return std::task::Poll::Ready(#network_behaviour_action::DialAddress { address }); } diff --git a/misc/core-derive/tests/test.rs b/misc/core-derive/tests/test.rs index 6181de8e..1dfcd847 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -263,3 +263,46 @@ fn nested_derives_with_import() { require_net_behaviour::(); } } + +#[test] +fn event_process_false() { + enum BehaviourOutEvent { + Ping(libp2p::ping::PingEvent), + Identify(libp2p::identify::IdentifyEvent) + } + + impl From for BehaviourOutEvent { + fn from(event: libp2p::ping::PingEvent) -> Self { + BehaviourOutEvent::Ping(event) + } + } + + impl From for BehaviourOutEvent { + fn from(event: libp2p::identify::IdentifyEvent) -> Self { + BehaviourOutEvent::Identify(event) + } + } + + #[allow(dead_code)] + #[derive(NetworkBehaviour)] + #[behaviour(out_event = "BehaviourOutEvent", event_process = false)] + struct Foo { + ping: libp2p::ping::Ping, + identify: libp2p::identify::Identify, + } + + #[allow(dead_code)] + fn bar() { + require_net_behaviour::(); + + let mut swarm: libp2p::Swarm = unimplemented!(); + + // check that the event is bubbled up all the way to swarm + let _ = async { + match swarm.next().await { + BehaviourOutEvent::Ping(_) => {}, + BehaviourOutEvent::Identify(_) => {}, + } + }; + } +} diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 66333f6e..8a01d483 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.1 [2020-07-08] + +- Documentation updates. + # 0.20.0 [2020-07-01] - Updated the `libp2p-core` dependency. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 37727f52..99848420 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.20.0" +version = "0.20.1" 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 bce5fbe2..f75a31ab 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -31,18 +31,27 @@ use std::{error, task::Context, task::Poll}; /// /// Crate users can implement this trait by using the the `#[derive(NetworkBehaviour)]` /// proc macro re-exported by the `libp2p` crate. The macro generates a delegating `trait` -/// implementation for the `struct`, which delegates method calls to all trait members. Any events -/// generated by struct members are delegated to [`NetworkBehaviourEventProcess`] implementations -/// which are expected to be provided by the user. +/// implementation for the `struct`, which delegates method calls to all trait members. /// -/// Optionally one can implement a custom `poll` function, which needs to be tagged with the -/// `#[behaviour(poll_method = "poll")]` attribute, and would be called last with no parameters. -/// -/// By default the derive sets the `NetworkBehaviour::OutEvent` as `()` but this can be overriden +/// By default the derive sets the [`NetworkBehaviour::OutEvent`] as `()` but this can be overridden /// with `#[behaviour(out_event = "AnotherType")]`. /// -/// `#[behaviour(ignore)]` can be added on a struct field to disable generation of delegation to -/// the fields which do not implement `NetworkBehaviour`. +/// Struct members that don't implement [`NetworkBehaviour`] must be annotated with `#[behaviour(ignore)]`. +/// +/// By default, events generated by the remaining members are delegated to [`NetworkBehaviourEventProcess`] +/// implementations. Those must be provided by the user on the type that [`NetworkBehaviour`] is +/// derived on. +/// +/// Alternatively, users can specify `#[behaviour(event_process = false)]`. In this case, users +/// should provide a custom `out_event` and implement [`From`] for each of the event types generated +/// by the struct members. +/// Not processing events within the derived [`NetworkBehaviour`] will cause them to be emitted as +/// part of polling the swarm in [`SwarmEvent::Behaviour`](crate::SwarmEvent::Behaviour). +/// +/// 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. pub trait NetworkBehaviour: Send + 'static { /// Handler for all the protocols the network behaviour supports. type ProtocolsHandler: IntoProtocolsHandler; @@ -193,8 +202,11 @@ pub trait PollParameters { fn local_peer_id(&self) -> &PeerId; } -/// When deriving [`NetworkBehaviour`] this trait must be implemented for all the possible event types -/// generated by the inner behaviours. +/// 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. pub trait NetworkBehaviourEventProcess { /// Called when one of the fields of the type you're deriving `NetworkBehaviour` on generates /// an event. From 6ad05b0ff1cb11ceec37cb191adb0d13feaceeb4 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Wed, 8 Jul 2020 11:51:49 +0200 Subject: [PATCH 05/11] [libp2p-swarm] Ignore a node's own addresses on dialing. (#1646) * Ignore a node's own addresses on dialing. Dialing attempts of a local node to one of its own addresses for what appears to be a different peer ID are futile and bound to fail with an `InvalidPeerId` error. To avoid such futile dialing attempts, filter out the node's own addresses from the addresses reported by the `NetworkBehaviour` for any peer. There can be a few reasons why a `NetworkBehaviour` may think an address belongs to a different peer, e.g.: 1. In the context of e.g. `libp2p-kad`, the local node may have changed its network identity (e.g. key rotation) and "discovers" its former identity in the DHT, with the same address(es). 2. Another peer may erroneously or intentionally, possibly even maliciously, report one of the local node's addresses as its own, making the node try to connect to itself. Relates to https://github.com/paritytech/stakingops-issues/issues/18. * Remove filtering of external addresses. Since these are obtained from other peers, it would constitute an attack vector. It is furthermore usually not possible for a peer behind a NAT to dial its own external address so these are unlikely to cause `InvalidPeerId` errors as a result of a peer dialing itself under the expectation of one of its former peer IDs. --- swarm/CHANGELOG.md | 7 +++++++ swarm/src/lib.rs | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 8a01d483..9208db10 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -2,6 +2,13 @@ - Documentation updates. +- Ignore addresses returned by `NetworkBehaviour::addresses_of_peer` +that the `Swarm` considers to be listening addresses of the local node. This +avoids futile dialing attempts of a node to itself, which can otherwise +even happen in genuine situations, e.g. after the local node changed +its network identity and a behaviour makes a dialing attempt to a +former identity using the same addresses. + # 0.20.0 [2020-07-01] - Updated the `libp2p-core` dependency. diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 70d2d2f0..800dbc13 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -382,13 +382,16 @@ where TBehaviour: NetworkBehaviour, /// dialing attempt or `addresses_of_peer` reports no addresses, `Ok(false)` /// is returned. pub fn dial(me: &mut Self, peer_id: &PeerId) -> Result<(), DialError> { - let mut addrs = me.behaviour.addresses_of_peer(peer_id).into_iter(); - let peer = me.network.peer(peer_id.clone()); + let self_listening = &me.listened_addrs; + let mut addrs = me.behaviour.addresses_of_peer(peer_id) + .into_iter() + .filter(|a| !self_listening.contains(a)); let result = if let Some(first) = addrs.next() { let handler = me.behaviour.new_handler().into_node_handler_builder(); - peer.dial(first, addrs, handler) + me.network.peer(peer_id.clone()) + .dial(first, addrs, handler) .map(|_| ()) .map_err(DialError::ConnectionLimit) } else { @@ -696,11 +699,14 @@ where TBehaviour: NetworkBehaviour, // ongoing dialing attempt, if there is one. log::trace!("Condition for new dialing attempt to {:?} not met: {:?}", peer_id, condition); + let self_listening = &this.listened_addrs; if let Some(mut peer) = this.network.peer(peer_id.clone()).into_dialing() { let addrs = this.behaviour.addresses_of_peer(peer.id()); let mut attempt = peer.some_attempt(); - for addr in addrs { - attempt.add_address(addr); + for a in addrs { + if !self_listening.contains(&a) { + attempt.add_address(a); + } } } } From 68587ee180c076e6b83a4d3bb3193dcc9a656b59 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Thu, 9 Jul 2020 11:50:49 +0200 Subject: [PATCH 06/11] Update rustls dependency. (#1655) * Update rustls dependency. * Bump async-tls lower bound. * Bump async-tls to 0.8. 0.7.1 has been yanked. Since `libp2p-websockets` exposes neither `async-tls` nor `rustls` on its API, this can be a patch release. --- transports/websocket/CHANGELOG.md | 4 ++++ transports/websocket/Cargo.toml | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index b62469db..7c28dd5e 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.21.1 [2020-07-09] + +- Update `async-tls` and `rustls` dependency. + # 0.21.0 [2020-07-02] - Update `libp2p-core`. diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 1f741760..017e263b 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.21.0" +version = "0.21.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,13 +10,13 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -async-tls = "0.7.0" +async-tls = "0.8.0" either = "1.5.3" futures = "0.3.1" libp2p-core = { version = "0.20.0", path = "../../core" } log = "0.4.8" quicksink = "0.1" -rustls = "0.17.0" +rustls = "0.18.0" rw-stream-sink = "0.2.0" soketto = { version = "0.4.1", features = ["deflate"] } url = "2.1" From e61ccd22df4e682f3982048e9bc86af86542b8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Klaehn?= Date: Mon, 13 Jul 2020 12:20:10 +0200 Subject: [PATCH 07/11] Add ord for multiaddr (#1653) So you can use it in ordering based containers --- misc/multiaddr/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/multiaddr/src/lib.rs b/misc/multiaddr/src/lib.rs index f81b8ada..da1a729c 100644 --- a/misc/multiaddr/src/lib.rs +++ b/misc/multiaddr/src/lib.rs @@ -36,7 +36,7 @@ static_assertions::const_assert! { } /// Representation of a Multiaddr. -#[derive(PartialEq, Eq, Clone, Hash)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] pub struct Multiaddr { bytes: Arc> } impl Multiaddr { From c8b426005fff0892b32bd1de058039badecdf839 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Mon, 13 Jul 2020 12:35:32 +0200 Subject: [PATCH 08/11] [request-response] Close substream after writing request/response. (#1660) * Close substream after writing request/response. * Update protocols/request-response/src/handler/protocol.rs Co-authored-by: Thomas Eizinger Co-authored-by: Thomas Eizinger --- protocols/request-response/CHANGELOG.md | 8 ++++++++ protocols/request-response/Cargo.toml | 2 +- protocols/request-response/src/handler/protocol.rs | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 84e59dad..b4d45ca4 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.1.1 + +- Always properly `close()` the substream after sending requests and +responses in the `InboundUpgrade` and `OutboundUpgrade`. Otherwise this is +left to `RequestResponseCodec::write_request` and `RequestResponseCodec::write_response`, +which can be a pitfall and lead to subtle problems (see e.g. +https://github.com/libp2p/rust-libp2p/pull/1606). + # 0.1.0 - Initial release. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index ae4df0a3..79ee83d6 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-request-response" edition = "2018" description = "Generic Request/Response Protocols" -version = "0.1.0" +version = "0.1.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/request-response/src/handler/protocol.rs b/protocols/request-response/src/handler/protocol.rs index c0dcdaf9..6373e90d 100644 --- a/protocols/request-response/src/handler/protocol.rs +++ b/protocols/request-response/src/handler/protocol.rs @@ -113,6 +113,7 @@ where write.await?; } } + io.close().await?; Ok(()) }.boxed() } @@ -156,10 +157,10 @@ where async move { let write = self.codec.write_request(&protocol, &mut io, self.request); write.await?; + io.close().await?; let read = self.codec.read_response(&protocol, &mut io); let response = read.await?; Ok(response) }.boxed() } } - From 8e7f71b0684f6c4e2652320e854a04cce9e0014d Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Mon, 13 Jul 2020 10:39:01 +0000 Subject: [PATCH 09/11] Remove libp2p-secio benchmarks (#1661) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They don’t compile anymore. --- protocols/secio/Cargo.toml | 4 - protocols/secio/benches/bench.rs | 124 ------------------------------- 2 files changed, 128 deletions(-) delete mode 100644 protocols/secio/benches/bench.rs diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index 17825796..ae45eda0 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -50,7 +50,3 @@ async-std = "1.6.2" criterion = "0.3" libp2p-mplex = { path = "../../muxers/mplex" } libp2p-tcp = { path = "../../transports/tcp", features = ["async-std"] } - -[[bench]] -name = "bench" -harness = false diff --git a/protocols/secio/benches/bench.rs b/protocols/secio/benches/bench.rs deleted file mode 100644 index a6a81ff4..00000000 --- a/protocols/secio/benches/bench.rs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -use criterion::{Bencher, Criterion, criterion_main, criterion_group}; -use futures::prelude::*; -use libp2p_core::Transport; -use tokio::{ - io, - runtime::current_thread::Runtime -}; - -fn secio_and_send_data(bench: &mut Bencher, data: &[u8]) { - let key = libp2p_secio::SecioKeyPair::ed25519_generated().unwrap(); - let transport = - libp2p_tcp::TcpConfig::new().with_upgrade(libp2p_secio::SecioConfig::new(key)); - - let data_vec = data.to_vec(); - - bench.iter(move || { - let (listener, addr) = transport - .clone() - .listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()) - .unwrap(); - - let listener_side = listener - .into_future() - .map_err(|(err, _)| err) - .and_then(|(client, _)| client.unwrap().0) - .map_err(|_| panic!()) - .and_then(|client| io::read_to_end(client.stream, Vec::new())) - .and_then(|msg| { - assert_eq!(msg.1, data); - Ok(()) - }); - - let dialer_side = transport - .clone() - .dial(addr) - .unwrap() - .map_err(|_| panic!()) - .and_then(|server| io::write_all(server.stream, data_vec.clone())) - .map(|_| ()); - - let combined = listener_side.select(dialer_side) - .map_err(|(err, _)| panic!("{:?}", err)) - .map(|_| ()); - let mut rt = Runtime::new().unwrap(); - rt.block_on(combined).unwrap(); - }) -} - -fn raw_tcp_connect_and_send_data(bench: &mut Bencher, data: &[u8]) { - let transport = libp2p_tcp::TcpConfig::new(); - let data_vec = data.to_vec(); - - bench.iter(move || { - let (listener, addr) = transport - .clone() - .listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()) - .unwrap(); - - let listener_side = listener - .into_future() - .map_err(|(err, _)| err) - .and_then(|(client, _)| client.unwrap().0) - .map_err(|_| panic!()) - .and_then(|client| io::read_to_end(client, Vec::new())) - .and_then(|msg| { - assert_eq!(msg.1, data); - Ok(()) - }); - - let dialer_side = transport - .clone() - .dial(addr) - .unwrap() - .map_err(|_| panic!()) - .and_then(|server| io::write_all(server, data_vec.clone())) - .map(|_| ()); - - let combined = listener_side.select(dialer_side) - .map_err(|(err, _)| panic!("{:?}", err)) - .map(|_| ()); - let mut rt = Runtime::new().unwrap(); - rt.block_on(combined).unwrap(); - }) -} - -fn criterion_benchmarks(bench: &mut Criterion) { - bench.bench_function("secio_connect_and_send_hello", move |b| secio_and_send_data(b, b"hello world")); - bench.bench_function("raw_tcp_connect_and_send_hello", move |b| raw_tcp_connect_and_send_data(b, b"hello world")); - - let data = (0 .. 1024).map(|_| rand::random::()).collect::>(); - bench.bench_function("secio_connect_and_send_one_kb", { let data = data.clone(); move |b| secio_and_send_data(b, &data) }); - bench.bench_function("raw_tcp_connect_and_send_one_kb", move |b| raw_tcp_connect_and_send_data(b, &data)); - - let data = (0 .. 1024 * 1024).map(|_| rand::random::()).collect::>(); - bench.bench_function("secio_connect_and_send_one_mb", { let data = data.clone(); move |b| secio_and_send_data(b, &data) }); - bench.bench_function("raw_tcp_connect_and_send_one_mb", move |b| raw_tcp_connect_and_send_data(b, &data)); - - let data = (0 .. 2 * 1024 * 1024).map(|_| rand::random::()).collect::>(); - bench.bench_function("secio_connect_and_send_two_mb", { let data = data.clone(); move |b| secio_and_send_data(b, &data) }); - bench.bench_function("raw_tcp_connect_and_send_two_mb", move |b| raw_tcp_connect_and_send_data(b, &data)); -} - -criterion_group!(benches, criterion_benchmarks); -criterion_main!(benches); From cc3438ec378c653cbfda9f73585687bdad45a92f Mon Sep 17 00:00:00 2001 From: tmakarios Date: Wed, 15 Jul 2020 21:14:29 +1200 Subject: [PATCH 10/11] Align explanation with previously altered example code (#1663) Co-authored-by: Tim Makarios --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c6e7b6c8..6f019e19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,8 @@ //! let transport = tcp.upgrade(upgrade::Version::V1).authenticate(secio).multiplex(yamux); //! # } //! ``` -//! In this example, `tcp_secio` is a new [`Transport`] that negotiates the secio protocol +//! In this example, `transport` is a new [`Transport`] that negotiates the +//! secio and yamux protocols //! on all connections. //! //! ## Network Behaviour From 7c7d6a9d2ed45e7ace0558e80fa1630e49c73094 Mon Sep 17 00:00:00 2001 From: Roman Borschel Date: Fri, 17 Jul 2020 12:01:49 +0200 Subject: [PATCH 11/11] Upgrade ed25519-dalek to pre.4 (#1665) * Upgrade ed25519-dalek to pre.4 * Update core/src/identity/ed25519.rs Co-authored-by: Pierre Krieger Co-authored-by: Pierre Krieger --- core/CHANGELOG.md | 4 ++++ core/Cargo.toml | 4 ++-- core/src/identity/ed25519.rs | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 2b8b6763..14c8889d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.1 [2020-17-17] + +- Update ed25519-dalek dependency. + # 0.20.0 [2020-07-01] - Conditional compilation fixes for the `wasm32-wasi` target diff --git a/core/Cargo.toml b/core/Cargo.toml index 137cb86c..f242a45f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.20.0" +version = "0.20.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] asn1_der = "0.6.1" bs58 = "0.3.0" -ed25519-dalek = "1.0.0-pre.3" +ed25519-dalek = "1.0.0-pre.4" either = "1.5" fnv = "1.0" futures = { version = "0.3.1", features = ["executor", "thread-pool"] } diff --git a/core/src/identity/ed25519.rs b/core/src/identity/ed25519.rs index f68e5d03..089fb360 100644 --- a/core/src/identity/ed25519.rs +++ b/core/src/identity/ed25519.rs @@ -20,8 +20,9 @@ //! Ed25519 keys. -use ed25519_dalek as ed25519; +use ed25519_dalek::{self as ed25519, Signer as _, Verifier as _}; use rand::RngCore; +use std::convert::TryFrom; use super::error::DecodingError; use zeroize::Zeroize; use core::fmt; @@ -107,7 +108,7 @@ pub struct PublicKey(ed25519::PublicKey); impl PublicKey { /// Verify the Ed25519 signature on a message using the public key. pub fn verify(&self, msg: &[u8], sig: &[u8]) -> bool { - ed25519::Signature::from_bytes(sig).and_then(|s| self.0.verify(msg, &s)).is_ok() + ed25519::Signature::try_from(sig).and_then(|s| self.0.verify(msg, &s)).is_ok() } /// Encode the public key into a byte array in compressed form, i.e.