config.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package point
  2. import (
  3. "github.com/v2ray/v2ray-core/app/router"
  4. "github.com/v2ray/v2ray-core/common/log"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. )
  7. type ConnectionConfig struct {
  8. Protocol string
  9. Settings []byte
  10. }
  11. type LogConfig struct {
  12. AccessLog string
  13. ErrorLog string
  14. LogLevel log.LogLevel
  15. }
  16. const (
  17. AllocationStrategyAlways = "always"
  18. AllocationStrategyRandom = "random"
  19. AllocationStrategyExternal = "external"
  20. )
  21. type InboundDetourAllocationConfig struct {
  22. Strategy string // Allocation strategy of this inbound detour.
  23. Concurrency int // Number of handlers (ports) running in parallel.
  24. Refresh int // Number of minutes before a handler is regenerated.
  25. }
  26. type InboundDetourConfig struct {
  27. Protocol string
  28. PortRange v2net.PortRange
  29. Tag string
  30. Allocation *InboundDetourAllocationConfig
  31. Settings []byte
  32. }
  33. type OutboundDetourConfig struct {
  34. Protocol string
  35. Tag string
  36. Settings []byte
  37. }
  38. type Config struct {
  39. Port v2net.Port
  40. LogConfig *LogConfig
  41. RouterConfig *router.Config
  42. InboundConfig *ConnectionConfig
  43. OutboundConfig *ConnectionConfig
  44. InboundDetours []*InboundDetourConfig
  45. OutboundDetours []*OutboundDetourConfig
  46. }
  47. type ConfigLoader func(init string) (*Config, error)
  48. var (
  49. configLoader ConfigLoader
  50. )
  51. func LoadConfig(init string) (*Config, error) {
  52. if configLoader == nil {
  53. return nil, ErrorBadConfiguration
  54. }
  55. return configLoader(init)
  56. }