config.go 1.5 KB

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