ant_libp2p_swarm/handler/
pending.rs1use std::{
23 convert::Infallible,
24 task::{Context, Poll},
25};
26
27use ant_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, Self::InboundOpenInfo> {
55 SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ())
56 }
57
58 fn on_behaviour_event(&mut self, v: Self::FromBehaviour) {
59 #[allow(unreachable_patterns)]
61 ant_libp2p_core::util::unreachable(v)
62 }
63
64 fn poll(
65 &mut self,
66 _: &mut Context<'_>,
67 ) -> Poll<
68 ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
69 > {
70 Poll::Pending
71 }
72
73 fn on_connection_event(
74 &mut self,
75 event: ConnectionEvent<
76 Self::InboundProtocol,
77 Self::OutboundProtocol,
78 Self::InboundOpenInfo,
79 Self::OutboundOpenInfo,
80 >,
81 ) {
82 match event {
83 #[allow(unreachable_patterns)]
85 ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
86 protocol, ..
87 }) => ant_libp2p_core::util::unreachable(protocol),
88 #[allow(unreachable_patterns)]
90 ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
91 protocol,
92 info: _info,
93 }) => {
94 ant_libp2p_core::util::unreachable(protocol);
95 #[allow(unreachable_code, clippy::used_underscore_binding)]
96 {
97 ant_libp2p_core::util::unreachable(_info);
98 }
99 }
100 #[allow(unreachable_patterns)]
102 ConnectionEvent::AddressChange(_)
103 | ConnectionEvent::DialUpgradeError(_)
104 | ConnectionEvent::ListenUpgradeError(_)
105 | ConnectionEvent::LocalProtocolsChange(_)
106 | ConnectionEvent::RemoteProtocolsChange(_) => {}
107 }
108 }
109}