main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "flag"
  4. "io/ioutil"
  5. "path"
  6. "github.com/v2ray/v2ray-core"
  7. "github.com/v2ray/v2ray-core/log"
  8. // The following are neccesary as they register handlers in their init functions.
  9. _ "github.com/v2ray/v2ray-core/net/freedom"
  10. _ "github.com/v2ray/v2ray-core/net/socks"
  11. _ "github.com/v2ray/v2ray-core/net/vmess"
  12. )
  13. var (
  14. configFile = flag.String("config", "", "Config file for this Point server.")
  15. )
  16. func main() {
  17. flag.Parse()
  18. log.SetLogLevel(log.DebugLevel)
  19. if configFile == nil || len(*configFile) == 0 {
  20. panic(log.Error("Config file is not set."))
  21. }
  22. rawVConfig, err := ioutil.ReadFile(*configFile)
  23. if err != nil {
  24. panic(log.Error("Failed to read config file (%s): %v", *configFile, err))
  25. }
  26. vconfig, err := core.LoadConfig(rawVConfig)
  27. if err != nil {
  28. panic(log.Error("Failed to parse Config: %v", err))
  29. }
  30. if !path.IsAbs(vconfig.InboundConfig.File) && len(vconfig.InboundConfig.File) > 0 {
  31. vconfig.InboundConfig.File = path.Join(path.Dir(*configFile), vconfig.InboundConfig.File)
  32. }
  33. if !path.IsAbs(vconfig.OutboundConfig.File) && len(vconfig.OutboundConfig.File) > 0 {
  34. vconfig.OutboundConfig.File = path.Join(path.Dir(*configFile), vconfig.OutboundConfig.File)
  35. }
  36. vPoint, err := core.NewPoint(vconfig)
  37. if err != nil {
  38. panic(log.Error("Failed to create Point server: %v", err))
  39. }
  40. err = vPoint.Start()
  41. if err != nil {
  42. log.Error("Error starting Point server: %v", err)
  43. }
  44. finish := make(chan bool)
  45. <-finish
  46. }