outbound.go 1.2 KB

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