mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
inbound detour
This commit is contained in:
parent
1708c48f5b
commit
3c43268898
@ -16,9 +16,15 @@ type LogConfig interface {
|
||||
AccessLog() string
|
||||
}
|
||||
|
||||
type InboundDetour interface {
|
||||
type PortRange interface {
|
||||
From() uint16
|
||||
To() uint16
|
||||
}
|
||||
|
||||
type InboundDetourConfig interface {
|
||||
Protocol() string
|
||||
Port()
|
||||
PortRange() PortRange
|
||||
Settings() interface{}
|
||||
}
|
||||
|
||||
type PointConfig interface {
|
||||
@ -26,4 +32,5 @@ type PointConfig interface {
|
||||
LogConfig() LogConfig
|
||||
InboundConfig() ConnectionConfig
|
||||
OutboundConfig() ConnectionConfig
|
||||
InboundDetours() []InboundDetourConfig
|
||||
}
|
||||
|
@ -19,11 +19,15 @@ func (c *ConnectionConfig) Protocol() string {
|
||||
}
|
||||
|
||||
func (c *ConnectionConfig) Settings() interface{} {
|
||||
configObj := proxyjson.CreateConfig(c.Protocol(), c.Type)
|
||||
return loadConnectionConfig(c.SettingsMessage, c.Protocol(), c.Type)
|
||||
}
|
||||
|
||||
func loadConnectionConfig(message json.RawMessage, protocol string, cType proxyconfig.Type) interface{} {
|
||||
configObj := proxyjson.CreateConfig(protocol, cType)
|
||||
if configObj == nil {
|
||||
panic("Unknown protocol " + c.Protocol())
|
||||
panic("Unknown protocol " + protocol)
|
||||
}
|
||||
err := json.Unmarshal(c.SettingsMessage, configObj)
|
||||
err := json.Unmarshal(message, configObj)
|
||||
if err != nil {
|
||||
log.Error("Unable to parse connection config: %v", err)
|
||||
panic("Failed to parse connection config.")
|
||||
|
26
app/point/config/json/inbound_detour.go
Normal file
26
app/point/config/json/inbound_detour.go
Normal file
@ -0,0 +1,26 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
||||
)
|
||||
|
||||
type InboundDetourConfig struct {
|
||||
ProtocolValue string
|
||||
PortRangeValue *PortRange
|
||||
SettingsValue json.RawMessage
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) Protocol() string {
|
||||
return this.ProtocolValue
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) PortRange() config.PortRange {
|
||||
return this.PortRangeValue
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) Settings() interface{} {
|
||||
return loadConnectionConfig(this.SettingsValue, this.ProtocolValue, proxyconfig.TypeInbound)
|
||||
}
|
@ -12,10 +12,11 @@ import (
|
||||
|
||||
// Config is the config for Point server.
|
||||
type Config struct {
|
||||
PortValue uint16 `json:"port"` // Port of this Point server.
|
||||
LogConfigValue *LogConfig `json:"log"`
|
||||
InboundConfigValue *ConnectionConfig `json:"inbound"`
|
||||
OutboundConfigValue *ConnectionConfig `json:"outbound"`
|
||||
PortValue uint16 `json:"port"` // Port of this Point server.
|
||||
LogConfigValue *LogConfig `json:"log"`
|
||||
InboundConfigValue *ConnectionConfig `json:"inbound"`
|
||||
OutboundConfigValue *ConnectionConfig `json:"outbound"`
|
||||
InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"`
|
||||
}
|
||||
|
||||
func (config *Config) Port() uint16 {
|
||||
@ -43,6 +44,14 @@ func (config *Config) OutboundConfig() config.ConnectionConfig {
|
||||
return config.OutboundConfigValue
|
||||
}
|
||||
|
||||
func (this *Config) InboundDetours() []config.InboundDetourConfig {
|
||||
detours := make([]config.InboundDetourConfig, len(this.InboundDetoursValue))
|
||||
for idx, detour := range this.InboundDetoursValue {
|
||||
detours[idx] = detour
|
||||
}
|
||||
return detours
|
||||
}
|
||||
|
||||
func LoadConfig(file string) (*Config, error) {
|
||||
fixedFile := os.ExpandEnv(file)
|
||||
rawConfig, err := ioutil.ReadFile(fixedFile)
|
||||
|
@ -21,6 +21,28 @@ type LogConfig struct {
|
||||
AccessLogValue string
|
||||
}
|
||||
|
||||
type PortRange struct {
|
||||
FromValue uint16
|
||||
ToValue uint16
|
||||
}
|
||||
|
||||
func (this *PortRange) From() uint16 {
|
||||
return this.FromValue
|
||||
}
|
||||
|
||||
func (this *PortRange) To() uint16 {
|
||||
return this.ToValue
|
||||
}
|
||||
|
||||
type InboundDetourConfig struct {
|
||||
ConnectionConfig
|
||||
PortRangeValue *PortRange
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) PortRange() config.PortRange {
|
||||
return this.PortRangeValue
|
||||
}
|
||||
|
||||
func (config *LogConfig) AccessLog() string {
|
||||
return config.AccessLogValue
|
||||
}
|
||||
@ -30,6 +52,7 @@ type Config struct {
|
||||
LogConfigValue *LogConfig
|
||||
InboundConfigValue *ConnectionConfig
|
||||
OutboundConfigValue *ConnectionConfig
|
||||
InboundDetoursValue []*InboundDetourConfig
|
||||
}
|
||||
|
||||
func (config *Config) Port() uint16 {
|
||||
@ -47,3 +70,11 @@ func (config *Config) InboundConfig() config.ConnectionConfig {
|
||||
func (config *Config) OutboundConfig() config.ConnectionConfig {
|
||||
return config.OutboundConfigValue
|
||||
}
|
||||
|
||||
func (this *Config) InboundDetours() []config.InboundDetourConfig {
|
||||
detours := make([]config.InboundDetourConfig, len(this.InboundDetoursValue))
|
||||
for idx, detour := range this.InboundDetoursValue {
|
||||
detours[idx] = detour
|
||||
}
|
||||
return detours
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user