mirror of
https://github.com/fatedier/frp.git
synced 2026-07-31 09:52:53 +08:00
feat: add negotiated binary UDP packets (#5456)
This commit is contained in:
@@ -192,6 +192,41 @@ transport.wireProtocol = "v2"
|
||||
})
|
||||
})
|
||||
|
||||
var _ = ginkgo.Describe("[Compatibility: BinaryUDPPacket]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
supportsV2, knownVersion := baselineSupportsControlWireProtocolV2(compatCtx.BaselineVersion)
|
||||
if !knownVersion || !supportsV2 {
|
||||
ginkgo.Skip(fmt.Sprintf("baseline version %q does not have known wire protocol v2 support", compatCtx.BaselineVersion))
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.It("current frps falls back to JSON for baseline frpc", func() {
|
||||
portName := port.GenName("CompatBinaryUDPBaselineFRPC")
|
||||
clientConf := udpClientConfig("udp", portName, `transport.wireProtocol = "v2"`)
|
||||
f.RunProcessesWithBinaries(
|
||||
compatCtx.CurrentFRPSPath,
|
||||
compatCtx.BaselineFRPCPath,
|
||||
consts.DefaultServerConfig,
|
||||
[]string{clientConf},
|
||||
)
|
||||
framework.NewRequestExpect(f).Protocol("udp").PortName(portName).Ensure()
|
||||
})
|
||||
|
||||
ginkgo.It("current frpc falls back to JSON for baseline frps", func() {
|
||||
portName := port.GenName("CompatBinaryUDPBaselineFRPS")
|
||||
clientConf := udpClientConfig("udp", portName, `transport.wireProtocol = "v2"`)
|
||||
f.RunProcessesWithBinaries(
|
||||
compatCtx.BaselineFRPSPath,
|
||||
compatCtx.CurrentFRPCPath,
|
||||
consts.DefaultServerConfig,
|
||||
[]string{clientConf},
|
||||
)
|
||||
framework.NewRequestExpect(f).Protocol("udp").PortName(portName).Ensure()
|
||||
})
|
||||
})
|
||||
|
||||
func tcpClientConfig(proxyName string, remotePortName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
serverAddr = "127.0.0.1"
|
||||
@@ -208,6 +243,22 @@ remotePort = {{ .%s }}
|
||||
`, consts.PortServerName, extra, proxyName, framework.TCPEchoServerPort, remotePortName)
|
||||
}
|
||||
|
||||
func udpClientConfig(proxyName string, remotePortName string, extra string) string {
|
||||
return fmt.Sprintf(`
|
||||
serverAddr = "127.0.0.1"
|
||||
serverPort = {{ .%s }}
|
||||
loginFailExit = true
|
||||
log.level = "trace"
|
||||
%s
|
||||
|
||||
[[proxies]]
|
||||
name = "%s"
|
||||
type = "udp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
`, consts.PortServerName, extra, proxyName, framework.UDPEchoServerPort, remotePortName)
|
||||
}
|
||||
|
||||
func expectProcessExit(p *process.Process, timeout time.Duration) {
|
||||
select {
|
||||
case <-p.Done():
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
|
||||
@@ -204,6 +205,87 @@ var _ = ginkgo.Describe("[Feature: WireProtocol]", func() {
|
||||
})
|
||||
})
|
||||
|
||||
var _ = ginkgo.Describe("[Feature: BinaryUDPPacket]", func() {
|
||||
f := framework.NewDefaultFramework()
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
protocol string
|
||||
extraServer string
|
||||
extraTransport string
|
||||
}{
|
||||
{name: "tcp mux on", protocol: "tcp", extraTransport: "transport.tcpMux = true"},
|
||||
{name: "tcp mux off", protocol: "tcp", extraServer: "transport.tcpMux = false", extraTransport: "transport.tcpMux = false"},
|
||||
{name: "kcp", protocol: "kcp"},
|
||||
{name: "quic stream", protocol: "quic"},
|
||||
{name: "websocket", protocol: "websocket"},
|
||||
} {
|
||||
ginkgo.It(tc.name, func() {
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
server: renderBindPortConfig(tc.protocol) + "\n" + tc.extraServer,
|
||||
client: fmt.Sprintf(`
|
||||
transport.wireProtocol = "v2"
|
||||
transport.protocol = %q
|
||||
%s
|
||||
`, tc.protocol, tc.extraTransport),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
ginkgo.It("wss", func() {
|
||||
wssPort := f.AllocPort()
|
||||
runClientServerTest(f, &generalTestConfigures{
|
||||
clientPrefix: fmt.Sprintf(`
|
||||
serverAddr = "127.0.0.1"
|
||||
serverPort = %d
|
||||
loginFailExit = false
|
||||
transport.protocol = "wss"
|
||||
transport.wireProtocol = "v2"
|
||||
log.level = "trace"
|
||||
`, wssPort),
|
||||
client2: fmt.Sprintf(`
|
||||
[[proxies]]
|
||||
name = "wss2ws"
|
||||
type = "tcp"
|
||||
remotePort = %d
|
||||
[proxies.plugin]
|
||||
type = "https2http"
|
||||
localAddr = "127.0.0.1:{{ .%s }}"
|
||||
`, wssPort, consts.PortServerName),
|
||||
testDelay: 10 * time.Second,
|
||||
})
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
transport string
|
||||
}{
|
||||
{name: "plain"},
|
||||
{name: "aes-cfb", transport: "transport.useEncryption = true"},
|
||||
{name: "snappy", transport: "transport.useCompression = true"},
|
||||
{name: "snappy and aes-cfb", transport: "transport.useEncryption = true\ntransport.useCompression = true"},
|
||||
{name: "limiter", transport: "transport.bandwidthLimit = \"1MB\""},
|
||||
} {
|
||||
ginkgo.It(tc.name, func() {
|
||||
serverConf := consts.DefaultServerConfig
|
||||
udpPortName := port.GenName("BinaryUDPPacket")
|
||||
clientConf := consts.DefaultClientConfig + fmt.Sprintf(`
|
||||
transport.wireProtocol = "v2"
|
||||
|
||||
[[proxies]]
|
||||
name = "udp"
|
||||
type = "udp"
|
||||
localPort = {{ .%s }}
|
||||
remotePort = {{ .%s }}
|
||||
%s
|
||||
`, framework.UDPEchoServerPort, udpPortName, tc.transport)
|
||||
|
||||
f.RunProcesses(serverConf, []string{clientConf})
|
||||
framework.NewRequestExpect(f).Protocol("udp").PortName(udpPortName).Ensure()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
type wireClientInfo struct {
|
||||
ClientID string `json:"clientID"`
|
||||
WireProtocol string `json:"wireProtocol"`
|
||||
|
||||
Reference in New Issue
Block a user