2015-09-19 09:35:20 -04:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
2015-12-07 16:47:47 -05:00
|
|
|
"github.com/v2ray/v2ray-core/app/router"
|
|
|
|
routertesting "github.com/v2ray/v2ray-core/app/router/testing"
|
2015-12-05 15:10:14 -05:00
|
|
|
"github.com/v2ray/v2ray-core/common/log"
|
2015-11-21 15:43:40 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2015-12-06 10:41:41 -05:00
|
|
|
"github.com/v2ray/v2ray-core/shell/point"
|
2015-09-19 09:35:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectionConfig struct {
|
|
|
|
ProtocolValue string
|
2016-01-02 11:40:51 -05:00
|
|
|
SettingsValue []byte
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (config *ConnectionConfig) Protocol() string {
|
|
|
|
return config.ProtocolValue
|
|
|
|
}
|
|
|
|
|
2016-01-02 11:40:51 -05:00
|
|
|
func (config *ConnectionConfig) Settings() []byte {
|
2015-10-06 17:11:08 -04:00
|
|
|
return config.SettingsValue
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
|
|
|
|
2015-10-09 11:58:35 -04:00
|
|
|
type LogConfig struct {
|
|
|
|
AccessLogValue string
|
2015-12-05 15:10:14 -05:00
|
|
|
ErrorLogValue string
|
|
|
|
LogLevelValue log.LogLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
func (config *LogConfig) AccessLog() string {
|
|
|
|
return config.AccessLogValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *LogConfig) ErrorLog() string {
|
|
|
|
return this.ErrorLogValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *LogConfig) LogLevel() log.LogLevel {
|
|
|
|
return this.LogLevelValue
|
2015-10-09 11:58:35 -04:00
|
|
|
}
|
|
|
|
|
2015-10-31 17:22:43 -04:00
|
|
|
type PortRange struct {
|
2015-12-02 06:47:54 -05:00
|
|
|
FromValue v2net.Port
|
|
|
|
ToValue v2net.Port
|
2015-10-31 17:22:43 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 06:47:54 -05:00
|
|
|
func (this *PortRange) From() v2net.Port {
|
2015-10-31 17:22:43 -04:00
|
|
|
return this.FromValue
|
|
|
|
}
|
|
|
|
|
2015-12-02 06:47:54 -05:00
|
|
|
func (this *PortRange) To() v2net.Port {
|
2015-10-31 17:22:43 -04:00
|
|
|
return this.ToValue
|
|
|
|
}
|
|
|
|
|
2015-12-28 17:17:38 -05:00
|
|
|
type InboundDetourAllocationConfig struct {
|
|
|
|
StrategyValue string
|
|
|
|
ConcurrencyValue int
|
2015-12-29 14:52:35 -05:00
|
|
|
RefreshSec int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *InboundDetourAllocationConfig) Refresh() int {
|
|
|
|
return this.RefreshSec
|
2015-12-28 17:17:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *InboundDetourAllocationConfig) Strategy() string {
|
|
|
|
return this.StrategyValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *InboundDetourAllocationConfig) Concurrency() int {
|
|
|
|
return this.ConcurrencyValue
|
|
|
|
}
|
|
|
|
|
2015-10-31 17:22:43 -04:00
|
|
|
type InboundDetourConfig struct {
|
2015-12-02 18:41:34 -05:00
|
|
|
*ConnectionConfig
|
2015-12-28 17:17:38 -05:00
|
|
|
PortRangeValue *PortRange
|
|
|
|
TagValue string
|
|
|
|
AllocationStrategy *InboundDetourAllocationConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *InboundDetourConfig) Allocation() point.InboundDetourAllocationConfig {
|
|
|
|
return this.AllocationStrategy
|
2015-12-07 18:54:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *InboundDetourConfig) Tag() string {
|
|
|
|
return this.TagValue
|
2015-10-31 17:22:43 -04:00
|
|
|
}
|
|
|
|
|
2015-11-21 15:43:40 -05:00
|
|
|
func (this *InboundDetourConfig) PortRange() v2net.PortRange {
|
2015-10-31 17:22:43 -04:00
|
|
|
return this.PortRangeValue
|
|
|
|
}
|
|
|
|
|
2015-11-22 11:41:52 -05:00
|
|
|
type OutboundDetourConfig struct {
|
2015-12-02 18:41:34 -05:00
|
|
|
*ConnectionConfig
|
2015-11-30 10:14:38 -05:00
|
|
|
TagValue string
|
2015-11-22 11:41:52 -05:00
|
|
|
}
|
|
|
|
|
2015-11-30 10:14:38 -05:00
|
|
|
func (this *OutboundDetourConfig) Tag() string {
|
2015-11-22 11:41:52 -05:00
|
|
|
return this.TagValue
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:35:20 -04:00
|
|
|
type Config struct {
|
2015-12-02 15:44:01 -05:00
|
|
|
PortValue v2net.Port
|
2015-11-22 11:41:52 -05:00
|
|
|
LogConfigValue *LogConfig
|
2015-12-07 16:47:47 -05:00
|
|
|
RouterConfigValue *routertesting.RouterConfig
|
2015-11-22 11:41:52 -05:00
|
|
|
InboundConfigValue *ConnectionConfig
|
|
|
|
OutboundConfigValue *ConnectionConfig
|
|
|
|
InboundDetoursValue []*InboundDetourConfig
|
|
|
|
OutboundDetoursValue []*OutboundDetourConfig
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 15:44:01 -05:00
|
|
|
func (config *Config) Port() v2net.Port {
|
2015-09-19 09:35:20 -04:00
|
|
|
return config.PortValue
|
|
|
|
}
|
|
|
|
|
2015-12-06 10:41:41 -05:00
|
|
|
func (config *Config) LogConfig() point.LogConfig {
|
2015-12-02 18:41:34 -05:00
|
|
|
if config.LogConfigValue == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2015-10-09 11:58:35 -04:00
|
|
|
return config.LogConfigValue
|
|
|
|
}
|
|
|
|
|
2015-12-07 18:04:02 -05:00
|
|
|
func (this *Config) RouterConfig() router.Config {
|
2015-12-02 18:41:34 -05:00
|
|
|
if this.RouterConfigValue == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-22 11:41:52 -05:00
|
|
|
return this.RouterConfigValue
|
|
|
|
}
|
|
|
|
|
2015-12-06 10:41:41 -05:00
|
|
|
func (this *Config) InboundConfig() point.ConnectionConfig {
|
2015-12-02 18:41:34 -05:00
|
|
|
if this.InboundConfigValue == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return this.InboundConfigValue
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
|
|
|
|
2015-12-06 10:41:41 -05:00
|
|
|
func (this *Config) OutboundConfig() point.ConnectionConfig {
|
2015-12-02 18:41:34 -05:00
|
|
|
if this.OutboundConfigValue == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return this.OutboundConfigValue
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
2015-10-31 17:22:43 -04:00
|
|
|
|
2015-12-06 10:41:41 -05:00
|
|
|
func (this *Config) InboundDetours() []point.InboundDetourConfig {
|
|
|
|
detours := make([]point.InboundDetourConfig, len(this.InboundDetoursValue))
|
2015-10-31 17:22:43 -04:00
|
|
|
for idx, detour := range this.InboundDetoursValue {
|
|
|
|
detours[idx] = detour
|
|
|
|
}
|
|
|
|
return detours
|
|
|
|
}
|
2015-11-22 11:41:52 -05:00
|
|
|
|
2015-12-06 10:41:41 -05:00
|
|
|
func (this *Config) OutboundDetours() []point.OutboundDetourConfig {
|
|
|
|
detours := make([]point.OutboundDetourConfig, len(this.OutboundDetoursValue))
|
2015-11-22 11:41:52 -05:00
|
|
|
for idx, detour := range this.OutboundDetoursValue {
|
|
|
|
detours[idx] = detour
|
|
|
|
}
|
|
|
|
return detours
|
|
|
|
}
|