mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-24 23:31:33 +00:00
Add an error associated type to ProtocolsHandler (#795)
This commit is contained in:
@ -25,7 +25,6 @@ use libp2p_core::{
|
||||
upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade}
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::io;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use void::{Void, unreachable};
|
||||
|
||||
@ -59,6 +58,7 @@ where
|
||||
{
|
||||
type InEvent = Void;
|
||||
type OutEvent = IdentifySender<TSubstream>;
|
||||
type Error = Void;
|
||||
type Substream = TSubstream;
|
||||
type InboundProtocol = IdentifyProtocolConfig;
|
||||
type OutboundProtocol = DeniedUpgrade;
|
||||
@ -104,7 +104,7 @@ where
|
||||
Self::OutEvent,
|
||||
>,
|
||||
>,
|
||||
io::Error,
|
||||
Self::Error,
|
||||
> {
|
||||
if !self.pending_result.is_empty() {
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(
|
||||
|
@ -26,7 +26,7 @@ use libp2p_core::{
|
||||
};
|
||||
use std::{io, marker::PhantomData, time::{Duration, Instant}};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::Delay;
|
||||
use tokio_timer::{self, Delay};
|
||||
use void::{Void, unreachable};
|
||||
|
||||
/// Delay between the moment we connect and the first time we identify.
|
||||
@ -81,6 +81,7 @@ where
|
||||
{
|
||||
type InEvent = Void;
|
||||
type OutEvent = PeriodicIdHandlerEvent;
|
||||
type Error = tokio_timer::Error;
|
||||
type Substream = TSubstream;
|
||||
type InboundProtocol = DeniedUpgrade;
|
||||
type OutboundProtocol = IdentifyProtocolConfig;
|
||||
@ -132,7 +133,7 @@ where
|
||||
PeriodicIdHandlerEvent,
|
||||
>,
|
||||
>,
|
||||
io::Error,
|
||||
Self::Error,
|
||||
> {
|
||||
if let Some(pending_result) = self.pending_result.take() {
|
||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(
|
||||
@ -146,15 +147,14 @@ where
|
||||
};
|
||||
|
||||
// Poll the future that fires when we need to identify the node again.
|
||||
match next_id.poll() {
|
||||
Ok(Async::NotReady) => Ok(Async::NotReady),
|
||||
Ok(Async::Ready(())) => {
|
||||
match next_id.poll()? {
|
||||
Async::NotReady => Ok(Async::NotReady),
|
||||
Async::Ready(()) => {
|
||||
next_id.reset(Instant::now() + DELAY_TO_NEXT_ID);
|
||||
let upgrade = self.config.clone();
|
||||
let ev = ProtocolsHandlerEvent::OutboundSubstreamRequest { upgrade, info: () };
|
||||
Ok(Async::Ready(Some(ev)))
|
||||
}
|
||||
Err(err) => Err(io::Error::new(io::ErrorKind::Other, err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user