v2ray-core/proxy/handler_cache.go

46 lines
1.3 KiB
Go
Raw Normal View History

2016-12-15 15:46:20 +01:00
package proxy
2016-01-02 23:08:36 +01:00
import (
2016-08-20 20:55:45 +02:00
"v2ray.com/core/app"
"v2ray.com/core/common"
2016-12-04 09:10:47 +01:00
"v2ray.com/core/common/errors"
2016-01-02 23:08:36 +01:00
)
var (
2016-06-14 22:54:08 +02:00
inboundFactories = make(map[string]InboundHandlerFactory)
outboundFactories = make(map[string]OutboundHandlerFactory)
2016-01-02 23:08:36 +01:00
)
2016-06-14 22:54:08 +02:00
func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) error {
2016-01-02 23:08:36 +01:00
if _, found := inboundFactories[name]; found {
2016-08-18 08:34:21 +02:00
return common.ErrDuplicatedName
2016-01-02 23:08:36 +01:00
}
inboundFactories[name] = creator
return nil
}
2016-06-14 22:54:08 +02:00
func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) error {
2016-01-02 23:08:36 +01:00
if _, found := outboundFactories[name]; found {
2016-08-18 08:34:21 +02:00
return common.ErrDuplicatedName
2016-01-02 23:08:36 +01:00
}
outboundFactories[name] = creator
return nil
}
2016-12-15 15:46:20 +01:00
func CreateInboundHandler(name string, space app.Space, config interface{}, meta *InboundHandlerMeta) (InboundHandler, error) {
2016-01-02 23:08:36 +01:00
creator, found := inboundFactories[name]
if !found {
2016-12-15 15:46:20 +01:00
return nil, errors.New("Proxy: Unknown inbound name: " + name)
2016-01-02 23:08:36 +01:00
}
2016-10-14 22:21:45 +02:00
return creator.Create(space, config, meta)
2016-01-02 23:08:36 +01:00
}
2016-12-15 15:46:20 +01:00
func CreateOutboundHandler(name string, space app.Space, config interface{}, meta *OutboundHandlerMeta) (OutboundHandler, error) {
2016-01-02 23:08:36 +01:00
creator, found := outboundFactories[name]
if !found {
2016-12-15 15:46:20 +01:00
return nil, errors.New("Proxy: Unknown outbound name: " + name)
2016-01-02 23:08:36 +01:00
}
2016-10-14 22:21:45 +02:00
return creator.Create(space, config, meta)
2016-01-02 23:08:36 +01:00
}