mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
append to a given buffer when packing a packet
This commit is contained in:
parent
b0524c1241
commit
628ba87727
5 changed files with 118 additions and 107 deletions
|
@ -493,11 +493,11 @@ var _ = Describe("Packet packer", func() {
|
|||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
framer.EXPECT().HasData()
|
||||
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).To(MatchError(errNothingToPack))
|
||||
})
|
||||
|
||||
It("packs single packets", func() {
|
||||
It("appends single packets", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||
|
@ -509,7 +509,9 @@ var _ = Describe("Packet packer", func() {
|
|||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
}
|
||||
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
|
||||
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
buffer := getPacketBuffer()
|
||||
buffer.Data = append(buffer.Data, []byte("foobar")...)
|
||||
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p).ToNot(BeNil())
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
|
@ -517,6 +519,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(buffer.Data[:6]).To(Equal([]byte("foobar"))) // make sure the packet was actually appended
|
||||
Expect(buffer.Data).To(ContainSubstring(string(b)))
|
||||
})
|
||||
|
||||
|
@ -527,7 +530,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(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(p.Ack).To(Equal(ack))
|
||||
|
@ -545,7 +548,8 @@ var _ = Describe("Packet packer", func() {
|
|||
}
|
||||
expectAppendControlFrames(frames...)
|
||||
expectAppendStreamFrames()
|
||||
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
buffer := getPacketBuffer()
|
||||
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Frames).To(HaveLen(2))
|
||||
|
@ -574,7 +578,8 @@ var _ = Describe("Packet packer", func() {
|
|||
time.Sleep(scaleDuration(20 * time.Millisecond))
|
||||
|
||||
framer.EXPECT().HasData()
|
||||
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
buffer := getPacketBuffer()
|
||||
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Frames).To(HaveLen(1))
|
||||
|
@ -602,7 +607,8 @@ var _ = Describe("Packet packer", func() {
|
|||
time.Sleep(scaleDuration(20 * time.Millisecond))
|
||||
|
||||
framer.EXPECT().HasData()
|
||||
p, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
buffer := getPacketBuffer()
|
||||
p, err := packer.AppendPacket(buffer, maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Ack).ToNot(BeNil())
|
||||
|
@ -628,7 +634,7 @@ var _ = Describe("Packet packer", func() {
|
|||
return fs, 0
|
||||
}),
|
||||
)
|
||||
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).To(MatchError(errNothingToPack))
|
||||
})
|
||||
|
||||
|
@ -685,7 +691,8 @@ var _ = Describe("Packet packer", func() {
|
|||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
expectAppendControlFrames()
|
||||
expectAppendStreamFrames(ackhandler.StreamFrame{Frame: f})
|
||||
_, buffer, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
buffer := getPacketBuffer()
|
||||
_, err := packer.AppendPacket(buffer, 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 +741,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(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Frames).To(BeEmpty())
|
||||
|
@ -754,7 +761,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(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Ack).ToNot(BeNil())
|
||||
|
@ -771,7 +778,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(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var hasPing bool
|
||||
|
@ -790,7 +797,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(maxPacketSize, protocol.Version1)
|
||||
p, err = packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Ack).ToNot(BeNil())
|
||||
|
@ -806,7 +813,7 @@ var _ = Describe("Packet packer", func() {
|
|||
expectAppendControlFrames()
|
||||
expectAppendStreamFrames()
|
||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
_, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
_, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).To(MatchError(errNothingToPack))
|
||||
// now add some frame to send
|
||||
expectAppendControlFrames()
|
||||
|
@ -817,7 +824,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(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.Ack).To(Equal(ack))
|
||||
var hasPing bool
|
||||
|
@ -839,7 +846,7 @@ var _ = Describe("Packet packer", func() {
|
|||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
expectAppendStreamFrames()
|
||||
expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}})
|
||||
p, _, err := packer.PackPacket(maxPacketSize, protocol.Version1)
|
||||
p, err := packer.AppendPacket(getPacketBuffer(), maxPacketSize, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p).ToNot(BeNil())
|
||||
Expect(p.Frames).ToNot(ContainElement(&wire.PingFrame{}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue