Skip to content

Commit f919f49

Browse files
committed
Add BBR profile and hop interval randomization for Hysteria2
1 parent 79f9ef0 commit f919f49

File tree

9 files changed

+94
-16
lines changed

9 files changed

+94
-16
lines changed

docs/configuration/inbound/hysteria2.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
icon: material/alert-decagram
33
---
44

5+
!!! quote "Changes in sing-box 1.14.0"
6+
7+
:material-plus: [bbr_profile](#bbr_profile)
8+
59
!!! quote "Changes in sing-box 1.11.0"
610

711
:material-alert: [masquerade](#masquerade)
@@ -31,6 +35,7 @@ icon: material/alert-decagram
3135
"ignore_client_bandwidth": false,
3236
"tls": {},
3337
"masquerade": "", // or {}
38+
"bbr_profile": "",
3439
"brutal_debug": false
3540
}
3641
```
@@ -141,6 +146,14 @@ Fixed response headers.
141146

142147
Fixed response content.
143148

149+
#### bbr_profile
150+
151+
!!! question "Since sing-box 1.14.0"
152+
153+
BBR congestion control algorithm profile, one of `conservative` `standard` `aggressive`.
154+
155+
`standard` is used by default.
156+
144157
#### brutal_debug
145158

146159
Enable debug information logging for Hysteria Brutal CC.

docs/configuration/inbound/hysteria2.zh.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
icon: material/alert-decagram
33
---
44

5+
!!! quote "sing-box 1.14.0 中的更改"
6+
7+
:material-plus: [bbr_profile](#bbr_profile)
8+
59
!!! quote "sing-box 1.11.0 中的更改"
610

711
:material-alert: [masquerade](#masquerade)
@@ -31,6 +35,7 @@ icon: material/alert-decagram
3135
"ignore_client_bandwidth": false,
3236
"tls": {},
3337
"masquerade": "", // 或 {}
38+
"bbr_profile": "",
3439
"brutal_debug": false
3540
}
3641
```
@@ -138,6 +143,14 @@ HTTP3 服务器认证失败时的行为 (对象配置)。
138143

139144
固定响应内容。
140145

146+
#### bbr_profile
147+
148+
!!! question "自 sing-box 1.14.0 起"
149+
150+
BBR 拥塞控制算法配置,可选 `conservative` `standard` `aggressive`
151+
152+
默认使用 `standard`
153+
141154
#### brutal_debug
142155

143156
启用 Hysteria Brutal CC 的调试信息日志记录。

docs/configuration/outbound/hysteria2.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
!!! quote "Changes in sing-box 1.14.0"
2+
3+
:material-plus: [hop_interval_max](#hop_interval_max)
4+
:material-plus: [bbr_profile](#bbr_profile)
5+
16
!!! quote "Changes in sing-box 1.11.0"
27

38
:material-plus: [server_ports](#server_ports)
@@ -9,13 +14,14 @@
914
{
1015
"type": "hysteria2",
1116
"tag": "hy2-out",
12-
17+
1318
"server": "127.0.0.1",
1419
"server_port": 1080,
1520
"server_ports": [
1621
"2080:3000"
1722
],
1823
"hop_interval": "",
24+
"hop_interval_max": "",
1925
"up_mbps": 100,
2026
"down_mbps": 100,
2127
"obfs": {
@@ -25,8 +31,9 @@
2531
"password": "goofy_ahh_password",
2632
"network": "tcp",
2733
"tls": {},
34+
"bbr_profile": "",
2835
"brutal_debug": false,
29-
36+
3037
... // Dial Fields
3138
}
3239
```
@@ -75,6 +82,14 @@ Port hopping interval.
7582

7683
`30s` is used by default.
7784

85+
#### hop_interval_max
86+
87+
!!! question "Since sing-box 1.14.0"
88+
89+
Maximum port hopping interval, used for randomization.
90+
91+
If set, the actual hop interval will be randomly chosen between `hop_interval` and `hop_interval_max`.
92+
7893
#### up_mbps, down_mbps
7994

8095
Max bandwidth, in Mbps.
@@ -109,6 +124,14 @@ Both is enabled by default.
109124

110125
TLS configuration, see [TLS](/configuration/shared/tls/#outbound).
111126

127+
#### bbr_profile
128+
129+
!!! question "Since sing-box 1.14.0"
130+
131+
BBR congestion control algorithm profile, one of `conservative` `standard` `aggressive`.
132+
133+
`standard` is used by default.
134+
112135
#### brutal_debug
113136

114137
Enable debug information logging for Hysteria Brutal CC.

docs/configuration/outbound/hysteria2.zh.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
!!! quote "sing-box 1.14.0 中的更改"
2+
3+
:material-plus: [hop_interval_max](#hop_interval_max)
4+
:material-plus: [bbr_profile](#bbr_profile)
5+
16
!!! quote "sing-box 1.11.0 中的更改"
27

38
:material-plus: [server_ports](#server_ports)
@@ -16,6 +21,7 @@
1621
"2080:3000"
1722
],
1823
"hop_interval": "",
24+
"hop_interval_max": "",
1925
"up_mbps": 100,
2026
"down_mbps": 100,
2127
"obfs": {
@@ -25,8 +31,9 @@
2531
"password": "goofy_ahh_password",
2632
"network": "tcp",
2733
"tls": {},
34+
"bbr_profile": "",
2835
"brutal_debug": false,
29-
36+
3037
... // 拨号字段
3138
}
3239
```
@@ -73,6 +80,14 @@
7380

7481
默认使用 `30s`
7582

83+
#### hop_interval_max
84+
85+
!!! question "自 sing-box 1.14.0 起"
86+
87+
最大端口跳跃间隔,用于随机化。
88+
89+
如果设置,实际跳跃间隔将在 `hop_interval``hop_interval_max` 之间随机选择。
90+
7691
#### up_mbps, down_mbps
7792

7893
最大带宽。
@@ -107,6 +122,14 @@ QUIC 流量混淆器密码.
107122

108123
TLS 配置, 参阅 [TLS](/zh/configuration/shared/tls/#出站)
109124

125+
#### bbr_profile
126+
127+
!!! question "自 sing-box 1.14.0 起"
128+
129+
BBR 拥塞控制算法配置,可选 `conservative` `standard` `aggressive`
130+
131+
默认使用 `standard`
132+
110133
#### brutal_debug
111134

112135
启用 Hysteria Brutal CC 的调试信息日志记录。

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/anthropics/anthropic-sdk-go v1.26.0
77
github.com/anytls/sing-anytls v0.0.11
88
github.com/caddyserver/certmagic v0.25.2
9+
github.com/caddyserver/zerossl v0.1.5
910
github.com/coder/websocket v1.8.14
1011
github.com/cretz/bine v0.2.0
1112
github.com/database64128/tfo-go/v2 v2.3.2
@@ -19,6 +20,7 @@ require (
1920
github.com/libdns/acmedns v0.5.0
2021
github.com/libdns/alidns v1.0.6
2122
github.com/libdns/cloudflare v0.2.2
23+
github.com/libdns/libdns v1.1.1
2224
github.com/logrusorgru/aurora v2.0.3+incompatible
2325
github.com/mdlayher/netlink v1.9.0
2426
github.com/metacubex/utls v1.8.4
@@ -37,7 +39,7 @@ require (
3739
github.com/sagernet/quic-go v0.59.0-sing-box-mod.4
3840
github.com/sagernet/sing v0.8.4
3941
github.com/sagernet/sing-mux v0.3.4
40-
github.com/sagernet/sing-quic v0.6.1
42+
github.com/sagernet/sing-quic v0.6.2-0.20260330152607-bf674c163212
4143
github.com/sagernet/sing-shadowsocks v0.2.8
4244
github.com/sagernet/sing-shadowsocks2 v0.2.1
4345
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11
@@ -69,7 +71,6 @@ require (
6971
github.com/akutz/memconn v0.1.0 // indirect
7072
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
7173
github.com/andybalholm/brotli v1.1.0 // indirect
72-
github.com/caddyserver/zerossl v0.1.5 // indirect
7374
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
7475
github.com/coreos/go-iptables v0.7.1-0.20240112124308-65c67c9f46e6 // indirect
7576
github.com/database64128/netx-go v0.1.1 // indirect
@@ -96,7 +97,6 @@ require (
9697
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9798
github.com/klauspost/compress v1.18.0 // indirect
9899
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
99-
github.com/libdns/libdns v1.1.1 // indirect
100100
github.com/mdlayher/socket v0.5.1 // indirect
101101
github.com/mitchellh/go-ps v1.0.0 // indirect
102102
github.com/pierrec/lz4/v4 v4.1.21 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ github.com/sagernet/sing v0.8.4 h1:Fj+jlY3F8vhcRfz/G/P3Dwcs5wqnmyNPT7u1RVVmjFI=
240240
github.com/sagernet/sing v0.8.4/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
241241
github.com/sagernet/sing-mux v0.3.4 h1:ZQplKl8MNXutjzbMVtWvWG31fohhgOfCuUZR4dVQ8+s=
242242
github.com/sagernet/sing-mux v0.3.4/go.mod h1:QvlKMyNBNrQoyX4x+gq028uPbLM2XeRpWtDsWBJbFSk=
243-
github.com/sagernet/sing-quic v0.6.1 h1:lx0tcm99wIA1RkyvILNzRSsMy1k7TTQYIhx71E/WBlw=
244-
github.com/sagernet/sing-quic v0.6.1/go.mod h1:K5bWvITOm4vE10fwLfrWpw27bCoVJ+tfQ79tOWg+Ko8=
243+
github.com/sagernet/sing-quic v0.6.2-0.20260330152607-bf674c163212 h1:7mFOUqy+DyOj7qKGd1X54UMXbnbJiiMileK/tn17xYc=
244+
github.com/sagernet/sing-quic v0.6.2-0.20260330152607-bf674c163212/go.mod h1:K5bWvITOm4vE10fwLfrWpw27bCoVJ+tfQ79tOWg+Ko8=
245245
github.com/sagernet/sing-shadowsocks v0.2.8 h1:PURj5PRoAkqeHh2ZW205RWzN9E9RtKCVCzByXruQWfE=
246246
github.com/sagernet/sing-shadowsocks v0.2.8/go.mod h1:lo7TWEMDcN5/h5B8S0ew+r78ZODn6SwVaFhvB6H+PTI=
247247
github.com/sagernet/sing-shadowsocks2 v0.2.1 h1:dWV9OXCeFPuYGHb6IRqlSptVnSzOelnqqs2gQ2/Qioo=

option/hysteria2.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Hysteria2InboundOptions struct {
1919
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth,omitempty"`
2020
InboundTLSOptionsContainer
2121
Masquerade *Hysteria2Masquerade `json:"masquerade,omitempty"`
22+
BBRProfile string `json:"bbr_profile,omitempty"`
2223
BrutalDebug bool `json:"brutal_debug,omitempty"`
2324
}
2425

@@ -112,13 +113,15 @@ type Hysteria2MasqueradeString struct {
112113
type Hysteria2OutboundOptions struct {
113114
DialerOptions
114115
ServerOptions
115-
ServerPorts badoption.Listable[string] `json:"server_ports,omitempty"`
116-
HopInterval badoption.Duration `json:"hop_interval,omitempty"`
117-
UpMbps int `json:"up_mbps,omitempty"`
118-
DownMbps int `json:"down_mbps,omitempty"`
119-
Obfs *Hysteria2Obfs `json:"obfs,omitempty"`
120-
Password string `json:"password,omitempty"`
121-
Network NetworkList `json:"network,omitempty"`
116+
ServerPorts badoption.Listable[string] `json:"server_ports,omitempty"`
117+
HopInterval badoption.Duration `json:"hop_interval,omitempty"`
118+
HopIntervalMax badoption.Duration `json:"hop_interval_max,omitempty"`
119+
UpMbps int `json:"up_mbps,omitempty"`
120+
DownMbps int `json:"down_mbps,omitempty"`
121+
Obfs *Hysteria2Obfs `json:"obfs,omitempty"`
122+
Password string `json:"password,omitempty"`
123+
Network NetworkList `json:"network,omitempty"`
122124
OutboundTLSOptionsContainer
123-
BrutalDebug bool `json:"brutal_debug,omitempty"`
125+
BBRProfile string `json:"bbr_profile,omitempty"`
126+
BrutalDebug bool `json:"brutal_debug,omitempty"`
124127
}

protocol/hysteria2/inbound.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
125125
UDPTimeout: udpTimeout,
126126
Handler: inbound,
127127
MasqueradeHandler: masqueradeHandler,
128+
BBRProfile: options.BBRProfile,
128129
})
129130
if err != nil {
130131
return nil, err

protocol/hysteria2/outbound.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
7373
ServerAddress: options.ServerOptions.Build(),
7474
ServerPorts: options.ServerPorts,
7575
HopInterval: time.Duration(options.HopInterval),
76+
HopIntervalMax: time.Duration(options.HopIntervalMax),
7677
SendBPS: uint64(options.UpMbps * hysteria.MbpsToBps),
7778
ReceiveBPS: uint64(options.DownMbps * hysteria.MbpsToBps),
7879
SalamanderPassword: salamanderPassword,
7980
Password: options.Password,
8081
TLSConfig: tlsConfig,
8182
UDPDisabled: !common.Contains(networkList, N.NetworkUDP),
83+
BBRProfile: options.BBRProfile,
8284
})
8385
if err != nil {
8486
return nil, err

0 commit comments

Comments
 (0)