1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

Router interface

This commit is contained in:
V2Ray 2015-10-28 23:18:07 +01:00
parent 9b8632d01a
commit d0ae47e2ce
3 changed files with 56 additions and 0 deletions

24
app/router/router.go Normal file
View File

@ -0,0 +1,24 @@
package router
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/config"
)
type Router interface {
TakeDetour(v2net.Packet) (config.ConnectionTag, error)
}
type RouterFactory interface {
Create(rawConfig interface{}) (Router, error)
}
var (
routerCache = make(map[string]RouterFactory)
)
func RegisterRouter(name string, factory RouterFactory) error {
// TODO: check name
routerCache[name] = factory
return nil
}

View File

@ -0,0 +1,25 @@
package wildcard_router
import (
"github.com/v2ray/v2ray-core/app/router"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/config"
)
type WildcardRouter struct {
}
func (router *WildcardRouter) TakeDetour(packet v2net.Packet) (config.ConnectionTag, error) {
return "", nil
}
type WildcardRouterFactory struct {
}
func (factory *WildcardRouterFactory) Create(rawConfig interface{}) (router.Router, error) {
return &WildcardRouter{}, nil
}
func init() {
router.RegisterRouter("wildcard", &WildcardRouterFactory{})
}

View File

@ -7,6 +7,13 @@ const (
TypeOutbound = Type("outbound")
)
type RouterConfig interface {
Strategy() string
Settings() interface{}
}
type ConnectionTag string
type ConnectionConfig interface {
Protocol() string
Settings(configType Type) interface{}