diff --git a/app/point/config/config.go b/app/point/config/config.go index bfd598a2..650df370 100644 --- a/app/point/config/config.go +++ b/app/point/config/config.go @@ -1,10 +1,5 @@ package config -type RouterConfig interface { - Strategy() string - Settings() interface{} -} - type DetourTag string type ConnectionConfig interface { diff --git a/app/router/config/config.go b/app/router/config/config.go new file mode 100644 index 00000000..0878e3a1 --- /dev/null +++ b/app/router/config/config.go @@ -0,0 +1,6 @@ +package config + +type RouterConfig interface { + Strategy() string + Settings() interface{} +} diff --git a/app/router/config/json/cache.go b/app/router/config/json/cache.go new file mode 100644 index 00000000..dda78605 --- /dev/null +++ b/app/router/config/json/cache.go @@ -0,0 +1,25 @@ +package json + +type ConfigObjectCreator func() interface{} + +var ( + configCache map[string]ConfigObjectCreator +) + +func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error { + // TODO: check strategy + configCache[strategy] = creator + return nil +} + +func CreateRouterConfig(strategy string) interface{} { + creator, found := configCache[strategy] + if !found { + return nil + } + return creator() +} + +func init() { + configCache = make(map[string]ConfigObjectCreator) +} diff --git a/app/router/config/json/json.go b/app/router/config/json/json.go new file mode 100644 index 00000000..17363a62 --- /dev/null +++ b/app/router/config/json/json.go @@ -0,0 +1,18 @@ +package json + +import ( + "encoding/json" +) + +type RouterConfig struct { + StrategyValue string `json:"strategy"` + SettingsValue json.RawMessage `json:"settings"` +} + +func (this *RouterConfig) Strategy() string { + return this.StrategyValue +} + +func (this *RouterConfig) Settings() interface{} { + return CreateRouterConfig(this.Strategy()) +} diff --git a/app/router/rules/router.go b/app/router/rules/router.go new file mode 100644 index 00000000..1e8c7fa0 --- /dev/null +++ b/app/router/rules/router.go @@ -0,0 +1 @@ +package rules diff --git a/app/router/wildcard_router/router.go b/app/router/wildcard_router/router.go deleted file mode 100644 index bc18f41e..00000000 --- a/app/router/wildcard_router/router.go +++ /dev/null @@ -1,25 +0,0 @@ -package wildcard_router - -import ( - "github.com/v2ray/v2ray-core/app/point/config" - "github.com/v2ray/v2ray-core/app/router" - v2net "github.com/v2ray/v2ray-core/common/net" -) - -type WildcardRouter struct { -} - -func (router *WildcardRouter) TakeDetour(packet v2net.Packet) (config.DetourTag, error) { - return "", nil -} - -type WildcardRouterFactory struct { -} - -func (factory *WildcardRouterFactory) Create(rawConfig interface{}) (router.Router, error) { - return &WildcardRouter{}, nil -} - -func init() { - router.RegisterRouter("wildcard", &WildcardRouterFactory{}) -}