diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index 48b7802e..05a21df8 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use crate::listen_handler::IdentifyListenHandler; -use crate::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent}; +use crate::periodic_id_handler::{PeriodicIdHandler, PeriodicIdHandlerEvent}; use crate::protocol::{IdentifyInfo, IdentifySender, IdentifySenderFuture}; use futures::prelude::*; use libp2p_core::protocols_handler::{ProtocolsHandler, ProtocolsHandlerSelect}; @@ -65,11 +65,11 @@ impl NetworkBehaviour for Identify where TSubstream: AsyncRead + AsyncWrite, { - type ProtocolsHandler = ProtocolsHandlerSelect, PeriodicIdentification>; + type ProtocolsHandler = ProtocolsHandlerSelect, PeriodicIdHandler>; type OutEvent = IdentifyEvent; fn new_handler(&mut self) -> Self::ProtocolsHandler { - IdentifyListenHandler::new().select(PeriodicIdentification::new()) + IdentifyListenHandler::new().select(PeriodicIdHandler::new()) } fn inject_connected(&mut self, peer_id: PeerId, endpoint: ConnectedPoint) { @@ -91,7 +91,7 @@ where event: ::OutEvent, ) { match event { - EitherOutput::Second(PeriodicIdentificationEvent::Identified(remote)) => { + EitherOutput::Second(PeriodicIdHandlerEvent::Identified(remote)) => { self.events .push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Identified { peer_id, @@ -110,7 +110,7 @@ where disconnect; QED"); self.to_answer.push((sender, observed.clone())); } - EitherOutput::Second(PeriodicIdentificationEvent::IdentificationError(err)) => { + EitherOutput::Second(PeriodicIdHandlerEvent::IdentificationError(err)) => { self.events .push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Error { peer_id, diff --git a/protocols/identify/src/periodic_id_handler.rs b/protocols/identify/src/periodic_id_handler.rs index 5848f287..a6d256ed 100644 --- a/protocols/identify/src/periodic_id_handler.rs +++ b/protocols/identify/src/periodic_id_handler.rs @@ -37,13 +37,13 @@ const DELAY_TO_NEXT_ID: Duration = Duration::from_secs(5 * 60); const TRY_AGAIN_ON_ERR: Duration = Duration::from_secs(60 * 60); /// Protocol handler that identifies the remote at a regular period. -pub struct PeriodicIdentification { +pub struct PeriodicIdHandler { /// Configuration for the protocol. config: IdentifyProtocolConfig, - /// If `Some`, we successfully generated an `PeriodicIdentificationEvent` and we will produce + /// If `Some`, we successfully generated an `PeriodicIdHandlerEvent` and we will produce /// it the next time `poll()` is invoked. - pending_result: Option, + pending_result: Option, /// Future that fires when we need to identify the node again. If `None`, means that we should /// shut down. @@ -55,18 +55,18 @@ pub struct PeriodicIdentification { /// Event produced by the periodic identifier. #[derive(Debug)] -pub enum PeriodicIdentificationEvent { +pub enum PeriodicIdHandlerEvent { /// We obtained identification information from the remote Identified(RemoteInfo), /// Failed to identify the remote. IdentificationError(io::Error), } -impl PeriodicIdentification { - /// Builds a new `PeriodicIdentification`. +impl PeriodicIdHandler { + /// Builds a new `PeriodicIdHandler`. #[inline] pub fn new() -> Self { - PeriodicIdentification { + PeriodicIdHandler { config: IdentifyProtocolConfig, pending_result: None, next_id: Some(Delay::new(Instant::now() + DELAY_TO_FIRST_ID)), @@ -75,12 +75,12 @@ impl PeriodicIdentification { } } -impl ProtocolsHandler for PeriodicIdentification +impl ProtocolsHandler for PeriodicIdHandler where TSubstream: AsyncRead + AsyncWrite, { type InEvent = Void; - type OutEvent = PeriodicIdentificationEvent; + type OutEvent = PeriodicIdHandlerEvent; type Substream = TSubstream; type InboundProtocol = DeniedUpgrade; type OutboundProtocol = IdentifyProtocolConfig; @@ -100,7 +100,7 @@ where protocol: >::Output, _info: Self::OutboundOpenInfo, ) { - self.pending_result = Some(PeriodicIdentificationEvent::Identified(protocol)) + self.pending_result = Some(PeriodicIdHandlerEvent::Identified(protocol)) } #[inline] @@ -111,7 +111,7 @@ where #[inline] fn inject_dial_upgrade_error(&mut self, _: Self::OutboundOpenInfo, err: io::Error) { - self.pending_result = Some(PeriodicIdentificationEvent::IdentificationError(err)); + self.pending_result = Some(PeriodicIdHandlerEvent::IdentificationError(err)); if let Some(ref mut next_id) = self.next_id { next_id.reset(Instant::now() + TRY_AGAIN_ON_ERR); } @@ -129,7 +129,7 @@ where ProtocolsHandlerEvent< Self::OutboundProtocol, Self::OutboundOpenInfo, - PeriodicIdentificationEvent, + PeriodicIdHandlerEvent, >, >, io::Error, diff --git a/protocols/identify/src/periodic_id_layer.rs b/protocols/identify/src/periodic_id_layer.rs index 07f91625..e369edcc 100644 --- a/protocols/identify/src/periodic_id_layer.rs +++ b/protocols/identify/src/periodic_id_layer.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent}; +use crate::periodic_id_handler::{PeriodicIdHandler, PeriodicIdHandlerEvent}; use crate::protocol::IdentifyInfo; use futures::prelude::*; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; @@ -50,11 +50,11 @@ impl NetworkBehaviour for PeriodicIdentify; + type ProtocolsHandler = PeriodicIdHandler; type OutEvent = PeriodicIdentifyEvent; fn new_handler(&mut self) -> Self::ProtocolsHandler { - PeriodicIdentification::new() + PeriodicIdHandler::new() } fn inject_connected(&mut self, _: PeerId, _: ConnectedPoint) {} @@ -67,7 +67,7 @@ where event: ::OutEvent, ) { match event { - PeriodicIdentificationEvent::Identified(remote) => { + PeriodicIdHandlerEvent::Identified(remote) => { self.events .push_back(NetworkBehaviourAction::ReportObservedAddr { address: remote.observed_addr.clone(),