mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 08:37:56 +00:00
Update to libp2p 0.12 (#3408)
This commit is contained in:
committed by
Gavin Wood
parent
6a7a222882
commit
be732a2d68
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
@@ -159,7 +158,7 @@ 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)
|
||||
}
|
||||
|
||||
@@ -167,7 +166,7 @@ impl<TSubstream> DiscoveryBehaviour<TSubstream> {
|
||||
/// `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);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
@@ -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()));
|
||||
@@ -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));
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user