mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
return the packet number length when peek a new packet number
This commit is contained in:
parent
ebbf839fa4
commit
c81cd92daf
7 changed files with 48 additions and 113 deletions
|
@ -31,9 +31,8 @@ type SentPacketHandler interface {
|
|||
DequeuePacketForRetransmission() *Packet
|
||||
DequeueProbePacket() (*Packet, error)
|
||||
|
||||
PeekPacketNumber() protocol.PacketNumber
|
||||
PeekPacketNumber() (protocol.PacketNumber, protocol.PacketNumberLen)
|
||||
PopPacketNumber() protocol.PacketNumber
|
||||
GetPacketNumberLen(protocol.PacketNumber) protocol.PacketNumberLen
|
||||
|
||||
GetAlarmTimeout() time.Time
|
||||
OnAlarm() error
|
||||
|
|
|
@ -521,18 +521,15 @@ func (h *sentPacketHandler) DequeueProbePacket() (*Packet, error) {
|
|||
return h.DequeuePacketForRetransmission(), nil
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) PeekPacketNumber() protocol.PacketNumber {
|
||||
return h.packetNumberGenerator.Peek()
|
||||
func (h *sentPacketHandler) PeekPacketNumber() (protocol.PacketNumber, protocol.PacketNumberLen) {
|
||||
pn := h.packetNumberGenerator.Peek()
|
||||
return pn, protocol.GetPacketNumberLengthForHeader(pn, h.lowestUnacked(), h.version)
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) PopPacketNumber() protocol.PacketNumber {
|
||||
return h.packetNumberGenerator.Pop()
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) GetPacketNumberLen(p protocol.PacketNumber) protocol.PacketNumberLen {
|
||||
return protocol.GetPacketNumberLengthForHeader(p, h.lowestUnacked(), h.version)
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) SendMode() SendMode {
|
||||
numTrackedPackets := len(h.retransmissionQueue) + h.packetHistory.Len()
|
||||
|
||||
|
|
|
@ -89,12 +89,6 @@ var _ = Describe("SentPacketHandler", func() {
|
|||
ExpectWithOffset(1, handler.rttStats.SmoothedRTT()).To(Equal(rtt))
|
||||
}
|
||||
|
||||
It("determines the packet number length", func() {
|
||||
handler.largestAcked = 0x1337
|
||||
Expect(handler.GetPacketNumberLen(0x1338)).To(Equal(protocol.PacketNumberLen2))
|
||||
Expect(handler.GetPacketNumberLen(0xfffffff)).To(Equal(protocol.PacketNumberLen4))
|
||||
})
|
||||
|
||||
Context("registering sent packets", func() {
|
||||
It("accepts two consecutive packets", func() {
|
||||
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1}))
|
||||
|
|
|
@ -86,18 +86,6 @@ func (mr *MockSentPacketHandlerMockRecorder) GetLowestPacketNotConfirmedAcked()
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLowestPacketNotConfirmedAcked", reflect.TypeOf((*MockSentPacketHandler)(nil).GetLowestPacketNotConfirmedAcked))
|
||||
}
|
||||
|
||||
// GetPacketNumberLen mocks base method
|
||||
func (m *MockSentPacketHandler) GetPacketNumberLen(arg0 protocol.PacketNumber) protocol.PacketNumberLen {
|
||||
ret := m.ctrl.Call(m, "GetPacketNumberLen", arg0)
|
||||
ret0, _ := ret[0].(protocol.PacketNumberLen)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetPacketNumberLen indicates an expected call of GetPacketNumberLen
|
||||
func (mr *MockSentPacketHandlerMockRecorder) GetPacketNumberLen(arg0 interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPacketNumberLen", reflect.TypeOf((*MockSentPacketHandler)(nil).GetPacketNumberLen), arg0)
|
||||
}
|
||||
|
||||
// OnAlarm mocks base method
|
||||
func (m *MockSentPacketHandler) OnAlarm() error {
|
||||
ret := m.ctrl.Call(m, "OnAlarm")
|
||||
|
@ -111,10 +99,11 @@ func (mr *MockSentPacketHandlerMockRecorder) OnAlarm() *gomock.Call {
|
|||
}
|
||||
|
||||
// PeekPacketNumber mocks base method
|
||||
func (m *MockSentPacketHandler) PeekPacketNumber() protocol.PacketNumber {
|
||||
func (m *MockSentPacketHandler) PeekPacketNumber() (protocol.PacketNumber, protocol.PacketNumberLen) {
|
||||
ret := m.ctrl.Call(m, "PeekPacketNumber")
|
||||
ret0, _ := ret[0].(protocol.PacketNumber)
|
||||
return ret0
|
||||
ret1, _ := ret[1].(protocol.PacketNumberLen)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// PeekPacketNumber indicates an expected call of PeekPacketNumber
|
||||
|
|
|
@ -60,9 +60,8 @@ func getMaxPacketSize(addr net.Addr) protocol.ByteCount {
|
|||
}
|
||||
|
||||
type packetNumberManager interface {
|
||||
PeekPacketNumber() protocol.PacketNumber
|
||||
PeekPacketNumber() (protocol.PacketNumber, protocol.PacketNumberLen)
|
||||
PopPacketNumber() protocol.PacketNumber
|
||||
GetPacketNumberLen(protocol.PacketNumber) protocol.PacketNumberLen
|
||||
}
|
||||
|
||||
type sealingManager interface {
|
||||
|
@ -399,12 +398,10 @@ func (p *packetPacker) composeNextPacket(
|
|||
}
|
||||
|
||||
func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header {
|
||||
pnum := p.pnManager.PeekPacketNumber()
|
||||
packetNumberLen := p.pnManager.GetPacketNumberLen(pnum)
|
||||
|
||||
pn, pnLen := p.pnManager.PeekPacketNumber()
|
||||
header := &wire.Header{
|
||||
PacketNumber: pnum,
|
||||
PacketNumberLen: packetNumberLen,
|
||||
PacketNumber: pn,
|
||||
PacketNumberLen: pnLen,
|
||||
Version: p.version,
|
||||
DestConnectionID: p.destConnID,
|
||||
}
|
||||
|
|
|
@ -112,8 +112,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("generating a packet header", func() {
|
||||
It("uses the Long Header format", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
h := packer.getHeader(protocol.EncryptionHandshake)
|
||||
Expect(h.IsLongHeader).To(BeTrue())
|
||||
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
||||
|
@ -122,8 +121,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("sets source and destination connection ID", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
destConnID := protocol.ConnectionID{8, 7, 6, 5, 4, 3, 2, 1}
|
||||
packer.srcConnID = srcConnID
|
||||
|
@ -134,8 +132,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("changes the destination connection ID", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
srcConnID := protocol.ConnectionID{1, 1, 1, 1, 1, 1, 1, 1}
|
||||
packer.srcConnID = srcConnID
|
||||
dest1 := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
|
@ -151,8 +148,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("uses the Short Header format for 1-RTT packets", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x1337))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen4)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x1337), protocol.PacketNumberLen4)
|
||||
h := packer.getHeader(protocol.Encryption1RTT)
|
||||
Expect(h.IsLongHeader).To(BeFalse())
|
||||
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x1337)))
|
||||
|
@ -167,8 +163,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("returns nil when no packet is queued", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
// don't expect any calls to PopPacketNumber
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -180,8 +175,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs single packets", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -201,8 +195,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("stores the encryption level a packet was sealed with", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -217,8 +210,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a single ACK", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 42, Smallest: 1}}}
|
||||
ackFramer.EXPECT().GetAckFrame().Return(ack)
|
||||
|
@ -232,8 +224,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a CONNECTION_CLOSE", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
// expect no framer.PopStreamFrames
|
||||
ccf := wire.ConnectionCloseFrame{
|
||||
|
@ -248,8 +239,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs control frames", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -264,8 +254,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("accounts for the space consumed by control frames", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
var maxSize protocol.ByteCount
|
||||
|
@ -292,8 +281,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs ACK packets", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}}
|
||||
|
@ -307,8 +295,7 @@ var _ = Describe("Packet packer", func() {
|
|||
Context("making ACK packets retransmittable", func() {
|
||||
sendMaxNumNonRetransmittableAcks := func() {
|
||||
for i := 0; i < protocol.MaxNonRetransmittableAcks; i++ {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame().Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
|
@ -323,8 +310,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("adds a PING frame when it's supposed to send a retransmittable packet", func() {
|
||||
sendMaxNumNonRetransmittableAcks()
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame().Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
|
@ -335,8 +321,7 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(p.frames).To(ContainElement(&wire.PingFrame{}))
|
||||
// make sure the next packet doesn't contain another PING
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame().Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
|
@ -351,8 +336,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("waits until there's something to send before adding a PING frame", func() {
|
||||
sendMaxNumNonRetransmittableAcks()
|
||||
// nothing to send
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
expectAppendControlFrames()
|
||||
expectAppendStreamFrames()
|
||||
|
@ -363,8 +347,7 @@ var _ = Describe("Packet packer", func() {
|
|||
// now add some frame to send
|
||||
expectAppendControlFrames()
|
||||
expectAppendStreamFrames()
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame().Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
|
||||
|
@ -376,8 +359,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("doesn't send a PING if it already sent another retransmittable frame", func() {
|
||||
sendMaxNumNonRetransmittableAcks()
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -392,8 +374,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("STREAM frame handling", func() {
|
||||
It("does not split a STREAM frame with maximum size", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
|
@ -431,8 +412,7 @@ var _ = Describe("Packet packer", func() {
|
|||
Data: []byte("frame 3"),
|
||||
DataLenPresent: true,
|
||||
}
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -451,8 +431,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("doesn't send unencrypted stream data on a data stream", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.EncryptionInitial, sealer)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
expectAppendControlFrames()
|
||||
|
@ -465,8 +444,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("retransmissions", func() {
|
||||
It("retransmits a small packet", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil)
|
||||
frames := []wire.Frame{
|
||||
|
@ -485,8 +463,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs two packets for retransmission if the original packet contained many control frames", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil)
|
||||
var frames []wire.Frame
|
||||
|
@ -514,8 +491,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("splits a STREAM frame that doesn't fit", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil)
|
||||
packets, err := packer.PackRetransmission(&ackhandler.Packet{
|
||||
|
@ -543,8 +519,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("splits STREAM frames, if necessary", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).AnyTimes()
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).AnyTimes()
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42)).AnyTimes()
|
||||
for i := 0; i < 100; i++ {
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil).MaxTimes(2)
|
||||
|
@ -581,8 +556,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs two packets for retransmission if the original packet contained many STREAM frames", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil)
|
||||
var frames []wire.Frame
|
||||
|
@ -611,8 +585,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("correctly sets the DataLenPresent on STREAM frames", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.Encryption1RTT).Return(sealer, nil)
|
||||
frames := []wire.Frame{
|
||||
|
@ -640,8 +613,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("max packet size", func() {
|
||||
It("sets the maximum packet size", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer).Times(2)
|
||||
ackFramer.EXPECT().GetAckFrame().Times(2)
|
||||
var initialMaxPacketSize protocol.ByteCount
|
||||
|
@ -666,8 +638,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("doesn't increase the max packet size", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42)).Times(2)
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).Times(2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2).Times(2)
|
||||
sealingManager.EXPECT().GetSealer().Return(protocol.Encryption1RTT, sealer).Times(2)
|
||||
ackFramer.EXPECT().GetAckFrame().Times(2)
|
||||
var initialMaxPacketSize protocol.ByteCount
|
||||
|
@ -695,8 +666,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
Context("packing crypto packets", func() {
|
||||
It("sets the payload length", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
f := &wire.CryptoFrame{
|
||||
Offset: 0x1337,
|
||||
|
@ -713,8 +683,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("packs a maximum size crypto packet", func() {
|
||||
var f *wire.CryptoFrame
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionHandshake).Return(sealer, nil)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -737,8 +706,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
It("pads Initial packets to the required minimum packet size", func() {
|
||||
f := &wire.CryptoFrame{Data: []byte("foobar")}
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionInitial).Return(sealer, nil)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -756,8 +724,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("sets the correct payload length for an Initial packet", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionInitial).Return(sealer, nil)
|
||||
ackFramer.EXPECT().GetAckFrame()
|
||||
|
@ -775,8 +742,7 @@ var _ = Describe("Packet packer", func() {
|
|||
It("adds an ACK frame", func() {
|
||||
f := &wire.CryptoFrame{Data: []byte("foobar")}
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 42, Largest: 1337}}}
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionInitial).Return(sealer, nil)
|
||||
ackFramer.EXPECT().GetAckFrame().Return(ack)
|
||||
|
@ -797,8 +763,7 @@ var _ = Describe("Packet packer", func() {
|
|||
sf := &wire.StreamFrame{Data: []byte("foobar")}
|
||||
|
||||
It("packs a retransmission with the right encryption level", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionInitial).Return(sealer, nil)
|
||||
packet := &ackhandler.Packet{
|
||||
|
@ -816,8 +781,7 @@ var _ = Describe("Packet packer", func() {
|
|||
|
||||
// this should never happen, since non forward-secure packets are limited to a size smaller than MaxPacketSize, such that it is always possible to retransmit them without splitting the StreamFrame
|
||||
It("refuses to send a packet larger than MaxPacketSize", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(gomock.Any()).Return(sealer, nil)
|
||||
packet := &ackhandler.Packet{
|
||||
EncryptionLevel: protocol.EncryptionHandshake,
|
||||
|
@ -834,8 +798,7 @@ var _ = Describe("Packet packer", func() {
|
|||
})
|
||||
|
||||
It("packs a retransmission for an Initial packet", func() {
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
pnManager.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PeekPacketNumber().Return(protocol.PacketNumber(0x42), protocol.PacketNumberLen2)
|
||||
pnManager.EXPECT().PopPacketNumber().Return(protocol.PacketNumber(0x42))
|
||||
sealingManager.EXPECT().GetSealerWithEncryptionLevel(protocol.EncryptionInitial).Return(sealer, nil)
|
||||
packer.perspective = protocol.PerspectiveClient
|
||||
|
|
|
@ -610,7 +610,6 @@ var _ = Describe("Session", func() {
|
|||
newPacket := getPacket(234)
|
||||
sess.windowUpdateQueue.callback(&wire.MaxDataFrame{})
|
||||
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
|
||||
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
|
||||
sph.EXPECT().DequeuePacketForRetransmission().Return(packetToRetransmit)
|
||||
sph.EXPECT().SendMode().Return(ackhandler.SendRetransmission)
|
||||
sph.EXPECT().SendMode().Return(ackhandler.SendAny)
|
||||
|
@ -664,7 +663,6 @@ var _ = Describe("Session", func() {
|
|||
retransmittedPacket := getPacket(123)
|
||||
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
|
||||
sph.EXPECT().TimeUntilSend()
|
||||
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
|
||||
sph.EXPECT().SendMode().Return(ackhandler.SendTLP)
|
||||
sph.EXPECT().ShouldSendNumPackets().Return(1)
|
||||
sph.EXPECT().DequeueProbePacket().Return(packetToRetransmit, nil)
|
||||
|
@ -691,7 +689,6 @@ var _ = Describe("Session", func() {
|
|||
BeforeEach(func() {
|
||||
sph = mockackhandler.NewMockSentPacketHandler(mockCtrl)
|
||||
sph.EXPECT().GetAlarmTimeout().AnyTimes()
|
||||
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
|
||||
sph.EXPECT().DequeuePacketForRetransmission().AnyTimes()
|
||||
sess.sentPacketHandler = sph
|
||||
streamManager.EXPECT().CloseWithError(gomock.Any())
|
||||
|
@ -835,7 +832,6 @@ var _ = Describe("Session", func() {
|
|||
sph.EXPECT().TimeUntilSend().AnyTimes()
|
||||
sph.EXPECT().SendMode().Return(ackhandler.SendAny).AnyTimes()
|
||||
sph.EXPECT().ShouldSendNumPackets().AnyTimes().Return(1)
|
||||
sph.EXPECT().GetPacketNumberLen(gomock.Any()).Return(protocol.PacketNumberLen2).AnyTimes()
|
||||
sph.EXPECT().SentPacket(gomock.Any())
|
||||
sess.sentPacketHandler = sph
|
||||
packer.EXPECT().PackPacket().Return(getPacket(1), nil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue