2017-02-05 07:44:08 +00:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-20 02:50:46 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2021-02-17 00:07:12 +00:00
|
|
|
|
2021-02-16 20:31:50 +00:00
|
|
|
. "github.com/v2fly/v2ray-core/v4"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/app/dispatcher"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/protocol"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/serial"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/uuid"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/features/dns"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/features/dns/localdns"
|
|
|
|
_ "github.com/v2fly/v2ray-core/v4/main/distro/all"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/proxy/dokodemo"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/proxy/vmess"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/proxy/vmess/outbound"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/testing/servers/tcp"
|
2017-02-05 07:44:08 +00:00
|
|
|
)
|
|
|
|
|
2018-10-22 09:26:22 +00:00
|
|
|
func TestV2RayDependency(t *testing.T) {
|
|
|
|
instance := new(Instance)
|
|
|
|
|
|
|
|
wait := make(chan bool, 1)
|
|
|
|
instance.RequireFeatures(func(d dns.Client) {
|
|
|
|
if d == nil {
|
|
|
|
t.Error("expected dns client fulfilled, but actually nil")
|
|
|
|
}
|
|
|
|
wait <- true
|
|
|
|
})
|
2018-11-19 20:58:03 +00:00
|
|
|
instance.AddFeature(localdns.New())
|
2018-10-22 09:26:22 +00:00
|
|
|
<-wait
|
|
|
|
}
|
|
|
|
|
2017-02-05 07:44:08 +00:00
|
|
|
func TestV2RayClose(t *testing.T) {
|
2018-12-05 15:27:32 +00:00
|
|
|
port := tcp.PickPort()
|
|
|
|
|
2020-10-11 11:22:46 +00:00
|
|
|
userID := uuid.New()
|
2017-02-05 07:44:08 +00:00
|
|
|
config := &Config{
|
2018-01-10 11:59:45 +00:00
|
|
|
App: []*serial.TypedMessage{
|
2018-10-11 20:48:57 +00:00
|
|
|
serial.ToTypedMessage(&dispatcher.Config{}),
|
2018-01-10 11:59:45 +00:00
|
|
|
serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
|
|
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
|
|
|
},
|
|
|
|
Inbound: []*InboundHandlerConfig{
|
2017-02-05 07:44:08 +00:00
|
|
|
{
|
|
|
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
2017-08-29 12:32:54 +00:00
|
|
|
PortRange: net.SinglePortRange(port),
|
|
|
|
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
2017-02-05 07:44:08 +00:00
|
|
|
}),
|
|
|
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
2017-08-29 12:32:54 +00:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-02-05 07:44:08 +00:00
|
|
|
Port: uint32(0),
|
2017-08-29 12:32:54 +00:00
|
|
|
NetworkList: &net.NetworkList{
|
|
|
|
Network: []net.Network{net.Network_TCP, net.Network_UDP},
|
2017-02-05 07:44:08 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2018-01-10 11:59:45 +00:00
|
|
|
Outbound: []*OutboundHandlerConfig{
|
2017-02-05 07:44:08 +00:00
|
|
|
{
|
|
|
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
|
|
Receiver: []*protocol.ServerEndpoint{
|
|
|
|
{
|
2017-08-29 12:32:54 +00:00
|
|
|
Address: net.NewIPOrDomain(net.LocalHostIP),
|
2017-02-05 07:44:08 +00:00
|
|
|
Port: uint32(0),
|
|
|
|
User: []*protocol.User{
|
|
|
|
{
|
|
|
|
Account: serial.ToTypedMessage(&vmess.Account{
|
2020-10-11 11:22:46 +00:00
|
|
|
Id: userID.String(),
|
2017-02-05 07:44:08 +00:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-10-11 20:48:57 +00:00
|
|
|
cfgBytes, err := proto.Marshal(config)
|
|
|
|
common.Must(err)
|
2017-02-05 07:44:08 +00:00
|
|
|
|
improve commands (#648)
* stat show json refactor
> will show {} since scripts should expect it, its the json style of blank value
* combine statistics commands to one
* code optimize
* fix runtime flag
* remove json indent
* change overridden to override
* api bi -json
* convert stdin support
code optimize
* writeRow() code optimize
add stats tittle
revert back to restartlogger
* api log -restart
* follow log
* codeql
* move -json to shared flags
* flags optimize
* update flag descriptions
* change "-v" of "api bo" to duration
* change "-expire" of "tls cert" to days
* cmds short description optimize
* fix multiple log followers
* Format loader refactor
* "infra/conf/merge" refactor
* "LoadConfig" refactor
* add "infra/conf/mergers"
* contribute to it will benifit `v2ray run`,`v2ray test`,`v2ray convert`
* easily add new formats, by just adding a converter like json.FromTOML
* default format auto, to all cmds above
* auto detect input format
* mixed formats support
* better stdin behavior
* don't wait if no content
* don't use 'stdin:' placeholder
* `v2ray test` now behaves exactly the same with `v2ray run`, including stdin reading
* api ado, adi, rmo, rmi refactor
* support folders to files resolving, mixed formats
* remove remaining 'stdin:' placeholders
* fix tests
* os.Stdin.Stat() behaves different in platforms, removed
* code optimize
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
2021-02-21 15:02:42 +00:00
|
|
|
server, err := StartInstance(FormatProtobuf, cfgBytes)
|
2018-10-11 20:48:57 +00:00
|
|
|
common.Must(err)
|
2017-02-10 15:25:54 +00:00
|
|
|
server.Close()
|
2017-02-05 07:44:08 +00:00
|
|
|
}
|