forked from quic-go/quic-go
refactor frame parser to remove version parameter from constructor
This commit is contained in:
@@ -13,11 +13,11 @@ var _ = Describe("Frame parsing", func() {
|
||||
var parser FrameParser
|
||||
|
||||
BeforeEach(func() {
|
||||
parser = NewFrameParser(true, protocol.Version1)
|
||||
parser = NewFrameParser(true)
|
||||
})
|
||||
|
||||
It("returns nil if there's nothing more to read", func() {
|
||||
l, f, err := parser.ParseNext(nil, protocol.Encryption1RTT)
|
||||
l, f, err := parser.ParseNext(nil, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(l).To(BeZero())
|
||||
Expect(f).To(BeNil())
|
||||
@@ -27,14 +27,14 @@ var _ = Describe("Frame parsing", func() {
|
||||
b := []byte{0, 0} // 2 PADDING frames
|
||||
b, err := (&PingFrame{}).Append(b, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(Equal(&PingFrame{}))
|
||||
Expect(l).To(Equal(2 + 1))
|
||||
})
|
||||
|
||||
It("handles PADDING at the end", func() {
|
||||
l, f, err := parser.ParseNext([]byte{0, 0, 0}, protocol.Encryption1RTT)
|
||||
l, f, err := parser.ParseNext([]byte{0, 0, 0}, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(BeNil())
|
||||
Expect(l).To(Equal(3))
|
||||
@@ -47,7 +47,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
b, err = (&PingFrame{}).Append(b, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(BeAssignableToTypeOf(&PingFrame{}))
|
||||
Expect(l).To(Equal(1))
|
||||
@@ -57,7 +57,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 0x13}}}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
@@ -73,7 +73,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
_, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// The ACK frame is always written using the protocol.AckDelayExponent.
|
||||
// That's why we expect a different value when parsing.
|
||||
@@ -88,7 +88,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, frame, err := parser.ParseNext(b, protocol.EncryptionHandshake)
|
||||
_, frame, err := parser.ParseNext(b, protocol.EncryptionHandshake, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.(*AckFrame).DelayTime).To(Equal(time.Second))
|
||||
})
|
||||
@@ -101,7 +101,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -111,7 +111,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &StopSendingFrame{StreamID: 0x42}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -124,7 +124,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
@@ -135,7 +135,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &NewTokenFrame{Token: []byte("foobar")}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
@@ -151,7 +151,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(Equal(f))
|
||||
@@ -164,7 +164,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -177,7 +177,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -190,7 +190,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -200,7 +200,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &DataBlockedFrame{MaximumData: 0x1234}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -213,7 +213,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -226,7 +226,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -240,7 +240,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -250,7 +250,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &RetireConnectionIDFrame{SequenceNumber: 0x1337}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -260,7 +260,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &PathChallengeFrame{Data: [8]byte{1, 2, 3, 4, 5, 6, 7, 8}}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
@@ -272,7 +272,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &PathResponseFrame{Data: [8]byte{1, 2, 3, 4, 5, 6, 7, 8}}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).ToNot(BeNil())
|
||||
Expect(frame).To(BeAssignableToTypeOf(f))
|
||||
@@ -287,7 +287,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -297,7 +297,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &HandshakeDoneFrame{}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
@@ -307,18 +307,18 @@ var _ = Describe("Frame parsing", func() {
|
||||
f := &DatagramFrame{Data: []byte("foobar")}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(Equal(f))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
})
|
||||
|
||||
It("errors when DATAGRAM frames are not supported", func() {
|
||||
parser = NewFrameParser(false, protocol.Version1)
|
||||
parser = NewFrameParser(false)
|
||||
f := &DatagramFrame{Data: []byte("foobar")}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, _, err = parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
_, _, err = parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).To(MatchError(&qerr.TransportError{
|
||||
ErrorCode: qerr.FrameEncodingError,
|
||||
FrameType: 0x30,
|
||||
@@ -327,7 +327,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
})
|
||||
|
||||
It("errors on invalid type", func() {
|
||||
_, _, err := parser.ParseNext([]byte{0x42}, protocol.Encryption1RTT)
|
||||
_, _, err := parser.ParseNext([]byte{0x42}, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).To(MatchError(&qerr.TransportError{
|
||||
ErrorCode: qerr.FrameEncodingError,
|
||||
FrameType: 0x42,
|
||||
@@ -342,7 +342,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
}
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, _, err = parser.ParseNext(b[:len(b)-2], protocol.Encryption1RTT)
|
||||
_, _, err = parser.ParseNext(b[:len(b)-2], protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.(*qerr.TransportError).ErrorCode).To(Equal(qerr.FrameEncodingError))
|
||||
})
|
||||
@@ -384,7 +384,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
|
||||
It("rejects all frames but ACK, CRYPTO, PING and CONNECTION_CLOSE in Initial packets", func() {
|
||||
for i, b := range framesSerialized {
|
||||
_, _, err := parser.ParseNext(b, protocol.EncryptionInitial)
|
||||
_, _, err := parser.ParseNext(b, protocol.EncryptionInitial, protocol.Version1)
|
||||
switch frames[i].(type) {
|
||||
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *PingFrame:
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -398,7 +398,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
|
||||
It("rejects all frames but ACK, CRYPTO, PING and CONNECTION_CLOSE in Handshake packets", func() {
|
||||
for i, b := range framesSerialized {
|
||||
_, _, err := parser.ParseNext(b, protocol.EncryptionHandshake)
|
||||
_, _, err := parser.ParseNext(b, protocol.EncryptionHandshake, protocol.Version1)
|
||||
switch frames[i].(type) {
|
||||
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *PingFrame:
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -412,7 +412,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
|
||||
It("rejects all frames but ACK, CRYPTO, CONNECTION_CLOSE, NEW_TOKEN, PATH_RESPONSE and RETIRE_CONNECTION_ID in 0-RTT packets", func() {
|
||||
for i, b := range framesSerialized {
|
||||
_, _, err := parser.ParseNext(b, protocol.Encryption0RTT)
|
||||
_, _, err := parser.ParseNext(b, protocol.Encryption0RTT, protocol.Version1)
|
||||
switch frames[i].(type) {
|
||||
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *NewTokenFrame, *PathResponseFrame, *RetireConnectionIDFrame:
|
||||
Expect(err).To(BeAssignableToTypeOf(&qerr.TransportError{}))
|
||||
@@ -426,7 +426,7 @@ var _ = Describe("Frame parsing", func() {
|
||||
|
||||
It("accepts all frame types in 1-RTT packets", func() {
|
||||
for _, b := range framesSerialized {
|
||||
_, _, err := parser.ParseNext(b, protocol.Encryption1RTT)
|
||||
_, _, err := parser.ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user