Skip to content

Commit e79465d

Browse files
committed
chore: add inbound test for hysteria2
1 parent 345d3d7 commit e79465d

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

docs/config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,31 @@ listeners:
12981298
# password: "example"
12991299
### 注意,对于trojan listener, 至少需要填写 “certificate和private-key” 或 “reality-config” 或 “ss-option” 的其中一项 ###
13001300

1301+
- name: hysteria2-in-1
1302+
type: hysteria2
1303+
port: 10820 # 支持使用ports格式,例如200,302 or 200,204,401-429,501-503
1304+
listen: 0.0.0.0
1305+
# rule: sub-rule-name1 # 默认使用 rules,如果未找到 sub-rule 则直接使用 rules
1306+
# proxy: proxy # 如果不为空则直接将该入站流量交由指定 proxy 处理 (当 proxy 不为空时,这里的 proxy 名称必须合法,否则会出错)
1307+
users:
1308+
00000000-0000-0000-0000-000000000000: PASSWORD_0
1309+
00000000-0000-0000-0000-000000000001: PASSWORD_1
1310+
# certificate: ./server.crt
1311+
# private-key: ./server.key
1312+
## up 和 down 均不写或为 0 则使用 BBR 流控
1313+
# up: "30 Mbps" # 若不写单位,默认为 Mbps
1314+
# down: "200 Mbps" # 若不写单位,默认为 Mbps
1315+
# obfs: salamander # 默认为空,如果填写则开启 obfs,目前仅支持 salamander
1316+
# obfs-password: yourpassword
1317+
# max-idle-time: 15000
1318+
# alpn:
1319+
# - h3
1320+
# ignore-client-bandwidth: false
1321+
# HTTP3 服务器认证失败时的行为 (URL 字符串配置),如果 masquerade 未配置,则返回 404 页
1322+
# masquerade: file:///var/www # 作为文件服务器
1323+
# masquerade: http://127.0.0.1:8080 #作为反向代理
1324+
# masquerade: https://127.0.0.1:8080 #作为反向代理
1325+
13011326
- name: tun-in-1
13021327
type: tun
13031328
# rule: sub-rule-name1 # 默认使用 rules,如果未找到 sub-rule 则直接使用 rules

listener/inbound/hysteria2_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package inbound_test
2+
3+
import (
4+
"net/netip"
5+
"testing"
6+
7+
"github.com/metacubex/mihomo/adapter/outbound"
8+
"github.com/metacubex/mihomo/listener/inbound"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func testInboundHysteria2(t *testing.T, inboundOptions inbound.Hysteria2Option, outboundOptions outbound.Hysteria2Option) {
14+
inboundOptions.BaseOption = inbound.BaseOption{
15+
NameStr: "hysteria2_inbound",
16+
Listen: "127.0.0.1",
17+
Port: "0",
18+
}
19+
inboundOptions.Users = map[string]string{"test": userUUID}
20+
in, err := inbound.NewHysteria2(&inboundOptions)
21+
assert.NoError(t, err)
22+
23+
tunnel := NewHttpTestTunnel()
24+
defer tunnel.Close()
25+
26+
err = in.Listen(tunnel)
27+
assert.NoError(t, err)
28+
defer in.Close()
29+
30+
addrPort, err := netip.ParseAddrPort(in.Address())
31+
assert.NoError(t, err)
32+
33+
outboundOptions.Name = "hysteria2_outbound"
34+
outboundOptions.Server = addrPort.Addr().String()
35+
outboundOptions.Port = int(addrPort.Port())
36+
outboundOptions.Password = userUUID
37+
38+
out, err := outbound.NewHysteria2(outboundOptions)
39+
assert.NoError(t, err)
40+
defer out.Close()
41+
42+
tunnel.DoTest(t, out)
43+
}
44+
45+
func TestInboundHysteria2_TLS(t *testing.T) {
46+
inboundOptions := inbound.Hysteria2Option{
47+
Certificate: tlsCertificate,
48+
PrivateKey: tlsPrivateKey,
49+
}
50+
outboundOptions := outbound.Hysteria2Option{
51+
Fingerprint: tlsFingerprint,
52+
}
53+
testInboundHysteria2(t, inboundOptions, outboundOptions)
54+
}
55+
56+
func TestInboundHysteria2_Salamander(t *testing.T) {
57+
inboundOptions := inbound.Hysteria2Option{
58+
Certificate: tlsCertificate,
59+
PrivateKey: tlsPrivateKey,
60+
Obfs: "salamander",
61+
ObfsPassword: userUUID,
62+
}
63+
outboundOptions := outbound.Hysteria2Option{
64+
Fingerprint: tlsFingerprint,
65+
Obfs: "salamander",
66+
ObfsPassword: userUUID,
67+
}
68+
testInboundHysteria2(t, inboundOptions, outboundOptions)
69+
}
70+
71+
func TestInboundHysteria2_Brutal(t *testing.T) {
72+
inboundOptions := inbound.Hysteria2Option{
73+
Certificate: tlsCertificate,
74+
PrivateKey: tlsPrivateKey,
75+
Up: "30 Mbps",
76+
Down: "200 Mbps",
77+
}
78+
outboundOptions := outbound.Hysteria2Option{
79+
Fingerprint: tlsFingerprint,
80+
Up: "30 Mbps",
81+
Down: "200 Mbps",
82+
}
83+
testInboundHysteria2(t, inboundOptions, outboundOptions)
84+
}

0 commit comments

Comments
 (0)