| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | 
							- package internal
 
- import (
 
- 	"errors"
 
- 	"github.com/v2ray/v2ray-core/app"
 
- 	"github.com/v2ray/v2ray-core/proxy"
 
- )
 
- var (
 
- 	inboundFactories  = make(map[string]InboundHandlerCreator)
 
- 	outboundFactories = make(map[string]OutboundHandlerCreator)
 
- 	ErrorProxyNotFound    = errors.New("Proxy not found.")
 
- 	ErrorNameExists       = errors.New("Proxy with the same name already exists.")
 
- 	ErrorBadConfiguration = errors.New("Bad proxy configuration.")
 
- )
 
- func RegisterInboundHandlerCreator(name string, creator InboundHandlerCreator) error {
 
- 	if _, found := inboundFactories[name]; found {
 
- 		return ErrorNameExists
 
- 	}
 
- 	inboundFactories[name] = creator
 
- 	return nil
 
- }
 
- func MustRegisterInboundHandlerCreator(name string, creator InboundHandlerCreator) {
 
- 	if err := RegisterInboundHandlerCreator(name, creator); err != nil {
 
- 		panic(err)
 
- 	}
 
- }
 
- func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerCreator) error {
 
- 	if _, found := outboundFactories[name]; found {
 
- 		return ErrorNameExists
 
- 	}
 
- 	outboundFactories[name] = creator
 
- 	return nil
 
- }
 
- func MustRegisterOutboundHandlerCreator(name string, creator OutboundHandlerCreator) {
 
- 	if err := RegisterOutboundHandlerCreator(name, creator); err != nil {
 
- 		panic(err)
 
- 	}
 
- }
 
- func CreateInboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 
- 	creator, found := inboundFactories[name]
 
- 	if !found {
 
- 		return nil, ErrorProxyNotFound
 
- 	}
 
- 	if len(rawConfig) > 0 {
 
- 		proxyConfig, err := CreateInboundConfig(name, rawConfig)
 
- 		if err != nil {
 
- 			return nil, err
 
- 		}
 
- 		return creator(space, proxyConfig, meta)
 
- 	}
 
- 	return creator(space, nil, meta)
 
- }
 
- func CreateOutboundHandler(name string, space app.Space, rawConfig []byte, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 
- 	creator, found := outboundFactories[name]
 
- 	if !found {
 
- 		return nil, ErrorProxyNotFound
 
- 	}
 
- 	if len(rawConfig) > 0 {
 
- 		proxyConfig, err := CreateOutboundConfig(name, rawConfig)
 
- 		if err != nil {
 
- 			return nil, err
 
- 		}
 
- 		return creator(space, proxyConfig, meta)
 
- 	}
 
- 	return creator(space, nil, meta)
 
- }
 
 
  |