Skip to content

Commit

Permalink
enable settings_h3_datagram (mozilla#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
KershawChang authored Feb 14, 2023
1 parent c9a19ac commit 811f918
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 75 deletions.
14 changes: 14 additions & 0 deletions neqo-http3/src/conn_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const QPACK_TABLE_SIZE_LIMIT: u64 = (1 << 30) - 1;
const QPACK_MAX_BLOCKED_STREAMS_DEFAULT: u16 = 20;
const MAX_PUSH_STREAM_DEFAULT: u64 = 0;
const WEBTRANSPORT_DEFAULT: bool = false;
const HTTP3_DATAGRAM_DEFAULT: bool = false;

#[derive(Debug, Clone)]
pub struct Http3Parameters {
conn_params: ConnectionParameters,
qpack_settings: QpackSettings,
max_concurrent_push_streams: u64,
webtransport: bool,
http3_datagram: bool,
}

impl Default for Http3Parameters {
Expand All @@ -33,6 +35,7 @@ impl Default for Http3Parameters {
},
max_concurrent_push_streams: MAX_PUSH_STREAM_DEFAULT,
webtransport: WEBTRANSPORT_DEFAULT,
http3_datagram: HTTP3_DATAGRAM_DEFAULT,
}
}
}
Expand Down Expand Up @@ -116,4 +119,15 @@ impl Http3Parameters {
pub fn get_webtransport(&self) -> bool {
self.webtransport
}

#[must_use]
pub fn http3_datagram(mut self, http3_datagram: bool) -> Self {
self.http3_datagram = http3_datagram;
self
}

#[must_use]
pub fn get_http3_datagram(&self) -> bool {
self.http3_datagram
}
}
4 changes: 3 additions & 1 deletion neqo-http3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,9 @@ impl Http3Connection {
qpack_changed = true;
}
HSettingType::BlockedStreams => qpack_changed = true,
HSettingType::MaxHeaderListSize | HSettingType::EnableWebTransport => (),
HSettingType::MaxHeaderListSize
| HSettingType::EnableWebTransport
| HSettingType::EnableH3Datagram => (),
}
}
if qpack_changed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,40 +63,27 @@ enum ClientState {
ClientDisabled,
}

#[derive(PartialEq, Eq)]
enum ClientResumedState {
ClientResumed,
ClientSuspended,
}

#[derive(PartialEq, Eq)]
enum ServerState {
ServerEnabled,
ServerDisabled,
}

#[derive(PartialEq, Eq)]
enum ServerResumedState {
ServerResumed,
ServerSuspended,
}

fn zero_rtt(
client_state: &ClientState,
server_state: &ServerState,
client_resumed: &ClientResumedState,
server_resumed: &ServerResumedState,
client_resumed_state: &ClientState,
server_resumed_state: &ServerState,
) {
let (mut client, mut server) = connect_wt(
ClientState::ClientEnabled.eq(client_state),
ServerState::ServerEnabled.eq(server_state),
);
assert_eq!(
client.webtransport_enabled(),
ClientState::ClientEnabled.eq(client_state) && ServerState::ServerEnabled.eq(server_state)
);
let client_org = ClientState::ClientEnabled.eq(client_state);
let server_org = ServerState::ServerEnabled.eq(server_state);
let client_resumed = ClientState::ClientEnabled.eq(client_resumed_state);
let server_resumed = ServerState::ServerEnabled.eq(server_resumed_state);

// exchane token
let (mut client, mut server) = connect_wt(client_org, server_org);
assert_eq!(client.webtransport_enabled(), client_org && server_org);

// exchange token
let out = server.process(None, now());
// We do not have a token so we need to wait for a resumption token timer to trigger.
std::mem::drop(client.process(out.dgram(), now() + Duration::from_millis(250)));
Expand All @@ -112,14 +99,8 @@ fn zero_rtt(
})
.unwrap();

let mut client = default_http3_client(
Http3Parameters::default()
.webtransport(ClientResumedState::ClientResumed.eq(client_resumed)),
);
let mut server = default_http3_server(
Http3Parameters::default()
.webtransport(ServerResumedState::ServerResumed.eq(server_resumed)),
);
let mut client = default_http3_client(Http3Parameters::default().webtransport(client_resumed));
let mut server = default_http3_server(Http3Parameters::default().webtransport(server_resumed));
client
.enable_resumption(now(), &token)
.expect("Set resumption token.");
Expand All @@ -130,116 +111,123 @@ fn zero_rtt(
assert_eq!(&client.state(), &Http3State::Connected);
assert_eq!(
client.webtransport_enabled(),
ClientResumedState::ClientResumed.eq(client_resumed)
&& ServerResumedState::ServerResumed.eq(server_resumed)
client_resumed && server_resumed
);
check_wt_event(
&mut client,
ClientResumedState::ClientResumed.eq(client_resumed),
ServerResumedState::ServerResumed.eq(server_resumed),

let mut early_data_accepted = true;
// The only case we should not do 0-RTT is when webtransport was enabled
// originally and is disabled afterwards.
if server_org && !server_resumed {
early_data_accepted = false;
}
assert_eq!(
client.tls_info().unwrap().early_data_accepted(),
early_data_accepted
);

check_wt_event(&mut client, client_resumed, server_resumed);
}

#[test]
fn zero_rtt_wt_settings() {
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerResumed,
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerSuspended,
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerResumed,
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerSuspended,
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
);

zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerSuspended,
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerResumed,
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerSuspended,
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerResumed,
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
);

zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerSuspended,
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerResumed,
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerSuspended,
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerResumed,
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
);

zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerResumed,
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientSuspended,
&ServerResumedState::ServerSuspended,
&ClientState::ClientDisabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerSuspended,
&ClientState::ClientEnabled,
&ServerState::ServerDisabled,
);
zero_rtt(
&ClientState::ClientDisabled,
&ServerState::ServerEnabled,
&ClientResumedState::ClientResumed,
&ServerResumedState::ServerResumed,
&ClientState::ClientEnabled,
&ServerState::ServerEnabled,
);
}

Expand Down
Loading

0 comments on commit 811f918

Please sign in to comment.