Skip to main content

volans_swarm/handler/
pending.rs

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