mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
Rename PeriodicIdentification to PeriodicIdHandler (#757)
* Rename PeriodicIdentification to PeriodicIdentificationHandler * Concern
This commit is contained in:
@ -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<TSubstream, TTopology> NetworkBehaviour<TTopology> for Identify<TSubstream>
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type ProtocolsHandler = ProtocolsHandlerSelect<IdentifyListenHandler<TSubstream>, PeriodicIdentification<TSubstream>>;
|
||||
type ProtocolsHandler = ProtocolsHandlerSelect<IdentifyListenHandler<TSubstream>, PeriodicIdHandler<TSubstream>>;
|
||||
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: <Self::ProtocolsHandler as ProtocolsHandler>::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,
|
||||
|
@ -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<TSubstream> {
|
||||
pub struct PeriodicIdHandler<TSubstream> {
|
||||
/// 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<PeriodicIdentificationEvent>,
|
||||
pending_result: Option<PeriodicIdHandlerEvent>,
|
||||
|
||||
/// 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<TSubstream> {
|
||||
|
||||
/// 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<TSubstream> PeriodicIdentification<TSubstream> {
|
||||
/// Builds a new `PeriodicIdentification`.
|
||||
impl<TSubstream> PeriodicIdHandler<TSubstream> {
|
||||
/// 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<TSubstream> PeriodicIdentification<TSubstream> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> ProtocolsHandler for PeriodicIdentification<TSubstream>
|
||||
impl<TSubstream> ProtocolsHandler for PeriodicIdHandler<TSubstream>
|
||||
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: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::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,
|
||||
|
@ -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<TSubstream, TTopology> NetworkBehaviour<TTopology> for PeriodicIdentify<TSu
|
||||
where
|
||||
TSubstream: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type ProtocolsHandler = PeriodicIdentification<TSubstream>;
|
||||
type ProtocolsHandler = PeriodicIdHandler<TSubstream>;
|
||||
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: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
||||
) {
|
||||
match event {
|
||||
PeriodicIdentificationEvent::Identified(remote) => {
|
||||
PeriodicIdHandlerEvent::Identified(remote) => {
|
||||
self.events
|
||||
.push_back(NetworkBehaviourAction::ReportObservedAddr {
|
||||
address: remote.observed_addr.clone(),
|
||||
|
Reference in New Issue
Block a user