mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
Router interface
This commit is contained in:
parent
9b8632d01a
commit
d0ae47e2ce
24
app/router/router.go
Normal file
24
app/router/router.go
Normal 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
|
||||
}
|
25
app/router/wildcard_router/router.go
Normal file
25
app/router/wildcard_router/router.go
Normal 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{})
|
||||
}
|
@ -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{}
|
||||
|
Loading…
Reference in New Issue
Block a user