mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
ackhandler: avoid calling time.Now() when generating ACK frame (#4886)
This commit is contained in:
parent
29f98a296c
commit
92dc1970ec
9 changed files with 125 additions and 93 deletions
|
@ -49,5 +49,5 @@ type ReceivedPacketHandler interface {
|
|||
DropPackets(protocol.EncryptionLevel)
|
||||
|
||||
GetAlarmTimeout() time.Time
|
||||
GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame
|
||||
GetAckFrame(_ protocol.EncryptionLevel, now time.Time, onlyIfQueued bool) *wire.AckFrame
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func (h *receivedPacketHandler) GetAlarmTimeout() time.Time {
|
|||
return h.appDataPackets.GetAlarmTimeout()
|
||||
}
|
||||
|
||||
func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame {
|
||||
func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel, now time.Time, onlyIfQueued bool) *wire.AckFrame {
|
||||
//nolint:exhaustive // 0-RTT packets can't contain ACK frames.
|
||||
switch encLevel {
|
||||
case protocol.EncryptionInitial:
|
||||
|
@ -101,7 +101,7 @@ func (h *receivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel, o
|
|||
}
|
||||
return nil
|
||||
case protocol.Encryption1RTT:
|
||||
return h.appDataPackets.GetAckFrame(onlyIfQueued)
|
||||
return h.appDataPackets.GetAckFrame(now, onlyIfQueued)
|
||||
default:
|
||||
// 0-RTT packets can't contain ACK frames
|
||||
return nil
|
||||
|
|
|
@ -17,7 +17,8 @@ func TestGenerateACKsForPacketNumberSpaces(t *testing.T) {
|
|||
sentPackets := NewMockSentPacketTracker(ctrl)
|
||||
handler := newReceivedPacketHandler(sentPackets, utils.DefaultLogger)
|
||||
|
||||
sendTime := time.Now().Add(-time.Second)
|
||||
now := time.Now()
|
||||
sendTime := now.Add(-time.Second)
|
||||
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().AnyTimes()
|
||||
sentPackets.EXPECT().ReceivedPacket(protocol.EncryptionInitial, sendTime).Times(2)
|
||||
sentPackets.EXPECT().ReceivedPacket(protocol.EncryptionHandshake, sendTime).Times(2)
|
||||
|
@ -31,7 +32,7 @@ func TestGenerateACKsForPacketNumberSpaces(t *testing.T) {
|
|||
require.NoError(t, handler.ReceivedPacket(4, protocol.ECNCE, protocol.Encryption1RTT, sendTime, true))
|
||||
|
||||
// Initial
|
||||
initialAck := handler.GetAckFrame(protocol.EncryptionInitial, true)
|
||||
initialAck := handler.GetAckFrame(protocol.EncryptionInitial, now, true)
|
||||
require.NotNil(t, initialAck)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 2, Largest: 3}}, initialAck.AckRanges)
|
||||
require.Zero(t, initialAck.DelayTime)
|
||||
|
@ -40,7 +41,7 @@ func TestGenerateACKsForPacketNumberSpaces(t *testing.T) {
|
|||
require.Zero(t, initialAck.ECNCE)
|
||||
|
||||
// Handshake
|
||||
handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake, true)
|
||||
handshakeAck := handler.GetAckFrame(protocol.EncryptionHandshake, now, true)
|
||||
require.NotNil(t, handshakeAck)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 1, Largest: 2}}, handshakeAck.AckRanges)
|
||||
require.Zero(t, handshakeAck.DelayTime)
|
||||
|
@ -49,10 +50,10 @@ func TestGenerateACKsForPacketNumberSpaces(t *testing.T) {
|
|||
require.Zero(t, handshakeAck.ECNCE)
|
||||
|
||||
// 1-RTT
|
||||
oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT, true)
|
||||
oneRTTAck := handler.GetAckFrame(protocol.Encryption1RTT, now, true)
|
||||
require.NotNil(t, oneRTTAck)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 4, Largest: 5}}, oneRTTAck.AckRanges)
|
||||
require.InDelta(t, time.Second, oneRTTAck.DelayTime, float64(50*time.Millisecond))
|
||||
require.Equal(t, time.Second, oneRTTAck.DelayTime)
|
||||
require.Zero(t, oneRTTAck.ECT0)
|
||||
require.Zero(t, oneRTTAck.ECT1)
|
||||
require.EqualValues(t, 2, oneRTTAck.ECNCE)
|
||||
|
@ -71,7 +72,7 @@ func TestReceive0RTTAnd1RTT(t *testing.T) {
|
|||
require.NoError(t, handler.ReceivedPacket(2, protocol.ECNNon, protocol.Encryption0RTT, sendTime, true))
|
||||
require.NoError(t, handler.ReceivedPacket(3, protocol.ECNNon, protocol.Encryption1RTT, sendTime, true))
|
||||
|
||||
ack := handler.GetAckFrame(protocol.Encryption1RTT, true)
|
||||
ack := handler.GetAckFrame(protocol.Encryption1RTT, time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 2, Largest: 3}}, ack.AckRanges)
|
||||
|
||||
|
@ -95,17 +96,17 @@ func TestDropPackets(t *testing.T) {
|
|||
require.NoError(t, handler.ReceivedPacket(2, protocol.ECNNon, protocol.Encryption1RTT, sendTime, true))
|
||||
|
||||
// Initial
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.EncryptionInitial, true))
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.EncryptionInitial, time.Now(), true))
|
||||
handler.DropPackets(protocol.EncryptionInitial)
|
||||
require.Nil(t, handler.GetAckFrame(protocol.EncryptionInitial, true))
|
||||
require.Nil(t, handler.GetAckFrame(protocol.EncryptionInitial, time.Now(), true))
|
||||
|
||||
// Handshake
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.EncryptionHandshake, true))
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.EncryptionHandshake, time.Now(), true))
|
||||
handler.DropPackets(protocol.EncryptionHandshake)
|
||||
require.Nil(t, handler.GetAckFrame(protocol.EncryptionHandshake, true))
|
||||
require.Nil(t, handler.GetAckFrame(protocol.EncryptionHandshake, time.Now(), true))
|
||||
|
||||
// 1-RTT
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.Encryption1RTT, true))
|
||||
require.NotNil(t, handler.GetAckFrame(protocol.Encryption1RTT, time.Now(), true))
|
||||
|
||||
// 0-RTT is a no-op
|
||||
handler.DropPackets(protocol.Encryption0RTT)
|
||||
|
@ -122,7 +123,7 @@ func TestAckRangePruning(t *testing.T) {
|
|||
require.NoError(t, handler.ReceivedPacket(1, protocol.ECNNon, protocol.Encryption1RTT, sendTime, true))
|
||||
require.NoError(t, handler.ReceivedPacket(2, protocol.ECNNon, protocol.Encryption1RTT, sendTime, true))
|
||||
|
||||
ack := handler.GetAckFrame(protocol.Encryption1RTT, true)
|
||||
ack := handler.GetAckFrame(protocol.Encryption1RTT, time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 1, Largest: 2}}, ack.AckRanges)
|
||||
|
||||
|
@ -130,7 +131,7 @@ func TestAckRangePruning(t *testing.T) {
|
|||
sentPackets.EXPECT().GetLowestPacketNotConfirmedAcked().Return(protocol.PacketNumber(2))
|
||||
require.NoError(t, handler.ReceivedPacket(4, protocol.ECNNon, protocol.Encryption1RTT, sendTime, true))
|
||||
|
||||
ack = handler.GetAckFrame(protocol.Encryption1RTT, true)
|
||||
ack = handler.GetAckFrame(protocol.Encryption1RTT, time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 2, Largest: 4}}, ack.AckRanges)
|
||||
}
|
||||
|
|
|
@ -196,8 +196,7 @@ func (h *appDataReceivedPacketTracker) shouldQueueACK(pn protocol.PacketNumber,
|
|||
return false
|
||||
}
|
||||
|
||||
func (h *appDataReceivedPacketTracker) GetAckFrame(onlyIfQueued bool) *wire.AckFrame {
|
||||
now := time.Now()
|
||||
func (h *appDataReceivedPacketTracker) GetAckFrame(now time.Time, onlyIfQueued bool) *wire.AckFrame {
|
||||
if onlyIfQueued && !h.ackQueued {
|
||||
if h.ackAlarm.IsZero() || h.ackAlarm.After(now) {
|
||||
return nil
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestAppDataReceivedPacketTrackerECN(t *testing.T) {
|
|||
require.NoError(t, tr.ReceivedPacket(pn, protocol.ECNCE, time.Now(), true))
|
||||
pn++
|
||||
}
|
||||
ack := tr.GetAckFrame(false)
|
||||
ack := tr.GetAckFrame(time.Now(), false)
|
||||
require.Equal(t, uint64(1), ack.ECT0)
|
||||
require.Equal(t, uint64(2), ack.ECT1)
|
||||
require.Equal(t, uint64(3), ack.ECNCE)
|
||||
|
@ -73,14 +73,14 @@ func TestAppDataReceivedPacketTrackerAckEverySecondPacket(t *testing.T) {
|
|||
tr := newAppDataReceivedPacketTracker(utils.DefaultLogger)
|
||||
// the first packet is always acknowledged
|
||||
require.NoError(t, tr.ReceivedPacket(0, protocol.ECNNon, time.Now(), true))
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
for p := protocol.PacketNumber(1); p <= 20; p++ {
|
||||
require.NoError(t, tr.ReceivedPacket(p, protocol.ECNNon, time.Now(), true))
|
||||
switch p % 2 {
|
||||
case 0:
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
case 1:
|
||||
require.Nil(t, tr.GetAckFrame(true))
|
||||
require.Nil(t, tr.GetAckFrame(time.Now(), true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,20 +90,20 @@ func TestAppDataReceivedPacketTrackerAlarmTimeout(t *testing.T) {
|
|||
|
||||
// the first packet is always acknowledged
|
||||
require.NoError(t, tr.ReceivedPacket(0, protocol.ECNNon, time.Now(), true))
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
|
||||
now := time.Now()
|
||||
require.NoError(t, tr.ReceivedPacket(1, protocol.ECNNon, now, false))
|
||||
require.Nil(t, tr.GetAckFrame(true))
|
||||
require.Nil(t, tr.GetAckFrame(time.Now(), true))
|
||||
require.Zero(t, tr.GetAlarmTimeout())
|
||||
|
||||
rcvTime := now.Add(10 * time.Millisecond)
|
||||
require.NoError(t, tr.ReceivedPacket(2, protocol.ECNNon, rcvTime, true))
|
||||
require.Equal(t, rcvTime.Add(protocol.MaxAckDelay), tr.GetAlarmTimeout())
|
||||
require.Nil(t, tr.GetAckFrame(true))
|
||||
require.Nil(t, tr.GetAckFrame(time.Now(), true))
|
||||
|
||||
// no timeout after the ACK has been dequeued
|
||||
require.NotNil(t, tr.GetAckFrame(false))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), false))
|
||||
require.Zero(t, tr.GetAlarmTimeout())
|
||||
}
|
||||
|
||||
|
@ -112,10 +112,10 @@ func TestAppDataReceivedPacketTrackerQueuesECNCE(t *testing.T) {
|
|||
|
||||
// the first packet is always acknowledged
|
||||
require.NoError(t, tr.ReceivedPacket(0, protocol.ECNNon, time.Now(), true))
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
|
||||
require.NoError(t, tr.ReceivedPacket(1, protocol.ECNCE, time.Now(), true))
|
||||
ack := tr.GetAckFrame(true)
|
||||
ack := tr.GetAckFrame(time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, protocol.PacketNumber(1), ack.LargestAcked())
|
||||
require.EqualValues(t, 1, ack.ECNCE)
|
||||
|
@ -126,16 +126,16 @@ func TestAppDataReceivedPacketTrackerMissingPackets(t *testing.T) {
|
|||
|
||||
// the first packet is always acknowledged
|
||||
require.NoError(t, tr.ReceivedPacket(0, protocol.ECNNon, time.Now(), true))
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
|
||||
require.NoError(t, tr.ReceivedPacket(5, protocol.ECNNon, time.Now(), true))
|
||||
ack := tr.GetAckFrame(true) // ACK: 0 and 5, missing: 1, 2, 3, 4
|
||||
ack := tr.GetAckFrame(time.Now(), true) // ACK: 0 and 5, missing: 1, 2, 3, 4
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 5, Largest: 5}, {Smallest: 0, Largest: 0}}, ack.AckRanges)
|
||||
|
||||
// now receive one of the missing packets
|
||||
require.NoError(t, tr.ReceivedPacket(3, protocol.ECNNon, time.Now(), true))
|
||||
require.NotNil(t, tr.GetAckFrame(true))
|
||||
require.NotNil(t, tr.GetAckFrame(time.Now(), true))
|
||||
}
|
||||
|
||||
func TestAppDataReceivedPacketTrackerDelayTime(t *testing.T) {
|
||||
|
@ -144,13 +144,13 @@ func TestAppDataReceivedPacketTrackerDelayTime(t *testing.T) {
|
|||
now := time.Now()
|
||||
require.NoError(t, tr.ReceivedPacket(1, protocol.ECNNon, now, true))
|
||||
require.NoError(t, tr.ReceivedPacket(2, protocol.ECNNon, now.Add(-1337*time.Millisecond), true))
|
||||
ack := tr.GetAckFrame(true)
|
||||
ack := tr.GetAckFrame(now, true)
|
||||
require.NotNil(t, ack)
|
||||
require.InDelta(t, 1337*time.Millisecond, ack.DelayTime, float64(50*time.Millisecond))
|
||||
require.Equal(t, 1337*time.Millisecond, ack.DelayTime)
|
||||
|
||||
// don't use a negative delay time
|
||||
require.NoError(t, tr.ReceivedPacket(3, protocol.ECNNon, now.Add(time.Hour), true))
|
||||
ack = tr.GetAckFrame(false)
|
||||
ack = tr.GetAckFrame(now, false)
|
||||
require.NotNil(t, ack)
|
||||
require.Zero(t, ack.DelayTime)
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func TestAppDataReceivedPacketTrackerIgnoreBelow(t *testing.T) {
|
|||
for i := 5; i <= 10; i++ {
|
||||
require.NoError(t, tr.ReceivedPacket(protocol.PacketNumber(i), protocol.ECNNon, time.Now(), true))
|
||||
}
|
||||
ack := tr.GetAckFrame(true)
|
||||
ack := tr.GetAckFrame(time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 5, Largest: 10}}, ack.AckRanges)
|
||||
|
||||
|
@ -174,7 +174,7 @@ func TestAppDataReceivedPacketTrackerIgnoreBelow(t *testing.T) {
|
|||
|
||||
require.NoError(t, tr.ReceivedPacket(11, protocol.ECNNon, time.Now(), true))
|
||||
require.NoError(t, tr.ReceivedPacket(12, protocol.ECNNon, time.Now(), true))
|
||||
ack = tr.GetAckFrame(true)
|
||||
ack = tr.GetAckFrame(time.Now(), true)
|
||||
require.NotNil(t, ack)
|
||||
require.Equal(t, []wire.AckRange{{Smallest: 7, Largest: 12}}, ack.AckRanges)
|
||||
|
||||
|
|
|
@ -79,17 +79,17 @@ func (c *MockReceivedPacketHandlerDropPacketsCall) DoAndReturn(f func(protocol.E
|
|||
}
|
||||
|
||||
// GetAckFrame mocks base method.
|
||||
func (m *MockReceivedPacketHandler) GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame {
|
||||
func (m *MockReceivedPacketHandler) GetAckFrame(arg0 protocol.EncryptionLevel, now time.Time, onlyIfQueued bool) *wire.AckFrame {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAckFrame", encLevel, onlyIfQueued)
|
||||
ret := m.ctrl.Call(m, "GetAckFrame", arg0, now, onlyIfQueued)
|
||||
ret0, _ := ret[0].(*wire.AckFrame)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetAckFrame indicates an expected call of GetAckFrame.
|
||||
func (mr *MockReceivedPacketHandlerMockRecorder) GetAckFrame(encLevel, onlyIfQueued any) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
func (mr *MockReceivedPacketHandlerMockRecorder) GetAckFrame(arg0, now, onlyIfQueued any) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockReceivedPacketHandler)(nil).GetAckFrame), encLevel, onlyIfQueued)
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockReceivedPacketHandler)(nil).GetAckFrame), arg0, now, onlyIfQueued)
|
||||
return &MockReceivedPacketHandlerGetAckFrameCall{Call: call}
|
||||
}
|
||||
|
||||
|
@ -105,13 +105,13 @@ func (c *MockReceivedPacketHandlerGetAckFrameCall) Return(arg0 *wire.AckFrame) *
|
|||
}
|
||||
|
||||
// Do rewrite *gomock.Call.Do
|
||||
func (c *MockReceivedPacketHandlerGetAckFrameCall) Do(f func(protocol.EncryptionLevel, bool) *wire.AckFrame) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
func (c *MockReceivedPacketHandlerGetAckFrameCall) Do(f func(protocol.EncryptionLevel, time.Time, bool) *wire.AckFrame) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
c.Call = c.Call.Do(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// DoAndReturn rewrite *gomock.Call.DoAndReturn
|
||||
func (c *MockReceivedPacketHandlerGetAckFrameCall) DoAndReturn(f func(protocol.EncryptionLevel, bool) *wire.AckFrame) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
func (c *MockReceivedPacketHandlerGetAckFrameCall) DoAndReturn(f func(protocol.EncryptionLevel, time.Time, bool) *wire.AckFrame) *MockReceivedPacketHandlerGetAckFrameCall {
|
||||
c.Call = c.Call.DoAndReturn(f)
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ package quic
|
|||
|
||||
import (
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
|
||||
protocol "github.com/quic-go/quic-go/internal/protocol"
|
||||
wire "github.com/quic-go/quic-go/internal/wire"
|
||||
|
@ -42,17 +43,17 @@ func (m *MockAckFrameSource) EXPECT() *MockAckFrameSourceMockRecorder {
|
|||
}
|
||||
|
||||
// GetAckFrame mocks base method.
|
||||
func (m *MockAckFrameSource) GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame {
|
||||
func (m *MockAckFrameSource) GetAckFrame(arg0 protocol.EncryptionLevel, now time.Time, onlyIfQueued bool) *wire.AckFrame {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAckFrame", encLevel, onlyIfQueued)
|
||||
ret := m.ctrl.Call(m, "GetAckFrame", arg0, now, onlyIfQueued)
|
||||
ret0, _ := ret[0].(*wire.AckFrame)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetAckFrame indicates an expected call of GetAckFrame.
|
||||
func (mr *MockAckFrameSourceMockRecorder) GetAckFrame(encLevel, onlyIfQueued any) *MockAckFrameSourceGetAckFrameCall {
|
||||
func (mr *MockAckFrameSourceMockRecorder) GetAckFrame(arg0, now, onlyIfQueued any) *MockAckFrameSourceGetAckFrameCall {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockAckFrameSource)(nil).GetAckFrame), encLevel, onlyIfQueued)
|
||||
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAckFrame", reflect.TypeOf((*MockAckFrameSource)(nil).GetAckFrame), arg0, now, onlyIfQueued)
|
||||
return &MockAckFrameSourceGetAckFrameCall{Call: call}
|
||||
}
|
||||
|
||||
|
@ -68,13 +69,13 @@ func (c *MockAckFrameSourceGetAckFrameCall) Return(arg0 *wire.AckFrame) *MockAck
|
|||
}
|
||||
|
||||
// Do rewrite *gomock.Call.Do
|
||||
func (c *MockAckFrameSourceGetAckFrameCall) Do(f func(protocol.EncryptionLevel, bool) *wire.AckFrame) *MockAckFrameSourceGetAckFrameCall {
|
||||
func (c *MockAckFrameSourceGetAckFrameCall) Do(f func(protocol.EncryptionLevel, time.Time, bool) *wire.AckFrame) *MockAckFrameSourceGetAckFrameCall {
|
||||
c.Call = c.Call.Do(f)
|
||||
return c
|
||||
}
|
||||
|
||||
// DoAndReturn rewrite *gomock.Call.DoAndReturn
|
||||
func (c *MockAckFrameSourceGetAckFrameCall) DoAndReturn(f func(protocol.EncryptionLevel, bool) *wire.AckFrame) *MockAckFrameSourceGetAckFrameCall {
|
||||
func (c *MockAckFrameSourceGetAckFrameCall) DoAndReturn(f func(protocol.EncryptionLevel, time.Time, bool) *wire.AckFrame) *MockAckFrameSourceGetAckFrameCall {
|
||||
c.Call = c.Call.DoAndReturn(f)
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ type frameSource interface {
|
|||
}
|
||||
|
||||
type ackFrameSource interface {
|
||||
GetAckFrame(encLevel protocol.EncryptionLevel, onlyIfQueued bool) *wire.AckFrame
|
||||
GetAckFrame(_ protocol.EncryptionLevel, now time.Time, onlyIfQueued bool) *wire.AckFrame
|
||||
}
|
||||
|
||||
type packetPacker struct {
|
||||
|
@ -342,7 +342,14 @@ func (p *packetPacker) PackCoalescedPacket(onlyAck bool, maxSize protocol.ByteCo
|
|||
}
|
||||
var size protocol.ByteCount
|
||||
if initialSealer != nil {
|
||||
initialHdr, initialPayload = p.maybeGetCryptoPacket(maxSize-protocol.ByteCount(initialSealer.Overhead()), protocol.EncryptionInitial, onlyAck, true, v)
|
||||
initialHdr, initialPayload = p.maybeGetCryptoPacket(
|
||||
maxSize-protocol.ByteCount(initialSealer.Overhead()),
|
||||
protocol.EncryptionInitial,
|
||||
now,
|
||||
onlyAck,
|
||||
true,
|
||||
v,
|
||||
)
|
||||
if initialPayload.length > 0 {
|
||||
size += p.longHeaderPacketLength(initialHdr, initialPayload, v) + protocol.ByteCount(initialSealer.Overhead())
|
||||
}
|
||||
|
@ -357,7 +364,14 @@ func (p *packetPacker) PackCoalescedPacket(onlyAck bool, maxSize protocol.ByteCo
|
|||
return nil, err
|
||||
}
|
||||
if handshakeSealer != nil {
|
||||
handshakeHdr, handshakePayload = p.maybeGetCryptoPacket(maxSize-size-protocol.ByteCount(handshakeSealer.Overhead()), protocol.EncryptionHandshake, onlyAck, size == 0, v)
|
||||
handshakeHdr, handshakePayload = p.maybeGetCryptoPacket(
|
||||
maxSize-size-protocol.ByteCount(handshakeSealer.Overhead()),
|
||||
protocol.EncryptionHandshake,
|
||||
now,
|
||||
onlyAck,
|
||||
size == 0,
|
||||
v,
|
||||
)
|
||||
if handshakePayload.length > 0 {
|
||||
s := p.longHeaderPacketLength(handshakeHdr, handshakePayload, v) + protocol.ByteCount(handshakeSealer.Overhead())
|
||||
size += s
|
||||
|
@ -477,9 +491,15 @@ func (p *packetPacker) appendPacket(
|
|||
return p.appendShortHeaderPacket(buf, connID, pn, pnLen, kp, pl, 0, maxPacketSize, sealer, false, v)
|
||||
}
|
||||
|
||||
func (p *packetPacker) maybeGetCryptoPacket(maxPacketSize protocol.ByteCount, encLevel protocol.EncryptionLevel, onlyAck, ackAllowed bool, v protocol.Version) (*wire.ExtendedHeader, payload) {
|
||||
func (p *packetPacker) maybeGetCryptoPacket(
|
||||
maxPacketSize protocol.ByteCount,
|
||||
encLevel protocol.EncryptionLevel,
|
||||
now time.Time,
|
||||
onlyAck, ackAllowed bool,
|
||||
v protocol.Version,
|
||||
) (*wire.ExtendedHeader, payload) {
|
||||
if onlyAck {
|
||||
if ack := p.acks.GetAckFrame(encLevel, true); ack != nil {
|
||||
if ack := p.acks.GetAckFrame(encLevel, now, true); ack != nil {
|
||||
return p.getLongHeader(encLevel, v), payload{
|
||||
ack: ack,
|
||||
length: ack.Length(v),
|
||||
|
@ -506,7 +526,7 @@ func (p *packetPacker) maybeGetCryptoPacket(maxPacketSize protocol.ByteCount, en
|
|||
hasData := s.HasData()
|
||||
var ack *wire.AckFrame
|
||||
if ackAllowed {
|
||||
ack = p.acks.GetAckFrame(encLevel, !hasRetransmission && !hasData)
|
||||
ack = p.acks.GetAckFrame(encLevel, now, !hasRetransmission && !hasData)
|
||||
}
|
||||
if !hasData && !hasRetransmission && ack == nil {
|
||||
// nothing to send
|
||||
|
@ -610,7 +630,7 @@ func (p *packetPacker) composeNextPacket(
|
|||
v protocol.Version,
|
||||
) payload {
|
||||
if onlyAck {
|
||||
if ack := p.acks.GetAckFrame(protocol.Encryption1RTT, true); ack != nil {
|
||||
if ack := p.acks.GetAckFrame(protocol.Encryption1RTT, now, true); ack != nil {
|
||||
return payload{ack: ack, length: ack.Length(v)}
|
||||
}
|
||||
return payload{}
|
||||
|
@ -622,7 +642,7 @@ func (p *packetPacker) composeNextPacket(
|
|||
var hasAck bool
|
||||
var pl payload
|
||||
if ackAllowed {
|
||||
if ack := p.acks.GetAckFrame(protocol.Encryption1RTT, !hasRetransmission && !hasData); ack != nil {
|
||||
if ack := p.acks.GetAckFrame(protocol.Encryption1RTT, now, !hasRetransmission && !hasData); ack != nil {
|
||||
pl.ack = ack
|
||||
pl.length += ack.Length(v)
|
||||
hasAck = true
|
||||
|
@ -734,7 +754,7 @@ func (p *packetPacker) MaybePackProbePacket(
|
|||
default:
|
||||
panic("unknown encryption level")
|
||||
}
|
||||
hdr, pl := p.maybeGetCryptoPacket(maxPacketSize-protocol.ByteCount(sealer.Overhead()), encLevel, false, true, v)
|
||||
hdr, pl := p.maybeGetCryptoPacket(maxPacketSize-protocol.ByteCount(sealer.Overhead()), encLevel, now, false, true, v)
|
||||
if pl.length == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ func TestPackLongHeaders(t *testing.T) {
|
|||
token := make([]byte, 20)
|
||||
rand.Read(token)
|
||||
tp.packer.SetToken(token)
|
||||
now := time.Now()
|
||||
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24), protocol.PacketNumberLen3)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x24))
|
||||
|
@ -136,12 +137,12 @@ func TestPackLongHeaders(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().Get0RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, now, false)
|
||||
// don't EXPECT any calls for a Handshake ACK frame
|
||||
tp.initialStream.Write([]byte("initial"))
|
||||
tp.packer.retransmissionQueue.addHandshake(&wire.PingFrame{})
|
||||
|
||||
p, err := tp.packer.PackCoalescedPacket(false, maxPacketSize, time.Now(), protocol.Version1)
|
||||
p, err := tp.packer.PackCoalescedPacket(false, maxPacketSize, now, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, maxPacketSize, p.buffer.Len())
|
||||
require.Len(t, p.longHdrPackets, 2)
|
||||
|
@ -174,9 +175,9 @@ func TestPackCoalescedAckOnlyPacketNothingToSend(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetInitialSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, gomock.Any(), true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true)
|
||||
p, err := tp.packer.PackCoalescedPacket(true, 1234, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, p)
|
||||
|
@ -195,7 +196,7 @@ func testPackInitialAckOnlyPacket(t *testing.T, pers protocol.Perspective) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.EncryptionInitial).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().GetInitialSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true).Return(ack)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), true).Return(ack)
|
||||
p, err := tp.packer.PackCoalescedPacket(true, maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
|
@ -224,7 +225,7 @@ func TestPack1RTTAckOnlyPacket(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true).Return(ack)
|
||||
p, buffer, err := tp.packer.PackAckOnlyPacket(maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ack, p.Ack)
|
||||
|
@ -239,15 +240,17 @@ func TestPack0RTTPacket(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().Get0RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), true)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption0RTT).Return(protocol.PacketNumber(0x42))
|
||||
cf := ackhandler.Frame{Frame: &wire.MaxDataFrame{MaximumData: 0x1337}}
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
// TODO: check sizes
|
||||
tp.framer.EXPECT().Append(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(fs []ackhandler.Frame, sf []ackhandler.StreamFrame, _ protocol.ByteCount, _ time.Time, _ protocol.Version) ([]ackhandler.Frame, []ackhandler.StreamFrame, protocol.ByteCount) {
|
||||
return append(fs, cf), sf, cf.Frame.Length(protocol.Version1)
|
||||
})
|
||||
tp.framer.EXPECT().Append(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
|
||||
func(fs []ackhandler.Frame, sf []ackhandler.StreamFrame, _ protocol.ByteCount, _ time.Time, _ protocol.Version) ([]ackhandler.Frame, []ackhandler.StreamFrame, protocol.ByteCount) {
|
||||
return append(fs, cf), sf, cf.Frame.Length(protocol.Version1)
|
||||
},
|
||||
)
|
||||
p, err := tp.packer.PackCoalescedPacket(false, protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
|
@ -266,7 +269,7 @@ func TestPack0RTTPacketNoACK(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetInitialSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), true)
|
||||
// no further calls to get an ACK frame
|
||||
p, err := tp.packer.PackCoalescedPacket(true, protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -286,7 +289,7 @@ func TestPackCoalescedAppData(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, gomock.Any(), false)
|
||||
// don't expect any calls for a 1-RTT ACK frame
|
||||
tp.handshakeStream.Write([]byte("handshake"))
|
||||
expectAppendFrames(tp.framer, nil, []ackhandler.StreamFrame{{Frame: &wire.StreamFrame{Data: []byte("foobar")}}})
|
||||
|
@ -449,7 +452,7 @@ func TestPack1RTTPacketNothingToSend(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
// don't expect any calls to PopPacketNumber
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true)
|
||||
tp.framer.EXPECT().HasData()
|
||||
_, err := tp.packer.AppendPacket(getPacketBuffer(), protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.ErrorIs(t, err, errNothingToPack)
|
||||
|
@ -462,7 +465,7 @@ func TestPack1RTTPacketWithData(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false)
|
||||
f := &wire.StreamFrame{
|
||||
StreamID: 5,
|
||||
Data: []byte{0xde, 0xca, 0xfb, 0xad},
|
||||
|
@ -508,7 +511,7 @@ func TestPack1RTTPacketWithACK(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 42, Smallest: 1}}}
|
||||
tp.framer.EXPECT().HasData()
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(ack)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true).Return(ack)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
p, err := tp.packer.AppendPacket(getPacketBuffer(), protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -522,7 +525,7 @@ func TestPackPathChallengeAndPathResponse(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false)
|
||||
frames := []ackhandler.Frame{
|
||||
{Frame: &wire.PathChallengeFrame{}},
|
||||
{Frame: &wire.PathResponseFrame{}},
|
||||
|
@ -557,7 +560,7 @@ func TestPackDatagramFrames(t *testing.T) {
|
|||
mockCtrl := gomock.NewController(t)
|
||||
tp := newTestPacketPacker(t, mockCtrl, protocol.PerspectiveServer)
|
||||
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
|
@ -581,7 +584,7 @@ func TestPackLargeDatagramFrame(t *testing.T) {
|
|||
const maxPacketSize = 1000
|
||||
mockCtrl := gomock.NewController(t)
|
||||
tp := newTestPacketPacker(t, mockCtrl, protocol.PerspectiveServer)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 100}}})
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 100}}})
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
|
@ -599,7 +602,7 @@ func TestPackLargeDatagramFrame(t *testing.T) {
|
|||
// Now try packing again, but with a smaller packet size.
|
||||
// The DATAGRAM frame should now be dropped, as we can't expect to ever be able tosend it out.
|
||||
const newMaxPacketSize = maxPacketSize - 10
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x43), protocol.PacketNumberLen2)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData()
|
||||
|
@ -620,7 +623,7 @@ func TestPackRetransmissions(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetInitialSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), false)
|
||||
p, err := tp.packer.PackCoalescedPacket(false, 1000, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, p.longHdrPackets, 1)
|
||||
|
@ -637,7 +640,9 @@ func packMaxNumNonAckElicitingAcks(t *testing.T, tp *testPacketPacker, mockCtrl
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false).Return(
|
||||
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
|
||||
)
|
||||
expectAppendFrames(tp.framer, nil, nil)
|
||||
p, err := tp.packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -657,7 +662,7 @@ func TestPackEvery20thPacketAckEliciting(t *testing.T) {
|
|||
// Now there's nothing to send, so we shouldn't generate a packet just to send a PING
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
expectAppendFrames(tp.framer, nil, nil)
|
||||
_, err := tp.packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
|
||||
|
@ -668,7 +673,9 @@ func TestPackEvery20thPacketAckEliciting(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false).Return(
|
||||
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
|
||||
)
|
||||
expectAppendFrames(tp.framer, nil, nil)
|
||||
p, err := tp.packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -681,7 +688,9 @@ func TestPackEvery20thPacketAckEliciting(t *testing.T) {
|
|||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false).Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false).Return(
|
||||
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
|
||||
)
|
||||
expectAppendFrames(tp.framer, nil, nil)
|
||||
p, err = tp.packer.AppendPacket(getPacketBuffer(), maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -700,7 +709,7 @@ func TestPackLongHeaderPadToAtLeast4Bytes(t *testing.T) {
|
|||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(sealer, nil)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
tp.retransmissionQueue.addHandshake(&wire.PingFrame{})
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionHandshake, gomock.Any(), false)
|
||||
|
||||
packet, err := tp.packer.PackCoalescedPacket(false, protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -739,7 +748,7 @@ func TestPackShortHeaderPadToAtLeast4Bytes(t *testing.T) {
|
|||
sealer := newMockShortHeaderSealer(mockCtrl)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(sealer, nil)
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false)
|
||||
expectAppendFrames(tp.framer, nil, []ackhandler.StreamFrame{{Frame: f}})
|
||||
|
||||
buffer := getPacketBuffer()
|
||||
|
@ -796,7 +805,7 @@ func testPackProbePacket(t *testing.T, encLevel protocol.EncryptionLevel, perspe
|
|||
tp.sealingManager.EXPECT().GetHandshakeSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.packer.handshakeStream.Write([]byte("foobar"))
|
||||
}
|
||||
tp.ackFramer.EXPECT().GetAckFrame(encLevel, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(encLevel, gomock.Any(), false)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(encLevel).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(encLevel).Return(protocol.PacketNumber(0x42))
|
||||
|
||||
|
@ -827,7 +836,7 @@ func TestPackProbePacketNothingToSend(t *testing.T) {
|
|||
mockCtrl := gomock.NewController(t)
|
||||
tp := newTestPacketPacker(t, mockCtrl, protocol.PerspectiveClient)
|
||||
tp.sealingManager.EXPECT().GetInitialSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.EncryptionInitial, gomock.Any(), true)
|
||||
|
||||
p, err := tp.packer.MaybePackProbePacket(protocol.EncryptionInitial, protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -840,15 +849,17 @@ func TestPack1RTTProbePacket(t *testing.T) {
|
|||
mockCtrl := gomock.NewController(t)
|
||||
tp := newTestPacketPacker(t, mockCtrl, protocol.PerspectiveServer)
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, false)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), false)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.pnManager.EXPECT().PopPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42))
|
||||
tp.framer.EXPECT().HasData().Return(true)
|
||||
tp.framer.EXPECT().Append(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(func(cf []ackhandler.Frame, sf []ackhandler.StreamFrame, size protocol.ByteCount, _ time.Time, v protocol.Version) ([]ackhandler.Frame, []ackhandler.StreamFrame, protocol.ByteCount) {
|
||||
f, split := (&wire.StreamFrame{Data: make([]byte, 2*maxPacketSize)}).MaybeSplitOffFrame(size, v)
|
||||
require.True(t, split)
|
||||
return cf, append(sf, ackhandler.StreamFrame{Frame: f}), f.Length(v)
|
||||
})
|
||||
tp.framer.EXPECT().Append(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), protocol.Version1).DoAndReturn(
|
||||
func(cf []ackhandler.Frame, sf []ackhandler.StreamFrame, size protocol.ByteCount, _ time.Time, v protocol.Version) ([]ackhandler.Frame, []ackhandler.StreamFrame, protocol.ByteCount) {
|
||||
f, split := (&wire.StreamFrame{Data: make([]byte, 2*maxPacketSize)}).MaybeSplitOffFrame(size, v)
|
||||
require.True(t, split)
|
||||
return cf, append(sf, ackhandler.StreamFrame{Frame: f}), f.Length(v)
|
||||
},
|
||||
)
|
||||
|
||||
p, err := tp.packer.MaybePackProbePacket(protocol.Encryption1RTT, maxPacketSize, time.Now(), protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
|
@ -868,7 +879,7 @@ func TestPackProbePacketNothingToPack(t *testing.T) {
|
|||
|
||||
tp.sealingManager.EXPECT().Get1RTTSealer().Return(newMockShortHeaderSealer(mockCtrl), nil)
|
||||
tp.pnManager.EXPECT().PeekPacketNumber(protocol.Encryption1RTT).Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, true)
|
||||
tp.ackFramer.EXPECT().GetAckFrame(protocol.Encryption1RTT, gomock.Any(), true)
|
||||
tp.framer.EXPECT().HasData()
|
||||
|
||||
packet, err := tp.packer.MaybePackProbePacket(protocol.Encryption1RTT, protocol.MaxByteCount, time.Now(), protocol.Version1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue