use cryptographic random to generate new connection IDs

fixes #348
This commit is contained in:
Marten Seemann
2017-01-18 14:19:53 +07:00
parent d5ec70fc7d
commit 86e02c4d2c
3 changed files with 39 additions and 4 deletions

18
utils/connection_id.go Normal file
View File

@@ -0,0 +1,18 @@
package utils
import (
"crypto/rand"
"encoding/binary"
"github.com/lucas-clemente/quic-go/protocol"
)
// GenerateConnectionID generates a connection ID using cryptographic random
func GenerateConnectionID() (protocol.ConnectionID, error) {
b := make([]byte, 8, 8)
_, err := rand.Read(b)
if err != nil {
return 0, err
}
return protocol.ConnectionID(binary.LittleEndian.Uint64(b)), nil
}