add rtt stats

This commit is contained in:
Lucas Clemente
2016-04-27 17:19:57 +02:00
parent 6a7f331269
commit 85ca2a3245
4 changed files with 426 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/rand"
"io"
"time"
)
// ReadStream is the read part of a QUIC stream
@@ -172,6 +173,22 @@ func MaxInt64(a, b int64) int64 {
return b
}
// MaxDuration returns the max duration
func MaxDuration(a, b time.Duration) time.Duration {
if a > b {
return a
}
return b
}
// AbsDuration returns the absolute value of a time duration
func AbsDuration(d time.Duration) time.Duration {
if d >= 0 {
return d
}
return -d
}
// RandomBit returns a cryptographically secure random bit (encoded as true / false)
func RandomBit() (bool, error) {
// ToDo: it's probably more efficient to read a bigger slice of random numbers at once and to cache them somewhere