SplitHTTP client: Add minUploadInterval (#3592)

This commit is contained in:
mmmray 2024-07-27 14:52:36 +02:00 committed by GitHub
parent 7cf5ee8afd
commit 8a4217fdf5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 188 additions and 25 deletions

View file

@ -1,6 +1,8 @@
package splithttp
import (
"crypto/rand"
"math/big"
"net/http"
"github.com/xtls/xray-core/common"
@ -45,8 +47,29 @@ func (c *Config) GetNormalizedMaxUploadSize() int32 {
return c.MaxUploadSize
}
func (c *Config) GetNormalizedMinUploadInterval() RandRangeConfig {
r := c.MinUploadIntervalMs
if r == nil {
r = &RandRangeConfig{
From: 30,
To: 30,
}
}
return *r
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
return new(Config)
}))
}
func (c RandRangeConfig) roll() int32 {
if c.From == c.To {
return c.From
}
bigInt, _ := rand.Int(rand.Reader, big.NewInt(int64(c.To-c.From)))
return c.From + int32(bigInt.Int64())
}