proxyman.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Package proxyman defines applications for manageing inbound and outbound proxies.
  2. package proxyman
  3. import (
  4. "context"
  5. "v2ray.com/core/app"
  6. "v2ray.com/core/common/net"
  7. "v2ray.com/core/proxy"
  8. "v2ray.com/core/transport/ray"
  9. )
  10. type InboundHandlerManager interface {
  11. GetHandler(ctx context.Context, tag string) (InboundHandler, error)
  12. AddHandler(ctx context.Context, config *InboundHandlerConfig) error
  13. Start() error
  14. Close()
  15. }
  16. type InboundHandler interface {
  17. Start() error
  18. Close()
  19. // For migration
  20. GetRandomInboundProxy() (proxy.InboundHandler, net.Port, int)
  21. }
  22. type OutboundHandlerManager interface {
  23. GetHandler(tag string) OutboundHandler
  24. GetDefaultHandler() OutboundHandler
  25. AddHandler(ctx context.Context, config *OutboundHandlerConfig) error
  26. }
  27. type OutboundHandler interface {
  28. Dispatch(ctx context.Context, outboundRay ray.OutboundRay)
  29. }
  30. func InboundHandlerManagerFromSpace(space app.Space) InboundHandlerManager {
  31. app := space.GetApplication((*InboundHandlerManager)(nil))
  32. if app == nil {
  33. return nil
  34. }
  35. return app.(InboundHandlerManager)
  36. }
  37. func OutboundHandlerManagerFromSpace(space app.Space) OutboundHandlerManager {
  38. app := space.GetApplication((*OutboundHandlerManager)(nil))
  39. if app == nil {
  40. return nil
  41. }
  42. return app.(OutboundHandlerManager)
  43. }