config.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. v2net "github.com/v2ray/v2ray-core/common/net"
  6. "github.com/v2ray/v2ray-core/shell/point/config"
  7. )
  8. type ConnectionConfig struct {
  9. ProtocolValue string
  10. SettingsValue interface{}
  11. }
  12. func (config *ConnectionConfig) Protocol() string {
  13. return config.ProtocolValue
  14. }
  15. func (config *ConnectionConfig) Settings() interface{} {
  16. return config.SettingsValue
  17. }
  18. type LogConfig struct {
  19. AccessLogValue string
  20. }
  21. type PortRange struct {
  22. FromValue v2net.Port
  23. ToValue v2net.Port
  24. }
  25. func (this *PortRange) From() v2net.Port {
  26. return this.FromValue
  27. }
  28. func (this *PortRange) To() v2net.Port {
  29. return this.ToValue
  30. }
  31. type InboundDetourConfig struct {
  32. *ConnectionConfig
  33. PortRangeValue *PortRange
  34. }
  35. func (this *InboundDetourConfig) PortRange() v2net.PortRange {
  36. return this.PortRangeValue
  37. }
  38. type OutboundDetourConfig struct {
  39. *ConnectionConfig
  40. TagValue string
  41. }
  42. func (this *OutboundDetourConfig) Tag() string {
  43. return this.TagValue
  44. }
  45. func (config *LogConfig) AccessLog() string {
  46. return config.AccessLogValue
  47. }
  48. type Config struct {
  49. PortValue v2net.Port
  50. LogConfigValue *LogConfig
  51. RouterConfigValue *routertestingconfig.RouterConfig
  52. InboundConfigValue *ConnectionConfig
  53. OutboundConfigValue *ConnectionConfig
  54. InboundDetoursValue []*InboundDetourConfig
  55. OutboundDetoursValue []*OutboundDetourConfig
  56. }
  57. func (config *Config) Port() v2net.Port {
  58. return config.PortValue
  59. }
  60. func (config *Config) LogConfig() config.LogConfig {
  61. if config.LogConfigValue == nil {
  62. return nil
  63. }
  64. return config.LogConfigValue
  65. }
  66. func (this *Config) RouterConfig() routerconfig.RouterConfig {
  67. if this.RouterConfigValue == nil {
  68. return nil
  69. }
  70. return this.RouterConfigValue
  71. }
  72. func (this *Config) InboundConfig() config.ConnectionConfig {
  73. if this.InboundConfigValue == nil {
  74. return nil
  75. }
  76. return this.InboundConfigValue
  77. }
  78. func (this *Config) OutboundConfig() config.ConnectionConfig {
  79. if this.OutboundConfigValue == nil {
  80. return nil
  81. }
  82. return this.OutboundConfigValue
  83. }
  84. func (this *Config) InboundDetours() []config.InboundDetourConfig {
  85. detours := make([]config.InboundDetourConfig, len(this.InboundDetoursValue))
  86. for idx, detour := range this.InboundDetoursValue {
  87. detours[idx] = detour
  88. }
  89. return detours
  90. }
  91. func (this *Config) OutboundDetours() []config.OutboundDetourConfig {
  92. detours := make([]config.OutboundDetourConfig, len(this.OutboundDetoursValue))
  93. for idx, detour := range this.OutboundDetoursValue {
  94. detours[idx] = detour
  95. }
  96. return detours
  97. }