From 29154bd0ab9339d8328e7b963d24fb795fb324e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 21 Sep 2022 15:34:41 +0100 Subject: [PATCH] protocols/identify: Revise symbol naming. --- examples/ipfs-private.rs | 13 +- misc/metrics/src/identify.rs | 12 +- misc/metrics/src/lib.rs | 4 +- protocols/autonat/examples/client.rs | 12 +- protocols/autonat/examples/server.rs | 12 +- protocols/dcutr/examples/client.rs | 18 +-- protocols/identify/CHANGELOG.md | 8 ++ protocols/identify/Cargo.toml | 1 + protocols/identify/examples/identify.rs | 9 +- .../src/{identify.rs => behaviour.rs} | 120 +++++++++--------- protocols/identify/src/handler.rs | 93 ++++++-------- protocols/identify/src/lib.rs | 31 +++-- protocols/identify/src/protocol.rs | 50 ++++---- protocols/relay/examples/relay_v2.rs | 12 +- .../examples/register_with_identify.rs | 14 +- .../rendezvous/examples/rendezvous_point.rs | 14 +- swarm-derive/tests/test.rs | 42 +++--- swarm/src/behaviour.rs | 10 +- 18 files changed, 243 insertions(+), 232 deletions(-) rename protocols/identify/src/{identify.rs => behaviour.rs} (90%) diff --git a/examples/ipfs-private.rs b/examples/ipfs-private.rs index b67bfa9009ee..063d1ff2d6ed 100644 --- a/examples/ipfs-private.rs +++ b/examples/ipfs-private.rs @@ -39,8 +39,7 @@ use libp2p::{ either::EitherTransport, muxing::StreamMuxerBox, transport, transport::upgrade::Version, }, gossipsub::{self, Gossipsub, GossipsubConfigBuilder, GossipsubEvent, MessageAuthenticity}, - identify::{Identify, IdentifyConfig, IdentifyEvent}, - identity, + identify, identity, multiaddr::Protocol, noise, ping::{self, PingEvent}, @@ -158,13 +157,13 @@ async fn main() -> Result<(), Box> { #[behaviour(out_event = "MyBehaviourEvent")] struct MyBehaviour { gossipsub: Gossipsub, - identify: Identify, + identify: identify::Behaviour, ping: ping::Behaviour, } enum MyBehaviourEvent { Gossipsub(GossipsubEvent), - Identify(IdentifyEvent), + Identify(identify::Event), Ping(PingEvent), } @@ -174,8 +173,8 @@ async fn main() -> Result<(), Box> { } } - impl From for MyBehaviourEvent { - fn from(event: IdentifyEvent) -> Self { + impl From for MyBehaviourEvent { + fn from(event: identify::Event) -> Self { MyBehaviourEvent::Identify(event) } } @@ -198,7 +197,7 @@ async fn main() -> Result<(), Box> { gossipsub_config, ) .expect("Valid configuration"), - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "/ipfs/0.1.0".into(), local_key.public(), )), diff --git a/misc/metrics/src/identify.rs b/misc/metrics/src/identify.rs index 730528167a89..8f91521713f4 100644 --- a/misc/metrics/src/identify.rs +++ b/misc/metrics/src/identify.rs @@ -112,16 +112,16 @@ impl Metrics { } } -impl super::Recorder for Metrics { - fn record(&self, event: &libp2p_identify::IdentifyEvent) { +impl super::Recorder for Metrics { + fn record(&self, event: &libp2p_identify::Event) { match event { - libp2p_identify::IdentifyEvent::Error { .. } => { + libp2p_identify::Event::Error { .. } => { self.error.inc(); } - libp2p_identify::IdentifyEvent::Pushed { .. } => { + libp2p_identify::Event::Pushed { .. } => { self.pushed.inc(); } - libp2p_identify::IdentifyEvent::Received { peer_id, info, .. } => { + libp2p_identify::Event::Received { peer_id, info, .. } => { { let mut protocols: Vec = info .protocols @@ -168,7 +168,7 @@ impl super::Recorder for Metrics { self.received_info_listen_addrs .observe(info.listen_addrs.len() as f64); } - libp2p_identify::IdentifyEvent::Sent { .. } => { + libp2p_identify::Event::Sent { .. } => { self.sent.inc(); } } diff --git a/misc/metrics/src/lib.rs b/misc/metrics/src/lib.rs index d9fa3c40ffe6..3f4b04633adc 100644 --- a/misc/metrics/src/lib.rs +++ b/misc/metrics/src/lib.rs @@ -112,8 +112,8 @@ impl Recorder for Metrics { } #[cfg(feature = "identify")] -impl Recorder for Metrics { - fn record(&self, event: &libp2p_identify::IdentifyEvent) { +impl Recorder for Metrics { + fn record(&self, event: &libp2p_identify::Event) { self.identify.record(event) } } diff --git a/protocols/autonat/examples/client.rs b/protocols/autonat/examples/client.rs index c2030d99bca8..17fb10372030 100644 --- a/protocols/autonat/examples/client.rs +++ b/protocols/autonat/examples/client.rs @@ -32,7 +32,7 @@ use clap::Parser; use futures::prelude::*; use libp2p::autonat; -use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent}; +use libp2p::identify; use libp2p::multiaddr::Protocol; use libp2p::swarm::{Swarm, SwarmEvent}; use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId}; @@ -91,14 +91,14 @@ async fn main() -> Result<(), Box> { #[derive(NetworkBehaviour)] #[behaviour(out_event = "Event")] struct Behaviour { - identify: Identify, + identify: identify::Behaviour, auto_nat: autonat::Behaviour, } impl Behaviour { fn new(local_public_key: identity::PublicKey) -> Self { Self { - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "/ipfs/0.1.0".into(), local_public_key.clone(), )), @@ -119,11 +119,11 @@ impl Behaviour { #[derive(Debug)] enum Event { AutoNat(autonat::Event), - Identify(IdentifyEvent), + Identify(identify::Event), } -impl From for Event { - fn from(v: IdentifyEvent) -> Self { +impl From for Event { + fn from(v: identify::Event) -> Self { Self::Identify(v) } } diff --git a/protocols/autonat/examples/server.rs b/protocols/autonat/examples/server.rs index c4ea7a93e9e9..72592be70829 100644 --- a/protocols/autonat/examples/server.rs +++ b/protocols/autonat/examples/server.rs @@ -29,7 +29,7 @@ use clap::Parser; use futures::prelude::*; use libp2p::autonat; -use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent}; +use libp2p::identify; use libp2p::multiaddr::Protocol; use libp2p::swarm::{Swarm, SwarmEvent}; use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId}; @@ -76,14 +76,14 @@ async fn main() -> Result<(), Box> { #[derive(NetworkBehaviour)] #[behaviour(out_event = "Event")] struct Behaviour { - identify: Identify, + identify: identify::Behaviour, auto_nat: autonat::Behaviour, } impl Behaviour { fn new(local_public_key: identity::PublicKey) -> Self { Self { - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "/ipfs/0.1.0".into(), local_public_key.clone(), )), @@ -98,11 +98,11 @@ impl Behaviour { #[derive(Debug)] enum Event { AutoNat(autonat::Event), - Identify(IdentifyEvent), + Identify(identify::Event), } -impl From for Event { - fn from(v: IdentifyEvent) -> Self { +impl From for Event { + fn from(v: identify::Event) -> Self { Self::Identify(v) } } diff --git a/protocols/dcutr/examples/client.rs b/protocols/dcutr/examples/client.rs index e70e54cca3b2..d0bde020d38f 100644 --- a/protocols/dcutr/examples/client.rs +++ b/protocols/dcutr/examples/client.rs @@ -27,7 +27,7 @@ use libp2p::core::transport::OrTransport; use libp2p::core::upgrade; use libp2p::dcutr; use libp2p::dns::DnsConfig; -use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent, IdentifyInfo}; +use libp2p::identify; use libp2p::noise; use libp2p::ping::{Ping, PingConfig, PingEvent}; use libp2p::relay::v2::client::{self, Client}; @@ -109,14 +109,14 @@ fn main() -> Result<(), Box> { struct Behaviour { relay_client: Client, ping: Ping, - identify: Identify, + identify: identify::Behaviour, dcutr: dcutr::behaviour::Behaviour, } #[derive(Debug)] enum Event { Ping(PingEvent), - Identify(IdentifyEvent), + Identify(identify::Event), Relay(client::Event), Dcutr(dcutr::behaviour::Event), } @@ -127,8 +127,8 @@ fn main() -> Result<(), Box> { } } - impl From for Event { - fn from(e: IdentifyEvent) -> Self { + impl From for Event { + fn from(e: identify::Event) -> Self { Event::Identify(e) } } @@ -148,7 +148,7 @@ fn main() -> Result<(), Box> { let behaviour = Behaviour { relay_client: client, ping: Ping::new(PingConfig::new()), - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "/TODO/0.0.1".to_string(), local_key.public(), )), @@ -201,12 +201,12 @@ fn main() -> Result<(), Box> { SwarmEvent::Dialing { .. } => {} SwarmEvent::ConnectionEstablished { .. } => {} SwarmEvent::Behaviour(Event::Ping(_)) => {} - SwarmEvent::Behaviour(Event::Identify(IdentifyEvent::Sent { .. })) => { + SwarmEvent::Behaviour(Event::Identify(identify::Event::Sent { .. })) => { info!("Told relay its public address."); told_relay_observed_addr = true; } - SwarmEvent::Behaviour(Event::Identify(IdentifyEvent::Received { - info: IdentifyInfo { observed_addr, .. }, + SwarmEvent::Behaviour(Event::Identify(identify::Event::Received { + info: identify::Info { observed_addr, .. }, .. })) => { info!("Relay told us our public address: {:?}", observed_addr); diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 1455966b0915..4bdbbc72625c 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -4,6 +4,14 @@ - Update to `libp2p-core` `v0.36.0`. +- Rename types as per [discussion 2174]. + `Identify` has been renamed to `Behaviour`. + The `Identify` prefix has been removed from various types like `IdentifyEvent`. + Users should prefer importing the identify protocol as a module (`use libp2p::identify;`), + and refer to its types via `identify::`. For example: `identify::Behaviour` or `identify::Event`. + + [discussion 2174]: https://github.com/libp2p/rust-libp2p/discussions/2174 + # 0.38.0 - Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index f147c5bb2c8e..3fa624edcab0 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -29,6 +29,7 @@ async-std = { version = "1.6.2", features = ["attributes"] } env_logger = "0.9" libp2p = { path = "../..", default-features = false, features = [ "dns-async-std", + "identify", "mplex", "noise", "tcp-async-io", diff --git a/protocols/identify/examples/identify.rs b/protocols/identify/examples/identify.rs index 278cf0cc9912..b02eb1c9ebf0 100644 --- a/protocols/identify/examples/identify.rs +++ b/protocols/identify/examples/identify.rs @@ -37,8 +37,7 @@ //! and will send each other identify info which is then printed to the console. use futures::prelude::*; -use libp2p::{identity, Multiaddr, PeerId}; -use libp2p_identify::{Identify, IdentifyConfig, IdentifyEvent}; +use libp2p::{identify, identity, Multiaddr, PeerId}; use libp2p_swarm::{Swarm, SwarmEvent}; use std::error::Error; @@ -51,7 +50,7 @@ async fn main() -> Result<(), Box> { let transport = libp2p::development_transport(local_key.clone()).await?; // Create a identify network behaviour. - let behaviour = Identify::new(IdentifyConfig::new( + let behaviour = identify::Behaviour::new(identify::Config::new( "/ipfs/id/1.0.0".to_string(), local_key.public(), )); @@ -74,11 +73,11 @@ async fn main() -> Result<(), Box> { match swarm.select_next_some().await { SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {:?}", address), // Prints peer id identify info is being sent to. - SwarmEvent::Behaviour(IdentifyEvent::Sent { peer_id, .. }) => { + SwarmEvent::Behaviour(identify::Event::Sent { peer_id, .. }) => { println!("Sent identify info to {:?}", peer_id) } // Prints out the info received via the identify event - SwarmEvent::Behaviour(IdentifyEvent::Received { info, .. }) => { + SwarmEvent::Behaviour(identify::Event::Received { info, .. }) => { println!("Received {:?}", info) } _ => {} diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/behaviour.rs similarity index 90% rename from protocols/identify/src/identify.rs rename to protocols/identify/src/behaviour.rs index d30e98e14004..5db4da58c2af 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/behaviour.rs @@ -18,8 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::handler::{IdentifyHandlerEvent, IdentifyHandlerProto, IdentifyPush}; -use crate::protocol::{IdentifyInfo, ReplySubstream, UpgradeError}; +use crate::handler::{self, Proto, Push}; +use crate::protocol::{Info, ReplySubstream, UpgradeError}; use futures::prelude::*; use libp2p_core::{ connection::ConnectionId, multiaddr::Protocol, transport::ListenerId, ConnectedPoint, @@ -46,14 +46,14 @@ use std::{ /// All external addresses of the local node supposedly observed by remotes /// are reported via [`NetworkBehaviourAction::ReportObservedAddr`] with a /// [score](AddressScore) of `1`. -pub struct Identify { - config: IdentifyConfig, +pub struct Behaviour { + config: Config, /// For each peer we're connected to, the observed address to send back to it. connected: HashMap>, /// Pending replies to send. pending_replies: VecDeque, /// Pending events to be emitted when polled. - events: VecDeque>, + events: VecDeque>, /// Peers to which an active push with current information about /// the local peer should be sent. pending_push: HashSet, @@ -76,10 +76,10 @@ enum Reply { }, } -/// Configuration for the [`Identify`] [`NetworkBehaviour`]. +/// Configuration for the [`Behaviour`] [`NetworkBehaviour`]. #[non_exhaustive] #[derive(Debug, Clone)] -pub struct IdentifyConfig { +pub struct Config { /// Application-specific version of the protocol family used by the peer, /// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`. pub protocol_version: String, @@ -119,11 +119,11 @@ pub struct IdentifyConfig { pub cache_size: usize, } -impl IdentifyConfig { - /// Creates a new configuration for the `Identify` behaviour that +impl Config { + /// Creates a new configuration for the identify [`Behaviour`] that /// advertises the given protocol version and public key. pub fn new(protocol_version: String, local_public_key: PublicKey) -> Self { - IdentifyConfig { + Self { protocol_version, agent_version: format!("rust-libp2p/{}", env!("CARGO_PKG_VERSION")), local_public_key, @@ -172,12 +172,12 @@ impl IdentifyConfig { } } -impl Identify { - /// Creates a new `Identify` network behaviour. - pub fn new(config: IdentifyConfig) -> Self { +impl Behaviour { + /// Creates a new identify [`Behaviour`]. + pub fn new(config: Config) -> Self { let discovered_peers = LruCache::new(config.cache_size); - Identify { + Self { config, connected: HashMap::new(), pending_replies: VecDeque::new(), @@ -204,12 +204,12 @@ impl Identify { } } -impl NetworkBehaviour for Identify { - type ConnectionHandler = IdentifyHandlerProto; - type OutEvent = IdentifyEvent; +impl NetworkBehaviour for Behaviour { + type ConnectionHandler = Proto; + type OutEvent = Event; fn new_handler(&mut self) -> Self::ConnectionHandler { - IdentifyHandlerProto::new(self.config.initial_delay, self.config.interval) + Proto::new(self.config.initial_delay, self.config.interval) } fn inject_connection_established( @@ -296,7 +296,7 @@ impl NetworkBehaviour for Identify { event: <::Handler as ConnectionHandler>::OutEvent, ) { match event { - IdentifyHandlerEvent::Identified(mut info) => { + handler::Event::Identified(mut info) => { // Remove invalid multiaddrs. info.listen_addrs .retain(|addr| multiaddr_matches_peer_id(addr, &peer_id)); @@ -306,21 +306,24 @@ impl NetworkBehaviour for Identify { .put(peer_id, HashSet::from_iter(info.listen_addrs.clone())); let observed = info.observed_addr.clone(); - self.events.push_back(NetworkBehaviourAction::GenerateEvent( - IdentifyEvent::Received { peer_id, info }, - )); + self.events + .push_back(NetworkBehaviourAction::GenerateEvent(Event::Received { + peer_id, + info, + })); self.events .push_back(NetworkBehaviourAction::ReportObservedAddr { address: observed, score: AddressScore::Finite(1), }); } - IdentifyHandlerEvent::IdentificationPushed => { - self.events.push_back(NetworkBehaviourAction::GenerateEvent( - IdentifyEvent::Pushed { peer_id }, - )); + handler::Event::IdentificationPushed => { + self.events + .push_back(NetworkBehaviourAction::GenerateEvent(Event::Pushed { + peer_id, + })); } - IdentifyHandlerEvent::Identify(sender) => { + handler::Event::Identify(sender) => { let observed = self .connected .get(&peer_id) @@ -335,10 +338,12 @@ impl NetworkBehaviour for Identify { observed: observed.clone(), }); } - IdentifyHandlerEvent::IdentificationError(error) => { - self.events.push_back(NetworkBehaviourAction::GenerateEvent( - IdentifyEvent::Error { peer_id, error }, - )); + handler::Event::IdentificationError(error) => { + self.events + .push_back(NetworkBehaviourAction::GenerateEvent(Event::Error { + peer_id, + error, + })); } } } @@ -364,7 +369,7 @@ impl NetworkBehaviour for Identify { let listen_addrs = listen_addrs(params); let protocols = supported_protocols(params); - let info = IdentifyInfo { + let info = Info { public_key: self.config.local_public_key.clone(), protocol_version: self.config.protocol_version.clone(), agent_version: self.config.agent_version.clone(), @@ -373,7 +378,7 @@ impl NetworkBehaviour for Identify { observed_addr, }; - (*peer, IdentifyPush(info)) + (*peer, Push(info)) }) }); @@ -394,7 +399,7 @@ impl NetworkBehaviour for Identify { loop { match reply { Some(Reply::Queued { peer, io, observed }) => { - let info = IdentifyInfo { + let info = Info { listen_addrs: listen_addrs(params), protocols: supported_protocols(params), public_key: self.config.local_public_key.clone(), @@ -409,7 +414,7 @@ impl NetworkBehaviour for Identify { sending += 1; match Future::poll(Pin::new(&mut io), cx) { Poll::Ready(Ok(())) => { - let event = IdentifyEvent::Sent { peer_id: peer }; + let event = Event::Sent { peer_id: peer }; return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event)); } Poll::Pending => { @@ -422,7 +427,7 @@ impl NetworkBehaviour for Identify { } } Poll::Ready(Err(err)) => { - let event = IdentifyEvent::Error { + let event = Event::Error { peer_id: peer, error: ConnectionHandlerUpgrErr::Upgrade( libp2p_core::upgrade::UpgradeError::Apply(err), @@ -452,13 +457,13 @@ impl NetworkBehaviour for Identify { /// Event emitted by the `Identify` behaviour. #[allow(clippy::large_enum_variant)] #[derive(Debug)] -pub enum IdentifyEvent { +pub enum Event { /// Identification information has been received from a peer. Received { /// The peer that has been identified. peer_id: PeerId, /// The information provided by the peer. - info: IdentifyInfo, + info: Info, }, /// Identification information of the local node has been sent to a peer in /// response to an identification request. @@ -538,9 +543,8 @@ mod tests { fn periodic_identify() { let (mut swarm1, pubkey1) = { let (pubkey, transport) = transport(); - let protocol = Identify::new( - IdentifyConfig::new("a".to_string(), pubkey.clone()) - .with_agent_version("b".to_string()), + let protocol = Behaviour::new( + Config::new("a".to_string(), pubkey.clone()).with_agent_version("b".to_string()), ); let swarm = Swarm::new(transport, protocol, pubkey.to_peer_id()); (swarm, pubkey) @@ -548,9 +552,8 @@ mod tests { let (mut swarm2, pubkey2) = { let (pubkey, transport) = transport(); - let protocol = Identify::new( - IdentifyConfig::new("c".to_string(), pubkey.clone()) - .with_agent_version("d".to_string()), + let protocol = Behaviour::new( + Config::new("c".to_string(), pubkey.clone()).with_agent_version("d".to_string()), ); let swarm = Swarm::new(transport, protocol, pubkey.to_peer_id()); (swarm, pubkey) @@ -588,9 +591,8 @@ mod tests { .factor_second() .0 { - future::Either::Left(SwarmEvent::Behaviour(IdentifyEvent::Received { - info, - .. + future::Either::Left(SwarmEvent::Behaviour(Event::Received { + info, .. })) => { assert_eq!(info.public_key, pubkey2); assert_eq!(info.protocol_version, "c"); @@ -599,9 +601,8 @@ mod tests { assert!(info.listen_addrs.is_empty()); return; } - future::Either::Right(SwarmEvent::Behaviour(IdentifyEvent::Received { - info, - .. + future::Either::Right(SwarmEvent::Behaviour(Event::Received { + info, .. })) => { assert_eq!(info.public_key, pubkey1); assert_eq!(info.protocol_version, "a"); @@ -622,16 +623,15 @@ mod tests { let (mut swarm1, pubkey1) = { let (pubkey, transport) = transport(); - let protocol = Identify::new(IdentifyConfig::new("a".to_string(), pubkey.clone())); + let protocol = Behaviour::new(Config::new("a".to_string(), pubkey.clone())); let swarm = Swarm::new(transport, protocol, pubkey.to_peer_id()); (swarm, pubkey) }; let (mut swarm2, pubkey2) = { let (pubkey, transport) = transport(); - let protocol = Identify::new( - IdentifyConfig::new("a".to_string(), pubkey.clone()) - .with_agent_version("b".to_string()), + let protocol = Behaviour::new( + Config::new("a".to_string(), pubkey.clone()).with_agent_version("b".to_string()), ); let swarm = Swarm::new(transport, protocol, pubkey.to_peer_id()); (swarm, pubkey) @@ -665,7 +665,7 @@ mod tests { .factor_second() .0 { - future::Either::Left(SwarmEvent::Behaviour(IdentifyEvent::Received { + future::Either::Left(SwarmEvent::Behaviour(Event::Received { info, .. })) => { @@ -697,8 +697,8 @@ mod tests { let mut swarm1 = { let (pubkey, transport) = transport(); - let protocol = Identify::new( - IdentifyConfig::new("a".to_string(), pubkey.clone()) + let protocol = Behaviour::new( + Config::new("a".to_string(), pubkey.clone()) // `swarm1` will set `KeepAlive::No` once it identified `swarm2` and thus // closes the connection. At this point in time `swarm2` might not yet have // identified `swarm1`. To give `swarm2` enough time, set an initial delay on @@ -711,8 +711,8 @@ mod tests { let mut swarm2 = { let (pubkey, transport) = transport(); - let protocol = Identify::new( - IdentifyConfig::new("a".to_string(), pubkey.clone()) + let protocol = Behaviour::new( + Config::new("a".to_string(), pubkey.clone()) .with_cache_size(100) .with_agent_version("b".to_string()), ); @@ -749,7 +749,7 @@ mod tests { // Wait until we identified. async_std::task::block_on(async { loop { - if let SwarmEvent::Behaviour(IdentifyEvent::Received { .. }) = + if let SwarmEvent::Behaviour(Event::Received { .. }) = swarm2.select_next_some().await { break; diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index af4d7f8cba3b..20db7f844965 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -19,8 +19,7 @@ // DEALINGS IN THE SOFTWARE. use crate::protocol::{ - IdentifyInfo, IdentifyProtocol, IdentifyPushProtocol, InboundPush, OutboundPush, - ReplySubstream, UpgradeError, + InboundPush, Info, OutboundPush, Protocol, PushProtocol, ReplySubstream, UpgradeError, }; use futures::future::BoxFuture; use futures::prelude::*; @@ -36,29 +35,29 @@ use log::warn; use smallvec::SmallVec; use std::{io, pin::Pin, task::Context, task::Poll, time::Duration}; -pub struct IdentifyHandlerProto { +pub struct Proto { initial_delay: Duration, interval: Duration, } -impl IdentifyHandlerProto { +impl Proto { pub fn new(initial_delay: Duration, interval: Duration) -> Self { - IdentifyHandlerProto { + Proto { initial_delay, interval, } } } -impl IntoConnectionHandler for IdentifyHandlerProto { - type Handler = IdentifyHandler; +impl IntoConnectionHandler for Proto { + type Handler = Handler; fn into_handler(self, remote_peer_id: &PeerId, _endpoint: &ConnectedPoint) -> Self::Handler { - IdentifyHandler::new(self.initial_delay, self.interval, *remote_peer_id) + Handler::new(self.initial_delay, self.interval, *remote_peer_id) } fn inbound_protocol(&self) -> ::InboundProtocol { - SelectUpgrade::new(IdentifyProtocol, IdentifyPushProtocol::inbound()) + SelectUpgrade::new(Protocol, PushProtocol::inbound()) } } @@ -67,15 +66,15 @@ impl IntoConnectionHandler for IdentifyHandlerProto { /// Outbound requests are sent periodically. The handler performs expects /// at least one identification request to be answered by the remote before /// permitting the underlying connection to be closed. -pub struct IdentifyHandler { +pub struct Handler { remote_peer_id: PeerId, - inbound_identify_push: Option>>, + inbound_identify_push: Option>>, /// Pending events to yield. events: SmallVec< [ConnectionHandlerEvent< - EitherUpgrade>, + EitherUpgrade>, (), - IdentifyHandlerEvent, + Event, io::Error, >; 4], >, @@ -92,9 +91,9 @@ pub struct IdentifyHandler { /// Event produced by the `IdentifyHandler`. #[derive(Debug)] -pub enum IdentifyHandlerEvent { +pub enum Event { /// We obtained identification information from the remote. - Identified(IdentifyInfo), + Identified(Info), /// We actively pushed our identification information to the remote. IdentificationPushed, /// We received a request for identification. @@ -105,12 +104,12 @@ pub enum IdentifyHandlerEvent { /// Identifying information of the local node that is pushed to a remote. #[derive(Debug)] -pub struct IdentifyPush(pub IdentifyInfo); +pub struct Push(pub Info); -impl IdentifyHandler { +impl Handler { /// Creates a new `IdentifyHandler`. pub fn new(initial_delay: Duration, interval: Duration, remote_peer_id: PeerId) -> Self { - IdentifyHandler { + Self { remote_peer_id, inbound_identify_push: Default::default(), events: SmallVec::new(), @@ -121,20 +120,17 @@ impl IdentifyHandler { } } -impl ConnectionHandler for IdentifyHandler { - type InEvent = IdentifyPush; - type OutEvent = IdentifyHandlerEvent; +impl ConnectionHandler for Handler { + type InEvent = Push; + type OutEvent = Event; type Error = io::Error; - type InboundProtocol = SelectUpgrade>; - type OutboundProtocol = EitherUpgrade>; + type InboundProtocol = SelectUpgrade>; + type OutboundProtocol = EitherUpgrade>; type OutboundOpenInfo = (); type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { - SubstreamProtocol::new( - SelectUpgrade::new(IdentifyProtocol, IdentifyPushProtocol::inbound()), - (), - ) + SubstreamProtocol::new(SelectUpgrade::new(Protocol, PushProtocol::inbound()), ()) } fn inject_fully_negotiated_inbound( @@ -143,9 +139,9 @@ impl ConnectionHandler for IdentifyHandler { _: Self::InboundOpenInfo, ) { match output { - EitherOutput::First(substream) => self.events.push(ConnectionHandlerEvent::Custom( - IdentifyHandlerEvent::Identify(substream), - )), + EitherOutput::First(substream) => self + .events + .push(ConnectionHandlerEvent::Custom(Event::Identify(substream))), EitherOutput::Second(fut) => { if self.inbound_identify_push.replace(fut).is_some() { warn!( @@ -165,22 +161,23 @@ impl ConnectionHandler for IdentifyHandler { ) { match output { EitherOutput::First(remote_info) => { - self.events.push(ConnectionHandlerEvent::Custom( - IdentifyHandlerEvent::Identified(remote_info), - )); + self.events + .push(ConnectionHandlerEvent::Custom(Event::Identified( + remote_info, + ))); self.keep_alive = KeepAlive::No; } - EitherOutput::Second(()) => self.events.push(ConnectionHandlerEvent::Custom( - IdentifyHandlerEvent::IdentificationPushed, - )), + EitherOutput::Second(()) => self + .events + .push(ConnectionHandlerEvent::Custom(Event::IdentificationPushed)), } } - fn inject_event(&mut self, IdentifyPush(push): Self::InEvent) { + fn inject_event(&mut self, Push(push): Self::InEvent) { self.events .push(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol: SubstreamProtocol::new( - EitherUpgrade::B(IdentifyPushProtocol::outbound(push)), + EitherUpgrade::B(PushProtocol::outbound(push)), (), ), }); @@ -200,9 +197,10 @@ impl ConnectionHandler for IdentifyHandler { UpgradeError::Apply(EitherError::A(ioe)) => UpgradeError::Apply(ioe), UpgradeError::Apply(EitherError::B(ioe)) => UpgradeError::Apply(ioe), }); - self.events.push(ConnectionHandlerEvent::Custom( - IdentifyHandlerEvent::IdentificationError(err), - )); + self.events + .push(ConnectionHandlerEvent::Custom(Event::IdentificationError( + err, + ))); self.keep_alive = KeepAlive::No; self.trigger_next_identify.reset(self.interval); } @@ -215,12 +213,7 @@ impl ConnectionHandler for IdentifyHandler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent< - Self::OutboundProtocol, - Self::OutboundOpenInfo, - IdentifyHandlerEvent, - Self::Error, - >, + ConnectionHandlerEvent, > { if !self.events.is_empty() { return Poll::Ready(self.events.remove(0)); @@ -232,7 +225,7 @@ impl ConnectionHandler for IdentifyHandler { Poll::Ready(()) => { self.trigger_next_identify.reset(self.interval); let ev = ConnectionHandlerEvent::OutboundSubstreamRequest { - protocol: SubstreamProtocol::new(EitherUpgrade::A(IdentifyProtocol), ()), + protocol: SubstreamProtocol::new(EitherUpgrade::A(Protocol), ()), }; return Poll::Ready(ev); } @@ -246,9 +239,7 @@ impl ConnectionHandler for IdentifyHandler { self.inbound_identify_push.take(); if let Ok(info) = res { - return Poll::Ready(ConnectionHandlerEvent::Custom( - IdentifyHandlerEvent::Identified(info), - )); + return Poll::Ready(ConnectionHandlerEvent::Custom(Event::Identified(info))); } } diff --git a/protocols/identify/src/lib.rs b/protocols/identify/src/lib.rs index 2f73a5a0cadb..2502b32cbfc2 100644 --- a/protocols/identify/src/lib.rs +++ b/protocols/identify/src/lib.rs @@ -35,20 +35,35 @@ //! //! # Usage //! -//! The [`Identify`] struct implements a `NetworkBehaviour` that negotiates +//! The [`Behaviour`] struct implements a `NetworkBehaviour` that negotiates //! and executes the protocol on every established connection, emitting -//! [`IdentifyEvent`]s. +//! [`Event`]s. //! //! [Identify]: https://github.com/libp2p/specs/tree/master/identify -//! [`Identify`]: self::Identify -//! [`IdentifyEvent`]: self::IdentifyEvent -//! [`IdentifyInfo`]: self::IdentifyInfo +//! [`Behaviour`]: self::Behaviour +//! [`Event`]: self::Event +//! [`Info`]: self::Info -pub use self::identify::{Identify, IdentifyConfig, IdentifyEvent}; -pub use self::protocol::{IdentifyInfo, UpgradeError, PROTOCOL_NAME, PUSH_PROTOCOL_NAME}; +pub use self::behaviour::{Behaviour, Config, Event}; +pub use self::protocol::{Info, UpgradeError, PROTOCOL_NAME, PUSH_PROTOCOL_NAME}; +#[deprecated( + since = "0.39.0", + note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p::identify::Config`" +)] +pub type IdentifyConfig = Config; + +#[deprecated( + since = "0.39.0", + note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p::identify::Event`" +)] +pub type IdentifyEvent = Event; + +#[deprecated(since = "0.39.0", note = "Use libp2p::identify::Behaviour instead.")] +pub type Identify = Behaviour; + +mod behaviour; mod handler; -mod identify; mod protocol; #[allow(clippy::derive_partial_eq_without_eq)] diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 163ac0aa3962..63a03df37073 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -40,29 +40,29 @@ pub const PUSH_PROTOCOL_NAME: &[u8; 19] = b"/ipfs/id/push/1.0.0"; /// Substream upgrade protocol for `/ipfs/id/1.0.0`. #[derive(Debug, Clone)] -pub struct IdentifyProtocol; +pub struct Protocol; /// Substream upgrade protocol for `/ipfs/id/push/1.0.0`. #[derive(Debug, Clone)] -pub struct IdentifyPushProtocol(T); +pub struct PushProtocol(T); pub struct InboundPush(); -pub struct OutboundPush(IdentifyInfo); +pub struct OutboundPush(Info); -impl IdentifyPushProtocol { +impl PushProtocol { pub fn inbound() -> Self { - IdentifyPushProtocol(InboundPush()) + PushProtocol(InboundPush()) } } -impl IdentifyPushProtocol { - pub fn outbound(info: IdentifyInfo) -> Self { - IdentifyPushProtocol(OutboundPush(info)) +impl PushProtocol { + pub fn outbound(info: Info) -> Self { + PushProtocol(OutboundPush(info)) } } /// Information of a peer sent in protocol messages. #[derive(Debug, Clone)] -pub struct IdentifyInfo { +pub struct Info { /// The public key of the local peer. pub public_key: PublicKey, /// Application-specific version of the protocol family used by the peer, @@ -98,12 +98,12 @@ where /// /// Consumes the substream, returning a future that resolves /// when the reply has been sent on the underlying connection. - pub async fn send(self, info: IdentifyInfo) -> Result<(), UpgradeError> { + pub async fn send(self, info: Info) -> Result<(), UpgradeError> { send(self.inner, info).await.map_err(Into::into) } } -impl UpgradeInfo for IdentifyProtocol { +impl UpgradeInfo for Protocol { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -112,7 +112,7 @@ impl UpgradeInfo for IdentifyProtocol { } } -impl InboundUpgrade for IdentifyProtocol { +impl InboundUpgrade for Protocol { type Output = ReplySubstream; type Error = UpgradeError; type Future = future::Ready>; @@ -122,11 +122,11 @@ impl InboundUpgrade for IdentifyProtocol { } } -impl OutboundUpgrade for IdentifyProtocol +impl OutboundUpgrade for Protocol where C: AsyncRead + AsyncWrite + Unpin + Send + 'static, { - type Output = IdentifyInfo; + type Output = Info; type Error = UpgradeError; type Future = Pin> + Send>>; @@ -135,7 +135,7 @@ where } } -impl UpgradeInfo for IdentifyPushProtocol { +impl UpgradeInfo for PushProtocol { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -144,11 +144,11 @@ impl UpgradeInfo for IdentifyPushProtocol { } } -impl InboundUpgrade for IdentifyPushProtocol +impl InboundUpgrade for PushProtocol where C: AsyncRead + AsyncWrite + Unpin + Send + 'static, { - type Output = BoxFuture<'static, Result>; + type Output = BoxFuture<'static, Result>; type Error = Void; type Future = future::Ready>; @@ -158,7 +158,7 @@ where } } -impl OutboundUpgrade for IdentifyPushProtocol +impl OutboundUpgrade for PushProtocol where C: AsyncWrite + Unpin + Send + 'static, { @@ -171,7 +171,7 @@ where } } -async fn send(io: T, info: IdentifyInfo) -> Result<(), UpgradeError> +async fn send(io: T, info: Info) -> Result<(), UpgradeError> where T: AsyncWrite + Unpin, { @@ -205,7 +205,7 @@ where Ok(()) } -async fn recv(mut socket: T) -> Result +async fn recv(mut socket: T) -> Result where T: AsyncRead + AsyncWrite + Unpin, { @@ -225,7 +225,7 @@ where Ok(info) } -impl TryFrom for IdentifyInfo { +impl TryFrom for Info { type Error = UpgradeError; fn try_from(msg: structs_proto::Identify) -> Result { @@ -244,7 +244,7 @@ impl TryFrom for IdentifyInfo { let public_key = PublicKey::from_protobuf_encoding(&msg.public_key.unwrap_or_default())?; let observed_addr = parse_multiaddr(msg.observed_addr.unwrap_or_default())?; - let info = IdentifyInfo { + let info = Info { public_key, protocol_version: msg.protocol_version.unwrap_or_default(), agent_version: msg.agent_version.unwrap_or_default(), @@ -332,10 +332,10 @@ mod tests { .await .unwrap(); - let sender = apply_inbound(socket, IdentifyProtocol).await.unwrap(); + let sender = apply_inbound(socket, Protocol).await.unwrap(); sender - .send(IdentifyInfo { + .send(Info { public_key: send_pubkey, protocol_version: "proto_version".to_owned(), agent_version: "agent_version".to_owned(), @@ -354,7 +354,7 @@ mod tests { let mut transport = TcpTransport::default(); let socket = transport.dial(rx.await.unwrap()).unwrap().await.unwrap(); - let info = apply_outbound(socket, IdentifyProtocol, upgrade::Version::V1) + let info = apply_outbound(socket, Protocol, upgrade::Version::V1) .await .unwrap(); assert_eq!( diff --git a/protocols/relay/examples/relay_v2.rs b/protocols/relay/examples/relay_v2.rs index 0e75b486ae10..fa78eeefabff 100644 --- a/protocols/relay/examples/relay_v2.rs +++ b/protocols/relay/examples/relay_v2.rs @@ -23,7 +23,7 @@ use clap::Parser; use futures::executor::block_on; use futures::stream::StreamExt; use libp2p::core::upgrade; -use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent}; +use libp2p::identify; use libp2p::multiaddr::Protocol; use libp2p::ping::{Ping, PingConfig, PingEvent}; use libp2p::relay::v2::relay::{self, Relay}; @@ -60,7 +60,7 @@ fn main() -> Result<(), Box> { let behaviour = Behaviour { relay: Relay::new(local_peer_id, Default::default()), ping: Ping::new(PingConfig::new()), - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "/TODO/0.0.1".to_string(), local_key.public(), )), @@ -97,13 +97,13 @@ fn main() -> Result<(), Box> { struct Behaviour { relay: Relay, ping: Ping, - identify: Identify, + identify: identify::Behaviour, } #[derive(Debug)] enum Event { Ping(PingEvent), - Identify(IdentifyEvent), + Identify(identify::Event), Relay(relay::Event), } @@ -113,8 +113,8 @@ impl From for Event { } } -impl From for Event { - fn from(e: IdentifyEvent) -> Self { +impl From for Event { + fn from(e: identify::Event) -> Self { Event::Identify(e) } } diff --git a/protocols/rendezvous/examples/register_with_identify.rs b/protocols/rendezvous/examples/register_with_identify.rs index 3896db3e3d1a..8ec73171108d 100644 --- a/protocols/rendezvous/examples/register_with_identify.rs +++ b/protocols/rendezvous/examples/register_with_identify.rs @@ -21,7 +21,7 @@ use futures::StreamExt; use libp2p::core::identity; use libp2p::core::PeerId; -use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent}; +use libp2p::identify; use libp2p::ping::{Ping, PingConfig, PingEvent, PingSuccess}; use libp2p::swarm::{Swarm, SwarmEvent}; use libp2p::{development_transport, rendezvous}; @@ -42,7 +42,7 @@ async fn main() { let mut swarm = Swarm::new( development_transport(identity.clone()).await.unwrap(), MyBehaviour { - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "rendezvous-example/1.0.0".to_string(), identity.public(), )), @@ -75,7 +75,7 @@ async fn main() { log::error!("Lost connection to rendezvous point {}", error); } // once `/identify` did its job, we know our external address and can register - SwarmEvent::Behaviour(MyEvent::Identify(IdentifyEvent::Received { .. })) => { + SwarmEvent::Behaviour(MyEvent::Identify(identify::Event::Received { .. })) => { swarm.behaviour_mut().rendezvous.register( rendezvous::Namespace::from_static("rendezvous"), rendezvous_point, @@ -116,7 +116,7 @@ async fn main() { #[derive(Debug)] enum MyEvent { Rendezvous(rendezvous::client::Event), - Identify(IdentifyEvent), + Identify(identify::Event), Ping(PingEvent), } @@ -126,8 +126,8 @@ impl From for MyEvent { } } -impl From for MyEvent { - fn from(event: IdentifyEvent) -> Self { +impl From for MyEvent { + fn from(event: identify::Event) -> Self { MyEvent::Identify(event) } } @@ -142,7 +142,7 @@ impl From for MyEvent { #[behaviour(event_process = false)] #[behaviour(out_event = "MyEvent")] struct MyBehaviour { - identify: Identify, + identify: identify::Behaviour, rendezvous: rendezvous::client::Behaviour, ping: Ping, } diff --git a/protocols/rendezvous/examples/rendezvous_point.rs b/protocols/rendezvous/examples/rendezvous_point.rs index 9d5ee6ca7db5..74fed34079f2 100644 --- a/protocols/rendezvous/examples/rendezvous_point.rs +++ b/protocols/rendezvous/examples/rendezvous_point.rs @@ -21,9 +21,7 @@ use futures::StreamExt; use libp2p::core::identity; use libp2p::core::PeerId; -use libp2p::identify::Identify; -use libp2p::identify::IdentifyConfig; -use libp2p::identify::IdentifyEvent; +use libp2p::identify; use libp2p::ping; use libp2p::ping::{Ping, PingEvent}; use libp2p::swarm::{Swarm, SwarmEvent}; @@ -49,7 +47,7 @@ async fn main() { let mut swarm = Swarm::new( development_transport(identity.clone()).await.unwrap(), MyBehaviour { - identify: Identify::new(IdentifyConfig::new( + identify: identify::Behaviour::new(identify::Config::new( "rendezvous-example/1.0.0".to_string(), identity.public(), )), @@ -105,7 +103,7 @@ async fn main() { enum MyEvent { Rendezvous(rendezvous::server::Event), Ping(PingEvent), - Identify(IdentifyEvent), + Identify(identify::Event), } impl From for MyEvent { @@ -120,8 +118,8 @@ impl From for MyEvent { } } -impl From for MyEvent { - fn from(event: IdentifyEvent) -> Self { +impl From for MyEvent { + fn from(event: identify::Event) -> Self { MyEvent::Identify(event) } } @@ -130,7 +128,7 @@ impl From for MyEvent { #[behaviour(event_process = false)] #[behaviour(out_event = "MyEvent")] struct MyBehaviour { - identify: Identify, + identify: identify::Behaviour, rendezvous: rendezvous::server::Behaviour, ping: Ping, } diff --git a/swarm-derive/tests/test.rs b/swarm-derive/tests/test.rs index e0f77eefd303..ec868b160704 100644 --- a/swarm-derive/tests/test.rs +++ b/swarm-derive/tests/test.rs @@ -59,7 +59,7 @@ fn two_fields() { #[derive(NetworkBehaviour)] struct Foo { ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, + identify: libp2p::identify::Behaviour, } #[allow(dead_code)] @@ -69,7 +69,7 @@ fn two_fields() { match _out_event { FooEvent::Ping(libp2p::ping::Event { .. }) => {} FooEvent::Identify(event) => { - let _: libp2p::identify::IdentifyEvent = event; + let _: libp2p::identify::Event = event; } } } @@ -81,7 +81,7 @@ fn three_fields() { #[derive(NetworkBehaviour)] struct Foo { ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, + identify: libp2p::identify::Behaviour, kad: libp2p::kad::Kademlia, } @@ -92,7 +92,7 @@ fn three_fields() { match _out_event { FooEvent::Ping(libp2p::ping::Event { .. }) => {} FooEvent::Identify(event) => { - let _: libp2p::identify::IdentifyEvent = event; + let _: libp2p::identify::Event = event; } FooEvent::Kad(event) => { let _: libp2p::kad::KademliaEvent = event; @@ -108,12 +108,12 @@ fn custom_event() { #[behaviour(out_event = "MyEvent")] struct Foo { ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, + identify: libp2p::identify::Behaviour, } enum MyEvent { Ping(libp2p::ping::PingEvent), - Identify(libp2p::identify::IdentifyEvent), + Identify(libp2p::identify::Event), } impl From for MyEvent { @@ -122,8 +122,8 @@ fn custom_event() { } } - impl From for MyEvent { - fn from(event: libp2p::identify::IdentifyEvent) -> Self { + impl From for MyEvent { + fn from(event: libp2p::identify::Event) -> Self { MyEvent::Identify(event) } } @@ -141,12 +141,12 @@ fn custom_event_mismatching_field_names() { #[behaviour(out_event = "MyEvent")] struct Foo { a: libp2p::ping::Ping, - b: libp2p::identify::Identify, + b: libp2p::identify::Behaviour, } enum MyEvent { Ping(libp2p::ping::PingEvent), - Identify(libp2p::identify::IdentifyEvent), + Identify(libp2p::identify::Event), } impl From for MyEvent { @@ -155,8 +155,8 @@ fn custom_event_mismatching_field_names() { } } - impl From for MyEvent { - fn from(event: libp2p::identify::IdentifyEvent) -> Self { + impl From for MyEvent { + fn from(event: libp2p::identify::Event) -> Self { MyEvent::Identify(event) } } @@ -222,7 +222,7 @@ fn nested_derives_with_import() { fn custom_event_emit_event_through_poll() { enum BehaviourOutEvent { Ping(libp2p::ping::PingEvent), - Identify(libp2p::identify::IdentifyEvent), + Identify(libp2p::identify::Event), } impl From for BehaviourOutEvent { @@ -231,8 +231,8 @@ fn custom_event_emit_event_through_poll() { } } - impl From for BehaviourOutEvent { - fn from(event: libp2p::identify::IdentifyEvent) -> Self { + impl From for BehaviourOutEvent { + fn from(event: libp2p::identify::Event) -> Self { BehaviourOutEvent::Identify(event) } } @@ -242,7 +242,7 @@ fn custom_event_emit_event_through_poll() { #[behaviour(out_event = "BehaviourOutEvent")] struct Foo { ping: libp2p::ping::Ping, - identify: libp2p::identify::Identify, + identify: libp2p::identify::Behaviour, } #[allow(dead_code, unreachable_code)] @@ -271,7 +271,7 @@ fn with_toggle() { #[allow(dead_code)] #[derive(NetworkBehaviour)] struct Foo { - identify: libp2p::identify::Identify, + identify: libp2p::identify::Behaviour, ping: Toggle, } @@ -289,7 +289,7 @@ fn with_either() { #[derive(NetworkBehaviour)] struct Foo { kad: libp2p::kad::Kademlia, - ping_or_identify: Either, + ping_or_identify: Either, } #[allow(dead_code)] @@ -304,7 +304,7 @@ fn custom_event_with_either() { enum BehaviourOutEvent { Kad(libp2p::kad::KademliaEvent), - PingOrIdentify(Either), + PingOrIdentify(Either), } impl From for BehaviourOutEvent { @@ -313,7 +313,7 @@ fn custom_event_with_either() { } } - impl From> for BehaviourOutEvent { + impl From> for BehaviourOutEvent { fn from(event: Either) -> Self { BehaviourOutEvent::PingOrIdentify(event) } @@ -324,7 +324,7 @@ fn custom_event_with_either() { #[behaviour(out_event = "BehaviourOutEvent")] struct Foo { kad: libp2p::kad::Kademlia, - ping_or_identify: Either, + ping_or_identify: Either, } #[allow(dead_code)] diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index a5bf0e06f060..67b2fc146077 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -90,23 +90,23 @@ pub(crate) type THandlerOutEvent = /// addition to the event `enum` itself. /// /// ``` rust -/// # use libp2p::identify::{Identify, IdentifyEvent}; +/// # use libp2p::identify; /// # use libp2p::ping::{Ping, PingEvent}; /// # use libp2p::NetworkBehaviour; /// #[derive(NetworkBehaviour)] /// #[behaviour(out_event = "Event")] /// struct MyBehaviour { -/// identify: Identify, +/// identify: identify::Behaviour, /// ping: Ping, /// } /// /// enum Event { -/// Identify(IdentifyEvent), +/// Identify(identify::Event), /// Ping(PingEvent), /// } /// -/// impl From for Event { -/// fn from(event: IdentifyEvent) -> Self { +/// impl From for Event { +/// fn from(event: identify::Event) -> Self { /// Self::Identify(event) /// } /// }