router.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package routing
  2. import (
  3. "context"
  4. "v2ray.com/core/common"
  5. "v2ray.com/core/features"
  6. )
  7. // Router is a feature to choose an outbound tag for the given request.
  8. //
  9. // v2ray:api:stable
  10. type Router interface {
  11. features.Feature
  12. // PickRoute returns a tag of an OutboundHandler based on the given context.
  13. PickRoute(ctx context.Context) (string, error)
  14. }
  15. // RouterType return the type of Router interface. Can be used to implement common.HasType.
  16. //
  17. // v2ray:api:stable
  18. func RouterType() interface{} {
  19. return (*Router)(nil)
  20. }
  21. // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
  22. type DefaultRouter struct{}
  23. // Type implements common.HasType.
  24. func (DefaultRouter) Type() interface{} {
  25. return RouterType()
  26. }
  27. // PickRoute implements Router.
  28. func (DefaultRouter) PickRoute(ctx context.Context) (string, error) {
  29. return "", common.ErrNoClue
  30. }
  31. // Start implements common.Runnable.
  32. func (DefaultRouter) Start() error {
  33. return nil
  34. }
  35. // Close implements common.Closable.
  36. func (DefaultRouter) Close() error {
  37. return nil
  38. }