packer: reduce number of calls to time.Now() when packing packets (#3815)

This commit is contained in:
Marten Seemann 2023-06-03 09:58:41 +03:00 committed by GitHub
parent 56432a8b79
commit 591ab1ab5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 177 additions and 170 deletions

View file

@ -168,7 +168,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames()
f := &wire.StreamFrame{Data: []byte{0xde, 0xca, 0xfb, 0xad}}
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(BeEmpty())
@ -207,7 +207,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true)
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).To(BeNil())
})
@ -219,7 +219,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).Return(ack)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(HaveLen(1))
@ -236,7 +236,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).Return(ack)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(HaveLen(1))
@ -256,7 +256,7 @@ var _ = Describe("Packet packer", func() {
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true)
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(true, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(BeEmpty())
@ -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.PackAckOnlyPacket(maxPacketSize, protocol.Version1)
p, buffer, err := packer.PackAckOnlyPacket(maxPacketSize, time.Now(), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Ack).To(Equal(ack))
@ -308,7 +308,7 @@ var _ = Describe("Packet packer", func() {
framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(frames []ackhandler.StreamFrame, _ protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.StreamFrame, protocol.ByteCount) {
return frames, 0
})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
@ -318,7 +318,7 @@ var _ = Describe("Packet packer", func() {
})
It("doesn't add an ACK-only 0-RTT packet", func() { // ACK frames cannot be sent in 0-RTT packets
p, err := packer.PackCoalescedPacket(true, protocol.MaxByteCount, protocol.Version1)
p, err := packer.PackCoalescedPacket(true, protocol.MaxByteCount, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).To(BeNil())
})
@ -333,7 +333,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
quicErr := qerr.NewLocalCryptoError(0x42, "crypto error")
quicErr.FrameType = 0x1234
p, err := packer.PackConnectionClose(quicErr, maxPacketSize, protocol.Version1)
p, err := packer.PackConnectionClose(quicErr, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].header.Type).To(Equal(protocol.PacketTypeHandshake))
@ -353,15 +353,17 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysDropped)
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
// expect no framer.PopStreamFrames
now := time.Now()
p, err := packer.PackConnectionClose(&qerr.TransportError{
ErrorCode: qerr.CryptoBufferExceeded,
ErrorMessage: "test error",
}, maxPacketSize, protocol.Version1)
}, maxPacketSize, now, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(BeEmpty())
Expect(p.shortHdrPacket.Frames).To(HaveLen(1))
Expect(p.shortHdrPacket.Frames[0].Frame).To(BeAssignableToTypeOf(&wire.ConnectionCloseFrame{}))
ccf := p.shortHdrPacket.Frames[0].Frame.(*wire.ConnectionCloseFrame)
Expect(p.shortHdrPacket.Packet.SendTime).To(Equal(now))
Expect(ccf.IsApplicationError).To(BeFalse())
Expect(ccf.ErrorCode).To(BeEquivalentTo(qerr.CryptoBufferExceeded))
Expect(ccf.ReasonPhrase).To(Equal("test error"))
@ -380,7 +382,7 @@ var _ = Describe("Packet packer", func() {
p, err := packer.PackApplicationClose(&qerr.ApplicationError{
ErrorCode: 0x1337,
ErrorMessage: "test error",
}, maxPacketSize, protocol.Version1)
}, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(2))
Expect(p.longHdrPackets[0].header.Type).To(Equal(protocol.PacketTypeInitial))
@ -422,7 +424,7 @@ var _ = Describe("Packet packer", func() {
p, err := packer.PackApplicationClose(&qerr.ApplicationError{
ErrorCode: 0x1337,
ErrorMessage: "test error",
}, maxPacketSize, protocol.Version1)
}, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.buffer.Len()).To(BeNumerically("<", protocol.MinInitialPacketSize))
@ -457,7 +459,7 @@ var _ = Describe("Packet packer", func() {
p, err := packer.PackApplicationClose(&qerr.ApplicationError{
ErrorCode: 0x1337,
ErrorMessage: "test error",
}, maxPacketSize, protocol.Version1)
}, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(2))
Expect(p.buffer.Len()).To(BeNumerically(">=", protocol.MinInitialPacketSize))
@ -493,7 +495,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
framer.EXPECT().HasData()
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
})
@ -511,7 +513,8 @@ var _ = Describe("Packet packer", func() {
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
buffer := getPacketBuffer()
buffer.Data = append(buffer.Data, []byte("foobar")...)
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
now := time.Now()
p, err := packer.AppendPacket(buffer, maxPacketSize, now, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
b, err := f.Append(nil, protocol.Version1)
@ -519,6 +522,7 @@ var _ = Describe("Packet packer", func() {
Expect(p.Frames).To(BeEmpty())
Expect(p.StreamFrames).To(HaveLen(1))
Expect(p.StreamFrames[0].Frame.StreamID).To(Equal(f.StreamID))
Expect(p.Packet.SendTime).To(Equal(now))
Expect(buffer.Data[:6]).To(Equal([]byte("foobar"))) // make sure the packet was actually appended
Expect(buffer.Data).To(ContainSubstring(string(b)))
})
@ -530,7 +534,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Ack).To(Equal(ack))
@ -549,7 +553,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames(frames...)
expectAppendStreamFrames()
buffer := getPacketBuffer()
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(buffer, maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(HaveLen(2))
@ -579,7 +583,7 @@ var _ = Describe("Packet packer", func() {
framer.EXPECT().HasData()
buffer := getPacketBuffer()
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(buffer, maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(HaveLen(1))
@ -608,7 +612,7 @@ var _ = Describe("Packet packer", func() {
framer.EXPECT().HasData()
buffer := getPacketBuffer()
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(buffer, maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -634,7 +638,7 @@ var _ = Describe("Packet packer", func() {
return fs, 0
}),
)
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
})
@ -648,7 +652,7 @@ var _ = Describe("Packet packer", func() {
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
handshakeStream.EXPECT().HasData()
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
packet, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
packet, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(packet).ToNot(BeNil())
Expect(packet.longHdrPackets).To(HaveLen(1))
@ -692,7 +696,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
buffer := getPacketBuffer()
_, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
_, err := packer.AppendPacket(buffer, maxPacketSize, time.Now(), 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())]
@ -741,7 +745,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Frames).To(BeEmpty())
@ -761,7 +765,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -778,7 +782,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
var hasPing bool
@ -797,7 +801,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err = packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).ToNot(BeNil())
@ -813,7 +817,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames()
expectAppendStreamFrames()
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).To(MatchError(errNothingToPack))
// now add some frame to send
expectAppendControlFrames()
@ -824,7 +828,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.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.Ack).To(Equal(ack))
var hasPing bool
@ -846,7 +850,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
expectAppendStreamFrames()
expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}})
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.Frames).ToNot(ContainElement(&wire.PingFrame{}))
@ -868,7 +872,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().GetInitialSealer().Return(nil, handshake.ErrKeysDropped)
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
parsePacket(p.buffer.Data)
@ -887,7 +891,7 @@ var _ = Describe("Packet packer", func() {
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
return &wire.CryptoFrame{Offset: 0x42, Data: []byte("initial")}
})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeNumerically(">=", protocol.MinInitialPacketSize))
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
@ -917,7 +921,7 @@ var _ = Describe("Packet packer", func() {
Expect(f.Length(protocol.Version1)).To(Equal(size))
return f
})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].frames).To(HaveLen(1))
@ -943,7 +947,7 @@ var _ = Describe("Packet packer", func() {
handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
return &wire.CryptoFrame{Offset: 0x1337, Data: []byte("handshake")}
})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
Expect(p.longHdrPackets).To(HaveLen(2))
@ -977,7 +981,7 @@ var _ = Describe("Packet packer", func() {
})
handshakeStream.EXPECT().HasData()
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
Expect(p.longHdrPackets).To(HaveLen(2))
@ -1008,7 +1012,7 @@ var _ = Describe("Packet packer", func() {
handshakeStream.EXPECT().HasData()
packer.retransmissionQueue.AddInitial(&wire.PingFrame{})
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
Expect(p.longHdrPackets).To(HaveLen(2))
@ -1042,7 +1046,7 @@ var _ = Describe("Packet packer", func() {
expectAppendStreamFrames()
framer.EXPECT().HasData().Return(true)
packer.retransmissionQueue.AddAppData(&wire.PingFrame{})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
Expect(p.longHdrPackets).To(HaveLen(1))
@ -1078,7 +1082,7 @@ var _ = Describe("Packet packer", func() {
})
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: &wire.StreamFrame{Data: []byte("foobar")}})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeNumerically(">=", protocol.MinInitialPacketSize))
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
@ -1115,7 +1119,7 @@ var _ = Describe("Packet packer", func() {
})
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: &wire.StreamFrame{Data: []byte("foobar")}})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeNumerically("<", 100))
Expect(p.longHdrPackets).To(HaveLen(1))
@ -1148,7 +1152,7 @@ var _ = Describe("Packet packer", func() {
Expect(f.Length(protocol.Version1)).To(Equal(s))
return f
})
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.shortHdrPacket).To(BeNil())
@ -1167,7 +1171,7 @@ var _ = Describe("Packet packer", func() {
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
handshakeStream.EXPECT().HasData()
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
packet, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
packet, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(packet).ToNot(BeNil())
Expect(packet.longHdrPackets).To(HaveLen(1))
@ -1208,7 +1212,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
initialStream.EXPECT().HasData()
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].EncryptionLevel()).To(Equal(protocol.EncryptionInitial))
@ -1224,7 +1228,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].ack).To(Equal(ack))
@ -1236,7 +1240,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
initialStream.EXPECT().HasData()
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).To(BeNil())
})
@ -1252,7 +1256,7 @@ var _ = Describe("Packet packer", func() {
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].ack).To(Equal(ack))
@ -1275,7 +1279,7 @@ var _ = Describe("Packet packer", func() {
initialStream.EXPECT().HasData().Return(true).Times(2)
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
packer.perspective = protocol.PerspectiveClient
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.buffer.Len()).To(BeNumerically(">=", protocol.MinInitialPacketSize))
Expect(p.buffer.Len()).To(BeEquivalentTo(maxPacketSize))
@ -1300,7 +1304,7 @@ var _ = Describe("Packet packer", func() {
initialStream.EXPECT().HasData().Return(true).Times(2)
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
packer.perspective = protocol.PerspectiveClient
p, err := packer.PackCoalescedPacket(false, maxPacketSize, protocol.Version1)
p, err := packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p.longHdrPackets).To(HaveLen(1))
Expect(p.longHdrPackets[0].ack).To(Equal(ack))
@ -1323,7 +1327,7 @@ var _ = Describe("Packet packer", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
p, err := packer.MaybePackProbePacket(protocol.EncryptionInitial, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.EncryptionInitial, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(HaveLen(1))
@ -1345,7 +1349,7 @@ var _ = Describe("Packet packer", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen1)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
p, err := packer.MaybePackProbePacket(protocol.EncryptionInitial, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.EncryptionInitial, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
@ -1369,7 +1373,7 @@ var _ = Describe("Packet packer", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
p, err := packer.MaybePackProbePacket(protocol.EncryptionHandshake, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.EncryptionHandshake, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
@ -1390,7 +1394,7 @@ var _ = Describe("Packet packer", func() {
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
p, err := packer.MaybePackProbePacket(protocol.EncryptionHandshake, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.EncryptionHandshake, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
@ -1414,7 +1418,7 @@ var _ = Describe("Packet packer", func() {
expectAppendControlFrames()
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
p, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(BeEmpty())
@ -1440,7 +1444,7 @@ var _ = Describe("Packet packer", func() {
return append(fs, ackhandler.StreamFrame{Frame: sf}), sf.Length(v)
})
p, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, protocol.Version1)
p, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
Expect(p.longHdrPackets).To(BeEmpty())
@ -1457,7 +1461,7 @@ var _ = Describe("Packet packer", func() {
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
framer.EXPECT().HasData()
packet, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, protocol.Version1)
packet, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, time.Now(), protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(packet).To(BeNil())
})