mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-05 00:47:51 -05:00
function to create router
This commit is contained in:
parent
0d06561b7e
commit
0a8e283e55
@ -1,10 +1,16 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app/point/config"
|
"github.com/v2ray/v2ray-core/app/point/config"
|
||||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
RouterNotFound = errors.New("Router not found.")
|
||||||
|
)
|
||||||
|
|
||||||
type Router interface {
|
type Router interface {
|
||||||
TakeDetour(v2net.Packet) (config.ConnectionTag, error)
|
TakeDetour(v2net.Packet) (config.ConnectionTag, error)
|
||||||
}
|
}
|
||||||
@ -22,3 +28,10 @@ func RegisterRouter(name string, factory RouterFactory) error {
|
|||||||
routerCache[name] = factory
|
routerCache[name] = factory
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateRouter(name string, rawConfig interface{}) (Router, error) {
|
||||||
|
if factory, found := routerCache[name]; found {
|
||||||
|
return factory.Create(rawConfig)
|
||||||
|
}
|
||||||
|
return nil, RouterNotFound
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user