config.go 3.2 KB

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