v2fly/features/routing/router.go

49 lines
1.1 KiB
Go
Raw Normal View History

package routing
import (
"context"
2018-10-21 08:27:13 +00:00
"v2ray.com/core/common"
"v2ray.com/core/features"
)
// Router is a feature to choose an outbound tag for the given request.
2018-12-03 21:44:42 +00:00
//
// v2ray:api:stable
type Router interface {
features.Feature
// PickRoute returns a tag of an OutboundHandler based on the given context.
PickRoute(ctx context.Context) (string, error)
}
2018-10-12 21:57:56 +00:00
2018-10-13 13:15:49 +00:00
// RouterType return the type of Router interface. Can be used to implement common.HasType.
2018-12-03 21:44:42 +00:00
//
// v2ray:api:stable
2018-10-12 21:57:56 +00:00
func RouterType() interface{} {
return (*Router)(nil)
}
2018-10-21 08:27:13 +00:00
2018-10-22 06:42:10 +00:00
// DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
2018-10-21 08:27:13 +00:00
type DefaultRouter struct{}
2018-10-22 06:42:10 +00:00
// Type implements common.HasType.
2018-10-21 08:27:13 +00:00
func (DefaultRouter) Type() interface{} {
return RouterType()
}
2018-10-22 06:42:10 +00:00
// PickRoute implements Router.
2018-10-21 08:27:13 +00:00
func (DefaultRouter) PickRoute(ctx context.Context) (string, error) {
return "", common.ErrNoClue
}
2018-10-22 06:42:10 +00:00
// Start implements common.Runnable.
2018-10-21 08:27:13 +00:00
func (DefaultRouter) Start() error {
return nil
}
2018-10-22 06:42:10 +00:00
// Close implements common.Closable.
2018-10-21 08:27:13 +00:00
func (DefaultRouter) Close() error {
return nil
}