derp: use rand instead of crypto/rand to generate jitter

We don't need crypto/rand. Let the OS keep its entropy bits.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
pull/686/head
Josh Bleecher Snyder 4 years ago
parent dbb4c246fa
commit 062bd67d3b

@ -17,7 +17,7 @@ import (
"io"
"io/ioutil"
"log"
"math/big"
"math/rand"
"os"
"runtime"
"strconv"
@ -56,6 +56,10 @@ func init() {
}
}
func init() {
rand.Seed(time.Now().UnixNano())
}
const (
perClientSendQueueDepth = 32 // packets buffered for sending
writeTimeout = 2 * time.Second
@ -927,11 +931,7 @@ func (c *sclient) sendLoop(ctx context.Context) error {
}
}()
jitterMs, err := crand.Int(crand.Reader, big.NewInt(5000))
if err != nil {
panic(err)
}
jitter := time.Duration(jitterMs.Int64()) * time.Millisecond
jitter := time.Duration(rand.Intn(5000)) * time.Millisecond
keepAliveTick := time.NewTicker(keepAlive + jitter)
defer keepAliveTick.Stop()

Loading…
Cancel
Save