Skip to content

Commit

Permalink
#2057: Option to disable GREASE random transport parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstyura committed Nov 28, 2024
1 parent 1c463ab commit 55f954b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
17 changes: 17 additions & 0 deletions quinn-proto/src/config/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct TransportConfig {
pub(crate) congestion_controller_factory: Arc<dyn congestion::ControllerFactory + Send + Sync>,

pub(crate) enable_segmentation_offload: bool,

pub(crate) send_grease_transport_parameter: bool,
}

impl TransportConfig {
Expand Down Expand Up @@ -314,6 +316,14 @@ impl TransportConfig {
self.enable_segmentation_offload = enabled;
self
}

/// Specifies whether the GREASE transport parameter is sent during transport parameter negotiation.
///
/// Defaults to `true`.
pub fn send_grease_random_transport_parameter(&mut self, enabled: bool) -> &mut Self {
self.send_grease_transport_parameter = enabled;
self
}
}

impl Default for TransportConfig {
Expand Down Expand Up @@ -354,6 +364,8 @@ impl Default for TransportConfig {
congestion_controller_factory: Arc::new(congestion::CubicConfig::default()),

enable_segmentation_offload: true,

send_grease_transport_parameter: true,
}
}
}
Expand Down Expand Up @@ -385,6 +397,7 @@ impl fmt::Debug for TransportConfig {
deterministic_packet_numbers: _,
congestion_controller_factory: _,
enable_segmentation_offload,
send_grease_transport_parameter,
} = self;
fmt.debug_struct("TransportConfig")
.field("max_concurrent_bidi_streams", max_concurrent_bidi_streams)
Expand Down Expand Up @@ -412,6 +425,10 @@ impl fmt::Debug for TransportConfig {
.field("datagram_send_buffer_size", datagram_send_buffer_size)
.field("congestion_controller_factory", &"[ opaque ]")
.field("enable_segmentation_offload", enable_segmentation_offload)
.field(
"send_grease_transport_parameter",
send_grease_transport_parameter,
)
.finish()
}
}
Expand Down
30 changes: 29 additions & 1 deletion quinn-proto/src/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ impl TransportParameters {
min_ack_delay: Some(
VarInt::from_u64(u64::try_from(TIMER_GRANULARITY.as_micros()).unwrap()).unwrap(),
),
grease_transport_parameter: Some(ReservedTransportParameter::random(rng)),
grease_transport_parameter: if config.send_grease_transport_parameter {
Some(ReservedTransportParameter::random(rng))
} else {
None
},
..Self::default()
}
}
Expand Down Expand Up @@ -636,6 +640,30 @@ mod test {
assert_eq!(read_params, TransportParameters::default());
}

#[test]
fn grease_transport_parameter_not_serialized_when_disabled() {
let mut params = TransportParameters::default();
params.grease_transport_parameter = None;

let mut buf = Vec::new();
params.write(&mut buf);
assert!(buf.is_empty());
}

#[test]
fn grease_transport_parameter_is_serialized_when_enabled() {
let mut params = TransportParameters::default();
params.grease_transport_parameter = Some(ReservedTransportParameter {
id: VarInt::from_u32(27),
payload: [0xAB, 0xFF, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
payload_len: 3,
});

let mut buf = Vec::new();
params.write(&mut buf);
assert_eq!(buf, [27, 3, 0xAB, 0xFF, 0x1])
}

#[test]
fn read_semantic_validation() {
#[allow(clippy::type_complexity)]
Expand Down

0 comments on commit 55f954b

Please sign in to comment.