mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-11 18:47:17 +03:00
Add port hopping for hysteria2
This commit is contained in:
@@ -3,24 +3,36 @@ package main
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing-quic/hysteria2"
|
||||
"github.com/sagernet/sing/common"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
func TestHysteria2Self(t *testing.T) {
|
||||
t.Run("self", func(t *testing.T) {
|
||||
testHysteria2Self(t, "")
|
||||
testHysteria2Self(t, "", false)
|
||||
})
|
||||
t.Run("self-salamander", func(t *testing.T) {
|
||||
testHysteria2Self(t, "password")
|
||||
testHysteria2Self(t, "password", false)
|
||||
})
|
||||
t.Run("self-hop", func(t *testing.T) {
|
||||
testHysteria2Self(t, "", true)
|
||||
})
|
||||
t.Run("self-hop-salamander", func(t *testing.T) {
|
||||
testHysteria2Self(t, "password", true)
|
||||
})
|
||||
}
|
||||
|
||||
func testHysteria2Self(t *testing.T, salamanderPassword string) {
|
||||
func TestHysteria2Hop(t *testing.T) {
|
||||
testHysteria2Self(t, "password", true)
|
||||
}
|
||||
|
||||
func testHysteria2Self(t *testing.T, salamanderPassword string, portHop bool) {
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
var obfs *option.Hysteria2Obfs
|
||||
if salamanderPassword != "" {
|
||||
@@ -29,6 +41,14 @@ func testHysteria2Self(t *testing.T, salamanderPassword string) {
|
||||
Password: salamanderPassword,
|
||||
}
|
||||
}
|
||||
var (
|
||||
serverPorts []string
|
||||
hopInterval time.Duration
|
||||
)
|
||||
if portHop {
|
||||
serverPorts = []string{F.ToString(serverPort, ":", serverPort)}
|
||||
hopInterval = 5 * time.Second
|
||||
}
|
||||
startInstance(t, option.Options{
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
@@ -77,10 +97,12 @@ func testHysteria2Self(t *testing.T, salamanderPassword string) {
|
||||
Server: "127.0.0.1",
|
||||
ServerPort: serverPort,
|
||||
},
|
||||
UpMbps: 100,
|
||||
DownMbps: 100,
|
||||
Obfs: obfs,
|
||||
Password: "password",
|
||||
ServerPorts: serverPorts,
|
||||
HopInterval: badoption.Duration(hopInterval),
|
||||
UpMbps: 100,
|
||||
DownMbps: 100,
|
||||
Obfs: obfs,
|
||||
Password: "password",
|
||||
OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
|
||||
TLS: &option.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
@@ -112,6 +134,10 @@ func testHysteria2Self(t *testing.T, salamanderPassword string) {
|
||||
},
|
||||
})
|
||||
testSuitLargeUDP(t, clientPort, testPort)
|
||||
if portHop {
|
||||
time.Sleep(5 * time.Second)
|
||||
testSuitLargeUDP(t, clientPort, testPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHysteria2Inbound(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user