config.go 2.2 KB

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