Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocols/identify: Revise symbol naming #2927

Merged
merged 7 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

- [PR 2918]: https://github.com/libp2p/rust-libp2p/pull/2918

- Update to [`libp2p-identify` `v0.39.1`](protocols/identify/CHANGELOG.md#0391).

# 0.48.0

- Update to [`libp2p-core` `v0.36.0`](core/CHANGELOG.md#0360).
Expand Down
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,
mxinden marked this conversation as resolved.
Show resolved Hide resolved
multiaddr::Protocol,
noise, ping,
pnet::{PnetConfig, PreSharedKey},
Expand Down Expand Up @@ -157,13 +156,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(ping::Event),
}

Expand All @@ -173,8 +172,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 @@ -197,7 +196,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
2 changes: 1 addition & 1 deletion misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 0.10.0 [unreleased]

- Update to `libp2p-kad` `v0.41.0`.
-

- Update to `libp2p-identify` `v0.39.1`.

- Update to `libp2p-swarm` `v0.40.0`.
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/autonat_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/autonat_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/dcutr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libp2p::core::multiaddr::{Multiaddr, Protocol};
use libp2p::core::transport::OrTransport;
use libp2p::core::upgrade;
use libp2p::dns::DnsConfig;
use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent, IdentifyInfo};
use libp2p::identify;
use libp2p::noise;
use libp2p::relay::v2::client::{self, Client};
use libp2p::swarm::{SwarmBuilder, SwarmEvent};
Expand Down Expand Up @@ -108,14 +108,14 @@ fn main() -> Result<(), Box<dyn Error>> {
struct Behaviour {
relay_client: Client,
ping: ping::Behaviour,
identify: Identify,
identify: identify::Behaviour,
dcutr: dcutr::behaviour::Behaviour,
}

#[derive(Debug)]
enum Event {
Ping(ping::Event),
Identify(IdentifyEvent),
Identify(identify::Event),
Relay(client::Event),
Dcutr(dcutr::behaviour::Event),
}
Expand All @@ -126,8 +126,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 @@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let behaviour = Behaviour {
relay_client: client,
ping: ping::Behaviour::new(ping::Config::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 @@ -200,12 +200,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 @@ -2,6 +2,14 @@

- Update dependencies.

- 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
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

- Update to `libp2p-core` `v0.37.0`.

- Update to `libp2p-swarm` `v0.40.0`.
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