mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
bundle ACK frames when packing a packet
This commit is contained in:
parent
fa381fffa0
commit
9177500096
8 changed files with 187 additions and 112 deletions
|
@ -68,5 +68,5 @@ type ReceivedPacketHandler interface {
|
||||||
DropPackets(protocol.EncryptionLevel)
|
DropPackets(protocol.EncryptionLevel)
|
||||||
|
|
||||||
GetAlarmTimeout() time.Time
|
GetAlarmTimeout() time.Time
|
||||||
GetAckFrame(protocol.EncryptionLevel) *wire.AckFrame
|
GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,20 +113,20 @@ func (h *receivedPacketHandler) GetAlarmTimeout() time.Time {
|
||||||
return utils.MinNonZeroTime(utils.MinNonZeroTime(initialAlarm, handshakeAlarm), oneRTTAlarm)
|
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
|
var ack *wire.AckFrame
|
||||||
switch encLevel {
|
switch encLevel {
|
||||||
case protocol.EncryptionInitial:
|
case protocol.EncryptionInitial:
|
||||||
if h.initialPackets != nil {
|
if h.initialPackets != nil {
|
||||||
ack = h.initialPackets.GetAckFrame(true)
|
ack = h.initialPackets.GetAckFrame(onlyIfQueued)
|
||||||
}
|
}
|
||||||
case protocol.EncryptionHandshake:
|
case protocol.EncryptionHandshake:
|
||||||
if h.handshakePackets != nil {
|
if h.handshakePackets != nil {
|
||||||
ack = h.handshakePackets.GetAckFrame(true)
|
ack = h.handshakePackets.GetAckFrame(onlyIfQueued)
|
||||||
}
|
}
|
||||||
case protocol.Encryption1RTT:
|
case protocol.Encryption1RTT:
|
||||||
// 0-RTT packets can't contain ACK frames
|
// 0-RTT packets can't contain ACK frames
|
||||||
return h.appDataPackets.GetAckFrame(true)
|
return h.appDataPackets.GetAckFrame(onlyIfQueued)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,17 +40,17 @@ var _ = Describe("Received Packet Handler", func() {
|
||||||
Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, 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).ToNot(BeNil())
|
||||||
Expect(initialAck.AckRanges).To(HaveLen(1))
|
Expect(initialAck.AckRanges).To(HaveLen(1))
|
||||||
Expect(initialAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3}))
|
Expect(initialAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3}))
|
||||||
Expect(initialAck.DelayTime).To(BeZero())
|
Expect(initialAck.DelayTime).To(BeZero())
|
||||||
handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake)
|
handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake, true)
|
||||||
Expect(handshakeAck).ToNot(BeNil())
|
Expect(handshakeAck).ToNot(BeNil())
|
||||||
Expect(handshakeAck.AckRanges).To(HaveLen(1))
|
Expect(handshakeAck.AckRanges).To(HaveLen(1))
|
||||||
Expect(handshakeAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 1, Largest: 2}))
|
Expect(handshakeAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 1, Largest: 2}))
|
||||||
Expect(handshakeAck.DelayTime).To(BeZero())
|
Expect(handshakeAck.DelayTime).To(BeZero())
|
||||||
oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT)
|
oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT, true)
|
||||||
Expect(oneRTTAck).ToNot(BeNil())
|
Expect(oneRTTAck).ToNot(BeNil())
|
||||||
Expect(oneRTTAck.AckRanges).To(HaveLen(1))
|
Expect(oneRTTAck.AckRanges).To(HaveLen(1))
|
||||||
Expect(oneRTTAck.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 4, Largest: 5}))
|
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)
|
sendTime := time.Now().Add(-time.Second)
|
||||||
Expect(handler.ReceivedPacket(2, protocol.Encryption0RTT, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(2, protocol.Encryption0RTT, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(3, protocol.Encryption1RTT, 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).ToNot(BeNil())
|
||||||
Expect(ack.AckRanges).To(HaveLen(1))
|
Expect(ack.AckRanges).To(HaveLen(1))
|
||||||
Expect(ack.AckRanges[0]).To(Equal(wire.AckRange{Smallest: 2, Largest: 3}))
|
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)
|
sendTime := time.Now().Add(-time.Second)
|
||||||
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, 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)
|
handler.DropPackets(protocol.EncryptionInitial)
|
||||||
Expect(handler.GetAckFrame(protocol.EncryptionInitial)).To(BeNil())
|
Expect(handler.GetAckFrame(protocol.EncryptionInitial, true)).To(BeNil())
|
||||||
Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).ToNot(BeNil())
|
Expect(handler.GetAckFrame(protocol.EncryptionHandshake, true)).ToNot(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("drops Handshake packets", func() {
|
It("drops Handshake packets", func() {
|
||||||
|
@ -105,10 +105,10 @@ var _ = Describe("Received Packet Handler", func() {
|
||||||
sendTime := time.Now().Add(-time.Second)
|
sendTime := time.Now().Add(-time.Second)
|
||||||
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(2, protocol.Encryption1RTT, 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)
|
handler.DropPackets(protocol.EncryptionInitial)
|
||||||
Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).To(BeNil())
|
Expect(handler.GetAckFrame(protocol.EncryptionHandshake, true)).To(BeNil())
|
||||||
Expect(handler.GetAckFrame(protocol.Encryption1RTT)).ToNot(BeNil())
|
Expect(handler.GetAckFrame(protocol.Encryption1RTT, true)).ToNot(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("does nothing when dropping 0-RTT packets", func() {
|
It("does nothing when dropping 0-RTT packets", func() {
|
||||||
|
@ -121,7 +121,7 @@ var _ = Describe("Received Packet Handler", func() {
|
||||||
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Times(2)
|
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Times(2)
|
||||||
Expect(handler.ReceivedPacket(1, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
|
Expect(handler.ReceivedPacket(1, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
|
||||||
Expect(handler.ReceivedPacket(2, 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).ToNot(BeNil())
|
||||||
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
|
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
|
||||||
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2)))
|
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())
|
Expect(handler.ReceivedPacket(3, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
|
||||||
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Return(protocol.PacketNumber(2))
|
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Return(protocol.PacketNumber(2))
|
||||||
Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
|
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).ToNot(BeNil())
|
||||||
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(2)))
|
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(2)))
|
||||||
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
|
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
|
||||||
|
|
|
@ -49,17 +49,17 @@ func (mr *MockReceivedPacketHandlerMockRecorder) DropPackets(arg0 interface{}) *
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAckFrame mocks base method
|
// 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()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "GetAckFrame", arg0)
|
ret := m.ctrl.Call(m, "GetAckFrame", arg0, arg1)
|
||||||
ret0, _ := ret[0].(*wire.AckFrame)
|
ret0, _ := ret[0].(*wire.AckFrame)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAckFrame indicates an expected call of GetAckFrame
|
// 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()
|
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
|
// GetAlarmTimeout mocks base method
|
||||||
|
|
|
@ -36,15 +36,15 @@ func (m *MockAckFrameSource) EXPECT() *MockAckFrameSourceMockRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAckFrame mocks base method
|
// 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()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "GetAckFrame", arg0)
|
ret := m.ctrl.Call(m, "GetAckFrame", arg0, arg1)
|
||||||
ret0, _ := ret[0].(*wire.AckFrame)
|
ret0, _ := ret[0].(*wire.AckFrame)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAckFrame indicates an expected call of GetAckFrame
|
// 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()
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,3 +64,17 @@ func (mr *MockFrameSourceMockRecorder) AppendStreamFrames(arg0, arg1 interface{}
|
||||||
mr.mock.ctrl.T.Helper()
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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))
|
||||||
|
}
|
||||||
|
|
|
@ -135,12 +135,13 @@ type sealingManager interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type frameSource interface {
|
type frameSource interface {
|
||||||
|
HasData() bool
|
||||||
AppendStreamFrames([]ackhandler.Frame, protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount)
|
AppendStreamFrames([]ackhandler.Frame, protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount)
|
||||||
AppendControlFrames([]ackhandler.Frame, protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount)
|
AppendControlFrames([]ackhandler.Frame, protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ackFrameSource interface {
|
type ackFrameSource interface {
|
||||||
GetAckFrame(protocol.EncryptionLevel) *wire.AckFrame
|
GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
type packetPacker struct {
|
type packetPacker struct {
|
||||||
|
@ -279,18 +280,18 @@ func (p *packetPacker) MaybePackAckPacket(handshakeConfirmed bool) (*packedPacke
|
||||||
var encLevel protocol.EncryptionLevel
|
var encLevel protocol.EncryptionLevel
|
||||||
var ack *wire.AckFrame
|
var ack *wire.AckFrame
|
||||||
if !handshakeConfirmed {
|
if !handshakeConfirmed {
|
||||||
ack = p.acks.GetAckFrame(protocol.EncryptionInitial)
|
ack = p.acks.GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
if ack != nil {
|
if ack != nil {
|
||||||
encLevel = protocol.EncryptionInitial
|
encLevel = protocol.EncryptionInitial
|
||||||
} else {
|
} else {
|
||||||
ack = p.acks.GetAckFrame(protocol.EncryptionHandshake)
|
ack = p.acks.GetAckFrame(protocol.EncryptionHandshake, true)
|
||||||
if ack != nil {
|
if ack != nil {
|
||||||
encLevel = protocol.EncryptionHandshake
|
encLevel = protocol.EncryptionHandshake
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ack == nil {
|
if ack == nil {
|
||||||
ack = p.acks.GetAckFrame(protocol.Encryption1RTT)
|
ack = p.acks.GetAckFrame(protocol.Encryption1RTT, true)
|
||||||
if ack == nil {
|
if ack == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -431,11 +432,12 @@ func (p *packetPacker) maybeAppendCryptoPacket(buffer *packetBuffer, maxPacketSi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasData := s.HasData()
|
||||||
var ack *wire.AckFrame
|
var ack *wire.AckFrame
|
||||||
if encLevel != protocol.EncryptionHandshake || buffer.Len() == 0 {
|
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
|
// nothing to send
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -499,7 +501,7 @@ func (p *packetPacker) maybeAppendAppDataPacket(buffer *packetBuffer, maxPacketS
|
||||||
headerLen := header.GetLength(p.version)
|
headerLen := header.GetLength(p.version)
|
||||||
|
|
||||||
maxSize := maxPacketSize - buffer.Len() - protocol.ByteCount(sealer.Overhead()) - headerLen
|
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
|
// check if we have anything to send
|
||||||
if len(payload.frames) == 0 && payload.ack == nil {
|
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 {
|
func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount, ackAllowed bool) payload {
|
||||||
var payload payload
|
var payload payload
|
||||||
|
|
||||||
var ack *wire.AckFrame
|
var ack *wire.AckFrame
|
||||||
|
hasData := p.framer.HasData()
|
||||||
|
hasRetransmission := p.retransmissionQueue.HasAppData()
|
||||||
if ackAllowed {
|
if ackAllowed {
|
||||||
ack = p.acks.GetAckFrame(protocol.Encryption1RTT)
|
ack = p.acks.GetAckFrame(protocol.Encryption1RTT, !hasRetransmission && !hasData)
|
||||||
if ack != nil {
|
if ack != nil {
|
||||||
payload.ack = ack
|
payload.ack = ack
|
||||||
payload.length += ack.Length(p.version)
|
payload.length += ack.Length(p.version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
if ack == nil && !hasData && !hasRetransmission {
|
||||||
remainingLen := maxFrameSize - payload.length
|
return payload
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lengthAdded protocol.ByteCount
|
if hasRetransmission {
|
||||||
payload.frames, lengthAdded = p.framer.AppendControlFrames(payload.frames, maxFrameSize-payload.length)
|
for {
|
||||||
payload.length += lengthAdded
|
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)
|
if hasData {
|
||||||
payload.length += lengthAdded
|
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
|
return payload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,12 +167,13 @@ var _ = Describe("Packet packer", func() {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
framer.EXPECT().HasData().Return(true)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(nil, nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(nil, nil)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
f := &wire.StreamFrame{Data: []byte{0xde, 0xca, 0xfb, 0xad}}
|
f := &wire.StreamFrame{Data: []byte{0xde, 0xca, 0xfb, 0xad}}
|
||||||
expectAppendStreamFrames(ackhandler.Frame{Frame: f})
|
expectAppendStreamFrames(ackhandler.Frame{Frame: f})
|
||||||
|
@ -205,9 +206,9 @@ var _ = Describe("Packet packer", func() {
|
||||||
|
|
||||||
Context("packing ACK packets", func() {
|
Context("packing ACK packets", func() {
|
||||||
It("doesn't pack a packet if there's no ACK to send", func() {
|
It("doesn't pack a packet if there's no ACK to send", func() {
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||||
p, err := packer.MaybePackAckPacket(false)
|
p, err := packer.MaybePackAckPacket(false)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p).To(BeNil())
|
Expect(p).To(BeNil())
|
||||||
|
@ -218,8 +219,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).Return(ack)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).Return(ack)
|
||||||
p, err := packer.MaybePackAckPacket(false)
|
p, err := packer.MaybePackAckPacket(false)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(p).ToNot(BeNil())
|
Expect(p).ToNot(BeNil())
|
||||||
|
@ -232,7 +233,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
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)
|
p, err := packer.MaybePackAckPacket(true)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(p).ToNot(BeNil())
|
Expect(p).ToNot(BeNil())
|
||||||
|
@ -248,10 +249,10 @@ var _ = Describe("Packet packer", func() {
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil).AnyTimes()
|
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, nil).AnyTimes()
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable).AnyTimes()
|
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable).AnyTimes()
|
||||||
initialStream.EXPECT().HasData().AnyTimes()
|
initialStream.EXPECT().HasData().AnyTimes()
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial).AnyTimes()
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).AnyTimes()
|
||||||
handshakeStream.EXPECT().HasData().AnyTimes()
|
handshakeStream.EXPECT().HasData().AnyTimes()
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).AnyTimes()
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).AnyTimes()
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT).AnyTimes()
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).AnyTimes()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("packs a 0-RTT packet", func() {
|
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().PeekPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42))
|
||||||
cf := ackhandler.Frame{Frame: &wire.MaxDataFrame{ByteOffset: 0x1337}}
|
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) {
|
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)
|
return append(frames, cf), cf.Length(packer.version)
|
||||||
})
|
})
|
||||||
|
@ -422,20 +424,12 @@ var _ = Describe("Packet packer", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("packing normal packets", 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() {
|
It("returns nil when no packet is queued", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
// don't expect any calls to PopPacketNumber
|
// don't expect any calls to PopPacketNumber
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||||
framer.EXPECT().AppendControlFrames(nil, gomock.Any())
|
framer.EXPECT().HasData()
|
||||||
framer.EXPECT().AppendStreamFrames(nil, gomock.Any())
|
|
||||||
p, err := packer.PackPacket()
|
p, err := packer.PackPacket()
|
||||||
Expect(p).To(BeNil())
|
Expect(p).To(BeNil())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
framer.EXPECT().HasData().Return(true)
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
f := &wire.StreamFrame{
|
f := &wire.StreamFrame{
|
||||||
StreamID: 5,
|
StreamID: 5,
|
||||||
|
@ -465,7 +460,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
framer.EXPECT().HasData().Return(true)
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames(ackhandler.Frame{Frame: &wire.StreamFrame{
|
expectAppendStreamFrames(ackhandler.Frame{Frame: &wire.StreamFrame{
|
||||||
StreamID: 5,
|
StreamID: 5,
|
||||||
|
@ -480,10 +476,9 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 42, Smallest: 1}}}
|
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)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
expectAppendControlFrames()
|
|
||||||
expectAppendStreamFrames()
|
|
||||||
p, err := packer.PackPacket()
|
p, err := packer.PackPacket()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(p).ToNot(BeNil())
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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{
|
frames := []ackhandler.Frame{
|
||||||
{Frame: &wire.ResetStreamFrame{}},
|
{Frame: &wire.ResetStreamFrame{}},
|
||||||
{Frame: &wire.MaxDataFrame{}},
|
{Frame: &wire.MaxDataFrame{}},
|
||||||
|
@ -511,7 +507,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
It("accounts for the space consumed by control frames", func() {
|
It("accounts for the space consumed by control frames", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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
|
var maxSize protocol.ByteCount
|
||||||
gomock.InOrder(
|
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()).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().GetHandshakeSealer().Return(sealer, nil)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
|
packer.retransmissionQueue.AddHandshake(&wire.PingFrame{})
|
||||||
|
handshakeStream.EXPECT().HasData()
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
|
||||||
packet, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
packet, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(packet).ToNot(BeNil())
|
Expect(packet).ToNot(BeNil())
|
||||||
|
@ -573,7 +572,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealer := getSealer()
|
sealer := getSealer()
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
framer.EXPECT().HasData().Return(true)
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames(ackhandler.Frame{Frame: f})
|
expectAppendStreamFrames(ackhandler.Frame{Frame: f})
|
||||||
packet, err := packer.PackPacket()
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
framer.EXPECT().HasData().Return(true)
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames(ackhandler.Frame{Frame: f1}, ackhandler.Frame{Frame: f2}, ackhandler.Frame{Frame: f3})
|
expectAppendStreamFrames(ackhandler.Frame{Frame: f1}, ackhandler.Frame{Frame: f2}, ackhandler.Frame{Frame: f3})
|
||||||
p, err := packer.PackPacket()
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames()
|
expectAppendStreamFrames()
|
||||||
p, err := packer.PackPacket()
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames()
|
expectAppendStreamFrames()
|
||||||
p, err := packer.PackPacket()
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames()
|
expectAppendStreamFrames()
|
||||||
p, err = packer.PackPacket()
|
p, err = packer.PackPacket()
|
||||||
|
@ -682,9 +686,10 @@ var _ = Describe("Packet packer", func() {
|
||||||
// nothing to send
|
// nothing to send
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
|
framer.EXPECT().HasData().Return(true)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames()
|
expectAppendStreamFrames()
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
p, err := packer.PackPacket()
|
p, err := packer.PackPacket()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p).To(BeNil())
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
|
framer.EXPECT().HasData().Return(true)
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
|
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()
|
p, err = packer.PackPacket()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p.ack).To(Equal(ack))
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT)
|
framer.EXPECT().HasData().Return(true)
|
||||||
|
ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||||
expectAppendStreamFrames()
|
expectAppendStreamFrames()
|
||||||
expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}})
|
expectAppendControlFrames(ackhandler.Frame{Frame: &wire.MaxDataFrame{}})
|
||||||
p, err := packer.PackPacket()
|
p, err := packer.PackPacket()
|
||||||
|
@ -721,7 +728,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
It("sets the maximum packet size", func() {
|
It("sets the maximum packet size", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).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
|
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()).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount) {
|
||||||
initialMaxPacketSize = maxLen
|
initialMaxPacketSize = maxLen
|
||||||
|
@ -746,7 +754,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
It("doesn't increase the max packet size", func() {
|
It("doesn't increase the max packet size", func() {
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil).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
|
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()).Do(func(_ []ackhandler.Frame, maxLen protocol.ByteCount) ([]ackhandler.Frame, protocol.ByteCount) {
|
||||||
initialMaxPacketSize = maxLen
|
initialMaxPacketSize = maxLen
|
||||||
|
@ -778,7 +787,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
Offset: 0x1337,
|
Offset: 0x1337,
|
||||||
Data: []byte("foobar"),
|
Data: []byte("foobar"),
|
||||||
}
|
}
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
|
||||||
initialStream.EXPECT().HasData().Return(true).AnyTimes()
|
initialStream.EXPECT().HasData().Return(true).AnyTimes()
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
|
@ -795,8 +804,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(mocks.NewMockShortHeaderSealer(mockCtrl), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(mocks.NewMockShortHeaderSealer(mockCtrl), nil)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
|
||||||
initialStream.EXPECT().HasData()
|
initialStream.EXPECT().HasData()
|
||||||
handshakeStream.EXPECT().HasData().Return(true).Times(2)
|
handshakeStream.EXPECT().HasData().Return(true).Times(2)
|
||||||
handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
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().GetInitialSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
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
|
// don't EXPECT any calls for a Handshake ACK frame
|
||||||
initialStream.EXPECT().HasData().Return(true).Times(2)
|
initialStream.EXPECT().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
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().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get0RTTSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().Get0RTTSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
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
|
// don't EXPECT any calls for a Handshake ACK frame
|
||||||
initialStream.EXPECT().HasData().Return(true).Times(2)
|
initialStream.EXPECT().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
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().GetInitialSealer().Return(nil, handshake.ErrKeysDropped)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().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
|
// don't EXPECT any calls for a 1-RTT ACK frame
|
||||||
handshakeStream.EXPECT().HasData().Return(true).Times(2)
|
handshakeStream.EXPECT().HasData().Return(true).Times(2)
|
||||||
handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
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))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24))
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
// don't EXPECT any calls to GetHandshakeSealer and Get1RTTSealer
|
// 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().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(size protocol.ByteCount) *wire.CryptoFrame {
|
||||||
s := size - protocol.MinCoalescedPacketSize
|
s := size - protocol.MinCoalescedPacketSize
|
||||||
|
@ -955,7 +966,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24))
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
// don't EXPECT any calls to GetHandshakeSealer and Get1RTTSealer
|
// 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().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(s protocol.ByteCount) *wire.CryptoFrame {
|
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).DoAndReturn(func(s protocol.ByteCount) *wire.CryptoFrame {
|
||||||
f := &wire.CryptoFrame{Offset: 0x1337}
|
f := &wire.CryptoFrame{Offset: 0x1337}
|
||||||
|
@ -979,7 +990,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
oneRTTSealer := getSealer()
|
oneRTTSealer := getSealer()
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(oneRTTSealer, nil)
|
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().HasData().Return(true).Times(2)
|
||||||
handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(&wire.CryptoFrame{
|
handshakeStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(&wire.CryptoFrame{
|
||||||
Offset: 0x1337,
|
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())))
|
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() {
|
It("adds retransmissions", func() {
|
||||||
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
||||||
retransmissionQueue.AddInitial(f)
|
retransmissionQueue.AddInitial(f)
|
||||||
|
@ -1008,7 +1058,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().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()
|
initialStream.EXPECT().HasData()
|
||||||
p, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
p, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -1021,7 +1071,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
|
|
||||||
It("sends an Initial packet containing only an ACK", func() {
|
It("sends an Initial packet containing only an ACK", func() {
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 20}}}
|
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)
|
initialStream.EXPECT().HasData().Times(2)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
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().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
initialStream.EXPECT().HasData()
|
initialStream.EXPECT().HasData()
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
p, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
p, err := packer.PackCoalescedPacket(protocol.MaxByteCount)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(p).To(BeNil())
|
Expect(p).To(BeNil())
|
||||||
|
@ -1047,8 +1097,8 @@ var _ = Describe("Packet packer", func() {
|
||||||
|
|
||||||
It("sends a Handshake packet containing only an ACK", func() {
|
It("sends a Handshake packet containing only an ACK", func() {
|
||||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 20}}}
|
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 10, Largest: 20}}}
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake).Return(ack)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true).Return(ack)
|
||||||
initialStream.EXPECT().HasData()
|
initialStream.EXPECT().HasData()
|
||||||
handshakeStream.EXPECT().HasData().Times(2)
|
handshakeStream.EXPECT().HasData().Times(2)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(mocks.NewMockShortHeaderSealer(mockCtrl), nil)
|
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().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().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().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
||||||
packer.perspective = protocol.PerspectiveClient
|
packer.perspective = protocol.PerspectiveClient
|
||||||
|
@ -1095,7 +1145,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().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().HasData().Return(true).Times(2)
|
||||||
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
initialStream.EXPECT().PopCryptoFrame(gomock.Any()).Return(f)
|
||||||
packer.version = protocol.VersionTLS
|
packer.version = protocol.VersionTLS
|
||||||
|
@ -1114,7 +1164,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
||||||
retransmissionQueue.AddInitial(f)
|
retransmissionQueue.AddInitial(f)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
|
||||||
initialStream.EXPECT().HasData()
|
initialStream.EXPECT().HasData()
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
|
||||||
|
@ -1134,7 +1184,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
f := &wire.CryptoFrame{Data: []byte("Initial")}
|
||||||
retransmissionQueue.AddInitial(f)
|
retransmissionQueue.AddInitial(f)
|
||||||
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetInitialSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
|
||||||
initialStream.EXPECT().HasData()
|
initialStream.EXPECT().HasData()
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
|
||||||
|
@ -1152,7 +1202,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
f := &wire.CryptoFrame{Data: []byte("Handshake")}
|
f := &wire.CryptoFrame{Data: []byte("Handshake")}
|
||||||
retransmissionQueue.AddHandshake(f)
|
retransmissionQueue.AddHandshake(f)
|
||||||
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
sealingManager.EXPECT().GetHandshakeSealer().Return(getSealer(), nil)
|
||||||
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake)
|
ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
|
||||||
handshakeStream.EXPECT().HasData()
|
handshakeStream.EXPECT().HasData()
|
||||||
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.EncryptionHandshake).Return(protocol.PacketNumber(0x42))
|
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")}
|
f := &wire.StreamFrame{Data: []byte("1-RTT")}
|
||||||
retransmissionQueue.AddInitial(f)
|
retransmissionQueue.AddInitial(f)
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||||
|
framer.EXPECT().HasData().Return(true)
|
||||||
expectAppendControlFrames()
|
expectAppendControlFrames()
|
||||||
expectAppendStreamFrames(ackhandler.Frame{Frame: f})
|
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() {
|
It("returns nil if there's no probe data to send", func() {
|
||||||
sealingManager.EXPECT().Get1RTTSealer().Return(getSealer(), nil)
|
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)
|
pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||||
expectAppendControlFrames()
|
framer.EXPECT().HasData()
|
||||||
expectAppendStreamFrames()
|
|
||||||
|
|
||||||
packet, err := packer.MaybePackProbePacket(protocol.Encryption1RTT)
|
packet, err := packer.MaybePackProbePacket(protocol.Encryption1RTT)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue