2015-09-12 05:51:42 -04:00
|
|
|
package main
|
|
|
|
|
2015-09-12 14:36:21 -04:00
|
|
|
import (
|
|
|
|
"flag"
|
2015-09-18 05:59:36 -04:00
|
|
|
"fmt"
|
2015-10-18 07:14:34 -04:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-09-12 14:36:21 -04:00
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core"
|
2015-10-14 08:51:19 -04:00
|
|
|
"github.com/v2ray/v2ray-core/app/point"
|
2015-10-30 17:50:45 -04:00
|
|
|
jsonconf "github.com/v2ray/v2ray-core/app/point/config/json"
|
2015-09-19 18:50:21 -04:00
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
2015-09-12 14:36:21 -04:00
|
|
|
|
2015-09-13 14:01:50 -04:00
|
|
|
// The following are neccesary as they register handlers in their init functions.
|
2015-10-30 10:56:46 -04:00
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/config/json"
|
2015-10-06 18:30:44 -04:00
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
2015-10-06 17:11:08 -04:00
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
2015-09-19 17:54:36 -04:00
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/socks"
|
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/vmess"
|
2015-10-16 06:05:59 -04:00
|
|
|
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
|
2015-09-12 14:36:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-10-18 07:14:34 -04:00
|
|
|
configFile string
|
2015-10-07 04:05:11 -04:00
|
|
|
logLevel = flag.String("loglevel", "warning", "Level of log info to be printed to console, available value: debug, info, warning, error")
|
2015-09-18 05:59:36 -04:00
|
|
|
version = flag.Bool("version", false, "Show current version of V2Ray.")
|
2015-09-12 14:36:21 -04:00
|
|
|
)
|
|
|
|
|
2015-10-18 07:14:34 -04: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 05:51:42 -04:00
|
|
|
func main() {
|
2015-09-12 14:36:21 -04:00
|
|
|
flag.Parse()
|
2015-09-15 18:06:22 -04:00
|
|
|
|
2015-10-13 08:30:37 -04:00
|
|
|
core.PrintVersion()
|
|
|
|
|
2015-09-18 05:59:36 -04:00
|
|
|
if *version {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-09-15 18:06:22 -04: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 04:05:11 -04:00
|
|
|
default:
|
|
|
|
fmt.Println("Unknown log level: " + *logLevel)
|
|
|
|
return
|
2015-09-15 18:06:22 -04:00
|
|
|
}
|
2015-09-12 14:36:21 -04:00
|
|
|
|
2015-10-18 07:14:34 -04:00
|
|
|
if len(configFile) == 0 {
|
2015-10-07 04:05:11 -04:00
|
|
|
log.Error("Config file is not set.")
|
|
|
|
return
|
2015-09-12 14:36:21 -04:00
|
|
|
}
|
2015-10-18 07:14:34 -04:00
|
|
|
config, err := jsonconf.LoadConfig(configFile)
|
2015-09-12 14:36:21 -04:00
|
|
|
if err != nil {
|
2015-10-18 07:14:34 -04:00
|
|
|
log.Error("Failed to read config file (%s): %v", configFile, err)
|
2015-10-07 04:05:11 -04:00
|
|
|
return
|
2015-09-12 14:36:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-09 11:43:27 -04:00
|
|
|
if config.LogConfig() != nil && len(config.LogConfig().AccessLog()) > 0 {
|
|
|
|
log.InitAccessLogger(config.LogConfig().AccessLog())
|
|
|
|
}
|
|
|
|
|
2015-10-14 08:51:19 -04:00
|
|
|
vPoint, err := point.NewPoint(config)
|
2015-09-12 14:36:21 -04:00
|
|
|
if err != nil {
|
2015-10-07 04:05:11 -04:00
|
|
|
log.Error("Failed to create Point server: %v", err)
|
|
|
|
return
|
2015-09-12 14:36:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = vPoint.Start()
|
|
|
|
if err != nil {
|
2015-09-12 16:11:54 -04:00
|
|
|
log.Error("Error starting Point server: %v", err)
|
2015-10-07 04:05:11 -04:00
|
|
|
return
|
2015-09-12 14:36:21 -04:00
|
|
|
}
|
2015-09-12 05:51:42 -04:00
|
|
|
|
2015-09-12 14:36:21 -04:00
|
|
|
finish := make(chan bool)
|
|
|
|
<-finish
|
2015-09-12 05:51:42 -04:00
|
|
|
}
|