config.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package mocks
  2. import (
  3. "github.com/v2ray/v2ray-core/app/router"
  4. "github.com/v2ray/v2ray-core/common/log"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. "github.com/v2ray/v2ray-core/shell/point"
  7. )
  8. type ConnectionConfig struct {
  9. ProtocolValue string
  10. SettingsValue []byte
  11. }
  12. func (config *ConnectionConfig) Protocol() string {
  13. return config.ProtocolValue
  14. }
  15. func (config *ConnectionConfig) Settings() []byte {
  16. return config.SettingsValue
  17. }
  18. type LogConfig struct {
  19. AccessLogValue string
  20. ErrorLogValue string
  21. LogLevelValue log.LogLevel
  22. }
  23. func (config *LogConfig) AccessLog() string {
  24. return config.AccessLogValue
  25. }
  26. func (this *LogConfig) ErrorLog() string {
  27. return this.ErrorLogValue
  28. }
  29. func (this *LogConfig) LogLevel() log.LogLevel {
  30. return this.LogLevelValue
  31. }
  32. type InboundDetourAllocationConfig struct {
  33. StrategyValue string
  34. ConcurrencyValue int
  35. RefreshSec int
  36. }
  37. func (this *InboundDetourAllocationConfig) Refresh() int {
  38. return this.RefreshSec
  39. }
  40. func (this *InboundDetourAllocationConfig) Strategy() string {
  41. return this.StrategyValue
  42. }
  43. func (this *InboundDetourAllocationConfig) Concurrency() int {
  44. return this.ConcurrencyValue
  45. }
  46. type InboundDetourConfig struct {
  47. *ConnectionConfig
  48. PortRangeValue *v2net.PortRange
  49. TagValue string
  50. AllocationStrategy *InboundDetourAllocationConfig
  51. }
  52. func (this *InboundDetourConfig) Allocation() point.InboundDetourAllocationConfig {
  53. return this.AllocationStrategy
  54. }
  55. func (this *InboundDetourConfig) Tag() string {
  56. return this.TagValue
  57. }
  58. func (this *InboundDetourConfig) PortRange() v2net.PortRange {
  59. return *this.PortRangeValue
  60. }
  61. type OutboundDetourConfig struct {
  62. *ConnectionConfig
  63. TagValue string
  64. }
  65. func (this *OutboundDetourConfig) Tag() string {
  66. return this.TagValue
  67. }
  68. type Config struct {
  69. PortValue v2net.Port
  70. LogConfigValue *LogConfig
  71. RouterConfigValue *router.Config
  72. InboundConfigValue *ConnectionConfig
  73. OutboundConfigValue *ConnectionConfig
  74. InboundDetoursValue []*InboundDetourConfig
  75. OutboundDetoursValue []*OutboundDetourConfig
  76. }
  77. func (config *Config) Port() v2net.Port {
  78. return config.PortValue
  79. }
  80. func (config *Config) LogConfig() point.LogConfig {
  81. if config.LogConfigValue == nil {
  82. return nil
  83. }
  84. return config.LogConfigValue
  85. }
  86. func (this *Config) RouterConfig() *router.Config {
  87. if this.RouterConfigValue == nil {
  88. return nil
  89. }
  90. return this.RouterConfigValue
  91. }
  92. func (this *Config) InboundConfig() point.ConnectionConfig {
  93. if this.InboundConfigValue == nil {
  94. return nil
  95. }
  96. return this.InboundConfigValue
  97. }
  98. func (this *Config) OutboundConfig() point.ConnectionConfig {
  99. if this.OutboundConfigValue == nil {
  100. return nil
  101. }
  102. return this.OutboundConfigValue
  103. }
  104. func (this *Config) InboundDetours() []point.InboundDetourConfig {
  105. detours := make([]point.InboundDetourConfig, len(this.InboundDetoursValue))
  106. for idx, detour := range this.InboundDetoursValue {
  107. detours[idx] = detour
  108. }
  109. return detours
  110. }
  111. func (this *Config) OutboundDetours() []point.OutboundDetourConfig {
  112. detours := make([]point.OutboundDetourConfig, len(this.OutboundDetoursValue))
  113. for idx, detour := range this.OutboundDetoursValue {
  114. detours[idx] = detour
  115. }
  116. return detours
  117. }