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

View File

@@ -2,6 +2,7 @@ package utils
import (
"bytes"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -133,6 +134,15 @@ var _ = Describe("Utils", func() {
It("returns the maximum int64", func() {
Expect(MaxInt64(5, 7)).To(Equal(int64(7)))
})
It("returns the maximum duration", func() {
Expect(MaxDuration(time.Microsecond, time.Nanosecond)).To(Equal(time.Microsecond))
})
})
It("returns the abs time", func() {
Expect(AbsDuration(time.Microsecond)).To(Equal(time.Microsecond))
Expect(AbsDuration(-time.Microsecond)).To(Equal(time.Microsecond))
})
Context("Min", func() {