-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
server_env.go
73 lines (63 loc) · 2.03 KB
/
server_env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package scenarios
import (
"os"
"path/filepath"
_ "github.com/v2ray/v2ray-core/app/router/json"
_ "github.com/v2ray/v2ray-core/app/router/rules"
_ "github.com/v2ray/v2ray-core/app/router/rules/json"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/shell/point"
pointjson "github.com/v2ray/v2ray-core/shell/point/json"
// The following are neccesary as they register handlers in their init functions.
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
_ "github.com/v2ray/v2ray-core/proxy/blackhole/json"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/json"
_ "github.com/v2ray/v2ray-core/proxy/freedom"
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
_ "github.com/v2ray/v2ray-core/proxy/socks"
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
)
var (
serverup = make(map[string]bool)
)
func TestFile(filename string) string {
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
}
func InitializeServerSetOnce(testcase string) error {
if up, found := serverup[testcase]; found && up {
return nil
}
err := InitializeServer(TestFile(testcase + "_server.json"))
if err != nil {
return err
}
err = InitializeServer(TestFile(testcase + "_client.json"))
if err != nil {
return err
}
serverup[testcase] = true
return nil
}
func InitializeServer(configFile string) error {
config, err := pointjson.LoadConfig(configFile)
if err != nil {
log.Error("Failed to read config file (%s): %v", configFile, err)
return err
}
vPoint, err := point.NewPoint(config)
if err != nil {
log.Error("Failed to create Point server: %v", err)
return err
}
err = vPoint.Start()
if err != nil {
log.Error("Error starting Point server: %v", err)
return err
}
return nil
}