mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +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
|
@ -183,6 +183,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||
|
||||
maxConcurrentUploads := transportConfiguration.GetNormalizedMaxConcurrentUploads()
|
||||
maxUploadSize := transportConfiguration.GetNormalizedMaxUploadSize()
|
||||
minUploadInterval := transportConfiguration.GetNormalizedMinUploadInterval()
|
||||
|
||||
if tlsConfig != nil {
|
||||
requestURL.Scheme = "https"
|
||||
|
@ -207,6 +208,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||
requestsLimiter := semaphore.New(int(maxConcurrentUploads))
|
||||
var requestCounter int64
|
||||
|
||||
lastWrite := time.Now()
|
||||
|
||||
// by offloading the uploads into a buffered pipe, multiple conn.Write
|
||||
// calls get automatically batched together into larger POST requests.
|
||||
// without batching, bandwidth is extremely limited.
|
||||
|
@ -237,6 +240,14 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||
}
|
||||
}()
|
||||
|
||||
if minUploadInterval.From > 0 {
|
||||
roll := time.Duration(minUploadInterval.roll()) * time.Millisecond
|
||||
if time.Since(lastWrite) < roll {
|
||||
time.Sleep(roll)
|
||||
}
|
||||
|
||||
lastWrite = time.Now()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue