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>
This commit is contained in:
Josh Bleecher Snyder 2020-08-13 14:06:43 -07:00
parent dbb4c246fa
commit 062bd67d3b

View File

@ -17,7 +17,7 @@
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"math/big" "math/rand"
"os" "os"
"runtime" "runtime"
"strconv" "strconv"
@ -56,6 +56,10 @@ func init() {
} }
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
const ( const (
perClientSendQueueDepth = 32 // packets buffered for sending perClientSendQueueDepth = 32 // packets buffered for sending
writeTimeout = 2 * time.Second 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)) jitter := time.Duration(rand.Intn(5000)) * time.Millisecond
if err != nil {
panic(err)
}
jitter := time.Duration(jitterMs.Int64()) * time.Millisecond
keepAliveTick := time.NewTicker(keepAlive + jitter) keepAliveTick := time.NewTicker(keepAlive + jitter)
defer keepAliveTick.Stop() defer keepAliveTick.Stop()