ant_libp2p_swarm/
dummy.rs1use std::{
2 convert::Infallible,
3 task::{Context, Poll},
4};
5
6use ant_libp2p_core::{transport::PortUse, upgrade::DeniedUpgrade, Endpoint, Multiaddr};
7use libp2p_identity::PeerId;
8
9use crate::{
10 behaviour::{FromSwarm, NetworkBehaviour, ToSwarm},
11 connection::ConnectionId,
12 handler::{ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound},
13 ConnectionDenied, ConnectionHandlerEvent, StreamUpgradeError, SubstreamProtocol, THandler,
14 THandlerInEvent, THandlerOutEvent,
15};
16
17pub struct Behaviour;
19
20impl NetworkBehaviour for Behaviour {
21 type ConnectionHandler = ConnectionHandler;
22 type ToSwarm = Infallible;
23
24 fn handle_established_inbound_connection(
25 &mut self,
26 _: ConnectionId,
27 _: PeerId,
28 _: &Multiaddr,
29 _: &Multiaddr,
30 ) -> Result<THandler<Self>, ConnectionDenied> {
31 Ok(ConnectionHandler)
32 }
33
34 fn handle_established_outbound_connection(
35 &mut self,
36 _: ConnectionId,
37 _: PeerId,
38 _: &Multiaddr,
39 _: Endpoint,
40 _: PortUse,
41 ) -> Result<THandler<Self>, ConnectionDenied> {
42 Ok(ConnectionHandler)
43 }
44
45 fn on_connection_handler_event(
46 &mut self,
47 _: PeerId,
48 _: ConnectionId,
49 event: THandlerOutEvent<Self>,
50 ) {
51 #[allow(unreachable_patterns)]
53 ant_libp2p_core::util::unreachable(event)
54 }
55
56 fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
57 Poll::Pending
58 }
59
60 fn on_swarm_event(&mut self, _event: FromSwarm) {}
61}
62
63#[derive(Clone)]
66pub struct ConnectionHandler;
67
68impl crate::handler::ConnectionHandler for ConnectionHandler {
69 type FromBehaviour = Infallible;
70 type ToBehaviour = Infallible;
71 type InboundProtocol = DeniedUpgrade;
72 type OutboundProtocol = DeniedUpgrade;
73 type InboundOpenInfo = ();
74 type OutboundOpenInfo = Infallible;
75
76 fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
77 SubstreamProtocol::new(DeniedUpgrade, ())
78 }
79
80 fn on_behaviour_event(&mut self, event: Self::FromBehaviour) {
81 #[allow(unreachable_patterns)]
83 ant_libp2p_core::util::unreachable(event)
84 }
85
86 fn poll(
87 &mut self,
88 _: &mut Context<'_>,
89 ) -> Poll<
90 ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
91 > {
92 Poll::Pending
93 }
94
95 fn on_connection_event(
96 &mut self,
97 event: ConnectionEvent<
98 Self::InboundProtocol,
99 Self::OutboundProtocol,
100 Self::InboundOpenInfo,
101 Self::OutboundOpenInfo,
102 >,
103 ) {
104 match event {
105 #[allow(unreachable_patterns)]
107 ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
108 protocol, ..
109 }) => ant_libp2p_core::util::unreachable(protocol),
110 #[allow(unreachable_patterns)]
112 ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
113 protocol, ..
114 }) => ant_libp2p_core::util::unreachable(protocol),
115 #[allow(unreachable_patterns)]
117 ConnectionEvent::DialUpgradeError(DialUpgradeError { info: _, error }) => match error {
118 #[allow(unreachable_patterns)]
120 StreamUpgradeError::Timeout => unreachable!(),
121 StreamUpgradeError::Apply(e) => ant_libp2p_core::util::unreachable(e),
122 StreamUpgradeError::NegotiationFailed | StreamUpgradeError::Io(_) => {
123 unreachable!("Denied upgrade does not support any protocols")
124 }
125 },
126 #[allow(unreachable_patterns)]
128 ConnectionEvent::AddressChange(_)
129 | ConnectionEvent::ListenUpgradeError(_)
130 | ConnectionEvent::LocalProtocolsChange(_)
131 | ConnectionEvent::RemoteProtocolsChange(_) => {}
132 }
133 }
134}