Debian Codegraph @

third_party/rust/neqo-http3/src/features/extended_connect/mod.rs

raw
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
6
7 pub(crate) mod webtransport_session;
8 pub(crate) mod webtransport_streams;
9
10 use std::fmt::Debug;
11
12 use neqo_common::Header;
13 use neqo_transport::{AppError, StreamId};
14 pub(crate) use webtransport_session::WebTransportSession;
15
16 use crate::{
17 client_events::Http3ClientEvents,
18 features::NegotiationState,
19 settings::{HSettingType, HSettings},
20 CloseType, Http3StreamInfo, Http3StreamType, Res,
21 };
22
23 #[derive(Debug, PartialEq, Eq, Clone)]
24 pub enum SessionCloseReason {
25 Error(AppError),
26 Status(u16),
27 Clean { error: u32, message: String },
28 }
29
30 impl From<CloseType> for SessionCloseReason {
31 fn from(close_type: CloseType) -> Self {
32 match close_type {
33 CloseType::ResetApp(e) | CloseType::ResetRemote(e) | CloseType::LocalError(e) => {
34 Self::Error(e)
35 }
36 CloseType::Done => Self::Clean {
37 error: 0,
38 message: String::new(),
39 },
40 }
41 }
42 }
43
44 pub(crate) trait ExtendedConnectEvents: Debug {
45 fn session_start(
46 &self,
47 connect_type: ExtendedConnectType,
48 stream_id: StreamId,
49 status: u16,
50 headers: Vec<Header>,
51 );
52 fn session_end(
53 &self,
54 connect_type: ExtendedConnectType,
55 stream_id: StreamId,
56 reason: SessionCloseReason,
57 headers: Option<Vec<Header>>,
58 );
59 fn extended_connect_new_stream(&self, stream_info: Http3StreamInfo) -> Res<()>;
60 fn new_datagram(&self, session_id: StreamId, datagram: Vec<u8>);
61 }
62
63 #[derive(Debug, PartialEq, Copy, Clone, Eq)]
64 pub(crate) enum ExtendedConnectType {
65 WebTransport,
66 }
67
68 impl ExtendedConnectType {
69 #[must_use]
70 #[expect(
71 clippy::unused_self,
72 reason = "This will change when we have more features using ExtendedConnectType."
73 )]
74 pub const fn string(self) -> &'static str {
75 "webtransport"
76 }
77
78 #[expect(
79 clippy::unused_self,
80 reason = "This will change when we have more features using ExtendedConnectType."
81 )]
82 #[must_use]
83 pub const fn get_stream_type(self, session_id: StreamId) -> Http3StreamType {
84 Http3StreamType::WebTransport(session_id)
85 }
86 }
87
88 impl From<ExtendedConnectType> for HSettingType {
89 fn from(_type: ExtendedConnectType) -> Self {
90 // This will change when we have more features using ExtendedConnectType.
91 Self::EnableWebTransport
92 }
93 }
94
95 #[derive(Debug)]
96 pub(crate) struct ExtendedConnectFeature {
97 feature_negotiation: NegotiationState,
98 }
99
100 impl ExtendedConnectFeature {
101 #[must_use]
102 pub fn new(connect_type: ExtendedConnectType, enable: bool) -> Self {
103 Self {
104 feature_negotiation: NegotiationState::new(enable, HSettingType::from(connect_type)),
105 }
106 }
107
108 pub fn set_listener(&mut self, new_listener: Http3ClientEvents) {
109 self.feature_negotiation.set_listener(new_listener);
110 }
111
112 pub fn handle_settings(&mut self, settings: &HSettings) {
113 self.feature_negotiation.handle_settings(settings);
114 }
115
116 #[must_use]
117 pub const fn enabled(&self) -> bool {
118 self.feature_negotiation.enabled()
119 }
120 }
121 #[cfg(test)]
122 mod tests;