use a single bytes.Reader for frame parsing (#3536)

This commit is contained in:
Marten Seemann 2022-09-01 11:06:50 +03:00 committed by GitHub
parent 93e1d031b9
commit dfd35cb071
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 104 additions and 61 deletions

View file

@ -1286,12 +1286,12 @@ func (s *connection) handleFrames(
// Only used for tracing.
// If we're not tracing, this slice will always remain empty.
var frames []wire.Frame
r := bytes.NewReader(data)
for {
frame, err := s.frameParser.ParseNext(r, encLevel)
for len(data) > 0 {
l, frame, err := s.frameParser.ParseNext(data, encLevel)
if err != nil {
return false, err
}
data = data[l:]
if frame == nil {
break
}

View file

@ -1,7 +1,6 @@
package frames
import (
"bytes"
"fmt"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -37,19 +36,19 @@ func Fuzz(data []byte) int {
parser := wire.NewFrameParser(true, version)
parser.SetAckDelayExponent(protocol.DefaultAckDelayExponent)
r := bytes.NewReader(data)
initialLen := r.Len()
initialLen := len(data)
var frames []wire.Frame
for r.Len() > 0 {
f, err := parser.ParseNext(r, encLevel)
for len(data) > 0 {
l, f, err := parser.ParseNext(data, encLevel)
if err != nil {
break
}
data = data[l:]
frames = append(frames, f)
}
parsedLen := initialLen - r.Len()
parsedLen := initialLen - len(data)
if len(frames) == 0 {
return 0

View file

@ -11,6 +11,8 @@ import (
)
type frameParser struct {
r bytes.Reader // cached bytes.Reader, so we don't have to repeatedly allocate them
ackDelayExponent uint8
supportsDatagrams bool
@ -21,6 +23,7 @@ type frameParser struct {
// NewFrameParser creates a new frame parser.
func NewFrameParser(supportsDatagrams bool, v protocol.VersionNumber) FrameParser {
return &frameParser{
r: *bytes.NewReader(nil),
supportsDatagrams: supportsDatagrams,
version: v,
}
@ -28,9 +31,18 @@ func NewFrameParser(supportsDatagrams bool, v protocol.VersionNumber) FrameParse
// ParseNext parses the next frame.
// It skips PADDING frames.
func (p *frameParser) ParseNext(r *bytes.Reader, encLevel protocol.EncryptionLevel) (Frame, error) {
func (p *frameParser) ParseNext(data []byte, encLevel protocol.EncryptionLevel) (int, Frame, error) {
startLen := len(data)
p.r.Reset(data)
frame, err := p.parseNext(&p.r, encLevel)
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) {
for r.Len() != 0 {
typeByte, _ := r.ReadByte()
typeByte, _ := p.r.ReadByte()
if typeByte == 0x0 { // PADDING frame
continue
}

View file

@ -1,7 +1,6 @@
package wire
import (
"bytes"
"time"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -18,37 +17,52 @@ var _ = Describe("Frame parsing", func() {
})
It("returns nil if there's nothing more to read", func() {
f, err := parser.ParseNext(bytes.NewReader(nil), protocol.Encryption1RTT)
l, f, err := parser.ParseNext(nil, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(l).To(BeZero())
Expect(f).To(BeNil())
})
It("skips PADDING frames", func() {
b := []byte{0} // PADDING frame
b := []byte{0, 0} // 2 PADDING frames
b, err := (&PingFrame{}).Append(b, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
f, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(f).To(Equal(&PingFrame{}))
Expect(l).To(Equal(2 + 1))
})
It("handles PADDING at the end", func() {
r := bytes.NewReader([]byte{0, 0, 0})
f, err := parser.ParseNext(r, protocol.Encryption1RTT)
l, f, err := parser.ParseNext([]byte{0, 0, 0}, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(f).To(BeNil())
Expect(r.Len()).To(BeZero())
Expect(l).To(Equal(3))
})
It("parses a single frame", func() {
var b []byte
for i := 0; i < 10; i++ {
var err error
b, err = (&PingFrame{}).Append(b, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
}
l, f, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(f).To(BeAssignableToTypeOf(&PingFrame{}))
Expect(l).To(Equal(1))
})
It("unpacks ACK frames", func() {
f := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 0x13}}}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(BeAssignableToTypeOf(f))
Expect(frame.(*AckFrame).LargestAcked()).To(Equal(protocol.PacketNumber(0x13)))
Expect(l).To(Equal(len(b)))
})
It("uses the custom ack delay exponent for 1RTT packets", func() {
@ -59,7 +73,7 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
_, frame, err := parser.ParseNext(b, 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.
@ -74,7 +88,7 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.EncryptionHandshake)
_, frame, err := parser.ParseNext(b, protocol.EncryptionHandshake)
Expect(err).ToNot(HaveOccurred())
Expect(frame.(*AckFrame).DelayTime).To(Equal(time.Second))
})
@ -87,18 +101,20 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks STOP_SENDING frames", func() {
f := &StopSendingFrame{StreamID: 0x42}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks CRYPTO frames", func() {
@ -108,20 +124,22 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks NEW_TOKEN frames", func() {
f := &NewTokenFrame{Token: []byte("foobar")}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks STREAM frames", func() {
@ -133,10 +151,11 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks MAX_DATA frames", func() {
@ -145,9 +164,10 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks MAX_STREAM_DATA frames", func() {
@ -157,9 +177,10 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks MAX_STREAMS frames", func() {
@ -169,18 +190,20 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks DATA_BLOCKED frames", func() {
f := &DataBlockedFrame{MaximumData: 0x1234}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks STREAM_DATA_BLOCKED frames", func() {
@ -190,9 +213,10 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks STREAMS_BLOCKED frames", func() {
@ -202,9 +226,10 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks NEW_CONNECTION_ID frames", func() {
@ -215,40 +240,44 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks RETIRE_CONNECTION_ID frames", func() {
f := &RetireConnectionIDFrame{SequenceNumber: 0x1337}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks PATH_CHALLENGE frames", 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())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(BeAssignableToTypeOf(f))
Expect(frame.(*PathChallengeFrame).Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
Expect(l).To(Equal(len(b)))
})
It("unpacks PATH_RESPONSE frames", 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())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(BeAssignableToTypeOf(f))
Expect(frame.(*PathResponseFrame).Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
Expect(l).To(Equal(len(b)))
})
It("unpacks CONNECTION_CLOSE frames", func() {
@ -258,27 +287,30 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks HANDSHAKE_DONE frames", func() {
f := &HandshakeDoneFrame{}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("unpacks DATAGRAM frames", func() {
f := &DatagramFrame{Data: []byte("foobar")}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
frame, err := parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
l, frame, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
Expect(l).To(Equal(len(b)))
})
It("errors when DATAGRAM frames are not supported", func() {
@ -286,7 +318,7 @@ var _ = Describe("Frame parsing", func() {
f := &DatagramFrame{Data: []byte("foobar")}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
_, err = parser.ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
_, _, err = parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.FrameEncodingError,
FrameType: 0x30,
@ -295,7 +327,7 @@ var _ = Describe("Frame parsing", func() {
})
It("errors on invalid type", func() {
_, err := parser.ParseNext(bytes.NewReader([]byte{0x42}), protocol.Encryption1RTT)
_, _, err := parser.ParseNext([]byte{0x42}, protocol.Encryption1RTT)
Expect(err).To(MatchError(&qerr.TransportError{
ErrorCode: qerr.FrameEncodingError,
FrameType: 0x42,
@ -310,7 +342,7 @@ var _ = Describe("Frame parsing", func() {
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
_, err = parser.ParseNext(bytes.NewReader(b[:len(b)-2]), protocol.Encryption1RTT)
_, _, err = parser.ParseNext(b[:len(b)-2], protocol.Encryption1RTT)
Expect(err).To(HaveOccurred())
Expect(err.(*qerr.TransportError).ErrorCode).To(Equal(qerr.FrameEncodingError))
})
@ -352,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(bytes.NewReader(b), protocol.EncryptionInitial)
_, _, err := parser.ParseNext(b, protocol.EncryptionInitial)
switch frames[i].(type) {
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *PingFrame:
Expect(err).ToNot(HaveOccurred())
@ -366,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(bytes.NewReader(b), protocol.EncryptionHandshake)
_, _, err := parser.ParseNext(b, protocol.EncryptionHandshake)
switch frames[i].(type) {
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *PingFrame:
Expect(err).ToNot(HaveOccurred())
@ -380,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(bytes.NewReader(b), protocol.Encryption0RTT)
_, _, err := parser.ParseNext(b, protocol.Encryption0RTT)
switch frames[i].(type) {
case *AckFrame, *ConnectionCloseFrame, *CryptoFrame, *NewTokenFrame, *PathResponseFrame, *RetireConnectionIDFrame:
Expect(err).To(BeAssignableToTypeOf(&qerr.TransportError{}))
@ -394,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(bytes.NewReader(b), protocol.Encryption1RTT)
_, _, err := parser.ParseNext(b, protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
}
})

View file

@ -1,8 +1,6 @@
package wire
import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
)
@ -14,6 +12,6 @@ type Frame interface {
// A FrameParser parses QUIC frames, one by one.
type FrameParser interface {
ParseNext(*bytes.Reader, protocol.EncryptionLevel) (Frame, error)
ParseNext([]byte, protocol.EncryptionLevel) (int, Frame, error)
SetAckDelayExponent(uint8)
}

View file

@ -618,7 +618,8 @@ var _ = Describe("Packet packer", func() {
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, packer.getDestConnID().Len())
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(packet.buffer.Data)
data := packet.buffer.Data
r := bytes.NewReader(data)
extHdr, err := hdr.ParseExtended(r, packer.version)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen1))
@ -632,10 +633,10 @@ var _ = Describe("Packet packer", func() {
Expect(secondPayloadByte).To(Equal(byte(0)))
// ... followed by the PING
frameParser := wire.NewFrameParser(false, packer.version)
frame, err := frameParser.ParseNext(r, protocol.Encryption1RTT)
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(BeAssignableToTypeOf(&wire.PingFrame{}))
Expect(r.Len()).To(Equal(sealer.Overhead()))
Expect(r.Len() - l).To(Equal(sealer.Overhead()))
})
It("pads if payload length + packet number length is smaller than 4", func() {
@ -658,7 +659,8 @@ var _ = Describe("Packet packer", func() {
packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, packer.getDestConnID().Len())
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(packet.buffer.Data)
data := packet.buffer.Data
r := bytes.NewReader(data)
extHdr, err := hdr.ParseExtended(r, packer.version)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen1))
@ -669,14 +671,14 @@ var _ = Describe("Packet packer", func() {
Expect(firstPayloadByte).To(Equal(byte(0)))
// ... followed by the STREAM frame
frameParser := wire.NewFrameParser(true, packer.version)
frame, err := frameParser.ParseNext(r, protocol.Encryption1RTT)
l, frame, err := frameParser.ParseNext(packet.buffer.Data[len(data)-r.Len():], protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(BeAssignableToTypeOf(&wire.StreamFrame{}))
sf := frame.(*wire.StreamFrame)
Expect(sf.StreamID).To(Equal(f.StreamID))
Expect(sf.Fin).To(Equal(f.Fin))
Expect(sf.Data).To(BeEmpty())
Expect(r.Len()).To(BeZero())
Expect(r.Len() - l).To(BeZero())
})
It("packs multiple small STREAM frames into single packet", func() {
@ -1208,7 +1210,8 @@ var _ = Describe("Packet packer", func() {
// packet.buffer.Data = packet.buffer.Data[:packet.buffer.Len()-protocol.ByteCount(sealer.Overhead())]
hdr, _, _, err := wire.ParsePacket(packet.buffer.Data, packer.getDestConnID().Len())
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(packet.buffer.Data)
data := packet.buffer.Data
r := bytes.NewReader(data)
extHdr, err := hdr.ParseExtended(r, packer.version)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen1))
@ -1222,10 +1225,10 @@ var _ = Describe("Packet packer", func() {
Expect(secondPayloadByte).To(Equal(byte(0)))
// ... followed by the PING
frameParser := wire.NewFrameParser(false, packer.version)
frame, err := frameParser.ParseNext(r, protocol.Encryption1RTT)
l, frame, err := frameParser.ParseNext(data[len(data)-r.Len():], protocol.Encryption1RTT)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(BeAssignableToTypeOf(&wire.PingFrame{}))
Expect(r.Len()).To(Equal(sealer.Overhead()))
Expect(r.Len() - l).To(Equal(sealer.Overhead()))
})
It("adds retransmissions", func() {

View file

@ -762,7 +762,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(bytes.NewReader(data), protocol.EncryptionInitial)
_, f, err := wire.NewFrameParser(false, origHdr.Version).ParseNext(data, protocol.EncryptionInitial)
Expect(err).ToNot(HaveOccurred())
Expect(f).To(BeAssignableToTypeOf(&wire.ConnectionCloseFrame{}))
ccf := f.(*wire.ConnectionCloseFrame)

View file

@ -1,7 +1,6 @@
package quic
import (
"bytes"
"context"
"errors"
"math/rand"
@ -45,7 +44,7 @@ var _ = Describe("Streams Map (incoming)", func() {
checkFrameSerialization := func(f wire.Frame) {
b, err := f.Append(nil, protocol.VersionTLS)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
frame, err := wire.NewFrameParser(false, protocol.VersionTLS).ParseNext(bytes.NewReader(b), protocol.Encryption1RTT)
_, frame, err := wire.NewFrameParser(false, protocol.VersionTLS).ParseNext(b, protocol.Encryption1RTT)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
Expect(f).To(Equal(frame))
}