From b9eb025bdc5a8f0c351ea8dabb76e022e6e01d2e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 29 Mar 2019 17:24:25 +0100 Subject: [PATCH] Make Connection instants deterministic --- quinn-proto/src/connection.rs | 19 ++++++++++--------- quinn-proto/src/endpoint.rs | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/quinn-proto/src/connection.rs b/quinn-proto/src/connection.rs index 8f0662334..800258c13 100644 --- a/quinn-proto/src/connection.rs +++ b/quinn-proto/src/connection.rs @@ -157,6 +157,7 @@ impl Connection { remote: SocketAddr, client_config: Option, tls: TlsSession, + now: Instant, remote_validated: bool, ) -> Self { let side = if client_config.is_some() { @@ -168,7 +169,7 @@ impl Connection { let initial_space = PacketSpace { crypto: Some(CryptoSpace::new(Crypto::new_initial(&init_cid, side))), - ..PacketSpace::new() + ..PacketSpace::new(now) }; let state = State::Handshake(state::Handshake { rem_cid_set: side.is_server(), @@ -205,7 +206,7 @@ impl Connection { endpoint_events: VecDeque::new(), cids_issued: 0, spin: false, - spaces: [initial_space, PacketSpace::new(), PacketSpace::new()], + spaces: [initial_space, PacketSpace::new(now), PacketSpace::new(now)], highest_space: SpaceId::Initial, prev_crypto: None, path_challenge: None, @@ -222,13 +223,13 @@ impl Connection { crypto_count: 0, pto_count: 0, loss_time: None, - time_of_last_sent_ack_eliciting_packet: Instant::now(), - time_of_last_sent_crypto_packet: Instant::now(), + time_of_last_sent_ack_eliciting_packet: now, + time_of_last_sent_crypto_packet: now, rtt: RttEstimator::new(), in_flight: InFlight::new(), congestion_window: config.initial_window, - recovery_start_time: Instant::now(), + recovery_start_time: now, ssthresh: u64::max_value(), ecn_counters: frame::EcnCounts::ZERO, sending_ecn: true, @@ -1231,7 +1232,7 @@ impl Connection { crypto: Some(CryptoSpace::new(Crypto::new_initial( &rem_cid, self.side, ))), - ..PacketSpace::new() + ..PacketSpace::new(now) }; self.write_tls(); @@ -3240,12 +3241,12 @@ struct PacketSpace { } impl PacketSpace { - fn new() -> Self { + fn new(now: Instant) -> Self { Self { crypto: None, dedup: Dedup::new(), rx_packet: 0, - rx_packet_time: Instant::now(), + rx_packet_time: now, pending: Retransmits::default(), pending_acks: RangeSet::new(), @@ -3253,7 +3254,7 @@ impl PacketSpace { next_packet_number: 0, largest_acked_packet: 0, - largest_acked_packet_sent: Instant::now(), + largest_acked_packet_sent: now, sent_packets: BTreeMap::new(), ecn_feedback: frame::EcnCounts::ZERO, diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs index 1007d239b..f9e6aac61 100644 --- a/quinn-proto/src/endpoint.rs +++ b/quinn-proto/src/endpoint.rs @@ -327,6 +327,7 @@ impl Endpoint { tls_config: crypto_config, server_name: server_name.into(), }), + Instant::now(), )?; Ok((ch, conn)) } @@ -362,6 +363,7 @@ impl Endpoint { remote: SocketAddr, transport_config: Arc, opts: ConnectionOpts, + now: Instant, ) -> Result<(ConnectionHandle, Connection), ConnectError> { let loc_cid = self.new_cid(); let params = TransportParameters::new(&transport_config); @@ -402,6 +404,7 @@ impl Endpoint { remote, client_config, tls, + now, remote_validated, ); let id = self.connections.insert(ConnectionMeta { @@ -544,6 +547,7 @@ impl Endpoint { ConnectionOpts::Server { orig_dst_cid: retry_cid, }, + now, ) .unwrap(); if dst_cid.len() != 0 {