Merge pull request #2936 from lucas-clemente/initial-conn-ids

allow up to 20 byte for the initial connection IDs
This commit is contained in:
Marten Seemann
2020-12-14 23:39:51 +07:00
committed by GitHub
2 changed files with 7 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ import (
// A ConnectionID in QUIC
type ConnectionID []byte
const maxConnectionIDLen = 18
const maxConnectionIDLen = 20
// GenerateConnectionID generates a connection ID using cryptographic random
func GenerateConnectionID(len int) (ConnectionID, error) {
@@ -22,7 +22,7 @@ func GenerateConnectionID(len int) (ConnectionID, error) {
}
// GenerateConnectionIDForInitial generates a connection ID for the Initial packet.
// It uses a length randomly chosen between 8 and 18 bytes.
// It uses a length randomly chosen between 8 and 20 bytes.
func GenerateConnectionIDForInitial() (ConnectionID, error) {
r := make([]byte, 1)
if _, err := rand.Read(r); err != nil {

View File

@@ -25,21 +25,21 @@ var _ = Describe("Connection ID generation", func() {
})
It("generates random length destination connection IDs", func() {
var has8ByteConnID, has18ByteConnID bool
var has8ByteConnID, has20ByteConnID bool
for i := 0; i < 1000; i++ {
c, err := GenerateConnectionIDForInitial()
Expect(err).ToNot(HaveOccurred())
Expect(c.Len()).To(BeNumerically(">=", 8))
Expect(c.Len()).To(BeNumerically("<=", 18))
Expect(c.Len()).To(BeNumerically("<=", 20))
if c.Len() == 8 {
has8ByteConnID = true
}
if c.Len() == 18 {
has18ByteConnID = true
if c.Len() == 20 {
has20ByteConnID = true
}
}
Expect(has8ByteConnID).To(BeTrue())
Expect(has18ByteConnID).To(BeTrue())
Expect(has20ByteConnID).To(BeTrue())
})
It("says if connection IDs are equal", func() {