Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Update to libp2p v0.20.1 #6465

Merged
5 commits merged into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 263 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ blake2 = { opt-level = 3 }
blake2-rfc = { opt-level = 3 }
blake2b_simd = { opt-level = 3 }
blake2s_simd = { opt-level = 3 }
chacha20-poly1305-aead = { opt-level = 3 }
chacha20poly1305 = { opt-level = 3 }
cranelift-codegen = { opt-level = 3 }
cranelift-wasm = { opt-level = 3 }
crc32fast = { opt-level = 3 }
Expand Down
2 changes: 1 addition & 1 deletion bin/node/browser-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"

[dependencies]
futures-timer = "3.0.2"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
jsonrpc-core = "14.2.0"
serde = "1.0.106"
serde_json = "1.0.48"
Expand Down
2 changes: 1 addition & 1 deletion bin/utils/subkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ derive_more = { version = "0.99.2" }
sc-rpc = { version = "2.0.0-rc4", path = "../../../client/rpc" }
jsonrpc-core-client = { version = "14.2.0", features = ["http"] }
hyper = "0.12.35"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
serde_json = "1.0"

[features]
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", default-features = false, version = "1
derive_more = "0.99.2"
futures = "0.3.4"
futures-timer = "3.0.1"
libp2p = { version = "0.19.1", default-features = false, features = ["kad"] }
libp2p = { version = "0.20.1", default-features = false, features = ["kad"] }
log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc4"}
prost = "0.6.1"
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.4"
futures-timer = "3.0.1"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
log = "0.4.8"
lru = "0.4.3"
sc-network = { version = "0.8.0-rc4", path = "../network" }
Expand Down
4 changes: 2 additions & 2 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ wasm-timer = "0.2"
zeroize = "1.0.0"

[dependencies.libp2p]
version = "0.19.1"
version = "0.20.1"
default-features = false
features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std", "websocket", "yamux"]

[dev-dependencies]
async-std = "1.5"
assert_matches = "1.3"
env_logger = "0.7.0"
libp2p = { version = "0.19.1", default-features = false, features = ["secio"] }
libp2p = { version = "0.20.1", default-features = false, features = ["secio"] }
quickcheck = "0.9.0"
rand = "0.7.2"
sp-keyring = { version = "2.0.0-rc4", path = "../../primitives/keyring" }
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
Ok(ok) => {
let results = ok.records
.into_iter()
.map(|r| (r.key, r.value))
.map(|r| (r.record.key, r.record.value))
.collect();

DiscoveryOut::ValueFound(results)
Expand Down
2 changes: 1 addition & 1 deletion client/network/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parking_lot = "0.10.0"
futures = "0.3.4"
futures-timer = "3.0.1"
rand = "0.7.2"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
sp-consensus = { version = "0.8.0-rc4", path = "../../../primitives/consensus/common" }
sc-consensus = { version = "0.8.0-rc4", path = "../../../client/consensus/common" }
sc-client-api = { version = "2.0.0-rc4", path = "../../api" }
Expand Down
2 changes: 1 addition & 1 deletion client/peerset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
futures = "0.3.4"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
sp-utils = { version = "2.0.0-rc4", path = "../../primitives/utils"}
log = "0.4.8"
serde_json = "1.0.41"
Expand Down
3 changes: 1 addition & 2 deletions client/telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ targets = ["x86_64-unknown-linux-gnu"]


[dependencies]
bytes = "0.5"
parking_lot = "0.10.0"
futures = "0.3.4"
futures-timer = "3.0.1"
wasm-timer = "0.2.0"
libp2p = { version = "0.19.1", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] }
libp2p = { version = "0.20.1", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] }
log = "0.4.8"
pin-project = "0.4.6"
rand = "0.7.2"
Expand Down
21 changes: 10 additions & 11 deletions client/telemetry/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! events indicating what happened since the latest polling.
//!

use bytes::BytesMut;
use futures::{prelude::*, ready};
use libp2p::{core::transport::OptionalTransport, Multiaddr, Transport, wasm_ext};
use log::{trace, warn, error};
Expand Down Expand Up @@ -61,8 +60,8 @@ impl<T: ?Sized + Stream + Sink<I>, I> StreamAndSink<I> for T {}

type WsTrans = libp2p::core::transport::boxed::Boxed<
Pin<Box<dyn StreamAndSink<
BytesMut,
Item = Result<BytesMut, io::Error>,
Vec<u8>,
Item = Result<Vec<u8>, io::Error>,
Error = io::Error
> + Send>>,
io::Error
Expand Down Expand Up @@ -92,12 +91,12 @@ impl TelemetryWorker {
libp2p::websocket::framed::WsConfig::new(inner)
.and_then(|connec, _| {
let connec = connec
.with(|item: BytesMut| {
.with(|item| {
let item = libp2p::websocket::framed::OutgoingData::Binary(item);
future::ready(Ok::<_, io::Error>(item))
})
.try_filter(|item| future::ready(item.is_data()))
.map_ok(|data| BytesMut::from(data.as_ref()));
.map_ok(|data| data.into_bytes());
future::ready(Ok::<_, io::Error>(connec))
})
});
Expand Down Expand Up @@ -189,7 +188,7 @@ impl TelemetryWorker {
/// For some context, we put this object around the `wasm_ext::ExtTransport` in order to make sure
/// that each telemetry message maps to one single call to `write` in the WASM FFI.
#[pin_project::pin_project]
struct StreamSink<T>(#[pin] T, Option<BytesMut>);
struct StreamSink<T>(#[pin] T, Option<Vec<u8>>);

impl<T> From<T> for StreamSink<T> {
fn from(inner: T) -> StreamSink<T> {
Expand All @@ -198,15 +197,15 @@ impl<T> From<T> for StreamSink<T> {
}

impl<T: AsyncRead> Stream for StreamSink<T> {
type Item = Result<BytesMut, io::Error>;
type Item = Result<Vec<u8>, io::Error>;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
let this = self.project();
let mut buf = [0; 128];
let mut buf = vec![0; 128];
match ready!(AsyncRead::poll_read(this.0, cx, &mut buf)) {
Ok(0) => Poll::Ready(None),
Ok(n) => {
let buf: BytesMut = buf[..n].into();
buf.truncate(n);
Poll::Ready(Some(Ok(buf)))
},
Err(err) => Poll::Ready(Some(Err(err))),
Expand All @@ -232,15 +231,15 @@ impl<T: AsyncWrite> StreamSink<T> {
}
}

impl<T: AsyncWrite> Sink<BytesMut> for StreamSink<T> {
impl<T: AsyncWrite> Sink<Vec<u8>> for StreamSink<T> {
type Error = io::Error;

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
ready!(StreamSink::poll_flush_buffer(self, cx))?;
Poll::Ready(Ok(()))
}

fn start_send(self: Pin<&mut Self>, item: BytesMut) -> Result<(), Self::Error> {
fn start_send(self: Pin<&mut Self>, item: Vec<u8>) -> Result<(), Self::Error> {
let this = self.project();
debug_assert!(this.1.is_none());
*this.1 = Some(item);
Expand Down
13 changes: 6 additions & 7 deletions client/telemetry/src/worker/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

//! Contains the `Node` struct, which handles communications with a single telemetry endpoint.

use bytes::BytesMut;
use futures::prelude::*;
use futures_timer::Delay;
use libp2p::Multiaddr;
Expand Down Expand Up @@ -57,7 +56,7 @@ struct NodeSocketConnected<TTrans: Transport> {
/// Where to send data.
sink: TTrans::Output,
/// Queue of packets to send.
pending: VecDeque<BytesMut>,
pending: VecDeque<Vec<u8>>,
/// If true, we need to flush the sink.
need_flush: bool,
/// A timeout for the socket to write data.
Expand Down Expand Up @@ -103,15 +102,15 @@ impl<TTrans: Transport> Node<TTrans> {

impl<TTrans: Transport, TSinkErr> Node<TTrans>
where TTrans: Clone + Unpin, TTrans::Dial: Unpin,
TTrans::Output: Sink<BytesMut, Error = TSinkErr>
+ Stream<Item=Result<BytesMut, TSinkErr>>
TTrans::Output: Sink<Vec<u8>, Error = TSinkErr>
+ Stream<Item=Result<Vec<u8>, TSinkErr>>
+ Unpin,
TSinkErr: fmt::Debug
{
/// Sends a WebSocket frame to the node. Returns an error if we are not connected to the node.
///
/// After calling this method, you should call `poll` in order for it to be properly processed.
pub fn send_message(&mut self, payload: impl Into<BytesMut>) -> Result<(), ()> {
pub fn send_message(&mut self, payload: impl Into<Vec<u8>>) -> Result<(), ()> {
if let NodeSocket::Connected(NodeSocketConnected { pending, .. }) = &mut self.socket {
if pending.len() <= MAX_PENDING {
trace!(target: "telemetry", "Adding log entry to queue for {:?}", self.addr);
Expand Down Expand Up @@ -203,8 +202,8 @@ fn gen_rand_reconnect_delay() -> Delay {
}

impl<TTrans: Transport, TSinkErr> NodeSocketConnected<TTrans>
where TTrans::Output: Sink<BytesMut, Error = TSinkErr>
+ Stream<Item=Result<BytesMut, TSinkErr>>
where TTrans::Output: Sink<Vec<u8>, Error = TSinkErr>
+ Stream<Item=Result<Vec<u8>, TSinkErr>>
+ Unpin
{
/// Processes the queue of messages for the connected socket.
Expand Down
2 changes: 1 addition & 1 deletion primitives/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
derive_more = "0.99.2"
libp2p = { version = "0.19.1", default-features = false }
libp2p = { version = "0.20.1", default-features = false }
log = "0.4.8"
sp-core = { path= "../../core", version = "2.0.0-rc4"}
sp-inherents = { version = "2.0.0-rc4", path = "../../inherents" }
Expand Down