diff --git a/connection.go b/connection.go index 96dda493..ffdec0fa 100644 --- a/connection.go +++ b/connection.go @@ -503,7 +503,7 @@ func (s *connection) preSetup() { uint64(s.config.MaxIncomingUniStreams), s.perspective, ) - s.framer = newFramer(s.streamsMap, s.version) + s.framer = newFramer(s.streamsMap) s.receivedPackets = make(chan *receivedPacket, protocol.MaxConnUnprocessedPackets) s.closeChan = make(chan closeError, 1) s.sendingScheduled = make(chan struct{}, 1) diff --git a/connection_test.go b/connection_test.go index a83690c6..a09e648c 100644 --- a/connection_test.go +++ b/connection_test.go @@ -308,7 +308,7 @@ var _ = Describe("Connection", func() { data := [8]byte{1, 2, 3, 4, 5, 6, 7, 8} err := conn.handleFrame(&wire.PathChallengeFrame{Data: data}, protocol.Encryption1RTT, protocol.ConnectionID{}) Expect(err).ToNot(HaveOccurred()) - frames, _ := conn.framer.AppendControlFrames(nil, 1000) + frames, _ := conn.framer.AppendControlFrames(nil, 1000, protocol.Version1) Expect(frames).To(Equal([]*ackhandler.Frame{{Frame: &wire.PathResponseFrame{Data: data}}})) }) @@ -1269,7 +1269,7 @@ var _ = Describe("Connection", func() { tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), buffer.Len(), nil, []logging.Frame{}) conn.scheduleSending() Eventually(sent).Should(BeClosed()) - frames, _ := conn.framer.AppendControlFrames(nil, 1000) + frames, _ := conn.framer.AppendControlFrames(nil, 1000, protocol.Version1) Expect(frames).To(Equal([]*ackhandler.Frame{{Frame: &logging.DataBlockedFrame{MaximumData: 1337}}})) }) @@ -1869,7 +1869,7 @@ var _ = Describe("Connection", func() { close(finishHandshake) var frames []*ackhandler.Frame Eventually(func() []*ackhandler.Frame { - frames, _ = conn.framer.AppendControlFrames(nil, protocol.MaxByteCount) + frames, _ = conn.framer.AppendControlFrames(nil, protocol.MaxByteCount, protocol.Version1) return frames }).ShouldNot(BeEmpty()) var count int @@ -1928,8 +1928,8 @@ var _ = Describe("Connection", func() { conn.sentPacketHandler = sph done := make(chan struct{}) connRunner.EXPECT().Retire(clientDestConnID) - packer.EXPECT().PackPacket(false, gomock.Any(), conn.version).DoAndReturn(func(bool, time.Time, protocol.VersionNumber) (shortHeaderPacket, *packetBuffer, error) { - frames, _ := conn.framer.AppendControlFrames(nil, protocol.MaxByteCount) + packer.EXPECT().PackPacket(false, gomock.Any(), conn.version).DoAndReturn(func(_ bool, _ time.Time, v protocol.VersionNumber) (shortHeaderPacket, *packetBuffer, error) { + frames, _ := conn.framer.AppendControlFrames(nil, protocol.MaxByteCount, v) Expect(frames).ToNot(BeEmpty()) Expect(frames[0].Frame).To(BeEquivalentTo(&wire.HandshakeDoneFrame{})) defer close(done) @@ -2744,7 +2744,7 @@ var _ = Describe("Client Connection", func() { conn.handleTransportParameters(params) conn.handleHandshakeComplete() // make sure the connection ID is not retired - cf, _ := conn.framer.AppendControlFrames(nil, protocol.MaxByteCount) + cf, _ := conn.framer.AppendControlFrames(nil, protocol.MaxByteCount, protocol.Version1) Expect(cf).To(BeEmpty()) connRunner.EXPECT().AddResetToken(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, conn) Expect(conn.connIDManager.Get()).To(Equal(protocol.ParseConnectionID([]byte{1, 2, 3, 4}))) diff --git a/framer.go b/framer.go index fa2179f5..72a23e3f 100644 --- a/framer.go +++ b/framer.go @@ -14,10 +14,10 @@ type framer interface { HasData() bool QueueControlFrame(wire.Frame) - AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) + AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) AddActiveStream(protocol.StreamID) - AppendStreamFrames([]*ackhandler.Frame, protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) + AppendStreamFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) Handle0RTTRejection() error } @@ -26,7 +26,6 @@ type framerI struct { mutex sync.Mutex streamGetter streamGetter - version protocol.VersionNumber activeStreams map[protocol.StreamID]struct{} streamQueue []protocol.StreamID @@ -37,14 +36,10 @@ type framerI struct { var _ framer = &framerI{} -func newFramer( - streamGetter streamGetter, - v protocol.VersionNumber, -) framer { +func newFramer(streamGetter streamGetter) framer { return &framerI{ streamGetter: streamGetter, activeStreams: make(map[protocol.StreamID]struct{}), - version: v, } } @@ -67,12 +62,12 @@ func (f *framerI) QueueControlFrame(frame wire.Frame) { f.controlFrameMutex.Unlock() } -func (f *framerI) AppendControlFrames(frames []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 { frame := f.controlFrames[len(f.controlFrames)-1] - frameLen := frame.Length(f.version) + frameLen := frame.Length(v) if length+frameLen > maxLen { break } @@ -95,7 +90,7 @@ func (f *framerI) AddActiveStream(id protocol.StreamID) { f.mutex.Unlock() } -func (f *framerI) AppendStreamFrames(frames []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { +func (f *framerI) AppendStreamFrames(frames []*ackhandler.Frame, maxLen protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { var length protocol.ByteCount var lastFrame *ackhandler.Frame f.mutex.Lock() @@ -120,7 +115,7 @@ func (f *framerI) AppendStreamFrames(frames []*ackhandler.Frame, maxLen protocol // Therefore, we can pretend to have more bytes available when popping // the STREAM frame (which will always have the DataLen set). remainingLen += quicvarint.Len(uint64(remainingLen)) - frame, hasMoreData := str.popStreamFrame(remainingLen, f.version) + frame, hasMoreData := str.popStreamFrame(remainingLen, v) if hasMoreData { // put the stream back in the queue (at the end) f.streamQueue = append(f.streamQueue, id) } else { // no more data to send. Stream is not active any more @@ -133,15 +128,15 @@ func (f *framerI) AppendStreamFrames(frames []*ackhandler.Frame, maxLen protocol continue } frames = append(frames, frame) - length += frame.Length(f.version) + length += frame.Length(v) lastFrame = frame } f.mutex.Unlock() if lastFrame != nil { - lastFrameLen := lastFrame.Length(f.version) + lastFrameLen := lastFrame.Length(v) // account for the smaller size of the last STREAM frame lastFrame.Frame.(*wire.StreamFrame).DataLenPresent = false - length += lastFrame.Length(f.version) - lastFrameLen + length += lastFrame.Length(v) - lastFrameLen } return frames, length } diff --git a/framer_test.go b/framer_test.go index 77ab90f7..7a5d8a78 100644 --- a/framer_test.go +++ b/framer_test.go @@ -33,7 +33,7 @@ var _ = Describe("Framer", func() { stream1.EXPECT().StreamID().Return(protocol.StreamID(5)).AnyTimes() stream2 = NewMockSendStreamI(mockCtrl) stream2.EXPECT().StreamID().Return(protocol.StreamID(6)).AnyTimes() - framer = newFramer(streamGetter, protocol.Version1) + framer = newFramer(streamGetter) }) Context("handling control frames", func() { @@ -42,7 +42,7 @@ var _ = Describe("Framer", func() { msf := &wire.MaxStreamsFrame{MaxStreamNum: 0x1337} framer.QueueControlFrame(mdf) framer.QueueControlFrame(msf) - frames, length := framer.AppendControlFrames(nil, 1000) + frames, length := framer.AppendControlFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(2)) fs := []wire.Frame{frames[0].Frame, frames[1].Frame} Expect(fs).To(ContainElement(mdf)) @@ -55,7 +55,7 @@ var _ = Describe("Framer", func() { f := &wire.MaxDataFrame{MaximumData: 0x42} framer.QueueControlFrame(f) Expect(framer.HasData()).To(BeTrue()) - frames, _ := framer.AppendControlFrames(nil, 1000) + frames, _ := framer.AppendControlFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(framer.HasData()).To(BeFalse()) }) @@ -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) + 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)) @@ -79,10 +79,10 @@ var _ = Describe("Framer", func() { for i := 0; i < numFrames+1; i++ { framer.QueueControlFrame(bf) } - frames, length := framer.AppendControlFrames(nil, maxSize) + frames, length := framer.AppendControlFrames(nil, maxSize, protocol.Version1) Expect(frames).To(HaveLen(numFrames)) Expect(length).To(BeNumerically(">", maxSize-bfLen)) - frames, length = framer.AppendControlFrames(nil, maxSize) + frames, length = framer.AppendControlFrames(nil, maxSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(length).To(Equal(bfLen)) }) @@ -105,7 +105,7 @@ var _ = Describe("Framer", func() { framer.QueueControlFrame(f) } Expect(framer.Handle0RTTRejection()).To(Succeed()) - fs, length := framer.AppendControlFrames(nil, protocol.MaxByteCount) + fs, length := framer.AppendControlFrames(nil, protocol.MaxByteCount, protocol.Version1) Expect(fs).To(HaveLen(2)) Expect(length).To(Equal(ping.Length(version) + ncid.Length(version))) }) @@ -113,7 +113,7 @@ var _ = Describe("Framer", func() { Context("popping STREAM frames", func() { It("returns nil when popping an empty framer", func() { - Expect(framer.AppendStreamFrames(nil, 1000)).To(BeEmpty()) + Expect(framer.AppendStreamFrames(nil, 1000, protocol.Version1)).To(BeEmpty()) }) It("returns STREAM frames", func() { @@ -126,7 +126,7 @@ var _ = Describe("Framer", func() { } stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) framer.AddActiveStream(id1) - fs, length := framer.AppendStreamFrames(nil, 1000) + fs, length := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(fs).To(HaveLen(1)) Expect(fs[0].Frame.(*wire.StreamFrame).DataLenPresent).To(BeFalse()) Expect(length).To(Equal(f.Length(version))) @@ -141,11 +141,11 @@ var _ = Describe("Framer", func() { f2 := &wire.StreamFrame{StreamID: id1, Data: []byte("bar")} stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f1}, true) stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f2}, false) - frames, _ := framer.AppendStreamFrames(nil, protocol.MaxByteCount) + frames, _ := framer.AppendStreamFrames(nil, protocol.MaxByteCount, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f1)) Expect(framer.HasData()).To(BeTrue()) - frames, _ = framer.AppendStreamFrames(nil, protocol.MaxByteCount) + frames, _ = framer.AppendStreamFrames(nil, protocol.MaxByteCount, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f2)) Expect(framer.HasData()).To(BeFalse()) @@ -162,7 +162,7 @@ var _ = Describe("Framer", func() { framer.AddActiveStream(id1) mdf := &wire.MaxDataFrame{MaximumData: 1337} frames := []*ackhandler.Frame{{Frame: mdf}} - fs, length := framer.AppendStreamFrames(frames, 1000) + fs, length := framer.AppendStreamFrames(frames, 1000, protocol.Version1) Expect(fs).To(HaveLen(2)) Expect(fs[0].Frame).To(Equal(mdf)) Expect(fs[1].Frame.(*wire.StreamFrame).Data).To(Equal([]byte("foobar"))) @@ -181,7 +181,7 @@ var _ = Describe("Framer", func() { stream2.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) framer.AddActiveStream(id1) framer.AddActiveStream(id2) - frames, _ := framer.AppendStreamFrames(nil, 1000) + frames, _ := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f)) }) @@ -198,7 +198,7 @@ var _ = Describe("Framer", func() { stream2.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) framer.AddActiveStream(id1) framer.AddActiveStream(id2) - frames, _ := framer.AppendStreamFrames(nil, 1000) + frames, _ := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f)) }) @@ -210,14 +210,14 @@ var _ = Describe("Framer", func() { stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f1}, true) stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f2}, false) framer.AddActiveStream(id1) // only add it once - frames, _ := framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ := framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f1)) - frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f2)) // no further calls to popStreamFrame, after popStreamFrame said there's no more data - frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(BeNil()) }) @@ -233,15 +233,15 @@ var _ = Describe("Framer", func() { framer.AddActiveStream(id1) // only add it once framer.AddActiveStream(id2) // first a frame from stream 1 - frames, _ := framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ := framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f11)) // then a frame from stream 2 - frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f2)) // then another frame from stream 1 - frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + frames, _ = framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) Expect(frames).To(HaveLen(1)) Expect(frames[0].Frame).To(Equal(f12)) }) @@ -256,7 +256,7 @@ var _ = Describe("Framer", func() { stream2.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f2}, true) framer.AddActiveStream(id1) framer.AddActiveStream(id2) - frames, length := framer.AppendStreamFrames(nil, 1000) + frames, length := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(2)) Expect(frames[0].Frame).To(Equal(f1)) Expect(frames[1].Frame).To(Equal(f2)) @@ -272,7 +272,7 @@ var _ = Describe("Framer", func() { stream2.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f2}, false) framer.AddActiveStream(id2) framer.AddActiveStream(id1) - frames, _ := framer.AppendStreamFrames(nil, 1000) + frames, _ := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(2)) Expect(frames[0].Frame).To(Equal(f2)) Expect(frames[1].Frame).To(Equal(f1)) @@ -284,12 +284,12 @@ var _ = Describe("Framer", func() { stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) // only one call to this function framer.AddActiveStream(id1) framer.AddActiveStream(id1) - frames, _ := framer.AppendStreamFrames(nil, 1000) + frames, _ := framer.AppendStreamFrames(nil, 1000, protocol.Version1) Expect(frames).To(HaveLen(1)) }) It("does not pop empty frames", func() { - fs, length := framer.AppendStreamFrames(nil, 500) + fs, length := framer.AppendStreamFrames(nil, 500, protocol.Version1) Expect(fs).To(BeEmpty()) Expect(length).To(BeZero()) }) @@ -307,7 +307,7 @@ var _ = Describe("Framer", func() { return &ackhandler.Frame{Frame: f}, false }) framer.AddActiveStream(id1) - frames, _ := framer.AppendStreamFrames(nil, i) + frames, _ := framer.AppendStreamFrames(nil, i, protocol.Version1) Expect(frames).To(HaveLen(1)) f := frames[0].Frame.(*wire.StreamFrame) Expect(f.DataLenPresent).To(BeFalse()) @@ -338,7 +338,7 @@ var _ = Describe("Framer", func() { }) framer.AddActiveStream(id1) framer.AddActiveStream(id2) - frames, _ := framer.AppendStreamFrames(nil, i) + frames, _ := framer.AppendStreamFrames(nil, i, protocol.Version1) Expect(frames).To(HaveLen(2)) f1 := frames[0].Frame.(*wire.StreamFrame) f2 := frames[1].Frame.(*wire.StreamFrame) @@ -353,12 +353,12 @@ var _ = Describe("Framer", func() { f := &wire.StreamFrame{Data: []byte("foobar")} stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) framer.AddActiveStream(id1) - framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize) + framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize, protocol.Version1) }) It("does not pop frames smaller than the minimum size", func() { // don't expect a call to PopStreamFrame() - framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize-1) + framer.AppendStreamFrames(nil, protocol.MinStreamFrameSize-1, protocol.Version1) }) It("stops iterating when the remaining size is smaller than the minimum STREAM frame size", func() { @@ -371,7 +371,7 @@ var _ = Describe("Framer", func() { } stream1.EXPECT().popStreamFrame(gomock.Any(), protocol.Version1).Return(&ackhandler.Frame{Frame: f}, false) framer.AddActiveStream(id1) - fs, length := framer.AppendStreamFrames(nil, 500) + fs, length := framer.AppendStreamFrames(nil, 500, protocol.Version1) Expect(fs).To(HaveLen(1)) Expect(fs[0].Frame).To(Equal(f)) Expect(length).To(Equal(f.Length(version))) @@ -380,7 +380,7 @@ var _ = Describe("Framer", func() { It("drops all STREAM frames when 0-RTT is rejected", func() { framer.AddActiveStream(id1) Expect(framer.Handle0RTTRejection()).To(Succeed()) - fs, length := framer.AppendStreamFrames(nil, protocol.MaxByteCount) + fs, length := framer.AppendStreamFrames(nil, protocol.MaxByteCount, protocol.Version1) Expect(fs).To(BeEmpty()) Expect(length).To(BeZero()) }) diff --git a/mock_frame_source_test.go b/mock_frame_source_test.go index ed2efa67..b12be743 100644 --- a/mock_frame_source_test.go +++ b/mock_frame_source_test.go @@ -36,33 +36,33 @@ func (m *MockFrameSource) EXPECT() *MockFrameSourceMockRecorder { } // AppendControlFrames mocks base method. -func (m *MockFrameSource) AppendControlFrames(arg0 []*ackhandler.Frame, arg1 protocol.ByteCount) ([]*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) + ret := m.ctrl.Call(m, "AppendControlFrames", arg0, arg1, arg2) ret0, _ := ret[0].([]*ackhandler.Frame) ret1, _ := ret[1].(protocol.ByteCount) return ret0, ret1 } // AppendControlFrames indicates an expected call of AppendControlFrames. -func (mr *MockFrameSourceMockRecorder) AppendControlFrames(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockFrameSourceMockRecorder) AppendControlFrames(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendControlFrames", reflect.TypeOf((*MockFrameSource)(nil).AppendControlFrames), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendControlFrames", reflect.TypeOf((*MockFrameSource)(nil).AppendControlFrames), arg0, arg1, arg2) } // AppendStreamFrames mocks base method. -func (m *MockFrameSource) AppendStreamFrames(arg0 []*ackhandler.Frame, arg1 protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { +func (m *MockFrameSource) AppendStreamFrames(arg0 []*ackhandler.Frame, arg1 protocol.ByteCount, arg2 protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AppendStreamFrames", arg0, arg1) + ret := m.ctrl.Call(m, "AppendStreamFrames", arg0, arg1, arg2) ret0, _ := ret[0].([]*ackhandler.Frame) ret1, _ := ret[1].(protocol.ByteCount) return ret0, ret1 } // AppendStreamFrames indicates an expected call of AppendStreamFrames. -func (mr *MockFrameSourceMockRecorder) AppendStreamFrames(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockFrameSourceMockRecorder) AppendStreamFrames(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendStreamFrames", reflect.TypeOf((*MockFrameSource)(nil).AppendStreamFrames), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendStreamFrames", reflect.TypeOf((*MockFrameSource)(nil).AppendStreamFrames), arg0, arg1, arg2) } // HasData mocks base method. diff --git a/packet_packer.go b/packet_packer.go index 2f97c631..a938230d 100644 --- a/packet_packer.go +++ b/packet_packer.go @@ -143,8 +143,8 @@ type sealingManager interface { type frameSource interface { HasData() bool - AppendStreamFrames([]*ackhandler.Frame, protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) - AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) + AppendStreamFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) + AppendControlFrames([]*ackhandler.Frame, protocol.ByteCount, protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) } type ackFrameSource interface { @@ -681,10 +681,10 @@ func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount, onlyAc if hasData { var lengthAdded protocol.ByteCount - pl.frames, lengthAdded = p.framer.AppendControlFrames(pl.frames, maxFrameSize-pl.length) + pl.frames, lengthAdded = p.framer.AppendControlFrames(pl.frames, maxFrameSize-pl.length, v) pl.length += lengthAdded - pl.frames, lengthAdded = p.framer.AppendStreamFrames(pl.frames, maxFrameSize-pl.length) + pl.frames, lengthAdded = p.framer.AppendStreamFrames(pl.frames, maxFrameSize-pl.length, v) pl.length += lengthAdded } return pl diff --git a/packet_packer_test.go b/packet_packer_test.go index 220fa7b9..943ee39e 100644 --- a/packet_packer_test.go +++ b/packet_packer_test.go @@ -63,23 +63,23 @@ var _ = Describe("Packet packer", func() { ExpectWithOffset(1, len(data)-l+int(pnLen)).To(BeNumerically(">=", 4)) } - appendFrames := func(fs, frames []*ackhandler.Frame) ([]*ackhandler.Frame, protocol.ByteCount) { + appendFrames := func(fs, frames []*ackhandler.Frame, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { var length protocol.ByteCount for _, f := range frames { - length += f.Frame.Length(protocol.Version1) + length += f.Frame.Length(v) } return append(fs, frames...), length } expectAppendStreamFrames := func(frames ...*ackhandler.Frame) { - framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, _ protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { - return appendFrames(fs, frames) + framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + return appendFrames(fs, frames, v) }) } expectAppendControlFrames := func(frames ...*ackhandler.Frame) { - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, _ protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { - return appendFrames(fs, frames) + framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, _ protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + return appendFrames(fs, frames, v) }) } @@ -300,12 +300,12 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42)) cf := &ackhandler.Frame{Frame: &wire.MaxDataFrame{MaximumData: 0x1337}} framer.EXPECT().HasData().Return(true) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(frames []*ackhandler.Frame, _ protocol.ByteCount) ([]*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(protocol.Version1) + return append(frames, cf), cf.Length(v) }) // TODO: check sizes - framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(frames []*ackhandler.Frame, _ protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(frames []*ackhandler.Frame, _ protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { return frames, 0 }) p, err := packer.PackCoalescedPacket(false, protocol.Version1) @@ -612,11 +612,11 @@ var _ = Describe("Packet packer", func() { ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) var maxSize protocol.ByteCount gomock.InOrder( - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }), - framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any()).Do(func(fs []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { + framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), protocol.Version1).Do(func(fs []*ackhandler.Frame, maxLen protocol.ByteCount, _ protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { Expect(maxLen).To(Equal(maxSize - 444)) return fs, 0 }), @@ -845,7 +845,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()).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }) @@ -856,7 +856,7 @@ var _ = Describe("Packet packer", func() { packer.HandleTransportParameters(&wire.TransportParameters{ MaxUDPPayloadSize: maxPacketSize - 10, }) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }) @@ -871,7 +871,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()).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }) @@ -882,7 +882,7 @@ var _ = Describe("Packet packer", func() { packer.HandleTransportParameters(&wire.TransportParameters{ MaxUDPPayloadSize: maxPacketSize + 10, }) - framer.EXPECT().AppendControlFrames(gomock.Any(), gomock.Any()).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }) @@ -899,7 +899,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()).Do(func(_ []*ackhandler.Frame, maxLen protocol.ByteCount) ([]*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 }) @@ -909,7 +909,7 @@ var _ = Describe("Packet packer", func() { // 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) { + 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 }) @@ -1496,10 +1496,10 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42)) framer.EXPECT().HasData().Return(true) expectAppendControlFrames() - framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any()).DoAndReturn(func(fs []*ackhandler.Frame, maxSize protocol.ByteCount) ([]*ackhandler.Frame, protocol.ByteCount) { - sf, split := f.MaybeSplitOffFrame(maxSize, protocol.Version1) + framer.EXPECT().AppendStreamFrames(gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(fs []*ackhandler.Frame, maxSize protocol.ByteCount, v protocol.VersionNumber) ([]*ackhandler.Frame, protocol.ByteCount) { + sf, split := f.MaybeSplitOffFrame(maxSize, v) Expect(split).To(BeTrue()) - return append(fs, &ackhandler.Frame{Frame: sf}), sf.Length(protocol.Version1) + return append(fs, &ackhandler.Frame{Frame: sf}), sf.Length(v) }) p, err := packer.MaybePackProbePacket(protocol.Encryption1RTT, protocol.Version1)