Router config

pull/55/head
V2Ray 9 years ago
parent 1d4b98ab9a
commit 57dc6c69f1

@ -1,10 +1,5 @@
package config
type RouterConfig interface {
Strategy() string
Settings() interface{}
}
type DetourTag string
type ConnectionConfig interface {

@ -0,0 +1,6 @@
package config
type RouterConfig interface {
Strategy() string
Settings() interface{}
}

@ -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)
}

@ -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())
}

@ -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{})
}
Loading…
Cancel
Save