From 91775000964b86d5796707ec4d9574eb0f74ad04 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 13 May 2020 18:46:04 +0700 Subject: [PATCH] bundle ACK frames when packing a packet --- internal/ackhandler/interfaces.go | 2 +- .../ackhandler/received_packet_handler.go | 8 +- .../received_packet_handler_test.go | 24 +-- .../ackhandler/received_packet_handler.go | 8 +- mock_ack_frame_source_test.go | 8 +- mock_frame_source_test.go | 14 ++ packet_packer.go | 61 +++--- packet_packer_test.go | 174 +++++++++++------- 8 files changed, 187 insertions(+), 112 deletions(-) diff --git a/internal/ackhandler/interfaces.go b/internal/ackhandler/interfaces.go index d6109f91..a233704d 100644 --- a/internal/ackhandler/interfaces.go +++ b/internal/ackhandler/interfaces.go @@ -68,5 +68,5 @@ type ReceivedPacketHandler interface { DropPackets(protocol.EncryptionLevel) GetAlarmTimeout() time.Time - GetAckFrame(protocol.EncryptionLevel) *wire.AckFrame + GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame } diff --git a/internal/ackhandler/received_packet_handler.go b/internal/ackhandler/received_packet_handler.go index af67a0c4..1b707639 100644 --- a/internal/ackhandler/received_packet_handler.go +++ b/internal/ackhandler/received_packet_handler.go @@ -113,20 +113,20 @@ func (h *receivedPacketHandler) GetAlarmTimeout() time.Time { return utils.MinNonZeroTime(utils.MinNonZeroTime(initialAlarm, handshakeAlarm), oneRTTAlarm) } -func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel) *wire.AckFrame { +func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame { var ack *wire.AckFrame switch encLevel { case protocol.EncryptionInitial: if h.initialPackets != nil { - ack = h.initialPackets.GetAckFrame(true) + ack = h.initialPackets.GetAckFrame(onlyIfQueued) } case protocol.EncryptionHandshake: if h.handshakePackets != nil { - ack = h.handshakePackets.GetAckFrame(true) + ack = h.handshakePackets.GetAckFrame(onlyIfQueued) } case protocol.Encryption1RTT: // 0-RTT packets can't contain ACK frames - return h.appDataPackets.GetAckFrame(true) + return h.appDataPackets.GetAckFrame(onlyIfQueued) default: return nil } diff --git a/internal/ackhandler/received_packet_handler_test.go b/internal/ackhandler/received_packet_handler_test.go index deb32372..7fbf2119 100644 --- a/internal/ackhandler/received_packet_handler_test.go +++ b/internal/ackhandler/received_packet_handler_test.go @@ -40,17 +40,17 @@ var _ = Describe("Received Packet Handler", func() { Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) - initialAck := handler.GetAckFrame(protocol.EncryptionInitial) + initialAck := handler.GetAckFrame(protocol.EncryptionInitial, true) Expect(initialAck).ToNot(BeNil()) Expect(initialAck.AckRanges).To(HaveLen(1)) Expect(initialAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3})) Expect(initialAck.DelayTime).To(BeZero()) - handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake) + handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake, true) Expect(handshakeAck).ToNot(BeNil()) Expect(handshakeAck.AckRanges).To(HaveLen(1)) Expect(handshakeAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 1, Largest: 2})) Expect(handshakeAck.DelayTime).To(BeZero()) - oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT) + oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT, true) Expect(oneRTTAck).ToNot(BeNil()) Expect(oneRTTAck.AckRanges).To(HaveLen(1)) Expect(oneRTTAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 4, Largest: 5})) @@ -64,7 +64,7 @@ var _ = Describe("Received Packet Handler", func() { sendTime := time.Now().Add(-time.Second) Expect(handler.ReceivedPacket(2, protocol.Encryption0RTT, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(3, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) - ack := handler.GetAckFrame(protocol.Encryption1RTT) + ack := handler.GetAckFrame(protocol.Encryption1RTT, true) Expect(ack).ToNot(BeNil()) Expect(ack.AckRanges).To(HaveLen(1)) Expect(ack.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3})) @@ -93,10 +93,10 @@ var _ = Describe("Received Packet Handler", func() { sendTime := time.Now().Add(-time.Second) Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed()) - Expect(handler.GetAckFrame(protocol.EncryptionInitial)).ToNot(BeNil()) + Expect(handler.GetAckFrame(protocol.EncryptionInitial, true)).ToNot(BeNil()) handler.DropPackets(protocol.EncryptionInitial) - Expect(handler.GetAckFrame(protocol.EncryptionInitial)).To(BeNil()) - Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).ToNot(BeNil()) + Expect(handler.GetAckFrame(protocol.EncryptionInitial, true)).To(BeNil()) + Expect(handler.GetAckFrame(protocol.EncryptionHandshake, true)).ToNot(BeNil()) }) It("drops Handshake packets", func() { @@ -105,10 +105,10 @@ var _ = Describe("Received Packet Handler", func() { sendTime := time.Now().Add(-time.Second) Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(2, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) - Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).ToNot(BeNil()) + Expect(handler.GetAckFrame(protocol.EncryptionHandshake, true)).ToNot(BeNil()) handler.DropPackets(protocol.EncryptionInitial) - Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).To(BeNil()) - Expect(handler.GetAckFrame(protocol.Encryption1RTT)).ToNot(BeNil()) + Expect(handler.GetAckFrame(protocol.EncryptionHandshake, true)).To(BeNil()) + Expect(handler.GetAckFrame(protocol.Encryption1RTT, true)).ToNot(BeNil()) }) It("does nothing when dropping 0-RTT packets", func() { @@ -121,7 +121,7 @@ var _ = Describe("Received Packet Handler", func() { sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Times(2) Expect(handler.ReceivedPacket(1, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) Expect(handler.ReceivedPacket(2, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) - ack := handler.GetAckFrame(protocol.Encryption1RTT) + ack := handler.GetAckFrame(protocol.Encryption1RTT, true) Expect(ack).ToNot(BeNil()) Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2))) @@ -129,7 +129,7 @@ var _ = Describe("Received Packet Handler", func() { Expect(handler.ReceivedPacket(3, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Return(protocol.PacketNumber(2)) Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)).To(Succeed()) - ack = handler.GetAckFrame(protocol.Encryption1RTT) + ack = handler.GetAckFrame(protocol.Encryption1RTT, true) Expect(ack).ToNot(BeNil()) Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(2))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4))) diff --git a/internal/mocks/ackhandler/received_packet_handler.go b/internal/mocks/ackhandler/received_packet_handler.go index 064c62b9..6362cec1 100644 --- a/internal/mocks/ackhandler/received_packet_handler.go +++ b/internal/mocks/ackhandler/received_packet_handler.go @@ -49,17 +49,17 @@ func (mr *MockReceivedPacketHandlerMockRecorder) DropPackets(arg0 interface{}) * } // GetAckFrame mocks base method -func (m *MockReceivedPacketHandler) GetAckFrame(arg0 protocol.EncryptionLevel) *wire.AckFrame { +func (m *MockReceivedPacketHandler) GetAckFrame(arg0 protocol.EncryptionLevel, arg1 bool) *wire.AckFrame { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAckFrame", arg0) + ret := m.ctrl.Call(m, "GetAckFrame", arg0, arg1) ret0, _ := ret[0].(*wire.AckFrame) return ret0 } // GetAckFrame indicates an expected call of GetAckFrame -func (mr *MockReceivedPacketHandlerMockRecorder) GetAckFrame(arg0 interface{}) *gomock.Call { +func (mr *MockReceivedPacketHandlerMockRecorder) GetAckFrame(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockReceivedPacketHandler)(nil).GetAckFrame), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockReceivedPacketHandler)(nil).GetAckFrame), arg0, arg1) } // GetAlarmTimeout mocks base method diff --git a/mock_ack_frame_source_test.go b/mock_ack_frame_source_test.go index c088a947..528719a0 100644 --- a/mock_ack_frame_source_test.go +++ b/mock_ack_frame_source_test.go @@ -36,15 +36,15 @@ func (m *MockAckFrameSource) EXPECT() *MockAckFrameSourceMockRecorder { } // GetAckFrame mocks base method -func (m *MockAckFrameSource) GetAckFrame(arg0 protocol.EncryptionLevel) *wire.AckFrame { +func (m *MockAckFrameSource) GetAckFrame(arg0 protocol.EncryptionLevel, arg1 bool) *wire.AckFrame { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAckFrame", arg0) + ret := m.ctrl.Call(m, "GetAckFrame", arg0, arg1) ret0, _ := ret[0].(*wire.AckFrame) return ret0 } // GetAckFrame indicates an expected call of GetAckFrame -func (mr *MockAckFrameSourceMockRecorder) GetAckFrame(arg0 interface{}) *gomock.Call { +func (mr *MockAckFrameSourceMockRecorder) GetAckFrame(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockAckFrameSource)(nil).GetAckFrame), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockAckFrameSource)(nil).GetAckFrame), arg0, arg1) } diff --git a/mock_frame_source_test.go b/mock_frame_source_test.go index 24693286..56407b83 100644 --- a/mock_frame_source_test.go +++ b/mock_frame_source_test.go @@ -64,3 +64,17 @@ func (mr *MockFrameSourceMockRecorder) AppendStreamFrames(arg0, arg1 interface{} mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppendStreamFrames", reflect.TypeOf((*MockFrameSource)(nil).AppendStreamFrames), arg0, arg1) } + +// HasData mocks base method +func (m *MockFrameSource) HasData() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasData") + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasData indicates an expected call of HasData +func (mr *MockFrameSourceMockRecorder) HasData() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasData", reflect.TypeOf((*MockFrameSource)(nil).HasData)) +} diff --git a/packet_packer.go b/packet_packer.go index 92a771c1..6606e447 100644 --- a/packet_packer.go +++ b/packet_packer.go @@ -135,12 +135,13 @@ 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) } type ackFrameSource interface { - GetAckFrame(protocol.EncryptionLevel) *wire.AckFrame + GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame } type packetPacker struct { @@ -279,18 +280,18 @@ func (p *packetPacker) MaybePackAckPacket(handshakeConfirmed bool) (*packedPacke var encLevel protocol.EncryptionLevel var ack *wire.AckFrame if !handshakeConfirmed { - ack = p.acks.GetAckFrame(protocol.EncryptionInitial) + ack = p.acks.GetAckFrame(protocol.EncryptionInitial, true) if ack != nil { encLevel = protocol.EncryptionInitial } else { - ack = p.acks.GetAckFrame(protocol.EncryptionHandshake) + ack = p.acks.GetAckFrame(protocol.EncryptionHandshake, true) if ack != nil { encLevel = protocol.EncryptionHandshake } } } if ack == nil { - ack = p.acks.GetAckFrame(protocol.Encryption1RTT) + ack = p.acks.GetAckFrame(protocol.Encryption1RTT, true) if ack == nil { return nil, nil } @@ -431,11 +432,12 @@ func (p *packetPacker) maybeAppendCryptoPacket(buffer *packetBuffer, maxPacketSi } } + hasData := s.HasData() var ack *wire.AckFrame if encLevel != protocol.EncryptionHandshake || buffer.Len() == 0 { - ack = p.acks.GetAckFrame(encLevel) + ack = p.acks.GetAckFrame(encLevel, !hasRetransmission && !hasData) } - if !s.HasData() && !hasRetransmission && ack == nil { + if !hasData && !hasRetransmission && ack == nil { // nothing to send return nil, nil } @@ -499,7 +501,7 @@ func (p *packetPacker) maybeAppendAppDataPacket(buffer *packetBuffer, maxPacketS headerLen := header.GetLength(p.version) maxSize := maxPacketSize - buffer.Len() - protocol.ByteCount(sealer.Overhead()) - headerLen - payload := p.composeNextPacket(maxSize, encLevel != protocol.Encryption0RTT && buffer.Len() == 0) + payload := p.composeNextPacket(maxSize, encLevel == protocol.Encryption1RTT && buffer.Len() == 0) // check if we have anything to send if len(payload.frames) == 0 && payload.ack == nil { @@ -523,35 +525,44 @@ func (p *packetPacker) maybeAppendAppDataPacket(buffer *packetBuffer, maxPacketS func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount, ackAllowed bool) payload { var payload payload - var ack *wire.AckFrame + hasData := p.framer.HasData() + hasRetransmission := p.retransmissionQueue.HasAppData() if ackAllowed { - ack = p.acks.GetAckFrame(protocol.Encryption1RTT) + ack = p.acks.GetAckFrame(protocol.Encryption1RTT, !hasRetransmission && !hasData) if ack != nil { payload.ack = ack payload.length += ack.Length(p.version) } } - for { - remainingLen := maxFrameSize - payload.length - if remainingLen < protocol.MinStreamFrameSize { - break - } - f := p.retransmissionQueue.GetAppDataFrame(remainingLen) - if f == nil { - break - } - payload.frames = append(payload.frames, ackhandler.Frame{Frame: f}) - payload.length += f.Length(p.version) + if ack == nil && !hasData && !hasRetransmission { + return payload } - var lengthAdded protocol.ByteCount - payload.frames, lengthAdded = p.framer.AppendControlFrames(payload.frames, maxFrameSize-payload.length) - payload.length += lengthAdded + if hasRetransmission { + for { + remainingLen := maxFrameSize - payload.length + if remainingLen < protocol.MinStreamFrameSize { + break + } + f := p.retransmissionQueue.GetAppDataFrame(remainingLen) + if f == nil { + break + } + payload.frames = append(payload.frames, ackhandler.Frame{Frame: f}) + payload.length += f.Length(p.version) + } + } - payload.frames, lengthAdded = p.framer.AppendStreamFrames(payload.frames, maxFrameSize-payload.length) - payload.length += lengthAdded + if hasData { + var lengthAdded protocol.ByteCount + payload.frames, lengthAdded = p.framer.AppendControlFrames(payload.frames, maxFrameSize-payload.length) + payload.length += lengthAdded + + payload.frames, lengthAdded = p.framer.AppendStreamFrames(payload.frames, maxFrameSize-payload.length) + payload.length += lengthAdded + } return payload } diff --git a/packet_packer_test.go b/packet_packer_test.go index 69aacaba..97fa328a 100644 --- a/packet_packer_test.go +++ b/packet_packer_test.go @@ -167,12 +167,13 @@ var _ = Describe("Packet packer", func() { } }), ) + framer.EXPECT().HasData().Return(true) sealingManager.EXPECT().GetInitialSealer().Return(nil, nil) sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil) sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendControlFrames() f := &wire.StreamFrame{Data: []byte{0xde, 0xca, 0xfb, 0xad}} expectAppendStreamFrames(ackhandler.Frame{Frame: f}) @@ -205,9 +206,9 @@ var _ = Describe("Packet packer", func() { Context("packing ACK packets", func() { It("doesn't pack a packet if there's no ACK to send", func() { - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true) p, err := packer.MaybePackAckPacket(false) Expect(err).ToNot(HaveOccurred()) Expect(p).To(BeNil()) @@ -218,8 +219,8 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42)) sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}} - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).Return(ack) p, err := packer.MaybePackAckPacket(false) Expect(err).NotTo(HaveOccurred()) Expect(p).ToNot(BeNil()) @@ -232,7 +233,7 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42)) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}} - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack) p, err := packer.MaybePackAckPacket(true) Expect(err).NotTo(HaveOccurred()) Expect(p).ToNot(BeNil()) @@ -248,10 +249,10 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil).AnyTimes() sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable).AnyTimes() initialStream.EXPECT().HasData().AnyTimes() - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial).AnyTimes() + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).AnyTimes() handshakeStream.EXPECT().HasData().AnyTimes() - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).AnyTimes() - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).AnyTimes() + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).AnyTimes() + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).AnyTimes() }) It("packs a 0-RTT packet", func() { @@ -259,6 +260,7 @@ var _ = Describe("Packet packer", func() { 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{ByteOffset: 0x1337}} + framer.EXPECT().HasData().Return(true) framer.EXPECT().AppendControlFrames(nil, gomock.Any()).DoAndReturn(func(frames []ackhandler.Frame, _ protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount) { return append(frames, cf), cf.Length(packer.version) }) @@ -422,20 +424,12 @@ var _ = Describe("Packet packer", func() { }) Context("packing normal packets", func() { - BeforeEach(func() { - initialStream.EXPECT().HasData().AnyTimes() - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial).AnyTimes() - handshakeStream.EXPECT().HasData().AnyTimes() - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).AnyTimes() - }) - It("returns nil when no packet is queued", func() { pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) // don't expect any calls to PopPacketNumber sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) - framer.EXPECT().AppendControlFrames(nil, gomock.Any()) - framer.EXPECT().AppendStreamFrames(nil, gomock.Any()) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true) + framer.EXPECT().HasData() p, err := packer.PackPacket() Expect(p).To(BeNil()) Expect(err).ToNot(HaveOccurred()) @@ -445,7 +439,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendControlFrames() f := &wire.StreamFrame{ StreamID: 5, @@ -465,7 +460,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendControlFrames() expectAppendStreamFrames(ackhandler.Frame{Frame: &wire.StreamFrame{ StreamID: 5, @@ -480,10 +476,9 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42)) ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 42, Smallest: 1}}} - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(ack) + framer.EXPECT().HasData() + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - expectAppendControlFrames() - expectAppendStreamFrames() p, err := packer.PackPacket() Expect(err).NotTo(HaveOccurred()) Expect(p).ToNot(BeNil()) @@ -494,7 +489,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) frames := []ackhandler.Frame{ {Frame: &wire.ResetStreamFrame{}}, {Frame: &wire.MaxDataFrame{}}, @@ -511,7 +507,8 @@ var _ = Describe("Packet packer", func() { It("accounts for the space consumed by control frames", func() { pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + 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) { @@ -535,6 +532,8 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(sealer, nil) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) packer.retransmissionQueue.AddHandshake(&wire.PingFrame{}) + handshakeStream.EXPECT().HasData() + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) packet, err := packer.PackCoalescedPacket(protocol.MaxByteCount) Expect(err).ToNot(HaveOccurred()) Expect(packet).ToNot(BeNil()) @@ -573,7 +572,8 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42)) sealer := getSealer() sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendControlFrames() expectAppendStreamFrames(ackhandler.Frame{Frame: f}) packet, err := packer.PackPacket() @@ -622,7 +622,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendControlFrames() expectAppendStreamFrames(ackhandler.Frame{Frame: f1}, ackhandler.Frame{Frame: f2}, ackhandler.Frame{Frame: f3}) p, err := packer.PackPacket() @@ -640,7 +641,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) expectAppendControlFrames() expectAppendStreamFrames() p, err := packer.PackPacket() @@ -656,7 +658,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) expectAppendControlFrames() expectAppendStreamFrames() p, err := packer.PackPacket() @@ -667,7 +670,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}) expectAppendControlFrames() expectAppendStreamFrames() p, err = packer.PackPacket() @@ -682,9 +686,10 @@ var _ = Describe("Packet packer", func() { // nothing to send pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) + framer.EXPECT().HasData().Return(true) expectAppendControlFrames() expectAppendStreamFrames() - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) p, err := packer.PackPacket() Expect(err).ToNot(HaveOccurred()) Expect(p).To(BeNil()) @@ -694,8 +699,9 @@ var _ = Describe("Packet packer", 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) + framer.EXPECT().HasData().Return(true) ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}} - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(ack) p, err = packer.PackPacket() Expect(err).ToNot(HaveOccurred()) Expect(p.ack).To(Equal(ack)) @@ -707,7 +713,8 @@ var _ = Describe("Packet packer", 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) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) expectAppendStreamFrames() expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}}) p, err := packer.PackPacket() @@ -721,7 +728,8 @@ var _ = Describe("Packet packer", func() { It("sets the maximum packet size", func() { pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).Times(2) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Times(2) + 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) { initialMaxPacketSize = maxLen @@ -746,7 +754,8 @@ var _ = Describe("Packet packer", func() { It("doesn't increase the max packet size", func() { pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).Times(2) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).Times(2) + 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) { initialMaxPacketSize = maxLen @@ -778,7 +787,7 @@ var _ = Describe("Packet packer", func() { Offset: 0x1337, Data: []byte("foobar"), } - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData().Return(true).AnyTimes() initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) @@ -795,8 +804,8 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42)) sealingManager.EXPECT().GetInitialSealer().Return(mocks.NewMockShortHeaderSealer(mockCtrl), nil) sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) initialStream.EXPECT().HasData() handshakeStream.EXPECT().HasData().Return(true).Times(2) handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame { @@ -822,7 +831,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) // don't EXPECT any calls for a Handshake ACK frame initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame { @@ -860,7 +869,8 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get0RTTSealer().Return(getSealer(), nil) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) // don't EXPECT any calls for a Handshake ACK frame initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame { @@ -895,7 +905,8 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetInitialSealer().Return(nil, handshake.ErrKeysDropped) sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) + framer.EXPECT().HasData().Return(true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) // don't EXPECT any calls for a 1-RTT ACK frame handshakeStream.EXPECT().HasData().Return(true).Times(2) handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame { @@ -926,7 +937,7 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24)) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) // don't EXPECT any calls to GetHandshakeSealer and Get1RTTSealer - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame { s := size - protocol.MinCoalescedPacketSize @@ -955,7 +966,7 @@ var _ = Describe("Packet packer", func() { pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24)) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) // don't EXPECT any calls to GetHandshakeSealer and Get1RTTSealer - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(s protocol.ByteCount) *wire.CryptoFrame { f := &wire.CryptoFrame{Offset: 0x1337} @@ -979,7 +990,8 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) oneRTTSealer := getSealer() sealingManager.EXPECT().Get1RTTSealer().Return(oneRTTSealer, nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) + framer.EXPECT().HasData().Return(true) handshakeStream.EXPECT().HasData().Return(true).Times(2) handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(&wire.CryptoFrame{ Offset: 0x1337, @@ -999,6 +1011,44 @@ var _ = Describe("Packet packer", func() { Expect(appDataSize).To(Equal(size - p.packets[0].length - p.packets[1].header.GetLength(packer.version) - protocol.ByteCount(oneRTTSealer.Overhead()))) }) + It("pads if payload length + packet number length is smaller than 4, for Long Header packets", func() { + pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen1) + pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42)) + sealer := getSealer() + sealingManager.EXPECT().GetInitialSealer().Return(nil, handshake.ErrKeysDropped) + sealingManager.EXPECT().GetHandshakeSealer().Return(sealer, nil) + sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) + packer.retransmissionQueue.AddHandshake(&wire.PingFrame{}) + handshakeStream.EXPECT().HasData() + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) + packet, err := packer.PackCoalescedPacket(protocol.MaxByteCount) + Expect(err).ToNot(HaveOccurred()) + Expect(packet).ToNot(BeNil()) + Expect(packet.packets).To(HaveLen(1)) + // cut off the tag that the mock sealer added + // packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())] + hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, len(packer.getDestConnID())) + Expect(err).ToNot(HaveOccurred()) + r := bytes.NewReader(packet.buffer.Data) + extHdr, err := hdr.ParseExtended(r, packer.version) + Expect(err).ToNot(HaveOccurred()) + Expect(extHdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen1)) + Expect(r.Len()).To(Equal(4 - 1 /* packet number length */ + sealer.Overhead())) + // the first bytes of the payload should be a 2 PADDING frames... + firstPayloadByte, err := r.ReadByte() + Expect(err).ToNot(HaveOccurred()) + Expect(firstPayloadByte).To(Equal(byte(0))) + secondPayloadByte, err := r.ReadByte() + Expect(err).ToNot(HaveOccurred()) + Expect(secondPayloadByte).To(Equal(byte(0))) + // ... followed by the PING + frameParser := wire.NewFrameParser(packer.version) + frame, err := frameParser.ParseNext(r, protocol.Encryption1RTT) + Expect(err).ToNot(HaveOccurred()) + Expect(frame).To(BeAssignableToTypeOf(&wire.PingFrame{})) + Expect(r.Len()).To(Equal(sealer.Overhead())) + }) + It("adds retransmissions", func() { f := &wire.CryptoFrame{Data: []byte("Initial")} retransmissionQueue.AddInitial(f) @@ -1008,7 +1058,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData() p, err := packer.PackCoalescedPacket(protocol.MaxByteCount) Expect(err).ToNot(HaveOccurred()) @@ -1021,7 +1071,7 @@ var _ = Describe("Packet packer", func() { It("sends an Initial packet containing only an ACK", func() { ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 20}}} - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).Return(ack) initialStream.EXPECT().HasData().Times(2) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) @@ -1039,7 +1089,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) initialStream.EXPECT().HasData() - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) p, err := packer.PackCoalescedPacket(protocol.MaxByteCount) Expect(err).ToNot(HaveOccurred()) Expect(p).To(BeNil()) @@ -1047,8 +1097,8 @@ var _ = Describe("Packet packer", func() { It("sends a Handshake packet containing only an ACK", func() { ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 20}}} - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).Return(ack) initialStream.EXPECT().HasData() handshakeStream.EXPECT().HasData().Times(2) sealingManager.EXPECT().GetInitialSealer().Return(mocks.NewMockShortHeaderSealer(mockCtrl), nil) @@ -1072,7 +1122,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f) packer.perspective = protocol.PerspectiveClient @@ -1095,7 +1145,7 @@ var _ = Describe("Packet packer", func() { sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial).Return(ack) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false).Return(ack) initialStream.EXPECT().HasData().Return(true).Times(2) initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f) packer.version = protocol.VersionTLS @@ -1114,7 +1164,7 @@ var _ = Describe("Packet packer", func() { f := &wire.CryptoFrame{Data: []byte("Initial")} retransmissionQueue.AddInitial(f) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData() pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42)) @@ -1134,7 +1184,7 @@ var _ = Describe("Packet packer", func() { f := &wire.CryptoFrame{Data: []byte("Initial")} retransmissionQueue.AddInitial(f) sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false) initialStream.EXPECT().HasData() pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42)) @@ -1152,7 +1202,7 @@ var _ = Describe("Packet packer", func() { f := &wire.CryptoFrame{Data: []byte("Handshake")} retransmissionQueue.AddHandshake(f) sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake) + ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false) handshakeStream.EXPECT().HasData() pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42)) @@ -1170,9 +1220,10 @@ var _ = Describe("Packet packer", func() { f := &wire.StreamFrame{Data: []byte("1-RTT")} retransmissionQueue.AddInitial(f) sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false) pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42)) + framer.EXPECT().HasData().Return(true) expectAppendControlFrames() expectAppendStreamFrames(ackhandler.Frame{Frame: f}) @@ -1186,10 +1237,9 @@ var _ = Describe("Packet packer", func() { It("returns nil if there's no probe data to send", func() { sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil) - ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT) + ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true) pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2) - expectAppendControlFrames() - expectAppendStreamFrames() + framer.EXPECT().HasData() packet, err := packer.MaybePackProbePacket(protocol.Encryption1RTT) Expect(err).ToNot(HaveOccurred())