From f2935941449647bf713762cd635f54035e306280 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Wed, 18 Dec 2019 16:31:31 +0100 Subject: [PATCH 01/10] Several changes. - Pin `futures_codec` to version 0.3.3 as later versions require at least bytes-0.5 which he have not upgraded to yet. - Replace `futures::executor::block_on` with `async_std::task::block_on` where `async-std` is already a dependency to work around an issue with `park`/`unpark` behaviour. - Use the published version of `quicksink`. --- core/src/nodes/listeners.rs | 2 +- core/tests/network_dial_error.rs | 10 +++++----- core/tests/network_simult.rs | 2 +- muxers/mplex/Cargo.toml | 2 +- protocols/identify/Cargo.toml | 2 +- protocols/identify/src/identify.rs | 2 +- protocols/kad/Cargo.toml | 2 +- protocols/ping/src/handler.rs | 2 +- protocols/ping/tests/ping.rs | 2 +- protocols/plaintext/Cargo.toml | 2 +- protocols/secio/Cargo.toml | 2 +- protocols/secio/src/codec/mod.rs | 4 ++-- protocols/secio/src/handshake.rs | 2 +- transports/tcp/src/lib.rs | 2 +- transports/websocket/Cargo.toml | 2 +- 15 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/nodes/listeners.rs b/core/src/nodes/listeners.rs index 5663b81a9dd..13054fea70c 100644 --- a/core/src/nodes/listeners.rs +++ b/core/src/nodes/listeners.rs @@ -358,7 +358,7 @@ mod tests { #[test] fn incoming_event() { - futures::executor::block_on(async move { + async_std::task::block_on(async move { let mem_transport = transport::MemoryTransport::default(); let mut listeners = ListenersStream::new(mem_transport); diff --git a/core/tests/network_dial_error.rs b/core/tests/network_dial_error.rs index 976ec980369..d36690d66b9 100644 --- a/core/tests/network_dial_error.rs +++ b/core/tests/network_dial_error.rs @@ -113,7 +113,7 @@ fn deny_incoming_connec() { swarm1.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap(); - let address = futures::executor::block_on(future::poll_fn(|cx| { + let address = async_std::task::block_on(future::poll_fn(|cx| { if let Poll::Ready(NetworkEvent::NewListenerAddress { listen_addr, .. }) = swarm1.poll(cx) { Poll::Ready(listen_addr) } else { @@ -126,7 +126,7 @@ fn deny_incoming_connec() { .into_not_connected().unwrap() .connect(address.clone(), TestHandler::default().into_node_handler_builder()); - futures::executor::block_on(future::poll_fn(|cx| -> Poll> { + async_std::task::block_on(future::poll_fn(|cx| -> Poll> { match swarm1.poll(cx) { Poll::Ready(NetworkEvent::IncomingConnection(inc)) => drop(inc), Poll::Ready(_) => unreachable!(), @@ -182,7 +182,7 @@ fn dial_self() { swarm.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap(); - let (address, mut swarm) = futures::executor::block_on( + let (address, mut swarm) = async_std::task::block_on( future::lazy(move |cx| { if let Poll::Ready(NetworkEvent::NewListenerAddress { listen_addr, .. }) = swarm.poll(cx) { Ok::<_, void::Void>((listen_addr, swarm)) @@ -196,7 +196,7 @@ fn dial_self() { let mut got_dial_err = false; let mut got_inc_err = false; - futures::executor::block_on(future::poll_fn(|cx| -> Poll> { + async_std::task::block_on(future::poll_fn(|cx| -> Poll> { loop { match swarm.poll(cx) { Poll::Ready(NetworkEvent::UnknownPeerDialError { @@ -284,7 +284,7 @@ fn multiple_addresses_err() { .connect_iter(addresses.clone(), TestHandler::default().into_node_handler_builder()) .unwrap(); - futures::executor::block_on(future::poll_fn(|cx| -> Poll> { + async_std::task::block_on(future::poll_fn(|cx| -> Poll> { loop { match swarm.poll(cx) { Poll::Ready(NetworkEvent::DialError { diff --git a/core/tests/network_simult.rs b/core/tests/network_simult.rs index 35c183151b4..b88082d4a2b 100644 --- a/core/tests/network_simult.rs +++ b/core/tests/network_simult.rs @@ -280,7 +280,7 @@ fn raw_swarm_simultaneous_connect() { } }); - if futures::executor::block_on(future) { + if async_std::task::block_on(future) { // The test exercised what we wanted to exercise: a simultaneous connect. break } diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 6dc5bbaaeb8..b66bd39454d 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "0.4.5" fnv = "1.0" futures = "0.3.1" -futures_codec = "0.3.1" +futures_codec = "= 0.3.3" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4" parking_lot = "0.9" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index d997109da3c..6e6a52bde45 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] bytes = "0.4" -futures_codec = "0.3.1" +futures_codec = "= 0.3.3" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index da371b7c70f..45d79755e04 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -315,7 +315,7 @@ mod tests { // it will permit the connection to be closed, as defined by // `IdentifyHandler::connection_keep_alive`. Hence the test succeeds if // either `Identified` event arrives correctly. - futures::executor::block_on(async move { + async_std::task::block_on(async move { loop { match future::select(swarm1.next(), swarm2.next()).await.factor_second().0 { future::Either::Left(Some(Ok(IdentifyEvent::Received { info, .. }))) => { diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index e855b64c925..b72974b07e5 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -14,7 +14,7 @@ arrayvec = "0.5.1" bytes = "0.4" either = "1.5" fnv = "1.0" -futures_codec = "0.3.1" +futures_codec = "= 0.3.3" futures = "0.3.1" log = "0.4" libp2p-core = { version = "0.13.0", path = "../../core" } diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index e758441962d..5ade98a8706 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -282,7 +282,7 @@ mod tests { fn tick(h: &mut PingHandler) -> ProtocolsHandlerEvent { - futures::executor::block_on(future::poll_fn(|cx| h.poll(cx) )) + async_std::task::block_on(future::poll_fn(|cx| h.poll(cx) )) } #[test] diff --git a/protocols/ping/tests/ping.rs b/protocols/ping/tests/ping.rs index 2c214319bab..5bbd6e66f33 100644 --- a/protocols/ping/tests/ping.rs +++ b/protocols/ping/tests/ping.rs @@ -84,7 +84,7 @@ fn ping() { }; let result = future::select(Box::pin(peer1), Box::pin(peer2)); - let ((p1, p2, rtt), _) = futures::executor::block_on(result).factor_first(); + let ((p1, p2, rtt), _) = async_std::task::block_on(result).factor_first(); assert!(p1 == peer1_id && p2 == peer2_id || p1 == peer2_id && p2 == peer1_id); assert!(rtt < Duration::from_millis(50)); } diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 1632f8e8a4a..2f9b45a076b 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] bytes = "0.4.12" futures = "0.3.1" -futures_codec = "0.3.1" +futures_codec = "= 0.3.3" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" protobuf = "2.8.1" diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index 0dd7fdf9ddf..f16502586eb 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -19,7 +19,7 @@ lazy_static = "1.2.0" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.6" protobuf = "2.8" -quicksink = { git = "https://github.com/paritytech/quicksink.git" } +quicksink = "0.1" rand = "0.7" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } sha2 = "0.8.0" diff --git a/protocols/secio/src/codec/mod.rs b/protocols/secio/src/codec/mod.rs index 5e8ec83af9a..8a4fabe5c00 100644 --- a/protocols/secio/src/codec/mod.rs +++ b/protocols/secio/src/codec/mod.rs @@ -156,7 +156,7 @@ mod tests { ); let data = b"hello world"; - futures::executor::block_on(async move { + async_std::task::block_on(async move { encoder.send(data.to_vec()).await.unwrap(); let rx = decoder.next().await.unwrap().unwrap(); assert_eq!(rx, data); @@ -209,7 +209,7 @@ mod tests { codec.send(data.to_vec().into()).await.unwrap(); }; - futures::executor::block_on(future::join(client, server)); + async_std::task::block_on(future::join(client, server)); } #[test] diff --git a/protocols/secio/src/handshake.rs b/protocols/secio/src/handshake.rs index 26dff5273c0..edf7216c417 100644 --- a/protocols/secio/src/handshake.rs +++ b/protocols/secio/src/handshake.rs @@ -419,7 +419,7 @@ mod tests { } }); - futures::executor::block_on(async move { + async_std::task::block_on(async move { let listen_addr = l_a_rx.await.unwrap(); let connec = async_std::net::TcpStream::connect(&listen_addr).await.unwrap(); let mut codec = handshake(connec, key2).await.unwrap().0; diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 6de747ea4da..99ebad02f65 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -486,7 +486,7 @@ mod tests { .for_each(|_| futures::future::ready(())); let client = TcpConfig::new().dial(addr).expect("dialer"); - futures::executor::block_on(futures::future::join(server, client)).1.unwrap(); + async_std::task::block_on(futures::future::join(server, client)).1.unwrap(); } #[test] diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 593619afbc5..ce9c84b03c4 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -16,7 +16,7 @@ either = "1.5.3" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" -quicksink = { git = "https://github.com/paritytech/quicksink.git" } +quicksink = "0.1" rustls = "0.16" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } soketto = { git = "https://github.com/paritytech/soketto.git", branch = "develop", features = ["deflate"] } From be8d811641039eb3629f167ac4a9b0b2a10ef8bc Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Wed, 18 Dec 2019 16:50:07 +0100 Subject: [PATCH 02/10] Update `futures-timer` to version 2. This removes the last dependencies to futures-preview. --- core/Cargo.toml | 2 +- core/src/transport/timeout.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index a0b4fdc103d..756b3ce0644 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,7 @@ ed25519-dalek = "1.0.0-pre.3" failure = "0.1" fnv = "1.0" futures = { version = "0.3.1", features = ["compat", "io-compat", "executor", "thread-pool"] } -futures-timer = "0.3" +futures-timer = "2" lazy_static = "1.2" libsecp256k1 = { version = "0.3.1", optional = true } log = "0.4" diff --git a/core/src/transport/timeout.rs b/core/src/transport/timeout.rs index 15fcf855ac6..5effaeb99b1 100644 --- a/core/src/transport/timeout.rs +++ b/core/src/transport/timeout.rs @@ -172,10 +172,9 @@ where Poll::Ready(Err(err)) => return Poll::Ready(Err(TransportTimeoutError::Other(err))), } - match TryFuture::try_poll(Pin::new(&mut this.timer), cx) { + match Pin::new(&mut this.timer).poll(cx) { Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => Poll::Ready(Err(TransportTimeoutError::Timeout)), - Poll::Ready(Err(err)) => Poll::Ready(Err(TransportTimeoutError::TimerError(err))), + Poll::Ready(()) => Poll::Ready(Err(TransportTimeoutError::Timeout)) } } } From 9349d6ce25660d7d0180dca170dcb55126864f7d Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Wed, 18 Dec 2019 17:43:25 +0100 Subject: [PATCH 03/10] Fix test. --- core/tests/network_simult.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/tests/network_simult.rs b/core/tests/network_simult.rs index b88082d4a2b..84f77c62139 100644 --- a/core/tests/network_simult.rs +++ b/core/tests/network_simult.rs @@ -18,8 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -mod util; - use futures::prelude::*; use libp2p_core::{identity, upgrade, Transport}; use libp2p_core::nodes::{Network, NetworkEvent, Peer}; @@ -111,10 +109,7 @@ fn raw_swarm_simultaneous_connect() { let transport = libp2p_tcp::TcpConfig::new() .upgrade(upgrade::Version::V1Lazy) .authenticate(libp2p_secio::SecioConfig::new(local_key)) - .multiplex(libp2p_mplex::MplexConfig::new()) - .and_then(|(peer, mplex), _| { - util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex)) - }); + .multiplex(libp2p_mplex::MplexConfig::new()); Network::new(transport, local_public_key.into_peer_id()) }; @@ -124,10 +119,7 @@ fn raw_swarm_simultaneous_connect() { let transport = libp2p_tcp::TcpConfig::new() .upgrade(upgrade::Version::V1Lazy) .authenticate(libp2p_secio::SecioConfig::new(local_key)) - .multiplex(libp2p_mplex::MplexConfig::new()) - .and_then(|(peer, mplex), _| { - util::CloseMuxer::new(mplex).map_ok(move |mplex| (peer, mplex)) - }); + .multiplex(libp2p_mplex::MplexConfig::new()); Network::new(transport, local_public_key.into_peer_id()) }; From 34a631d560e577dc03fad973260242f0bdd8d4b0 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Thu, 19 Dec 2019 12:28:46 +0100 Subject: [PATCH 04/10] Fix deflate test. Skip over empty messages or else the socket may not be connected by the time `close` is called on it. --- protocols/deflate/src/lib.rs | 1 + protocols/deflate/tests/test.rs | 84 ++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/protocols/deflate/src/lib.rs b/protocols/deflate/src/lib.rs index 0a2719683a4..581900b43de 100644 --- a/protocols/deflate/src/lib.rs +++ b/protocols/deflate/src/lib.rs @@ -71,6 +71,7 @@ where } /// Decodes and encodes traffic using DEFLATE. +#[derive(Debug)] pub struct DeflateOutput { /// Inner stream where we read compressed data from and write compressed data to. inner: S, diff --git a/protocols/deflate/tests/test.rs b/protocols/deflate/tests/test.rs index 84fb22138fe..896fb491349 100644 --- a/protocols/deflate/tests/test.rs +++ b/protocols/deflate/tests/test.rs @@ -18,59 +18,77 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use futures::{prelude::*, channel::oneshot}; +use futures::{future, prelude::*}; use libp2p_core::{transport::Transport, upgrade}; use libp2p_deflate::DeflateConfig; use libp2p_tcp::TcpConfig; -use quickcheck::QuickCheck; +use quickcheck::{QuickCheck, RngCore, TestResult}; #[test] fn deflate() { - fn prop(message: Vec) -> bool { - run(message); - true + fn prop(message: Vec) -> TestResult { + if message.is_empty() { + return TestResult::discard() + } + async_std::task::block_on(run(message)); + TestResult::passed() } - - QuickCheck::new() - .max_tests(30) - .quickcheck(prop as fn(Vec) -> bool) + QuickCheck::new().quickcheck(prop as fn(Vec) -> TestResult) } #[test] fn lot_of_data() { - run((0..16*1024*1024).map(|_| rand::random::()).collect()); + let mut v = vec![0; 2 * 1024 * 1024]; + rand::thread_rng().fill_bytes(&mut v); + async_std::task::block_on(run(v)) } -fn run(message1: Vec) { - let transport1 = TcpConfig::new() - .and_then(|c, e| upgrade::apply(c, DeflateConfig::default(), e, upgrade::Version::V1)); - let transport2 = transport1.clone(); - let message2 = message1.clone(); - let (l_a_tx, l_a_rx) = oneshot::channel(); +async fn run(message1: Vec) { + let transport = TcpConfig::new() + .and_then(|conn, endpoint| { + upgrade::apply(conn, DeflateConfig::default(), endpoint, upgrade::Version::V1) + }); - async_std::task::spawn(async move { - let mut server = transport1.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap(); - let server_address = server.next().await.unwrap().unwrap().into_new_address().unwrap(); - l_a_tx.send(server_address).unwrap(); + let mut listener = transport.clone() + .listen_on("/ip4/0.0.0.0/tcp/0".parse().expect("multiaddr")) + .expect("listener"); - let mut connec = server.next().await.unwrap().unwrap().into_upgrade().unwrap().0.await.unwrap(); + let listen_addr = listener.by_ref().next().await + .expect("some event") + .expect("no error") + .into_new_address() + .expect("new address"); + + let message2 = message1.clone(); + + let listener_task = async_std::task::spawn(async move { + let mut conn = listener + .filter(|e| future::ready(e.as_ref().map(|e| e.is_upgrade()).unwrap_or(false))) + .next() + .await + .expect("some event") + .expect("no error") + .into_upgrade() + .expect("upgrade") + .0 + .await + .expect("connection"); let mut buf = vec![0; message2.len()]; - connec.read_exact(&mut buf).await.unwrap(); + conn.read_exact(&mut buf).await.expect("read_exact"); assert_eq!(&buf[..], &message2[..]); - connec.write_all(&message2).await.unwrap(); - connec.close().await.unwrap(); + conn.write_all(&message2).await.expect("write_all"); + conn.close().await.expect("close") }); - futures::executor::block_on(async move { - let listen_addr = l_a_rx.await.unwrap(); - let mut connec = transport2.dial(listen_addr).unwrap().await.unwrap(); - connec.write_all(&message1).await.unwrap(); - connec.close().await.unwrap(); + let mut conn = transport.dial(listen_addr).expect("dialer").await.expect("connection"); + conn.write_all(&message1).await.expect("write_all"); + conn.close().await.expect("close"); - let mut buf = Vec::new(); - connec.read_to_end(&mut buf).await.unwrap(); - assert_eq!(&buf[..], &message1[..]); - }); + let mut buf = Vec::new(); + conn.read_to_end(&mut buf).await.expect("read_to_end"); + assert_eq!(&buf[..], &message1[..]); + + listener_task.await } From 589fdafddac11615c39da3f360d8769117fc9e44 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Fri, 20 Dec 2019 12:17:54 +0100 Subject: [PATCH 05/10] Use published versions of soketto and yamux. --- muxers/yamux/Cargo.toml | 2 +- transports/websocket/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 4b437dc9232..2c46470cb30 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -15,4 +15,4 @@ libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" parking_lot = "0.9" thiserror = "1.0" -yamux = { git = "https://github.com/paritytech/yamux.git", branch = "develop" } +yamux = "0.3" diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index ce9c84b03c4..39e03f0feb8 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -19,7 +19,7 @@ log = "0.4.8" quicksink = "0.1" rustls = "0.16" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } -soketto = { git = "https://github.com/paritytech/soketto.git", branch = "develop", features = ["deflate"] } +soketto = { version = "0.3", features = ["deflate"] } url = "2.1" webpki = "0.21" webpki-roots = "0.18" From 2bc8d9590d01957fdeedbed6f4dcef02123d504e Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Sat, 21 Dec 2019 15:35:55 +0100 Subject: [PATCH 06/10] Update to bytes v0.5 Except for `multiaddr` which encapsulates its use of bytes v0.4 now. --- Cargo.toml | 2 +- core/Cargo.toml | 4 +- core/src/transport/memory.rs | 4 +- misc/multiaddr/src/lib.rs | 22 ++------- misc/multihash/Cargo.toml | 6 +-- misc/multihash/src/lib.rs | 2 +- misc/multistream-select/Cargo.toml | 4 +- .../src/length_delimited.rs | 4 +- misc/multistream-select/src/negotiated.rs | 10 ++--- misc/multistream-select/src/protocol.rs | 6 +-- misc/rw-stream-sink/Cargo.toml | 2 +- misc/rw-stream-sink/src/lib.rs | 45 +++++++------------ muxers/mplex/Cargo.toml | 6 +-- muxers/mplex/src/lib.rs | 2 +- protocols/floodsub/Cargo.toml | 4 +- protocols/identify/Cargo.toml | 6 +-- protocols/kad/Cargo.toml | 6 +-- protocols/kad/src/protocol.rs | 20 ++++----- protocols/kad/src/record.rs | 2 +- protocols/noise/Cargo.toml | 2 +- protocols/ping/Cargo.toml | 6 +-- protocols/plaintext/Cargo.toml | 6 +-- protocols/plaintext/src/handshake.rs | 2 +- transports/tcp/Cargo.toml | 2 +- transports/websocket/Cargo.toml | 2 +- 25 files changed, 72 insertions(+), 105 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 596325e6cae..f1cf74164b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ default = ["secp256k1", "libp2p-websocket"] secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"] [dependencies] -bytes = "0.4" +bytes = "0.5" futures = "0.3.1" multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "misc/multiaddr" } multihash = { package = "parity-multihash", version = "0.2.0", path = "misc/multihash" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 756b3ce0644..b5d57802326 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] asn1_der = "0.6.1" bs58 = "0.3.0" -bytes = "0.4" +bytes = "0.5" ed25519-dalek = "1.0.0-pre.3" failure = "0.1" fnv = "1.0" @@ -32,7 +32,7 @@ rand = "0.7" rw-stream-sink = { version = "0.1.1", path = "../misc/rw-stream-sink" } sha2 = "0.8.0" smallvec = "1.0" -unsigned-varint = "0.2" +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } void = "1" zeroize = "1" diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index ad3312e6b0c..4fdbb47d504 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -19,7 +19,6 @@ // DEALINGS IN THE SOFTWARE. use crate::{Transport, transport::{TransportError, ListenerEvent}}; -use bytes::IntoBuf; use fnv::FnvHashMap; use futures::{future::{self, Ready}, prelude::*, channel::mpsc, task::Context, task::Poll}; use lazy_static::lazy_static; @@ -271,8 +270,7 @@ impl Sink for Chan { } } -impl Into>> for Chan { - #[inline] +impl> Into>> for Chan { fn into(self) -> RwStreamSink> { RwStreamSink::new(self) } diff --git a/misc/multiaddr/src/lib.rs b/misc/multiaddr/src/lib.rs index 5d3f0ae67ce..a425219e43f 100644 --- a/misc/multiaddr/src/lib.rs +++ b/misc/multiaddr/src/lib.rs @@ -7,7 +7,7 @@ mod errors; mod from_url; mod util; -use bytes::{Bytes, BytesMut}; +use bytes::Bytes; use serde::{ Deserialize, Deserializer, @@ -290,10 +290,10 @@ impl From for Multiaddr { } } -impl TryFrom for Multiaddr { +impl TryFrom> for Multiaddr { type Error = Error; - fn try_from(v: Bytes) -> Result { + fn try_from(v: Vec) -> Result { // Check if the argument is a valid `Multiaddr` by reading its protocols. let mut slice = &v[..]; while !slice.is_empty() { @@ -304,22 +304,6 @@ impl TryFrom for Multiaddr { } } -impl TryFrom for Multiaddr { - type Error = Error; - - fn try_from(v: BytesMut) -> Result { - Multiaddr::try_from(v.freeze()) - } -} - -impl TryFrom> for Multiaddr { - type Error = Error; - - fn try_from(v: Vec) -> Result { - Multiaddr::try_from(Bytes::from(v)) - } -} - impl TryFrom for Multiaddr { type Error = Error; diff --git a/misc/multihash/Cargo.toml b/misc/multihash/Cargo.toml index 82a231fb6d5..d5505bb4e27 100644 --- a/misc/multihash/Cargo.toml +++ b/misc/multihash/Cargo.toml @@ -11,9 +11,9 @@ documentation = "https://docs.rs/parity-multihash/" [dependencies] blake2 = { version = "0.8", default-features = false } -bytes = "0.4.12" -rand = { version = "0.6", default-features = false, features = ["std"] } +bytes = "0.5" +rand = { version = "0.7", default-features = false, features = ["std"] } sha-1 = { version = "0.8", default-features = false } sha2 = { version = "0.8", default-features = false } sha3 = { version = "0.8", default-features = false } -unsigned-varint = "0.2" +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } diff --git a/misc/multihash/src/lib.rs b/misc/multihash/src/lib.rs index 25a1d82434d..ec7eaeab1df 100644 --- a/misc/multihash/src/lib.rs +++ b/misc/multihash/src/lib.rs @@ -247,7 +247,7 @@ impl<'a> MultihashRef<'a> { /// This operation allocates. pub fn into_owned(self) -> Multihash { Multihash { - bytes: Bytes::from(self.bytes) + bytes: Bytes::copy_from_slice(self.bytes) } } diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index 43ca2137189..dab3aaabfb5 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -10,12 +10,12 @@ categories = ["network-programming", "asynchronous"] edition = "2018" [dependencies] -bytes = "0.4" +bytes = "0.5" futures = "0.1" log = "0.4" smallvec = "1.0" tokio-io = "0.1" -unsigned-varint = "0.2.2" +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } [dev-dependencies] tokio = "0.1" diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index 91e3fe88870..bc363c7e167 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use bytes::{Bytes, BytesMut, BufMut}; +use bytes::{Bytes, BytesMut, Buf, BufMut}; use futures::{try_ready, Async, Poll, Sink, StartSend, Stream, AsyncSink}; use std::{io, u16}; use tokio_io::{AsyncRead, AsyncWrite}; @@ -136,7 +136,7 @@ impl LengthDelimited { "Failed to write buffered frame.")) } - self.write_buffer.split_to(n); + self.write_buffer.advance(n); } Ok(Async::Ready(())) diff --git a/misc/multistream-select/src/negotiated.rs b/misc/multistream-select/src/negotiated.rs index 5e2c7ac991a..7611aee5f60 100644 --- a/misc/multistream-select/src/negotiated.rs +++ b/misc/multistream-select/src/negotiated.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use bytes::BytesMut; +use bytes::{BytesMut, Buf}; use crate::protocol::{Protocol, MessageReader, Message, Version, ProtocolError}; use futures::{prelude::*, Async, try_ready}; use log::debug; @@ -93,7 +93,7 @@ impl Negotiated { } if let State::Completed { remaining, .. } = &mut self.state { - let _ = remaining.take(); // Drop remaining data flushed above. + let _ = remaining.split_to(remaining.len()); // Drop remaining data flushed above. return Ok(Async::Ready(())) } @@ -232,7 +232,7 @@ where if n == 0 { return Err(io::ErrorKind::WriteZero.into()) } - remaining.split_to(n); + remaining.advance(n); } io.write(buf) }, @@ -251,7 +251,7 @@ where io::ErrorKind::WriteZero, "Failed to write remaining buffer.")) } - remaining.split_to(n); + remaining.advance(n); } io.flush() }, @@ -363,7 +363,7 @@ mod tests { let cap = rem.len() + free as usize; let step = u8::min(free, step) as usize + 1; let buf = Capped { buf: Vec::with_capacity(cap), step }; - let rem = BytesMut::from(rem); + let rem = BytesMut::from(&rem[..]); let mut io = Negotiated::completed(buf, rem.clone()); let mut written = 0; loop { diff --git a/misc/multistream-select/src/protocol.rs b/misc/multistream-select/src/protocol.rs index a21b80030f8..d895a2272ed 100644 --- a/misc/multistream-select/src/protocol.rs +++ b/misc/multistream-select/src/protocol.rs @@ -143,7 +143,7 @@ impl TryFrom<&[u8]> for Protocol { type Error = ProtocolError; fn try_from(value: &[u8]) -> Result { - Self::try_from(Bytes::from(value)) + Self::try_from(Bytes::copy_from_slice(value)) } } @@ -208,7 +208,7 @@ impl Message { out_msg.push(b'\n') } dest.reserve(out_msg.len()); - dest.put(out_msg); + dest.put(out_msg.as_ref()); Ok(()) } Message::NotAvailable => { @@ -254,7 +254,7 @@ impl Message { if len == 0 || len > rem.len() || rem[len - 1] != b'\n' { return Err(ProtocolError::InvalidMessage) } - let p = Protocol::try_from(Bytes::from(&rem[.. len - 1]))?; + let p = Protocol::try_from(Bytes::copy_from_slice(&rem[.. len - 1]))?; protocols.push(p); remaining = &rem[len ..] } diff --git a/misc/rw-stream-sink/Cargo.toml b/misc/rw-stream-sink/Cargo.toml index 2d4709cfe27..e9aeb595674 100644 --- a/misc/rw-stream-sink/Cargo.toml +++ b/misc/rw-stream-sink/Cargo.toml @@ -10,8 +10,8 @@ keywords = ["networking"] categories = ["network-programming", "asynchronous"] [dependencies] -bytes = "0.4.12" futures = "0.3.1" +static_assertions = "1" [dev-dependencies] async-std = "1.0" diff --git a/misc/rw-stream-sink/src/lib.rs b/misc/rw-stream-sink/src/lib.rs index 8bcdd3a3613..80f919f2ff1 100644 --- a/misc/rw-stream-sink/src/lib.rs +++ b/misc/rw-stream-sink/src/lib.rs @@ -25,26 +25,19 @@ //! Each call to [`AsyncWrite::poll_write`] will send one packet to the sink. //! Calls to [`AsyncRead::read`] will read from the stream's incoming packets. -use bytes::{IntoBuf, Buf}; use futures::{prelude::*, ready}; -use std::{io, pin::Pin, task::{Context, Poll}}; +use std::{io::{self, Read}, pin::Pin, task::{Context, Poll}}; + +static_assertions::const_assert!(std::mem::size_of::() <= std::mem::size_of::()); /// Wraps a [`Stream`] and [`Sink`] whose items are buffers. /// Implements [`AsyncRead`] and [`AsyncWrite`]. -pub struct RwStreamSink -where - S: TryStream, - ::Ok: IntoBuf -{ +pub struct RwStreamSink { inner: S, - current_item: Option<<::Ok as IntoBuf>::Buf> + current_item: Option::Ok>> } -impl RwStreamSink -where - S: TryStream, - ::Ok: IntoBuf -{ +impl RwStreamSink { /// Wraps around `inner`. pub fn new(inner: S) -> Self { RwStreamSink { inner, current_item: None } @@ -54,35 +47,32 @@ where impl AsyncRead for RwStreamSink where S: TryStream + Unpin, - ::Ok: IntoBuf + ::Ok: AsRef<[u8]> { fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll> { // Grab the item to copy from. let item_to_copy = loop { if let Some(ref mut i) = self.current_item { - if i.has_remaining() { + if i.position() < i.get_ref().as_ref().len() as u64 { break i } } self.current_item = Some(match ready!(self.inner.try_poll_next_unpin(cx)) { - Some(Ok(i)) => i.into_buf(), + Some(Ok(i)) => std::io::Cursor::new(i), Some(Err(e)) => return Poll::Ready(Err(e)), None => return Poll::Ready(Ok(0)) // EOF }); }; // Copy it! - debug_assert!(item_to_copy.has_remaining()); - let to_copy = std::cmp::min(buf.len(), item_to_copy.remaining()); - item_to_copy.take(to_copy).copy_to_slice(&mut buf[.. to_copy]); - Poll::Ready(Ok(to_copy)) + Poll::Ready(Ok(item_to_copy.read(buf)?)) } } impl AsyncWrite for RwStreamSink where S: TryStream + Sink<::Ok, Error = io::Error> + Unpin, - ::Ok: IntoBuf + for<'r> From<&'r [u8]> + ::Ok: for<'r> From<&'r [u8]> { fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll> { ready!(Pin::new(&mut self.inner).poll_ready(cx)?); @@ -102,16 +92,11 @@ where } } -impl Unpin for RwStreamSink -where - S: TryStream, - ::Ok: IntoBuf -{} +impl Unpin for RwStreamSink {} #[cfg(test)] mod tests { use async_std::task; - use bytes::Bytes; use futures::{channel::mpsc, prelude::*, stream}; use std::{pin::Pin, task::{Context, Poll}}; use super::RwStreamSink; @@ -163,9 +148,9 @@ mod tests { let mut wrapper = RwStreamSink::new(Wrapper(rx2.map(Ok), tx1)); task::block_on(async move { - tx2.send(Bytes::from("hel")).await.unwrap(); - tx2.send(Bytes::from("lo wor")).await.unwrap(); - tx2.send(Bytes::from("ld")).await.unwrap(); + tx2.send(Vec::from("hel")).await.unwrap(); + tx2.send(Vec::from("lo wor")).await.unwrap(); + tx2.send(Vec::from("ld")).await.unwrap(); tx2.close().await.unwrap(); let mut data = Vec::new(); diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index b66bd39454d..46980cebf50 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -10,14 +10,14 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -bytes = "0.4.5" +bytes = "0.5" fnv = "1.0" futures = "0.3.1" -futures_codec = "= 0.3.3" +futures_codec = "0.3.4" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4" parking_lot = "0.9" -unsigned-varint = { version = "0.2.3", features = ["futures-codec"] } +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } [dev-dependencies] async-std = "1.0" diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index 0c97cbe2047..30d00450ad2 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -535,7 +535,7 @@ where C: AsyncRead + AsyncWrite + Unpin let elem = codec::Elem::Data { substream_id: substream.num, - data: From::from(&buf[..to_write]), + data: Bytes::copy_from_slice(&buf[..to_write]), endpoint: substream.endpoint, }; diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index f1c46f6bac5..c67df097b4d 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -11,12 +11,12 @@ categories = ["network-programming", "asynchronous"] [dependencies] bs58 = "0.3.0" -bytes = "0.4" +bytes = "0.5" cuckoofilter = "0.3.2" fnv = "1.0" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } protobuf = "2.8" -rand = "0.6" +rand = "0.7" smallvec = "1.0" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 6e6a52bde45..5e742b117f7 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -bytes = "0.4" -futures_codec = "= 0.3.3" +bytes = "0.5" +futures_codec = "0.3.4" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } @@ -20,7 +20,7 @@ multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../mis protobuf = "2.8" smallvec = "1.0" wasm-timer = "0.2" -unsigned-varint = { version = "0.2.3", features = ["futures-codec"] } +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } [dev-dependencies] async-std = "1.0" diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index b72974b07e5..583cff9ccd3 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -11,10 +11,10 @@ categories = ["network-programming", "asynchronous"] [dependencies] arrayvec = "0.5.1" -bytes = "0.4" +bytes = "0.5" either = "1.5" fnv = "1.0" -futures_codec = "= 0.3.3" +futures_codec = "0.3.4" futures = "0.3.1" log = "0.4" libp2p-core = { version = "0.13.0", path = "../../core" } @@ -27,7 +27,7 @@ sha2 = "0.8.0" smallvec = "1.0" wasm-timer = "0.2" uint = "0.8" -unsigned-varint = { version = "0.2.3", features = ["futures-codec"] } +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } void = "1.0" [dev-dependencies] diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 3f937929031..645c151d21e 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -58,7 +58,6 @@ pub enum KadConnectionType { } impl From for KadConnectionType { - #[inline] fn from(raw: proto::Message_ConnectionType) -> KadConnectionType { use proto::Message_ConnectionType::{ CAN_CONNECT, CANNOT_CONNECT, CONNECTED, NOT_CONNECTED @@ -73,7 +72,6 @@ impl From for KadConnectionType { } impl Into for KadConnectionType { - #[inline] fn into(self) -> proto::Message_ConnectionType { use proto::Message_ConnectionType::{ CAN_CONNECT, CANNOT_CONNECT, CONNECTED, NOT_CONNECTED @@ -181,7 +179,6 @@ where type Future = future::Ready>; type Error = io::Error; - #[inline] fn upgrade_inbound(self, incoming: Negotiated, _: Self::Info) -> Self::Future { let mut codec = UviBytes::default(); codec.set_max_len(4096); @@ -191,7 +188,9 @@ where .err_into() .with::<_, _, fn(_) -> _, _>(|response| { let proto_struct = resp_msg_to_proto(response); - future::ready(proto_struct.write_to_bytes().map_err(invalid_data)) + future::ready(proto_struct.write_to_bytes() + .map(io::Cursor::new) + .map_err(invalid_data)) }) .and_then::<_, fn(_) -> _>(|bytes| { let request = match protobuf::parse_from_bytes(&bytes) { @@ -212,7 +211,6 @@ where type Future = future::Ready>; type Error = io::Error; - #[inline] fn upgrade_outbound(self, incoming: Negotiated, _: Self::Info) -> Self::Future { let mut codec = UviBytes::default(); codec.set_max_len(4096); @@ -222,7 +220,9 @@ where .err_into() .with::<_, _, fn(_) -> _, _>(|request| { let proto_struct = req_msg_to_proto(request); - future::ready(proto_struct.write_to_bytes().map_err(invalid_data)) + future::ready(proto_struct.write_to_bytes() + .map(io::Cursor::new) + .map_err(invalid_data)) }) .and_then::<_, fn(_) -> _>(|bytes| { let response = match protobuf::parse_from_bytes(&bytes) { @@ -243,11 +243,11 @@ pub type KadOutStreamSink = KadStreamSink; pub type KadStreamSink = stream::AndThen< sink::With< - stream::ErrInto>>, io::Error>, - Vec, + stream::ErrInto>>>, io::Error>, + io::Cursor>, A, - future::Ready, io::Error>>, - fn(A) -> future::Ready, io::Error>>, + future::Ready>, io::Error>>, + fn(A) -> future::Ready>, io::Error>>, >, future::Ready>, fn(BytesMut) -> future::Ready>, diff --git a/protocols/kad/src/record.rs b/protocols/kad/src/record.rs index c33b3106080..dcd724b5e2d 100644 --- a/protocols/kad/src/record.rs +++ b/protocols/kad/src/record.rs @@ -35,7 +35,7 @@ pub struct Key(Bytes); impl Key { /// Creates a new key from the bytes of the input. pub fn new>(key: &K) -> Self { - Key(Bytes::from(key.as_ref())) + Key(Bytes::copy_from_slice(key.as_ref())) } /// Copies the bytes of the key into a new vector. diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index cc23636836e..ab5bff28cfd 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/libp2p/rust-libp2p" edition = "2018" [dependencies] -bytes = "0.4" +bytes = "0.5" curve25519-dalek = "1" futures = "0.3.1" lazy_static = "1.2" diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index fedf4f470d0..704436deb5d 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -10,15 +10,15 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -bytes = "0.4" +bytes = "0.5" +futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } log = "0.4.1" multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../misc/multiaddr" } -futures = "0.3.1" rand = "0.7.2" -wasm-timer = "0.2" void = "1.0" +wasm-timer = "0.2" [dev-dependencies] async-std = "1.0" diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 2f9b45a076b..575181a868d 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -10,14 +10,14 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -bytes = "0.4.12" +bytes = "0.5" futures = "0.3.1" -futures_codec = "= 0.3.3" +futures_codec = "0.3.4" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" protobuf = "2.8.1" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } -unsigned-varint = { version = "0.2.3", features = ["futures-codec"] } +unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } void = "1.0.2" [dev-dependencies] diff --git a/protocols/plaintext/src/handshake.rs b/protocols/plaintext/src/handshake.rs index 9a295766a3f..b3c6ca4b14c 100644 --- a/protocols/plaintext/src/handshake.rs +++ b/protocols/plaintext/src/handshake.rs @@ -120,7 +120,7 @@ where let context = HandshakeContext::new(config)?; trace!("sending exchange to remote"); - socket.send(BytesMut::from(context.state.exchange_bytes.clone())).await?; + socket.send(BytesMut::from(&context.state.exchange_bytes[..])).await?; trace!("receiving the remote's exchange"); let context = match socket.next().await { diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 12244e13f39..62fb629ce44 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-std = "1.0" -bytes = "0.4.12" +bytes = "0.5" futures = "0.3.1" futures-timer = "2.0" get_if_addrs = "0.5.3" diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 39e03f0feb8..cf8203c5bef 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-tls = "0.6" -bytes = "0.4.12" +bytes = "0.5" either = "1.5.3" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } From 34b36b464b300ef22524f4da49e58a402d620486 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Sat, 21 Dec 2019 17:14:59 +0100 Subject: [PATCH 07/10] Cover more cases in simultaneous connect test. --- core/tests/network_simult.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/tests/network_simult.rs b/core/tests/network_simult.rs index 84f77c62139..d01fea04764 100644 --- a/core/tests/network_simult.rs +++ b/core/tests/network_simult.rs @@ -152,7 +152,7 @@ fn raw_swarm_simultaneous_connect() { Dialing, Connected, Replaced, - Errored + Denied } loop { @@ -162,7 +162,7 @@ fn raw_swarm_simultaneous_connect() { let mut swarm1_dial_start = Delay::new(Duration::new(0, rand::random::() % 50_000_000)); let mut swarm2_dial_start = Delay::new(Duration::new(0, rand::random::() % 50_000_000)); - let future = future::poll_fn(|cx| -> Poll { + let future = future::poll_fn(|cx| { loop { let mut swarm1_not_ready = false; let mut swarm2_not_ready = false; @@ -202,7 +202,7 @@ fn raw_swarm_simultaneous_connect() { error: IncomingError::DeniedLowerPriority, .. }) => { assert_eq!(swarm1_step, Step::Connected); - swarm1_step = Step::Errored + swarm1_step = Step::Denied } Poll::Ready(NetworkEvent::Connected { conn_info, .. }) => { assert_eq!(conn_info, *swarm2.local_peer_id()); @@ -233,7 +233,7 @@ fn raw_swarm_simultaneous_connect() { error: IncomingError::DeniedLowerPriority, .. }) => { assert_eq!(swarm2_step, Step::Connected); - swarm2_step = Step::Errored + swarm2_step = Step::Denied } Poll::Ready(NetworkEvent::Connected { conn_info, .. }) => { assert_eq!(conn_info, *swarm1.local_peer_id()); @@ -260,9 +260,12 @@ fn raw_swarm_simultaneous_connect() { match (swarm1_step, swarm2_step) { | (Step::Connected, Step::Replaced) - | (Step::Connected, Step::Errored) + | (Step::Connected, Step::Denied) | (Step::Replaced, Step::Connected) - | (Step::Errored, Step::Connected) => return Poll::Ready(true), + | (Step::Replaced, Step::Denied) + | (Step::Replaced, Step::Replaced) + | (Step::Denied, Step::Connected) + | (Step::Denied, Step::Replaced) => return Poll::Ready(true), _else => () } From 83e4c60923b22d4c23af6031cd7b480730905f79 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Mon, 30 Dec 2019 12:08:17 +0100 Subject: [PATCH 08/10] Update yamux dependency. --- muxers/yamux/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 2c46470cb30..a25a24203ab 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -15,4 +15,4 @@ libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" parking_lot = "0.9" thiserror = "1.0" -yamux = "0.3" +yamux = "0.4" From 72f1018acda6d081f14b59c92bc83efc1a86dc0d Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Thu, 2 Jan 2020 10:45:43 +0100 Subject: [PATCH 09/10] Update to unsigned-varint v0.3 --- core/Cargo.toml | 2 +- misc/multiaddr/Cargo.toml | 2 +- misc/multihash/Cargo.toml | 2 +- misc/multistream-select/Cargo.toml | 2 +- muxers/mplex/Cargo.toml | 2 +- protocols/identify/Cargo.toml | 2 +- protocols/kad/Cargo.toml | 2 +- protocols/plaintext/Cargo.toml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index b5d57802326..02328e4e2ee 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -32,7 +32,7 @@ rand = "0.7" rw-stream-sink = { version = "0.1.1", path = "../misc/rw-stream-sink" } sha2 = "0.8.0" smallvec = "1.0" -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } +unsigned-varint = "0.3" void = "1" zeroize = "1" diff --git a/misc/multiaddr/Cargo.toml b/misc/multiaddr/Cargo.toml index c7b6b1bc671..9e3820ef9a9 100644 --- a/misc/multiaddr/Cargo.toml +++ b/misc/multiaddr/Cargo.toml @@ -17,7 +17,7 @@ data-encoding = "2.1" multihash = { package = "parity-multihash", version = "0.2.0", path = "../multihash" } percent-encoding = "2.1.0" serde = "1.0.70" -unsigned-varint = "0.2" +unsigned-varint = "0.3" url = { version = "2.1.0", default-features = false } [dev-dependencies] diff --git a/misc/multihash/Cargo.toml b/misc/multihash/Cargo.toml index d5505bb4e27..215513a6258 100644 --- a/misc/multihash/Cargo.toml +++ b/misc/multihash/Cargo.toml @@ -16,4 +16,4 @@ rand = { version = "0.7", default-features = false, features = ["std"] } sha-1 = { version = "0.8", default-features = false } sha2 = { version = "0.8", default-features = false } sha3 = { version = "0.8", default-features = false } -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } +unsigned-varint = "0.3" diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index dab3aaabfb5..1012f3b6f6f 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.1" log = "0.4" smallvec = "1.0" tokio-io = "0.1" -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5" } +unsigned-varint = "0.3" [dev-dependencies] tokio = "0.1" diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 46980cebf50..e978ea763fc 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -17,7 +17,7 @@ futures_codec = "0.3.4" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4" parking_lot = "0.9" -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } +unsigned-varint = { version = "0.3", features = ["futures-codec"] } [dev-dependencies] async-std = "1.0" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 5e742b117f7..d98f86aac6d 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -20,7 +20,7 @@ multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../mis protobuf = "2.8" smallvec = "1.0" wasm-timer = "0.2" -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } +unsigned-varint = { version = "0.3", features = ["futures-codec"] } [dev-dependencies] async-std = "1.0" diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 583cff9ccd3..f4ef68c7b55 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -27,7 +27,7 @@ sha2 = "0.8.0" smallvec = "1.0" wasm-timer = "0.2" uint = "0.8" -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } +unsigned-varint = { version = "0.3", features = ["futures-codec"] } void = "1.0" [dev-dependencies] diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 575181a868d..29c82d6a272 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -17,7 +17,7 @@ libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" protobuf = "2.8.1" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } -unsigned-varint = { git = "https://github.com/twittner/unsigned-varint.git", branch = "bytes-0.5", features = ["futures-codec"] } +unsigned-varint = { version = "0.3", features = ["futures-codec"] } void = "1.0.2" [dev-dependencies] From d870c734eecd2e5e99f2df7cea71808261d53d74 Mon Sep 17 00:00:00 2001 From: Toralf Wittner Date: Thu, 2 Jan 2020 10:48:51 +0100 Subject: [PATCH 10/10] Pin protobuf to version 2.8.1 --- core/Cargo.toml | 2 +- protocols/floodsub/Cargo.toml | 2 +- protocols/identify/Cargo.toml | 2 +- protocols/kad/Cargo.toml | 2 +- protocols/noise/Cargo.toml | 4 ++-- protocols/plaintext/Cargo.toml | 2 +- protocols/secio/Cargo.toml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 02328e4e2ee..30f7067ae1b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -26,7 +26,7 @@ multihash = { package = "parity-multihash", version = "0.2.0", path = "../misc/m multistream-select = { version = "0.6.0", path = "../misc/multistream-select" } parking_lot = "0.9.0" pin-project = "0.4.6" -protobuf = "2.8" +protobuf = "= 2.8.1" quick-error = "1.2" rand = "0.7" rw-stream-sink = { version = "0.1.1", path = "../misc/rw-stream-sink" } diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index c67df097b4d..db6e016f8c1 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -17,6 +17,6 @@ fnv = "1.0" futures = "0.3.1" libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } -protobuf = "2.8" +protobuf = "= 2.8.1" rand = "0.7" smallvec = "1.0" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index d98f86aac6d..fa8a917ceb1 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -17,7 +17,7 @@ libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } log = "0.4.1" multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../misc/multiaddr" } -protobuf = "2.8" +protobuf = "= 2.8.1" smallvec = "1.0" wasm-timer = "0.2" unsigned-varint = { version = "0.3", features = ["futures-codec"] } diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index f4ef68c7b55..f79b0a5ab9e 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -21,7 +21,7 @@ libp2p-core = { version = "0.13.0", path = "../../core" } libp2p-swarm = { version = "0.3.0", path = "../../swarm" } multiaddr = { package = "parity-multiaddr", version = "0.6.0", path = "../../misc/multiaddr" } multihash = { package = "parity-multihash", version = "0.2.0", path = "../../misc/multihash" } -protobuf = "2.8" +protobuf = "= 2.8.1" rand = "0.7.2" sha2 = "0.8.0" smallvec = "1.0" diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index ab5bff28cfd..762a77baf8d 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -14,8 +14,8 @@ futures = "0.3.1" lazy_static = "1.2" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4" -protobuf = "2.8" -rand = "^0.7.2" +protobuf = "= 2.8.1" +rand = "0.7.2" ring = { version = "0.16.9", features = ["alloc"], default-features = false } snow = { version = "0.6.1", features = ["ring-resolver"], default-features = false } x25519-dalek = "0.5" diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 29c82d6a272..577b0d83510 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -15,7 +15,7 @@ futures = "0.3.1" futures_codec = "0.3.4" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.8" -protobuf = "2.8.1" +protobuf = "= 2.8.1" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" } unsigned-varint = { version = "0.3", features = ["futures-codec"] } void = "1.0.2" diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index f16502586eb..ff03c6f8c95 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -18,7 +18,7 @@ hmac = "0.7.0" lazy_static = "1.2.0" libp2p-core = { version = "0.13.0", path = "../../core" } log = "0.4.6" -protobuf = "2.8" +protobuf = "= 2.8.1" quicksink = "0.1" rand = "0.7" rw-stream-sink = { version = "0.1.1", path = "../../misc/rw-stream-sink" }