2015-10-28 18:18:07 -04:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Router interface {
|
2015-11-30 10:14:38 -05:00
|
|
|
TakeDetour(v2net.Destination) (string, error)
|
2015-10-28 18:18:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-11-03 17:24:56 -05:00
|
|
|
|
|
|
|
func CreateRouter(name string, rawConfig interface{}) (Router, error) {
|
|
|
|
if factory, found := routerCache[name]; found {
|
|
|
|
return factory.Create(rawConfig)
|
|
|
|
}
|
2016-01-30 06:23:56 -05:00
|
|
|
return nil, ErrorRouterNotFound
|
2015-11-03 17:24:56 -05:00
|
|
|
}
|