mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 13:17:36 +03:00
use the ack_delay_exponent sent in the transport parameters
This commit is contained in:
parent
155ebd18a2
commit
cebb4342ec
5 changed files with 68 additions and 29 deletions
|
@ -2,6 +2,7 @@ package wire
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/qerr"
|
||||
|
@ -21,7 +22,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
})
|
||||
|
||||
It("returns nil if there's nothing more to read", func() {
|
||||
f, err := parser.ParseNext(bytes.NewReader(nil))
|
||||
f, err := parser.ParseNext(bytes.NewReader(nil), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(BeNil())
|
||||
})
|
||||
|
@ -29,14 +30,14 @@ var _ = Describe("Frame parsing", func() {
|
|||
It("skips PADDING frames", func() {
|
||||
buf.Write([]byte{0}) // PADDING frame
|
||||
(&PingFrame{}).Write(buf, versionIETFFrames)
|
||||
f, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
f, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(Equal(&PingFrame{}))
|
||||
})
|
||||
|
||||
It("handles PADDING at the end", func() {
|
||||
r := bytes.NewReader([]byte{0, 0, 0})
|
||||
f, err := parser.ParseNext(r)
|
||||
f, err := parser.ParseNext(r, protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(BeNil())
|
||||
Expect(r.Len()).To(BeZero())
|
||||
|
@ -46,13 +47,39 @@ var _ = Describe("Frame parsing", func() {
|
|||
f := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 0x13}}}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
Expect(frame.(*AckFrame).LargestAcked()).To(Equal(protocol.PacketNumber(0x13)))
|
||||
})
|
||||
|
||||
It("uses the custom ack delay exponent for 1RTT packets", func() {
|
||||
parser.SetAckDelayExponent(protocol.AckDelayExponent + 2)
|
||||
f := &AckFrame{
|
||||
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
|
||||
DelayTime: time.Second,
|
||||
}
|
||||
Expect(f.Write(buf, versionIETFFrames)).To(Succeed())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// The ACK frame is always written using the protocol.AckDelayExponent.
|
||||
// That's why we expect a different value when parsing.
|
||||
Expect(frame.(*AckFrame).DelayTime).To(Equal(4 * time.Second))
|
||||
})
|
||||
|
||||
It("uses the default ack delay exponent for non-1RTT packets", func() {
|
||||
parser.SetAckDelayExponent(protocol.AckDelayExponent + 2)
|
||||
f := &AckFrame{
|
||||
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
|
||||
DelayTime: time.Second,
|
||||
}
|
||||
Expect(f.Write(buf, versionIETFFrames)).To(Succeed())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.EncryptionHandshake)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.(*AckFrame).DelayTime).To(Equal(time.Second))
|
||||
})
|
||||
|
||||
It("unpacks RESET_STREAM frames", func() {
|
||||
f := &ResetStreamFrame{
|
||||
StreamID: 0xdeadbeef,
|
||||
|
@ -61,7 +88,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -71,7 +98,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -83,7 +110,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
|
@ -93,7 +120,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
f := &NewTokenFrame{Token: []byte("foobar")}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
|
@ -108,7 +135,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
|
@ -121,7 +148,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -134,7 +161,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -147,7 +174,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -157,7 +184,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -169,7 +196,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -182,7 +209,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -195,7 +222,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
buf := &bytes.Buffer{}
|
||||
Expect(f.Write(buf, versionIETFFrames)).To(Succeed())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -204,7 +231,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
f := &RetireConnectionIDFrame{SequenceNumber: 0x1337}
|
||||
buf := &bytes.Buffer{}
|
||||
Expect(f.Write(buf, versionIETFFrames)).To(Succeed())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
@ -213,7 +240,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
f := &PathChallengeFrame{Data: [8]byte{1, 2, 3, 4, 5, 6, 7, 8}}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
|
@ -224,7 +251,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
f := &PathResponseFrame{Data: [8]byte{1, 2, 3, 4, 5, 6, 7, 8}}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
|
@ -239,13 +266,13 @@ var _ = Describe("Frame parsing", func() {
|
|||
buf := &bytes.Buffer{}
|
||||
err := f.Write(buf, versionIETFFrames)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()))
|
||||
frame, err := parser.ParseNext(bytes.NewReader(buf.Bytes()), protocol.Encryption1RTT)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
})
|
||||
|
||||
It("errors on invalid type", func() {
|
||||
_, err := parser.ParseNext(bytes.NewReader([]byte{0x42}))
|
||||
_, err := parser.ParseNext(bytes.NewReader([]byte{0x42}), protocol.Encryption1RTT)
|
||||
Expect(err).To(MatchError("InvalidFrameData: unknown type byte 0x42"))
|
||||
})
|
||||
|
||||
|
@ -256,7 +283,7 @@ var _ = Describe("Frame parsing", func() {
|
|||
}
|
||||
b := &bytes.Buffer{}
|
||||
f.Write(b, versionIETFFrames)
|
||||
_, err := parser.ParseNext(bytes.NewReader(b.Bytes()[:b.Len()-2]))
|
||||
_, err := parser.ParseNext(bytes.NewReader(b.Bytes()[:b.Len()-2]), protocol.Encryption1RTT)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidFrameData))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue