Browse Source

Router config

pull/55/head
V2Ray 9 years ago
parent
commit
57dc6c69f1
  1. 5
      app/point/config/config.go
  2. 6
      app/router/config/config.go
  3. 25
      app/router/config/json/cache.go
  4. 18
      app/router/config/json/json.go
  5. 1
      app/router/rules/router.go
  6. 25
      app/router/wildcard_router/router.go

5
app/point/config/config.go

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

6
app/router/config/config.go

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

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

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

1
app/router/rules/router.go

@ -0,0 +1 @@
package rules

25
app/router/wildcard_router/router.go

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