golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/ack_delay.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.21
     6  
     7  package quic
     8  
     9  import (
    10  	"math"
    11  	"time"
    12  )
    13  
    14  // An unscaledAckDelay is an ACK Delay field value from an ACK packet,
    15  // without the ack_delay_exponent scaling applied.
    16  type unscaledAckDelay int64
    17  
    18  func unscaledAckDelayFromDuration(d time.Duration, ackDelayExponent uint8) unscaledAckDelay {
    19  	return unscaledAckDelay(d.Microseconds() >> ackDelayExponent)
    20  }
    21  
    22  func (d unscaledAckDelay) Duration(ackDelayExponent uint8) time.Duration {
    23  	if int64(d) > (math.MaxInt64>>ackDelayExponent)/int64(time.Microsecond) {
    24  		// If scaling the delay would overflow, ignore the delay.
    25  		return 0
    26  	}
    27  	return time.Duration(d<<ackDelayExponent) * time.Microsecond
    28  }