2017-12-12 02:51:45 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/binary"
|
|
|
|
|
2018-01-03 19:19:49 +00:00
|
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
2017-12-12 02:51:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GenerateConnectionID generates a connection ID using cryptographic random
|
|
|
|
func GenerateConnectionID() (protocol.ConnectionID, error) {
|
2018-01-03 19:19:49 +00:00
|
|
|
b := make([]byte, 8)
|
2017-12-12 02:51:45 +00:00
|
|
|
_, err := rand.Read(b)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return protocol.ConnectionID(binary.LittleEndian.Uint64(b)), nil
|
|
|
|
}
|