Skip to content

Commit

Permalink
Rename public API symbols
Browse files Browse the repository at this point in the history
This follows the guidelines discussed in #2217.
  • Loading branch information
thomaseizinger committed Dec 8, 2022
1 parent 1c2712c commit 160a9c6
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@

# `libp2p` facade crate

# 0.50.1

- Update individual crates.
- Update to [`libp2p-dcutr` `v0.8.1`](protocols/dcutr/CHANGELOG.md#081).

# 0.50.0

This is a large release. After > 4 years, rust-libp2p ships with an [(alpha) QUIC
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition = "2021"
rust-version = "1.62.0"
description = "Peer-to-peer networking library"
version = "0.50.0"
version = "0.50.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -94,7 +94,7 @@ instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature

libp2p-autonat = { version = "0.9.0", path = "protocols/autonat", optional = true }
libp2p-core = { version = "0.38.0", path = "core" }
libp2p-dcutr = { version = "0.8.0", path = "protocols/dcutr", optional = true }
libp2p-dcutr = { version = "0.8.1", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.41.0", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.41.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.42.0", path = "protocols/kad", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.11.1 [unreleased]

- Update to `libp2p-dcutr` `v0.8.1`.

# 0.11.0

- Update to `libp2p-dcutr` `v0.8.0`.
Expand Down
4 changes: 2 additions & 2 deletions misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-metrics"
edition = "2021"
rust-version = "1.62.0"
description = "Metrics for libp2p"
version = "0.11.0"
version = "0.11.1"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -20,7 +20,7 @@ dcutr = ["libp2p-dcutr"]

[dependencies]
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-dcutr = { version = "0.8.0", path = "../../protocols/dcutr", optional = true }
libp2p-dcutr = { version = "0.8.1", path = "../../protocols/dcutr", optional = true }
libp2p-identify = { version = "0.41.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.42.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.41.0", path = "../../protocols/ping", optional = true }
Expand Down
20 changes: 10 additions & 10 deletions misc/metrics/src/dcutr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,30 @@ enum EventType {
DirectConnectionUpgradeFailed,
}

impl From<&libp2p_dcutr::behaviour::Event> for EventType {
fn from(event: &libp2p_dcutr::behaviour::Event) -> Self {
impl From<&libp2p_dcutr::Event> for EventType {
fn from(event: &libp2p_dcutr::Event) -> Self {
match event {
libp2p_dcutr::behaviour::Event::InitiatedDirectConnectionUpgrade {
libp2p_dcutr::Event::InitiatedDirectConnectionUpgrade {
remote_peer_id: _,
local_relayed_addr: _,
} => EventType::InitiateDirectConnectionUpgrade,
libp2p_dcutr::behaviour::Event::RemoteInitiatedDirectConnectionUpgrade {
libp2p_dcutr::Event::RemoteInitiatedDirectConnectionUpgrade {
remote_peer_id: _,
remote_relayed_addr: _,
} => EventType::RemoteInitiatedDirectConnectionUpgrade,
libp2p_dcutr::behaviour::Event::DirectConnectionUpgradeSucceeded {
remote_peer_id: _,
} => EventType::DirectConnectionUpgradeSucceeded,
libp2p_dcutr::behaviour::Event::DirectConnectionUpgradeFailed {
libp2p_dcutr::Event::DirectConnectionUpgradeSucceeded { remote_peer_id: _ } => {
EventType::DirectConnectionUpgradeSucceeded
}
libp2p_dcutr::Event::DirectConnectionUpgradeFailed {
remote_peer_id: _,
error: _,
} => EventType::DirectConnectionUpgradeFailed,
}
}
}

impl super::Recorder<libp2p_dcutr::behaviour::Event> for Metrics {
fn record(&self, event: &libp2p_dcutr::behaviour::Event) {
impl super::Recorder<libp2p_dcutr::Event> for Metrics {
fn record(&self, event: &libp2p_dcutr::Event) {
self.events
.get_or_create(&EventLabels {
event: event.into(),
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 @@ -100,8 +100,8 @@ pub trait Recorder<Event> {
}

#[cfg(feature = "dcutr")]
impl Recorder<libp2p_dcutr::behaviour::Event> for Metrics {
fn record(&self, event: &libp2p_dcutr::behaviour::Event) {
impl Recorder<libp2p_dcutr::Event> for Metrics {
fn record(&self, event: &libp2p_dcutr::Event) {
self.dcutr.record(event)
}
}
Expand Down
7 changes: 7 additions & 0 deletions protocols/dcutr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.8.1 [unreleased]

- Deprecate various API symbols to follow the conventions discussed in [issue 2217]. See [PR XXXX].

[issue 2217]: https://github.com/libp2p/rust-libp2p/issues/2217
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX

# 0.8.0

- Update to `prost-codec` `v0.3.0`.
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-dcutr"
edition = "2021"
rust-version = "1.62.0"
description = "Direct connection upgrade through relay"
version = "0.8.0"
version = "0.8.1"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
10 changes: 5 additions & 5 deletions protocols/dcutr/examples/dcutr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn main() -> Result<(), Box<dyn Error>> {
relay_client: Client,
ping: ping::Behaviour,
identify: identify::Behaviour,
dcutr: dcutr::behaviour::Behaviour,
dcutr: dcutr::Behaviour,
}

#[derive(Debug)]
Expand All @@ -118,7 +118,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Ping(ping::Event),
Identify(identify::Event),
Relay(client::Event),
Dcutr(dcutr::behaviour::Event),
Dcutr(dcutr::Event),
}

impl From<ping::Event> for Event {
Expand All @@ -139,8 +139,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

impl From<dcutr::behaviour::Event> for Event {
fn from(e: dcutr::behaviour::Event) -> Self {
impl From<dcutr::Event> for Event {
fn from(e: dcutr::Event) -> Self {
Event::Dcutr(e)
}
}
Expand All @@ -152,7 +152,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"/TODO/0.0.1".to_string(),
local_key.public(),
)),
dcutr: dcutr::behaviour::Behaviour::new(),
dcutr: dcutr::Behaviour::new(),
};

let mut swarm = match ThreadPool::new() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ pub enum Event {
},
DirectConnectionUpgradeFailed {
remote_peer_id: PeerId,
error: UpgradeError,
error: Error,
},
}

#[derive(Debug, Error)]
pub enum UpgradeError {
pub enum Error {
#[error("Failed to dial peer.")]
Dial,
#[error("Failed to establish substream: {0}.")]
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Behaviour {
.into(),
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
remote_peer_id: peer_id,
error: UpgradeError::Dial,
error: Error::Dial,
})
.into(),
]);
Expand Down Expand Up @@ -231,7 +231,7 @@ impl NetworkBehaviour for Behaviour {
self.queued_actions.push_back(
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
remote_peer_id: event_source,
error: UpgradeError::Handler(error),
error: Error::Handler(error),
})
.into(),
);
Expand All @@ -255,7 +255,7 @@ impl NetworkBehaviour for Behaviour {
self.queued_actions.push_back(
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
remote_peer_id: event_source,
error: UpgradeError::Handler(error),
error: Error::Handler(error),
})
.into(),
);
Expand Down
12 changes: 9 additions & 3 deletions protocols/dcutr/src/handler/relayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ pub struct Handler {
/// A pending fatal error that results in the connection being closed.
pending_error: Option<
ConnectionHandlerUpgrErr<
EitherError<protocol::inbound::UpgradeError, protocol::outbound::UpgradeError>,
EitherError<
protocol::inbound::InboundUpgradeError,
protocol::outbound::OutboundUpgradeError,
>,
>,
>,
/// Queue of events to return when polled.
Expand All @@ -148,7 +151,7 @@ pub struct Handler {
>,
/// Inbound connect, accepted by the behaviour, pending completion.
inbound_connect:
Option<BoxFuture<'static, Result<Vec<Multiaddr>, protocol::inbound::UpgradeError>>>,
Option<BoxFuture<'static, Result<Vec<Multiaddr>, protocol::inbound::InboundUpgradeError>>>,
keep_alive: KeepAlive,
}

Expand Down Expand Up @@ -302,7 +305,10 @@ impl ConnectionHandler for Handler {
type InEvent = Command;
type OutEvent = Event;
type Error = ConnectionHandlerUpgrErr<
EitherError<protocol::inbound::UpgradeError, protocol::outbound::UpgradeError>,
EitherError<
protocol::inbound::InboundUpgradeError,
protocol::outbound::OutboundUpgradeError,
>,
>;
type InboundProtocol = upgrade::EitherUpgrade<protocol::inbound::Upgrade, DeniedUpgrade>;
type OutboundProtocol = protocol::outbound::Upgrade;
Expand Down
43 changes: 36 additions & 7 deletions protocols/dcutr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,45 @@

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub mod behaviour;
mod behaviour_impl;
mod handler;
mod protocol;

pub use protocol::{
inbound::UpgradeError as InboundUpgradeError, outbound::UpgradeError as OutboundUpgradeError,
PROTOCOL_NAME,
};

#[allow(clippy::derive_partial_eq_without_eq)]
mod message_proto {
include!(concat!(env!("OUT_DIR"), "/holepunch.pb.rs"));
}

pub use behaviour_impl::Behaviour;
pub use behaviour_impl::Error;
pub use behaviour_impl::Event;
pub use protocol::PROTOCOL_NAME;
pub mod inbound {
pub use crate::protocol::inbound::InboundUpgradeError as UpgradeError; // TODO: Rename the inner error once `cargo-semver-checks` supports it: https://github.com/obi1kenobi/cargo-semver-checks/issues/152
}

pub mod outbound {
pub use crate::protocol::outbound::OutboundUpgradeError as UpgradeError; // TODO: Rename the inner error once `cargo-semver-checks` supports it: https://github.com/obi1kenobi/cargo-semver-checks/issues/152
}

#[deprecated(
since = "0.8.1",
note = "Use `libp2p_dcutr::inbound::UpgradeError` instead.`"
)]
pub type InboundUpgradeError = inbound::UpgradeError;

#[deprecated(
since = "0.8.1",
note = "Use `libp2p_dcutr::outbound::UpgradeError` instead.`"
)]
pub type OutboundUpgradeError = outbound::UpgradeError;

pub mod behaviour {
#[deprecated(since = "0.8.1", note = "Use `libp2p_dcutr::Behaviour` instead.`")]
pub type Behaviour = crate::Behaviour;

#[deprecated(since = "0.8.1", note = "Use `libp2p_dcutr::Event` instead.`")]
pub type Event = crate::Event;

#[deprecated(since = "0.8.1", note = "Use `libp2p_dcutr::Error` instead.`")]
pub type UpgradeError = crate::Error;
}
28 changes: 16 additions & 12 deletions protocols/dcutr/src/protocol/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl upgrade::UpgradeInfo for Upgrade {

impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
type Output = PendingConnect;
type Error = UpgradeError;
type Error = InboundUpgradeError;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;

fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
Expand All @@ -50,11 +50,13 @@ impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
);

async move {
let HolePunch { r#type, obs_addrs } =
substream.next().await.ok_or(UpgradeError::StreamClosed)??;
let HolePunch { r#type, obs_addrs } = substream
.next()
.await
.ok_or(InboundUpgradeError::StreamClosed)??;

let obs_addrs = if obs_addrs.is_empty() {
return Err(UpgradeError::NoAddresses);
return Err(InboundUpgradeError::NoAddresses);
} else {
obs_addrs
.into_iter()
Expand All @@ -65,14 +67,15 @@ impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
Err(_) => true,
})
.collect::<Result<Vec<Multiaddr>, _>>()
.map_err(|_| UpgradeError::InvalidAddrs)?
.map_err(|_| InboundUpgradeError::InvalidAddrs)?
};

let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?;
let r#type =
hole_punch::Type::from_i32(r#type).ok_or(InboundUpgradeError::ParseTypeField)?;

match r#type {
hole_punch::Type::Connect => {}
hole_punch::Type::Sync => return Err(UpgradeError::UnexpectedTypeSync),
hole_punch::Type::Sync => return Err(InboundUpgradeError::UnexpectedTypeSync),
}

Ok(PendingConnect {
Expand All @@ -93,7 +96,7 @@ impl PendingConnect {
pub async fn accept(
mut self,
local_obs_addrs: Vec<Multiaddr>,
) -> Result<Vec<Multiaddr>, UpgradeError> {
) -> Result<Vec<Multiaddr>, InboundUpgradeError> {
let msg = HolePunch {
r#type: hole_punch::Type::Connect.into(),
obs_addrs: local_obs_addrs.into_iter().map(|a| a.to_vec()).collect(),
Expand All @@ -104,11 +107,12 @@ impl PendingConnect {
.substream
.next()
.await
.ok_or(UpgradeError::StreamClosed)??;
.ok_or(InboundUpgradeError::StreamClosed)??;

let r#type = hole_punch::Type::from_i32(r#type).ok_or(UpgradeError::ParseTypeField)?;
let r#type =
hole_punch::Type::from_i32(r#type).ok_or(InboundUpgradeError::ParseTypeField)?;
match r#type {
hole_punch::Type::Connect => return Err(UpgradeError::UnexpectedTypeConnect),
hole_punch::Type::Connect => return Err(InboundUpgradeError::UnexpectedTypeConnect),
hole_punch::Type::Sync => {}
}

Expand All @@ -117,7 +121,7 @@ impl PendingConnect {
}

#[derive(Debug, Error)]
pub enum UpgradeError {
pub enum InboundUpgradeError {
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
Expand Down

0 comments on commit 160a9c6

Please sign in to comment.