libp2p_swarm/handler/
pending.rs1use std::{
23 convert::Infallible,
24 task::{Context, Poll},
25};
26
27use libp2p_core::upgrade::PendingUpgrade;
28
29use crate::handler::{
30 ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound,
31 FullyNegotiatedOutbound, SubstreamProtocol,
32};
33
34#[derive(Clone, Debug)]
36pub struct PendingConnectionHandler {
37 protocol_name: String,
38}
39
40impl PendingConnectionHandler {
41 pub fn new(protocol_name: String) -> Self {
42 PendingConnectionHandler { protocol_name }
43 }
44}
45
46impl ConnectionHandler for PendingConnectionHandler {
47 type FromBehaviour = Infallible;
48 type ToBehaviour = Infallible;
49 type InboundProtocol = PendingUpgrade<String>;
50 type OutboundProtocol = PendingUpgrade<String>;
51 type OutboundOpenInfo = Infallible;
52 type InboundOpenInfo = ();
53
54 fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol> {
55 SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ())
56 }
57
58 fn on_behaviour_event(&mut self, v: Self::FromBehaviour) {
59 libp2p_core::util::unreachable(v)
60 }
61
62 fn poll(
63 &mut self,
64 _: &mut Context<'_>,
65 ) -> Poll<ConnectionHandlerEvent<Self::OutboundProtocol, Infallible, Self::ToBehaviour>> {
66 Poll::Pending
67 }
68
69 fn on_connection_event(
70 &mut self,
71 event: ConnectionEvent<Self::InboundProtocol, Self::OutboundProtocol, (), Infallible>,
72 ) {
73 match event {
74 ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
75 protocol, ..
76 }) => libp2p_core::util::unreachable(protocol),
77 ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
78 protocol,
79 info: _info,
80 }) => {
81 libp2p_core::util::unreachable(protocol);
82 #[allow(unreachable_code, clippy::used_underscore_binding)]
83 {
84 libp2p_core::util::unreachable(_info);
85 }
86 }
87 ConnectionEvent::AddressChange(_)
88 | ConnectionEvent::DialUpgradeError(_)
89 | ConnectionEvent::ListenUpgradeError(_)
90 | ConnectionEvent::LocalProtocolsChange(_)
91 | ConnectionEvent::RemoteProtocolsChange(_) => {}
92 }
93 }
94}