outbound.go 1.4 KB

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