2018-10-11 14:43:37 -04:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/features"
|
2018-10-11 14:43:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Router is a feature to choose an outbound tag for the given request.
|
2018-12-03 16:44:42 -05:00
|
|
|
//
|
2020-09-18 05:30:59 -04:00
|
|
|
// v2ray:api:stable
|
2018-10-11 14:43:37 -04:00
|
|
|
type Router interface {
|
|
|
|
features.Feature
|
|
|
|
|
2020-09-18 05:30:59 -04:00
|
|
|
// PickRoute returns a route decision based on the given routing context.
|
|
|
|
PickRoute(ctx Context) (Route, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Route is the routing result of Router feature.
|
|
|
|
//
|
|
|
|
// v2ray:api:stable
|
|
|
|
type Route interface {
|
|
|
|
// A Route is also a routing context.
|
|
|
|
Context
|
|
|
|
|
|
|
|
// GetOutboundGroupTags returns the detoured outbound group tags in sequence before a final outbound is chosen.
|
|
|
|
GetOutboundGroupTags() []string
|
|
|
|
|
|
|
|
// GetOutboundTag returns the tag of the outbound the connection was dispatched to.
|
|
|
|
GetOutboundTag() string
|
2018-10-11 14:43:37 -04:00
|
|
|
}
|
2018-10-12 17:57:56 -04:00
|
|
|
|
2018-10-13 09:15:49 -04:00
|
|
|
// RouterType return the type of Router interface. Can be used to implement common.HasType.
|
2018-12-03 16:44:42 -05:00
|
|
|
//
|
|
|
|
// v2ray:api:stable
|
2018-10-12 17:57:56 -04:00
|
|
|
func RouterType() interface{} {
|
|
|
|
return (*Router)(nil)
|
|
|
|
}
|
2018-10-21 04:27:13 -04:00
|
|
|
|
2018-10-22 02:42:10 -04:00
|
|
|
// DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
|
2018-10-21 04:27:13 -04:00
|
|
|
type DefaultRouter struct{}
|
|
|
|
|
2018-10-22 02:42:10 -04:00
|
|
|
// Type implements common.HasType.
|
2018-10-21 04:27:13 -04:00
|
|
|
func (DefaultRouter) Type() interface{} {
|
|
|
|
return RouterType()
|
|
|
|
}
|
|
|
|
|
2018-10-22 02:42:10 -04:00
|
|
|
// PickRoute implements Router.
|
2020-09-18 05:30:59 -04:00
|
|
|
func (DefaultRouter) PickRoute(ctx Context) (Route, error) {
|
|
|
|
return nil, common.ErrNoClue
|
2018-10-21 04:27:13 -04:00
|
|
|
}
|
|
|
|
|
2018-10-22 02:42:10 -04:00
|
|
|
// Start implements common.Runnable.
|
2018-10-21 04:27:13 -04:00
|
|
|
func (DefaultRouter) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-22 02:42:10 -04:00
|
|
|
// Close implements common.Closable.
|
2018-10-21 04:27:13 -04:00
|
|
|
func (DefaultRouter) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|