mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Apply breaking changes of new libp2p versions (#3877)
* Apply breaking changes of new libp2p versions * Oops, forgot to update version * Fix tests * Fix imports with WASM * Fix WASM for real * Update core/network/src/debug_info.rs Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com> * Fix compilation
This commit is contained in:
committed by
Bastian Köcher
parent
1aaf31a34d
commit
cc09bfbd09
@@ -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;
|
||||
@@ -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 }) =>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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)) => {
|
||||
@@ -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
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user