1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00

106 lines
2.6 KiB
Go
Raw Normal View History

2015-09-12 11:51:42 +02:00
package main
2015-09-12 20:36:21 +02:00
import (
"flag"
2015-09-18 11:59:36 +02:00
"fmt"
2015-10-18 13:14:34 +02:00
"os"
2016-05-10 15:51:38 -07:00
"os/signal"
2015-10-18 13:14:34 +02:00
"path/filepath"
2015-09-12 20:36:21 +02:00
"github.com/v2ray/v2ray-core"
2015-11-22 21:05:16 +01:00
_ "github.com/v2ray/v2ray-core/app/router/rules"
2015-09-20 00:50:21 +02:00
"github.com/v2ray/v2ray-core/common/log"
2015-11-29 14:45:32 +01:00
"github.com/v2ray/v2ray-core/shell/point"
2015-09-12 20:36:21 +02:00
2016-02-05 22:04:43 +01:00
// The following are necessary as they register handlers in their init functions.
2015-11-22 21:05:16 +01:00
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
2015-10-30 15:56:46 +01:00
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
2015-10-07 00:30:44 +02:00
_ "github.com/v2ray/v2ray-core/proxy/freedom"
2015-12-15 16:00:47 +01:00
_ "github.com/v2ray/v2ray-core/proxy/http"
_ "github.com/v2ray/v2ray-core/proxy/shadowsocks"
_ "github.com/v2ray/v2ray-core/proxy/socks"
2015-12-07 19:32:38 +00:00
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
2016-06-14 22:54:08 +02:00
_ "github.com/v2ray/v2ray-core/transport/internet/kcp"
_ "github.com/v2ray/v2ray-core/transport/internet/tcp"
_ "github.com/v2ray/v2ray-core/transport/internet/udp"
2015-09-12 20:36:21 +02:00
)
var (
2015-10-18 13:14:34 +02:00
configFile string
2015-10-07 10:05:11 +02:00
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
2015-09-18 11:59:36 +02:00
version = flag.Bool("version", false, "Show current version of V2Ray.")
2016-01-24 12:58:04 +01:00
test = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
2015-09-12 20:36:21 +02:00
)
2015-10-18 13:14:34 +02:00
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.")
}
2015-09-12 11:51:42 +02:00
func main() {
2015-09-12 20:36:21 +02:00
flag.Parse()
2015-09-16 00:06:22 +02:00
2015-10-13 14:30:37 +02:00
core.PrintVersion()
2015-09-18 11:59:36 +02:00
if *version {
return
}
2015-09-16 00:06:22 +02:00
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)
2015-10-07 10:05:11 +02:00
default:
fmt.Println("Unknown log level: " + *logLevel)
return
2015-09-16 00:06:22 +02:00
}
2015-09-12 20:36:21 +02:00
2015-10-18 13:14:34 +02:00
if len(configFile) == 0 {
2015-10-07 10:05:11 +02:00
log.Error("Config file is not set.")
return
2015-09-12 20:36:21 +02:00
}
2016-01-17 21:43:10 +01:00
config, err := point.LoadConfig(configFile)
2015-09-12 20:36:21 +02:00
if err != nil {
2016-01-18 12:24:33 +01:00
log.Error("Failed to read config file (", configFile, "): ", configFile, err)
2015-10-07 10:05:11 +02:00
return
2015-09-12 20:36:21 +02:00
}
2016-01-17 21:43:10 +01:00
if config.LogConfig != nil && len(config.LogConfig.AccessLog) > 0 {
log.InitAccessLogger(config.LogConfig.AccessLog)
2015-10-09 17:43:27 +02:00
}
2015-10-14 14:51:19 +02:00
vPoint, err := point.NewPoint(config)
2015-09-12 20:36:21 +02:00
if err != nil {
2016-01-18 12:24:33 +01:00
log.Error("Failed to create Point server: ", err)
2015-10-07 10:05:11 +02:00
return
2015-09-12 20:36:21 +02:00
}
2016-01-24 12:58:04 +01:00
if *test {
fmt.Println("Configuration OK.")
return
}
2015-09-12 20:36:21 +02:00
err = vPoint.Start()
if err != nil {
2016-01-18 12:24:33 +01:00
log.Error("Error starting Point server: ", err)
2015-10-07 10:05:11 +02:00
return
2015-09-12 20:36:21 +02:00
}
2015-09-12 11:51:42 +02:00
2016-05-10 15:51:38 -07:00
osSignals := make(chan os.Signal, 1)
signal.Notify(osSignals, os.Interrupt, os.Kill)
<-osSignals
vPoint.Close()
2015-09-12 11:51:42 +02:00
}