Skip to content

Commit

Permalink
fix: poorly named qtps (#215)
Browse files Browse the repository at this point in the history
- Rename GREASE to GREASETransportParameter.
- Rename Padding to PaddingTransportParameter.
- Adding GREASE QTP ID check against `id >= 27`. Otherwise `max_ack_delay = 11` will be incorrectly recognized as a GREASE value.
  • Loading branch information
gaukas committed Aug 9, 2023
1 parent 30a2200 commit 2ae5748
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions u_quic_transport_parameters.go
Expand Up @@ -61,7 +61,7 @@ type TransportParameter interface {
Value() []byte
}

type GREASE struct {
type GREASETransportParameter struct {
IdOverride uint64 // if set to a valid GREASE ID, use this instead of randomly generated one.
Length uint16 // if len(ValueOverride) == 0, will generate random data of this size.
ValueOverride []byte // if len(ValueOverride) > 0, use this instead of random bytes.
Expand All @@ -73,12 +73,12 @@ const (

// IsGREASEID returns true if id is a valid GREASE ID for
// transport parameters.
func (GREASE) IsGREASEID(id uint64) bool {
return (id-27)%31 == 0
func (GREASETransportParameter) IsGREASEID(id uint64) bool {
return id >= 27 && (id-27)%31 == 0
}

// GetGREASEID returns a random valid GREASE ID for transport parameters.
func (GREASE) GetGREASEID() uint64 {
func (GREASETransportParameter) GetGREASEID() uint64 {
max := big.NewInt(GREASE_MAX_MULTIPLIER)

randMultiply, err := rand.Int(rand.Reader, max)
Expand All @@ -89,14 +89,14 @@ func (GREASE) GetGREASEID() uint64 {
return 27 + randMultiply.Uint64()*31
}

func (g *GREASE) ID() uint64 {
func (g *GREASETransportParameter) ID() uint64 {
if !g.IsGREASEID(g.IdOverride) {
g.IdOverride = g.GetGREASEID()
}
return g.IdOverride
}

func (g *GREASE) Value() []byte {
func (g *GREASETransportParameter) Value() []byte {
if len(g.ValueOverride) == 0 {
g.ValueOverride = make([]byte, g.Length)
rand.Read(g.ValueOverride)
Expand Down Expand Up @@ -271,13 +271,13 @@ func (*VersionInformation) GetGREASEVersion() uint32 {
return uint32(randVal.Uint64()&math.MaxUint32) | 0x0a0a0a0a // all GREASE versions are in 0x?a?a?a?a
}

type Padding []byte
type PaddingTransportParameter []byte

func (Padding) ID() uint64 {
func (PaddingTransportParameter) ID() uint64 {
return padding
}

func (p Padding) Value() []byte {
func (p PaddingTransportParameter) Value() []byte {
return p
}

Expand Down
2 changes: 1 addition & 1 deletion u_quic_transport_parameters_test.go
Expand Up @@ -32,7 +32,7 @@ var (
LegacyID: true,
},
InitialMaxStreamsUni(16),
&GREASE{
&GREASETransportParameter{
IdOverride: 0xff02de1a,
ValueOverride: []byte{
0x43, 0xe8,
Expand Down

0 comments on commit 2ae5748

Please sign in to comment.