use std::{
convert::Infallible,
task::{Context, Poll},
};
use libp2p_core::upgrade::PendingUpgrade;
use crate::handler::{
ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound,
FullyNegotiatedOutbound, SubstreamProtocol,
};
#[derive(Clone, Debug)]
pub struct PendingConnectionHandler {
protocol_name: String,
}
impl PendingConnectionHandler {
pub fn new(protocol_name: String) -> Self {
PendingConnectionHandler { protocol_name }
}
}
impl ConnectionHandler for PendingConnectionHandler {
type FromBehaviour = Infallible;
type ToBehaviour = Infallible;
type InboundProtocol = PendingUpgrade<String>;
type OutboundProtocol = PendingUpgrade<String>;
type OutboundOpenInfo = Infallible;
type InboundOpenInfo = ();
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol> {
SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ())
}
fn on_behaviour_event(&mut self, v: Self::FromBehaviour) {
libp2p_core::util::unreachable(v)
}
fn poll(
&mut self,
_: &mut Context<'_>,
) -> Poll<ConnectionHandlerEvent<Self::OutboundProtocol, Infallible, Self::ToBehaviour>> {
Poll::Pending
}
fn on_connection_event(
&mut self,
event: ConnectionEvent<Self::InboundProtocol, Self::OutboundProtocol, (), Infallible>,
) {
match event {
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
protocol, ..
}) => libp2p_core::util::unreachable(protocol),
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol,
info: _info,
}) => {
libp2p_core::util::unreachable(protocol);
#[allow(unreachable_code, clippy::used_underscore_binding)]
{
libp2p_core::util::unreachable(_info);
}
}
ConnectionEvent::AddressChange(_)
| ConnectionEvent::DialUpgradeError(_)
| ConnectionEvent::ListenUpgradeError(_)
| ConnectionEvent::LocalProtocolsChange(_)
| ConnectionEvent::RemoteProtocolsChange(_) => {}
}
}
}