router.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. type Router interface {
  9. features.Feature
  10. // PickRoute returns a tag of an OutboundHandler based on the given context.
  11. PickRoute(ctx context.Context) (string, error)
  12. }
  13. // RouterType return the type of Router interface. Can be used to implement common.HasType.
  14. func RouterType() interface{} {
  15. return (*Router)(nil)
  16. }
  17. // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
  18. type DefaultRouter struct{}
  19. // Type implements common.HasType.
  20. func (DefaultRouter) Type() interface{} {
  21. return RouterType()
  22. }
  23. // PickRoute implements Router.
  24. func (DefaultRouter) PickRoute(ctx context.Context) (string, error) {
  25. return "", common.ErrNoClue
  26. }
  27. // Start implements common.Runnable.
  28. func (DefaultRouter) Start() error {
  29. return nil
  30. }
  31. // Close implements common.Closable.
  32. func (DefaultRouter) Close() error {
  33. return nil
  34. }