mirror of
https://github.com/fatedier/frp.git
synced 2026-07-31 07:52:53 +08:00
feat: add negotiated binary UDP packets (#5456)
This commit is contained in:
@@ -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