refactor(dcutr): reshape public API to follow naming guidelines (#3214)

With this patch, the naming of types follows the guidelines discussed in #2217.
This commit is contained in:
Thomas Eizinger
2022-12-20 16:03:40 +11:00
committed by GitHub
parent 06aa694d0a
commit 93335b8818
7 changed files with 65 additions and 32 deletions

View File

@ -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}.")]
@ -164,7 +164,7 @@ impl Behaviour {
.into(),
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
remote_peer_id: peer_id,
error: UpgradeError::Dial,
error: Error::Dial,
})
.into(),
]);
@ -236,7 +236,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(),
);
@ -260,7 +260,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(),
);

View File

@ -23,7 +23,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
pub mod behaviour;
mod behaviour_impl; // TODO: Rename back `behaviour` once deprecation symbols are removed.
mod handler;
mod protocol;
#[allow(clippy::derive_partial_eq_without_eq)]
@ -31,6 +31,35 @@ 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 type InboundUpgradeError = protocol::inbound::UpgradeError;
pub type OutboundUpgradeError = protocol::outbound::UpgradeError;
pub mod inbound {
pub use crate::protocol::inbound::UpgradeError;
}
pub mod outbound {
pub use crate::protocol::outbound::UpgradeError;
}
#[deprecated(
since = "0.9.0",
note = "Use `libp2p_dcutr::inbound::UpgradeError` instead.`"
)]
pub type InboundUpgradeError = inbound::UpgradeError;
#[deprecated(
since = "0.9.0",
note = "Use `libp2p_dcutr::outbound::UpgradeError` instead.`"
)]
pub type OutboundUpgradeError = outbound::UpgradeError;
pub mod behaviour {
#[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Behaviour` instead.`")]
pub type Behaviour = crate::Behaviour;
#[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Event` instead.`")]
pub type Event = crate::Event;
#[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Error` instead.`")]
pub type UpgradeError = crate::Error;
}