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

Apply breaking changes of new libp2p versions #3877

Merged
merged 9 commits into from
Nov 6, 2019
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
482 changes: 174 additions & 308 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ client = { package = "substrate-client", path = "../../core/client" }
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
derive_more = "0.15.0"
futures-preview = "0.3.0-alpha.19"
libp2p = { version = "0.12.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
libp2p = { version = "0.13.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
network = { package = "substrate-network", path = "../../core/network" }
primitives = { package = "substrate-primitives", path = "../primitives" }
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
derive_more = "0.15.0"
libp2p = { version = "0.12.0", default-features = false }
libp2p = { version = "0.13.0", default-features = false }
log = "0.4.8"
primitives = { package = "substrate-primitives", path= "../../primitives" }
inherents = { package = "substrate-inherents", path = "../../inherents" }
Expand Down
2 changes: 1 addition & 1 deletion core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linked_hash_set = "0.1.3"
lru-cache = "0.1.2"
rustc-hex = "2.0.1"
rand = "0.7.2"
libp2p = { version = "0.12.0", default-features = false, features = ["libp2p-websocket"] }
libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-websocket"] }
fork-tree = { path = "../../core/utils/fork-tree" }
consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
client = { package = "substrate-client", path = "../../core/client" }
Expand Down
12 changes: 5 additions & 7 deletions core/network/src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use libp2p::Multiaddr;
use libp2p::core::{ConnectedPoint, either::EitherOutput, PeerId, PublicKey};
use libp2p::swarm::{IntoProtocolsHandler, IntoProtocolsHandlerSelect, ProtocolsHandler};
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p::identify::{Identify, IdentifyEvent, protocol::IdentifyInfo};
use libp2p::identify::{Identify, IdentifyEvent, IdentifyInfo};
use libp2p::ping::{Ping, PingConfig, PingEvent, PingSuccess};
use log::{debug, trace, error};
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -287,16 +287,14 @@ where TSubstream: AsyncRead + AsyncWrite {
Async::NotReady => break,
Async::Ready(NetworkBehaviourAction::GenerateEvent(event)) => {
match event {
IdentifyEvent::Identified { peer_id, info, .. } => {
IdentifyEvent::Received { peer_id, info, .. } => {
self.handle_identify_report(&peer_id, &info);
let event = DebugInfoEvent::Identified { peer_id, info };
return Async::Ready(NetworkBehaviourAction::GenerateEvent(event));
}
IdentifyEvent::Error { .. } => {}
IdentifyEvent::SendBack { result: Err(ref err), ref peer_id } =>
debug!(target: "sub-libp2p", "Error when sending back identify info \
to {:?} => {}", peer_id, err),
IdentifyEvent::SendBack { .. } => {}
IdentifyEvent::Error { peer_id, error } =>
debug!(target: "sub-libp2p", "Identification with peer {:?} failed => {}", peer_id, error),
IdentifyEvent::Sent { .. } => {}
}
},
Async::Ready(NetworkBehaviourAction::DialAddress { address }) =>
Expand Down
14 changes: 11 additions & 3 deletions core/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,24 @@ mod tests {
// Build swarms whose behaviour is `DiscoveryBehaviour`.
let mut swarms = (0..25).map(|_| {
let keypair = Keypair::generate_ed25519();
let keypair2 = keypair.clone();

let transport = MemoryTransport
.with_upgrade(libp2p::secio::SecioConfig::new(keypair.clone()))
.and_then(move |out, endpoint| {
let peer_id = out.remote_key.into_peer_id();
let secio = libp2p::secio::SecioConfig::new(keypair2);
libp2p::core::upgrade::apply(
out,
secio,
endpoint,
libp2p::core::upgrade::Version::V1
)
})
.and_then(move |(peer_id, stream), endpoint| {
let peer_id2 = peer_id.clone();
let upgrade = libp2p::yamux::Config::default()
.map_inbound(move |muxer| (peer_id, muxer))
.map_outbound(move |muxer| (peer_id2, muxer));
upgrade::apply(out.stream, upgrade, endpoint)
upgrade::apply(stream, upgrade, endpoint, libp2p::core::upgrade::Version::V1)
});

let behaviour = DiscoveryBehaviour::new(keypair.public(), user_defined.clone(), false);
Expand Down
21 changes: 17 additions & 4 deletions core/network/src/legacy_proto/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,27 @@ fn build_nodes()
.collect();

for index in 0 .. 2 {
let keypair = keypairs[index].clone();
let transport = libp2p::core::transport::MemoryTransport
.with_upgrade(libp2p::secio::SecioConfig::new(keypairs[index].clone()))
.and_then(move |out, endpoint| {
let peer_id = out.remote_key.into_peer_id();
libp2p::core::upgrade::apply(out.stream, libp2p::yamux::Config::default(), endpoint)
let secio = libp2p::secio::SecioConfig::new(keypair);
libp2p::core::upgrade::apply(
out,
secio,
endpoint,
libp2p::core::upgrade::Version::V1
)
})
.and_then(move |(peer_id, stream), endpoint| {
libp2p::core::upgrade::apply(
stream,
libp2p::yamux::Config::default(),
endpoint,
libp2p::core::upgrade::Version::V1
)
.map(|muxer| (peer_id, libp2p::core::muxing::StreamMuxerBox::new(muxer)))
})
.with_timeout(Duration::from_secs(20))
.timeout(Duration::from_secs(20))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed();

Expand Down
18 changes: 9 additions & 9 deletions core/network/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use libp2p::{
#[cfg(not(target_os = "unknown"))]
use libp2p::{tcp, dns, websocket, noise};
#[cfg(not(target_os = "unknown"))]
use libp2p::core::{upgrade, either::EitherError, either::EitherOutput};
use libp2p::core::{self, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox};
use libp2p::core::{either::EitherError, either::EitherOutput};
use libp2p::core::{self, upgrade, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox};
use std::{io, sync::Arc, time::Duration, usize};

pub use self::bandwidth::BandwidthSinks;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn build_transport(
#[cfg(not(target_os = "unknown"))]
let transport = transport.and_then(move |stream, endpoint| {
let upgrade = core::upgrade::SelectUpgrade::new(noise_config, secio_config);
core::upgrade::apply(stream, upgrade, endpoint)
core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1)
.and_then(|out| match out {
// We negotiated noise
EitherOutput::First((remote_id, out)) => {
Expand All @@ -101,16 +101,16 @@ pub fn build_transport(
Ok((EitherOutput::First(out), remote_key.into_peer_id()))
}
// We negotiated secio
EitherOutput::Second(out) =>
Ok((EitherOutput::Second(out.stream), out.remote_key.into_peer_id()))
EitherOutput::Second((remote_id, out)) =>
Ok((EitherOutput::Second(out), remote_id))
})
});

// For WASM, we only support secio for now.
#[cfg(target_os = "unknown")]
let transport = transport.and_then(move |stream, endpoint| {
core::upgrade::apply(stream, secio_config, endpoint)
.and_then(|out| Ok((out.stream, out.remote_key.into_peer_id())))
core::upgrade::apply(stream, secio_config, endpoint, upgrade::Version::V1)
.and_then(|(id, stream)| Ok((stream, id)))
});

// Multiplexing
Expand All @@ -120,11 +120,11 @@ pub fn build_transport(
.map_inbound(move |muxer| (peer_id, muxer))
.map_outbound(move |muxer| (peer_id2, muxer));

core::upgrade::apply(stream, upgrade, endpoint)
core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1)
.map(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer)))
})

.with_timeout(Duration::from_secs(20))
.timeout(Duration::from_secs(20))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion core/peerset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"

[dependencies]
futures-preview = "0.3.0-alpha.19"
libp2p = { version = "0.12.0", default-features = false }
libp2p = { version = "0.13.0", default-features = false }
linked-hash-map = "0.5.2"
log = "0.4.8"
lru-cache = "0.1.2"
Expand Down
2 changes: 1 addition & 1 deletion core/telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parking_lot = "0.9.0"
futures01 = { package = "futures", version = "0.1" }
futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] }
futures-timer = "0.4.0"
libp2p = { version = "0.12.0", default-features = false, features = ["libp2p-websocket"] }
libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-websocket"] }
log = "0.4.8"
rand = "0.7.2"
serde = { version = "1.0.101", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion core/telemetry/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl TelemetryWorker {

let transport = transport
.map((|inner, _| Compat01As03Sink::new(inner)) as fn(_, _) -> _)
.with_timeout(CONNECT_TIMEOUT);
.timeout(CONNECT_TIMEOUT);

TelemetryWorker {
nodes: endpoints.into_iter().map(|(addr, verbosity)| {
Expand Down
2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ transaction-factory = { path = "../../test-utils/transaction-factory", optional
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }

# WASM-specific dependencies
libp2p = { version = "0.12.0", default-features = false, optional = true }
libp2p = { version = "0.13.0", default-features = false, optional = true }
clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true } # Imported just for the `no_cc` feature
console_error_panic_hook = { version = "0.1.1", optional = true }
console_log = { version = "0.1.2", optional = true }
Expand Down