config.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package point
  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. type LogConfig struct {
  27. AccessLog string
  28. ErrorLog string
  29. LogLevel log.LogLevel
  30. }
  31. const (
  32. AllocationStrategyAlways = "always"
  33. AllocationStrategyRandom = "random"
  34. AllocationStrategyExternal = "external"
  35. )
  36. type InboundDetourAllocationConfig struct {
  37. Strategy string // Allocation strategy of this inbound detour.
  38. Concurrency int // Number of handlers (ports) running in parallel.
  39. Refresh int // Number of minutes before a handler is regenerated.
  40. }
  41. type InboundDetourConfig struct {
  42. Protocol string
  43. PortRange v2net.PortRange
  44. ListenOn v2net.Address
  45. Tag string
  46. Allocation *InboundDetourAllocationConfig
  47. StreamSettings *internet.StreamConfig
  48. Settings []byte
  49. AllowPassiveConnection bool
  50. }
  51. type OutboundDetourConfig struct {
  52. Protocol string
  53. SendThrough v2net.Address
  54. StreamSettings *internet.StreamConfig
  55. Tag string
  56. Settings []byte
  57. }
  58. type Config struct {
  59. Port v2net.Port
  60. LogConfig *LogConfig
  61. RouterConfig *router.Config
  62. DNSConfig *dns.Config
  63. InboundConfig *InboundConnectionConfig
  64. OutboundConfig *OutboundConnectionConfig
  65. InboundDetours []*InboundDetourConfig
  66. OutboundDetours []*OutboundDetourConfig
  67. TransportConfig *transport.Config
  68. }
  69. type ConfigLoader func(input io.Reader) (*Config, error)
  70. var (
  71. configLoader ConfigLoader
  72. )
  73. func LoadConfig(input io.Reader) (*Config, error) {
  74. if configLoader == nil {
  75. return nil, common.ErrBadConfiguration
  76. }
  77. return configLoader(input)
  78. }