|
@@ -3,6 +3,8 @@ package scenarios
|
|
|
import (
|
|
import (
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
+ "v2ray.com/core/app/router"
|
|
|
|
|
+
|
|
|
xproxy "golang.org/x/net/proxy"
|
|
xproxy "golang.org/x/net/proxy"
|
|
|
socks4 "h12.me/socks"
|
|
socks4 "h12.me/socks"
|
|
|
"v2ray.com/core"
|
|
"v2ray.com/core"
|
|
@@ -10,6 +12,7 @@ import (
|
|
|
"v2ray.com/core/common/net"
|
|
"v2ray.com/core/common/net"
|
|
|
"v2ray.com/core/common/protocol"
|
|
"v2ray.com/core/common/protocol"
|
|
|
"v2ray.com/core/common/serial"
|
|
"v2ray.com/core/common/serial"
|
|
|
|
|
+ "v2ray.com/core/proxy/blackhole"
|
|
|
"v2ray.com/core/proxy/dokodemo"
|
|
"v2ray.com/core/proxy/dokodemo"
|
|
|
"v2ray.com/core/proxy/freedom"
|
|
"v2ray.com/core/proxy/freedom"
|
|
|
"v2ray.com/core/proxy/socks"
|
|
"v2ray.com/core/proxy/socks"
|
|
@@ -212,6 +215,107 @@ func TestSocksBridageUDP(t *testing.T) {
|
|
|
CloseAllServers(servers)
|
|
CloseAllServers(servers)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestSocksBridageUDPWithRouting(t *testing.T) {
|
|
|
|
|
+ assert := With(t)
|
|
|
|
|
+
|
|
|
|
|
+ udpServer := udp.Server{
|
|
|
|
|
+ MsgProcessor: xor,
|
|
|
|
|
+ }
|
|
|
|
|
+ dest, err := udpServer.Start()
|
|
|
|
|
+ assert(err, IsNil)
|
|
|
|
|
+ defer udpServer.Close()
|
|
|
|
|
+
|
|
|
|
|
+ serverPort := tcp.PickPort()
|
|
|
|
|
+ serverConfig := &core.Config{
|
|
|
|
|
+ App: []*serial.TypedMessage{
|
|
|
|
|
+ serial.ToTypedMessage(&router.Config{
|
|
|
|
|
+ Rule: []*router.RoutingRule{
|
|
|
|
|
+ {
|
|
|
|
|
+ Tag: "out",
|
|
|
|
|
+ InboundTag: []string{"socks"},
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ },
|
|
|
|
|
+ Inbound: []*core.InboundHandlerConfig{
|
|
|
|
|
+ {
|
|
|
|
|
+ Tag: "socks",
|
|
|
|
|
+ ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
|
+ PortRange: net.SinglePortRange(serverPort),
|
|
|
|
|
+ Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
+ }),
|
|
|
|
|
+ ProxySettings: serial.ToTypedMessage(&socks.ServerConfig{
|
|
|
|
|
+ AuthType: socks.AuthType_NO_AUTH,
|
|
|
|
|
+ Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
+ UdpEnabled: true,
|
|
|
|
|
+ }),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
|
+ {
|
|
|
|
|
+ ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ Tag: "out",
|
|
|
|
|
+ ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ clientPort := tcp.PickPort()
|
|
|
|
|
+ clientConfig := &core.Config{
|
|
|
|
|
+ Inbound: []*core.InboundHandlerConfig{
|
|
|
|
|
+ {
|
|
|
|
|
+ ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
|
+ PortRange: net.SinglePortRange(clientPort),
|
|
|
|
|
+ Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
+ }),
|
|
|
|
|
+ ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
|
|
|
+ Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
|
+ Port: uint32(dest.Port),
|
|
|
|
|
+ NetworkList: &net.NetworkList{
|
|
|
|
|
+ Network: []net.Network{net.Network_TCP, net.Network_UDP},
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
|
+ {
|
|
|
|
|
+ ProxySettings: serial.ToTypedMessage(&socks.ClientConfig{
|
|
|
|
|
+ Server: []*protocol.ServerEndpoint{
|
|
|
|
|
+ {
|
|
|
|
|
+ Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
|
+ Port: uint32(serverPort),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
|
|
|
+ assert(err, IsNil)
|
|
|
|
|
+
|
|
|
|
|
+ conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
|
|
|
|
|
+ IP: []byte{127, 0, 0, 1},
|
|
|
|
|
+ Port: int(clientPort),
|
|
|
|
|
+ })
|
|
|
|
|
+ assert(err, IsNil)
|
|
|
|
|
+
|
|
|
|
|
+ payload := "dokodemo request."
|
|
|
|
|
+ nBytes, err := conn.Write([]byte(payload))
|
|
|
|
|
+ assert(err, IsNil)
|
|
|
|
|
+ assert(nBytes, Equals, len(payload))
|
|
|
|
|
+
|
|
|
|
|
+ response := make([]byte, 1024)
|
|
|
|
|
+ nBytes, err = conn.Read(response)
|
|
|
|
|
+ assert(err, IsNil)
|
|
|
|
|
+ assert(response[:nBytes], Equals, xor([]byte(payload)))
|
|
|
|
|
+ assert(conn.Close(), IsNil)
|
|
|
|
|
+
|
|
|
|
|
+ CloseAllServers(servers)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestSocksConformance(t *testing.T) {
|
|
func TestSocksConformance(t *testing.T) {
|
|
|
assert := With(t)
|
|
assert := With(t)
|
|
|
|
|
|