mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
remove the LongHeader field from the wire.Header
This commit is contained in:
parent
aca052dc7c
commit
86edf7fd4b
23 changed files with 154 additions and 363 deletions
|
@ -878,7 +878,7 @@ func (s *connection) handlePacketImpl(rp *receivedPacket) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if wire.IsLongHeaderPacket(p.data[0]) {
|
if wire.IsLongHeaderPacket(p.data[0]) {
|
||||||
hdr, packetData, rest, err := wire.ParsePacket(p.data, s.srcConnIDLen)
|
hdr, packetData, rest, err := wire.ParsePacket(p.data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.tracer != nil {
|
if s.tracer != nil {
|
||||||
dropReason := logging.PacketDropHeaderParseError
|
dropReason := logging.PacketDropHeaderParseError
|
||||||
|
@ -1030,7 +1030,7 @@ func (s *connection) handleLongHeaderPacket(p *receivedPacket, hdr *wire.Header)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.handleUnpackedPacket(packet, p.ecn, p.rcvTime, p.Size()); err != nil {
|
if err := s.handleUnpackedLongHeaderPacket(packet, p.ecn, p.rcvTime, p.Size()); err != nil {
|
||||||
s.closeLocal(err)
|
s.closeLocal(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -1193,7 +1193,7 @@ func (s *connection) handleVersionNegotiationPacket(p *receivedPacket) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *connection) handleUnpackedPacket(
|
func (s *connection) handleUnpackedLongHeaderPacket(
|
||||||
packet *unpackedPacket,
|
packet *unpackedPacket,
|
||||||
ecn protocol.ECN,
|
ecn protocol.ECN,
|
||||||
rcvTime time.Time,
|
rcvTime time.Time,
|
||||||
|
@ -1212,7 +1212,7 @@ func (s *connection) handleUnpackedPacket(
|
||||||
s.tracer.NegotiatedVersion(s.version, clientVersions, serverVersions)
|
s.tracer.NegotiatedVersion(s.version, clientVersions, serverVersions)
|
||||||
}
|
}
|
||||||
// The server can change the source connection ID with the first Handshake packet.
|
// The server can change the source connection ID with the first Handshake packet.
|
||||||
if s.perspective == protocol.PerspectiveClient && packet.hdr.IsLongHeader && packet.hdr.SrcConnectionID != s.handshakeDestConnID {
|
if s.perspective == protocol.PerspectiveClient && packet.hdr.SrcConnectionID != s.handshakeDestConnID {
|
||||||
cid := packet.hdr.SrcConnectionID
|
cid := packet.hdr.SrcConnectionID
|
||||||
s.logger.Debugf("Received first packet. Switching destination connection ID to: %s", cid)
|
s.logger.Debugf("Received first packet. Switching destination connection ID to: %s", cid)
|
||||||
s.handshakeDestConnID = cid
|
s.handshakeDestConnID = cid
|
||||||
|
|
|
@ -66,7 +66,7 @@ var _ = Describe("Connection", func() {
|
||||||
if isLongHeader {
|
if isLongHeader {
|
||||||
packet.longHdrPackets = []*longHeaderPacket{{
|
packet.longHdrPackets = []*longHeaderPacket{{
|
||||||
header: &wire.ExtendedHeader{
|
header: &wire.ExtendedHeader{
|
||||||
Header: wire.Header{IsLongHeader: true},
|
Header: wire.Header{},
|
||||||
PacketNumber: pn,
|
PacketNumber: pn,
|
||||||
},
|
},
|
||||||
length: 6, // foobar
|
length: 6, // foobar
|
||||||
|
@ -659,7 +659,6 @@ var _ = Describe("Connection", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getLongHeaderPacket := func(extHdr *wire.ExtendedHeader, data []byte) *receivedPacket {
|
getLongHeaderPacket := func(extHdr *wire.ExtendedHeader, data []byte) *receivedPacket {
|
||||||
ExpectWithOffset(1, extHdr.IsLongHeader).To(BeTrue())
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect(extHdr.Write(buf, conn.version)).To(Succeed())
|
Expect(extHdr.Write(buf, conn.version)).To(Succeed())
|
||||||
return &receivedPacket{
|
return &receivedPacket{
|
||||||
|
@ -671,7 +670,6 @@ var _ = Describe("Connection", func() {
|
||||||
|
|
||||||
It("drops Retry packets", func() {
|
It("drops Retry packets", func() {
|
||||||
p := getLongHeaderPacket(&wire.ExtendedHeader{Header: wire.Header{
|
p := getLongHeaderPacket(&wire.ExtendedHeader{Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
|
@ -698,9 +696,8 @@ var _ = Describe("Connection", func() {
|
||||||
It("drops packets for which header decryption fails", func() {
|
It("drops packets for which header decryption fails", func() {
|
||||||
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
Version: conn.version,
|
||||||
Version: conn.version,
|
|
||||||
},
|
},
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -712,9 +709,8 @@ var _ = Describe("Connection", func() {
|
||||||
It("drops packets for which the version is unsupported", func() {
|
It("drops packets for which the version is unsupported", func() {
|
||||||
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
Version: conn.version + 1,
|
||||||
Version: conn.version + 1,
|
|
||||||
},
|
},
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -732,7 +728,6 @@ var _ = Describe("Connection", func() {
|
||||||
protocol.SupportedVersions = append(protocol.SupportedVersions, conn.version+1)
|
protocol.SupportedVersions = append(protocol.SupportedVersions, conn.version+1)
|
||||||
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
|
@ -747,7 +742,6 @@ var _ = Describe("Connection", func() {
|
||||||
It("informs the ReceivedPacketHandler about non-ack-eliciting packets", func() {
|
It("informs the ReceivedPacketHandler about non-ack-eliciting packets", func() {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: srcConnID,
|
DestConnectionID: srcConnID,
|
||||||
Version: protocol.Version1,
|
Version: protocol.Version1,
|
||||||
|
@ -819,7 +813,6 @@ var _ = Describe("Connection", func() {
|
||||||
expectReplaceWithClosed()
|
expectReplaceWithClosed()
|
||||||
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
p := getLongHeaderPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: srcConnID,
|
DestConnectionID: srcConnID,
|
||||||
Version: conn.version,
|
Version: conn.version,
|
||||||
|
@ -982,7 +975,6 @@ var _ = Describe("Connection", func() {
|
||||||
It("ignores packets with a different source connection ID", func() {
|
It("ignores packets with a different source connection ID", func() {
|
||||||
hdr1 := &wire.ExtendedHeader{
|
hdr1 := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
|
@ -994,7 +986,6 @@ var _ = Describe("Connection", func() {
|
||||||
}
|
}
|
||||||
hdr2 := &wire.ExtendedHeader{
|
hdr2 := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
||||||
|
@ -1026,7 +1017,6 @@ var _ = Describe("Connection", func() {
|
||||||
conn.handshakeComplete = false
|
conn.handshakeComplete = false
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
|
@ -1060,7 +1050,6 @@ var _ = Describe("Connection", func() {
|
||||||
getPacketWithLength := func(connID protocol.ConnectionID, length protocol.ByteCount) (int /* header length */, *receivedPacket) {
|
getPacketWithLength := func(connID protocol.ConnectionID, length protocol.ByteCount) (int /* header length */, *receivedPacket) {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
SrcConnectionID: destConnID,
|
SrcConnectionID: destConnID,
|
||||||
|
@ -1083,7 +1072,7 @@ var _ = Describe("Connection", func() {
|
||||||
return &unpackedPacket{
|
return &unpackedPacket{
|
||||||
encryptionLevel: protocol.EncryptionHandshake,
|
encryptionLevel: protocol.EncryptionHandshake,
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
|
hdr: &wire.ExtendedHeader{Header: wire.Header{}},
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
|
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), protocol.ByteCount(len(packet.data)), gomock.Any())
|
||||||
|
@ -1099,7 +1088,7 @@ var _ = Describe("Connection", func() {
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
hdr: &wire.ExtendedHeader{
|
hdr: &wire.ExtendedHeader{
|
||||||
PacketNumber: 1,
|
PacketNumber: 1,
|
||||||
Header: wire.Header{SrcConnectionID: destConnID, IsLongHeader: true},
|
Header: wire.Header{SrcConnectionID: destConnID},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
@ -1111,7 +1100,7 @@ var _ = Describe("Connection", func() {
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
hdr: &wire.ExtendedHeader{
|
hdr: &wire.ExtendedHeader{
|
||||||
PacketNumber: 2,
|
PacketNumber: 2,
|
||||||
Header: wire.Header{SrcConnectionID: destConnID, IsLongHeader: true},
|
Header: wire.Header{SrcConnectionID: destConnID},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
@ -1134,7 +1123,7 @@ var _ = Describe("Connection", func() {
|
||||||
return &unpackedPacket{
|
return &unpackedPacket{
|
||||||
encryptionLevel: protocol.EncryptionHandshake,
|
encryptionLevel: protocol.EncryptionHandshake,
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
|
hdr: &wire.ExtendedHeader{Header: wire.Header{}},
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -1158,7 +1147,7 @@ var _ = Describe("Connection", func() {
|
||||||
return &unpackedPacket{
|
return &unpackedPacket{
|
||||||
encryptionLevel: protocol.EncryptionHandshake,
|
encryptionLevel: protocol.EncryptionHandshake,
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
hdr: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true}},
|
hdr: &wire.ExtendedHeader{Header: wire.Header{}},
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
_, packet2 := getPacketWithLength(wrongConnID, 123)
|
_, packet2 := getPacketWithLength(wrongConnID, 123)
|
||||||
|
@ -1761,20 +1750,14 @@ var _ = Describe("Connection", func() {
|
||||||
longHdrPackets: []*longHeaderPacket{
|
longHdrPackets: []*longHeaderPacket{
|
||||||
{
|
{
|
||||||
header: &wire.ExtendedHeader{
|
header: &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{Type: protocol.PacketTypeInitial},
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
},
|
|
||||||
PacketNumber: 13,
|
PacketNumber: 13,
|
||||||
},
|
},
|
||||||
length: 123,
|
length: 123,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: &wire.ExtendedHeader{
|
header: &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{Type: protocol.PacketTypeHandshake},
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
|
||||||
},
|
|
||||||
PacketNumber: 37,
|
PacketNumber: 37,
|
||||||
},
|
},
|
||||||
length: 1234,
|
length: 1234,
|
||||||
|
@ -2454,7 +2437,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
newConnID := protocol.ParseConnectionID([]byte{1, 3, 3, 7, 1, 3, 3, 7})
|
newConnID := protocol.ParseConnectionID([]byte{1, 3, 3, 7, 1, 3, 3, 7})
|
||||||
p := getPacket(&wire.ExtendedHeader{
|
p := getPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
SrcConnectionID: newConnID,
|
SrcConnectionID: newConnID,
|
||||||
DestConnectionID: srcConnID,
|
DestConnectionID: srcConnID,
|
||||||
|
@ -2495,7 +2477,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: srcConnID,
|
DestConnectionID: srcConnID,
|
||||||
SrcConnectionID: destConnID,
|
SrcConnectionID: destConnID,
|
||||||
|
@ -2652,7 +2633,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
JustBeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
retryHdr = &wire.ExtendedHeader{
|
retryHdr = &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
|
@ -2903,7 +2883,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
|
|
||||||
hdr1 := &wire.ExtendedHeader{
|
hdr1 := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
|
@ -2915,7 +2894,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
}
|
}
|
||||||
hdr2 := &wire.ExtendedHeader{
|
hdr2 := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
||||||
|
@ -2943,7 +2921,6 @@ var _ = Describe("Client Connection", func() {
|
||||||
It("ignores 0-RTT packets", func() {
|
It("ignores 0-RTT packets", func() {
|
||||||
p := getPacket(&wire.ExtendedHeader{
|
p := getPacket(&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketType0RTT,
|
Type: protocol.PacketType0RTT,
|
||||||
DestConnectionID: srcConnID,
|
DestConnectionID: srcConnID,
|
||||||
Length: 2 + 6,
|
Length: 2 + 6,
|
||||||
|
|
|
@ -30,7 +30,6 @@ func getVNP(src, dest protocol.ArbitraryLenConnectionID, numVersions int) []byte
|
||||||
func main() {
|
func main() {
|
||||||
headers := []wire.Header{
|
headers := []wire.Header{
|
||||||
{ // Initial without token
|
{ // Initial without token
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: protocol.ParseConnectionID(getRandomData(3)),
|
SrcConnectionID: protocol.ParseConnectionID(getRandomData(3)),
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
|
@ -38,14 +37,12 @@ func main() {
|
||||||
Version: version,
|
Version: version,
|
||||||
},
|
},
|
||||||
{ // Initial without token, with zero-length src conn id
|
{ // Initial without token, with zero-length src conn id
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Length: protocol.ByteCount(rand.Intn(1000)),
|
Length: protocol.ByteCount(rand.Intn(1000)),
|
||||||
Version: version,
|
Version: version,
|
||||||
},
|
},
|
||||||
{ // Initial with Token
|
{ // Initial with Token
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: protocol.ParseConnectionID(getRandomData(10)),
|
SrcConnectionID: protocol.ParseConnectionID(getRandomData(10)),
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(19)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(19)),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
|
@ -54,7 +51,6 @@ func main() {
|
||||||
Token: getRandomData(25),
|
Token: getRandomData(25),
|
||||||
},
|
},
|
||||||
{ // Handshake packet
|
{ // Handshake packet
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: protocol.ParseConnectionID(getRandomData(5)),
|
SrcConnectionID: protocol.ParseConnectionID(getRandomData(5)),
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(10)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(10)),
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
|
@ -62,14 +58,12 @@ func main() {
|
||||||
Version: version,
|
Version: version,
|
||||||
},
|
},
|
||||||
{ // Handshake packet, with zero-length src conn id
|
{ // Handshake packet, with zero-length src conn id
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(12)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(12)),
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: protocol.ByteCount(rand.Intn(1000)),
|
Length: protocol.ByteCount(rand.Intn(1000)),
|
||||||
Version: version,
|
Version: version,
|
||||||
},
|
},
|
||||||
{ // 0-RTT packet
|
{ // 0-RTT packet
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
|
||||||
Type: protocol.PacketType0RTT,
|
Type: protocol.PacketType0RTT,
|
||||||
|
@ -77,7 +71,6 @@ func main() {
|
||||||
Version: version,
|
Version: version,
|
||||||
},
|
},
|
||||||
{ // Retry Packet, with empty orig dest conn id
|
{ // Retry Packet, with empty orig dest conn id
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
|
||||||
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
|
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
|
|
|
@ -30,8 +30,14 @@ func Fuzz(data []byte) int {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !wire.IsLongHeaderPacket(data[0]) {
|
||||||
|
wire.ParseShortHeader(data, connIDLen)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
is0RTTPacket := wire.Is0RTTPacket(data)
|
is0RTTPacket := wire.Is0RTTPacket(data)
|
||||||
hdr, _, _, err := wire.ParsePacket(data, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -42,11 +48,6 @@ func Fuzz(data []byte) int {
|
||||||
panic("inconsistent 0-RTT packet detection")
|
panic("inconsistent 0-RTT packet detection")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !wire.IsLongHeaderPacket(data[0]) {
|
|
||||||
wire.ParseShortHeader(data, connIDLen)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
var extHdr *wire.ExtendedHeader
|
var extHdr *wire.ExtendedHeader
|
||||||
// Parse the extended header, if this is not a Retry packet.
|
// Parse the extended header, if this is not a Retry packet.
|
||||||
if hdr.Type == protocol.PacketTypeRetry {
|
if hdr.Type == protocol.PacketTypeRetry {
|
||||||
|
@ -60,7 +61,7 @@ func Fuzz(data []byte) int {
|
||||||
}
|
}
|
||||||
// We always use a 2-byte encoding for the Length field in Long Header packets.
|
// We always use a 2-byte encoding for the Length field in Long Header packets.
|
||||||
// Serializing the header will fail when using a higher value.
|
// Serializing the header will fail when using a higher value.
|
||||||
if hdr.IsLongHeader && hdr.Length > 16383 {
|
if hdr.Length > 16383 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
|
|
|
@ -100,11 +100,10 @@ var _ = Describe("MITM test", func() {
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
if wire.IsLongHeaderPacket(raw[0]) {
|
if wire.IsLongHeaderPacket(raw[0]) {
|
||||||
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(raw)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
replyHdr := &wire.ExtendedHeader{
|
replyHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: hdr.IsLongHeader,
|
|
||||||
DestConnectionID: hdr.DestConnectionID,
|
DestConnectionID: hdr.DestConnectionID,
|
||||||
SrcConnectionID: hdr.SrcConnectionID,
|
SrcConnectionID: hdr.SrcConnectionID,
|
||||||
Type: hdr.Type,
|
Type: hdr.Type,
|
||||||
|
@ -340,7 +339,7 @@ var _ = Describe("MITM test", func() {
|
||||||
if dir == quicproxy.DirectionIncoming {
|
if dir == quicproxy.DirectionIncoming {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(raw)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
if hdr.Type != protocol.PacketTypeInitial {
|
if hdr.Type != protocol.PacketTypeInitial {
|
||||||
|
@ -382,7 +381,7 @@ var _ = Describe("MITM test", func() {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
|
||||||
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(raw)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
if hdr.Type != protocol.PacketTypeInitial {
|
if hdr.Type != protocol.PacketTypeInitial {
|
||||||
|
@ -415,7 +414,7 @@ var _ = Describe("MITM test", func() {
|
||||||
if dir == quicproxy.DirectionIncoming {
|
if dir == quicproxy.DirectionIncoming {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(raw)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
if hdr.Type != protocol.PacketTypeInitial || injected {
|
if hdr.Type != protocol.PacketTypeInitial || injected {
|
||||||
return 0
|
return 0
|
||||||
|
@ -443,7 +442,7 @@ var _ = Describe("MITM test", func() {
|
||||||
if dir == quicproxy.DirectionIncoming {
|
if dir == quicproxy.DirectionIncoming {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
|
hdr, _, _, err := wire.ParsePacket(raw)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
if hdr.Type != protocol.PacketTypeInitial || injected {
|
if hdr.Type != protocol.PacketTypeInitial || injected {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -38,7 +38,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
if !wire.IsLongHeaderPacket(data[0]) {
|
if !wire.IsLongHeaderPacket(data[0]) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
hdr, _, rest, err := wire.ParsePacket(data, 0)
|
hdr, _, rest, err := wire.ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
if hdr.Type == protocol.PacketType0RTT {
|
if hdr.Type == protocol.PacketType0RTT {
|
||||||
atomic.AddUint32(&num0RTTPackets, 1)
|
atomic.AddUint32(&num0RTTPackets, 1)
|
||||||
|
@ -351,7 +351,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
RemoteAddr: fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
|
RemoteAddr: fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
|
||||||
DelayPacket: func(_ quicproxy.Direction, data []byte) time.Duration {
|
DelayPacket: func(_ quicproxy.Direction, data []byte) time.Duration {
|
||||||
if wire.IsLongHeaderPacket(data[0]) {
|
if wire.IsLongHeaderPacket(data[0]) {
|
||||||
hdr, _, _, err := wire.ParsePacket(data, 0)
|
hdr, _, _, err := wire.ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
if hdr.Type == protocol.PacketType0RTT {
|
if hdr.Type == protocol.PacketType0RTT {
|
||||||
atomic.AddUint32(&num0RTTPackets, 1)
|
atomic.AddUint32(&num0RTTPackets, 1)
|
||||||
|
@ -363,7 +363,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
if !wire.IsLongHeaderPacket(data[0]) {
|
if !wire.IsLongHeaderPacket(data[0]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
hdr, _, _, err := wire.ParsePacket(data, 0)
|
hdr, _, _, err := wire.ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
if hdr.Type == protocol.PacketType0RTT {
|
if hdr.Type == protocol.PacketType0RTT {
|
||||||
// drop 25% of the 0-RTT packets
|
// drop 25% of the 0-RTT packets
|
||||||
|
@ -398,7 +398,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
|
|
||||||
countZeroRTTBytes := func(data []byte) (n protocol.ByteCount) {
|
countZeroRTTBytes := func(data []byte) (n protocol.ByteCount) {
|
||||||
for len(data) > 0 {
|
for len(data) > 0 {
|
||||||
hdr, _, rest, err := wire.ParsePacket(data, 0)
|
hdr, _, rest, err := wire.ParsePacket(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ var _ = Describe("QUIC Proxy", func() {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
hdr := wire.ExtendedHeader{
|
hdr := wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Version: protocol.VersionTLS,
|
Version: protocol.VersionTLS,
|
||||||
Length: 4 + protocol.ByteCount(len(payload)),
|
Length: 4 + protocol.ByteCount(len(payload)),
|
||||||
|
@ -48,7 +47,7 @@ var _ = Describe("QUIC Proxy", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
readPacketNumber := func(b []byte) protocol.PacketNumber {
|
readPacketNumber := func(b []byte) protocol.PacketNumber {
|
||||||
hdr, data, _, err := wire.ParsePacket(b, 0)
|
hdr, data, _, err := wire.ParsePacket(b)
|
||||||
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial))
|
Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial))
|
||||||
extHdr, err := hdr.ParseExtended(bytes.NewReader(data), protocol.VersionTLS)
|
extHdr, err := hdr.ParseExtended(bytes.NewReader(data), protocol.VersionTLS)
|
||||||
|
|
|
@ -50,7 +50,6 @@ func ComposeInitialPacket(srcConnID protocol.ConnectionID, destConnID protocol.C
|
||||||
length := payloadSize + int(pnLength) + sealer.Overhead()
|
length := payloadSize + int(pnLength) + sealer.Overhead()
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
@ -88,7 +87,6 @@ func ComposeRetryPacket(
|
||||||
) []byte {
|
) []byte {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
|
|
@ -42,12 +42,7 @@ func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (bool
|
||||||
if _, err := b.Seek(int64(h.Header.ParsedLen())-1, io.SeekCurrent); err != nil {
|
if _, err := b.Seek(int64(h.Header.ParsedLen())-1, io.SeekCurrent); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
var reservedBitsValid bool
|
reservedBitsValid, err := h.parseLongHeader(b, v)
|
||||||
if h.IsLongHeader {
|
|
||||||
reservedBitsValid, err = h.parseLongHeader(b, v)
|
|
||||||
} else {
|
|
||||||
panic("parsed a short header packet")
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -106,10 +101,7 @@ func (h *ExtendedHeader) Write(b *bytes.Buffer, ver protocol.VersionNumber) erro
|
||||||
if h.SrcConnectionID.Len() > protocol.MaxConnIDLen {
|
if h.SrcConnectionID.Len() > protocol.MaxConnIDLen {
|
||||||
return fmt.Errorf("invalid connection ID length: %d bytes", h.SrcConnectionID.Len())
|
return fmt.Errorf("invalid connection ID length: %d bytes", h.SrcConnectionID.Len())
|
||||||
}
|
}
|
||||||
if h.IsLongHeader {
|
return h.writeLongHeader(b, ver)
|
||||||
return h.writeLongHeader(b, ver)
|
|
||||||
}
|
|
||||||
panic("tried to write short extended header")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, version protocol.VersionNumber) error {
|
func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, version protocol.VersionNumber) error {
|
||||||
|
@ -171,39 +163,29 @@ func (h *ExtendedHeader) ParsedLen() protocol.ByteCount {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLength determines the length of the Header.
|
// GetLength determines the length of the Header.
|
||||||
func (h *ExtendedHeader) GetLength(v protocol.VersionNumber) protocol.ByteCount {
|
func (h *ExtendedHeader) GetLength(_ protocol.VersionNumber) protocol.ByteCount {
|
||||||
if h.IsLongHeader {
|
length := 1 /* type byte */ + 4 /* version */ + 1 /* dest conn ID len */ + protocol.ByteCount(h.DestConnectionID.Len()) + 1 /* src conn ID len */ + protocol.ByteCount(h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + 2 /* length */
|
||||||
length := 1 /* type byte */ + 4 /* version */ + 1 /* dest conn ID len */ + protocol.ByteCount(h.DestConnectionID.Len()) + 1 /* src conn ID len */ + protocol.ByteCount(h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + 2 /* length */
|
if h.Type == protocol.PacketTypeInitial {
|
||||||
if h.Type == protocol.PacketTypeInitial {
|
length += quicvarint.Len(uint64(len(h.Token))) + protocol.ByteCount(len(h.Token))
|
||||||
length += quicvarint.Len(uint64(len(h.Token))) + protocol.ByteCount(len(h.Token))
|
|
||||||
}
|
|
||||||
return length
|
|
||||||
}
|
}
|
||||||
|
|
||||||
length := protocol.ByteCount(1 /* type byte */ + h.DestConnectionID.Len())
|
|
||||||
length += protocol.ByteCount(h.PacketNumberLen)
|
|
||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log logs the Header
|
// Log logs the Header
|
||||||
func (h *ExtendedHeader) Log(logger utils.Logger) {
|
func (h *ExtendedHeader) Log(logger utils.Logger) {
|
||||||
if h.IsLongHeader {
|
var token string
|
||||||
var token string
|
if h.Type == protocol.PacketTypeInitial || h.Type == protocol.PacketTypeRetry {
|
||||||
if h.Type == protocol.PacketTypeInitial || h.Type == protocol.PacketTypeRetry {
|
if len(h.Token) == 0 {
|
||||||
if len(h.Token) == 0 {
|
token = "Token: (empty), "
|
||||||
token = "Token: (empty), "
|
} else {
|
||||||
} else {
|
token = fmt.Sprintf("Token: %#x, ", h.Token)
|
||||||
token = fmt.Sprintf("Token: %#x, ", h.Token)
|
}
|
||||||
}
|
if h.Type == protocol.PacketTypeRetry {
|
||||||
if h.Type == protocol.PacketTypeRetry {
|
logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sVersion: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.Version)
|
||||||
logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sVersion: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.Version)
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sPacketNumber: %d, PacketNumberLen: %d, Length: %d, Version: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.PacketNumber, h.PacketNumberLen, h.Length, h.Version)
|
|
||||||
} else {
|
|
||||||
panic("logged short ExtendedHeader")
|
|
||||||
}
|
}
|
||||||
|
logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sPacketNumber: %d, PacketNumberLen: %d, Length: %d, Version: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.PacketNumber, h.PacketNumberLen, h.Length, h.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePacketNumber(b *bytes.Buffer, pn protocol.PacketNumber, pnLen protocol.PacketNumberLen) error {
|
func writePacketNumber(b *bytes.Buffer, pn protocol.PacketNumber, pnLen protocol.PacketNumberLen) error {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Header", func() {
|
var _ = Describe("Header", func() {
|
||||||
const versionIETFHeader = protocol.VersionTLS // a QUIC version that uses the IETF Header format
|
const versionIETFHeader = protocol.Version1
|
||||||
|
|
||||||
Context("Writing", func() {
|
Context("Writing", func() {
|
||||||
var buf *bytes.Buffer
|
var buf *bytes.Buffer
|
||||||
|
@ -29,7 +29,6 @@ var _ = Describe("Header", func() {
|
||||||
It("writes", func() {
|
It("writes", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x0, 0x0, 0x13, 0x37}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x0, 0x0, 0x13, 0x37}),
|
||||||
|
@ -55,7 +54,6 @@ var _ = Describe("Header", func() {
|
||||||
It("writes a header with a 20 byte connection ID", func() {
|
It("writes a header with a 20 byte connection ID", func() {
|
||||||
err := (&ExtendedHeader{
|
err := (&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}), // connection IDs must be at most 20 bytes long
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}), // connection IDs must be at most 20 bytes long
|
||||||
Version: 0x1020304,
|
Version: 0x1020304,
|
||||||
|
@ -72,10 +70,9 @@ var _ = Describe("Header", func() {
|
||||||
token := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
|
token := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
Version: 0x1020304,
|
||||||
Version: 0x1020304,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Token: token,
|
||||||
Token: token,
|
|
||||||
},
|
},
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
|
@ -88,10 +85,9 @@ var _ = Describe("Header", func() {
|
||||||
It("uses a 2-byte encoding for the length on Initial packets", func() {
|
It("uses a 2-byte encoding for the length on Initial packets", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
Version: 0x1020304,
|
||||||
Version: 0x1020304,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Length: 37,
|
||||||
Length: 37,
|
|
||||||
},
|
},
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
|
@ -104,10 +100,9 @@ var _ = Describe("Header", func() {
|
||||||
It("writes a Retry packet", func() {
|
It("writes a Retry packet", func() {
|
||||||
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
||||||
Expect((&ExtendedHeader{Header: Header{
|
Expect((&ExtendedHeader{Header: Header{
|
||||||
IsLongHeader: true,
|
Version: protocol.Version1,
|
||||||
Version: protocol.Version1,
|
Type: protocol.PacketTypeRetry,
|
||||||
Type: protocol.PacketTypeRetry,
|
Token: token,
|
||||||
Token: token,
|
|
||||||
}}).Write(buf, versionIETFHeader)).To(Succeed())
|
}}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
expected := []byte{0xc0 | 0b11<<4}
|
expected := []byte{0xc0 | 0b11<<4}
|
||||||
expected = appendVersion(expected, protocol.Version1)
|
expected = appendVersion(expected, protocol.Version1)
|
||||||
|
@ -122,9 +117,8 @@ var _ = Describe("Header", func() {
|
||||||
It("writes an Initial", func() {
|
It("writes an Initial", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
Version: protocol.Version2,
|
||||||
Version: protocol.Version2,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
},
|
},
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
|
@ -135,10 +129,9 @@ var _ = Describe("Header", func() {
|
||||||
It("writes a Retry packet", func() {
|
It("writes a Retry packet", func() {
|
||||||
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
||||||
Expect((&ExtendedHeader{Header: Header{
|
Expect((&ExtendedHeader{Header: Header{
|
||||||
IsLongHeader: true,
|
Version: protocol.Version2,
|
||||||
Version: protocol.Version2,
|
Type: protocol.PacketTypeRetry,
|
||||||
Type: protocol.PacketTypeRetry,
|
Token: token,
|
||||||
Token: token,
|
|
||||||
}}).Write(buf, versionIETFHeader)).To(Succeed())
|
}}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
expected := []byte{0xc0 | 0b11<<4}
|
expected := []byte{0xc0 | 0b11<<4}
|
||||||
expected = appendVersion(expected, protocol.Version2)
|
expected = appendVersion(expected, protocol.Version2)
|
||||||
|
@ -151,9 +144,8 @@ var _ = Describe("Header", func() {
|
||||||
It("writes a Handshake Packet", func() {
|
It("writes a Handshake Packet", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
Version: protocol.Version2,
|
||||||
Version: protocol.Version2,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
|
||||||
},
|
},
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
|
@ -164,9 +156,8 @@ var _ = Describe("Header", func() {
|
||||||
It("writes a 0-RTT Packet", func() {
|
It("writes a 0-RTT Packet", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
Version: protocol.Version2,
|
||||||
Version: protocol.Version2,
|
Type: protocol.PacketType0RTT,
|
||||||
Type: protocol.PacketType0RTT,
|
|
||||||
},
|
},
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
|
@ -186,7 +177,6 @@ var _ = Describe("Header", func() {
|
||||||
It("has the right length for the Long Header, for a short length", func() {
|
It("has the right length for the Long Header, for a short length", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
|
@ -203,7 +193,6 @@ var _ = Describe("Header", func() {
|
||||||
It("has the right length for the Long Header, for a long length", func() {
|
It("has the right length for the Long Header, for a long length", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
|
@ -220,7 +209,6 @@ var _ = Describe("Header", func() {
|
||||||
It("has the right length for an Initial that has a short length", func() {
|
It("has the right length for an Initial that has a short length", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
|
@ -237,7 +225,6 @@ var _ = Describe("Header", func() {
|
||||||
It("has the right length for an Initial not containing a Token", func() {
|
It("has the right length for an Initial not containing a Token", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
|
@ -254,7 +241,6 @@ var _ = Describe("Header", func() {
|
||||||
It("has the right length for an Initial containing a Token", func() {
|
It("has the right length for an Initial containing a Token", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
|
@ -290,7 +276,6 @@ var _ = Describe("Header", func() {
|
||||||
It("logs Long Headers", func() {
|
It("logs Long Headers", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x013, 0x37, 0x13, 0x37}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x013, 0x37, 0x13, 0x37}),
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
|
@ -306,7 +291,6 @@ var _ = Describe("Header", func() {
|
||||||
It("logs Initial Packets with a Token", func() {
|
It("logs Initial Packets with a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
|
@ -323,7 +307,6 @@ var _ = Describe("Header", func() {
|
||||||
It("logs Initial packets without a Token", func() {
|
It("logs Initial packets without a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
|
@ -339,7 +322,6 @@ var _ = Describe("Header", func() {
|
||||||
It("logs Retry packets with a Token", func() {
|
It("logs Retry packets with a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xca, 0xfe, 0x13, 0x37}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
|
|
|
@ -121,9 +121,8 @@ var ErrUnsupportedVersion = errors.New("unsupported version")
|
||||||
|
|
||||||
// The Header is the version independent part of the header
|
// The Header is the version independent part of the header
|
||||||
type Header struct {
|
type Header struct {
|
||||||
IsLongHeader bool
|
typeByte byte
|
||||||
typeByte byte
|
Type protocol.PacketType
|
||||||
Type protocol.PacketType
|
|
||||||
|
|
||||||
Version protocol.VersionNumber
|
Version protocol.VersionNumber
|
||||||
SrcConnectionID protocol.ConnectionID
|
SrcConnectionID protocol.ConnectionID
|
||||||
|
@ -140,24 +139,22 @@ type Header struct {
|
||||||
// If the packet has a long header, the packet is cut according to the length field.
|
// If the packet has a long header, the packet is cut according to the length field.
|
||||||
// If we understand the version, the packet is header up unto the packet number.
|
// If we understand the version, the packet is header up unto the packet number.
|
||||||
// Otherwise, only the invariant part of the header is parsed.
|
// Otherwise, only the invariant part of the header is parsed.
|
||||||
func ParsePacket(data []byte, shortHeaderConnIDLen int) (*Header, []byte /* packet data */, []byte /* rest */, error) {
|
func ParsePacket(data []byte) (*Header, []byte, []byte, error) {
|
||||||
hdr, err := parseHeader(bytes.NewReader(data), shortHeaderConnIDLen)
|
if len(data) == 0 || !IsLongHeaderPacket(data[0]) {
|
||||||
|
return nil, nil, nil, errors.New("not a long header packet")
|
||||||
|
}
|
||||||
|
hdr, err := parseHeader(bytes.NewReader(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrUnsupportedVersion {
|
if err == ErrUnsupportedVersion {
|
||||||
return hdr, nil, nil, ErrUnsupportedVersion
|
return hdr, nil, nil, ErrUnsupportedVersion
|
||||||
}
|
}
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
var rest []byte
|
if protocol.ByteCount(len(data)) < hdr.ParsedLen()+hdr.Length {
|
||||||
if hdr.IsLongHeader {
|
return nil, nil, nil, fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(data)-int(hdr.ParsedLen()), hdr.Length)
|
||||||
if protocol.ByteCount(len(data)) < hdr.ParsedLen()+hdr.Length {
|
|
||||||
return nil, nil, nil, fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(data)-int(hdr.ParsedLen()), hdr.Length)
|
|
||||||
}
|
|
||||||
packetLen := int(hdr.ParsedLen() + hdr.Length)
|
|
||||||
rest = data[packetLen:]
|
|
||||||
data = data[:packetLen]
|
|
||||||
}
|
}
|
||||||
return hdr, data, rest, nil
|
packetLen := int(hdr.ParsedLen() + hdr.Length)
|
||||||
|
return hdr, data[:packetLen], data[packetLen:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseHeader parses the header.
|
// ParseHeader parses the header.
|
||||||
|
@ -165,43 +162,17 @@ func ParsePacket(data []byte, shortHeaderConnIDLen int) (*Header, []byte /* pack
|
||||||
// For long header packets:
|
// For long header packets:
|
||||||
// * if we understand the version: up to the packet number
|
// * if we understand the version: up to the packet number
|
||||||
// * if not, only the invariant part of the header
|
// * if not, only the invariant part of the header
|
||||||
func parseHeader(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error) {
|
func parseHeader(b *bytes.Reader) (*Header, error) {
|
||||||
startLen := b.Len()
|
startLen := b.Len()
|
||||||
h, err := parseHeaderImpl(b, shortHeaderConnIDLen)
|
|
||||||
if err != nil {
|
|
||||||
return h, err
|
|
||||||
}
|
|
||||||
h.parsedLen = protocol.ByteCount(startLen - b.Len())
|
|
||||||
return h, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHeaderImpl(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error) {
|
|
||||||
typeByte, err := b.ReadByte()
|
typeByte, err := b.ReadByte()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &Header{
|
h := &Header{typeByte: typeByte}
|
||||||
typeByte: typeByte,
|
err = h.parseLongHeader(b)
|
||||||
IsLongHeader: IsLongHeaderPacket(typeByte),
|
h.parsedLen = protocol.ByteCount(startLen - b.Len())
|
||||||
}
|
return h, err
|
||||||
|
|
||||||
if !h.IsLongHeader {
|
|
||||||
if h.typeByte&0x40 == 0 {
|
|
||||||
return nil, errors.New("not a QUIC packet")
|
|
||||||
}
|
|
||||||
if err := h.parseShortHeader(b, shortHeaderConnIDLen); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
return h, h.parseLongHeader(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Header) parseShortHeader(b *bytes.Reader, shortHeaderConnIDLen int) error {
|
|
||||||
var err error
|
|
||||||
h.DestConnectionID, err = protocol.ReadConnectionID(b, shortHeaderConnIDLen)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Header) parseLongHeader(b *bytes.Reader) error {
|
func (h *Header) parseLongHeader(b *bytes.Reader) error {
|
||||||
|
@ -321,8 +292,5 @@ func (h *Header) toExtendedHeader() *ExtendedHeader {
|
||||||
|
|
||||||
// PacketType is the type of the packet, for logging purposes
|
// PacketType is the type of the packet, for logging purposes
|
||||||
func (h *Header) PacketType() string {
|
func (h *Header) PacketType() string {
|
||||||
if h.IsLongHeader {
|
return h.Type.String()
|
||||||
return h.Type.String()
|
|
||||||
}
|
|
||||||
return "1-RTT"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ var _ = Describe("Header Parsing", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6}),
|
||||||
|
@ -35,7 +34,6 @@ var _ = Describe("Header Parsing", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x13, 0x37}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xca, 0xfb, 0xad, 0x13, 0x37}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 8, 9}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 8, 9}),
|
||||||
|
@ -186,10 +184,9 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte("foobar")...)
|
data = append(data, []byte("foobar")...)
|
||||||
Expect(IsVersionNegotiationPacket(data)).To(BeFalse())
|
Expect(IsVersionNegotiationPacket(data)).To(BeFalse())
|
||||||
|
|
||||||
hdr, pdata, rest, err := ParsePacket(data, 0)
|
hdr, pdata, rest, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(pdata).To(Equal(data))
|
Expect(pdata).To(Equal(data))
|
||||||
Expect(hdr.IsLongHeader).To(BeTrue())
|
|
||||||
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
||||||
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial))
|
Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial))
|
||||||
|
@ -214,7 +211,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
0xde, 0xca, 0xfb, 0xad, // dest conn ID
|
0xde, 0xca, 0xfb, 0xad, // dest conn ID
|
||||||
0xde, 0xad, 0xbe, 0xef, // src conn ID
|
0xde, 0xad, 0xbe, 0xef, // src conn ID
|
||||||
}
|
}
|
||||||
_, _, _, err := ParsePacket(data, 0)
|
_, _, _, err := ParsePacket(data)
|
||||||
Expect(err).To(MatchError("not a QUIC packet"))
|
Expect(err).To(MatchError("not a QUIC packet"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -228,9 +225,8 @@ var _ = Describe("Header Parsing", func() {
|
||||||
0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, // src conn ID
|
0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, // src conn ID
|
||||||
'f', 'o', 'o', 'b', 'a', 'r', // unspecified bytes
|
'f', 'o', 'o', 'b', 'a', 'r', // unspecified bytes
|
||||||
}
|
}
|
||||||
hdr, _, rest, err := ParsePacket(data, 0)
|
hdr, _, rest, err := ParsePacket(data)
|
||||||
Expect(err).To(MatchError(ErrUnsupportedVersion))
|
Expect(err).To(MatchError(ErrUnsupportedVersion))
|
||||||
Expect(hdr.IsLongHeader).To(BeTrue())
|
|
||||||
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0xdeadbeef)))
|
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0xdeadbeef)))
|
||||||
Expect(hdr.DestConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8})))
|
Expect(hdr.DestConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8})))
|
||||||
Expect(hdr.SrcConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1})))
|
Expect(hdr.SrcConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1})))
|
||||||
|
@ -245,7 +241,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef}...) // source connection ID
|
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef}...) // source connection ID
|
||||||
data = append(data, encodeVarInt(0)...) // length
|
data = append(data, encodeVarInt(0)...) // length
|
||||||
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketType0RTT))
|
Expect(hdr.Type).To(Equal(protocol.PacketType0RTT))
|
||||||
Expect(hdr.SrcConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef})))
|
Expect(hdr.SrcConnectionID).To(Equal(protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef})))
|
||||||
|
@ -260,7 +256,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, 0) // src conn ID len
|
data = append(data, 0) // src conn ID len
|
||||||
data = append(data, encodeVarInt(0)...) // length
|
data = append(data, encodeVarInt(0)...) // length
|
||||||
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.SrcConnectionID).To(BeZero())
|
Expect(hdr.SrcConnectionID).To(BeZero())
|
||||||
Expect(hdr.DestConnectionID).To(Equal(protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})))
|
Expect(hdr.DestConnectionID).To(Equal(protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})))
|
||||||
|
@ -274,7 +270,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, 0x0) // src conn ID len
|
data = append(data, 0x0) // src conn ID len
|
||||||
data = append(data, encodeVarInt(0)...) // length
|
data = append(data, encodeVarInt(0)...) // length
|
||||||
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
|
||||||
_, _, _, err := ParsePacket(data, 0)
|
_, _, _, err := ParsePacket(data)
|
||||||
Expect(err).To(MatchError(protocol.ErrInvalidConnectionIDLen))
|
Expect(err).To(MatchError(protocol.ErrInvalidConnectionIDLen))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -286,7 +282,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // length
|
data = append(data, encodeVarInt(0)...) // length
|
||||||
data = append(data, []byte{0x1, 0x23}...)
|
data = append(data, []byte{0x1, 0x23}...)
|
||||||
|
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
extHdr, err := hdr.ParseExtended(b, protocol.Version1)
|
extHdr, err := hdr.ParseExtended(b, protocol.Version1)
|
||||||
|
@ -305,7 +301,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
|
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
|
||||||
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
||||||
data = append(data, []byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}...)
|
data = append(data, []byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}...)
|
||||||
hdr, pdata, rest, err := ParsePacket(data, 0)
|
hdr, pdata, rest, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeRetry))
|
Expect(hdr.Type).To(Equal(protocol.PacketTypeRetry))
|
||||||
Expect(hdr.Version).To(Equal(protocol.Version1))
|
Expect(hdr.Version).To(Equal(protocol.Version1))
|
||||||
|
@ -325,7 +321,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
|
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
|
||||||
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
||||||
data = append(data, []byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}...)
|
data = append(data, []byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}...)
|
||||||
hdr, pdata, rest, err := ParsePacket(data, 0)
|
hdr, pdata, rest, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeRetry))
|
Expect(hdr.Type).To(Equal(protocol.PacketTypeRetry))
|
||||||
Expect(hdr.Version).To(Equal(protocol.Version2))
|
Expect(hdr.Version).To(Equal(protocol.Version2))
|
||||||
|
@ -343,7 +339,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
|
||||||
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...)
|
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...)
|
||||||
// this results in a token length of 0
|
// this results in a token length of 0
|
||||||
_, _, _, err := ParsePacket(data, 0)
|
_, _, _, err := ParsePacket(data)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -355,7 +351,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, encodeVarInt(0x42)...) // length, 1 byte
|
data = append(data, encodeVarInt(0x42)...) // length, 1 byte
|
||||||
data = append(data, []byte{0x12, 0x34}...) // packet number
|
data = append(data, []byte{0x12, 0x34}...) // packet number
|
||||||
|
|
||||||
_, _, _, err := ParsePacket(data, 0)
|
_, _, _, err := ParsePacket(data)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -365,7 +361,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{0x0, 0x0}...) // connection ID lengths
|
data = append(data, []byte{0x0, 0x0}...) // connection ID lengths
|
||||||
data = append(data, encodeVarInt(2)...) // length
|
data = append(data, encodeVarInt(2)...) // length
|
||||||
data = append(data, []byte{0x12, 0x34}...) // packet number
|
data = append(data, []byte{0x12, 0x34}...) // packet number
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeHandshake))
|
Expect(hdr.Type).To(Equal(protocol.PacketTypeHandshake))
|
||||||
extHdr, err := hdr.ParseExtended(bytes.NewReader(data), protocol.Version1)
|
extHdr, err := hdr.ParseExtended(bytes.NewReader(data), protocol.Version1)
|
||||||
|
@ -381,8 +377,8 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // dest conn ID
|
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // dest conn ID
|
||||||
data = append(data, 0x8) // src conn ID len
|
data = append(data, 0x8) // src conn ID len
|
||||||
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // src conn ID
|
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // src conn ID
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 1; i < len(data); i++ {
|
||||||
_, _, _, err := ParsePacket(data[:i], 0)
|
_, _, _, err := ParsePacket(data[:i])
|
||||||
Expect(err).To(Equal(io.EOF))
|
Expect(err).To(Equal(io.EOF))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -396,7 +392,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef}...) // packet number
|
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef}...) // packet number
|
||||||
for i := hdrLen; i < len(data); i++ {
|
for i := hdrLen; i < len(data); i++ {
|
||||||
data = data[:i]
|
data = data[:i]
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
_, err = hdr.ParseExtended(b, protocol.Version1)
|
_, err = hdr.ParseExtended(b, protocol.Version1)
|
||||||
|
@ -413,7 +409,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
hdrLen := len(data)
|
hdrLen := len(data)
|
||||||
for i := hdrLen; i < len(data); i++ {
|
for i := hdrLen; i < len(data); i++ {
|
||||||
data = data[:i]
|
data = data[:i]
|
||||||
hdr, _, _, err := ParsePacket(data, 0)
|
hdr, _, _, err := ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
_, err = hdr.ParseExtended(b, protocol.Version1)
|
_, err = hdr.ParseExtended(b, protocol.Version1)
|
||||||
|
@ -425,7 +421,6 @@ var _ = Describe("Header Parsing", func() {
|
||||||
It("cuts packets", func() {
|
It("cuts packets", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
hdr := Header{
|
hdr := Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
Length: 2 + 6,
|
Length: 2 + 6,
|
||||||
|
@ -439,7 +434,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
hdrRaw := append([]byte{}, buf.Bytes()...)
|
hdrRaw := append([]byte{}, buf.Bytes()...)
|
||||||
buf.Write([]byte("foobar")) // payload of the first packet
|
buf.Write([]byte("foobar")) // payload of the first packet
|
||||||
buf.Write([]byte("raboof")) // second packet
|
buf.Write([]byte("raboof")) // second packet
|
||||||
parsedHdr, data, rest, err := ParsePacket(buf.Bytes(), 4)
|
parsedHdr, data, rest, err := ParsePacket(buf.Bytes())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(parsedHdr.Type).To(Equal(hdr.Type))
|
Expect(parsedHdr.Type).To(Equal(hdr.Type))
|
||||||
Expect(parsedHdr.DestConnectionID).To(Equal(hdr.DestConnectionID))
|
Expect(parsedHdr.DestConnectionID).To(Equal(hdr.DestConnectionID))
|
||||||
|
@ -451,7 +446,6 @@ var _ = Describe("Header Parsing", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
Length: 3,
|
Length: 3,
|
||||||
|
@ -460,7 +454,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
PacketNumber: 0x1337,
|
PacketNumber: 0x1337,
|
||||||
PacketNumberLen: 2,
|
PacketNumberLen: 2,
|
||||||
}).Write(buf, protocol.Version1)).To(Succeed())
|
}).Write(buf, protocol.Version1)).To(Succeed())
|
||||||
_, _, _, err := ParsePacket(buf.Bytes(), 4)
|
_, _, _, err := ParsePacket(buf.Bytes())
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err.Error()).To(ContainSubstring("packet length (2 bytes) is smaller than the expected length (3 bytes)"))
|
Expect(err.Error()).To(ContainSubstring("packet length (2 bytes) is smaller than the expected length (3 bytes)"))
|
||||||
})
|
})
|
||||||
|
@ -469,7 +463,6 @@ var _ = Describe("Header Parsing", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
Header: Header{
|
Header: Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
Length: 1000,
|
Length: 1000,
|
||||||
|
@ -479,7 +472,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
PacketNumberLen: 2,
|
PacketNumberLen: 2,
|
||||||
}).Write(buf, protocol.Version1)).To(Succeed())
|
}).Write(buf, protocol.Version1)).To(Succeed())
|
||||||
buf.Write(make([]byte, 500-2 /* for packet number length */))
|
buf.Write(make([]byte, 500-2 /* for packet number length */))
|
||||||
_, _, _, err := ParsePacket(buf.Bytes(), 4)
|
_, _, _, err := ParsePacket(buf.Bytes())
|
||||||
Expect(err).To(MatchError("packet length (500 bytes) is smaller than the expected length (1000 bytes)"))
|
Expect(err).To(MatchError("packet length (500 bytes) is smaller than the expected length (1000 bytes)"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -491,7 +484,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("tells its packet type for logging", func() {
|
It("tells its packet type for logging", func() {
|
||||||
Expect((&Header{IsLongHeader: true, Type: protocol.PacketTypeHandshake}).PacketType()).To(Equal("Handshake"))
|
Expect((&Header{Type: protocol.PacketTypeInitial}).PacketType()).To(Equal("Initial"))
|
||||||
Expect((&Header{}).PacketType()).To(Equal("1-RTT"))
|
Expect((&Header{Type: protocol.PacketTypeHandshake}).PacketType()).To(Equal("Handshake"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,9 +6,6 @@ import (
|
||||||
|
|
||||||
// PacketTypeFromHeader determines the packet type from a *wire.Header.
|
// PacketTypeFromHeader determines the packet type from a *wire.Header.
|
||||||
func PacketTypeFromHeader(hdr *Header) PacketType {
|
func PacketTypeFromHeader(hdr *Header) PacketType {
|
||||||
if !hdr.IsLongHeader {
|
|
||||||
return PacketType1RTT
|
|
||||||
}
|
|
||||||
if hdr.Version == 0 {
|
if hdr.Version == 0 {
|
||||||
return PacketTypeVersionNegotiation
|
return PacketTypeVersionNegotiation
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,49 +12,38 @@ var _ = Describe("Packet Header", func() {
|
||||||
Context("determining the packet type from the header", func() {
|
Context("determining the packet type from the header", func() {
|
||||||
It("recognizes Initial packets", func() {
|
It("recognizes Initial packets", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{
|
Expect(PacketTypeFromHeader(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Version: protocol.VersionTLS,
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
})).To(Equal(PacketTypeInitial))
|
})).To(Equal(PacketTypeInitial))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("recognizes Handshake packets", func() {
|
It("recognizes Handshake packets", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{
|
Expect(PacketTypeFromHeader(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
Version: protocol.VersionTLS,
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
})).To(Equal(PacketTypeHandshake))
|
})).To(Equal(PacketTypeHandshake))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("recognizes Retry packets", func() {
|
It("recognizes Retry packets", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{
|
Expect(PacketTypeFromHeader(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeRetry,
|
||||||
Type: protocol.PacketTypeRetry,
|
Version: protocol.VersionTLS,
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
})).To(Equal(PacketTypeRetry))
|
})).To(Equal(PacketTypeRetry))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("recognizes 0-RTT packets", func() {
|
It("recognizes 0-RTT packets", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{
|
Expect(PacketTypeFromHeader(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketType0RTT,
|
||||||
Type: protocol.PacketType0RTT,
|
Version: protocol.VersionTLS,
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
})).To(Equal(PacketType0RTT))
|
})).To(Equal(PacketType0RTT))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("recognizes Version Negotiation packets", func() {
|
It("recognizes Version Negotiation packets", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{IsLongHeader: true})).To(Equal(PacketTypeVersionNegotiation))
|
Expect(PacketTypeFromHeader(&wire.Header{})).To(Equal(PacketTypeVersionNegotiation))
|
||||||
})
|
|
||||||
|
|
||||||
It("recognizes 1-RTT packets", func() {
|
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{})).To(Equal(PacketType1RTT))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("handles unrecognized packet types", func() {
|
It("handles unrecognized packet types", func() {
|
||||||
Expect(PacketTypeFromHeader(&wire.Header{
|
Expect(PacketTypeFromHeader(&wire.Header{Version: protocol.VersionTLS})).To(Equal(PacketTypeNotDetermined))
|
||||||
IsLongHeader: true,
|
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
})).To(Equal(PacketTypeNotDetermined))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,7 +40,6 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&wire.ExtendedHeader{
|
Expect((&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: t,
|
Type: t,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
Length: length,
|
Length: length,
|
||||||
|
|
|
@ -69,9 +69,6 @@ type coalescedPacket struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *longHeaderPacket) EncryptionLevel() protocol.EncryptionLevel {
|
func (p *longHeaderPacket) EncryptionLevel() protocol.EncryptionLevel {
|
||||||
if !p.header.IsLongHeader {
|
|
||||||
panic("this shouldn't happen any more")
|
|
||||||
}
|
|
||||||
//nolint:exhaustive // Will never be called for Retry packets (and they don't have encrypted data).
|
//nolint:exhaustive // Will never be called for Retry packets (and they don't have encrypted data).
|
||||||
switch p.header.Type {
|
switch p.header.Type {
|
||||||
case protocol.PacketTypeInitial:
|
case protocol.PacketTypeInitial:
|
||||||
|
@ -335,9 +332,6 @@ func (p *packetPacker) packConnectionClose(
|
||||||
// It takes into account that packets that have a tiny payload need to be padded,
|
// It takes into account that packets that have a tiny payload need to be padded,
|
||||||
// such that len(payload) + packet number len >= 4 + AEAD overhead
|
// such that len(payload) + packet number len >= 4 + AEAD overhead
|
||||||
func (p *packetPacker) longHeaderPacketLength(hdr *wire.ExtendedHeader, payload *payload) protocol.ByteCount {
|
func (p *packetPacker) longHeaderPacketLength(hdr *wire.ExtendedHeader, payload *payload) protocol.ByteCount {
|
||||||
if !hdr.IsLongHeader {
|
|
||||||
panic("wrong code path")
|
|
||||||
}
|
|
||||||
var paddingLen protocol.ByteCount
|
var paddingLen protocol.ByteCount
|
||||||
pnLen := protocol.ByteCount(hdr.PacketNumberLen)
|
pnLen := protocol.ByteCount(hdr.PacketNumberLen)
|
||||||
if payload.length < 4-pnLen {
|
if payload.length < 4-pnLen {
|
||||||
|
@ -780,7 +774,6 @@ func (p *packetPacker) getLongHeader(encLevel protocol.EncryptionLevel) *wire.Ex
|
||||||
PacketNumber: pn,
|
PacketNumber: pn,
|
||||||
PacketNumberLen: pnLen,
|
PacketNumberLen: pnLen,
|
||||||
}
|
}
|
||||||
hdr.IsLongHeader = true
|
|
||||||
hdr.Version = p.version
|
hdr.Version = p.version
|
||||||
hdr.SrcConnectionID = p.srcConnID
|
hdr.SrcConnectionID = p.srcConnID
|
||||||
hdr.DestConnectionID = p.getDestConnID()
|
hdr.DestConnectionID = p.getDestConnID()
|
||||||
|
@ -799,18 +792,13 @@ func (p *packetPacker) getLongHeader(encLevel protocol.EncryptionLevel) *wire.Ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packetPacker) appendLongHeaderPacket(buffer *packetBuffer, header *wire.ExtendedHeader, payload *payload, padding protocol.ByteCount, encLevel protocol.EncryptionLevel, sealer sealer) (*longHeaderPacket, error) {
|
func (p *packetPacker) appendLongHeaderPacket(buffer *packetBuffer, header *wire.ExtendedHeader, payload *payload, padding protocol.ByteCount, encLevel protocol.EncryptionLevel, sealer sealer) (*longHeaderPacket, error) {
|
||||||
if !header.IsLongHeader {
|
|
||||||
panic("shouldn't have called appendLongHeaderPacket")
|
|
||||||
}
|
|
||||||
var paddingLen protocol.ByteCount
|
var paddingLen protocol.ByteCount
|
||||||
pnLen := protocol.ByteCount(header.PacketNumberLen)
|
pnLen := protocol.ByteCount(header.PacketNumberLen)
|
||||||
if payload.length < 4-pnLen {
|
if payload.length < 4-pnLen {
|
||||||
paddingLen = 4 - pnLen - payload.length
|
paddingLen = 4 - pnLen - payload.length
|
||||||
}
|
}
|
||||||
paddingLen += padding
|
paddingLen += padding
|
||||||
if header.IsLongHeader {
|
header.Length = pnLen + protocol.ByteCount(sealer.Overhead()) + payload.length + paddingLen
|
||||||
header.Length = pnLen + protocol.ByteCount(sealer.Overhead()) + payload.length + paddingLen
|
|
||||||
}
|
|
||||||
|
|
||||||
raw := buffer.Data[len(buffer.Data):]
|
raw := buffer.Data[len(buffer.Data):]
|
||||||
buf := bytes.NewBuffer(buffer.Data)
|
buf := bytes.NewBuffer(buffer.Data)
|
||||||
|
|
|
@ -44,7 +44,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
if !wire.IsLongHeaderPacket(data[0]) {
|
if !wire.IsLongHeaderPacket(data[0]) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
hdr, _, more, err := wire.ParsePacket(data, connID.Len())
|
hdr, _, more, err := wire.ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
extHdr, err := hdr.ParseExtended(r, version)
|
extHdr, err := hdr.ParseExtended(r, version)
|
||||||
|
@ -136,7 +136,6 @@ var _ = Describe("Packet packer", func() {
|
||||||
It("uses the Long Header format", func() {
|
It("uses the Long Header format", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen3)
|
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen3)
|
||||||
h := packer.getLongHeader(protocol.EncryptionHandshake)
|
h := packer.getLongHeader(protocol.EncryptionHandshake)
|
||||||
Expect(h.IsLongHeader).To(BeTrue())
|
|
||||||
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
||||||
Expect(h.PacketNumberLen).To(Equal(protocol.PacketNumberLen3))
|
Expect(h.PacketNumberLen).To(Equal(protocol.PacketNumberLen3))
|
||||||
Expect(h.Version).To(Equal(packer.version))
|
Expect(h.Version).To(Equal(packer.version))
|
||||||
|
@ -657,7 +656,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(packet.longHdrPackets).To(HaveLen(1))
|
Expect(packet.longHdrPackets).To(HaveLen(1))
|
||||||
// cut off the tag that the mock sealer added
|
// cut off the tag that the mock sealer added
|
||||||
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
|
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
|
||||||
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, packer.getDestConnID().Len())
|
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
data := packet.buffer.Data
|
data := packet.buffer.Data
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
|
@ -1003,7 +1002,6 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.longHdrPackets).To(HaveLen(1))
|
Expect(p.longHdrPackets).To(HaveLen(1))
|
||||||
Expect(p.longHdrPackets[0].frames).To(HaveLen(1))
|
Expect(p.longHdrPackets[0].frames).To(HaveLen(1))
|
||||||
Expect(p.longHdrPackets[0].header.IsLongHeader).To(BeTrue())
|
|
||||||
Expect(p.buffer.Len()).To(BeEquivalentTo(packer.maxPacketSize))
|
Expect(p.buffer.Len()).To(BeEquivalentTo(packer.maxPacketSize))
|
||||||
parsePacket(p.buffer.Data)
|
parsePacket(p.buffer.Data)
|
||||||
})
|
})
|
||||||
|
@ -1206,13 +1204,11 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(p.shortHdrPacket).ToNot(BeNil())
|
Expect(p.shortHdrPacket).ToNot(BeNil())
|
||||||
Expect(p.shortHdrPacket.Frames).To(HaveLen(1))
|
Expect(p.shortHdrPacket.Frames).To(HaveLen(1))
|
||||||
Expect(p.shortHdrPacket.Frames[0].Frame.(*wire.StreamFrame).Data).To(Equal([]byte("foobar")))
|
Expect(p.shortHdrPacket.Frames[0].Frame.(*wire.StreamFrame).Data).To(Equal([]byte("foobar")))
|
||||||
hdr, _, more, err := wire.ParsePacket(p.buffer.Data, 0)
|
hdrs, more := parsePacket(p.buffer.Data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(hdrs).To(HaveLen(1))
|
||||||
Expect(hdr.Type).To(Equal(protocol.PacketTypeHandshake))
|
Expect(hdrs[0].Type).To(Equal(protocol.PacketTypeHandshake))
|
||||||
hdr, _, more, err = wire.ParsePacket(more, 0)
|
Expect(more).ToNot(BeEmpty())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
parseShortHeaderPacket(more)
|
||||||
Expect(hdr.IsLongHeader).To(BeFalse())
|
|
||||||
Expect(more).To(BeEmpty())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("doesn't add a coalesced packet if the remaining size is smaller than MaxCoalescedPacketSize", func() {
|
It("doesn't add a coalesced packet if the remaining size is smaller than MaxCoalescedPacketSize", func() {
|
||||||
|
@ -1256,7 +1252,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(packet.shortHdrPacket).To(BeNil())
|
Expect(packet.shortHdrPacket).To(BeNil())
|
||||||
// cut off the tag that the mock sealer added
|
// cut off the tag that the mock sealer added
|
||||||
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
|
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
|
||||||
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, packer.getDestConnID().Len())
|
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
data := packet.buffer.Data
|
data := packet.buffer.Data
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
|
@ -1295,7 +1291,6 @@ var _ = Describe("Packet packer", func() {
|
||||||
Expect(p.longHdrPackets).To(HaveLen(1))
|
Expect(p.longHdrPackets).To(HaveLen(1))
|
||||||
Expect(p.longHdrPackets[0].EncryptionLevel()).To(Equal(protocol.EncryptionInitial))
|
Expect(p.longHdrPackets[0].EncryptionLevel()).To(Equal(protocol.EncryptionInitial))
|
||||||
Expect(p.longHdrPackets[0].frames).To(Equal([]ackhandler.Frame{{Frame: f}}))
|
Expect(p.longHdrPackets[0].frames).To(Equal([]ackhandler.Frame{{Frame: f}}))
|
||||||
Expect(p.longHdrPackets[0].header.IsLongHeader).To(BeTrue())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("sends an Initial packet containing only an ACK", func() {
|
It("sends an Initial packet containing only an ACK", func() {
|
||||||
|
@ -1565,7 +1560,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
var _ = Describe("Converting to ackhandler.Packet", func() {
|
var _ = Describe("Converting to ackhandler.Packet", func() {
|
||||||
It("convert a packet", func() {
|
It("convert a packet", func() {
|
||||||
packet := &longHeaderPacket{
|
packet := &longHeaderPacket{
|
||||||
header: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true, Type: protocol.PacketTypeInitial}},
|
header: &wire.ExtendedHeader{Header: wire.Header{Type: protocol.PacketTypeInitial}},
|
||||||
frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}},
|
frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}},
|
||||||
ack: &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 100, Smallest: 80}}},
|
ack: &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 100, Smallest: 80}}},
|
||||||
length: 42,
|
length: 42,
|
||||||
|
@ -1580,7 +1575,7 @@ var _ = Describe("Converting to ackhandler.Packet", func() {
|
||||||
|
|
||||||
It("sets the LargestAcked to invalid, if the packet doesn't have an ACK frame", func() {
|
It("sets the LargestAcked to invalid, if the packet doesn't have an ACK frame", func() {
|
||||||
packet := &longHeaderPacket{
|
packet := &longHeaderPacket{
|
||||||
header: &wire.ExtendedHeader{Header: wire.Header{IsLongHeader: true, Type: protocol.PacketTypeHandshake}},
|
header: &wire.ExtendedHeader{Header: wire.Header{Type: protocol.PacketTypeHandshake}},
|
||||||
frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}},
|
frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}},
|
||||||
}
|
}
|
||||||
p := packet.ToAckHandlerPacket(time.Now(), nil)
|
p := packet.ToAckHandlerPacket(time.Now(), nil)
|
||||||
|
@ -1604,8 +1599,8 @@ var _ = Describe("Converting to ackhandler.Packet", func() {
|
||||||
p.Frames[1].OnLost(nil)
|
p.Frames[1].OnLost(nil)
|
||||||
Expect(pingLost).To(BeTrue())
|
Expect(pingLost).To(BeTrue())
|
||||||
},
|
},
|
||||||
Entry(protocol.EncryptionInitial.String(), wire.Header{IsLongHeader: true, Type: protocol.PacketTypeInitial}),
|
Entry(protocol.EncryptionInitial.String(), wire.Header{Type: protocol.PacketTypeInitial}),
|
||||||
Entry(protocol.EncryptionHandshake.String(), wire.Header{IsLongHeader: true, Type: protocol.PacketTypeHandshake}),
|
Entry(protocol.EncryptionHandshake.String(), wire.Header{Type: protocol.PacketTypeHandshake}),
|
||||||
Entry(protocol.Encryption0RTT.String(), wire.Header{IsLongHeader: true, Type: protocol.PacketType0RTT}),
|
Entry(protocol.Encryption0RTT.String(), wire.Header{Type: protocol.PacketType0RTT}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,14 +28,13 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
)
|
)
|
||||||
|
|
||||||
getLongHeader := func(extHdr *wire.ExtendedHeader) (*wire.Header, []byte) {
|
getLongHeader := func(extHdr *wire.ExtendedHeader) (*wire.Header, []byte) {
|
||||||
ExpectWithOffset(1, extHdr.IsLongHeader).To(BeTrue())
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
ExpectWithOffset(1, extHdr.Write(buf, version)).To(Succeed())
|
ExpectWithOffset(1, extHdr.Write(buf, version)).To(Succeed())
|
||||||
hdrLen := buf.Len()
|
hdrLen := buf.Len()
|
||||||
if extHdr.Length > protocol.ByteCount(extHdr.PacketNumberLen) {
|
if extHdr.Length > protocol.ByteCount(extHdr.PacketNumberLen) {
|
||||||
buf.Write(make([]byte, int(extHdr.Length)-int(extHdr.PacketNumberLen)))
|
buf.Write(make([]byte, int(extHdr.Length)-int(extHdr.PacketNumberLen)))
|
||||||
}
|
}
|
||||||
hdr, _, _, err := wire.ParsePacket(buf.Bytes(), connID.Len())
|
hdr, _, _, err := wire.ParsePacket(buf.Bytes())
|
||||||
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
||||||
return hdr, buf.Bytes()[:hdrLen]
|
return hdr, buf.Bytes()[:hdrLen]
|
||||||
}
|
}
|
||||||
|
@ -54,7 +53,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("errors when the packet is too small to obtain the header decryption sample, for long headers", func() {
|
It("errors when the packet is too small to obtain the header decryption sample, for long headers", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
Version: version,
|
Version: version,
|
||||||
|
@ -87,7 +85,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("opens Initial packets", func() {
|
It("opens Initial packets", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Length: 3 + 6, // packet number len + payload
|
Length: 3 + 6, // packet number len + payload
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
|
@ -113,7 +110,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("opens 0-RTT packets", func() {
|
It("opens 0-RTT packets", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketType0RTT,
|
Type: protocol.PacketType0RTT,
|
||||||
Length: 3 + 6, // packet number len + payload
|
Length: 3 + 6, // packet number len + payload
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
|
@ -164,7 +160,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("errors on empty packets, for long header packets", func() {
|
It("errors on empty packets, for long header packets", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
Version: Version1,
|
Version: Version1,
|
||||||
|
@ -207,7 +202,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("returns the error when unpacking fails", func() {
|
It("returns the error when unpacking fails", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: 3, // packet number len
|
Length: 3, // packet number len
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
|
@ -230,7 +224,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("defends against the timing side-channel when the reserved bits are wrong, for long header packets", func() {
|
It("defends against the timing side-channel when the reserved bits are wrong, for long header packets", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
Version: version,
|
Version: version,
|
||||||
|
@ -264,7 +257,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("returns the decryption error, when unpacking a packet with wrong reserved bits fails, for long headers", func() {
|
It("returns the decryption error, when unpacking a packet with wrong reserved bits fails, for long headers", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
Version: version,
|
Version: version,
|
||||||
|
@ -298,7 +290,6 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
It("decrypts the header", func() {
|
It("decrypts the header", func() {
|
||||||
extHdr := &wire.ExtendedHeader{
|
extHdr := &wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: 3, // packet number len
|
Length: 3, // packet number len
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
|
|
|
@ -32,30 +32,14 @@ var _ = Describe("Packet Header", func() {
|
||||||
checkEncoding(data, expected)
|
checkEncoding(data, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
It("marshals a header for a 1-RTT packet", func() {
|
|
||||||
check(
|
|
||||||
&wire.ExtendedHeader{
|
|
||||||
PacketNumber: 42,
|
|
||||||
KeyPhase: protocol.KeyPhaseZero,
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"packet_type": "1RTT",
|
|
||||||
"packet_number": 42,
|
|
||||||
"dcil": 0,
|
|
||||||
"key_phase_bit": "0",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
It("marshals a header with a payload length", func() {
|
It("marshals a header with a payload length", func() {
|
||||||
check(
|
check(
|
||||||
&wire.ExtendedHeader{
|
&wire.ExtendedHeader{
|
||||||
PacketNumber: 42,
|
PacketNumber: 42,
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Length: 123,
|
||||||
Length: 123,
|
Version: protocol.VersionNumber(0xdecafbad),
|
||||||
Version: protocol.VersionNumber(0xdecafbad),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
|
@ -73,11 +57,10 @@ var _ = Describe("Packet Header", func() {
|
||||||
&wire.ExtendedHeader{
|
&wire.ExtendedHeader{
|
||||||
PacketNumber: 4242,
|
PacketNumber: 4242,
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Length: 123,
|
||||||
Length: 123,
|
Version: protocol.VersionNumber(0xdecafbad),
|
||||||
Version: protocol.VersionNumber(0xdecafbad),
|
Token: []byte{0xde, 0xad, 0xbe, 0xef},
|
||||||
Token: []byte{0xde, 0xad, 0xbe, 0xef},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
|
@ -95,7 +78,6 @@ var _ = Describe("Packet Header", func() {
|
||||||
check(
|
check(
|
||||||
&wire.ExtendedHeader{
|
&wire.ExtendedHeader{
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0x11, 0x22, 0x33, 0x44}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0x11, 0x22, 0x33, 0x44}),
|
||||||
Version: protocol.VersionNumber(0xdecafbad),
|
Version: protocol.VersionNumber(0xdecafbad),
|
||||||
|
@ -118,9 +100,8 @@ var _ = Describe("Packet Header", func() {
|
||||||
&wire.ExtendedHeader{
|
&wire.ExtendedHeader{
|
||||||
PacketNumber: 0,
|
PacketNumber: 0,
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
Version: protocol.VersionNumber(0xdecafbad),
|
||||||
Version: protocol.VersionNumber(0xdecafbad),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
|
@ -138,7 +119,6 @@ var _ = Describe("Packet Header", func() {
|
||||||
&wire.ExtendedHeader{
|
&wire.ExtendedHeader{
|
||||||
PacketNumber: 42,
|
PacketNumber: 42,
|
||||||
Header: wire.Header{
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}),
|
||||||
Version: protocol.VersionNumber(0xdecafbad),
|
Version: protocol.VersionNumber(0xdecafbad),
|
||||||
|
@ -154,22 +134,5 @@ var _ = Describe("Packet Header", func() {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("marshals a 1-RTT header with a destination connection ID", func() {
|
|
||||||
check(
|
|
||||||
&wire.ExtendedHeader{
|
|
||||||
PacketNumber: 42,
|
|
||||||
Header: wire.Header{DestConnectionID: protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef})},
|
|
||||||
KeyPhase: protocol.KeyPhaseOne,
|
|
||||||
},
|
|
||||||
map[string]interface{}{
|
|
||||||
"packet_type": "1RTT",
|
|
||||||
"packet_number": 42,
|
|
||||||
"dcil": 4,
|
|
||||||
"dcid": "deadbeef",
|
|
||||||
"key_phase_bit": "1",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -29,8 +29,8 @@ func scaleDuration(t time.Duration) time.Duration {
|
||||||
func checkEncoding(data []byte, expected map[string]interface{}) {
|
func checkEncoding(data []byte, expected map[string]interface{}) {
|
||||||
// unmarshal the data
|
// unmarshal the data
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
ExpectWithOffset(1, json.Unmarshal(data, &m)).To(Succeed())
|
ExpectWithOffset(2, json.Unmarshal(data, &m)).To(Succeed())
|
||||||
ExpectWithOffset(1, m).To(HaveLen(len(expected)))
|
ExpectWithOffset(2, m).To(HaveLen(len(expected)))
|
||||||
for key, value := range expected {
|
for key, value := range expected {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case bool, string, map[string]interface{}:
|
case bool, string, map[string]interface{}:
|
||||||
|
|
|
@ -424,7 +424,6 @@ var _ = Describe("Tracing", func() {
|
||||||
tracer.SentLongHeaderPacket(
|
tracer.SentLongHeaderPacket(
|
||||||
&logging.ExtendedHeader{
|
&logging.ExtendedHeader{
|
||||||
Header: logging.Header{
|
Header: logging.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
||||||
|
@ -490,7 +489,6 @@ var _ = Describe("Tracing", func() {
|
||||||
tracer.ReceivedLongHeaderPacket(
|
tracer.ReceivedLongHeaderPacket(
|
||||||
&logging.ExtendedHeader{
|
&logging.ExtendedHeader{
|
||||||
Header: logging.Header{
|
Header: logging.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
||||||
|
@ -561,7 +559,6 @@ var _ = Describe("Tracing", func() {
|
||||||
It("records a received Retry packet", func() {
|
It("records a received Retry packet", func() {
|
||||||
tracer.ReceivedRetry(
|
tracer.ReceivedRetry(
|
||||||
&logging.Header{
|
&logging.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{4, 3, 2, 1}),
|
||||||
|
|
|
@ -348,7 +348,7 @@ func (s *baseServer) handlePacketImpl(p *receivedPacket) bool /* is the buffer s
|
||||||
}
|
}
|
||||||
// If we're creating a new connection, the packet will be passed to the connection.
|
// If we're creating a new connection, the packet will be passed to the connection.
|
||||||
// The header will then be parsed again.
|
// The header will then be parsed again.
|
||||||
hdr, _, _, err := wire.ParsePacket(p.data, s.config.ConnectionIDGenerator.ConnectionIDLen())
|
hdr, _, _, err := wire.ParsePacket(p.data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.config.Tracer != nil {
|
if s.config.Tracer != nil {
|
||||||
s.config.Tracer.DroppedPacket(p.remoteAddr, logging.PacketTypeNotDetermined, p.Size(), logging.PacketDropHeaderParseError)
|
s.config.Tracer.DroppedPacket(p.remoteAddr, logging.PacketTypeNotDetermined, p.Size(), logging.PacketDropHeaderParseError)
|
||||||
|
@ -364,7 +364,7 @@ func (s *baseServer) handlePacketImpl(p *receivedPacket) bool /* is the buffer s
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if hdr.IsLongHeader && hdr.Type != protocol.PacketTypeInitial {
|
if hdr.Type != protocol.PacketTypeInitial {
|
||||||
// Drop long header packets.
|
// Drop long header packets.
|
||||||
// There's little point in sending a Stateless Reset, since the client
|
// There's little point in sending a Stateless Reset, since the client
|
||||||
// might not have received the token yet.
|
// might not have received the token yet.
|
||||||
|
@ -566,7 +566,6 @@ func (s *baseServer) sendRetry(remoteAddr net.Addr, hdr *wire.Header, info *pack
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
replyHdr := &wire.ExtendedHeader{}
|
replyHdr := &wire.ExtendedHeader{}
|
||||||
replyHdr.IsLongHeader = true
|
|
||||||
replyHdr.Type = protocol.PacketTypeRetry
|
replyHdr.Type = protocol.PacketTypeRetry
|
||||||
replyHdr.Version = hdr.Version
|
replyHdr.Version = hdr.Version
|
||||||
replyHdr.SrcConnectionID = srcConnID
|
replyHdr.SrcConnectionID = srcConnID
|
||||||
|
@ -635,7 +634,6 @@ func (s *baseServer) sendError(remoteAddr net.Addr, hdr *wire.Header, sealer han
|
||||||
ccf := &wire.ConnectionCloseFrame{ErrorCode: uint64(errorCode)}
|
ccf := &wire.ConnectionCloseFrame{ErrorCode: uint64(errorCode)}
|
||||||
|
|
||||||
replyHdr := &wire.ExtendedHeader{}
|
replyHdr := &wire.ExtendedHeader{}
|
||||||
replyHdr.IsLongHeader = true
|
|
||||||
replyHdr.Type = protocol.PacketTypeInitial
|
replyHdr.Type = protocol.PacketTypeInitial
|
||||||
replyHdr.Version = hdr.Version
|
replyHdr.Version = hdr.Version
|
||||||
replyHdr.SrcConnectionID = hdr.DestConnectionID
|
replyHdr.SrcConnectionID = hdr.DestConnectionID
|
||||||
|
|
|
@ -44,9 +44,7 @@ var _ = Describe("Server", func() {
|
||||||
getPacket := func(hdr *wire.Header, p []byte) *receivedPacket {
|
getPacket := func(hdr *wire.Header, p []byte) *receivedPacket {
|
||||||
buffer := getPacketBuffer()
|
buffer := getPacketBuffer()
|
||||||
buf := bytes.NewBuffer(buffer.Data)
|
buf := bytes.NewBuffer(buffer.Data)
|
||||||
if hdr.IsLongHeader {
|
hdr.Length = 4 + protocol.ByteCount(len(p)) + 16
|
||||||
hdr.Length = 4 + protocol.ByteCount(len(p)) + 16
|
|
||||||
}
|
|
||||||
Expect((&wire.ExtendedHeader{
|
Expect((&wire.ExtendedHeader{
|
||||||
Header: *hdr,
|
Header: *hdr,
|
||||||
PacketNumber: 0x42,
|
PacketNumber: 0x42,
|
||||||
|
@ -69,7 +67,6 @@ var _ = Describe("Server", func() {
|
||||||
getInitial := func(destConnID protocol.ConnectionID) *receivedPacket {
|
getInitial := func(destConnID protocol.ConnectionID) *receivedPacket {
|
||||||
senderAddr := &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 42}
|
senderAddr := &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 42}
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
@ -90,7 +87,7 @@ var _ = Describe("Server", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseHeader := func(data []byte) *wire.Header {
|
parseHeader := func(data []byte) *wire.Header {
|
||||||
hdr, _, _, err := wire.ParsePacket(data, 0)
|
hdr, _, _, err := wire.ParsePacket(data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
return hdr
|
return hdr
|
||||||
}
|
}
|
||||||
|
@ -202,7 +199,6 @@ var _ = Describe("Server", func() {
|
||||||
Context("handling packets", func() {
|
Context("handling packets", func() {
|
||||||
It("drops Initial packets with a too short connection ID", func() {
|
It("drops Initial packets with a too short connection ID", func() {
|
||||||
p := getPacket(&wire.Header{
|
p := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||||
Version: serv.config.Versions[0],
|
Version: serv.config.Versions[0],
|
||||||
|
@ -215,7 +211,6 @@ var _ = Describe("Server", func() {
|
||||||
|
|
||||||
It("drops too small Initial", func() {
|
It("drops too small Initial", func() {
|
||||||
p := getPacket(&wire.Header{
|
p := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||||
Version: serv.config.Versions[0],
|
Version: serv.config.Versions[0],
|
||||||
|
@ -229,9 +224,8 @@ var _ = Describe("Server", func() {
|
||||||
|
|
||||||
It("drops non-Initial packets", func() {
|
It("drops non-Initial packets", func() {
|
||||||
p := getPacket(&wire.Header{
|
p := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Type: protocol.PacketTypeHandshake,
|
Version: serv.config.Versions[0],
|
||||||
Version: serv.config.Versions[0],
|
|
||||||
}, []byte("invalid"))
|
}, []byte("invalid"))
|
||||||
tracer.EXPECT().DroppedPacket(p.remoteAddr, logging.PacketTypeHandshake, p.Size(), logging.PacketDropUnexpectedPacket)
|
tracer.EXPECT().DroppedPacket(p.remoteAddr, logging.PacketTypeHandshake, p.Size(), logging.PacketDropUnexpectedPacket)
|
||||||
serv.handlePacket(p)
|
serv.handlePacket(p)
|
||||||
|
@ -249,7 +243,6 @@ var _ = Describe("Server", func() {
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -326,7 +319,6 @@ var _ = Describe("Server", func() {
|
||||||
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
||||||
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
||||||
packet := getPacket(&wire.Header{
|
packet := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
@ -358,7 +350,6 @@ var _ = Describe("Server", func() {
|
||||||
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
||||||
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
||||||
packet := getPacket(&wire.Header{
|
packet := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
@ -397,7 +388,6 @@ var _ = Describe("Server", func() {
|
||||||
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
srcConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5})
|
||||||
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
destConnID := protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6})
|
||||||
p := getPacket(&wire.Header{
|
p := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
|
@ -419,7 +409,6 @@ var _ = Describe("Server", func() {
|
||||||
It("replies with a Retry packet, if a token is required", func() {
|
It("replies with a Retry packet, if a token is required", func() {
|
||||||
serv.config.RequireAddressValidation = func(net.Addr) bool { return true }
|
serv.config.RequireAddressValidation = func(net.Addr) bool { return true }
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -451,7 +440,6 @@ var _ = Describe("Server", func() {
|
||||||
|
|
||||||
It("creates a connection, if no token is required", func() {
|
It("creates a connection, if no token is required", func() {
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -663,7 +651,7 @@ var _ = Describe("Server", func() {
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
p := getInitialWithRandomDestConnID()
|
p := getInitialWithRandomDestConnID()
|
||||||
hdr, _, _, err := wire.ParsePacket(p.data, 0)
|
hdr, _, _, err := wire.ParsePacket(p.data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
tracer.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -767,10 +755,9 @@ var _ = Describe("Server", func() {
|
||||||
token, err := serv.tokenGenerator.NewRetryToken(raddr, protocol.ConnectionID{}, protocol.ConnectionID{})
|
token, err := serv.tokenGenerator.NewRetryToken(raddr, protocol.ConnectionID{}, protocol.ConnectionID{})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
packet := getPacket(&wire.Header{
|
packet := getPacket(&wire.Header{
|
||||||
IsLongHeader: true,
|
Type: protocol.PacketTypeInitial,
|
||||||
Type: protocol.PacketTypeInitial,
|
Token: token,
|
||||||
Token: token,
|
Version: serv.config.Versions[0],
|
||||||
Version: serv.config.Versions[0],
|
|
||||||
}, make([]byte, protocol.MinInitialPacketSize))
|
}, make([]byte, protocol.MinInitialPacketSize))
|
||||||
packet.remoteAddr = raddr
|
packet.remoteAddr = raddr
|
||||||
conn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).MaxTimes(1)
|
conn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).MaxTimes(1)
|
||||||
|
@ -787,7 +774,6 @@ var _ = Describe("Server", func() {
|
||||||
token, err := serv.tokenGenerator.NewRetryToken(&net.UDPAddr{}, protocol.ConnectionID{}, protocol.ConnectionID{})
|
token, err := serv.tokenGenerator.NewRetryToken(&net.UDPAddr{}, protocol.ConnectionID{}, protocol.ConnectionID{})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -826,7 +812,6 @@ var _ = Describe("Server", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
time.Sleep(2 * time.Millisecond) // make sure the token is expired
|
time.Sleep(2 * time.Millisecond) // make sure the token is expired
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -860,7 +845,6 @@ var _ = Describe("Server", func() {
|
||||||
token, err := serv.tokenGenerator.NewToken(&net.UDPAddr{IP: net.IPv4(192, 168, 0, 1), Port: 1337})
|
token, err := serv.tokenGenerator.NewToken(&net.UDPAddr{IP: net.IPv4(192, 168, 0, 1), Port: 1337})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -892,7 +876,6 @@ var _ = Describe("Server", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
time.Sleep(2 * time.Millisecond) // make sure the token is expired
|
time.Sleep(2 * time.Millisecond) // make sure the token is expired
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
@ -918,7 +901,6 @@ var _ = Describe("Server", func() {
|
||||||
token, err := serv.tokenGenerator.NewRetryToken(&net.UDPAddr{}, protocol.ConnectionID{}, protocol.ConnectionID{})
|
token, err := serv.tokenGenerator.NewRetryToken(&net.UDPAddr{}, protocol.ConnectionID{}, protocol.ConnectionID{})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
hdr := &wire.Header{
|
hdr := &wire.Header{
|
||||||
IsLongHeader: true,
|
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
SrcConnectionID: protocol.ParseConnectionID([]byte{5, 4, 3, 2, 1}),
|
||||||
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue