diff --git a/shell/point/config.go b/shell/point/config.go index 0a740d5f0..34d8985f9 100644 --- a/shell/point/config.go +++ b/shell/point/config.go @@ -23,10 +23,22 @@ type DnsConfig interface { Settings() dns.CacheConfig } +const ( + AllocationStrategyAlways = "always" + AllocationStrategyRandom = "random" + AllocationStrategyExternal = "external" +) + +type InboundDetourAllocationConfig interface { + Strategy() string + Concurrency() int +} + type InboundDetourConfig interface { Protocol() string PortRange() v2net.PortRange Tag() string + Allocation() InboundDetourAllocationConfig Settings() interface{} } diff --git a/shell/point/json/inbound_detour.go b/shell/point/json/inbound_detour.go index ee942c9dd..50d779fbb 100644 --- a/shell/point/json/inbound_detour.go +++ b/shell/point/json/inbound_detour.go @@ -6,13 +6,32 @@ import ( v2net "github.com/v2ray/v2ray-core/common/net" v2netjson "github.com/v2ray/v2ray-core/common/net/json" proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config" + "github.com/v2ray/v2ray-core/shell/point" ) +type InboundDetourAllocationConfig struct { + StrategyValue string `json:"strategy"` + ConcurrencyValue int `json:"concurrency"` +} + +func (this *InboundDetourAllocationConfig) Strategy() string { + return this.StrategyValue +} + +func (this *InboundDetourAllocationConfig) Concurrency() int { + return this.ConcurrencyValue +} + type InboundDetourConfig struct { - ProtocolValue string `json:"protocol"` - PortRangeValue *v2netjson.PortRange `json:"port"` - SettingsValue json.RawMessage `json:"settings"` - TagValue string `json:"tag"` + ProtocolValue string `json:"protocol"` + PortRangeValue *v2netjson.PortRange `json:"port"` + SettingsValue json.RawMessage `json:"settings"` + TagValue string `json:"tag"` + AllocationValue *InboundDetourAllocationConfig `json:"allocate"` +} + +func (this *InboundDetourConfig) Allocation() point.InboundDetourAllocationConfig { + return this.AllocationValue } func (this *InboundDetourConfig) Protocol() string { diff --git a/shell/point/testing/mocks/config.go b/shell/point/testing/mocks/config.go index eeba6a447..7085fc0ec 100644 --- a/shell/point/testing/mocks/config.go +++ b/shell/point/testing/mocks/config.go @@ -52,10 +52,28 @@ func (this *PortRange) To() v2net.Port { return this.ToValue } +type InboundDetourAllocationConfig struct { + StrategyValue string + ConcurrencyValue int +} + +func (this *InboundDetourAllocationConfig) Strategy() string { + return this.StrategyValue +} + +func (this *InboundDetourAllocationConfig) Concurrency() int { + return this.ConcurrencyValue +} + type InboundDetourConfig struct { *ConnectionConfig - PortRangeValue *PortRange - TagValue string + PortRangeValue *PortRange + TagValue string + AllocationStrategy *InboundDetourAllocationConfig +} + +func (this *InboundDetourConfig) Allocation() point.InboundDetourAllocationConfig { + return this.AllocationStrategy } func (this *InboundDetourConfig) Tag() string {