config.go 2.2 KB

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