mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
refactor frame parser to remove version parameter from constructor
This commit is contained in:
parent
582edae63d
commit
ef28f4667f
8 changed files with 76 additions and 77 deletions
|
@ -508,7 +508,7 @@ var newClientConnection = func(
|
|||
func (s *connection) preSetup() {
|
||||
s.sendQueue = newSendQueue(s.conn)
|
||||
s.retransmissionQueue = newRetransmissionQueue()
|
||||
s.frameParser = wire.NewFrameParser(s.config.EnableDatagrams, s.version)
|
||||
s.frameParser = wire.NewFrameParser(s.config.EnableDatagrams)
|
||||
s.rttStats = &utils.RTTStats{}
|
||||
s.connFlowController = flowcontrol.NewConnectionFlowController(
|
||||
protocol.ByteCount(s.config.InitialConnectionReceiveWindow),
|
||||
|
@ -1284,7 +1284,7 @@ func (s *connection) handleFrames(
|
|||
// If we're not tracing, this slice will always remain empty.
|
||||
var frames []wire.Frame
|
||||
for len(data) > 0 {
|
||||
l, frame, err := s.frameParser.ParseNext(data, encLevel)
|
||||
l, frame, err := s.frameParser.ParseNext(data, encLevel, s.version)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func Fuzz(data []byte) int {
|
|||
encLevel := toEncLevel(data[0])
|
||||
data = data[PrefixLen:]
|
||||
|
||||
parser := wire.NewFrameParser(true, version)
|
||||
parser := wire.NewFrameParser(true)
|
||||
parser.SetAckDelayExponent(protocol.DefaultAckDelayExponent)
|
||||
|
||||
initialLen := len(data)
|
||||
|
@ -41,7 +41,7 @@ func Fuzz(data []byte) int {
|
|||
var frames []wire.Frame
|
||||
|
||||
for len(data) > 0 {
|
||||
l, f, err := parser.ParseNext(data, encLevel)
|
||||
l, f, err := parser.ParseNext(data, encLevel, version)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -16,31 +16,30 @@ type frameParser struct {
|
|||
ackDelayExponent uint8
|
||||
|
||||
supportsDatagrams bool
|
||||
|
||||
version protocol.VersionNumber
|
||||
}
|
||||
|
||||
var _ FrameParser = &frameParser{}
|
||||
|
||||
// NewFrameParser creates a new frame parser.
|
||||
func NewFrameParser(supportsDatagrams bool, v protocol.VersionNumber) FrameParser {
|
||||
func NewFrameParser(supportsDatagrams bool) *frameParser {
|
||||
return &frameParser{
|
||||
r: *bytes.NewReader(nil),
|
||||
supportsDatagrams: supportsDatagrams,
|
||||
version: v,
|
||||
}
|
||||
}
|
||||
|
||||
// ParseNext parses the next frame.
|
||||
// It skips PADDING frames.
|
||||
func (p *frameParser) ParseNext(data []byte, encLevel protocol.EncryptionLevel) (int, Frame, error) {
|
||||
func (p *frameParser) ParseNext(data []byte, encLevel protocol.EncryptionLevel, v protocol.VersionNumber) (int, Frame, error) {
|
||||
startLen := len(data)
|
||||
p.r.Reset(data)
|
||||
frame, err := p.parseNext(&p.r, encLevel)
|
||||
frame, err := p.parseNext(&p.r, encLevel, v)
|
||||
n := startLen - p.r.Len()
|
||||
p.r.Reset(nil)
|
||||
return n, frame, err
|
||||
}
|
||||
|
||||
func (p *frameParser) parseNext(r *bytes.Reader, encLevel protocol.EncryptionLevel) (Frame, error) {
|
||||
func (p *frameParser) parseNext(r *bytes.Reader, encLevel protocol.EncryptionLevel, v protocol.VersionNumber) (Frame, error) {
|
||||
for r.Len() != 0 {
|
||||
typeByte, _ := p.r.ReadByte()
|
||||
if typeByte == 0x0 { // PADDING frame
|
||||
|
@ -48,7 +47,7 @@ func (p *frameParser) parseNext(r *bytes.Reader, encLevel protocol.EncryptionLev
|
|||
}
|
||||
r.UnreadByte()
|
||||
|
||||
f, err := p.parseFrame(r, typeByte, encLevel)
|
||||
f, err := p.parseFrame(r, typeByte, encLevel, v)
|
||||
if err != nil {
|
||||
return nil, &qerr.TransportError{
|
||||
FrameType: uint64(typeByte),
|
||||
|
@ -61,56 +60,56 @@ func (p *frameParser) parseNext(r *bytes.Reader, encLevel protocol.EncryptionLev
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (p *frameParser) parseFrame(r *bytes.Reader, typeByte byte, encLevel protocol.EncryptionLevel) (Frame, error) {
|
||||
func (p *frameParser) parseFrame(r *bytes.Reader, typeByte byte, encLevel protocol.EncryptionLevel, v protocol.VersionNumber) (Frame, error) {
|
||||
var frame Frame
|
||||
var err error
|
||||
if typeByte&0xf8 == 0x8 {
|
||||
frame, err = parseStreamFrame(r, p.version)
|
||||
frame, err = parseStreamFrame(r, v)
|
||||
} else {
|
||||
switch typeByte {
|
||||
case 0x1:
|
||||
frame, err = parsePingFrame(r, p.version)
|
||||
frame, err = parsePingFrame(r, v)
|
||||
case 0x2, 0x3:
|
||||
ackDelayExponent := p.ackDelayExponent
|
||||
if encLevel != protocol.Encryption1RTT {
|
||||
ackDelayExponent = protocol.DefaultAckDelayExponent
|
||||
}
|
||||
frame, err = parseAckFrame(r, ackDelayExponent, p.version)
|
||||
frame, err = parseAckFrame(r, ackDelayExponent, v)
|
||||
case 0x4:
|
||||
frame, err = parseResetStreamFrame(r, p.version)
|
||||
frame, err = parseResetStreamFrame(r, v)
|
||||
case 0x5:
|
||||
frame, err = parseStopSendingFrame(r, p.version)
|
||||
frame, err = parseStopSendingFrame(r, v)
|
||||
case 0x6:
|
||||
frame, err = parseCryptoFrame(r, p.version)
|
||||
frame, err = parseCryptoFrame(r, v)
|
||||
case 0x7:
|
||||
frame, err = parseNewTokenFrame(r, p.version)
|
||||
frame, err = parseNewTokenFrame(r, v)
|
||||
case 0x10:
|
||||
frame, err = parseMaxDataFrame(r, p.version)
|
||||
frame, err = parseMaxDataFrame(r, v)
|
||||
case 0x11:
|
||||
frame, err = parseMaxStreamDataFrame(r, p.version)
|
||||
frame, err = parseMaxStreamDataFrame(r, v)
|
||||
case 0x12, 0x13:
|
||||
frame, err = parseMaxStreamsFrame(r, p.version)
|
||||
frame, err = parseMaxStreamsFrame(r, v)
|
||||
case 0x14:
|
||||
frame, err = parseDataBlockedFrame(r, p.version)
|
||||
frame, err = parseDataBlockedFrame(r, v)
|
||||
case 0x15:
|
||||
frame, err = parseStreamDataBlockedFrame(r, p.version)
|
||||
frame, err = parseStreamDataBlockedFrame(r, v)
|
||||
case 0x16, 0x17:
|
||||
frame, err = parseStreamsBlockedFrame(r, p.version)
|
||||
frame, err = parseStreamsBlockedFrame(r, v)
|
||||
case 0x18:
|
||||
frame, err = parseNewConnectionIDFrame(r, p.version)
|
||||
frame, err = parseNewConnectionIDFrame(r, v)
|
||||
case 0x19:
|
||||
frame, err = parseRetireConnectionIDFrame(r, p.version)
|
||||
frame, err = parseRetireConnectionIDFrame(r, v)
|
||||
case 0x1a:
|
||||
frame, err = parsePathChallengeFrame(r, p.version)
|
||||
frame, err = parsePathChallengeFrame(r, v)
|
||||
case 0x1b:
|
||||
frame, err = parsePathResponseFrame(r, p.version)
|
||||
frame, err = parsePathResponseFrame(r, v)
|
||||
case 0x1c, 0x1d:
|
||||
frame, err = parseConnectionCloseFrame(r, p.version)
|
||||
frame, err = parseConnectionCloseFrame(r, v)
|
||||
case 0x1e:
|
||||
frame, err = parseHandshakeDoneFrame(r, p.version)
|
||||
frame, err = parseHandshakeDoneFrame(r, v)
|
||||
case 0x30, 0x31:
|
||||
if p.supportsDatagrams {
|
||||
frame, err = parseDatagramFrame(r, p.version)
|
||||
frame, err = parseDatagramFrame(r, v)
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
})
|
||||
|
|
|
@ -12,6 +12,6 @@ type Frame interface {
|
|||
|
||||
// A FrameParser parses QUIC frames, one by one.
|
||||
type FrameParser interface {
|
||||
ParseNext([]byte, protocol.EncryptionLevel) (int, Frame, error)
|
||||
ParseNext([]byte, protocol.EncryptionLevel, protocol.VersionNumber) (int, Frame, error)
|
||||
SetAckDelayExponent(uint8)
|
||||
}
|
||||
|
|
|
@ -672,8 +672,8 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(secondPayloadByte).To(Equal(byte(0)))
|
||||
// ... followed by the PING
|
||||
frameParser := wire.NewFrameParser(false, packer.version)
|
||||
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT)
|
||||
frameParser := wire.NewFrameParser(false)
|
||||
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT, packer.version)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(BeAssignableToTypeOf(&wire.PingFrame{}))
|
||||
Expect(r.Len() - l).To(Equal(sealer.Overhead()))
|
||||
|
@ -708,8 +708,8 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(firstPayloadByte).To(Equal(byte(0)))
|
||||
// ... followed by the STREAM frame
|
||||
frameParser := wire.NewFrameParser(true, packer.version)
|
||||
l, frame, err := frameParser.ParseNext(buffer.Data[len(data)-r.Len():], protocol.Encryption1RTT)
|
||||
frameParser := wire.NewFrameParser(true)
|
||||
l, frame, err := frameParser.ParseNext(buffer.Data[len(data)-r.Len():], protocol.Encryption1RTT, packer.version)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(BeAssignableToTypeOf(&wire.StreamFrame{}))
|
||||
sf := frame.(*wire.StreamFrame)
|
||||
|
@ -1268,8 +1268,8 @@ var _ = Describe("Packet packer", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(secondPayloadByte).To(Equal(byte(0)))
|
||||
// ... followed by the PING
|
||||
frameParser := wire.NewFrameParser(false, packer.version)
|
||||
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT)
|
||||
frameParser := wire.NewFrameParser(false)
|
||||
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT, packer.version)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame).To(BeAssignableToTypeOf(&wire.PingFrame{}))
|
||||
Expect(r.Len() - l).To(Equal(sealer.Overhead()))
|
||||
|
|
|
@ -743,7 +743,7 @@ var _ = Describe("Server", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
data, err := opener.Open(nil, b[extHdr.ParsedLen():], extHdr.PacketNumber, b[:extHdr.ParsedLen()])
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, f, err := wire.NewFrameParser(false, origHdr.Version).ParseNext(data, protocol.EncryptionInitial)
|
||||
_, f, err := wire.NewFrameParser(false).ParseNext(data, protocol.EncryptionInitial, origHdr.Version)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(f).To(BeAssignableToTypeOf(&wire.ConnectionCloseFrame{}))
|
||||
ccf := f.(*wire.ConnectionCloseFrame)
|
||||
|
|
|
@ -42,9 +42,9 @@ var _ = Describe("Streams Map (incoming)", func() {
|
|||
|
||||
// check that the frame can be serialized and deserialized
|
||||
checkFrameSerialization := func(f wire.Frame) {
|
||||
b, err := f.Append(nil, protocol.VersionTLS)
|
||||
b, err := f.Append(nil, protocol.Version1)
|
||||
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
||||
_, frame, err := wire.NewFrameParser(false, protocol.VersionTLS).ParseNext(b, protocol.Encryption1RTT)
|
||||
_, frame, err := wire.NewFrameParser(false).ParseNext(b, protocol.Encryption1RTT, protocol.Version1)
|
||||
ExpectWithOffset(1, err).ToNot(HaveOccurred())
|
||||
Expect(f).To(Equal(frame))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue