Skip to content

Commit

Permalink
SplitHTTP Client: Multiplexing Config
Browse files Browse the repository at this point in the history
  • Loading branch information
YUNRU committed Aug 11, 2024
1 parent 0c73039 commit bcb0cb5
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 57 deletions.
31 changes: 31 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ type SplitHTTPConfig struct {
ScMinPostsIntervalMs *Int32Range `json:"scMinPostsIntervalMs"`
NoSSEHeader bool `json:"noSSEHeader"`
XPaddingBytes *Int32Range `json:"xPaddingBytes"`
Mux SplitHTTPMux `json:"mux"`
}

type SplitHTTPMux struct {
Mode string `json:"mode"`
MaxConnectionConcurrency Int32Range `json:"maxConnectionConcurrency"`
MaxConnectionLifetime Int32Range `json:"maxConnectionLifetime"`
MaxConnection int32 `json:"maxConnection"`
}

func splithttpNewRandRangeConfig(input *Int32Range) *splithttp.RandRangeConfig {
Expand All @@ -257,6 +265,28 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
} else if c.Host == "" && c.Headers["Host"] != "" {
c.Host = c.Headers["Host"]
}

// Multiplexing config
muxProtobuf := splithttp.Multiplexing{}
switch strings.ToLower(c.Mux.Mode) {
case "disabled", "off", "none":
muxProtobuf.Mode = splithttp.Multiplexing_DISABLED
case "prefer_reuse", "preferreuse", "prefer_existing", "preferexisting", "": // Default: Reuse existing connections before opening new ones
muxProtobuf.Mode = splithttp.Multiplexing_PREFER_EXTISTING
case "prefer_new", "prefernew": // Open new connections until max limit, then reuse
muxProtobuf.Mode = splithttp.Multiplexing_PREFER_NEW
default:
return nil, errors.New("unsupported splithttp multiplexing mode: ", c.Mux.Mode)
}
muxProtobuf.MaxConnectionConcurrency = &splithttp.RandRangeConfig{
From: c.Mux.MaxConnectionConcurrency.From,
To: c.Mux.MaxConnectionConcurrency.To,
}
muxProtobuf.MaxConnectionLifetime = &splithttp.RandRangeConfig{
From: c.Mux.MaxConnectionLifetime.From,
To: c.Mux.MaxConnectionLifetime.To,
}
muxProtobuf.MaxConnections = c.Mux.MaxConnection
config := &splithttp.Config{
Path: c.Path,
Host: c.Host,
Expand All @@ -266,6 +296,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
ScMinPostsIntervalMs: splithttpNewRandRangeConfig(c.ScMinPostsIntervalMs),
NoSSEHeader: c.NoSSEHeader,
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
Mux: &muxProtobuf,
}
return config, nil
}
Expand Down
24 changes: 21 additions & 3 deletions transport/internet/splithttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (c *Config) GetRequestHeader() http.Header {

return header
}

func (c *Config) WriteResponseHeader(writer http.ResponseWriter) {
paddingLen := c.GetNormalizedXPaddingBytes().roll()
if paddingLen > 0 {
Expand All @@ -72,17 +71,36 @@ func (c *Config) GetNormalizedScMaxConcurrentPosts() RandRangeConfig {
return *c.ScMaxConcurrentPosts
}

func (m *Multiplexing) GetNormalizedMaxConnectionConcurrency() RandRangeConfig {
if m.MaxConnectionConcurrency == nil || m.MaxConnectionConcurrency.To == 0 {
return RandRangeConfig{
From: 1,
To: 3,
}
}

return *m.MaxConnectionConcurrency
}

func (c *Multiplexing) GetNormalizedConnectionLifetime() RandRangeConfig {
if c.MaxConnectionLifetime == nil || c.MaxConnectionLifetime.To == 0 {
return RandRangeConfig{
From: 60000,
To: 90000,
}
}
return *c.MaxConnectionLifetime
}

func (c *Config) GetNormalizedScMaxEachPostBytes() RandRangeConfig {
if c.ScMaxEachPostBytes == nil || c.ScMaxEachPostBytes.To == 0 {
return RandRangeConfig{
From: 1000000,
To: 1000000,
}
}

return *c.ScMaxEachPostBytes
}

func (c *Config) GetNormalizedScMinPostsIntervalMs() RandRangeConfig {
if c.ScMinPostsIntervalMs == nil || c.ScMinPostsIntervalMs.To == 0 {
return RandRangeConfig{
Expand Down
Loading

0 comments on commit bcb0cb5

Please sign in to comment.