mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
use time.Duration as delay time type in ackframe
This commit is contained in:
parent
3a18452a93
commit
2878e47317
3 changed files with 9 additions and 18 deletions
|
@ -3,6 +3,7 @@ package frames
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
|
@ -14,7 +15,7 @@ var errInvalidNackRanges = errors.New("AckFrame: ACK frame contains invalid NACK
|
|||
type AckFrame struct {
|
||||
Entropy byte
|
||||
LargestObserved protocol.PacketNumber
|
||||
DelayTime uint64
|
||||
DelayTime time.Duration
|
||||
NackRanges []NackRange // has to be ordered. The NACK range with the highest FirstPacketNumber goes first, the NACK range with the lowest FirstPacketNumber goes last
|
||||
}
|
||||
|
||||
|
@ -29,7 +30,7 @@ func (f *AckFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, pa
|
|||
b.WriteByte(typeByte)
|
||||
b.WriteByte(f.Entropy)
|
||||
utils.WriteUint48(b, uint64(f.LargestObserved)) // TODO: send the correct length
|
||||
utils.WriteUfloat16(b, f.DelayTime)
|
||||
utils.WriteUfloat16(b, uint64(f.DelayTime/time.Microsecond))
|
||||
b.WriteByte(0x01) // Just one timestamp
|
||||
b.WriteByte(0x00) // Delta Largest observed
|
||||
utils.WriteUint32(b, 0) // First timestamp
|
||||
|
@ -150,10 +151,11 @@ func ParseAckFrame(r *bytes.Reader) (*AckFrame, error) {
|
|||
}
|
||||
frame.LargestObserved = protocol.PacketNumber(largestObserved)
|
||||
|
||||
frame.DelayTime, err = utils.ReadUfloat16(r)
|
||||
delay, err := utils.ReadUfloat16(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame.DelayTime = time.Duration(delay) * time.Microsecond
|
||||
|
||||
numTimestampByte, err := r.ReadByte()
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package frames
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
@ -16,7 +17,7 @@ var _ = Describe("AckFrame", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.Entropy).To(Equal(byte(0xA4)))
|
||||
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(0x03)))
|
||||
Expect(frame.DelayTime).To(Equal(uint64(430464)))
|
||||
Expect(frame.DelayTime).To(Equal(430464 * time.Microsecond))
|
||||
Expect(frame.HasNACK()).To(Equal(false))
|
||||
Expect(b.Len()).To(Equal(0))
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ package quic
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
|
@ -60,20 +61,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
It("unpacks ack frames", func() {
|
||||
f := &frames.AckFrame{
|
||||
LargestObserved: 1,
|
||||
DelayTime: 1,
|
||||
}
|
||||
err := f.Write(buf, 3, 6)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setReader(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
})
|
||||
|
||||
It("unpacks ack frames", func() {
|
||||
f := &frames.AckFrame{
|
||||
LargestObserved: 1,
|
||||
DelayTime: 1,
|
||||
DelayTime: time.Microsecond,
|
||||
}
|
||||
err := f.Write(buf, 3, 6)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue