| 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 |
use std::cmp::min; |
| 8 |
|
| 9 |
use neqo_qpack::QpackSettings; |
| 10 |
use neqo_transport::ConnectionParameters; |
| 11 |
|
| 12 |
const QPACK_MAX_TABLE_SIZE_DEFAULT: u64 = 65536; |
| 13 |
const QPACK_TABLE_SIZE_LIMIT: u64 = (1 << 30) - 1; |
| 14 |
const QPACK_MAX_BLOCKED_STREAMS_DEFAULT: u16 = 20; |
| 15 |
const MAX_PUSH_STREAM_DEFAULT: u64 = 0; |
| 16 |
const WEBTRANSPORT_DEFAULT: bool = false; |
| 17 |
const HTTP3_DATAGRAM_DEFAULT: bool = false; |
| 18 |
|
| 19 |
#[derive(Debug, Clone)] |
| 20 |
pub struct Http3Parameters { |
| 21 |
conn_params: ConnectionParameters, |
| 22 |
qpack_settings: QpackSettings, |
| 23 |
max_concurrent_push_streams: u64, |
| 24 |
webtransport: bool, |
| 25 |
http3_datagram: bool, |
| 26 |
} |
| 27 |
|
| 28 |
impl Default for Http3Parameters { |
| 29 |
fn default() -> Self { |
| 30 |
Self { |
| 31 |
conn_params: ConnectionParameters::default(), |
| 32 |
qpack_settings: QpackSettings { |
| 33 |
max_table_size_encoder: QPACK_MAX_TABLE_SIZE_DEFAULT, |
| 34 |
max_table_size_decoder: QPACK_MAX_TABLE_SIZE_DEFAULT, |
| 35 |
max_blocked_streams: QPACK_MAX_BLOCKED_STREAMS_DEFAULT, |
| 36 |
}, |
| 37 |
max_concurrent_push_streams: MAX_PUSH_STREAM_DEFAULT, |
| 38 |
webtransport: WEBTRANSPORT_DEFAULT, |
| 39 |
http3_datagram: HTTP3_DATAGRAM_DEFAULT, |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
impl Http3Parameters { |
| 45 |
#[must_use] |
| 46 |
pub const fn get_connection_parameters(&self) -> &ConnectionParameters { |
| 47 |
&self.conn_params |
| 48 |
} |
| 49 |
|
| 50 |
#[must_use] |
| 51 |
pub fn connection_parameters(mut self, conn_params: ConnectionParameters) -> Self { |
| 52 |
self.conn_params = conn_params; |
| 53 |
self |
| 54 |
} |
| 55 |
|
| 56 |
/// # Panics |
| 57 |
/// |
| 58 |
/// The table size must be smaller than 1 << 30 by the spec. |
| 59 |
#[must_use] |
| 60 |
pub fn max_table_size_encoder(mut self, mut max_table: u64) -> Self { |
| 61 |
assert!(max_table <= QPACK_TABLE_SIZE_LIMIT); |
| 62 |
max_table = min(max_table, QPACK_TABLE_SIZE_LIMIT); |
| 63 |
self.qpack_settings.max_table_size_encoder = max_table; |
| 64 |
self |
| 65 |
} |
| 66 |
|
| 67 |
#[must_use] |
| 68 |
pub const fn get_max_table_size_encoder(&self) -> u64 { |
| 69 |
self.qpack_settings.max_table_size_encoder |
| 70 |
} |
| 71 |
|
| 72 |
/// # Panics |
| 73 |
/// |
| 74 |
/// The table size must be smaller than 1 << 30 by the spec. |
| 75 |
#[must_use] |
| 76 |
pub fn max_table_size_decoder(mut self, mut max_table: u64) -> Self { |
| 77 |
assert!(max_table <= QPACK_TABLE_SIZE_LIMIT); |
| 78 |
max_table = min(max_table, QPACK_TABLE_SIZE_LIMIT); |
| 79 |
self.qpack_settings.max_table_size_decoder = max_table; |
| 80 |
self |
| 81 |
} |
| 82 |
|
| 83 |
#[must_use] |
| 84 |
pub const fn get_max_table_size_decoder(&self) -> u64 { |
| 85 |
self.qpack_settings.max_table_size_decoder |
| 86 |
} |
| 87 |
|
| 88 |
#[must_use] |
| 89 |
pub const fn max_blocked_streams(mut self, max_blocked: u16) -> Self { |
| 90 |
self.qpack_settings.max_blocked_streams = max_blocked; |
| 91 |
self |
| 92 |
} |
| 93 |
|
| 94 |
#[must_use] |
| 95 |
pub const fn get_max_blocked_streams(&self) -> u16 { |
| 96 |
self.qpack_settings.max_blocked_streams |
| 97 |
} |
| 98 |
|
| 99 |
#[must_use] |
| 100 |
pub const fn get_qpack_settings(&self) -> &QpackSettings { |
| 101 |
&self.qpack_settings |
| 102 |
} |
| 103 |
|
| 104 |
#[must_use] |
| 105 |
pub const fn max_concurrent_push_streams(mut self, max_push_streams: u64) -> Self { |
| 106 |
self.max_concurrent_push_streams = max_push_streams; |
| 107 |
self |
| 108 |
} |
| 109 |
|
| 110 |
#[must_use] |
| 111 |
pub const fn get_max_concurrent_push_streams(&self) -> u64 { |
| 112 |
self.max_concurrent_push_streams |
| 113 |
} |
| 114 |
|
| 115 |
#[must_use] |
| 116 |
pub const fn webtransport(mut self, webtransport: bool) -> Self { |
| 117 |
self.webtransport = webtransport; |
| 118 |
self |
| 119 |
} |
| 120 |
|
| 121 |
#[must_use] |
| 122 |
pub const fn get_webtransport(&self) -> bool { |
| 123 |
self.webtransport |
| 124 |
} |
| 125 |
|
| 126 |
#[must_use] |
| 127 |
pub const fn http3_datagram(mut self, http3_datagram: bool) -> Self { |
| 128 |
self.http3_datagram = http3_datagram; |
| 129 |
self |
| 130 |
} |
| 131 |
|
| 132 |
#[must_use] |
| 133 |
pub const fn get_http3_datagram(&self) -> bool { |
| 134 |
self.http3_datagram |
| 135 |
} |
| 136 |
} |