config.go 2.1 KB

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