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 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
217 changes: 94 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

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.14.0"
libp2p = { version = "0.11.0", default-features = false }
libp2p = { version = "0.12.0", default-features = false }
log = "0.4"
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.1"
rustc-hex = "2.0"
rand = "0.6"
libp2p = { version = "0.11.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
libp2p = { version = "0.12.0", default-features = false, features = ["secp256k1", "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
6 changes: 3 additions & 3 deletions core/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::protocol::{CustomMessageOutcome, Protocol};
use futures::prelude::*;
use libp2p::NetworkBehaviour;
use libp2p::core::{Multiaddr, PeerId, PublicKey};
use libp2p::kad::record;
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess};
use libp2p::core::{nodes::Substream, muxing::StreamMuxerBox};
use libp2p::multihash::Multihash;
use log::warn;
use sr_primitives::traits::Block as BlockT;
use std::iter;
Expand Down Expand Up @@ -101,12 +101,12 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Behaviour<B, S, H> {
}

/// Start querying a record from the DHT. Will later produce either a `ValueFound` or a `ValueNotFound` event.
pub fn get_value(&mut self, key: &Multihash) {
pub fn get_value(&mut self, key: &record::Key) {
self.discovery.get_value(key);
}

/// Starts putting a record into DHT. Will later produce either a `ValuePut` or a `ValuePutFailed` event.
pub fn put_value(&mut self, key: Multihash, value: Vec<u8>) {
pub fn put_value(&mut self, key: record::Key, value: Vec<u8>) {
self.discovery.put_value(key, value);
}
}
Expand Down
15 changes: 7 additions & 8 deletions core/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ use libp2p::core::{ConnectedPoint, Multiaddr, PeerId, PublicKey};
use libp2p::swarm::{ProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p::kad::{Kademlia, KademliaEvent, Quorum, Record};
use libp2p::kad::GetClosestPeersError;
use libp2p::kad::record::store::MemoryStore;
use libp2p::kad::record::{self, store::MemoryStore};
#[cfg(not(target_os = "unknown"))]
use libp2p::{swarm::toggle::Toggle};
#[cfg(not(target_os = "unknown"))]
use libp2p::core::{nodes::Substream, muxing::StreamMuxerBox};
#[cfg(not(target_os = "unknown"))]
use libp2p::mdns::{Mdns, MdnsEvent};
use libp2p::multihash::Multihash;
use libp2p::multiaddr::Protocol;
use log::{debug, info, trace, warn};
use std::{cmp, collections::VecDeque, time::Duration};
Expand Down Expand Up @@ -159,15 +158,15 @@ impl<TSubstream> DiscoveryBehaviour<TSubstream> {
/// Start fetching a record from the DHT.
///
/// A corresponding `ValueFound` or `ValueNotFound` event will later be generated.
pub fn get_value(&mut self, key: &Multihash) {
pub fn get_value(&mut self, key: &record::Key) {
self.kademlia.get_record(key, Quorum::One)
}

/// Start putting a record into the DHT. Other nodes can later fetch that value with
/// `get_value`.
///
/// A corresponding `ValuePut` or `ValuePutFailed` event will later be generated.
pub fn put_value(&mut self, key: Multihash, value: Vec<u8>) {
pub fn put_value(&mut self, key: record::Key, value: Vec<u8>) {
self.kademlia.put_record(Record::new(key, value), Quorum::All);
}
}
Expand All @@ -187,16 +186,16 @@ pub enum DiscoveryOut {
UnroutablePeer(PeerId),

/// The DHT yeided results for the record request, grouped in (key, value) pairs.
ValueFound(Vec<(Multihash, Vec<u8>)>),
ValueFound(Vec<(record::Key, Vec<u8>)>),

/// The record requested was not found in the DHT.
ValueNotFound(Multihash),
ValueNotFound(record::Key),

/// The record with a given key was successfully inserted into the DHT.
ValuePut(Multihash),
ValuePut(record::Key),

/// Inserting a value into the DHT failed.
ValuePutFailed(Multihash),
ValuePutFailed(record::Key),
}

impl<TSubstream> NetworkBehaviour for DiscoveryBehaviour<TSubstream>
Expand Down
8 changes: 4 additions & 4 deletions core/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ pub enum NetworkStatePeerEndpoint {
Dialing(Multiaddr),
/// We are listening.
Listening {
/// Address we're listening on that received the connection.
listen_addr: Multiaddr,
/// Local address of the connection.
local_addr: Multiaddr,
/// Address data is sent back to.
send_back_addr: Multiaddr,
},
Expand All @@ -298,9 +298,9 @@ impl From<ConnectedPoint> for NetworkStatePeerEndpoint {
match endpoint {
ConnectedPoint::Dialer { address } =>
NetworkStatePeerEndpoint::Dialing(address),
ConnectedPoint::Listener { listen_addr, send_back_addr } =>
ConnectedPoint::Listener { local_addr, send_back_addr } =>
NetworkStatePeerEndpoint::Listening {
listen_addr,
local_addr,
send_back_addr
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/network/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
//! Network event types. These are are not the part of the protocol, but rather
//! events that happen on the network like DHT get/put results received.

use libp2p::multihash::Multihash;
use libp2p::kad::record::Key;

/// Events generated by DHT as a response to get_value and put_value requests.
pub enum DhtEvent {
/// The value was found.
ValueFound(Vec<(Multihash, Vec<u8>)>),
ValueFound(Vec<(Key, Vec<u8>)>),

/// The requested record has not been found in the DHT.
ValueNotFound(Multihash),
ValueNotFound(Key),

/// The record has been successfully inserted into the DHT.
ValuePut(Multihash),
ValuePut(Key),

/// An error has occured while putting a record into the DHT.
ValuePutFailed(Multihash),
ValuePutFailed(Key),
}

/// Type for events generated by networking layer.
Expand Down
10 changes: 5 additions & 5 deletions core/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use consensus::import_queue::{BlockImportResult, BlockImportError};
use futures::{prelude::*, sync::mpsc};
use futures03::TryFutureExt as _;
use log::{warn, error, info};
use libp2p::{PeerId, Multiaddr, multihash::Multihash};
use libp2p::{PeerId, Multiaddr, kad::record};
use libp2p::core::{transport::boxed::Boxed, muxing::StreamMuxerBox};
use libp2p::swarm::NetworkBehaviour;
use parking_lot::Mutex;
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
///
/// This will generate either a `ValueFound` or a `ValueNotFound` event and pass it to
/// `on_event` on the network specialization.
pub fn get_value(&self, key: &Multihash) {
pub fn get_value(&self, key: &record::Key) {
let _ = self
.to_worker
.unbounded_send(ServerToWorkerMsg::GetValue(key.clone()));
Expand All @@ -466,7 +466,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
///
/// This will generate either a `ValuePut` or a `ValuePutFailed` event and pass it to
/// `on_event` on the network specialization.
pub fn put_value(&self, key: Multihash, value: Vec<u8>) {
pub fn put_value(&self, key: record::Key, value: Vec<u8>) {
let _ = self
.to_worker
.unbounded_send(ServerToWorkerMsg::PutValue(key, value));
Expand Down Expand Up @@ -584,8 +584,8 @@ enum ServerToWorkerMsg<B: BlockT, S: NetworkSpecialization<B>> {
ExecuteWithSpec(Box<dyn FnOnce(&mut S, &mut dyn Context<B>) + Send>),
ExecuteWithGossip(Box<dyn FnOnce(&mut ConsensusGossip<B>, &mut dyn Context<B>) + Send>),
GossipConsensusMessage(B::Hash, ConsensusEngineId, Vec<u8>, GossipMessageRecipient),
GetValue(Multihash),
PutValue(Multihash, Vec<u8>),
GetValue(record::Key),
PutValue(record::Key, Vec<u8>),
AddKnownAddress(PeerId, Multiaddr),
}

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.17"
libp2p = { version = "0.11.0", default-features = false }
libp2p = { version = "0.12.0", default-features = false }
linked-hash-map = "0.5"
log = "0.4"
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.17", features = ["compat"] }
futures-timer = "0.2.1"
libp2p = { version = "0.11.0", default-features = false, features = ["libp2p-websocket"] }
libp2p = { version = "0.12.0", default-features = false, features = ["libp2p-websocket"] }
log = "0.4"
rand = "0.6"
serde = { version = "1.0.81", features = ["derive"] }
Expand Down