Skip to content

Commit

Permalink
protocols/identify: Revise symbol naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Sep 22, 2022
1 parent e530118 commit 29154bd
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 232 deletions.
13 changes: 6 additions & 7 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -158,13 +157,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[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),
}

Expand All @@ -174,8 +173,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}

impl From<IdentifyEvent> for MyBehaviourEvent {
fn from(event: IdentifyEvent) -> Self {
impl From<identify::Event> for MyBehaviourEvent {
fn from(event: identify::Event) -> Self {
MyBehaviourEvent::Identify(event)
}
}
Expand All @@ -198,7 +197,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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(),
)),
Expand Down
12 changes: 6 additions & 6 deletions misc/metrics/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ impl Metrics {
}
}

impl super::Recorder<libp2p_identify::IdentifyEvent> for Metrics {
fn record(&self, event: &libp2p_identify::IdentifyEvent) {
impl super::Recorder<libp2p_identify::Event> 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<String> = info
.protocols
Expand Down Expand Up @@ -168,7 +168,7 @@ impl super::Recorder<libp2p_identify::IdentifyEvent> 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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions misc/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ impl Recorder<libp2p_gossipsub::GossipsubEvent> for Metrics {
}

#[cfg(feature = "identify")]
impl Recorder<libp2p_identify::IdentifyEvent> for Metrics {
fn record(&self, event: &libp2p_identify::IdentifyEvent) {
impl Recorder<libp2p_identify::Event> for Metrics {
fn record(&self, event: &libp2p_identify::Event) {
self.identify.record(event)
}
}
Expand Down
12 changes: 6 additions & 6 deletions protocols/autonat/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -91,14 +91,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[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(),
)),
Expand All @@ -119,11 +119,11 @@ impl Behaviour {
#[derive(Debug)]
enum Event {
AutoNat(autonat::Event),
Identify(IdentifyEvent),
Identify(identify::Event),
}

impl From<IdentifyEvent> for Event {
fn from(v: IdentifyEvent) -> Self {
impl From<identify::Event> for Event {
fn from(v: identify::Event) -> Self {
Self::Identify(v)
}
}
Expand Down
12 changes: 6 additions & 6 deletions protocols/autonat/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -76,14 +76,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[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(),
)),
Expand All @@ -98,11 +98,11 @@ impl Behaviour {
#[derive(Debug)]
enum Event {
AutoNat(autonat::Event),
Identify(IdentifyEvent),
Identify(identify::Event),
}

impl From<IdentifyEvent> for Event {
fn from(v: IdentifyEvent) -> Self {
impl From<identify::Event> for Event {
fn from(v: identify::Event) -> Self {
Self::Identify(v)
}
}
Expand Down
18 changes: 9 additions & 9 deletions protocols/dcutr/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -109,14 +109,14 @@ fn main() -> Result<(), Box<dyn Error>> {
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),
}
Expand All @@ -127,8 +127,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

impl From<IdentifyEvent> for Event {
fn from(e: IdentifyEvent) -> Self {
impl From<identify::Event> for Event {
fn from(e: identify::Event) -> Self {
Event::Identify(e)
}
}
Expand All @@ -148,7 +148,7 @@ fn main() -> Result<(), Box<dyn Error>> {
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(),
)),
Expand Down Expand Up @@ -201,12 +201,12 @@ fn main() -> Result<(), Box<dyn Error>> {
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);
Expand Down
8 changes: 8 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions protocols/identify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions protocols/identify/examples/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,7 +50,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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(),
));
Expand All @@ -74,11 +73,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
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)
}
_ => {}
Expand Down
Loading

0 comments on commit 29154bd

Please sign in to comment.