split code paths for packing normal and ACK-only packets

This commit is contained in:
Marten Seemann 2023-04-30 13:30:05 +02:00
parent db4e929ccf
commit b0524c1241
5 changed files with 81 additions and 54 deletions

View file

@ -272,7 +272,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack)
p, buffer, err := packer.PackPacket(true, time.Now(), maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackAckOnlyPacket(maxPacketSize, protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Ack).To(Equal(ack))
@ -493,7 +493,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
framer.EXPECT().HasData()
_, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
})
@ -509,7 +509,7 @@ var _ = Describe("Packet packer", func() {
Data: []byte{0xde, 0xca, 0xfb, 0xad},
}
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
p, buffer, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
b, err := f.Append(nil, protocol.Version1)
@ -527,7 +527,7 @@ var _ = Describe("Packet packer", func() {
framer.EXPECT().HasData()
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack)
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Ack).To(Equal(ack))
@ -545,7 +545,7 @@ var _ = Describe("Packet packer", func() {
}
expectAppendControlFrames(frames...)
expectAppendStreamFrames()
p, buffer, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(HaveLen(2))
@ -574,7 +574,7 @@ var _ = Describe("Packet packer", func() {
time.Sleep(scaleDuration(20 * time.Millisecond))
framer.EXPECT().HasData()
p, buffer, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(HaveLen(1))
@ -602,7 +602,7 @@ var _ = Describe("Packet packer", func() {
time.Sleep(scaleDuration(20 * time.Millisecond))
framer.EXPECT().HasData()
p, buffer, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -628,7 +628,7 @@ var _ = Describe("Packet packer", func() {
return fs, 0
}),
)
_, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
})
@ -685,7 +685,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
_, buffer, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
_, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
// cut off the tag that the mock sealer added
buffer.Data = buffer.Data[:buffer.Len()-protocol.ByteCount(sealer.Overhead())]
@ -734,7 +734,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f1}, ackhandler.StreamFrame{Frame: f2}, ackhandler.StreamFrame{Frame: f3})
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(BeEmpty())
@ -754,7 +754,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
expectAppendControlFrames()
expectAppendStreamFrames()
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -771,7 +771,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
expectAppendControlFrames()
expectAppendStreamFrames()
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
var hasPing bool
@ -790,7 +790,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
expectAppendControlFrames()
expectAppendStreamFrames()
p, _, err = packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err = packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -806,7 +806,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames()
expectAppendStreamFrames()
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
_, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
// now add some frame to send
expectAppendControlFrames()
@ -817,7 +817,7 @@ var _ = Describe("Packet packer", func() {
framer.EXPECT().HasData().Return(true)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(ack)
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).To(Equal(ack))
var hasPing bool
@ -839,7 +839,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
expectAppendStreamFrames()
expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}})
p, _, err := packer.PackPacket(false, time.Now(), maxPacketSize, protocol.Version1)
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Frames).ToNot(ContainElement(&wire.PingFrame{}))