config.go 2.8 KB

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