Update to libp2p v0.20.1 (#6465)

* Update to libp2p-0.20.0

* Update to `libp2p-0.20.1`.

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
Toralf Wittner
2020-06-30 10:02:51 +02:00
committed by GitHub
parent 2e2af4b05a
commit 3de2a88075
14 changed files with 291 additions and 194 deletions
+263 -163
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -206,7 +206,7 @@ blake2 = { opt-level = 3 }
blake2-rfc = { opt-level = 3 } blake2-rfc = { opt-level = 3 }
blake2b_simd = { opt-level = 3 } blake2b_simd = { opt-level = 3 }
blake2s_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-codegen = { opt-level = 3 }
cranelift-wasm = { opt-level = 3 } cranelift-wasm = { opt-level = 3 }
crc32fast = { opt-level = 3 } crc32fast = { opt-level = 3 }
@@ -8,7 +8,7 @@ license = "Apache-2.0"
[dependencies] [dependencies]
futures-timer = "3.0.2" 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" jsonrpc-core = "14.2.0"
serde = "1.0.106" serde = "1.0.106"
serde_json = "1.0.48" serde_json = "1.0.48"
+1 -1
View File
@@ -33,7 +33,7 @@ derive_more = { version = "0.99.2" }
sc-rpc = { version = "2.0.0-rc4", path = "../../../client/rpc" } sc-rpc = { version = "2.0.0-rc4", path = "../../../client/rpc" }
jsonrpc-core-client = { version = "14.2.0", features = ["http"] } jsonrpc-core-client = { version = "14.2.0", features = ["http"] }
hyper = "0.12.35" hyper = "0.12.35"
libp2p = { version = "0.19.1", default-features = false } libp2p = { version = "0.20.1", default-features = false }
serde_json = "1.0" serde_json = "1.0"
[features] [features]
@@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", default-features = false, version = "1
derive_more = "0.99.2" derive_more = "0.99.2"
futures = "0.3.4" futures = "0.3.4"
futures-timer = "3.0.1" 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" log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc4"} prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc4"}
prost = "0.6.1" prost = "0.6.1"
+1 -1
View File
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
futures = "0.3.4" futures = "0.3.4"
futures-timer = "3.0.1" 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" log = "0.4.8"
lru = "0.4.3" lru = "0.4.3"
sc-network = { version = "0.8.0-rc4", path = "../network" } sc-network = { version = "0.8.0-rc4", path = "../network" }
+2 -2
View File
@@ -63,7 +63,7 @@ wasm-timer = "0.2"
zeroize = "1.0.0" zeroize = "1.0.0"
[dependencies.libp2p] [dependencies.libp2p]
version = "0.19.1" version = "0.20.1"
default-features = false default-features = false
features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std", "websocket", "yamux"] features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std", "websocket", "yamux"]
@@ -71,7 +71,7 @@ features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std"
async-std = "1.5" async-std = "1.5"
assert_matches = "1.3" assert_matches = "1.3"
env_logger = "0.7.0" 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" quickcheck = "0.9.0"
rand = "0.7.2" rand = "0.7.2"
sp-keyring = { version = "2.0.0-rc4", path = "../../primitives/keyring" } sp-keyring = { version = "2.0.0-rc4", path = "../../primitives/keyring" }
+1 -1
View File
@@ -601,7 +601,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
Ok(ok) => { Ok(ok) => {
let results = ok.records let results = ok.records
.into_iter() .into_iter()
.map(|r| (r.key, r.value)) .map(|r| (r.record.key, r.record.value))
.collect(); .collect();
DiscoveryOut::ValueFound(results) DiscoveryOut::ValueFound(results)
+1 -1
View File
@@ -19,7 +19,7 @@ parking_lot = "0.10.0"
futures = "0.3.4" futures = "0.3.4"
futures-timer = "3.0.1" futures-timer = "3.0.1"
rand = "0.7.2" 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" } sp-consensus = { version = "0.8.0-rc4", path = "../../../primitives/consensus/common" }
sc-consensus = { version = "0.8.0-rc4", path = "../../../client/consensus/common" } sc-consensus = { version = "0.8.0-rc4", path = "../../../client/consensus/common" }
sc-client-api = { version = "2.0.0-rc4", path = "../../api" } sc-client-api = { version = "2.0.0-rc4", path = "../../api" }
+1 -1
View File
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
futures = "0.3.4" 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"} sp-utils = { version = "2.0.0-rc4", path = "../../primitives/utils"}
log = "0.4.8" log = "0.4.8"
serde_json = "1.0.41" serde_json = "1.0.41"
+1 -2
View File
@@ -14,12 +14,11 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
bytes = "0.5"
parking_lot = "0.10.0" parking_lot = "0.10.0"
futures = "0.3.4" futures = "0.3.4"
futures-timer = "3.0.1" futures-timer = "3.0.1"
wasm-timer = "0.2.0" 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" log = "0.4.8"
pin-project = "0.4.6" pin-project = "0.4.6"
rand = "0.7.2" rand = "0.7.2"
+10 -11
View File
@@ -28,7 +28,6 @@
//! events indicating what happened since the latest polling. //! events indicating what happened since the latest polling.
//! //!
use bytes::BytesMut;
use futures::{prelude::*, ready}; use futures::{prelude::*, ready};
use libp2p::{core::transport::OptionalTransport, Multiaddr, Transport, wasm_ext}; use libp2p::{core::transport::OptionalTransport, Multiaddr, Transport, wasm_ext};
use log::{trace, warn, error}; use log::{trace, warn, error};
@@ -61,8 +60,8 @@ impl<T: ?Sized + Stream + Sink<I>, I> StreamAndSink<I> for T {}
type WsTrans = libp2p::core::transport::boxed::Boxed< type WsTrans = libp2p::core::transport::boxed::Boxed<
Pin<Box<dyn StreamAndSink< Pin<Box<dyn StreamAndSink<
BytesMut, Vec<u8>,
Item = Result<BytesMut, io::Error>, Item = Result<Vec<u8>, io::Error>,
Error = io::Error Error = io::Error
> + Send>>, > + Send>>,
io::Error io::Error
@@ -92,12 +91,12 @@ impl TelemetryWorker {
libp2p::websocket::framed::WsConfig::new(inner) libp2p::websocket::framed::WsConfig::new(inner)
.and_then(|connec, _| { .and_then(|connec, _| {
let connec = connec let connec = connec
.with(|item: BytesMut| { .with(|item| {
let item = libp2p::websocket::framed::OutgoingData::Binary(item); let item = libp2p::websocket::framed::OutgoingData::Binary(item);
future::ready(Ok::<_, io::Error>(item)) future::ready(Ok::<_, io::Error>(item))
}) })
.try_filter(|item| future::ready(item.is_data())) .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)) future::ready(Ok::<_, io::Error>(connec))
}) })
}); });
@@ -189,7 +188,7 @@ impl TelemetryWorker {
/// For some context, we put this object around the `wasm_ext::ExtTransport` in order to make sure /// 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. /// that each telemetry message maps to one single call to `write` in the WASM FFI.
#[pin_project::pin_project] #[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> { impl<T> From<T> for StreamSink<T> {
fn from(inner: T) -> StreamSink<T> { fn from(inner: T) -> StreamSink<T> {
@@ -198,15 +197,15 @@ impl<T> From<T> for StreamSink<T> {
} }
impl<T: AsyncRead> Stream 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>> { fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
let this = self.project(); 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)) { match ready!(AsyncRead::poll_read(this.0, cx, &mut buf)) {
Ok(0) => Poll::Ready(None), Ok(0) => Poll::Ready(None),
Ok(n) => { Ok(n) => {
let buf: BytesMut = buf[..n].into(); buf.truncate(n);
Poll::Ready(Some(Ok(buf))) Poll::Ready(Some(Ok(buf)))
}, },
Err(err) => Poll::Ready(Some(Err(err))), Err(err) => Poll::Ready(Some(Err(err))),
@@ -232,7 +231,7 @@ 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; type Error = io::Error;
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> { fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
@@ -240,7 +239,7 @@ impl<T: AsyncWrite> Sink<BytesMut> for StreamSink<T> {
Poll::Ready(Ok(())) 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(); let this = self.project();
debug_assert!(this.1.is_none()); debug_assert!(this.1.is_none());
*this.1 = Some(item); *this.1 = Some(item);
@@ -18,7 +18,6 @@
//! Contains the `Node` struct, which handles communications with a single telemetry endpoint. //! Contains the `Node` struct, which handles communications with a single telemetry endpoint.
use bytes::BytesMut;
use futures::prelude::*; use futures::prelude::*;
use futures_timer::Delay; use futures_timer::Delay;
use libp2p::Multiaddr; use libp2p::Multiaddr;
@@ -57,7 +56,7 @@ struct NodeSocketConnected<TTrans: Transport> {
/// Where to send data. /// Where to send data.
sink: TTrans::Output, sink: TTrans::Output,
/// Queue of packets to send. /// Queue of packets to send.
pending: VecDeque<BytesMut>, pending: VecDeque<Vec<u8>>,
/// If true, we need to flush the sink. /// If true, we need to flush the sink.
need_flush: bool, need_flush: bool,
/// A timeout for the socket to write data. /// A timeout for the socket to write data.
@@ -103,15 +102,15 @@ impl<TTrans: Transport> Node<TTrans> {
impl<TTrans: Transport, TSinkErr> Node<TTrans> impl<TTrans: Transport, TSinkErr> Node<TTrans>
where TTrans: Clone + Unpin, TTrans::Dial: Unpin, where TTrans: Clone + Unpin, TTrans::Dial: Unpin,
TTrans::Output: Sink<BytesMut, Error = TSinkErr> TTrans::Output: Sink<Vec<u8>, Error = TSinkErr>
+ Stream<Item=Result<BytesMut, TSinkErr>> + Stream<Item=Result<Vec<u8>, TSinkErr>>
+ Unpin, + Unpin,
TSinkErr: fmt::Debug TSinkErr: fmt::Debug
{ {
/// Sends a WebSocket frame to the node. Returns an error if we are not connected to the node. /// 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. /// 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 let NodeSocket::Connected(NodeSocketConnected { pending, .. }) = &mut self.socket {
if pending.len() <= MAX_PENDING { if pending.len() <= MAX_PENDING {
trace!(target: "telemetry", "Adding log entry to queue for {:?}", self.addr); trace!(target: "telemetry", "Adding log entry to queue for {:?}", self.addr);
@@ -203,8 +202,8 @@ fn gen_rand_reconnect_delay() -> Delay {
} }
impl<TTrans: Transport, TSinkErr> NodeSocketConnected<TTrans> impl<TTrans: Transport, TSinkErr> NodeSocketConnected<TTrans>
where TTrans::Output: Sink<BytesMut, Error = TSinkErr> where TTrans::Output: Sink<Vec<u8>, Error = TSinkErr>
+ Stream<Item=Result<BytesMut, TSinkErr>> + Stream<Item=Result<Vec<u8>, TSinkErr>>
+ Unpin + Unpin
{ {
/// Processes the queue of messages for the connected socket. /// Processes the queue of messages for the connected socket.
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
derive_more = "0.99.2" 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" log = "0.4.8"
sp-core = { path= "../../core", version = "2.0.0-rc4"} sp-core = { path= "../../core", version = "2.0.0-rc4"}
sp-inherents = { version = "2.0.0-rc4", path = "../../inherents" } sp-inherents = { version = "2.0.0-rc4", path = "../../inherents" }