Skip to content

Commit

Permalink
Properly deprecate types with Ping prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Sep 23, 2022
1 parent 121a11c commit a772e5a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
9 changes: 4 additions & 5 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ use libp2p::{
identify::{Identify, IdentifyConfig, IdentifyEvent},
identity,
multiaddr::Protocol,
noise,
ping::{self, PingEvent},
noise, ping,
pnet::{PnetConfig, PreSharedKey},
swarm::SwarmEvent,
tcp::TcpTransport,
Expand Down Expand Up @@ -165,7 +164,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
enum MyBehaviourEvent {
Gossipsub(GossipsubEvent),
Identify(IdentifyEvent),
Ping(PingEvent),
Ping(ping::Event),
}

impl From<GossipsubEvent> for MyBehaviourEvent {
Expand All @@ -180,8 +179,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}

impl From<PingEvent> for MyBehaviourEvent {
fn from(event: PingEvent) -> Self {
impl From<ping::Event> for MyBehaviourEvent {
fn from(event: ping::Event) -> Self {
MyBehaviourEvent::Ping(event)
}
}
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 @@ -126,8 +126,8 @@ impl Recorder<libp2p_kad::KademliaEvent> for Metrics {
}

#[cfg(feature = "ping")]
impl Recorder<libp2p_ping::PingEvent> for Metrics {
fn record(&self, event: &libp2p_ping::PingEvent) {
impl Recorder<libp2p_ping::Event> for Metrics {
fn record(&self, event: &libp2p_ping::Event) {
self.ping.record(event)
}
}
Expand Down
18 changes: 9 additions & 9 deletions misc/metrics/src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ struct FailureLabels {
reason: Failure,
}

impl From<&libp2p_ping::PingFailure> for FailureLabels {
fn from(failure: &libp2p_ping::PingFailure) -> Self {
impl From<&libp2p_ping::Failure> for FailureLabels {
fn from(failure: &libp2p_ping::Failure) -> Self {
match failure {
libp2p_ping::PingFailure::Timeout => FailureLabels {
libp2p_ping::Failure::Timeout => FailureLabels {
reason: Failure::Timeout,
},
libp2p_ping::PingFailure::Unsupported => FailureLabels {
libp2p_ping::Failure::Unsupported => FailureLabels {
reason: Failure::Unsupported,
},
libp2p_ping::PingFailure::Other { .. } => FailureLabels {
libp2p_ping::Failure::Other { .. } => FailureLabels {
reason: Failure::Other,
},
}
Expand Down Expand Up @@ -92,13 +92,13 @@ impl Metrics {
}
}

impl super::Recorder<libp2p_ping::PingEvent> for Metrics {
fn record(&self, event: &libp2p_ping::PingEvent) {
impl super::Recorder<libp2p_ping::Event> for Metrics {
fn record(&self, event: &libp2p_ping::Event) {
match &event.result {
Ok(libp2p_ping::PingSuccess::Pong) => {
Ok(libp2p_ping::Success::Pong) => {
self.pong_received.inc();
}
Ok(libp2p_ping::PingSuccess::Ping { rtt }) => {
Ok(libp2p_ping::Success::Ping { rtt }) => {
self.rtt.observe(rtt.as_secs_f64());
}
Err(failure) => {
Expand Down
3 changes: 3 additions & 0 deletions protocols/ping/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# 0.39.1 [unreleased]

- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].
- Deprecate types with `Ping` prefix. Prefer importing them via the `ping` namespace, i.e. `libp2p::ping::Event` instead
of `libp2p::ping::PingEvent`. See [PR XXXX].

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

# 0.39.0

Expand Down
29 changes: 19 additions & 10 deletions protocols/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,25 @@ use std::{
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::{
protocol::PROTOCOL_NAME, 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;
#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Config instead.")]
pub type PingConfig = Config;

#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Event instead.")]
pub type PingEvent = Event;

#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Success instead.")]
pub type PingSuccess = Success;

#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Failure instead.")]
pub type PingFailure = Failure;

#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Result instead.")]
pub type PingResult = Result;

#[deprecated(since = "0.39.1", note = "Use libp2p::ping::Behaviour instead.")]
pub type Ping = Behaviour;

pub use self::protocol::PROTOCOL_NAME;

/// The result of an inbound or outbound ping.
pub type Result = std::result::Result<Success, Failure>;
Expand Down

0 comments on commit a772e5a

Please sign in to comment.