config.go 1.8 KB

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