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 #[allow(unreachable_patterns)]
61 libp2p_core::util::unreachable(v)
62 }
63
64 fn poll(
65 &mut self,
66 _: &mut Context<'_>,
67 ) -> Poll<ConnectionHandlerEvent<Self::OutboundProtocol, Infallible, Self::ToBehaviour>> {
68 Poll::Pending
69 }
70
71 fn on_connection_event(
72 &mut self,
73 event: ConnectionEvent<Self::InboundProtocol, Self::OutboundProtocol, (), Infallible>,
74 ) {
75 match event {
76 #[allow(unreachable_patterns)]
78 ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
79 protocol, ..
80 }) => libp2p_core::util::unreachable(protocol),
81 #[allow(unreachable_patterns)]
83 ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
84 protocol,
85 info: _info,
86 }) => {
87 libp2p_core::util::unreachable(protocol);
88 #[allow(unreachable_code, clippy::used_underscore_binding)]
89 {
90 libp2p_core::util::unreachable(_info);
91 }
92 }
93 #[allow(unreachable_patterns)]
95 ConnectionEvent::AddressChange(_)
96 | ConnectionEvent::DialUpgradeError(_)
97 | ConnectionEvent::ListenUpgradeError(_)
98 | ConnectionEvent::LocalProtocolsChange(_)
99 | ConnectionEvent::RemoteProtocolsChange(_) => {}
100 }
101 }
102}