From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/neqo-http3/src/features/mod.rs | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 third_party/rust/neqo-http3/src/features/mod.rs (limited to 'third_party/rust/neqo-http3/src/features/mod.rs') diff --git a/third_party/rust/neqo-http3/src/features/mod.rs b/third_party/rust/neqo-http3/src/features/mod.rs new file mode 100644 index 0000000000..0e045ed80b --- /dev/null +++ b/third_party/rust/neqo-http3/src/features/mod.rs @@ -0,0 +1,91 @@ +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use crate::{ + client_events::Http3ClientEvents, + settings::{HSettingType, HSettings}, +}; +use neqo_common::qtrace; +use std::fmt::Debug; +use std::mem; + +pub mod extended_connect; + +/// States: +/// - `Disable` - it is not turned on for this connection. +/// - `Negotiating` - the feature is enabled locally, but settings from the peer +/// have not been received yet. +/// - `Negotiated` - the settings have been received and both sides support the feature. +/// - `NegotiationFailed` - the settings have been received and the peer does not +/// support the feature. +#[derive(Debug)] +pub enum NegotiationState { + Disabled, + Negotiating { + feature_type: HSettingType, + listener: Option, + }, + Negotiated, + NegotiationFailed, +} + +impl NegotiationState { + #[must_use] + pub fn new(enable: bool, feature_type: HSettingType) -> Self { + if enable { + Self::Negotiating { + feature_type, + listener: None, + } + } else { + Self::Disabled + } + } + + pub fn set_listener(&mut self, new_listener: Http3ClientEvents) { + if let Self::Negotiating { listener, .. } = self { + *listener = Some(new_listener); + } + } + + pub fn handle_settings(&mut self, settings: &HSettings) { + if !self.locally_enabled() { + return; + } + + if let Self::Negotiating { + feature_type, + listener, + } = self + { + qtrace!( + "set_negotiated {:?} to {}", + feature_type, + settings.get(*feature_type) + ); + let cb = mem::take(listener); + let ft = *feature_type; + *self = if settings.get(ft) == 1 { + Self::Negotiated + } else { + Self::NegotiationFailed + }; + if let Some(l) = cb { + l.negotiation_done(ft, self.enabled()); + } + } + } + + #[must_use] + pub fn enabled(&self) -> bool { + matches!(self, &Self::Negotiated) + } + + #[must_use] + pub fn locally_enabled(&self) -> bool { + !matches!(self, &Self::Disabled) + } +} -- cgit v1.2.3