mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-27 21:01:04 +00:00
Update to libp2p v0.7.0 (#2343)
* Update to libp2p master * Fix tests * More tests fixing
This commit is contained in:
committed by
Gavin Wood
parent
e2bb429711
commit
3f06fe32f3
@@ -24,8 +24,9 @@ use libp2p::core::swarm::toggle::Toggle;
|
||||
use libp2p::identify::{Identify, IdentifyEvent, protocol::IdentifyInfo};
|
||||
use libp2p::kad::{Kademlia, KademliaOut};
|
||||
use libp2p::mdns::{Mdns, MdnsEvent};
|
||||
use libp2p::ping::{Ping, PingEvent};
|
||||
use log::{debug, trace, warn};
|
||||
use libp2p::multiaddr::Protocol;
|
||||
use libp2p::ping::{Ping, PingConfig, PingEvent, PingSuccess};
|
||||
use log::{debug, info, trace, warn};
|
||||
use std::{cmp, io, fmt, time::Duration};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::{Delay, clock::Clock};
|
||||
@@ -68,14 +69,14 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
|
||||
|
||||
let custom_protocols = CustomProto::new(protocol, peerset);
|
||||
|
||||
let mut kademlia = Kademlia::new(local_public_key.into_peer_id());
|
||||
let mut kademlia = Kademlia::new(local_public_key.clone().into_peer_id());
|
||||
for (peer_id, addr) in &known_addresses {
|
||||
kademlia.add_connected_address(peer_id, addr.clone());
|
||||
}
|
||||
|
||||
let clock = Clock::new();
|
||||
Behaviour {
|
||||
ping: Ping::new(),
|
||||
ping: Ping::new(PingConfig::new()),
|
||||
custom_protocols,
|
||||
discovery: DiscoveryBehaviour {
|
||||
user_defined: known_addresses,
|
||||
@@ -83,6 +84,7 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
|
||||
next_kad_random_query: Delay::new(clock.now()),
|
||||
duration_to_next_kad: Duration::from_secs(1),
|
||||
clock,
|
||||
local_peer_id: local_public_key.into_peer_id(),
|
||||
},
|
||||
identify,
|
||||
mdns: if enable_mdns {
|
||||
@@ -293,10 +295,11 @@ impl<TMessage, TSubstream> NetworkBehaviourEventProcess<KademliaOut> for Behavio
|
||||
impl<TMessage, TSubstream> NetworkBehaviourEventProcess<PingEvent> for Behaviour<TMessage, TSubstream> {
|
||||
fn inject_event(&mut self, event: PingEvent) {
|
||||
match event {
|
||||
PingEvent::PingSuccess { peer, time } => {
|
||||
trace!(target: "sub-libp2p", "Ping time with {:?}: {:?}", peer, time);
|
||||
self.events.push(BehaviourOut::PingSuccess { peer_id: peer, ping_time: time });
|
||||
PingEvent { peer, result: Ok(PingSuccess::Ping { rtt }) } => {
|
||||
trace!(target: "sub-libp2p", "Ping time with {:?}: {:?}", peer, rtt);
|
||||
self.events.push(BehaviourOut::PingSuccess { peer_id: peer, ping_time: rtt });
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,6 +338,8 @@ pub struct DiscoveryBehaviour<TSubstream> {
|
||||
duration_to_next_kad: Duration,
|
||||
/// `Clock` instance that uses the current execution context's source of time.
|
||||
clock: Clock,
|
||||
/// Identity of our local node.
|
||||
local_peer_id: PeerId,
|
||||
}
|
||||
|
||||
impl<TSubstream> NetworkBehaviour for DiscoveryBehaviour<TSubstream>
|
||||
@@ -386,6 +391,16 @@ where
|
||||
NetworkBehaviour::inject_node_event(&mut self.kademlia, peer_id, event)
|
||||
}
|
||||
|
||||
fn inject_new_external_addr(&mut self, addr: &Multiaddr) {
|
||||
let new_addr = addr.clone()
|
||||
.with(Protocol::P2p(self.local_peer_id.clone().into()));
|
||||
info!(target: "sub-libp2p", "Discovered external node address: {}", new_addr);
|
||||
}
|
||||
|
||||
fn inject_expired_listen_addr(&mut self, addr: &Multiaddr) {
|
||||
info!(target: "sub-libp2p", "No longer listening on {}", addr);
|
||||
}
|
||||
|
||||
fn poll(
|
||||
&mut self,
|
||||
params: &mut PollParameters,
|
||||
|
||||
Reference in New Issue
Block a user