diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3e9f51..ee75100c 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,10 +16,26 @@ - [`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) +- [`libp2p-core-derive` CHANGELOG](misc/core-derive/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 + ([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) diff --git a/Cargo.toml b/Cargo.toml index 0a2ee2ec..f64a70ec 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.1" 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.21.0", path = "transports/websocket", optional = true } [dev-dependencies] async-std = "1.6.2" diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 48d04a6f..14c8889d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,11 @@ -# 0.20.0 [????-??-??] +# 0.20.1 [2020-17-17] + +- Update ed25519-dalek dependency. + +# 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 82704f0b..ba70233f 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.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 9d0b4751..2659a202 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; @@ -114,7 +115,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. 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 41ac18b1..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.19.1" +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/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/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 { 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 05d2e07f..3bb68e25 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..b4d45ca4 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,4 +1,12 @@ +# 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. +- Initial release. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 023b83dc..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" @@ -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/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() } } - 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..ae45eda0 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" @@ -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 88a6e803..00000000 --- a/protocols/secio/benches/bench.rs +++ /dev/null @@ -1,126 +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); - -fn main () {} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index eb68a331..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 @@ -243,6 +244,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..9208db10 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,4 +1,17 @@ -# 0.20.0 [????-??-??] +# 0.20.1 [2020-07-08] + +- 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. - 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..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.19.1" +version = "0.20.1" 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/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. 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); + } } } } 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..1c87dc21 --- /dev/null +++ b/transports/wasm-ext/CHANGELOG.md @@ -0,0 +1,10 @@ +# 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. +- 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..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.19.0" +version = "0.20.1" 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/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)); } diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 9af3da88..7c28dd5e 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.21.1 [2020-07-09] + +- Update `async-tls` and `rustls` dependency. + +# 0.21.0 [2020-07-02] + +- Update `libp2p-core`. + # 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..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.20.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.19.2", path = "../../core" } +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"