|
|
@ -36,59 +36,87 @@ func TestVMessDynamicPort(t *testing.T) { |
|
|
|
defer tcpServer.Close() |
|
|
|
defer tcpServer.Close() |
|
|
|
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New()) |
|
|
|
userID := protocol.NewID(uuid.New()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
retry := 1 |
|
|
|
serverPort := tcp.PickPort() |
|
|
|
serverPort := tcp.PickPort() |
|
|
|
serverConfig := &core.Config{ |
|
|
|
for { |
|
|
|
App: []*serial.TypedMessage{ |
|
|
|
serverConfig := &core.Config{ |
|
|
|
serial.ToTypedMessage(&log.Config{ |
|
|
|
App: []*serial.TypedMessage{ |
|
|
|
ErrorLogLevel: clog.Severity_Debug, |
|
|
|
serial.ToTypedMessage(&log.Config{ |
|
|
|
ErrorLogType: log.LogType_Console, |
|
|
|
ErrorLogLevel: clog.Severity_Debug, |
|
|
|
}), |
|
|
|
ErrorLogType: log.LogType_Console, |
|
|
|
}, |
|
|
|
|
|
|
|
Inbound: []*core.InboundHandlerConfig{ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ |
|
|
|
|
|
|
|
PortRange: net.SinglePortRange(serverPort), |
|
|
|
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{ |
|
|
|
|
|
|
|
User: []*protocol.User{ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{ |
|
|
|
|
|
|
|
Id: userID.String(), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Detour: &inbound.DetourConfig{ |
|
|
|
|
|
|
|
To: "detour", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
}), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
Inbound: []*core.InboundHandlerConfig{ |
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ |
|
|
|
{ |
|
|
|
PortRange: &net.PortRange{ |
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ |
|
|
|
From: uint32(serverPort + 1), |
|
|
|
PortRange: net.SinglePortRange(serverPort), |
|
|
|
To: uint32(serverPort + 100), |
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP), |
|
|
|
}, |
|
|
|
}), |
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP), |
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{ |
|
|
|
AllocationStrategy: &proxyman.AllocationStrategy{ |
|
|
|
User: []*protocol.User{ |
|
|
|
Type: proxyman.AllocationStrategy_Random, |
|
|
|
{ |
|
|
|
Concurrency: &proxyman.AllocationStrategy_AllocationStrategyConcurrency{ |
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{ |
|
|
|
Value: 2, |
|
|
|
Id: userID.String(), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Refresh: &proxyman.AllocationStrategy_AllocationStrategyRefresh{ |
|
|
|
Detour: &inbound.DetourConfig{ |
|
|
|
Value: 5, |
|
|
|
To: "detour", |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}), |
|
|
|
}), |
|
|
|
}, |
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{}), |
|
|
|
{ |
|
|
|
Tag: "detour", |
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ |
|
|
|
|
|
|
|
PortRange: net.SinglePortRange(serverPort + 100), |
|
|
|
|
|
|
|
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}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ |
|
|
|
|
|
|
|
PortRange: &net.PortRange{ |
|
|
|
|
|
|
|
From: uint32(serverPort + 1), |
|
|
|
|
|
|
|
To: uint32(serverPort + 99), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP), |
|
|
|
|
|
|
|
AllocationStrategy: &proxyman.AllocationStrategy{ |
|
|
|
|
|
|
|
Type: proxyman.AllocationStrategy_Random, |
|
|
|
|
|
|
|
Concurrency: &proxyman.AllocationStrategy_AllocationStrategyConcurrency{ |
|
|
|
|
|
|
|
Value: 2, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Refresh: &proxyman.AllocationStrategy_AllocationStrategyRefresh{ |
|
|
|
|
|
|
|
Value: 5, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{}), |
|
|
|
|
|
|
|
Tag: "detour", |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Outbound: []*core.OutboundHandlerConfig{ |
|
|
|
Outbound: []*core.OutboundHandlerConfig{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}), |
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}), |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server, _ := InitializeServerConfig(serverConfig) |
|
|
|
|
|
|
|
if server != nil && tcpConnAvailableAtPort(t, serverPort + 100) { |
|
|
|
|
|
|
|
defer CloseServer(server) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
retry += 1 |
|
|
|
|
|
|
|
if (retry > 5) { |
|
|
|
|
|
|
|
t.Fatal("All attempts failed to start server") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
serverPort = tcp.PickPort() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clientPort := tcp.PickPort() |
|
|
|
clientPort := tcp.PickPort() |
|
|
@ -135,15 +163,30 @@ func TestVMessDynamicPort(t *testing.T) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig) |
|
|
|
server, err := InitializeServerConfig(clientConfig) |
|
|
|
common.Must(err) |
|
|
|
common.Must(err) |
|
|
|
defer CloseAllServers(servers) |
|
|
|
defer CloseServer(server) |
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
if !tcpConnAvailableAtPort(t, clientPort) { |
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { |
|
|
|
t.Fail() |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func tcpConnAvailableAtPort(t *testing.T, port net.Port) bool { |
|
|
|
|
|
|
|
for i := 1; ; i++ { |
|
|
|
|
|
|
|
if (i > 10) { |
|
|
|
|
|
|
|
t.Log("All attempts failed to test tcp conn") |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 10) |
|
|
|
|
|
|
|
if err := testTCPConn(port, 1024, time.Second*2)(); err != nil { |
|
|
|
|
|
|
|
t.Log("err ", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
t.Log("success with", i, "attempts") |
|
|
|
|
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestVMessGCM(t *testing.T) { |
|
|
|
func TestVMessGCM(t *testing.T) { |
|
|
|