set the ACK frame delay time when generating the frame

This commit is contained in:
Marten Seemann 2018-04-30 21:50:33 +09:00
parent 2127e2f1de
commit ee968aff67
6 changed files with 19 additions and 10 deletions

View file

@ -159,13 +159,14 @@ func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber
}
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
}
ack := &wire.AckFrame{
AckRanges: h.packetHistory.GetAckRanges(),
PacketReceivedTime: h.largestObservedReceivedTime,
AckRanges: h.packetHistory.GetAckRanges(),
DelayTime: now.Sub(h.largestObservedReceivedTime),
}
h.lastAck = ack

View file

@ -227,6 +227,16 @@ var _ = Describe("receivedPacketHandler", func() {
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() {
err := handler.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())

View file

@ -16,11 +16,7 @@ const ackDelayExponent = 3
// An AckFrame is an ACK frame
type AckFrame struct {
AckRanges []AckRange // has to be ordered. The highest ACK range goes first, the lowest ACK range goes last
// time when the LargestAcked was receiveid
// this field will not be set for received ACKs frames
PacketReceivedTime time.Time
DelayTime time.Duration
DelayTime time.Duration
}
// parseAckFrame reads an ACK frame

View file

@ -191,7 +191,6 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error
utils.BigEndian.WriteUint48(b, uint64(largestAcked)&(1<<48-1))
}
f.DelayTime = time.Since(f.PacketReceivedTime)
utils.BigEndian.WriteUfloat16(b, uint64(f.DelayTime/time.Microsecond))
var numRanges uint64

View file

@ -498,6 +498,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
It("writes a simple ACK frame", func() {
frameOrig := &AckFrame{
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
DelayTime: 876 * time.Microsecond,
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -506,6 +507,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(frame.DelayTime).To(Equal(frameOrig.DelayTime))
Expect(r.Len()).To(BeZero())
})

View file

@ -150,7 +150,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
buf := &bytes.Buffer{}
f := &AckFrame{
AckRanges: []AckRange{{Smallest: 0xdeadbeef, Largest: 0xdeadbeef}},
DelayTime: 18 * time.Second,
DelayTime: 18 * time.Millisecond,
}
err := f.Write(buf, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
@ -160,6 +160,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(frame.DelayTime).To(Equal(f.DelayTime))
Expect(b.Len()).To(BeZero())
})