mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 18:41:22 +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.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use crate::listen_handler::IdentifyListenHandler;
|
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 crate::protocol::{IdentifyInfo, IdentifySender, IdentifySenderFuture};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p_core::protocols_handler::{ProtocolsHandler, ProtocolsHandlerSelect};
|
use libp2p_core::protocols_handler::{ProtocolsHandler, ProtocolsHandlerSelect};
|
||||||
@ -65,11 +65,11 @@ impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Identify<TSubstream>
|
|||||||
where
|
where
|
||||||
TSubstream: AsyncRead + AsyncWrite,
|
TSubstream: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type ProtocolsHandler = ProtocolsHandlerSelect<IdentifyListenHandler<TSubstream>, PeriodicIdentification<TSubstream>>;
|
type ProtocolsHandler = ProtocolsHandlerSelect<IdentifyListenHandler<TSubstream>, PeriodicIdHandler<TSubstream>>;
|
||||||
type OutEvent = IdentifyEvent;
|
type OutEvent = IdentifyEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
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) {
|
fn inject_connected(&mut self, peer_id: PeerId, endpoint: ConnectedPoint) {
|
||||||
@ -91,7 +91,7 @@ where
|
|||||||
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
EitherOutput::Second(PeriodicIdentificationEvent::Identified(remote)) => {
|
EitherOutput::Second(PeriodicIdHandlerEvent::Identified(remote)) => {
|
||||||
self.events
|
self.events
|
||||||
.push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Identified {
|
.push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Identified {
|
||||||
peer_id,
|
peer_id,
|
||||||
@ -110,7 +110,7 @@ where
|
|||||||
disconnect; QED");
|
disconnect; QED");
|
||||||
self.to_answer.push((sender, observed.clone()));
|
self.to_answer.push((sender, observed.clone()));
|
||||||
}
|
}
|
||||||
EitherOutput::Second(PeriodicIdentificationEvent::IdentificationError(err)) => {
|
EitherOutput::Second(PeriodicIdHandlerEvent::IdentificationError(err)) => {
|
||||||
self.events
|
self.events
|
||||||
.push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Error {
|
.push_back(NetworkBehaviourAction::GenerateEvent(IdentifyEvent::Error {
|
||||||
peer_id,
|
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);
|
const TRY_AGAIN_ON_ERR: Duration = Duration::from_secs(60 * 60);
|
||||||
|
|
||||||
/// Protocol handler that identifies the remote at a regular period.
|
/// Protocol handler that identifies the remote at a regular period.
|
||||||
pub struct PeriodicIdentification<TSubstream> {
|
pub struct PeriodicIdHandler<TSubstream> {
|
||||||
/// Configuration for the protocol.
|
/// Configuration for the protocol.
|
||||||
config: IdentifyProtocolConfig,
|
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.
|
/// 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
|
/// Future that fires when we need to identify the node again. If `None`, means that we should
|
||||||
/// shut down.
|
/// shut down.
|
||||||
@ -55,18 +55,18 @@ pub struct PeriodicIdentification<TSubstream> {
|
|||||||
|
|
||||||
/// Event produced by the periodic identifier.
|
/// Event produced by the periodic identifier.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PeriodicIdentificationEvent {
|
pub enum PeriodicIdHandlerEvent {
|
||||||
/// We obtained identification information from the remote
|
/// We obtained identification information from the remote
|
||||||
Identified(RemoteInfo),
|
Identified(RemoteInfo),
|
||||||
/// Failed to identify the remote.
|
/// Failed to identify the remote.
|
||||||
IdentificationError(io::Error),
|
IdentificationError(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TSubstream> PeriodicIdentification<TSubstream> {
|
impl<TSubstream> PeriodicIdHandler<TSubstream> {
|
||||||
/// Builds a new `PeriodicIdentification`.
|
/// Builds a new `PeriodicIdHandler`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PeriodicIdentification {
|
PeriodicIdHandler {
|
||||||
config: IdentifyProtocolConfig,
|
config: IdentifyProtocolConfig,
|
||||||
pending_result: None,
|
pending_result: None,
|
||||||
next_id: Some(Delay::new(Instant::now() + DELAY_TO_FIRST_ID)),
|
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
|
where
|
||||||
TSubstream: AsyncRead + AsyncWrite,
|
TSubstream: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type InEvent = Void;
|
type InEvent = Void;
|
||||||
type OutEvent = PeriodicIdentificationEvent;
|
type OutEvent = PeriodicIdHandlerEvent;
|
||||||
type Substream = TSubstream;
|
type Substream = TSubstream;
|
||||||
type InboundProtocol = DeniedUpgrade;
|
type InboundProtocol = DeniedUpgrade;
|
||||||
type OutboundProtocol = IdentifyProtocolConfig;
|
type OutboundProtocol = IdentifyProtocolConfig;
|
||||||
@ -100,7 +100,7 @@ where
|
|||||||
protocol: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
|
protocol: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
|
||||||
_info: Self::OutboundOpenInfo,
|
_info: Self::OutboundOpenInfo,
|
||||||
) {
|
) {
|
||||||
self.pending_result = Some(PeriodicIdentificationEvent::Identified(protocol))
|
self.pending_result = Some(PeriodicIdHandlerEvent::Identified(protocol))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -111,7 +111,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inject_dial_upgrade_error(&mut self, _: Self::OutboundOpenInfo, err: io::Error) {
|
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 {
|
if let Some(ref mut next_id) = self.next_id {
|
||||||
next_id.reset(Instant::now() + TRY_AGAIN_ON_ERR);
|
next_id.reset(Instant::now() + TRY_AGAIN_ON_ERR);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ where
|
|||||||
ProtocolsHandlerEvent<
|
ProtocolsHandlerEvent<
|
||||||
Self::OutboundProtocol,
|
Self::OutboundProtocol,
|
||||||
Self::OutboundOpenInfo,
|
Self::OutboundOpenInfo,
|
||||||
PeriodicIdentificationEvent,
|
PeriodicIdHandlerEvent,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
io::Error,
|
io::Error,
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use crate::periodic_id_handler::{PeriodicIdentification, PeriodicIdentificationEvent};
|
use crate::periodic_id_handler::{PeriodicIdHandler, PeriodicIdHandlerEvent};
|
||||||
use crate::protocol::IdentifyInfo;
|
use crate::protocol::IdentifyInfo;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||||
@ -50,11 +50,11 @@ impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for PeriodicIdentify<TSu
|
|||||||
where
|
where
|
||||||
TSubstream: AsyncRead + AsyncWrite,
|
TSubstream: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type ProtocolsHandler = PeriodicIdentification<TSubstream>;
|
type ProtocolsHandler = PeriodicIdHandler<TSubstream>;
|
||||||
type OutEvent = PeriodicIdentifyEvent;
|
type OutEvent = PeriodicIdentifyEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||||
PeriodicIdentification::new()
|
PeriodicIdHandler::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_connected(&mut self, _: PeerId, _: ConnectedPoint) {}
|
fn inject_connected(&mut self, _: PeerId, _: ConnectedPoint) {}
|
||||||
@ -67,7 +67,7 @@ where
|
|||||||
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
PeriodicIdentificationEvent::Identified(remote) => {
|
PeriodicIdHandlerEvent::Identified(remote) => {
|
||||||
self.events
|
self.events
|
||||||
.push_back(NetworkBehaviourAction::ReportObservedAddr {
|
.push_back(NetworkBehaviourAction::ReportObservedAddr {
|
||||||
address: remote.observed_addr.clone(),
|
address: remote.observed_addr.clone(),
|
||||||
|
Reference in New Issue
Block a user