libp2p_swarm/handler/
pending.rs1use crate::handler::{
23 ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound,
24 FullyNegotiatedOutbound, 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 InboundProtocol = PendingUpgrade<String>;
46 type OutboundProtocol = PendingUpgrade<String>;
47 type OutboundOpenInfo = Void;
48 type InboundOpenInfo = ();
49
50 fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
51 SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ())
52 }
53
54 fn on_behaviour_event(&mut self, v: Self::FromBehaviour) {
55 void::unreachable(v)
56 }
57
58 fn poll(
59 &mut self,
60 _: &mut Context<'_>,
61 ) -> Poll<
62 ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
63 > {
64 Poll::Pending
65 }
66
67 fn on_connection_event(
68 &mut self,
69 event: ConnectionEvent<
70 Self::InboundProtocol,
71 Self::OutboundProtocol,
72 Self::InboundOpenInfo,
73 Self::OutboundOpenInfo,
74 >,
75 ) {
76 match event {
77 ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
78 protocol, ..
79 }) => void::unreachable(protocol),
80 ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
81 protocol,
82 info: _info,
83 }) => {
84 void::unreachable(protocol);
85 #[allow(unreachable_code, clippy::used_underscore_binding)]
86 {
87 void::unreachable(_info);
88 }
89 }
90 ConnectionEvent::AddressChange(_)
91 | ConnectionEvent::DialUpgradeError(_)
92 | ConnectionEvent::ListenUpgradeError(_)
93 | ConnectionEvent::LocalProtocolsChange(_)
94 | ConnectionEvent::RemoteProtocolsChange(_) => {}
95 }
96 }
97}