cmd/stunstamp: cleanup timeout and interval constants (#13393)
Updates #cleanup Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
parent
e7b5e8c8cd
commit
95f0094310
|
@ -53,7 +53,16 @@ var (
|
|||
)
|
||||
|
||||
const (
|
||||
minInterval = time.Second
|
||||
// maxTxJitter is the upper bounds for jitter introduced across probes
|
||||
maxTXJitter = time.Millisecond * 400
|
||||
// minInterval is the minimum allowed probe interval/step
|
||||
minInterval = time.Second * 10
|
||||
// txRxTimeout is the timeout value used for kernel timestamping loopback,
|
||||
// and packet receive operations
|
||||
txRxTimeout = time.Second * 2
|
||||
// maxBufferDuration is the maximum duration (maxBufferDuration /
|
||||
// *flagInterval steps worth) of buffered data that can be held in memory
|
||||
// before data loss occurs around prometheus unavailability.
|
||||
maxBufferDuration = time.Hour
|
||||
)
|
||||
|
||||
|
@ -322,7 +331,7 @@ func measureSTUNRTT(conn io.ReadWriteCloser, _ string, dst netip.AddrPort) (rtt
|
|||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected conn type: %T", conn)
|
||||
}
|
||||
err = uconn.SetReadDeadline(time.Now().Add(time.Second * 2))
|
||||
err = uconn.SetReadDeadline(time.Now().Add(txRxTimeout))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error setting read deadline: %w", err)
|
||||
}
|
||||
|
@ -380,7 +389,7 @@ func probe(meta nodeMeta, cf *connAndMeasureFn, dstPort int) (*time.Duration, er
|
|||
Port: dstPort,
|
||||
}
|
||||
|
||||
time.Sleep(rand.N(400 * time.Millisecond)) // jitter across tx
|
||||
time.Sleep(rand.N(maxTXJitter)) // jitter across tx
|
||||
rtt, err := cf.fn(cf.conn, meta.hostname, netip.AddrPortFrom(meta.addr, uint16(dstPort)))
|
||||
if err != nil {
|
||||
if isTemporaryOrTimeoutErr(err) {
|
||||
|
|
|
@ -107,7 +107,7 @@ func measureICMPRTT(source timestampSource, conn io.ReadWriteCloser, _ string, d
|
|||
}
|
||||
|
||||
if source == timestampSourceKernel {
|
||||
txCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||
txCtx, txCancel := context.WithTimeout(context.Background(), txRxTimeout)
|
||||
defer txCancel()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
|
@ -142,8 +142,8 @@ func measureICMPRTT(source timestampSource, conn io.ReadWriteCloser, _ string, d
|
|||
}
|
||||
}
|
||||
|
||||
rxCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||
defer txCancel()
|
||||
rxCtx, rxCancel := context.WithTimeout(context.Background(), txRxTimeout)
|
||||
defer rxCancel()
|
||||
|
||||
rxBuf := make([]byte, 1024)
|
||||
oob := make([]byte, 1024)
|
||||
|
@ -210,7 +210,7 @@ func measureSTUNRTTKernel(conn io.ReadWriteCloser, _ string, dst netip.AddrPort)
|
|||
return 0, fmt.Errorf("sendto error: %v", err) // don't wrap
|
||||
}
|
||||
|
||||
txCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||
txCtx, txCancel := context.WithTimeout(context.Background(), txRxTimeout)
|
||||
defer txCancel()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
|
@ -236,7 +236,7 @@ func measureSTUNRTTKernel(conn io.ReadWriteCloser, _ string, dst netip.AddrPort)
|
|||
break
|
||||
}
|
||||
|
||||
rxCtx, rxCancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||
rxCtx, rxCancel := context.WithTimeout(context.Background(), txRxTimeout)
|
||||
defer rxCancel()
|
||||
|
||||
for {
|
||||
|
|
Loading…
Reference in New Issue