dispatcher.go 844 B

12345678910111213141516171819202122232425262728
  1. package routing
  2. import (
  3. "context"
  4. "github.com/xtls/xray-core/common/net"
  5. "github.com/xtls/xray-core/features"
  6. "github.com/xtls/xray-core/transport"
  7. )
  8. // Dispatcher is a feature that dispatches inbound requests to outbound handlers based on rules.
  9. // Dispatcher is required to be registered in a Xray instance to make Xray function properly.
  10. //
  11. // xray:api:stable
  12. type Dispatcher interface {
  13. features.Feature
  14. // Dispatch returns a Ray for transporting data for the given request.
  15. Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error)
  16. DispatchLink(ctx context.Context, dest net.Destination, link *transport.Link) error
  17. }
  18. // DispatcherType returns the type of Dispatcher interface. Can be used to implement common.HasType.
  19. //
  20. // xray:api:stable
  21. func DispatcherType() interface{} {
  22. return (*Dispatcher)(nil)
  23. }