Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jun 21, 2024
1 parent fbc6678 commit 2107e48
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 73 deletions.
46 changes: 0 additions & 46 deletions dc/s2n-quic-dc/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use core::time::Duration;
use s2n_quic_core::{
dc,
path::{Handle, MaxMtu, Tuple},
varint::VarInt,
};
Expand Down Expand Up @@ -58,47 +56,3 @@ impl Controller for Tuple {
self
}
}

// TODO: replace with dc::ApplicationParams
#[derive(Clone, Copy, Debug)]
pub struct Parameters {
pub max_mtu: MaxMtu,
pub remote_max_data: VarInt,
pub local_send_max_data: VarInt,
pub local_recv_max_data: VarInt,
pub idle_timeout_secs: u32,
}

impl Default for Parameters {
fn default() -> Self {
Self {
max_mtu: *DEFAULT_MTU,
remote_max_data: *DEFAULT_MAX_DATA,
local_send_max_data: *DEFAULT_MAX_DATA,
local_recv_max_data: *DEFAULT_MAX_DATA,
idle_timeout_secs: *DEFAULT_IDLE_TIMEOUT,
}
}
}

impl Parameters {
#[inline]
pub fn idle_timeout(&self) -> Duration {
Duration::from_secs(self.idle_timeout_secs as _)
}
}

impl From<dc::ApplicationParams> for Parameters {
fn from(value: dc::ApplicationParams) -> Self {
Self {
max_mtu: value.max_mtu,
remote_max_data: value.remote_max_data,
local_send_max_data: value.local_send_max_data,
local_recv_max_data: value.local_recv_max_data,
idle_timeout_secs: value
.max_idle_timeout
.and_then(|timeout| timeout.as_secs().try_into().ok())
.unwrap_or(u32::MAX),
}
}
}
50 changes: 35 additions & 15 deletions dc/s2n-quic-dc/src/path/secret/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use crate::{
credentials::{Credentials, Id},
crypto,
packet::{secret_control as control, Packet},
path::Parameters,
};
use rand::Rng as _;
use s2n_codec::EncoderBuffer;
use s2n_quic_core::{
dc::{self},
dc::{self, ApplicationParams},
event::api::EndpointType,
};
use std::{
Expand Down Expand Up @@ -273,14 +272,13 @@ impl Map {
&& !self.state.requested_handshakes.pin().contains(&peer)
}

pub fn sealer(&self, peer: SocketAddr) -> Option<(Sealer, Parameters)> {
pub fn sealer(&self, peer: SocketAddr) -> Option<(Sealer, ApplicationParams)> {
let peers_guard = self.state.peers.guard();
let state = self.state.peers.get(&peer, &peers_guard)?;
state.mark_live(self.state.cleaner.epoch());

let sealer = state.uni_sealer();
let params = state.parameters;
Some((sealer, params))
Some((sealer, state.parameters))
}

pub fn opener(&self, credentials: &Credentials, control_out: &mut Vec<u8>) -> Option<Opener> {
Expand All @@ -289,22 +287,21 @@ impl Map {
Some(opener)
}

pub fn pair_for_peer(&self, peer: SocketAddr) -> Option<(Sealer, Opener, Parameters)> {
pub fn pair_for_peer(&self, peer: SocketAddr) -> Option<(Sealer, Opener, ApplicationParams)> {
let peers_guard = self.state.peers.guard();
let state = self.state.peers.get(&peer, &peers_guard)?;
state.mark_live(self.state.cleaner.epoch());

let params = state.parameters;
let (sealer, opener) = state.bidi_local();

Some((sealer, opener, params))
Some((sealer, opener, state.parameters))
}

pub fn pair_for_credentials(
&self,
credentials: &Credentials,
control_out: &mut Vec<u8>,
) -> Option<(Sealer, Opener, Parameters)> {
) -> Option<(Sealer, Opener, ApplicationParams)> {
let state = self.pre_authentication(credentials, control_out)?;

let params = state.parameters;
Expand Down Expand Up @@ -470,6 +467,7 @@ impl Map {
}

#[doc(hidden)]
#[cfg(any(test, feature = "testing"))]
pub fn for_test_with_peers(
peers: Vec<(schedule::Ciphersuite, dc::Version, SocketAddr)>,
) -> (Self, Vec<Id>) {
Expand Down Expand Up @@ -498,7 +496,7 @@ impl Map {
secret,
sender,
receiver_shared.clone().new_receiver(),
Default::default(),
testing::test_application_params(),
);
let entry = Arc::new(entry);
provider.insert(entry);
Expand All @@ -508,6 +506,7 @@ impl Map {
}

#[doc(hidden)]
#[cfg(any(test, feature = "testing"))]
pub fn test_insert(&self, peer: SocketAddr) {
let mut secret = [0; 32];
aws_lc_rs::rand::fill(&mut secret).unwrap();
Expand All @@ -519,7 +518,13 @@ impl Map {
);
let sender = sender::State::new([0; 16]);
let receiver = self.state.receiver_shared.clone().new_receiver();
let entry = Entry::new(peer, secret, sender, receiver, Default::default());
let entry = Entry::new(
peer,
secret,
sender,
receiver,
testing::test_application_params(),
);
self.insert(Arc::new(entry));
}

Expand Down Expand Up @@ -583,7 +588,7 @@ pub(super) struct Entry {
used_at: AtomicU64,
sender: sender::State,
receiver: receiver::State,
parameters: Parameters,
parameters: ApplicationParams,
}

// Retired is 0 if not yet retired. Otherwise it stores the background cleaner epoch at which it
Expand All @@ -609,7 +614,7 @@ impl Entry {
secret: schedule::Secret,
sender: sender::State,
receiver: receiver::State,
parameters: Parameters,
parameters: ApplicationParams,
) -> Self {
Self {
peer,
Expand Down Expand Up @@ -747,7 +752,7 @@ impl fmt::Debug for Dedup {
pub struct HandshakingPath {
peer: SocketAddr,
dc_version: dc::Version,
parameters: Parameters,
parameters: ApplicationParams,
endpoint_type: s2n_quic_core::endpoint::Type,
secret: Option<schedule::Secret>,
map: Map,
Expand All @@ -763,7 +768,7 @@ impl HandshakingPath {
Self {
peer: connection_info.remote_address.clone().into(),
dc_version: connection_info.dc_version,
parameters: connection_info.application_params.clone().into(),
parameters: connection_info.application_params,
endpoint_type,
secret: None,
map,
Expand Down Expand Up @@ -841,5 +846,20 @@ impl dc::Path for HandshakingPath {
}
}

#[cfg(any(test, feature = "testing"))]
pub mod testing {
use s2n_quic_core::{
connection::Limits, dc::ApplicationParams, transport::parameters::InitialFlowControlLimits,
};

pub fn test_application_params() -> ApplicationParams {
ApplicationParams::new(
s2n_quic_core::path::MaxMtu::default().into(),
&InitialFlowControlLimits::default(),
&Limits::default(),
)
}
}

#[cfg(test)]
mod test;
4 changes: 2 additions & 2 deletions dc/s2n-quic-dc/src/path/secret/map/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn fake_entry(peer: u16) -> Arc<Entry> {
),
sender::State::new([0; 16]),
receiver::State::without_shared(),
Parameters::default(),
super::testing::test_application_params(),
))
}

Expand Down Expand Up @@ -137,7 +137,7 @@ impl Model {
secret,
sender::State::new(stateless_reset),
state.state.receiver_shared.clone().new_receiver(),
Parameters::default(),
super::testing::test_application_params(),
)));

self.invariants.insert(Invariant::ContainsIp(ip));
Expand Down
12 changes: 8 additions & 4 deletions dc/s2n-quic-dc/src/stream/recv.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use super::TransportFeatures;
use super::{TransportFeatures, DEFAULT_IDLE_TIMEOUT};
use crate::{
allocator::Allocator,
crypto::{decrypt, encrypt, UninitSlice},
packet::{control, stream},
path::Parameters,
};
use core::{task::Poll, time::Duration};
use s2n_codec::{EncoderBuffer, EncoderValue};
use s2n_quic_core::{
buffer::{self, reader::storage::Infallible as _},
dc::ApplicationParams,
ensure,
frame::{self, ack::EcnCounts},
inet::ExplicitCongestionNotification,
Expand Down Expand Up @@ -54,7 +54,11 @@ pub struct Receiver {

impl Receiver {
#[inline]
pub fn new(stream_id: stream::Id, params: &Parameters, features: TransportFeatures) -> Self {
pub fn new(
stream_id: stream::Id,
params: &ApplicationParams,
features: TransportFeatures,
) -> Self {
let initial_max_data = params.local_recv_max_data;
Self {
stream_id,
Expand All @@ -64,7 +68,7 @@ impl Receiver {
recovery_ack: Default::default(),
state: Default::default(),
idle_timer: Default::default(),
idle_timeout: params.idle_timeout(),
idle_timeout: params.max_idle_timeout.unwrap_or(DEFAULT_IDLE_TIMEOUT),
tick_timer: Default::default(),
_should_transmit: false,
max_data: initial_max_data,
Expand Down
13 changes: 7 additions & 6 deletions dc/s2n-quic-dc/src/stream/send/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ use crate::{
self,
stream::{self, decoder, encoder},
},
path::Parameters,
recovery,
stream::{
processing,
send::{
application, buffer, error::Error, filter::Filter, probes,
transmission::Type as TransmissionType,
},
DEFAULT_IDLE_TIMEOUT,
},
};
use core::{task::Poll, time::Duration};
use s2n_codec::{DecoderBufferMut, EncoderBuffer};
use s2n_quic_core::{
dc::ApplicationParams,
ensure,
frame::{self, FrameMut},
inet::ExplicitCongestionNotification,
Expand Down Expand Up @@ -112,16 +113,16 @@ pub struct PeerActivity {

impl Worker {
#[inline]
pub fn new(stream_id: stream::Id, params: &Parameters) -> Self {
let mtu = params.max_mtu;
pub fn new(stream_id: stream::Id, params: &ApplicationParams) -> Self {
let mtu = params.max_datagram_size;
let initial_max_data = params.remote_max_data;
let local_max_data = params.local_send_max_data;

// initialize the pending data left to send
let mut unacked_ranges = IntervalSet::new();
unacked_ranges.insert(VarInt::ZERO..=VarInt::MAX).unwrap();

let cca = congestion::Controller::new(mtu.into());
let cca = congestion::Controller::new(mtu);
let max_sent_offset = VarInt::ZERO;

Self {
Expand All @@ -146,14 +147,14 @@ impl Worker {
pto_backoff: INITIAL_PTO_BACKOFF,
inflight_timer: Default::default(),
idle_timer: Default::default(),
idle_timeout: params.idle_timeout(),
idle_timeout: params.max_idle_timeout.unwrap_or(DEFAULT_IDLE_TIMEOUT),
error: None,
unacked_ranges,
max_sent_offset,
max_data: initial_max_data,
local_max_data_window: local_max_data,
peer_activity: None,
mtu: mtu.into(),
mtu,
max_sent_segment_size: 0,
}
}
Expand Down

0 comments on commit 2107e48

Please sign in to comment.