mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
set the ACK frame delay time when generating the frame
This commit is contained in:
parent
2127e2f1de
commit
ee968aff67
6 changed files with 19 additions and 10 deletions
|
@ -159,13 +159,14 @@ func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
|
func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
|
||||||
if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(time.Now())) {
|
now := time.Now()
|
||||||
|
if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(now)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ack := &wire.AckFrame{
|
ack := &wire.AckFrame{
|
||||||
AckRanges: h.packetHistory.GetAckRanges(),
|
AckRanges: h.packetHistory.GetAckRanges(),
|
||||||
PacketReceivedTime: h.largestObservedReceivedTime,
|
DelayTime: now.Sub(h.largestObservedReceivedTime),
|
||||||
}
|
}
|
||||||
|
|
||||||
h.lastAck = ack
|
h.lastAck = ack
|
||||||
|
|
|
@ -227,6 +227,16 @@ var _ = Describe("receivedPacketHandler", func() {
|
||||||
Expect(ack.HasMissingRanges()).To(BeFalse())
|
Expect(ack.HasMissingRanges()).To(BeFalse())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("sets the delay time", func() {
|
||||||
|
err := handler.ReceivedPacket(1, time.Time{}, true)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = handler.ReceivedPacket(2, time.Now().Add(-1337*time.Millisecond), true)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
ack := handler.GetAckFrame()
|
||||||
|
Expect(ack).ToNot(BeNil())
|
||||||
|
Expect(ack.DelayTime).To(BeNumerically("~", 1337*time.Millisecond, 50*time.Millisecond))
|
||||||
|
})
|
||||||
|
|
||||||
It("saves the last sent ACK", func() {
|
It("saves the last sent ACK", func() {
|
||||||
err := handler.ReceivedPacket(1, time.Time{}, true)
|
err := handler.ReceivedPacket(1, time.Time{}, true)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
|
@ -16,11 +16,7 @@ const ackDelayExponent = 3
|
||||||
// An AckFrame is an ACK frame
|
// An AckFrame is an ACK frame
|
||||||
type AckFrame struct {
|
type AckFrame struct {
|
||||||
AckRanges []AckRange // has to be ordered. The highest ACK range goes first, the lowest ACK range goes last
|
AckRanges []AckRange // has to be ordered. The highest ACK range goes first, the lowest ACK range goes last
|
||||||
|
DelayTime time.Duration
|
||||||
// time when the LargestAcked was receiveid
|
|
||||||
// this field will not be set for received ACKs frames
|
|
||||||
PacketReceivedTime time.Time
|
|
||||||
DelayTime time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseAckFrame reads an ACK frame
|
// parseAckFrame reads an ACK frame
|
||||||
|
|
|
@ -191,7 +191,6 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error
|
||||||
utils.BigEndian.WriteUint48(b, uint64(largestAcked)&(1<<48-1))
|
utils.BigEndian.WriteUint48(b, uint64(largestAcked)&(1<<48-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
f.DelayTime = time.Since(f.PacketReceivedTime)
|
|
||||||
utils.BigEndian.WriteUfloat16(b, uint64(f.DelayTime/time.Microsecond))
|
utils.BigEndian.WriteUfloat16(b, uint64(f.DelayTime/time.Microsecond))
|
||||||
|
|
||||||
var numRanges uint64
|
var numRanges uint64
|
||||||
|
|
|
@ -498,6 +498,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
|
||||||
It("writes a simple ACK frame", func() {
|
It("writes a simple ACK frame", func() {
|
||||||
frameOrig := &AckFrame{
|
frameOrig := &AckFrame{
|
||||||
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
|
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
|
||||||
|
DelayTime: 876 * time.Microsecond,
|
||||||
}
|
}
|
||||||
err := frameOrig.Write(b, versionBigEndian)
|
err := frameOrig.Write(b, versionBigEndian)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -506,6 +507,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
|
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
|
||||||
Expect(frame.HasMissingRanges()).To(BeFalse())
|
Expect(frame.HasMissingRanges()).To(BeFalse())
|
||||||
|
Expect(frame.DelayTime).To(Equal(frameOrig.DelayTime))
|
||||||
Expect(r.Len()).To(BeZero())
|
Expect(r.Len()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
f := &AckFrame{
|
f := &AckFrame{
|
||||||
AckRanges: []AckRange{{Smallest: 0xdeadbeef, Largest: 0xdeadbeef}},
|
AckRanges: []AckRange{{Smallest: 0xdeadbeef, Largest: 0xdeadbeef}},
|
||||||
DelayTime: 18 * time.Second,
|
DelayTime: 18 * time.Millisecond,
|
||||||
}
|
}
|
||||||
err := f.Write(buf, versionIETFFrames)
|
err := f.Write(buf, versionIETFFrames)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -160,6 +160,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame).To(Equal(f))
|
Expect(frame).To(Equal(f))
|
||||||
Expect(frame.HasMissingRanges()).To(BeFalse())
|
Expect(frame.HasMissingRanges()).To(BeFalse())
|
||||||
|
Expect(frame.DelayTime).To(Equal(f.DelayTime))
|
||||||
Expect(b.Len()).To(BeZero())
|
Expect(b.Len()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue