Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 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
471 changes: 413 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

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.18.0", default-features = false }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false }
jsonrpc-core = "14.0.5"
serde = "1.0.106"
serde_json = "1.0.48"
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.18.1", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-dev"}
prost = "0.6.1"
Expand Down
5 changes: 4 additions & 1 deletion client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -123,6 +123,9 @@ impl NetworkParams {

let listen_addresses = if self.listen_addr.is_empty() {
vec![
Multiaddr::empty()
.with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into()))
.with(Protocol::Tcp(port)),
Multiaddr::empty()
.with(Protocol::Ip4([0, 0, 0, 0].into()))
.with(Protocol::Tcp(port)),
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.18.1", default-features = false, features = ["websocket"] }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false, features = ["websocket"] }
log = "0.4.8"
lru = "0.4.3"
sc-network = { version = "0.8.0-dev", path = "../network" }
Expand Down
7 changes: 4 additions & 3 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ prost-build = "0.6.1"

[dependencies]
bitflags = "1.2.0"
bs58 = "0.3.1"
bytes = "0.5.0"
codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] }
derive_more = "0.99.2"
Expand Down Expand Up @@ -62,15 +63,15 @@ wasm-timer = "0.2"
zeroize = "1.0.0"

[dependencies.libp2p]
version = "0.18.1"
git = "https://github.com/libp2p/rust-libp2p"
default-features = false
features = ["websocket", "kad", "mdns", "ping", "identify", "mplex", "yamux", "noise"]
features = ["websocket", "kad", "mdns", "ping", "identify", "mplex", "yamux", "noise", "tcp-async-std"]

[dev-dependencies]
async-std = "1.5"
assert_matches = "1.3"
env_logger = "0.7.0"
libp2p = { version = "0.18.1", default-features = false, features = ["secio"] }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false, features = ["secio"] }
quickcheck = "0.9.0"
rand = "0.7.2"
sp-keyring = { version = "2.0.0-dev", path = "../../primitives/keyring" }
Expand Down
35 changes: 18 additions & 17 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use ip_network::IpNetwork;
use libp2p::core::{connection::{ConnectionId, ListenerId}, ConnectedPoint, Multiaddr, PeerId, PublicKey};
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters, ProtocolsHandler};
use libp2p::swarm::protocols_handler::multi::MultiHandler;
use libp2p::kad::{Kademlia, KademliaConfig, KademliaEvent, Quorum, Record};
use libp2p::kad::{Kademlia, KademliaConfig, KademliaEvent, QueryResult, Quorum, Record};
use libp2p::kad::GetClosestPeersError;
use libp2p::kad::handler::KademliaHandler;
use libp2p::kad::QueryId;
Expand Down Expand Up @@ -177,7 +177,7 @@ impl DiscoveryConfig {
kademlias: self.kademlias,
next_kad_random_query: Delay::new(Duration::new(0, 0)),
duration_to_next_kad: Duration::from_secs(1),
discoveries: VecDeque::new(),
pending_events: VecDeque::new(),
local_peer_id: self.local_peer_id,
num_connections: 0,
allow_private_ipv4: self.allow_private_ipv4,
Expand Down Expand Up @@ -213,8 +213,8 @@ pub struct DiscoveryBehaviour {
next_kad_random_query: Delay,
/// After `next_kad_random_query` triggers, the next one triggers after this duration.
duration_to_next_kad: Duration,
/// Discovered nodes to return.
discoveries: VecDeque<PeerId>,
/// Events to return in priority when polled.
pending_events: VecDeque<DiscoveryOut>,
/// Identity of our local node.
local_peer_id: PeerId,
/// Number of nodes we're currently connected to.
Expand Down Expand Up @@ -248,7 +248,7 @@ impl DiscoveryBehaviour {
for k in self.kademlias.values_mut() {
k.add_address(&peer_id, addr.clone())
}
self.discoveries.push_back(peer_id.clone());
self.pending_events.push_back(DiscoveryOut::Discovered(peer_id.clone()));
self.user_defined.push((peer_id, addr));
}
}
Expand All @@ -272,7 +272,7 @@ impl DiscoveryBehaviour {
/// A corresponding `ValueFound` or `ValueNotFound` event will later be generated.
pub fn get_value(&mut self, key: &record::Key) {
for k in self.kademlias.values_mut() {
k.get_record(key, Quorum::One)
k.get_record(key, Quorum::One);
}
}

Expand All @@ -282,7 +282,10 @@ impl DiscoveryBehaviour {
/// A corresponding `ValuePut` or `ValuePutFailed` event will later be generated.
pub fn put_value(&mut self, key: record::Key, value: Vec<u8>) {
for k in self.kademlias.values_mut() {
k.put_record(Record::new(key.clone(), value.clone()), Quorum::All)
if let Err(e) = k.put_record(Record::new(key.clone(), value.clone()), Quorum::All) {
warn!(target: "sub-libp2p", "Libp2p => Failed to put record: {:?}", e);
self.pending_events.push_back(DiscoveryOut::ValuePutFailed(key.clone()));
}
}
}

Expand Down Expand Up @@ -528,8 +531,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
>,
> {
// Immediately process the content of `discovered`.
if let Some(peer_id) = self.discoveries.pop_front() {
let ev = DiscoveryOut::Discovered(peer_id);
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}

Expand All @@ -541,7 +543,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
"Libp2p <= Starting random Kademlia request for {:?}",
random_peer_id);
for k in self.kademlias.values_mut() {
k.get_closest_peers(random_peer_id.clone())
k.get_closest_peers(random_peer_id.clone());
}
true
} else {
Expand Down Expand Up @@ -578,7 +580,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
let ev = DiscoveryOut::Discovered(peer);
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::GetClosestPeersResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::GetClosestPeers(res), .. } => {
match res {
Err(GetClosestPeersError::Timeout { key, peers }) => {
debug!(target: "sub-libp2p",
Expand All @@ -596,7 +598,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
}
}
KademliaEvent::GetRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::GetRecord(res), .. } => {
let ev = match res {
Ok(ok) => {
let results = ok.records
Expand All @@ -619,7 +621,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::PutRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::PutRecord(res), .. } => {
let ev = match res {
Ok(ok) => DiscoveryOut::ValuePut(ok.key),
Err(e) => {
Expand All @@ -630,7 +632,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::RepublishRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::RepublishRecord(res), .. } => {
match res {
Ok(ok) => debug!(target: "sub-libp2p",
"Libp2p => Record republished: {:?}",
Expand Down Expand Up @@ -675,9 +677,8 @@ impl NetworkBehaviour for DiscoveryBehaviour {
continue;
}

self.discoveries.extend(list.map(|(peer_id, _)| peer_id));
if let Some(peer_id) = self.discoveries.pop_front() {
let ev = DiscoveryOut::Discovered(peer_id);
self.pending_events.extend(list.map(|(peer_id, _)| DiscoveryOut::Discovered(peer_id)));
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
},
Expand Down
17 changes: 13 additions & 4 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -59,10 +59,11 @@ use sp_runtime::{
};
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use std::{
borrow::Cow,
borrow::{Borrow, Cow},
collections::HashSet,
fs, io,
marker::PhantomData,
num:: NonZeroUsize,
pin::Pin,
str,
sync::{
Expand Down Expand Up @@ -185,7 +186,13 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let local_identity = params.network_config.node_key.clone().into_keypair()?;
let local_public = local_identity.public();
let local_peer_id = local_public.clone().into_peer_id();
info!(target: "sub-libp2p", "🏷 Local node identity is: {}", local_peer_id.to_base58());
let local_peer_id_legacy = bs58::encode(Borrow::<[u8]>::borrow(&local_peer_id)).into_string();
info!(
target: "sub-libp2p",
"🏷 Local node identity is: {} (legacy representation: {})",
local_peer_id.to_base58(),
local_peer_id_legacy
);

// Initialize the metrics.
let metrics = match &params.metrics_registry {
Expand Down Expand Up @@ -286,7 +293,9 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
transport::build_transport(local_identity, config_mem, config_wasm, flowctrl)
};
let mut builder = SwarmBuilder::new(transport, behaviour, local_peer_id.clone())
.peer_connection_limit(crate::MAX_CONNECTIONS_PER_PEER);
.peer_connection_limit(crate::MAX_CONNECTIONS_PER_PEER)
.notify_handler_buffer_size(NonZeroUsize::new(16).expect("16 != 0; qed"))
.connection_event_buffer_size(128);
if let Some(spawner) = params.executor {
struct SpawnImpl<F>(F);
impl<F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>)> Executor for SpawnImpl<F> {
Expand Down
39 changes: 29 additions & 10 deletions client/network/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
Expand All @@ -22,7 +22,7 @@ use libp2p::{
};
#[cfg(not(target_os = "unknown"))]
use libp2p::{tcp, dns, websocket};
use libp2p::core::{self, upgrade, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox};
use libp2p::core::{self, either::{EitherError, EitherOutput}, upgrade, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox};
use std::{io, sync::Arc, time::Duration, usize};

pub use self::bandwidth::BandwidthSinks;
Expand All @@ -42,14 +42,22 @@ pub fn build_transport(
) -> (Boxed<(PeerId, StreamMuxerBox), io::Error>, Arc<bandwidth::BandwidthSinks>) {
// Build configuration objects for encryption mechanisms.
let noise_config = {
let noise_keypair = noise::Keypair::new().into_authentic(&keypair)
// For more information about this panic, see in "On the Importance of Checking
// Cryptographic Protocols for Faults" by Dan Boneh, Richard A. DeMillo,
// and Richard J. Lipton.
// For more information about these two panics, see in "On the Importance of
// Checking Cryptographic Protocols for Faults" by Dan Boneh, Richard A. DeMillo,
// and Richard J. Lipton.
let noise_keypair_legacy = noise::Keypair::<noise::X25519>::new().into_authentic(&keypair)
.expect("can only fail in case of a hardware bug; since this signing is performed only \
once and at initialization, we're taking the bet that the inconvenience of a very \
rare panic here is basically zero");
noise::NoiseConfig::ix(noise_keypair)
let noise_keypair_spec = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&keypair)
.expect("can only fail in case of a hardware bug; since this signing is performed only \
once and at initialization, we're taking the bet that the inconvenience of a very \
rare panic here is basically zero");

core::upgrade::SelectUpgrade::new(
noise::NoiseConfig::xx(noise_keypair_spec),
noise::NoiseConfig::ix(noise_keypair_legacy)
)
};

// Build configuration objects for multiplexing mechanisms.
Expand Down Expand Up @@ -97,11 +105,22 @@ pub fn build_transport(
// Encryption
let transport = transport.and_then(move |stream, endpoint| {
core::upgrade::apply(stream, noise_config, endpoint, upgrade::Version::V1)
.and_then(|(remote_id, out)| async move {
let remote_key = match remote_id {
noise::RemoteIdentity::IdentityKey(key) => key,
.map_err(|err|
err.map_err(|err| match err {
EitherError::A(err) => err,
EitherError::B(err) => err,
})
)
.and_then(|result| async move {
let remote_key = match &result {
EitherOutput::First((noise::RemoteIdentity::IdentityKey(key), _)) => key.clone(),
EitherOutput::Second((noise::RemoteIdentity::IdentityKey(key), _)) => key.clone(),
_ => return Err(upgrade::UpgradeError::Apply(noise::NoiseError::InvalidKey))
};
let out = match result {
EitherOutput::First((_, o)) => o,
EitherOutput::Second((_, o)) => o,
};
Ok((out, remote_key.into_peer_id()))
})
});
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.18.1", default-features = false, features = ["libp2p-websocket"] }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false, features = ["libp2p-websocket"] }
sp-consensus = { version = "0.8.0-dev", path = "../../../primitives/consensus/common" }
sc-consensus = { version = "0.8.0-dev", path = "../../../client/consensus/common" }
sc-client-api = { version = "2.0.0-dev", 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.18.1", default-features = false }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false }
sp-utils = { version = "2.0.0-dev", path = "../../primitives/utils"}
log = "0.4.8"
serde_json = "1.0.41"
Expand Down
2 changes: 1 addition & 1 deletion client/telemetry/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"
wasm-timer = "0.2.0"
libp2p = { version = "0.18.1", default-features = false, features = ["websocket", "wasm-ext", "tcp", "dns"] }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false, features = ["websocket", "wasm-ext", "tcp-async-std", "dns"] }
log = "0.4.8"
pin-project = "0.4.6"
rand = "0.7.2"
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.18.1", default-features = false }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", default-features = false }
log = "0.4.8"
sp-core = { path= "../../core", version = "2.0.0-dev"}
sp-inherents = { version = "2.0.0-dev", path = "../../inherents" }
Expand Down
2 changes: 1 addition & 1 deletion utils/browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
futures = { version = "0.3", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
log = "0.4.8"
libp2p-wasm-ext = { version = "0.18.0", features = ["websocket"] }
libp2p-wasm-ext = { git = "https://github.com/libp2p/rust-libp2p", features = ["websocket"] }
console_error_panic_hook = "0.1.6"
console_log = "0.1.2"
js-sys = "0.3.34"
Expand Down