use the peer's max_packet_size when packing packets

This commit is contained in:
Marten Seemann 2018-03-10 14:27:07 +07:00
parent 0f401b0b37
commit 9d18d30931
4 changed files with 44 additions and 1 deletions

View file

@ -895,7 +895,6 @@ var _ = Describe("Packet packer", func() {
Expect(sf2.StreamID).To(Equal(protocol.StreamID(5)))
Expect(sf2.DataLenPresent).To(BeFalse())
})
})
Context("packing ACK packets", func() {
@ -917,4 +916,38 @@ var _ = Describe("Packet packer", func() {
}))
})
})
Context("max packet size", func() {
It("sets the maximum packet size", func() {
for i := 0; i < 10*int(maxPacketSize); i++ {
packer.QueueControlFrame(&wire.PingFrame{})
}
mockStreamFramer.EXPECT().HasCryptoStreamData().AnyTimes()
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any()).AnyTimes()
p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
// now reduce the maxPacketSize
packer.SetMaxPacketSize(maxPacketSize - 10)
p, err = packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(maxPacketSize) - 10))
})
It("doesn't increase the max packet size", func() {
for i := 0; i < 10*int(maxPacketSize); i++ {
packer.QueueControlFrame(&wire.PingFrame{})
}
mockStreamFramer.EXPECT().HasCryptoStreamData().AnyTimes()
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any()).AnyTimes()
p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
// now try to increase the maxPacketSize
packer.SetMaxPacketSize(maxPacketSize + 10)
p, err = packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p.raw).To(HaveLen(int(maxPacketSize)))
})
})
})