Skip to content

Commit bcb0cb5

Browse files
author
YUNRU
committed
SplitHTTP Client: Multiplexing Config
1 parent 0c73039 commit bcb0cb5

6 files changed

Lines changed: 418 additions & 57 deletions

File tree

infra/conf/transport_internet.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ type SplitHTTPConfig struct {
234234
ScMinPostsIntervalMs *Int32Range `json:"scMinPostsIntervalMs"`
235235
NoSSEHeader bool `json:"noSSEHeader"`
236236
XPaddingBytes *Int32Range `json:"xPaddingBytes"`
237+
Mux SplitHTTPMux `json:"mux"`
238+
}
239+
240+
type SplitHTTPMux struct {
241+
Mode string `json:"mode"`
242+
MaxConnectionConcurrency Int32Range `json:"maxConnectionConcurrency"`
243+
MaxConnectionLifetime Int32Range `json:"maxConnectionLifetime"`
244+
MaxConnection int32 `json:"maxConnection"`
237245
}
238246

239247
func splithttpNewRandRangeConfig(input *Int32Range) *splithttp.RandRangeConfig {
@@ -257,6 +265,28 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
257265
} else if c.Host == "" && c.Headers["Host"] != "" {
258266
c.Host = c.Headers["Host"]
259267
}
268+
269+
// Multiplexing config
270+
muxProtobuf := splithttp.Multiplexing{}
271+
switch strings.ToLower(c.Mux.Mode) {
272+
case "disabled", "off", "none":
273+
muxProtobuf.Mode = splithttp.Multiplexing_DISABLED
274+
case "prefer_reuse", "preferreuse", "prefer_existing", "preferexisting", "": // Default: Reuse existing connections before opening new ones
275+
muxProtobuf.Mode = splithttp.Multiplexing_PREFER_EXTISTING
276+
case "prefer_new", "prefernew": // Open new connections until max limit, then reuse
277+
muxProtobuf.Mode = splithttp.Multiplexing_PREFER_NEW
278+
default:
279+
return nil, errors.New("unsupported splithttp multiplexing mode: ", c.Mux.Mode)
280+
}
281+
muxProtobuf.MaxConnectionConcurrency = &splithttp.RandRangeConfig{
282+
From: c.Mux.MaxConnectionConcurrency.From,
283+
To: c.Mux.MaxConnectionConcurrency.To,
284+
}
285+
muxProtobuf.MaxConnectionLifetime = &splithttp.RandRangeConfig{
286+
From: c.Mux.MaxConnectionLifetime.From,
287+
To: c.Mux.MaxConnectionLifetime.To,
288+
}
289+
muxProtobuf.MaxConnections = c.Mux.MaxConnection
260290
config := &splithttp.Config{
261291
Path: c.Path,
262292
Host: c.Host,
@@ -266,6 +296,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
266296
ScMinPostsIntervalMs: splithttpNewRandRangeConfig(c.ScMinPostsIntervalMs),
267297
NoSSEHeader: c.NoSSEHeader,
268298
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
299+
Mux: &muxProtobuf,
269300
}
270301
return config, nil
271302
}

transport/internet/splithttp/config.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (c *Config) GetRequestHeader() http.Header {
5353

5454
return header
5555
}
56-
5756
func (c *Config) WriteResponseHeader(writer http.ResponseWriter) {
5857
paddingLen := c.GetNormalizedXPaddingBytes().roll()
5958
if paddingLen > 0 {
@@ -72,17 +71,36 @@ func (c *Config) GetNormalizedScMaxConcurrentPosts() RandRangeConfig {
7271
return *c.ScMaxConcurrentPosts
7372
}
7473

74+
func (m *Multiplexing) GetNormalizedMaxConnectionConcurrency() RandRangeConfig {
75+
if m.MaxConnectionConcurrency == nil || m.MaxConnectionConcurrency.To == 0 {
76+
return RandRangeConfig{
77+
From: 1,
78+
To: 3,
79+
}
80+
}
81+
82+
return *m.MaxConnectionConcurrency
83+
}
84+
85+
func (c *Multiplexing) GetNormalizedConnectionLifetime() RandRangeConfig {
86+
if c.MaxConnectionLifetime == nil || c.MaxConnectionLifetime.To == 0 {
87+
return RandRangeConfig{
88+
From: 60000,
89+
To: 90000,
90+
}
91+
}
92+
return *c.MaxConnectionLifetime
93+
}
94+
7595
func (c *Config) GetNormalizedScMaxEachPostBytes() RandRangeConfig {
7696
if c.ScMaxEachPostBytes == nil || c.ScMaxEachPostBytes.To == 0 {
7797
return RandRangeConfig{
7898
From: 1000000,
7999
To: 1000000,
80100
}
81101
}
82-
83102
return *c.ScMaxEachPostBytes
84103
}
85-
86104
func (c *Config) GetNormalizedScMinPostsIntervalMs() RandRangeConfig {
87105
if c.ScMinPostsIntervalMs == nil || c.ScMinPostsIntervalMs.To == 0 {
88106
return RandRangeConfig{

0 commit comments

Comments
 (0)