mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
randomize the serialization order of control frames (#4069)
* randomize the serialization order of control frames * add comment for packetPacker.appendPacketPayload
This commit is contained in:
parent
abfe1ef548
commit
a7f807856c
1 changed files with 16 additions and 0 deletions
|
@ -1,9 +1,13 @@
|
||||||
package quic
|
package quic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
crand "crypto/rand"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"golang.org/x/exp/rand"
|
||||||
|
|
||||||
"github.com/quic-go/quic-go/internal/ackhandler"
|
"github.com/quic-go/quic-go/internal/ackhandler"
|
||||||
"github.com/quic-go/quic-go/internal/handshake"
|
"github.com/quic-go/quic-go/internal/handshake"
|
||||||
"github.com/quic-go/quic-go/internal/protocol"
|
"github.com/quic-go/quic-go/internal/protocol"
|
||||||
|
@ -122,6 +126,7 @@ type packetPacker struct {
|
||||||
acks ackFrameSource
|
acks ackFrameSource
|
||||||
datagramQueue *datagramQueue
|
datagramQueue *datagramQueue
|
||||||
retransmissionQueue *retransmissionQueue
|
retransmissionQueue *retransmissionQueue
|
||||||
|
rand rand.Rand
|
||||||
|
|
||||||
numNonAckElicitingAcks int
|
numNonAckElicitingAcks int
|
||||||
}
|
}
|
||||||
|
@ -140,6 +145,9 @@ func newPacketPacker(
|
||||||
datagramQueue *datagramQueue,
|
datagramQueue *datagramQueue,
|
||||||
perspective protocol.Perspective,
|
perspective protocol.Perspective,
|
||||||
) *packetPacker {
|
) *packetPacker {
|
||||||
|
var b [8]byte
|
||||||
|
_, _ = crand.Read(b[:])
|
||||||
|
|
||||||
return &packetPacker{
|
return &packetPacker{
|
||||||
cryptoSetup: cryptoSetup,
|
cryptoSetup: cryptoSetup,
|
||||||
getDestConnID: getDestConnID,
|
getDestConnID: getDestConnID,
|
||||||
|
@ -151,6 +159,7 @@ func newPacketPacker(
|
||||||
perspective: perspective,
|
perspective: perspective,
|
||||||
framer: framer,
|
framer: framer,
|
||||||
acks: acks,
|
acks: acks,
|
||||||
|
rand: *rand.New(rand.NewSource(binary.BigEndian.Uint64(b[:]))),
|
||||||
pnManager: packetNumberManager,
|
pnManager: packetNumberManager,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -832,6 +841,8 @@ func (p *packetPacker) appendShortHeaderPacket(
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// appendPacketPayload serializes the payload of a packet into the raw byte slice.
|
||||||
|
// It modifies the order of payload.frames.
|
||||||
func (p *packetPacker) appendPacketPayload(raw []byte, pl payload, paddingLen protocol.ByteCount, v protocol.VersionNumber) ([]byte, error) {
|
func (p *packetPacker) appendPacketPayload(raw []byte, pl payload, paddingLen protocol.ByteCount, v protocol.VersionNumber) ([]byte, error) {
|
||||||
payloadOffset := len(raw)
|
payloadOffset := len(raw)
|
||||||
if pl.ack != nil {
|
if pl.ack != nil {
|
||||||
|
@ -844,6 +855,11 @@ func (p *packetPacker) appendPacketPayload(raw []byte, pl payload, paddingLen pr
|
||||||
if paddingLen > 0 {
|
if paddingLen > 0 {
|
||||||
raw = append(raw, make([]byte, paddingLen)...)
|
raw = append(raw, make([]byte, paddingLen)...)
|
||||||
}
|
}
|
||||||
|
// Randomize the order of the control frames.
|
||||||
|
// This makes sure that the receiver doesn't rely on the order in which frames are packed.
|
||||||
|
if len(pl.frames) > 1 {
|
||||||
|
p.rand.Shuffle(len(pl.frames), func(i, j int) { pl.frames[i], pl.frames[j] = pl.frames[j], pl.frames[i] })
|
||||||
|
}
|
||||||
for _, f := range pl.frames {
|
for _, f := range pl.frames {
|
||||||
var err error
|
var err error
|
||||||
raw, err = f.Frame.Append(raw, v)
|
raw, err = f.Frame.Append(raw, v)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue