forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (79 loc) · 2.2 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/v2ray/v2ray-core"
_ "github.com/v2ray/v2ray-core/app/router/rules"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/shell/point"
// The following are necessary as they register handlers in their init functions.
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
_ "github.com/v2ray/v2ray-core/proxy/freedom"
_ "github.com/v2ray/v2ray-core/proxy/http"
_ "github.com/v2ray/v2ray-core/proxy/shadowsocks"
_ "github.com/v2ray/v2ray-core/proxy/socks"
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
)
var (
configFile string
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
version = flag.Bool("version", false, "Show current version of V2Ray.")
test = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
)
func init() {
defaultConfigFile := ""
workingDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err == nil {
defaultConfigFile = filepath.Join(workingDir, "config.json")
}
flag.StringVar(&configFile, "config", defaultConfigFile, "Config file for this Point server.")
}
func main() {
flag.Parse()
core.PrintVersion()
if *version {
return
}
switch *logLevel {
case "debug":
log.SetLogLevel(log.DebugLevel)
case "info":
log.SetLogLevel(log.InfoLevel)
case "warning":
log.SetLogLevel(log.WarningLevel)
case "error":
log.SetLogLevel(log.ErrorLevel)
default:
fmt.Println("Unknown log level: " + *logLevel)
return
}
if len(configFile) == 0 {
log.Error("Config file is not set.")
return
}
config, err := point.LoadConfig(configFile)
if err != nil {
log.Error("Failed to read config file (", configFile, "): ", configFile, err)
return
}
vPoint, err := point.NewPoint(config)
if err != nil {
log.Error("Failed to create Point server: ", err)
return
}
if *test {
fmt.Println("Configuration OK.")
return
}
err = vPoint.Start()
if err != nil {
log.Error("Error starting Point server: ", err)
return
}
finish := make(chan bool)
<-finish
}