config.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  47. func (this *InboundDetourAllocationConfig) Strategy() string {
  48. return this.StrategyValue
  49. }
  50. func (this *InboundDetourAllocationConfig) Concurrency() int {
  51. return this.ConcurrencyValue
  52. }
  53. type InboundDetourConfig struct {
  54. *ConnectionConfig
  55. PortRangeValue *PortRange
  56. TagValue string
  57. AllocationStrategy *InboundDetourAllocationConfig
  58. }
  59. func (this *InboundDetourConfig) Allocation() point.InboundDetourAllocationConfig {
  60. return this.AllocationStrategy
  61. }
  62. func (this *InboundDetourConfig) Tag() string {
  63. return this.TagValue
  64. }
  65. func (this *InboundDetourConfig) PortRange() v2net.PortRange {
  66. return this.PortRangeValue
  67. }
  68. type OutboundDetourConfig struct {
  69. *ConnectionConfig
  70. TagValue string
  71. }
  72. func (this *OutboundDetourConfig) Tag() string {
  73. return this.TagValue
  74. }
  75. type Config struct {
  76. PortValue v2net.Port
  77. LogConfigValue *LogConfig
  78. RouterConfigValue *routertesting.RouterConfig
  79. InboundConfigValue *ConnectionConfig
  80. OutboundConfigValue *ConnectionConfig
  81. InboundDetoursValue []*InboundDetourConfig
  82. OutboundDetoursValue []*OutboundDetourConfig
  83. }
  84. func (config *Config) Port() v2net.Port {
  85. return config.PortValue
  86. }
  87. func (config *Config) LogConfig() point.LogConfig {
  88. if config.LogConfigValue == nil {
  89. return nil
  90. }
  91. return config.LogConfigValue
  92. }
  93. func (this *Config) RouterConfig() router.Config {
  94. if this.RouterConfigValue == nil {
  95. return nil
  96. }
  97. return this.RouterConfigValue
  98. }
  99. func (this *Config) InboundConfig() point.ConnectionConfig {
  100. if this.InboundConfigValue == nil {
  101. return nil
  102. }
  103. return this.InboundConfigValue
  104. }
  105. func (this *Config) OutboundConfig() point.ConnectionConfig {
  106. if this.OutboundConfigValue == nil {
  107. return nil
  108. }
  109. return this.OutboundConfigValue
  110. }
  111. func (this *Config) InboundDetours() []point.InboundDetourConfig {
  112. detours := make([]point.InboundDetourConfig, len(this.InboundDetoursValue))
  113. for idx, detour := range this.InboundDetoursValue {
  114. detours[idx] = detour
  115. }
  116. return detours
  117. }
  118. func (this *Config) OutboundDetours() []point.OutboundDetourConfig {
  119. detours := make([]point.OutboundDetourConfig, len(this.OutboundDetoursValue))
  120. for idx, detour := range this.OutboundDetoursValue {
  121. detours[idx] = detour
  122. }
  123. return detours
  124. }