mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
SplitHTTP client: Add minUploadInterval (#3592)
This commit is contained in:
parent
7cf5ee8afd
commit
8a4217fdf5
6 changed files with 188 additions and 25 deletions
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
|
@ -242,3 +243,33 @@ func (v *User) Build() *protocol.User {
|
|||
Level: uint32(v.LevelByte),
|
||||
}
|
||||
}
|
||||
|
||||
// Int32Range deserializes from "1-2" or 1, so can deserialize from both int and number.
|
||||
// Negative integers can be passed as sentinel values, but do not parse as ranges.
|
||||
type Int32Range struct {
|
||||
From int32
|
||||
To int32
|
||||
}
|
||||
|
||||
func (v *Int32Range) UnmarshalJSON(data []byte) error {
|
||||
var stringrange string
|
||||
var rawint int32
|
||||
if err := json.Unmarshal(data, &stringrange); err == nil {
|
||||
pair := strings.SplitN(stringrange, "-", 2)
|
||||
if len(pair) == 2 {
|
||||
from, err := strconv.Atoi(pair[0])
|
||||
to, err2 := strconv.Atoi(pair[1])
|
||||
if err == nil && err2 == nil {
|
||||
v.From = int32(from)
|
||||
v.To = int32(to)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else if err := json.Unmarshal(data, &rawint); err == nil {
|
||||
v.From = rawint
|
||||
v.To = rawint
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("Invalid integer range, expected either string of form \"1-2\" or plain integer.")
|
||||
}
|
||||
|
|
|
@ -231,6 +231,7 @@ type SplitHTTPConfig struct {
|
|||
Headers map[string]string `json:"headers"`
|
||||
MaxConcurrentUploads int32 `json:"maxConcurrentUploads"`
|
||||
MaxUploadSize int32 `json:"maxUploadSize"`
|
||||
MinUploadIntervalMs Int32Range `json:"minUploadIntervalMs"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -249,6 +250,10 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
|
|||
Header: c.Headers,
|
||||
MaxConcurrentUploads: c.MaxConcurrentUploads,
|
||||
MaxUploadSize: c.MaxUploadSize,
|
||||
MinUploadIntervalMs: &splithttp.RandRangeConfig{
|
||||
From: c.MinUploadIntervalMs.From,
|
||||
To: c.MinUploadIntervalMs.To,
|
||||
},
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue