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