outbound.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package outbound
  2. import (
  3. "context"
  4. "v2ray.com/core/common"
  5. "v2ray.com/core/features"
  6. "v2ray.com/core/transport"
  7. )
  8. // Handler is the interface for handlers that process outbound connections.
  9. type Handler interface {
  10. common.Runnable
  11. Tag() string
  12. Dispatch(ctx context.Context, link *transport.Link)
  13. }
  14. type HandlerSelector interface {
  15. Select([]string) []string
  16. }
  17. // Manager is a feature that manages outbound.Handlers.
  18. type Manager interface {
  19. features.Feature
  20. // GetHandler returns an outbound.Handler for the given tag.
  21. GetHandler(tag string) Handler
  22. // GetDefaultHandler returns the default outbound.Handler. It is usually the first outbound.Handler specified in the configuration.
  23. GetDefaultHandler() Handler
  24. // AddHandler adds a handler into this outbound.Manager.
  25. AddHandler(ctx context.Context, handler Handler) error
  26. // RemoveHandler removes a handler from outbound.Manager.
  27. RemoveHandler(ctx context.Context, tag string) error
  28. }
  29. // ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
  30. func ManagerType() interface{} {
  31. return (*Manager)(nil)
  32. }