config.go 1.5 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. )
  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. type DnsConfig struct {
  18. Enabled bool
  19. Settings *dns.CacheConfig
  20. }
  21. const (
  22. AllocationStrategyAlways = "always"
  23. AllocationStrategyRandom = "random"
  24. AllocationStrategyExternal = "external"
  25. )
  26. type InboundDetourAllocationConfig struct {
  27. Strategy string // Allocation strategy of this inbound detour.
  28. Concurrency int // Number of handlers (ports) running in parallel.
  29. Refresh int // Number of seconds before a handler is regenerated.
  30. }
  31. type InboundDetourConfig struct {
  32. Protocol string
  33. PortRange v2net.PortRange
  34. Tag string
  35. Allocation *InboundDetourAllocationConfig
  36. Settings []byte
  37. }
  38. type OutboundDetourConfig struct {
  39. Protocol string
  40. Tag string
  41. Settings []byte
  42. }
  43. type Config struct {
  44. Port v2net.Port
  45. LogConfig *LogConfig
  46. RouterConfig *router.Config
  47. InboundConfig *ConnectionConfig
  48. OutboundConfig *ConnectionConfig
  49. InboundDetours []*InboundDetourConfig
  50. OutboundDetours []*OutboundDetourConfig
  51. }
  52. type ConfigLoader func(init string) (*Config, error)
  53. var (
  54. configLoader ConfigLoader
  55. )
  56. func LoadConfig(init string) (*Config, error) {
  57. if configLoader == nil {
  58. return nil, BadConfiguration
  59. }
  60. return configLoader(init)
  61. }