mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
change project structure
add across nodes ip limit add user ip recorder del config file watch
This commit is contained in:
78
node/node_test.go
Normal file
78
node/node_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package node_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "github.com/Yuzuki616/V2bX/node"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/api"
|
||||
_ "github.com/Yuzuki616/V2bX/example/distro/all"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/infra/conf"
|
||||
)
|
||||
|
||||
func TestController(t *testing.T) {
|
||||
serverConfig := &conf.Config{
|
||||
Stats: &conf.StatsConfig{},
|
||||
LogConfig: &conf.LogConfig{LogLevel: "debug"},
|
||||
}
|
||||
policyConfig := &conf.PolicyConfig{}
|
||||
policyConfig.Levels = map[uint32]*conf.Policy{0: &conf.Policy{
|
||||
StatsUserUplink: true,
|
||||
StatsUserDownlink: true,
|
||||
}}
|
||||
serverConfig.Policy = policyConfig
|
||||
config, _ := serverConfig.Build()
|
||||
|
||||
// config := &core.Config{
|
||||
// App: []*serial.TypedMessage{
|
||||
// serial.ToTypedMessage(&dispatcher.Config{}),
|
||||
// serial.ToTypedMessage(&proxyman.InboundConfig{}),
|
||||
// serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||
// serial.ToTypedMessage(&stats.Config{}),
|
||||
// }}
|
||||
|
||||
server, err := core.New(config)
|
||||
defer server.Close()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create instance: %s", err)
|
||||
}
|
||||
if err = server.Start(); err != nil {
|
||||
t.Errorf("Failed to start instance: %s", err)
|
||||
}
|
||||
certConfig := &CertConfig{
|
||||
CertMode: "http",
|
||||
CertDomain: "test.ss.tk",
|
||||
Provider: "alidns",
|
||||
Email: "ss@ss.com",
|
||||
}
|
||||
controlerconfig := &Config{
|
||||
UpdatePeriodic: 5,
|
||||
CertConfig: certConfig,
|
||||
}
|
||||
apiConfig := &api.Config{
|
||||
APIHost: "http://127.0.0.1:667",
|
||||
Key: "123",
|
||||
NodeID: 41,
|
||||
NodeType: "V2ray",
|
||||
}
|
||||
apiclient := api.New(apiConfig)
|
||||
c := New(server, apiclient, controlerconfig)
|
||||
fmt.Println("Sleep 1s")
|
||||
err = c.Start()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//Explicitly triggering GC to remove garbage from config loading.
|
||||
runtime.GC()
|
||||
|
||||
{
|
||||
osSignals := make(chan os.Signal, 1)
|
||||
signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||
<-osSignals
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user