config.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package core
  2. import (
  3. "io"
  4. "v2ray.com/core/app/dns"
  5. "v2ray.com/core/app/router"
  6. "v2ray.com/core/common"
  7. "v2ray.com/core/common/log"
  8. v2net "v2ray.com/core/common/net"
  9. "v2ray.com/core/transport"
  10. "v2ray.com/core/transport/internet"
  11. )
  12. type InboundConnectionConfig struct {
  13. Port v2net.Port
  14. ListenOn v2net.Address
  15. StreamSettings *internet.StreamConfig
  16. Protocol string
  17. Settings []byte
  18. AllowPassiveConnection bool
  19. }
  20. type OutboundConnectionConfig struct {
  21. Protocol string
  22. SendThrough v2net.Address
  23. StreamSettings *internet.StreamConfig
  24. Settings []byte
  25. }
  26. const (
  27. AllocationStrategyAlways = "always"
  28. AllocationStrategyRandom = "random"
  29. AllocationStrategyExternal = "external"
  30. )
  31. type InboundDetourAllocationConfig struct {
  32. Strategy string // Allocation strategy of this inbound detour.
  33. Concurrency int // Number of handlers (ports) running in parallel.
  34. Refresh int // Number of minutes before a handler is regenerated.
  35. }
  36. type InboundDetourConfig struct {
  37. Protocol string
  38. PortRange v2net.PortRange
  39. ListenOn v2net.Address
  40. Tag string
  41. Allocation *InboundDetourAllocationConfig
  42. StreamSettings *internet.StreamConfig
  43. Settings []byte
  44. AllowPassiveConnection bool
  45. }
  46. type OutboundDetourConfig struct {
  47. Protocol string
  48. SendThrough v2net.Address
  49. StreamSettings *internet.StreamConfig
  50. Tag string
  51. Settings []byte
  52. }
  53. type Config struct {
  54. Port v2net.Port
  55. LogConfig *log.Config
  56. RouterConfig *router.Config
  57. DNSConfig *dns.Config
  58. InboundConfig *InboundConnectionConfig
  59. OutboundConfig *OutboundConnectionConfig
  60. InboundDetours []*InboundDetourConfig
  61. OutboundDetours []*OutboundDetourConfig
  62. TransportConfig *transport.Config
  63. }
  64. type ConfigLoader func(input io.Reader) (*Config, error)
  65. var (
  66. configLoader ConfigLoader
  67. )
  68. func LoadConfig(input io.Reader) (*Config, error) {
  69. if configLoader == nil {
  70. return nil, common.ErrBadConfiguration
  71. }
  72. return configLoader(input)
  73. }