pack QUIC 34 packets with the correct maximum size

fixes #187
This commit is contained in:
Marten Seemann
2016-06-23 18:23:34 +07:00
parent 5e890a8f61
commit ab1db83134
3 changed files with 21 additions and 1 deletions

View File

@@ -181,6 +181,11 @@ func (p *packetPacker) composeNextPacket(stopWaitingFrame *frames.StopWaitingFra
maxFrameSize := protocol.MaxFrameAndPublicHeaderSize - publicHeaderLength
// until QUIC 33, packets have a 1 byte private header
if p.version < protocol.Version34 {
maxFrameSize--
}
if stopWaitingFrame != nil {
payloadFrames = append(payloadFrames, stopWaitingFrame)
minLength, err := stopWaitingFrame.MinLength(p.version)

View File

@@ -56,6 +56,7 @@ var _ = Describe("Packet packer", func() {
streamFrameQueue: newStreamFrameQueue(),
}
publicHeaderLen = 1 + 8 + 1 // 1 flag byte, 8 connection ID, 1 packet number
packer.version = protocol.Version34
})
AfterEach(func() {
@@ -267,6 +268,7 @@ var _ = Describe("Packet packer", func() {
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
p, err = packer.PackPacket(nil, []frames.Frame{})
Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(HaveLen(1))
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeFalse())
})
@@ -302,6 +304,19 @@ var _ = Describe("Packet packer", func() {
Expect(p.raw).To(ContainSubstring(string(f3.Data)))
})
It("packs a packet with a stream frame larger than maximum size, in QUIC < 34", func() {
packer.version = protocol.Version33
f := frames.StreamFrame{
StreamID: 5,
Offset: 1,
Data: bytes.Repeat([]byte{'f'}, int(protocol.MaxPacketSize)+100),
}
packer.AddStreamFrame(f)
p, err := packer.PackPacket(nil, []frames.Frame{})
Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(protocol.MaxPacketSize)))
})
It("splits one stream frame larger than maximum size", func() {
f := frames.StreamFrame{
StreamID: 7,

View File

@@ -41,7 +41,7 @@ const MaxByteCount = math.MaxUint64
const MaxPacketSize ByteCount = 1350
// MaxFrameAndPublicHeaderSize is the maximum size of a QUIC frame plus PublicHeader
const MaxFrameAndPublicHeaderSize = MaxPacketSize - 1 /*private header*/ - 12 /*crypto signature*/
const MaxFrameAndPublicHeaderSize = MaxPacketSize - 12 /*crypto signature*/
// DefaultTCPMSS is the default maximum packet size used in the Linux TCP implementation.
// Used in QUIC for congestion window computations in bytes.