diff --git a/examples/ipfs-private.rs b/examples/ipfs-private.rs index f3c7afd496c..bd90f5975a9 100644 --- a/examples/ipfs-private.rs +++ b/examples/ipfs-private.rs @@ -41,8 +41,7 @@ use libp2p::{ identify::{Identify, IdentifyConfig, IdentifyEvent}, identity, multiaddr::Protocol, - noise, - ping::{self, Ping, PingConfig, PingEvent}, + noise, ping, pnet::{PnetConfig, PreSharedKey}, swarm::{NetworkBehaviourEventProcess, SwarmEvent}, tcp::TcpConfig, @@ -167,7 +166,7 @@ fn main() -> Result<(), Box> { struct MyBehaviour { gossipsub: Gossipsub, identify: Identify, - ping: Ping, + ping: ping::Behaviour, } impl NetworkBehaviourEventProcess for MyBehaviour { @@ -196,14 +195,13 @@ fn main() -> Result<(), Box> { } } - impl NetworkBehaviourEventProcess for MyBehaviour { + impl NetworkBehaviourEventProcess for MyBehaviour { // Called when `ping` produces an event. - fn inject_event(&mut self, event: PingEvent) { - use ping::handler::{PingFailure, PingSuccess}; + fn inject_event(&mut self, event: ping::Event) { match event { - PingEvent { + ping::Event { peer, - result: Result::Ok(PingSuccess::Ping { rtt }), + result: Result::Ok(ping::Success::Ping { rtt }), } => { println!( "ping: rtt to {} is {} ms", @@ -211,29 +209,29 @@ fn main() -> Result<(), Box> { rtt.as_millis() ); } - PingEvent { + ping::Event { peer, - result: Result::Ok(PingSuccess::Pong), + result: Result::Ok(ping::Success::Pong), } => { println!("ping: pong from {}", peer.to_base58()); } - PingEvent { + ping::Event { peer, - result: Result::Err(PingFailure::Timeout), + result: Result::Err(ping::Failure::Timeout), } => { println!("ping: timeout to {}", peer.to_base58()); } - PingEvent { + ping::Event { peer, - result: Result::Err(PingFailure::Unsupported), + result: Result::Err(ping::Failure::Unsupported), } => { println!("ping: {} does not support ping protocol", peer.to_base58()); } - PingEvent { + ping::Event { peer, - result: Result::Err(PingFailure::Other { error }), + result: Result::Err(ping::Failure::Other { error }), } => { - println!("ping: failure with {}: {}", peer.to_base58(), error); + println!("ping: ping::Failure with {}: {}", peer.to_base58(), error); } } } @@ -255,7 +253,7 @@ fn main() -> Result<(), Box> { "/ipfs/0.1.0".into(), local_key.public(), )), - ping: Ping::new(PingConfig::new()), + ping: ping::Behaviour::new(ping::Config::new()), }; println!("Subscribing to {:?}", gossipsub_topic); diff --git a/examples/ping.rs b/examples/ping.rs index f38b4fc4011..ef5f538ed9d 100644 --- a/examples/ping.rs +++ b/examples/ping.rs @@ -42,9 +42,8 @@ use futures::executor::block_on; use futures::prelude::*; -use libp2p::ping::{Ping, PingConfig}; use libp2p::swarm::{Swarm, SwarmEvent}; -use libp2p::{identity, PeerId}; +use libp2p::{identity, ping, PeerId}; use std::error::Error; use std::task::Poll; @@ -60,7 +59,7 @@ fn main() -> Result<(), Box> { // For illustrative purposes, the ping protocol is configured to // keep the connection alive, so a continuous sequence of pings // can be observed. - let behaviour = Ping::new(PingConfig::new().with_keep_alive(true)); + let behaviour = ping::Behaviour::new(ping::Config::new().with_keep_alive(true)); let mut swarm = Swarm::new(transport, behaviour, local_peer_id); diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index 9959542845a..e4de6070fc3 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -18,6 +18,14 @@ [PR 2149]: https://github.com/libp2p/rust-libp2p/pull/2149/ +- Rename types as per [discussion 2174]. + `Ping` has been renamed to `Behaviour`. + The `Ping` prefix has been removed from various types like `PingEvent`. + Users should prefer importing the ping protocol as a module (`use libp2p::ping;`), + and refer to its types via `ping::`. For example: `ping::Behaviour` or `ping::Event`. + + [discussion 2174]: https://github.com/libp2p/rust-libp2p/discussions/2174 + # 0.30.0 [2021-07-12] - Update dependencies. diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 1c4233e2b22..435a5048485 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -39,7 +39,7 @@ use wasm_timer::Delay; /// The configuration for outbound pings. #[derive(Clone, Debug)] -pub struct PingConfig { +pub struct Config { /// The timeout of an outbound ping. timeout: Duration, /// The duration between the last successful outbound or inbound ping @@ -54,13 +54,13 @@ pub struct PingConfig { keep_alive: bool, } -impl PingConfig { +impl Config { /// Creates a new `PingConfig` with the following default settings: /// - /// * [`PingConfig::with_interval`] 15s - /// * [`PingConfig::with_timeout`] 20s - /// * [`PingConfig::with_max_failures`] 1 - /// * [`PingConfig::with_keep_alive`] false + /// * [`Config::with_interval`] 15s + /// * [`Config::with_timeout`] 20s + /// * [`Config::with_max_failures`] 1 + /// * [`Config::with_keep_alive`] false /// /// These settings have the following effect: /// @@ -116,12 +116,9 @@ impl PingConfig { } } -/// The result of an inbound or outbound ping. -pub type PingResult = Result; - /// The successful result of processing an inbound or outbound ping. #[derive(Debug)] -pub enum PingSuccess { +pub enum Success { /// Received a ping and sent back a pong. Pong, /// Sent a ping and received back a pong. @@ -132,7 +129,7 @@ pub enum PingSuccess { /// An outbound ping failure. #[derive(Debug)] -pub enum PingFailure { +pub enum Failure { /// The ping timed out, i.e. no response was received within the /// configured ping timeout. Timeout, @@ -144,22 +141,22 @@ pub enum PingFailure { }, } -impl fmt::Display for PingFailure { +impl fmt::Display for Failure { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - PingFailure::Timeout => f.write_str("Ping timeout"), - PingFailure::Other { error } => write!(f, "Ping error: {}", error), - PingFailure::Unsupported => write!(f, "Ping protocol not supported"), + Failure::Timeout => f.write_str("Ping timeout"), + Failure::Other { error } => write!(f, "Ping error: {}", error), + Failure::Unsupported => write!(f, "Ping protocol not supported"), } } } -impl Error for PingFailure { +impl Error for Failure { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - PingFailure::Timeout => None, - PingFailure::Other { error } => Some(&**error), - PingFailure::Unsupported => None, + Failure::Timeout => None, + Failure::Other { error } => Some(&**error), + Failure::Unsupported => None, } } } @@ -168,14 +165,14 @@ impl Error for PingFailure { /// and answering ping queries. /// /// If the remote doesn't respond, produces an error that closes the connection. -pub struct PingHandler { +pub struct Handler { /// Configuration options. - config: PingConfig, + config: Config, /// The timer used for the delay to the next ping as well as /// the ping timeout. timer: Delay, /// Outbound ping failures that are pending to be processed by `poll()`. - pending_errors: VecDeque, + pending_errors: VecDeque, /// The number of consecutive ping failures that occurred. /// /// Each successful ping resets this counter to 0. @@ -203,10 +200,10 @@ enum State { Active, } -impl PingHandler { +impl Handler { /// Builds a new `PingHandler` with the given configuration. - pub fn new(config: PingConfig) -> Self { - PingHandler { + pub fn new(config: Config) -> Self { + Handler { config, timer: Delay::new(Duration::new(0, 0)), pending_errors: VecDeque::with_capacity(2), @@ -218,10 +215,10 @@ impl PingHandler { } } -impl ProtocolsHandler for PingHandler { +impl ProtocolsHandler for Handler { type InEvent = Void; - type OutEvent = PingResult; - type Error = PingFailure; + type OutEvent = crate::Result; + type Error = Failure; type InboundProtocol = protocol::Ping; type OutboundProtocol = protocol::Ping; type OutboundOpenInfo = (); @@ -253,8 +250,8 @@ impl ProtocolsHandler for PingHandler { return; } // Note: This timeout only covers protocol negotiation. - ProtocolsHandlerUpgrErr::Timeout => PingFailure::Timeout, - e => PingFailure::Other { error: Box::new(e) }, + ProtocolsHandlerUpgrErr::Timeout => Failure::Timeout, + e => Failure::Other { error: Box::new(e) }, }; self.pending_errors.push_front(error); @@ -271,14 +268,14 @@ impl ProtocolsHandler for PingHandler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll> { + ) -> Poll> { match self.state { State::Inactive { reported: true } => { return Poll::Pending; // nothing to do on this connection } State::Inactive { reported: false } => { self.state = State::Inactive { reported: true }; - return Poll::Ready(ProtocolsHandlerEvent::Custom(Err(PingFailure::Unsupported))); + return Poll::Ready(ProtocolsHandlerEvent::Custom(Err(Failure::Unsupported))); } State::Active => {} } @@ -294,7 +291,7 @@ impl ProtocolsHandler for PingHandler { Poll::Ready(Ok(stream)) => { // A ping from a remote peer has been answered, wait for the next. self.inbound = Some(protocol::recv_ping(stream).boxed()); - return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(PingSuccess::Pong))); + return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(Success::Pong))); } } } @@ -328,7 +325,7 @@ impl ProtocolsHandler for PingHandler { Some(PingState::Ping(mut ping)) => match ping.poll_unpin(cx) { Poll::Pending => { if self.timer.poll_unpin(cx).is_ready() { - self.pending_errors.push_front(PingFailure::Timeout); + self.pending_errors.push_front(Failure::Timeout); } else { self.outbound = Some(PingState::Ping(ping)); break; @@ -338,13 +335,13 @@ impl ProtocolsHandler for PingHandler { self.failures = 0; self.timer.reset(self.config.interval); self.outbound = Some(PingState::Idle(stream)); - return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(PingSuccess::Ping { + return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(Success::Ping { rtt, }))); } Poll::Ready(Err(e)) => { self.pending_errors - .push_front(PingFailure::Other { error: Box::new(e) }); + .push_front(Failure::Other { error: Box::new(e) }); } }, Some(PingState::Idle(stream)) => match self.timer.poll_unpin(cx) { @@ -357,7 +354,7 @@ impl ProtocolsHandler for PingHandler { self.outbound = Some(PingState::Ping(protocol::send_ping(stream).boxed())); } Poll::Ready(Err(e)) => { - return Poll::Ready(ProtocolsHandlerEvent::Close(PingFailure::Other { + return Poll::Ready(ProtocolsHandlerEvent::Close(Failure::Other { error: Box::new(e), })) } diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index 70345dd0472..e0c6bdf1103 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -40,62 +40,78 @@ //! [`Swarm`]: libp2p_swarm::Swarm //! [`Transport`]: libp2p_core::Transport -pub mod handler; -pub mod protocol; - -use handler::PingHandler; -pub use handler::{PingConfig, PingFailure, PingResult, PingSuccess}; +mod handler; +mod protocol; +use handler::Handler; +pub use handler::{Config, Failure, Success}; use libp2p_core::{connection::ConnectionId, PeerId}; use libp2p_swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters}; -use std::{collections::VecDeque, task::Context, task::Poll}; +use std::{ + collections::VecDeque, + task::{Context, Poll}, +}; + +#[deprecated( + since = "0.30.0", + note = "Use re-exports that omit `Ping` prefix, i.e. `libp2p::ping::Config` etc" +)] +pub use self::{ + Config as PingConfig, Event as PingEvent, Failure as PingFailure, Result as PingResult, + Success as PingSuccess, +}; +#[deprecated(since = "0.30.0", note = "Use libp2p::ping::Behaviour instead.")] +pub use Behaviour as Ping; + +/// The result of an inbound or outbound ping. +pub type Result = std::result::Result; -/// `Ping` is a [`NetworkBehaviour`] that responds to inbound pings and +/// A [`NetworkBehaviour`] that responds to inbound pings and /// periodically sends outbound pings on every established connection. /// /// See the crate root documentation for more information. -pub struct Ping { +pub struct Behaviour { /// Configuration for outbound pings. - config: PingConfig, + config: Config, /// Queue of events to yield to the swarm. - events: VecDeque, + events: VecDeque, } /// Event generated by the `Ping` network behaviour. #[derive(Debug)] -pub struct PingEvent { +pub struct Event { /// The peer ID of the remote. pub peer: PeerId, /// The result of an inbound or outbound ping. - pub result: PingResult, + pub result: Result, } -impl Ping { +impl Behaviour { /// Creates a new `Ping` network behaviour with the given configuration. - pub fn new(config: PingConfig) -> Self { - Ping { + pub fn new(config: Config) -> Self { + Self { config, events: VecDeque::new(), } } } -impl Default for Ping { +impl Default for Behaviour { fn default() -> Self { - Ping::new(PingConfig::new()) + Self::new(Config::new()) } } -impl NetworkBehaviour for Ping { - type ProtocolsHandler = PingHandler; - type OutEvent = PingEvent; +impl NetworkBehaviour for Behaviour { + type ProtocolsHandler = Handler; + type OutEvent = Event; fn new_handler(&mut self) -> Self::ProtocolsHandler { - PingHandler::new(self.config.clone()) + Handler::new(self.config.clone()) } - fn inject_event(&mut self, peer: PeerId, _: ConnectionId, result: PingResult) { - self.events.push_front(PingEvent { peer, result }) + fn inject_event(&mut self, peer: PeerId, _: ConnectionId, result: Result) { + self.events.push_front(Event { peer, result }) } fn poll( diff --git a/protocols/ping/tests/ping.rs b/protocols/ping/tests/ping.rs index 3f10ace782b..e0d876bf512 100644 --- a/protocols/ping/tests/ping.rs +++ b/protocols/ping/tests/ping.rs @@ -29,7 +29,7 @@ use libp2p_core::{ }; use libp2p_mplex as mplex; use libp2p_noise as noise; -use libp2p_ping::*; +use libp2p_ping as ping; use libp2p_swarm::{DummyBehaviour, KeepAlive, Swarm, SwarmEvent}; use libp2p_tcp::TcpConfig; use libp2p_yamux as yamux; @@ -40,15 +40,15 @@ use std::{num::NonZeroU8, time::Duration}; #[test] fn ping_pong() { fn prop(count: NonZeroU8, muxer: MuxerChoice) { - let cfg = PingConfig::new() + let cfg = ping::Config::new() .with_keep_alive(true) .with_interval(Duration::from_millis(10)); let (peer1_id, trans) = mk_transport(muxer); - let mut swarm1 = Swarm::new(trans, Ping::new(cfg.clone()), peer1_id.clone()); + let mut swarm1 = Swarm::new(trans, ping::Behaviour::new(cfg.clone()), peer1_id.clone()); let (peer2_id, trans) = mk_transport(muxer); - let mut swarm2 = Swarm::new(trans, Ping::new(cfg), peer2_id.clone()); + let mut swarm2 = Swarm::new(trans, ping::Behaviour::new(cfg), peer2_id.clone()); let (mut tx, mut rx) = mpsc::channel::(1); @@ -63,16 +63,16 @@ fn ping_pong() { loop { match swarm1.select_next_some().await { SwarmEvent::NewListenAddr { address, .. } => tx.send(address).await.unwrap(), - SwarmEvent::Behaviour(PingEvent { + SwarmEvent::Behaviour(ping::Event { peer, - result: Ok(PingSuccess::Ping { rtt }), + result: Ok(ping::Success::Ping { rtt }), }) => { count1 -= 1; if count1 == 0 { return (pid1.clone(), peer, rtt); } } - SwarmEvent::Behaviour(PingEvent { result: Err(e), .. }) => { + SwarmEvent::Behaviour(ping::Event { result: Err(e), .. }) => { panic!("Ping failure: {:?}", e) } _ => {} @@ -86,16 +86,16 @@ fn ping_pong() { loop { match swarm2.select_next_some().await { - SwarmEvent::Behaviour(PingEvent { + SwarmEvent::Behaviour(ping::Event { peer, - result: Ok(PingSuccess::Ping { rtt }), + result: Ok(ping::Success::Ping { rtt }), }) => { count2 -= 1; if count2 == 0 { return (pid2.clone(), peer, rtt); } } - SwarmEvent::Behaviour(PingEvent { result: Err(e), .. }) => { + SwarmEvent::Behaviour(ping::Event { result: Err(e), .. }) => { panic!("Ping failure: {:?}", e) } _ => {} @@ -117,17 +117,17 @@ fn ping_pong() { #[test] fn max_failures() { fn prop(max_failures: NonZeroU8, muxer: MuxerChoice) { - let cfg = PingConfig::new() + let cfg = ping::Config::new() .with_keep_alive(true) .with_interval(Duration::from_millis(10)) .with_timeout(Duration::from_millis(0)) .with_max_failures(max_failures.into()); let (peer1_id, trans) = mk_transport(muxer); - let mut swarm1 = Swarm::new(trans, Ping::new(cfg.clone()), peer1_id.clone()); + let mut swarm1 = Swarm::new(trans, ping::Behaviour::new(cfg.clone()), peer1_id.clone()); let (peer2_id, trans) = mk_transport(muxer); - let mut swarm2 = Swarm::new(trans, Ping::new(cfg), peer2_id.clone()); + let mut swarm2 = Swarm::new(trans, ping::Behaviour::new(cfg), peer2_id.clone()); let (mut tx, mut rx) = mpsc::channel::(1); @@ -140,13 +140,13 @@ fn max_failures() { loop { match swarm1.select_next_some().await { SwarmEvent::NewListenAddr { address, .. } => tx.send(address).await.unwrap(), - SwarmEvent::Behaviour(PingEvent { - result: Ok(PingSuccess::Ping { .. }), + SwarmEvent::Behaviour(ping::Event { + result: Ok(ping::Success::Ping { .. }), .. }) => { count1 = 0; // there may be an occasional success } - SwarmEvent::Behaviour(PingEvent { result: Err(_), .. }) => { + SwarmEvent::Behaviour(ping::Event { result: Err(_), .. }) => { count1 += 1; } SwarmEvent::ConnectionClosed { .. } => return count1, @@ -162,13 +162,13 @@ fn max_failures() { loop { match swarm2.select_next_some().await { - SwarmEvent::Behaviour(PingEvent { - result: Ok(PingSuccess::Ping { .. }), + SwarmEvent::Behaviour(ping::Event { + result: Ok(ping::Success::Ping { .. }), .. }) => { count2 = 0; // there may be an occasional success } - SwarmEvent::Behaviour(PingEvent { result: Err(_), .. }) => { + SwarmEvent::Behaviour(ping::Event { result: Err(_), .. }) => { count2 += 1; } SwarmEvent::ConnectionClosed { .. } => return count2, @@ -197,7 +197,7 @@ fn unsupported_doesnt_fail() { let (peer2_id, trans) = mk_transport(MuxerChoice::Mplex); let mut swarm2 = Swarm::new( trans, - Ping::new(PingConfig::new().with_keep_alive(true)), + ping::Behaviour::new(ping::Config::new().with_keep_alive(true)), peer2_id.clone(), ); @@ -220,8 +220,8 @@ fn unsupported_doesnt_fail() { loop { match swarm2.select_next_some().await { - SwarmEvent::Behaviour(PingEvent { - result: Err(PingFailure::Unsupported), + SwarmEvent::Behaviour(ping::Event { + result: Err(ping::Failure::Unsupported), .. }) => { swarm2.disconnect_peer_id(peer1_id).unwrap(); diff --git a/protocols/relay/examples/relay.rs b/protocols/relay/examples/relay.rs index 5b8de71702b..5140d6d5874 100644 --- a/protocols/relay/examples/relay.rs +++ b/protocols/relay/examples/relay.rs @@ -60,13 +60,12 @@ use futures::executor::block_on; use futures::stream::StreamExt; use libp2p::dns::DnsConfig; -use libp2p::ping::{Ping, PingConfig, PingEvent}; use libp2p::plaintext; use libp2p::relay::{Relay, RelayConfig}; use libp2p::swarm::SwarmEvent; use libp2p::tcp::TcpConfig; use libp2p::Transport; -use libp2p::{core::upgrade, identity::ed25519}; +use libp2p::{core::upgrade, identity::ed25519, ping}; use libp2p::{identity, NetworkBehaviour, PeerId, Swarm}; use std::error::Error; use std::task::{Context, Poll}; @@ -99,8 +98,8 @@ fn main() -> Result<(), Box> { let behaviour = Behaviour { relay: relay_behaviour, - ping: Ping::new( - PingConfig::new() + ping: ping::Behaviour::new( + ping::Config::new() .with_keep_alive(true) .with_interval(Duration::from_secs(1)), ), @@ -213,18 +212,18 @@ fn get_client_listen_address(opt: &Opt) -> String { #[behaviour(out_event = "Event", event_process = false)] struct Behaviour { relay: Relay, - ping: Ping, + ping: ping::Behaviour, } #[derive(Debug)] enum Event { Relay(()), - Ping(PingEvent), + Ping(ping::Event), } -impl From for Event { - fn from(e: PingEvent) -> Self { - Event::Ping(e) +impl From for Event { + fn from(v: ping::Event) -> Self { + Self::Ping(v) } } diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index 29a0cfd35ed..bf3ccee5a7e 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -31,7 +31,7 @@ use libp2p_core::transport::{MemoryTransport, Transport, TransportError}; use libp2p_core::{identity, upgrade, PeerId}; use libp2p_identify::{Identify, IdentifyConfig, IdentifyEvent, IdentifyInfo}; use libp2p_kad::{GetClosestPeersOk, Kademlia, KademliaEvent, QueryResult}; -use libp2p_ping::{Ping, PingConfig, PingEvent}; +use libp2p_ping as ping; use libp2p_plaintext::PlainText2Config; use libp2p_relay::{Relay, RelayConfig}; use libp2p_swarm::protocols_handler::KeepAlive; @@ -174,7 +174,7 @@ fn src_connect_to_dst_listening_via_relay() { // Source Node waiting for Ping from Destination Node via Relay. loop { match src_swarm.select_next_some().await { - SwarmEvent::Behaviour(CombinedEvent::Ping(PingEvent { + SwarmEvent::Behaviour(CombinedEvent::Ping(ping::Event { peer, result: Ok(_), })) => { @@ -249,7 +249,7 @@ fn src_connect_to_dst_not_listening_via_active_relay() { // Source Node waiting for Ping from Destination Node via Relay. loop { match src_swarm.select_next_some().await { - SwarmEvent::Behaviour(CombinedEvent::Ping(PingEvent { + SwarmEvent::Behaviour(CombinedEvent::Ping(ping::Event { peer, result: Ok(_), })) => { @@ -337,7 +337,7 @@ fn src_connect_to_dst_via_established_connection_to_relay() { // Source Node waiting for Ping from Destination Node via Relay. loop { match src_swarm.select_next_some().await { - SwarmEvent::Behaviour(CombinedEvent::Ping(PingEvent { + SwarmEvent::Behaviour(CombinedEvent::Ping(ping::Event { peer, result: Ok(_), })) => { @@ -690,7 +690,7 @@ fn firewalled_src_discover_firewalled_dst_via_kad_and_connect_to_dst_via_routabl // Source Node waiting for Ping from Destination Node via Relay. loop { match src_swarm.select_next_some().await { - SwarmEvent::Behaviour(CombinedEvent::Ping(PingEvent { + SwarmEvent::Behaviour(CombinedEvent::Ping(ping::Event { peer, result: Ok(_), })) => { @@ -1019,7 +1019,7 @@ fn yield_incoming_connection_through_correct_listener() { if address == relay_1_addr_incl_circuit || address == relay_2_addr_incl_circuit || address == dst_addr => {} - SwarmEvent::Behaviour(CombinedEvent::Ping(PingEvent { + SwarmEvent::Behaviour(CombinedEvent::Ping(ping::Event { peer, result: Ok(_), })) => { @@ -1132,7 +1132,7 @@ fn yield_incoming_connection_through_correct_listener() { #[behaviour(out_event = "CombinedEvent", poll_method = "poll")] struct CombinedBehaviour { relay: Relay, - ping: Ping, + ping: ping::Behaviour, kad: Kademlia, identify: Identify, @@ -1143,7 +1143,7 @@ struct CombinedBehaviour { #[derive(Debug)] enum CombinedEvent { Kad(KademliaEvent), - Ping(PingEvent), + Ping(ping::Event), } impl CombinedBehaviour { @@ -1161,8 +1161,8 @@ impl CombinedBehaviour { } } -impl NetworkBehaviourEventProcess for CombinedBehaviour { - fn inject_event(&mut self, event: PingEvent) { +impl NetworkBehaviourEventProcess for CombinedBehaviour { + fn inject_event(&mut self, event: ping::Event) { self.events.push(CombinedEvent::Ping(event)); } } @@ -1288,7 +1288,7 @@ fn build_swarm(reachability: Reachability, relay_mode: RelayMode) -> Swarm