config.go 1.6 KB

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