Add EitherUpgrade and generalise OrUpgrade. (#662)

This commit is contained in:
Toralf Wittner
2018-11-20 15:09:59 +01:00
committed by GitHub
parent b213fd7bd7
commit 938b91742f
11 changed files with 179 additions and 368 deletions

View File

@ -23,7 +23,7 @@ use libp2p_core::{
OutboundUpgrade,
ProtocolsHandler,
ProtocolsHandlerEvent,
upgrade::{self, DeniedUpgrade}
upgrade::DeniedUpgrade
};
use log::warn;
use protocol::{Ping, PingDialer};
@ -40,7 +40,7 @@ use void::{Void, unreachable};
/// If the remote doesn't respond, produces `Unresponsive` and closes the connection.
pub struct PeriodicPingHandler<TSubstream> {
/// Configuration for the ping protocol.
ping_config: upgrade::Toggleable<Ping<Instant>>,
ping_config: Ping<Instant>,
/// State of the outgoing ping.
out_state: OutState<TSubstream>,
@ -128,7 +128,7 @@ impl<TSubstream> PeriodicPingHandler<TSubstream> {
let ping_timeout = Duration::from_secs(30);
PeriodicPingHandler {
ping_config: upgrade::toggleable(Default::default()),
ping_config: Default::default(),
out_state: OutState::NeedToOpen {
expires: Delay::new(Instant::now() + ping_timeout),
},
@ -154,7 +154,7 @@ where
type OutEvent = OutEvent;
type Substream = TSubstream;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = upgrade::Toggleable<Ping<Instant>>;
type OutboundProtocol = Ping<Instant>;
type OutboundOpenInfo = ();
#[inline]
@ -162,11 +162,6 @@ where
DeniedUpgrade
}
#[inline]
fn dialer_protocol(&self) -> Self::OutboundProtocol {
self.ping_config
}
fn inject_fully_negotiated_inbound(&mut self, protocol: Void) {
unreachable(protocol)
}

View File

@ -80,11 +80,6 @@ where
self.ping_config
}
#[inline]
fn dialer_protocol(&self) -> Self::OutboundProtocol {
DeniedUpgrade
}
fn inject_fully_negotiated_inbound(
&mut self,
protocol: <Self::InboundProtocol as InboundUpgrade<TSubstream>>::Output