derp: use rand instead of crypto/rand to generate jitter
We don't need crypto/rand. Let the OS keep its entropy bits.
"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()
