add a method to update the packer's max packet size

This commit is contained in:
Marten Seemann 2021-01-31 14:25:18 +08:00
parent c6ae91a8cf
commit 142071253d
2 changed files with 36 additions and 2 deletions

View file

@ -862,6 +862,13 @@ func (p *packetPacker) SetToken(token []byte) {
p.token = token
}
// When a higher MTU is discovered, use it.
func (p *packetPacker) SetMaxPacketSize(s protocol.ByteCount) {
p.maxPacketSize = s
}
// If the peer sets a max_packet_size that's smaller than the size we're currently using,
// we need to reduce the size of packets we send.
func (p *packetPacker) HandleTransportParameters(params *wire.TransportParameters) {
if params.MaxUDPPayloadSize != 0 {
p.maxPacketSize = utils.MinByteCount(p.maxPacketSize, params.MaxUDPPayloadSize)

View file

@ -802,8 +802,8 @@ var _ = Describe("Packet packer", func() {
})
})
Context("max packet size", func() {
It("sets the maximum packet size", func() {
Context("handling transport parameters", func() {
It("lowers the maximum packet size", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).Times(2)
framer.EXPECT().HasData().Return(true).Times(2)
@ -855,6 +855,33 @@ var _ = Describe("Packet packer", func() {
Expect(err).ToNot(HaveOccurred())
})
})
Context("max packet size", func() {
It("increases the max packet size", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).Times(2)
framer.EXPECT().HasData().Return(true).Times(2)
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Times(2)
var initialMaxPacketSize protocol.ByteCount
framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount) {
initialMaxPacketSize = maxLen
return nil, 0
})
expectAppendStreamFrames()
_, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
// now reduce the maxPacketSize
const packetSizeIncrease = 50
packer.SetMaxPacketSize(maxPacketSize + packetSizeIncrease)
framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount) {
Expect(maxLen).To(Equal(initialMaxPacketSize + packetSizeIncrease))
return nil, 0
})
expectAppendStreamFrames()
_, err = packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
})
})
})
Context("packing crypto packets", func() {