2018-02-06 07:47:50 -05:00
|
|
|
package scenarios
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-02-06 05:53:33 -05:00
|
|
|
"io"
|
2020-06-02 23:25:47 -04:00
|
|
|
"strings"
|
2018-02-06 07:47:50 -05:00
|
|
|
"testing"
|
2018-03-31 04:30:12 -04:00
|
|
|
"time"
|
2018-02-19 10:52:51 -05:00
|
|
|
|
2019-01-06 18:12:04 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2020-10-11 07:22:46 -04:00
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
2018-02-06 07:47:50 -05:00
|
|
|
"google.golang.org/grpc"
|
2021-10-28 06:34:19 -04:00
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
2021-02-16 15:31:50 -05:00
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
core "github.com/v2fly/v2ray-core/v5"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/commander"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/policy"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/proxyman"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/proxyman/command"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/router"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/app/stats"
|
|
|
|
statscmd "github.com/v2fly/v2ray-core/v5/app/stats/command"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/uuid"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/dokodemo"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/freedom"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/testing/servers/tcp"
|
2018-02-06 07:47:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommanderRemoveHandler(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-02-06 07:47:50 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
|
|
|
cmdPort := tcp.PickPort()
|
2018-02-06 07:47:50 -05:00
|
|
|
clientConfig := &core.Config{
|
2021-06-19 09:36:54 -04:00
|
|
|
App: []*anypb.Any{
|
2018-02-08 17:33:40 -05:00
|
|
|
serial.ToTypedMessage(&commander.Config{
|
|
|
|
Tag: "api",
|
2021-06-19 09:36:54 -04:00
|
|
|
Service: []*anypb.Any{
|
2018-02-08 17:33:40 -05:00
|
|
|
serial.ToTypedMessage(&command.Config{}),
|
|
|
|
},
|
|
|
|
}),
|
2018-02-06 07:47:50 -05:00
|
|
|
serial.ToTypedMessage(&router.Config{
|
|
|
|
Rule: []*router.RoutingRule{
|
|
|
|
{
|
|
|
|
InboundTag: []string{"api"},
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "api",
|
|
|
|
},
|
2018-02-06 07:47:50 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
Tag: "d",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(clientPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2018-11-20 10:58:26 -05:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2018-02-06 07:47:50 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tag: "api",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(cmdPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2018-11-20 10:58:26 -05:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2018-02-06 07:47:50 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
Tag: "default-outbound",
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(clientConfig)
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-07-12 17:38:10 -04:00
|
|
|
defer CloseAllServers(servers)
|
|
|
|
|
2019-02-03 13:46:53 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*5)(); err != nil {
|
|
|
|
t.Fatal(err)
|
2018-02-06 07:47:50 -05:00
|
|
|
}
|
|
|
|
|
2018-03-08 17:40:02 -05:00
|
|
|
cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-11-11 15:13:05 -05:00
|
|
|
defer cmdConn.Close()
|
2018-02-06 07:47:50 -05:00
|
|
|
|
|
|
|
hsClient := command.NewHandlerServiceClient(cmdConn)
|
|
|
|
resp, err := hsClient.RemoveInbound(context.Background(), &command.RemoveInboundRequest{
|
|
|
|
Tag: "d",
|
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if resp == nil {
|
|
|
|
t.Error("unexpected nil response")
|
|
|
|
}
|
2018-02-06 07:47:50 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
_, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
|
|
|
IP: []byte{127, 0, 0, 1},
|
|
|
|
Port: int(clientPort),
|
|
|
|
})
|
2019-02-03 13:46:53 -05:00
|
|
|
if err == nil {
|
|
|
|
t.Error("unexpected nil error")
|
|
|
|
}
|
2018-02-06 07:47:50 -05:00
|
|
|
}
|
|
|
|
}
|
2018-02-19 10:52:51 -05:00
|
|
|
|
|
|
|
func TestCommanderAddRemoveUser(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-02-19 10:52:51 -05:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
u1 := protocol.NewID(uuid.New())
|
|
|
|
u2 := protocol.NewID(uuid.New())
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
cmdPort := tcp.PickPort()
|
|
|
|
serverPort := tcp.PickPort()
|
2018-02-19 10:52:51 -05:00
|
|
|
serverConfig := &core.Config{
|
2021-06-19 09:36:54 -04:00
|
|
|
App: []*anypb.Any{
|
2018-02-19 10:52:51 -05:00
|
|
|
serial.ToTypedMessage(&commander.Config{
|
|
|
|
Tag: "api",
|
2021-06-19 09:36:54 -04:00
|
|
|
Service: []*anypb.Any{
|
2018-02-19 10:52:51 -05:00
|
|
|
serial.ToTypedMessage(&command.Config{}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
serial.ToTypedMessage(&router.Config{
|
|
|
|
Rule: []*router.RoutingRule{
|
|
|
|
{
|
|
|
|
InboundTag: []string{"api"},
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "api",
|
|
|
|
},
|
2018-02-19 10:52:51 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
serial.ToTypedMessage(&policy.Config{
|
|
|
|
Level: map[uint32]*policy.Policy{
|
2018-02-22 04:34:14 -05:00
|
|
|
0: {
|
2018-02-19 10:52:51 -05:00
|
|
|
Timeout: &policy.Policy_Timeout{
|
|
|
|
UplinkOnly: &policy.Second{Value: 0},
|
|
|
|
DownlinkOnly: &policy.Second{Value: 0},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
Tag: "v",
|
|
|
|
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: u1.String(),
|
2021-12-31 22:10:09 -05:00
|
|
|
AlterId: 0,
|
2018-02-19 10:52:51 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tag: "api",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(cmdPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2018-11-20 10:58:26 -05:00
|
|
|
Address: net.NewIPOrDomain(dest.Address),
|
|
|
|
Port: uint32(dest.Port),
|
|
|
|
Networks: []net.Network{net.Network_TCP},
|
2018-02-19 10:52:51 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 05:53:39 -05:00
|
|
|
clientPort := tcp.PickPort()
|
2018-02-19 10:52:51 -05:00
|
|
|
clientConfig := &core.Config{
|
2021-06-19 09:36:54 -04:00
|
|
|
App: []*anypb.Any{
|
2018-02-19 10:52:51 -05:00
|
|
|
serial.ToTypedMessage(&policy.Config{
|
|
|
|
Level: map[uint32]*policy.Policy{
|
2018-02-22 04:34:14 -05:00
|
|
|
0: {
|
2018-02-19 10:52:51 -05:00
|
|
|
Timeout: &policy.Policy_Timeout{
|
|
|
|
UplinkOnly: &policy.Second{Value: 0},
|
|
|
|
DownlinkOnly: &policy.Second{Value: 0},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
|
|
|
Tag: "d",
|
|
|
|
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},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: u2.String(),
|
2021-12-31 22:10:09 -05:00
|
|
|
AlterId: 0,
|
2018-02-19 10:52:51 -05:00
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_AES128_GCM,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-06 05:30:20 -05:00
|
|
|
defer CloseAllServers(servers)
|
2018-02-19 10:52:51 -05:00
|
|
|
|
2020-06-02 23:25:47 -04:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*5)(); err != io.EOF &&
|
|
|
|
/*We might wish to drain the connection*/
|
|
|
|
(err != nil && !strings.HasSuffix(err.Error(), "i/o timeout")) {
|
2019-02-06 05:53:33 -05:00
|
|
|
t.Fatal("expected error: ", err)
|
2018-02-19 10:52:51 -05:00
|
|
|
}
|
|
|
|
|
2018-03-08 17:40:02 -05:00
|
|
|
cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-11-11 15:13:05 -05:00
|
|
|
defer cmdConn.Close()
|
2018-02-19 10:52:51 -05:00
|
|
|
|
|
|
|
hsClient := command.NewHandlerServiceClient(cmdConn)
|
|
|
|
resp, err := hsClient.AlterInbound(context.Background(), &command.AlterInboundRequest{
|
|
|
|
Tag: "v",
|
|
|
|
Operation: serial.ToTypedMessage(
|
|
|
|
&command.AddUserOperation{
|
|
|
|
User: &protocol.User{
|
2021-02-16 15:31:50 -05:00
|
|
|
Email: "test@v2fly.org",
|
2018-02-19 10:52:51 -05:00
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: u2.String(),
|
2021-12-31 22:10:09 -05:00
|
|
|
AlterId: 0,
|
2018-02-19 10:52:51 -05:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("nil response")
|
|
|
|
}
|
2018-02-19 10:52:51 -05:00
|
|
|
|
2019-02-03 13:46:53 -05:00
|
|
|
if err := testTCPConn(clientPort, 1024, time.Second*5)(); err != nil {
|
|
|
|
t.Fatal(err)
|
2018-02-19 10:52:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = hsClient.AlterInbound(context.Background(), &command.AlterInboundRequest{
|
|
|
|
Tag: "v",
|
2021-02-16 15:31:50 -05:00
|
|
|
Operation: serial.ToTypedMessage(&command.RemoveUserOperation{Email: "test@v2fly.org"}),
|
2018-02-19 10:52:51 -05:00
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("nil response")
|
|
|
|
}
|
2018-02-19 10:52:51 -05:00
|
|
|
}
|
2018-03-31 04:30:12 -04:00
|
|
|
|
|
|
|
func TestCommanderStats(t *testing.T) {
|
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: xor,
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-03-31 04:30:12 -04:00
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
userID := protocol.NewID(uuid.New())
|
|
|
|
serverPort := tcp.PickPort()
|
|
|
|
cmdPort := tcp.PickPort()
|
|
|
|
|
|
|
|
serverConfig := &core.Config{
|
2021-06-19 09:36:54 -04:00
|
|
|
App: []*anypb.Any{
|
2018-03-31 04:30:12 -04:00
|
|
|
serial.ToTypedMessage(&stats.Config{}),
|
|
|
|
serial.ToTypedMessage(&commander.Config{
|
|
|
|
Tag: "api",
|
2021-06-19 09:36:54 -04:00
|
|
|
Service: []*anypb.Any{
|
2018-03-31 04:30:12 -04:00
|
|
|
serial.ToTypedMessage(&statscmd.Config{}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
serial.ToTypedMessage(&router.Config{
|
|
|
|
Rule: []*router.RoutingRule{
|
|
|
|
{
|
|
|
|
InboundTag: []string{"api"},
|
2018-11-07 19:01:53 -05:00
|
|
|
TargetTag: &router.RoutingRule_Tag{
|
|
|
|
Tag: "api",
|
|
|
|
},
|
2018-03-31 04:30:12 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
serial.ToTypedMessage(&policy.Config{
|
|
|
|
Level: map[uint32]*policy.Policy{
|
|
|
|
0: {
|
|
|
|
Timeout: &policy.Policy_Timeout{
|
|
|
|
UplinkOnly: &policy.Second{Value: 0},
|
|
|
|
DownlinkOnly: &policy.Second{Value: 0},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
Stats: &policy.Policy_Stats{
|
2018-03-31 14:30:49 -04:00
|
|
|
UserUplink: true,
|
|
|
|
UserDownlink: true,
|
2018-03-31 04:30:12 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-11 18:10:14 -04:00
|
|
|
System: &policy.SystemPolicy{
|
|
|
|
Stats: &policy.SystemPolicy_Stats{
|
|
|
|
InboundUplink: true,
|
|
|
|
},
|
|
|
|
},
|
2018-03-31 04:30:12 -04:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
Inbound: []*core.InboundHandlerConfig{
|
|
|
|
{
|
2018-04-11 18:10:14 -04:00
|
|
|
Tag: "vmess",
|
2018-03-31 04:30:12 -04:00
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(serverPort),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Level: 1,
|
|
|
|
Email: "test",
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
2021-12-31 22:10:09 -05:00
|
|
|
AlterId: 0,
|
2018-03-31 04:30:12 -04:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tag: "api",
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
|
|
PortRange: net.SinglePortRange(cmdPort),
|
|
|
|
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},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
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},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outbound: []*core.OutboundHandlerConfig{
|
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
|
|
Port: uint32(serverPort),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
|
|
|
Id: userID.String(),
|
2021-12-31 22:10:09 -05:00
|
|
|
AlterId: 0,
|
2018-03-31 04:30:12 -04:00
|
|
|
SecuritySettings: &protocol.SecurityConfig{
|
|
|
|
Type: protocol.SecurityType_AES128_GCM,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
2018-07-12 17:38:10 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to create all servers", err)
|
|
|
|
}
|
|
|
|
defer CloseAllServers(servers)
|
2018-03-31 04:30:12 -04:00
|
|
|
|
2019-01-11 11:17:59 -05:00
|
|
|
if err := testTCPConn(clientPort, 10240*1024, time.Second*20)(); err != nil {
|
|
|
|
t.Fatal(err)
|
2018-08-25 09:59:35 -04:00
|
|
|
}
|
2018-03-31 04:30:12 -04:00
|
|
|
|
|
|
|
cmdConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", cmdPort), grpc.WithInsecure(), grpc.WithBlock())
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2018-11-11 15:13:05 -05:00
|
|
|
defer cmdConn.Close()
|
2018-03-31 04:30:12 -04:00
|
|
|
|
2018-03-31 14:30:49 -04:00
|
|
|
const name = "user>>>test>>>traffic>>>uplink"
|
2018-03-31 04:30:12 -04:00
|
|
|
sClient := statscmd.NewStatsServiceClient(cmdConn)
|
|
|
|
|
|
|
|
sresp, err := sClient.GetStats(context.Background(), &statscmd.GetStatsRequest{
|
|
|
|
Name: name,
|
|
|
|
Reset_: true,
|
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if r := cmp.Diff(sresp.Stat, &statscmd.Stat{
|
|
|
|
Name: name,
|
|
|
|
Value: 10240 * 1024,
|
2020-06-08 04:16:50 -04:00
|
|
|
}, cmpopts.IgnoreUnexported(statscmd.Stat{})); r != "" {
|
2019-02-03 13:46:53 -05:00
|
|
|
t.Error(r)
|
|
|
|
}
|
2018-03-31 04:30:12 -04:00
|
|
|
|
|
|
|
sresp, err = sClient.GetStats(context.Background(), &statscmd.GetStatsRequest{
|
|
|
|
Name: name,
|
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if r := cmp.Diff(sresp.Stat, &statscmd.Stat{
|
|
|
|
Name: name,
|
|
|
|
Value: 0,
|
2020-06-08 04:16:50 -04:00
|
|
|
}, cmpopts.IgnoreUnexported(statscmd.Stat{})); r != "" {
|
2019-02-03 13:46:53 -05:00
|
|
|
t.Error(r)
|
|
|
|
}
|
2018-03-31 04:30:12 -04:00
|
|
|
|
2018-04-11 18:10:14 -04:00
|
|
|
sresp, err = sClient.GetStats(context.Background(), &statscmd.GetStatsRequest{
|
|
|
|
Name: "inbound>>>vmess>>>traffic>>>uplink",
|
|
|
|
Reset_: true,
|
|
|
|
})
|
2019-02-02 16:19:30 -05:00
|
|
|
common.Must(err)
|
2019-02-03 13:46:53 -05:00
|
|
|
if sresp.Stat.Value <= 10240*1024 {
|
|
|
|
t.Error("value < 10240*1024: ", sresp.Stat.Value)
|
|
|
|
}
|
2018-03-31 04:30:12 -04:00
|
|
|
}
|