Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'XTLS:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei authored Jul 29, 2024
2 parents 1aec3fc + 4c82ef8 commit 6c71835
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 100 deletions.
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
var (
Version_x byte = 1
Version_y byte = 8
Version_z byte = 22
Version_z byte = 23
)

var (
Expand Down
24 changes: 12 additions & 12 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ type SplitHTTPConfig struct {
Host string `json:"host"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
MaxConcurrentUploads Int32Range `json:"maxConcurrentUploads"`
MaxUploadSize Int32Range `json:"maxUploadSize"`
MinUploadIntervalMs Int32Range `json:"minUploadIntervalMs"`
ScMaxConcurrentPosts Int32Range `json:"scMaxConcurrentPosts"`
ScMaxEachPostBytes Int32Range `json:"scMaxEachPostBytes"`
ScMinPostsIntervalMs Int32Range `json:"scMinPostsIntervalMs"`
NoSSEHeader bool `json:"noSSEHeader"`
}

Expand All @@ -249,17 +249,17 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
Path: c.Path,
Host: c.Host,
Header: c.Headers,
MaxConcurrentUploads: &splithttp.RandRangeConfig{
From: c.MaxConcurrentUploads.From,
To: c.MaxConcurrentUploads.To,
ScMaxConcurrentPosts: &splithttp.RandRangeConfig{
From: c.ScMaxConcurrentPosts.From,
To: c.ScMaxConcurrentPosts.To,
},
MaxUploadSize: &splithttp.RandRangeConfig{
From: c.MaxUploadSize.From,
To: c.MaxUploadSize.To,
ScMaxEachPostBytes: &splithttp.RandRangeConfig{
From: c.ScMaxEachPostBytes.From,
To: c.ScMaxEachPostBytes.To,
},
MinUploadIntervalMs: &splithttp.RandRangeConfig{
From: c.MinUploadIntervalMs.From,
To: c.MinUploadIntervalMs.To,
ScMinPostsIntervalMs: &splithttp.RandRangeConfig{
From: c.ScMinPostsIntervalMs.From,
To: c.ScMinPostsIntervalMs.To,
},
NoSSEHeader: c.NoSSEHeader,
}
Expand Down
44 changes: 15 additions & 29 deletions transport/internet/splithttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,37 @@ func (c *Config) GetRequestHeader() http.Header {
return header
}

func (c *Config) GetNormalizedMaxConcurrentUploads(isServer bool) RandRangeConfig {
if c.MaxConcurrentUploads == nil || c.MaxConcurrentUploads.To == 0 {
if isServer {
return RandRangeConfig{
From: 200,
To: 200,
}
} else {
return RandRangeConfig{
From: 100,
To: 100,
}
func (c *Config) GetNormalizedScMaxConcurrentPosts() RandRangeConfig {
if c.ScMaxConcurrentPosts == nil || c.ScMaxConcurrentPosts.To == 0 {
return RandRangeConfig{
From: 100,
To: 100,
}
}

return *c.MaxConcurrentUploads
return *c.ScMaxConcurrentPosts
}

func (c *Config) GetNormalizedMaxUploadSize(isServer bool) RandRangeConfig {
if c.MaxUploadSize == nil || c.MaxUploadSize.To == 0 {
if isServer {
return RandRangeConfig{
From: 2000000,
To: 2000000,
}
} else {
return RandRangeConfig{
From: 1000000,
To: 1000000,
}
func (c *Config) GetNormalizedScMaxEachPostBytes() RandRangeConfig {
if c.ScMaxEachPostBytes == nil || c.ScMaxEachPostBytes.To == 0 {
return RandRangeConfig{
From: 1000000,
To: 1000000,
}
}

return *c.MaxUploadSize
return *c.ScMaxEachPostBytes
}

func (c *Config) GetNormalizedMinUploadInterval() RandRangeConfig {
if c.MinUploadIntervalMs == nil || c.MinUploadIntervalMs.To == 0 {
func (c *Config) GetNormalizedScMinPostsIntervalMs() RandRangeConfig {
if c.ScMinPostsIntervalMs == nil || c.ScMinPostsIntervalMs.To == 0 {
return RandRangeConfig{
From: 30,
To: 30,
}
}

return *c.MinUploadIntervalMs
return *c.ScMinPostsIntervalMs
}

func init() {
Expand Down
88 changes: 44 additions & 44 deletions transport/internet/splithttp/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions transport/internet/splithttp/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ message Config {
string host = 1;
string path = 2;
map<string, string> header = 3;
RandRangeConfig maxConcurrentUploads = 4;
RandRangeConfig maxUploadSize = 5;
RandRangeConfig minUploadIntervalMs = 6;
RandRangeConfig scMaxConcurrentPosts = 4;
RandRangeConfig scMaxEachPostBytes = 5;
RandRangeConfig scMinPostsIntervalMs = 6;
bool noSSEHeader = 7;
}

Expand Down
14 changes: 7 additions & 7 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
transportConfiguration := streamSettings.ProtocolSettings.(*Config)
tlsConfig := tls.ConfigFromStreamSettings(streamSettings)

maxConcurrentUploads := transportConfiguration.GetNormalizedMaxConcurrentUploads(false)
maxUploadSize := transportConfiguration.GetNormalizedMaxUploadSize(false)
minUploadInterval := transportConfiguration.GetNormalizedMinUploadInterval()
scMaxConcurrentPosts := transportConfiguration.GetNormalizedScMaxConcurrentPosts()
scMaxEachPostBytes := transportConfiguration.GetNormalizedScMaxEachPostBytes()
scMinPostsIntervalMs := transportConfiguration.GetNormalizedScMinPostsIntervalMs()

if tlsConfig != nil {
requestURL.Scheme = "https"
Expand All @@ -201,10 +201,10 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me

httpClient := getHTTPClient(ctx, dest, streamSettings)

uploadPipeReader, uploadPipeWriter := pipe.New(pipe.WithSizeLimit(maxUploadSize.roll()))
uploadPipeReader, uploadPipeWriter := pipe.New(pipe.WithSizeLimit(scMaxEachPostBytes.roll()))

go func() {
requestsLimiter := semaphore.New(int(maxConcurrentUploads.roll()))
requestsLimiter := semaphore.New(int(scMaxConcurrentPosts.roll()))
var requestCounter int64

lastWrite := time.Now()
Expand Down Expand Up @@ -239,8 +239,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}
}()

if minUploadInterval.From > 0 {
roll := time.Duration(minUploadInterval.roll()) * time.Millisecond
if scMinPostsIntervalMs.From > 0 {
roll := time.Duration(scMinPostsIntervalMs.roll()) * time.Millisecond
if time.Since(lastWrite) < roll {
time.Sleep(roll)
}
Expand Down
8 changes: 4 additions & 4 deletions transport/internet/splithttp/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (h *requestHandler) upsertSession(sessionId string) *httpSession {
}

s := &httpSession{
uploadQueue: NewUploadQueue(int(h.ln.config.GetNormalizedMaxConcurrentUploads(true).To)),
uploadQueue: NewUploadQueue(int(h.ln.config.GetNormalizedScMaxConcurrentPosts().To)),
isFullyConnected: done.New(),
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
}

currentSession := h.upsertSession(sessionId)
maxUploadSize := int(h.ln.config.GetNormalizedMaxUploadSize(true).To)
scMaxEachPostBytes := int(h.ln.config.GetNormalizedScMaxEachPostBytes().To)

if request.Method == "POST" {
seq := ""
Expand All @@ -139,8 +139,8 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req

payload, err := io.ReadAll(request.Body)

if len(payload) > maxUploadSize {
errors.LogInfo(context.Background(), "Too large upload. maxUploadSize is set to", maxUploadSize, "but request had size", len(payload), ". Adjust maxUploadSize on the server to be at least as large as client.")
if len(payload) > scMaxEachPostBytes {
errors.LogInfo(context.Background(), "Too large upload. scMaxEachPostBytes is set to ", scMaxEachPostBytes, "but request had size ", len(payload), ". Adjust scMaxEachPostBytes on the server to be at least as large as client.")
writer.WriteHeader(http.StatusRequestEntityTooLarge)
return
}
Expand Down

0 comments on commit 6c71835

Please sign in to comment.