mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-12 21:18:03 +08:00
chore: add inbound test for tuic
This commit is contained in:
parent
e79465d306
commit
7d7f5c8980
@ -211,6 +211,11 @@ func NewHttpTestTunnel() *TestTunnel {
|
|||||||
},
|
},
|
||||||
CloseFn: ln.Close,
|
CloseFn: ln.Close,
|
||||||
DoTestFn: func(t *testing.T, proxy C.ProxyAdapter) {
|
DoTestFn: func(t *testing.T, proxy C.ProxyAdapter) {
|
||||||
|
// Sequential testing for debugging
|
||||||
|
testFn(t, proxy, "http")
|
||||||
|
testFn(t, proxy, "https")
|
||||||
|
|
||||||
|
// Concurrent testing to detect stress
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
num := 50
|
num := 50
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
|
@ -35,6 +35,7 @@ func testInboundShadowSocks(t *testing.T, inboundOptions inbound.ShadowSocksOpti
|
|||||||
for _, cipher := range shadowsocksCipherList {
|
for _, cipher := range shadowsocksCipherList {
|
||||||
t.Run(cipher, func(t *testing.T) {
|
t.Run(cipher, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||||
inboundOptions.Cipher = cipher
|
inboundOptions.Cipher = cipher
|
||||||
outboundOptions.Cipher = cipher
|
outboundOptions.Cipher = cipher
|
||||||
testInboundShadowSocks0(t, inboundOptions, outboundOptions)
|
testInboundShadowSocks0(t, inboundOptions, outboundOptions)
|
||||||
|
79
listener/inbound/tuic_test.go
Normal file
79
listener/inbound/tuic_test.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package inbound_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/netip"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/adapter/outbound"
|
||||||
|
"github.com/metacubex/mihomo/listener/inbound"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tuicCCs = []string{"cubic", "new_reno", "bbr"}
|
||||||
|
|
||||||
|
func testInboundTuic(t *testing.T, inboundOptions inbound.TuicOption, outboundOptions outbound.TuicOption) {
|
||||||
|
inboundOptions.Users = map[string]string{userUUID: userUUID}
|
||||||
|
inboundOptions.Token = []string{userUUID}
|
||||||
|
|
||||||
|
for _, tuicCC := range tuicCCs {
|
||||||
|
t.Run("v4", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||||
|
outboundOptions.Token = userUUID
|
||||||
|
outboundOptions.CongestionController = tuicCC
|
||||||
|
inboundOptions.CongestionController = tuicCC
|
||||||
|
testInboundTuic0(t, inboundOptions, outboundOptions)
|
||||||
|
})
|
||||||
|
t.Run("v5", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
inboundOptions, outboundOptions := inboundOptions, outboundOptions // don't modify outside options value
|
||||||
|
outboundOptions.UUID = userUUID
|
||||||
|
outboundOptions.Password = userUUID
|
||||||
|
outboundOptions.CongestionController = tuicCC
|
||||||
|
inboundOptions.CongestionController = tuicCC
|
||||||
|
testInboundTuic0(t, inboundOptions, outboundOptions)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInboundTuic0(t *testing.T, inboundOptions inbound.TuicOption, outboundOptions outbound.TuicOption) {
|
||||||
|
inboundOptions.BaseOption = inbound.BaseOption{
|
||||||
|
NameStr: "tuic_inbound",
|
||||||
|
Listen: "127.0.0.1",
|
||||||
|
Port: "0",
|
||||||
|
}
|
||||||
|
in, err := inbound.NewTuic(&inboundOptions)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
tunnel := NewHttpTestTunnel()
|
||||||
|
defer tunnel.Close()
|
||||||
|
|
||||||
|
err = in.Listen(tunnel)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
|
addrPort, err := netip.ParseAddrPort(in.Address())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
outboundOptions.Name = "tuic_outbound"
|
||||||
|
outboundOptions.Server = addrPort.Addr().String()
|
||||||
|
outboundOptions.Port = int(addrPort.Port())
|
||||||
|
|
||||||
|
out, err := outbound.NewTuic(outboundOptions)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
tunnel.DoTest(t, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInboundTuic_TLS(t *testing.T) {
|
||||||
|
inboundOptions := inbound.TuicOption{
|
||||||
|
Certificate: tlsCertificate,
|
||||||
|
PrivateKey: tlsPrivateKey,
|
||||||
|
}
|
||||||
|
outboundOptions := outbound.TuicOption{
|
||||||
|
Fingerprint: tlsFingerprint,
|
||||||
|
}
|
||||||
|
testInboundTuic(t, inboundOptions, outboundOptions)
|
||||||
|
}
|
@ -60,6 +60,14 @@ func New(config LC.TuicServer, tunnel C.Tunnel, additions ...inbound.Addition) (
|
|||||||
} else {
|
} else {
|
||||||
tlsConfig.NextProtos = []string{"h3"}
|
tlsConfig.NextProtos = []string{"h3"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.MaxIdleTime == 0 {
|
||||||
|
config.MaxIdleTime = 15000
|
||||||
|
}
|
||||||
|
if config.AuthenticationTimeout == 0 {
|
||||||
|
config.AuthenticationTimeout = 1000
|
||||||
|
}
|
||||||
|
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
MaxIdleTimeout: time.Duration(config.MaxIdleTime) * time.Millisecond,
|
MaxIdleTimeout: time.Duration(config.MaxIdleTime) * time.Millisecond,
|
||||||
MaxIncomingStreams: ServerMaxIncomingStreams,
|
MaxIncomingStreams: ServerMaxIncomingStreams,
|
||||||
|
Loading…
Reference in New Issue
Block a user