Skip to content

Commit

Permalink
proto: Replace calls to Duration::new
Browse files Browse the repository at this point in the history
Replaces them with more modern and appropriate constructors or
constants.
  • Loading branch information
gretchenfrage committed Dec 26, 2024
1 parent 23b18f2 commit 9b33b25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ impl Connection {
/// Probe Timeout
fn pto(&self, space: SpaceId) -> Duration {
let max_ack_delay = match space {
SpaceId::Initial | SpaceId::Handshake => Duration::new(0, 0),
SpaceId::Initial | SpaceId::Handshake => Duration::ZERO,
SpaceId::Data => self.ack_frequency.max_ack_delay_for_pto(),
};
self.path.rtt.pto_base() + max_ack_delay
Expand Down Expand Up @@ -3844,7 +3844,7 @@ fn instant_saturating_sub(x: Instant, y: Instant) -> Duration {
if x > y {
x - y
} else {
Duration::new(0, 0)
Duration::ZERO
}
}

Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/pacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Pacer {

let unscaled_delay = smoothed_rtt
.checked_mul((bytes_to_send.max(self.capacity) - self.tokens) as _)
.unwrap_or_else(|| Duration::new(u64::MAX, 999_999_999))
.unwrap_or(Duration::MAX)
/ window;

// divisions come before multiplications to prevent overflow
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Pair {
epoch: now,
time: now,
mtu: DEFAULT_MTU,
latency: Duration::new(0, 0),
latency: Duration::ZERO,
spins: 0,
last_spin: false,
congestion_experienced: false,
Expand Down Expand Up @@ -315,7 +315,7 @@ impl TestEndpoint {
let socket = if env::var_os("SSLKEYLOGFILE").is_some() {
let socket = UdpSocket::bind(addr).expect("failed to bind UDP socket");
socket
.set_read_timeout(Some(Duration::new(0, 10_000_000)))
.set_read_timeout(Some(Duration::from_millis(10)))
.unwrap();
Some(socket)
} else {
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn encode_unix_secs(buf: &mut Vec<u8>, time: SystemTime) {
}

fn decode_unix_secs<B: Buf>(buf: &mut B) -> Option<SystemTime> {
Some(UNIX_EPOCH + Duration::new(buf.get::<u64>().ok()?, 0))
Some(UNIX_EPOCH + Duration::from_secs(buf.get::<u64>().ok()?))
}

/// Stateless reset token
Expand Down Expand Up @@ -253,7 +253,7 @@ mod test {
let token = RetryToken {
address,
orig_dst_cid: RandomConnectionIdGenerator::new(MAX_CID_SIZE).generate_cid(),
issued: UNIX_EPOCH + Duration::new(42, 0), // Fractional seconds would be lost
issued: UNIX_EPOCH + Duration::from_secs(42), // Fractional seconds would be lost
};
let encoded = token.encode(&prk, retry_src_cid);

Expand Down

0 comments on commit 9b33b25

Please sign in to comment.