1
0

router.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package routing
  2. import (
  3. "github.com/xtls/xray-core/common"
  4. "github.com/xtls/xray-core/features"
  5. )
  6. // Router is a feature to choose an outbound tag for the given request.
  7. //
  8. // xray:api:stable
  9. type Router interface {
  10. features.Feature
  11. // PickRoute returns a route decision based on the given routing context.
  12. PickRoute(ctx Context) (Route, error)
  13. }
  14. // Route is the routing result of Router feature.
  15. //
  16. // xray:api:stable
  17. type Route interface {
  18. // A Route is also a routing context.
  19. Context
  20. // GetOutboundGroupTags returns the detoured outbound group tags in sequence before a final outbound is chosen.
  21. GetOutboundGroupTags() []string
  22. // GetOutboundTag returns the tag of the outbound the connection was dispatched to.
  23. GetOutboundTag() string
  24. }
  25. // RouterType return the type of Router interface. Can be used to implement common.HasType.
  26. //
  27. // xray:api:stable
  28. func RouterType() interface{} {
  29. return (*Router)(nil)
  30. }
  31. // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
  32. type DefaultRouter struct{}
  33. // Type implements common.HasType.
  34. func (DefaultRouter) Type() interface{} {
  35. return RouterType()
  36. }
  37. // PickRoute implements Router.
  38. func (DefaultRouter) PickRoute(ctx Context) (Route, error) {
  39. return nil, common.ErrNoClue
  40. }
  41. // Start implements common.Runnable.
  42. func (DefaultRouter) Start() error {
  43. return nil
  44. }
  45. // Close implements common.Closable.
  46. func (DefaultRouter) Close() error {
  47. return nil
  48. }