mirror of
https://github.com/refraction-networking/utls.git
synced 2025-04-03 20:17:36 +03:00
fix: poorly named qtps (#215)
- 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.
This commit is contained in:
parent
30a2200750
commit
2ae5748ff0
2 changed files with 10 additions and 10 deletions
|
@ -61,7 +61,7 @@ type TransportParameter interface {
|
||||||
Value() []byte
|
Value() []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type GREASE struct {
|
type GREASETransportParameter struct {
|
||||||
IdOverride uint64 // if set to a valid GREASE ID, use this instead of randomly generated one.
|
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.
|
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.
|
ValueOverride []byte // if len(ValueOverride) > 0, use this instead of random bytes.
|
||||||
|
@ -73,12 +73,12 @@ const (
|
||||||
|
|
||||||
// IsGREASEID returns true if id is a valid GREASE ID for
|
// IsGREASEID returns true if id is a valid GREASE ID for
|
||||||
// transport parameters.
|
// transport parameters.
|
||||||
func (GREASE) IsGREASEID(id uint64) bool {
|
func (GREASETransportParameter) IsGREASEID(id uint64) bool {
|
||||||
return (id-27)%31 == 0
|
return id >= 27 && (id-27)%31 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGREASEID returns a random valid GREASE ID for transport parameters.
|
// GetGREASEID returns a random valid GREASE ID for transport parameters.
|
||||||
func (GREASE) GetGREASEID() uint64 {
|
func (GREASETransportParameter) GetGREASEID() uint64 {
|
||||||
max := big.NewInt(GREASE_MAX_MULTIPLIER)
|
max := big.NewInt(GREASE_MAX_MULTIPLIER)
|
||||||
|
|
||||||
randMultiply, err := rand.Int(rand.Reader, max)
|
randMultiply, err := rand.Int(rand.Reader, max)
|
||||||
|
@ -89,14 +89,14 @@ func (GREASE) GetGREASEID() uint64 {
|
||||||
return 27 + randMultiply.Uint64()*31
|
return 27 + randMultiply.Uint64()*31
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GREASE) ID() uint64 {
|
func (g *GREASETransportParameter) ID() uint64 {
|
||||||
if !g.IsGREASEID(g.IdOverride) {
|
if !g.IsGREASEID(g.IdOverride) {
|
||||||
g.IdOverride = g.GetGREASEID()
|
g.IdOverride = g.GetGREASEID()
|
||||||
}
|
}
|
||||||
return g.IdOverride
|
return g.IdOverride
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GREASE) Value() []byte {
|
func (g *GREASETransportParameter) Value() []byte {
|
||||||
if len(g.ValueOverride) == 0 {
|
if len(g.ValueOverride) == 0 {
|
||||||
g.ValueOverride = make([]byte, g.Length)
|
g.ValueOverride = make([]byte, g.Length)
|
||||||
rand.Read(g.ValueOverride)
|
rand.Read(g.ValueOverride)
|
||||||
|
@ -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
|
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
|
return padding
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Padding) Value() []byte {
|
func (p PaddingTransportParameter) Value() []byte {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ var (
|
||||||
LegacyID: true,
|
LegacyID: true,
|
||||||
},
|
},
|
||||||
InitialMaxStreamsUni(16),
|
InitialMaxStreamsUni(16),
|
||||||
&GREASE{
|
&GREASETransportParameter{
|
||||||
IdOverride: 0xff02de1a,
|
IdOverride: 0xff02de1a,
|
||||||
ValueOverride: []byte{
|
ValueOverride: []byte{
|
||||||
0x43, 0xe8,
|
0x43, 0xe8,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue