diff --git a/connection.go b/connection.go index b45de4dc..67a5df54 100644 --- a/connection.go +++ b/connection.go @@ -1988,7 +1988,7 @@ func (s *connection) logLongHeaderPacket(p *longHeaderPacket) { func (s *connection) logShortHeaderPacket( destConnID protocol.ConnectionID, ackFrame *wire.AckFrame, - frames []*ackhandler.Frame, + frames []ackhandler.Frame, streamFrames []ackhandler.StreamFrame, pn protocol.PacketNumber, pnLen protocol.PacketNumberLen, diff --git a/connection_test.go b/connection_test.go index 10f0c202..3dc1f923 100644 --- a/connection_test.go +++ b/connection_test.go @@ -310,7 +310,7 @@ var _ = Describe("Connection", func() { err := conn.handleFrame(&wire.PathChallengeFrame{Data: data}, protocol.Encryption1RTT, protocol.ConnectionID{}) Expect(err).ToNot(HaveOccurred()) frames, _ := conn.framer.AppendControlFrames(nil, 1000, protocol.Version1) - Expect(frames).To(Equal([]*ackhandler.Frame{{Frame: &wire.PathResponseFrame{Data: data}}})) + Expect(frames).To(Equal([]ackhandler.Frame{{Frame: &wire.PathResponseFrame{Data: data}}})) }) It("rejects NEW_TOKEN frames", func() { @@ -1271,7 +1271,7 @@ var _ = Describe("Connection", func() { conn.scheduleSending() Eventually(sent).Should(BeClosed()) frames, _ := conn.framer.AppendControlFrames(nil, 1000, protocol.Version1) - Expect(frames).To(Equal([]*ackhandler.Frame{{Frame: &logging.DataBlockedFrame{MaximumData: 1337}}})) + Expect(frames).To(Equal([]ackhandler.Frame{{Frame: &logging.DataBlockedFrame{MaximumData: 1337}}})) }) It("doesn't send when the SentPacketHandler doesn't allow it", func() { @@ -1868,8 +1868,8 @@ var _ = Describe("Connection", func() { handshakeCtx := conn.HandshakeComplete() Consistently(handshakeCtx).ShouldNot(BeClosed()) close(finishHandshake) - var frames []*ackhandler.Frame - Eventually(func() []*ackhandler.Frame { + var frames []ackhandler.Frame + Eventually(func() []ackhandler.Frame { frames, _ = conn.framer.AppendControlFrames(nil, protocol.MaxByteCount, protocol.Version1) return frames }).ShouldNot(BeEmpty()) @@ -1879,7 +1879,7 @@ var _ = Describe("Connection", func() { if cf, ok := f.Frame.(*wire.CryptoFrame); ok { count++ s += len(cf.Data) - Expect(f.Length(conn.version)).To(BeNumerically("<=", protocol.MaxPostHandshakeCryptoFrameSize)) + Expect(f.Frame.Length(conn.version)).To(BeNumerically("<=", protocol.MaxPostHandshakeCryptoFrameSize)) } } Expect(size).To(BeEquivalentTo(s)) diff --git a/framer.go b/framer.go index 92a3805a..9409af4c 100644 --- a/framer.go +++ b/framer.go @@ -15,7 +15,7 @@ type framer interface { HasData() bool QueueControlFrame(wire.Frame) - AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) + AppendControlFrames([]ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) AddActiveStream(protocol.StreamID) AppendStreamFrames([]ackhandler.StreamFrame, protocol.ByteCount, protocol.VersionNumber) ([]ackhandler.StreamFrame, protocol.ByteCount) @@ -63,7 +63,7 @@ func (f *framerI) QueueControlFrame(frame wire.Frame) { f.controlFrameMutex.Unlock() } -func (f *framerI) AppendControlFrames(frames []*ackhandler.Frame, maxLen protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { +func (f *framerI) AppendControlFrames(frames []ackhandler.Frame, maxLen protocol.ByteCount, v protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { var length protocol.ByteCount f.controlFrameMutex.Lock() for len(f.controlFrames) > 0 { @@ -72,9 +72,7 @@ func (f *framerI) AppendControlFrames(frames []*ackhandler.Frame, maxLen protoco if length+frameLen > maxLen { break } - af := ackhandler.GetFrame() - af.Frame = frame - frames = append(frames, af) + frames = append(frames, ackhandler.Frame{Frame: frame}) length += frameLen f.controlFrames = f.controlFrames[:len(f.controlFrames)-1] } diff --git a/framer_test.go b/framer_test.go index 7adc53e4..9615e78e 100644 --- a/framer_test.go +++ b/framer_test.go @@ -64,7 +64,7 @@ var _ = Describe("Framer", func() { ping := &wire.PingFrame{} mdf := &wire.MaxDataFrame{MaximumData: 0x42} framer.QueueControlFrame(mdf) - frames, length := framer.AppendControlFrames([]*ackhandler.Frame{{Frame: ping}}, 1000, protocol.Version1) + frames, length := framer.AppendControlFrames([]ackhandler.Frame{{Frame: ping}}, 1000, protocol.Version1) Expect(frames).To(HaveLen(2)) Expect(frames[0].Frame).To(Equal(ping)) Expect(frames[1].Frame).To(Equal(mdf)) diff --git a/internal/ackhandler/ack_eliciting.go b/internal/ackhandler/ack_eliciting.go index 4bab4190..34506b12 100644 --- a/internal/ackhandler/ack_eliciting.go +++ b/internal/ackhandler/ack_eliciting.go @@ -10,7 +10,7 @@ func IsFrameAckEliciting(f wire.Frame) bool { } // HasAckElicitingFrames returns true if at least one frame is ack-eliciting. -func HasAckElicitingFrames(fs []*Frame) bool { +func HasAckElicitingFrames(fs []Frame) bool { for _, f := range fs { if IsFrameAckEliciting(f.Frame) { return true diff --git a/internal/ackhandler/ack_eliciting_test.go b/internal/ackhandler/ack_eliciting_test.go index cf27dda5..cdd1c7e9 100644 --- a/internal/ackhandler/ack_eliciting_test.go +++ b/internal/ackhandler/ack_eliciting_test.go @@ -29,7 +29,7 @@ var _ = Describe("ack-eliciting frames", func() { }) It("HasAckElicitingFrames works for "+fName, func() { - Expect(HasAckElicitingFrames([]*Frame{{Frame: f}})).To(Equal(e)) + Expect(HasAckElicitingFrames([]Frame{{Frame: f}})).To(Equal(e)) }) } }) diff --git a/internal/ackhandler/frame.go b/internal/ackhandler/frame.go index cd75d56a..8c284e20 100644 --- a/internal/ackhandler/frame.go +++ b/internal/ackhandler/frame.go @@ -1,31 +1,13 @@ package ackhandler import ( - "sync" - "github.com/quic-go/quic-go/internal/wire" ) type Frame struct { - wire.Frame // nil if the frame has already been acknowledged in another packet - OnLost func(wire.Frame) - OnAcked func(wire.Frame) -} - -var framePool = sync.Pool{New: func() any { return &Frame{} }} - -func GetFrame() *Frame { - f := framePool.Get().(*Frame) - f.OnLost = nil - f.OnAcked = nil - return f -} - -func putFrame(f *Frame) { - f.Frame = nil - f.OnLost = nil - f.OnAcked = nil - framePool.Put(f) + Frame wire.Frame // nil if the frame has already been acknowledged in another packet + OnLost func(wire.Frame) + OnAcked func(wire.Frame) } type StreamFrame struct { diff --git a/internal/ackhandler/packet.go b/internal/ackhandler/packet.go index 257dd83b..5df38264 100644 --- a/internal/ackhandler/packet.go +++ b/internal/ackhandler/packet.go @@ -12,7 +12,7 @@ type Packet struct { SendTime time.Time PacketNumber protocol.PacketNumber StreamFrames []StreamFrame - Frames []*Frame + Frames []Frame LargestAcked protocol.PacketNumber // InvalidPacketNumber if the packet doesn't contain an ACK Length protocol.ByteCount EncryptionLevel protocol.EncryptionLevel @@ -49,9 +49,6 @@ func GetPacket() *Packet { // We currently only return Packets back into the pool when they're acknowledged (not when they're lost). // This simplifies the code, and gives the vast majority of the performance benefit we can gain from using the pool. func putPacket(p *Packet) { - for _, f := range p.Frames { - putFrame(f) - } p.Frames = nil p.StreamFrames = nil packetPool.Put(p) diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index 7b2cef2c..238d2b5d 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -54,7 +54,7 @@ var _ = Describe("SentPacketHandler", func() { p.SendTime = time.Now() } if len(p.Frames) == 0 { - p.Frames = []*Frame{ + p.Frames = []Frame{ {Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { lostPackets = append(lostPackets, p.PacketNumber) }}, } } @@ -276,7 +276,7 @@ var _ = Describe("SentPacketHandler", func() { ping := &wire.PingFrame{} handler.SentPacket(ackElicitingPacket(&Packet{ PacketNumber: 13, - Frames: []*Frame{{ + Frames: []Frame{{ Frame: ping, OnAcked: func(f wire.Frame) { Expect(f).To(Equal(ping)) acked = true @@ -428,20 +428,20 @@ var _ = Describe("SentPacketHandler", func() { { PacketNumber: 13, LargestAcked: 100, - Frames: []*Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, + Frames: []Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, Length: 1, EncryptionLevel: protocol.Encryption1RTT, }, { PacketNumber: 14, LargestAcked: 200, - Frames: []*Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, + Frames: []Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, Length: 1, EncryptionLevel: protocol.Encryption1RTT, }, { PacketNumber: 15, - Frames: []*Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, + Frames: []Frame{{Frame: &streamFrame, OnLost: func(wire.Frame) {}}}, Length: 1, EncryptionLevel: protocol.Encryption1RTT, }, @@ -501,7 +501,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(&Packet{ PacketNumber: 1, Length: 42, - Frames: []*Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) {}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) {}}}, EncryptionLevel: protocol.Encryption1RTT, }) }) @@ -548,7 +548,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, SendTime: time.Now().Add(-time.Hour), IsPathMTUProbePacket: true, - Frames: []*Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { mtuPacketDeclaredLost = true }}}, + Frames: []Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { mtuPacketDeclaredLost = true }}}, })) handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2})) // lose packet 1, but don't EXPECT any calls to OnPacketLost() @@ -595,7 +595,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(&Packet{ Length: 42, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) cong.EXPECT().CanSend(protocol.ByteCount(42)).Return(true) @@ -755,7 +755,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(ackElicitingPacket(&Packet{ PacketNumber: 1, SendTime: time.Now().Add(-time.Hour), - Frames: []*Frame{ + Frames: []Frame{ {Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { lostPackets = append(lostPackets, 1) }}, }, })) @@ -775,7 +775,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(ackElicitingPacket(&Packet{ PacketNumber: pn, SendTime: time.Now().Add(-time.Hour), - Frames: []*Frame{ + Frames: []Frame{ {Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { lostPackets = append(lostPackets, 1) }}, }, })) @@ -895,7 +895,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, Length: 599, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) Expect(handler.SendMode()).To(Equal(SendAny)) @@ -903,7 +903,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 2, Length: 1, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) Expect(handler.SendMode()).To(Equal(SendNone)) @@ -915,7 +915,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, Length: 900, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) // Amplification limited. We don't need to set a timer now. @@ -931,7 +931,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, Length: 900, EncryptionLevel: protocol.EncryptionHandshake, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) // Amplification limited. We don't need to set a timer now. @@ -965,7 +965,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, Length: 900, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{{Frame: &wire.PingFrame{}}}, + Frames: []Frame{{Frame: &wire.PingFrame{}}}, SendTime: time.Now(), }) Expect(handler.SendMode()).To(Equal(SendAny)) @@ -1158,7 +1158,7 @@ var _ = Describe("SentPacketHandler", func() { PacketNumber: 1, SendTime: now.Add(-3 * time.Second), IsPathMTUProbePacket: true, - Frames: []*Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { mtuPacketDeclaredLost = true }}}, + Frames: []Frame{{Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { mtuPacketDeclaredLost = true }}}, })) handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: now.Add(-3 * time.Second)})) ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}} @@ -1341,7 +1341,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(&Packet{ PacketNumber: 13, EncryptionLevel: protocol.EncryptionInitial, - Frames: []*Frame{ + Frames: []Frame{ {Frame: &wire.CryptoFrame{Data: []byte("foobar")}, OnLost: func(wire.Frame) { lostInitial = true }}, }, Length: 100, @@ -1350,7 +1350,7 @@ var _ = Describe("SentPacketHandler", func() { handler.SentPacket(&Packet{ PacketNumber: pn, EncryptionLevel: protocol.Encryption0RTT, - Frames: []*Frame{ + Frames: []Frame{ {Frame: &wire.StreamFrame{Data: []byte("foobar")}, OnLost: func(wire.Frame) { lost0RTT = true }}, }, Length: 999, diff --git a/mock_frame_source_test.go b/mock_frame_source_test.go index 21255ec6..e23aa39d 100644 --- a/mock_frame_source_test.go +++ b/mock_frame_source_test.go @@ -36,10 +36,10 @@ func (m *MockFrameSource) EXPECT() *MockFrameSourceMockRecorder { } // AppendControlFrames mocks base method. -func (m *MockFrameSource) AppendControlFrames(arg0 []*ackhandler.Frame, arg1 protocol.ByteCount, arg2 protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { +func (m *MockFrameSource) AppendControlFrames(arg0 []ackhandler.Frame, arg1 protocol.ByteCount, arg2 protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AppendControlFrames", arg0, arg1, arg2) - ret0, _ := ret[0].([]*ackhandler.Frame) + ret0, _ := ret[0].([]ackhandler.Frame) ret1, _ := ret[1].(protocol.ByteCount) return ret0, ret1 } diff --git a/packet_packer.go b/packet_packer.go index 27e42fa6..7e06040c 100644 --- a/packet_packer.go +++ b/packet_packer.go @@ -36,7 +36,7 @@ type sealer interface { type payload struct { streamFrames []ackhandler.StreamFrame - frames []*ackhandler.Frame + frames []ackhandler.Frame ack *wire.AckFrame length protocol.ByteCount } @@ -44,7 +44,7 @@ type payload struct { type longHeaderPacket struct { header *wire.ExtendedHeader ack *wire.AckFrame - frames []*ackhandler.Frame + frames []ackhandler.Frame streamFrames []ackhandler.StreamFrame // only used for 0-RTT packets length protocol.ByteCount @@ -147,7 +147,7 @@ type sealingManager interface { type frameSource interface { HasData() bool AppendStreamFrames([]ackhandler.StreamFrame, protocol.ByteCount, protocol.VersionNumber) ([]ackhandler.StreamFrame, protocol.ByteCount) - AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) + AppendControlFrames([]ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) } type ackFrameSource interface { @@ -244,7 +244,7 @@ func (p *packetPacker) packConnectionClose( ccf.ReasonPhrase = "" } pl := payload{ - frames: []*ackhandler.Frame{{Frame: ccf}}, + frames: []ackhandler.Frame{{Frame: ccf}}, length: ccf.Length(v), } @@ -345,7 +345,7 @@ func (p *packetPacker) shortHeaderPacketLength(connID protocol.ConnectionID, pnL } // size is the expected size of the packet, if no padding was applied. -func (p *packetPacker) initialPaddingLen(frames []*ackhandler.Frame, size protocol.ByteCount) protocol.ByteCount { +func (p *packetPacker) initialPaddingLen(frames []ackhandler.Frame, size protocol.ByteCount) protocol.ByteCount { // For the server, only ack-eliciting Initial packets need to be padded. if p.perspective == protocol.PerspectiveServer && !ackhandler.HasAckElicitingFrames(frames) { return 0 @@ -564,16 +564,14 @@ func (p *packetPacker) maybeGetCryptoPacket(maxPacketSize protocol.ByteCount, en if f == nil { break } - af := ackhandler.GetFrame() - af.Frame = f - pl.frames = append(pl.frames, af) + pl.frames = append(pl.frames, ackhandler.Frame{Frame: f}) frameLen := f.Length(v) pl.length += frameLen maxPacketSize -= frameLen } } else if s.HasData() { cf := s.PopCryptoFrame(maxPacketSize) - pl.frames = []*ackhandler.Frame{{Frame: cf}} + pl.frames = []ackhandler.Frame{{Frame: cf}} pl.length += cf.Length(v) } return hdr, pl @@ -605,11 +603,10 @@ func (p *packetPacker) maybeGetAppDataPacket(maxPayloadSize protocol.ByteCount, // the packet only contains an ACK if p.numNonAckElicitingAcks >= protocol.MaxNonAckElicitingAcks { ping := &wire.PingFrame{} - // don't retransmit the PING frame when it is lost - af := ackhandler.GetFrame() - af.Frame = ping - af.OnLost = func(wire.Frame) {} - pl.frames = append(pl.frames, af) + pl.frames = append(pl.frames, ackhandler.Frame{ + Frame: ping, + OnLost: func(wire.Frame) {}, // don't retransmit the PING frame when it is lost + }) pl.length += ping.Length(v) p.numNonAckElicitingAcks = 0 } else { @@ -650,11 +647,10 @@ func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount, onlyAc if f := p.datagramQueue.Peek(); f != nil { size := f.Length(v) if size <= maxFrameSize-pl.length { - af := ackhandler.GetFrame() - af.Frame = f - // set it to a no-op. Then we won't set the default callback, which would retransmit the frame. - af.OnLost = func(wire.Frame) {} - pl.frames = append(pl.frames, af) + pl.frames = append(pl.frames, ackhandler.Frame{ + Frame: f, + OnLost: func(wire.Frame) {}, // set it to a no-op. Then we won't set the default callback, which would retransmit the frame. + }) pl.length += size p.datagramQueue.Pop() } @@ -675,9 +671,7 @@ func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount, onlyAc if f == nil { break } - af := ackhandler.GetFrame() - af.Frame = f - pl.frames = append(pl.frames, af) + pl.frames = append(pl.frames, ackhandler.Frame{Frame: f}) pl.length += f.Length(v) } } @@ -767,8 +761,8 @@ func (p *packetPacker) MaybePackProbePacket(encLevel protocol.EncryptionLevel, v func (p *packetPacker) PackMTUProbePacket(ping ackhandler.Frame, size protocol.ByteCount, now time.Time, v protocol.VersionNumber) (shortHeaderPacket, *packetBuffer, error) { pl := payload{ - frames: []*ackhandler.Frame{&ping}, - length: ping.Length(v), + frames: []ackhandler.Frame{ping}, + length: ping.Frame.Length(v), } buffer := getPacketBuffer() s, err := p.cryptoSetup.Get1RTTSealer() @@ -934,7 +928,7 @@ func (p *packetPacker) appendPacketPayload(raw []byte, pl payload, paddingLen pr } for _, f := range pl.frames { var err error - raw, err = f.Append(raw, v) + raw, err = f.Frame.Append(raw, v) if err != nil { return nil, err } diff --git a/packet_packer_test.go b/packet_packer_test.go index 07d9e9a8..4fa2ce14 100644 --- a/packet_packer_test.go +++ b/packet_packer_test.go @@ -73,8 +73,8 @@ var _ = Describe("Packet packer", func() { }) } - expectAppendControlFrames := func(frames ...*ackhandler.Frame) { - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + expectAppendControlFrames := func(frames ...ackhandler.Frame) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(fs []ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { var length protocol.ByteCount for _, f := range frames { length += f.Frame.Length(v) @@ -299,11 +299,11 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().Get0RTTSealer().Return(getSealer(), nil).AnyTimes() pnManager.EXPECT().PeekPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42)) - cf := &ackhandler.Frame{Frame: &wire.MaxDataFrame{MaximumData: 0x1337}} + cf := ackhandler.Frame{Frame: &wire.MaxDataFrame{MaximumData: 0x1337}} framer.EXPECT().HasData().Return(true) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(frames []*ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(frames []ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { Expect(frames).To(BeEmpty()) - return append(frames, cf), cf.Length(v) + return append(frames, cf), cf.Frame.Length(v) }) // TODO: check sizes framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(frames []ackhandler.StreamFrame, _ protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.StreamFrame, protocol.ByteCount) { @@ -315,7 +315,7 @@ var _ = Describe("Packet packer", func() { Expect(p.longHdrPackets).To(HaveLen(1)) Expect(p.longHdrPackets[0].header.Type).To(Equal(protocol.PacketType0RTT)) Expect(p.longHdrPackets[0].EncryptionLevel()).To(Equal(protocol.Encryption0RTT)) - Expect(p.longHdrPackets[0].frames).To(Equal([]*ackhandler.Frame{cf})) + Expect(p.longHdrPackets[0].frames).To(Equal([]ackhandler.Frame{cf})) }) It("doesn't add an ACK-only 0-RTT packet", func() { // ACK frames cannot be sent in 0-RTT packets @@ -540,7 +540,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) framer.EXPECT().HasData().Return(true) ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) - frames := []*ackhandler.Frame{ + frames := []ackhandler.Frame{ {Frame: &wire.ResetStreamFrame{}}, {Frame: &wire.MaxDataFrame{}}, } @@ -620,7 +620,7 @@ var _ = Describe("Packet packer", func() { ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) var maxSize protocol.ByteCount gomock.InOrder( - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(fs []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(fs []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { maxSize = maxLen return fs, 444 }), @@ -839,7 +839,7 @@ var _ = Describe("Packet packer", func() { framer.EXPECT().HasData().Return(true) ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendStreamFrames() - expectAppendControlFrames(&ackhandler.Frame{Frame: &wire.MaxDataFrame{}}) + expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}}) p, _, err := packer.PackPacket(false, time.Now(), protocol.Version1) Expect(err).ToNot(HaveOccurred()) Expect(p).ToNot(BeNil()) @@ -854,7 +854,7 @@ var _ = Describe("Packet packer", func() { 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(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { initialMaxPacketSize = maxLen return nil, 0 }) @@ -865,7 +865,7 @@ var _ = Describe("Packet packer", func() { packer.HandleTransportParameters(&wire.TransportParameters{ MaxUDPPayloadSize: maxPacketSize - 10, }) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { Expect(maxLen).To(Equal(initialMaxPacketSize - 10)) return nil, 0 }) @@ -880,7 +880,7 @@ var _ = Describe("Packet packer", func() { 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(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { initialMaxPacketSize = maxLen return nil, 0 }) @@ -891,7 +891,7 @@ var _ = Describe("Packet packer", func() { packer.HandleTransportParameters(&wire.TransportParameters{ MaxUDPPayloadSize: maxPacketSize + 10, }) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { Expect(maxLen).To(Equal(initialMaxPacketSize)) return nil, 0 }) @@ -908,7 +908,7 @@ var _ = Describe("Packet packer", func() { 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(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { initialMaxPacketSize = maxLen return nil, 0 }) @@ -918,7 +918,7 @@ var _ = Describe("Packet packer", func() { // now reduce the maxPacketSize const packetSizeIncrease = 50 packer.SetMaxPacketSize(maxPacketSize + packetSizeIncrease) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]ackhandler.Frame, protocol.ByteCount) { Expect(maxLen).To(Equal(initialMaxPacketSize + packetSizeIncrease)) return nil, 0 }) @@ -1287,7 +1287,7 @@ var _ = Describe("Packet packer", func() { Expect(err).ToNot(HaveOccurred()) Expect(p.longHdrPackets).To(HaveLen(1)) Expect(p.longHdrPackets[0].EncryptionLevel()).To(Equal(protocol.EncryptionInitial)) - Expect(p.longHdrPackets[0].frames).To(Equal([]*ackhandler.Frame{{Frame: f}})) + Expect(p.longHdrPackets[0].frames).To(Equal([]ackhandler.Frame{{Frame: f}})) }) It("sends an Initial packet containing only an ACK", func() { @@ -1558,7 +1558,7 @@ var _ = Describe("Converting to ackhandler.Packet", func() { It("convert a packet", func() { packet := &longHeaderPacket{ header: &wire.ExtendedHeader{Header: wire.Header{Type: protocol.PacketTypeInitial}}, - frames: []*ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}}, + frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}}, ack: &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 100, Smallest: 80}}}, length: 42, } @@ -1573,7 +1573,7 @@ var _ = Describe("Converting to ackhandler.Packet", func() { It("sets the LargestAcked to invalid, if the packet doesn't have an ACK frame", func() { packet := &longHeaderPacket{ header: &wire.ExtendedHeader{Header: wire.Header{Type: protocol.PacketTypeHandshake}}, - frames: []*ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}}, + frames: []ackhandler.Frame{{Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}}}, } p := packet.ToAckHandlerPacket(time.Now(), nil) Expect(p.LargestAcked).To(Equal(protocol.InvalidPacketNumber)) @@ -1585,7 +1585,7 @@ var _ = Describe("Converting to ackhandler.Packet", func() { var pingLost bool packet := &longHeaderPacket{ header: &wire.ExtendedHeader{Header: hdr}, - frames: []*ackhandler.Frame{ + frames: []ackhandler.Frame{ {Frame: &wire.MaxDataFrame{}}, {Frame: &wire.PingFrame{}, OnLost: func(wire.Frame) { pingLost = true }}, },