config.go 3.4 KB

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