config.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. ListenOn v2net.Address
  31. Tag string
  32. Allocation *InboundDetourAllocationConfig
  33. Settings []byte
  34. }
  35. type OutboundDetourConfig struct {
  36. Protocol string
  37. Tag string
  38. Settings []byte
  39. }
  40. type Config struct {
  41. Port v2net.Port
  42. ListenOn v2net.Address
  43. LogConfig *LogConfig
  44. RouterConfig *router.Config
  45. DNSConfig *dns.Config
  46. InboundConfig *ConnectionConfig
  47. OutboundConfig *ConnectionConfig
  48. InboundDetours []*InboundDetourConfig
  49. OutboundDetours []*OutboundDetourConfig
  50. }
  51. type ConfigLoader func(init string) (*Config, error)
  52. var (
  53. configLoader ConfigLoader
  54. )
  55. func LoadConfig(init string) (*Config, error) {
  56. if configLoader == nil {
  57. return nil, ErrorBadConfiguration
  58. }
  59. return configLoader(init)
  60. }