handler_cache.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package proxy
  2. import (
  3. "v2ray.com/core/app"
  4. "v2ray.com/core/common"
  5. "v2ray.com/core/common/errors"
  6. )
  7. var (
  8. inboundFactories = make(map[string]InboundHandlerFactory)
  9. outboundFactories = make(map[string]OutboundHandlerFactory)
  10. )
  11. func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) error {
  12. if _, found := inboundFactories[name]; found {
  13. return common.ErrDuplicatedName
  14. }
  15. inboundFactories[name] = creator
  16. return nil
  17. }
  18. func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) error {
  19. if _, found := outboundFactories[name]; found {
  20. return common.ErrDuplicatedName
  21. }
  22. outboundFactories[name] = creator
  23. return nil
  24. }
  25. func CreateInboundHandler(name string, space app.Space, config interface{}, meta *InboundHandlerMeta) (InboundHandler, error) {
  26. creator, found := inboundFactories[name]
  27. if !found {
  28. return nil, errors.New("Proxy: Unknown inbound name: " + name)
  29. }
  30. return creator.Create(space, config, meta)
  31. }
  32. func CreateOutboundHandler(name string, space app.Space, config interface{}, meta *OutboundHandlerMeta) (OutboundHandler, error) {
  33. creator, found := outboundFactories[name]
  34. if !found {
  35. return nil, errors.New("Proxy: Unknown outbound name: " + name)
  36. }
  37. return creator.Create(space, config, meta)
  38. }