main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io/ioutil"
  6. "path/filepath"
  7. "github.com/v2ray/v2ray-core"
  8. "github.com/v2ray/v2ray-core/log"
  9. // The following are neccesary as they register handlers in their init functions.
  10. _ "github.com/v2ray/v2ray-core/net/freedom"
  11. _ "github.com/v2ray/v2ray-core/net/socks"
  12. _ "github.com/v2ray/v2ray-core/net/vmess"
  13. )
  14. var (
  15. configFile = flag.String("config", "", "Config file for this Point server.")
  16. logLevel = flag.String("loglevel", "", "Level of log info to be printed to console, available value: debug, info, warning, error")
  17. version = flag.Bool("version", false, "Show current version of V2Ray.")
  18. )
  19. func main() {
  20. flag.Parse()
  21. if *version {
  22. fmt.Printf("V2Ray version %s (%s): %s", core.Version, core.Codename, core.Intro)
  23. fmt.Println()
  24. return
  25. }
  26. switch *logLevel {
  27. case "debug":
  28. log.SetLogLevel(log.DebugLevel)
  29. case "info":
  30. log.SetLogLevel(log.InfoLevel)
  31. case "warning":
  32. log.SetLogLevel(log.WarningLevel)
  33. case "error":
  34. log.SetLogLevel(log.ErrorLevel)
  35. }
  36. if configFile == nil || len(*configFile) == 0 {
  37. panic(log.Error("Config file is not set."))
  38. }
  39. rawVConfig, err := ioutil.ReadFile(*configFile)
  40. if err != nil {
  41. panic(log.Error("Failed to read config file (%s): %v", *configFile, err))
  42. }
  43. vconfig, err := core.LoadConfig(rawVConfig)
  44. if err != nil {
  45. panic(log.Error("Failed to parse Config: %v", err))
  46. }
  47. if !filepath.IsAbs(vconfig.InboundConfig.File) && len(vconfig.InboundConfig.File) > 0 {
  48. vconfig.InboundConfig.File = filepath.Join(filepath.Dir(*configFile), vconfig.InboundConfig.File)
  49. }
  50. if !filepath.IsAbs(vconfig.OutboundConfig.File) && len(vconfig.OutboundConfig.File) > 0 {
  51. vconfig.OutboundConfig.File = filepath.Join(filepath.Dir(*configFile), vconfig.OutboundConfig.File)
  52. }
  53. vPoint, err := core.NewPoint(vconfig)
  54. if err != nil {
  55. panic(log.Error("Failed to create Point server: %v", err))
  56. }
  57. err = vPoint.Start()
  58. if err != nil {
  59. log.Error("Error starting Point server: %v", err)
  60. }
  61. finish := make(chan bool)
  62. <-finish
  63. }