use an array instead of a byte slice for Connection IDs

This commit is contained in:
Marten Seemann 2022-08-28 16:05:56 +03:00
parent 9e0f9e62ff
commit 1aced95d41
47 changed files with 530 additions and 487 deletions

View file

@ -224,13 +224,13 @@ func getFrames() []wire.Frame {
&wire.NewConnectionIDFrame{
SequenceNumber: seq1,
RetirePriorTo: seq1 / 2,
ConnectionID: getRandomData(4),
ConnectionID: protocol.ParseConnectionID(getRandomData(4)),
StatelessResetToken: token1,
},
&wire.NewConnectionIDFrame{
SequenceNumber: seq2,
RetirePriorTo: seq2,
ConnectionID: getRandomData(17),
ConnectionID: protocol.ParseConnectionID(getRandomData(17)),
StatelessResetToken: token2,
},
}...)

View file

@ -31,23 +31,23 @@ func main() {
headers := []wire.Header{
{ // Initial without token
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(3)),
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
SrcConnectionID: protocol.ParseConnectionID(getRandomData(3)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Initial without token, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Initial with Token
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(10)),
DestConnectionID: protocol.ConnectionID(getRandomData(19)),
SrcConnectionID: protocol.ParseConnectionID(getRandomData(10)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(19)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
@ -55,37 +55,37 @@ func main() {
},
{ // Handshake packet
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(5)),
DestConnectionID: protocol.ConnectionID(getRandomData(10)),
SrcConnectionID: protocol.ParseConnectionID(getRandomData(5)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(10)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Handshake packet, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID(getRandomData(12)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(12)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // 0-RTT packet
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ConnectionID(getRandomData(9)),
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
Type: protocol.PacketType0RTT,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Retry Packet, with empty orig dest conn id
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ConnectionID(getRandomData(9)),
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
Type: protocol.PacketTypeRetry,
Token: getRandomData(1000),
Version: version,
},
{ // Short-Header
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
},
}

View file

@ -73,7 +73,7 @@ func newToken(tg *handshake.TokenGenerator, data []byte) int {
if token.SentTime.Before(start) || token.SentTime.After(time.Now()) {
panic("incorrect send time")
}
if token.OriginalDestConnectionID != nil || token.RetrySrcConnectionID != nil {
if token.OriginalDestConnectionID.Len() > 0 || token.RetrySrcConnectionID.Len() > 0 {
panic("didn't expect connection IDs")
}
return 1
@ -89,12 +89,12 @@ func newRetryToken(tg *handshake.TokenGenerator, data []byte) int {
if len(data) < origDestConnIDLen {
return -1
}
origDestConnID := protocol.ConnectionID(data[:origDestConnIDLen])
origDestConnID := protocol.ParseConnectionID(data[:origDestConnIDLen])
data = data[origDestConnIDLen:]
if len(data) < retrySrcConnIDLen {
return -1
}
retrySrcConnID := protocol.ConnectionID(data[:retrySrcConnIDLen])
retrySrcConnID := protocol.ParseConnectionID(data[:retrySrcConnIDLen])
data = data[retrySrcConnIDLen:]
if len(data) < 1 {

View file

@ -43,13 +43,13 @@ func main() {
ActiveConnectionIDLimit: getRandomValue(),
}
if rand.Int()%2 == 0 {
tp.OriginalDestinationConnectionID = protocol.ConnectionID(getRandomData(rand.Intn(50)))
tp.OriginalDestinationConnectionID = protocol.ParseConnectionID(getRandomData(rand.Intn(21)))
}
if rand.Int()%2 == 0 {
tp.InitialSourceConnectionID = protocol.ConnectionID(getRandomData(rand.Intn(50)))
tp.InitialSourceConnectionID = protocol.ParseConnectionID(getRandomData(rand.Intn(21)))
}
if rand.Int()%2 == 0 {
connID := protocol.ConnectionID(getRandomData(rand.Intn(50)))
connID := protocol.ParseConnectionID(getRandomData(rand.Intn(21)))
tp.RetrySourceConnectionID = &connID
}
if rand.Int()%2 == 0 {
@ -65,7 +65,7 @@ func main() {
IPv4Port: uint16(rand.Int()),
IPv6: net.IP(getRandomData(16)),
IPv6Port: uint16(rand.Int()),
ConnectionID: protocol.ConnectionID(getRandomData(rand.Intn(25))),
ConnectionID: protocol.ParseConnectionID(getRandomData(rand.Intn(21))),
StatelessResetToken: token,
}
}