mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
refactor header writing to append to a byte slice (#3646)
This avoids having to allocate a bytes.Buffer.
This commit is contained in:
parent
3d4bbc28ba
commit
c24fbb094c
18 changed files with 282 additions and 279 deletions
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
||||
|
@ -85,28 +84,28 @@ func main() {
|
|||
PacketNumberLen: protocol.PacketNumberLen(rand.Intn(4) + 1),
|
||||
PacketNumber: protocol.PacketNumber(rand.Uint64()),
|
||||
}
|
||||
b := &bytes.Buffer{}
|
||||
if err := extHdr.Write(b, version); err != nil {
|
||||
b, err := extHdr.Append(nil, version)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if h.Type == protocol.PacketTypeRetry {
|
||||
b.Write([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
|
||||
b = append(b, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}...)
|
||||
}
|
||||
if h.Length > 0 {
|
||||
b.Write(make([]byte, h.Length))
|
||||
b = append(b, make([]byte, h.Length)...)
|
||||
}
|
||||
|
||||
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), header.PrefixLen); err != nil {
|
||||
if err := helper.WriteCorpusFileWithPrefix("corpus", b, header.PrefixLen); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// short header
|
||||
b := &bytes.Buffer{}
|
||||
if err := wire.WriteShortHeader(b, protocol.ParseConnectionID(getRandomData(8)), 1337, protocol.PacketNumberLen2, protocol.KeyPhaseOne); err != nil {
|
||||
b, err := wire.AppendShortHeader(nil, protocol.ParseConnectionID(getRandomData(8)), 1337, protocol.PacketNumberLen2, protocol.KeyPhaseOne)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), header.PrefixLen); err != nil {
|
||||
if err := helper.WriteCorpusFileWithPrefix("corpus", b, header.PrefixLen); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ func Fuzz(data []byte) int {
|
|||
if hdr.Length > 16383 {
|
||||
return 1
|
||||
}
|
||||
b := &bytes.Buffer{}
|
||||
if err := extHdr.Write(b, version); err != nil {
|
||||
b, err := extHdr.Append(nil, version)
|
||||
if err != nil {
|
||||
// We are able to parse packets with connection IDs longer than 20 bytes,
|
||||
// but in QUIC version 1, we don't write headers with longer connection IDs.
|
||||
if hdr.DestConnectionID.Len() <= protocol.MaxConnIDLen &&
|
||||
|
@ -76,8 +76,8 @@ func Fuzz(data []byte) int {
|
|||
}
|
||||
// GetLength is not implemented for Retry packets
|
||||
if hdr.Type != protocol.PacketTypeRetry {
|
||||
if expLen := extHdr.GetLength(version); expLen != protocol.ByteCount(b.Len()) {
|
||||
panic(fmt.Sprintf("inconsistent header length: %#v. Expected %d, got %d", extHdr, expLen, b.Len()))
|
||||
if expLen := extHdr.GetLength(version); expLen != protocol.ByteCount(len(b)) {
|
||||
panic(fmt.Sprintf("inconsistent header length: %#v. Expected %d, got %d", extHdr, expLen, len(b)))
|
||||
}
|
||||
}
|
||||
return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue