Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SplitHTTP client: Add xmux (multiplex controller) for H3 & H2 #3613

Merged
merged 13 commits into from
Sep 16, 2024
18 changes: 18 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"`
HttpMux SplitHTTPMux `json:"httpMux"`
}

type SplitHTTPMux struct {
RequestsPerConnection *Int32Range `json:"requestsPerConnection"`
ConnectionLifetimeMs *Int32Range `json:"connectionLifetimeMs"`
Connections *Int32Range `json:"connections"`
Concurrency *Int32Range `json:"concurrency"`
}

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

// Multiplexing config
muxProtobuf := splithttp.Multiplexing{
RequestsPerConnection: splithttpNewRandRangeConfig(c.HttpMux.RequestsPerConnection),
ConnectionLifetimeMs: splithttpNewRandRangeConfig(c.HttpMux.ConnectionLifetimeMs),
Connections: splithttpNewRandRangeConfig(c.HttpMux.Connections),
Concurrency: splithttpNewRandRangeConfig(c.HttpMux.Concurrency),
}

config := &splithttp.Config{
Path: c.Path,
Host: c.Host,
Expand All @@ -266,6 +283,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
ScMinPostsIntervalMs: splithttpNewRandRangeConfig(c.ScMinPostsIntervalMs),
NoSSEHeader: c.NoSSEHeader,
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
HttpMux: &muxProtobuf,
}
return config, nil
}
Expand Down
46 changes: 43 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 @@ -79,10 +78,8 @@ func (c *Config) GetNormalizedScMaxEachPostBytes() RandRangeConfig {
To: 1000000,
}
}

return *c.ScMaxEachPostBytes
}

func (c *Config) GetNormalizedScMinPostsIntervalMs() RandRangeConfig {
if c.ScMinPostsIntervalMs == nil || c.ScMinPostsIntervalMs.To == 0 {
return RandRangeConfig{
Expand All @@ -105,6 +102,49 @@ func (c *Config) GetNormalizedXPaddingBytes() RandRangeConfig {
return *c.XPaddingBytes
}

func (m *Multiplexing) GetNormalizedRequestsPerConnection() RandRangeConfig {
if m.RequestsPerConnection == nil {
return RandRangeConfig{
From: 0,
To: 0,
}
}

return *m.RequestsPerConnection
}

func (m *Multiplexing) GetNormalizedConnectionLifetimeMs() RandRangeConfig {
if m.ConnectionLifetimeMs == nil || m.ConnectionLifetimeMs.To == 0 {
return RandRangeConfig{
From: 0,
To: 0,
}
}
return *m.ConnectionLifetimeMs
}

func (m *Multiplexing) GetNormalizedConnections() RandRangeConfig {
if m.Connections == nil {
return RandRangeConfig{
From: 0,
To: 0,
}
}

return *m.Connections
}

func (m *Multiplexing) GetNormalizedConcurrency() RandRangeConfig {
if m.Concurrency == nil {
return RandRangeConfig{
From: 0,
To: 0,
}
}

return *m.Concurrency
}

func init() {
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
return new(Config)
Expand Down
190 changes: 158 additions & 32 deletions transport/internet/splithttp/config.pb.go

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

8 changes: 8 additions & 0 deletions transport/internet/splithttp/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ message Config {
RandRangeConfig scMinPostsIntervalMs = 6;
bool noSSEHeader = 7;
RandRangeConfig xPaddingBytes = 8;
Multiplexing httpMux = 9;
}

message RandRangeConfig {
ll11l1lIllIl1lll marked this conversation as resolved.
Show resolved Hide resolved
int32 from = 1;
int32 to = 2;
}

message Multiplexing {
RandRangeConfig requestsPerConnection = 4;
RandRangeConfig connectionLifetimeMs = 5;
RandRangeConfig connections = 6;
RandRangeConfig concurrency = 7;
}
Loading
Loading