server_env.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package scenarios
  2. import (
  3. "os"
  4. "path/filepath"
  5. _ "github.com/v2ray/v2ray-core/app/router/config/json"
  6. _ "github.com/v2ray/v2ray-core/app/router/rules"
  7. _ "github.com/v2ray/v2ray-core/app/router/rules/config/json"
  8. "github.com/v2ray/v2ray-core/common/log"
  9. "github.com/v2ray/v2ray-core/shell/point"
  10. jsonconf "github.com/v2ray/v2ray-core/shell/point/config/json"
  11. // The following are neccesary as they register handlers in their init functions.
  12. _ "github.com/v2ray/v2ray-core/proxy/blackhole"
  13. _ "github.com/v2ray/v2ray-core/proxy/blackhole/config/json"
  14. _ "github.com/v2ray/v2ray-core/proxy/dokodemo"
  15. _ "github.com/v2ray/v2ray-core/proxy/dokodemo/config/json"
  16. _ "github.com/v2ray/v2ray-core/proxy/freedom"
  17. _ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
  18. _ "github.com/v2ray/v2ray-core/proxy/socks"
  19. _ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
  20. _ "github.com/v2ray/v2ray-core/proxy/vmess"
  21. _ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
  22. )
  23. func TestFile(filename string) string {
  24. return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
  25. }
  26. func InitializeServer(configFile string) error {
  27. config, err := jsonconf.LoadConfig(configFile)
  28. if err != nil {
  29. log.Error("Failed to read config file (%s): %v", configFile, err)
  30. return err
  31. }
  32. vPoint, err := point.NewPoint(config)
  33. if err != nil {
  34. log.Error("Failed to create Point server: %v", err)
  35. return err
  36. }
  37. err = vPoint.Start()
  38. if err != nil {
  39. log.Error("Error starting Point server: %v", err)
  40. return err
  41. }
  42. return nil
  43. }