Skip to content

Commit

Permalink
XHTTP: The real upload / download splitting (#3955)
Browse files Browse the repository at this point in the history
* SplitHTTP client: Add real upload / download splitting

* Transport: Add XHTTP as an alias of SplitHTTP

* XHTTP config: Use `downloadSettings` instead
  • Loading branch information
RPRX authored Oct 31, 2024
1 parent e733148 commit b30e05d
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 219 deletions.
23 changes: 20 additions & 3 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type SplitHTTPConfig struct {
NoSSEHeader bool `json:"noSSEHeader"`
XPaddingBytes *Int32Range `json:"xPaddingBytes"`
Xmux Xmux `json:"xmux"`
DownloadSettings *StreamConfig `json:"downloadSettings"`
}

type Xmux struct {
Expand Down Expand Up @@ -299,6 +300,12 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
Xmux: &muxProtobuf,
}
var err error
if c.DownloadSettings != nil {
if config.DownloadSettings, err = c.DownloadSettings.Build(); err != nil {
return nil, errors.New(`Failed to build "downloadSettings".`).Base(err)
}
}
return config, nil
}

Expand Down Expand Up @@ -673,7 +680,7 @@ func (p TransportProtocol) Build() (string, error) {
return "grpc", nil
case "httpupgrade":
return "httpupgrade", nil
case "splithttp":
case "xhttp", "splithttp":
return "splithttp", nil
default:
return "", errors.New("Config: unknown transport protocol: ", p)
Expand Down Expand Up @@ -796,6 +803,8 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
}

type StreamConfig struct {
Address *Address `json:"address"`
Port uint16 `json:"port"`
Network *TransportProtocol `json:"network"`
Security string `json:"security"`
TLSSettings *TLSConfig `json:"tlsSettings"`
Expand All @@ -808,14 +817,19 @@ type StreamConfig struct {
SocketSettings *SocketConfig `json:"sockopt"`
GRPCConfig *GRPCConfig `json:"grpcSettings"`
HTTPUPGRADESettings *HttpUpgradeConfig `json:"httpupgradeSettings"`
XHTTPSettings *SplitHTTPConfig `json:"xhttpSettings"`
SplitHTTPSettings *SplitHTTPConfig `json:"splithttpSettings"`
}

// Build implements Buildable.
func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
config := &internet.StreamConfig{
Port: uint32(c.Port),
ProtocolName: "tcp",
}
if c.Address != nil {
config.Address = c.Address.Build()
}
if c.Network != nil {
protocol, err := c.Network.Build()
if err != nil {
Expand All @@ -839,7 +853,7 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
config.SecurityType = tm.Type
case "reality":
if config.ProtocolName != "tcp" && config.ProtocolName != "http" && config.ProtocolName != "grpc" && config.ProtocolName != "splithttp" {
return nil, errors.New("REALITY only supports TCP, H2, gRPC and SplitHTTP for now.")
return nil, errors.New("REALITY only supports RAW, H2, gRPC and XHTTP for now.")
}
if c.REALITYSettings == nil {
return nil, errors.New(`REALITY: Empty "realitySettings".`)
Expand Down Expand Up @@ -919,10 +933,13 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
Settings: serial.ToTypedMessage(hs),
})
}
if c.XHTTPSettings != nil {
c.SplitHTTPSettings = c.XHTTPSettings
}
if c.SplitHTTPSettings != nil {
hs, err := c.SplitHTTPSettings.Build()
if err != nil {
return nil, errors.New("Failed to build SplitHTTP config.").Base(err)
return nil, errors.New("Failed to build XHTTP config.").Base(err)
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
ProtocolName: "splithttp",
Expand Down
Loading

0 comments on commit b30e05d

Please sign in to comment.