config.go 2.9 KB

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