Merge branch 'rust_master' into fluence_master

# Conflicts:
#	protocols/secio/benches/bench.rs
This commit is contained in:
folex 2020-07-17 13:05:17 +03:00
commit 30c0a5f51b
58 changed files with 425 additions and 300 deletions

View File

@ -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)

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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

View File

@ -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 <admin@parity.io>"]
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"] }

View File

@ -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.

View File

@ -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`.

View File

@ -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 <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -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::<Vec<_>>();
// 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::<Vec<_>>();
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) };
}
Some(quote!{
loop {
match #field_name.poll(cx, poll_params) {
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) {
#generate_event_match_arm
std::task::Poll::Ready(#network_behaviour_action::DialAddress { address }) => {
return std::task::Poll::Ready(#network_behaviour_action::DialAddress { address });
}

View File

@ -263,3 +263,46 @@ fn nested_derives_with_import() {
require_net_behaviour::<Bar>();
}
}
#[test]
fn event_process_false() {
enum BehaviourOutEvent {
Ping(libp2p::ping::PingEvent),
Identify(libp2p::identify::IdentifyEvent)
}
impl From<libp2p::ping::PingEvent> for BehaviourOutEvent {
fn from(event: libp2p::ping::PingEvent) -> Self {
BehaviourOutEvent::Ping(event)
}
}
impl From<libp2p::identify::IdentifyEvent> 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::<Foo>();
let mut swarm: libp2p::Swarm<Foo> = unimplemented!();
// check that the event is bubbled up all the way to swarm
let _ = async {
match swarm.next().await {
BehaviourOutEvent::Ping(_) => {},
BehaviourOutEvent::Identify(_) => {},
}
};
}
}

View File

@ -1,3 +1,3 @@
# 0.9.1 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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<Vec<u8>> }
impl Multiaddr {

View File

@ -1,3 +1,3 @@
# 0.8.2 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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"

View File

@ -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

View File

@ -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 <admin@parity.io>"]
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"] }

View File

@ -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).

View File

@ -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 <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.19.2", path = "../../core" }
libp2p-core = { version = "0.20.0", path = "../../core" }
parking_lot = "0.10"
thiserror = "1.0"
yamux = "0.4.5"

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.2 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.19.2", path = "../../core" }
libp2p-core = { version = "0.20.0", path = "../../core" }
flate2 = "1.0"
[dev-dependencies]

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.1 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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.

View File

@ -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 <Age@AgeManning.com>"]
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"

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.2 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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]

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.2 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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]

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.1 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -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()
}
}

View File

@ -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.

View File

@ -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 <admin@parity.io>"]
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

View File

@ -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::<u8>()).collect::<Vec<_>>();
// 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::<u8>()).collect::<Vec<_>>();
// 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::<u8>()).collect::<Vec<_>>();
// 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 () {}

View File

@ -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;

View File

@ -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

View File

@ -2,7 +2,7 @@
name = "libp2p-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.19.1"
version = "0.20.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.19.2", path = "../core" }
libp2p-core = { version = "0.20.0", path = "../core" }
log = "0.4"
rand = "0.7"
smallvec = "1.0"

View File

@ -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<TEvent> {
/// Called when one of the fields of the type you're deriving `NetworkBehaviour` on generates
/// an event.

View File

@ -382,13 +382,16 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
/// 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<ProtocolsHandler = THandler>,
// 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);
}
}
}
}

View File

@ -0,0 +1,4 @@
# 0.20.0 [2020-07-01]
- Dependency and documentation updates.

View File

@ -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 <admin@parity.io>"]
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"

View File

@ -1,3 +1,7 @@
# 0.20.0 [2020-07-01]
- Updated dependencies.
# 0.19.2 [2020-06-22]
Updated dependencies.
- Updated dependencies.

View File

@ -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 <admin@parity.io>"]
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 }

View File

@ -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.

View File

@ -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 <admin@parity.io>"]
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 }

View File

@ -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))

View File

@ -1,6 +1,6 @@
[package]
name = "libp2p-wasm-ext"
version = "0.19.0"
version = "0.20.1"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
edition = "2018"
description = "Allows passing in an external transport in a WASM environment"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
js-sys = "0.3.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"

View File

@ -72,14 +72,17 @@ pub mod ffi {
#[wasm_bindgen(method, catch)]
pub fn listen_on(this: &Transport, multiaddr: &str) -> Result<js_sys::Iterator, JsValue>;
/// Returns a `ReadableStream`.
/// 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<Box<[JsValue]>>;

View File

@ -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) => {
function check() {
if (ws.readyState != 1) {
reject("WebSocket is closed");
return;
}
return new Promise((resolve, reject) => {
setTimeout(function check() {
if (ws.bufferedAmount == 0) {
// 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));
}

View File

@ -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

View File

@ -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 <admin@parity.io>"]
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"