volans_swarm/handler/
dummy.rs1use std::{
2 convert::Infallible,
3 task::{Context, Poll},
4};
5
6use volans_core::upgrade::{DeniedUpgrade, PendingUpgrade};
7
8use crate::{
9 ConnectionHandler, ConnectionHandlerEvent, InboundStreamHandler, InboundUpgradeSend,
10 OutboundStreamHandler, StreamUpgradeError, SubstreamProtocol,
11};
12
13#[derive(Clone, Debug)]
14pub struct DummyHandler;
15
16impl ConnectionHandler for DummyHandler {
17 type Action = Infallible;
18 type Event = Infallible;
19 fn handle_action(&mut self, _action: Self::Action) {
20 unreachable!("PendingConnectionHandler does not handle actions");
21 }
22 fn poll(&mut self, _cx: &mut Context<'_>) -> Poll<ConnectionHandlerEvent<Self::Event>> {
23 Poll::Pending
24 }
25}
26
27impl InboundStreamHandler for DummyHandler {
28 type InboundUpgrade = DeniedUpgrade;
29 type InboundUserData = ();
30
31 fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundUpgrade, Self::InboundUserData> {
32 SubstreamProtocol::new(DeniedUpgrade, ())
33 }
34
35 fn on_fully_negotiated(
36 &mut self,
37 _user_data: Self::InboundUserData,
38 _protocol: <Self::InboundUpgrade as InboundUpgradeSend>::Output,
39 ) {
40 unreachable!("PendingConnectionHandler does not support fully negotiated protocols",);
41 }
42
43 fn on_upgrade_error(
44 &mut self,
45 _user_data: Self::InboundUserData,
46 _error: <Self::InboundUpgrade as InboundUpgradeSend>::Error,
47 ) {
48 unreachable!("PendingConnectionHandler does not support upgrade errors");
49 }
50}
51
52impl OutboundStreamHandler for DummyHandler {
53 type OutboundUpgrade = PendingUpgrade<String>;
54 type OutboundUserData = Infallible;
55
56 fn on_fully_negotiated(
57 &mut self,
58 _user_data: Self::OutboundUserData,
59 _protocol: <Self::OutboundUpgrade as InboundUpgradeSend>::Output,
60 ) {
61 unreachable!("PendingConnectionHandler does not support fully negotiated protocols");
62 }
63
64 fn on_upgrade_error(
65 &mut self,
66 _user_data: Self::OutboundUserData,
67 _error: StreamUpgradeError<<Self::OutboundUpgrade as InboundUpgradeSend>::Error>,
68 ) {
69 unreachable!("PendingConnectionHandler does not support upgrade errors");
70 }
71
72 fn poll_outbound_request(
73 &mut self,
74 _cx: &mut Context<'_>,
75 ) -> Poll<SubstreamProtocol<Self::OutboundUpgrade, Self::OutboundUserData>> {
76 Poll::Pending
77 }
78}