github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/features/routing/router.go (about) 1 package routing 2 3 import ( 4 "github.com/xtls/xray-core/common" 5 "github.com/xtls/xray-core/common/serial" 6 "github.com/xtls/xray-core/features" 7 ) 8 9 // Router is a feature to choose an outbound tag for the given request. 10 // 11 // xray:api:stable 12 type Router interface { 13 features.Feature 14 15 // PickRoute returns a route decision based on the given routing context. 16 PickRoute(ctx Context) (Route, error) 17 AddRule(config *serial.TypedMessage, shouldAppend bool) error 18 RemoveRule(tag string) error 19 } 20 21 // Route is the routing result of Router feature. 22 // 23 // xray:api:stable 24 type Route interface { 25 // A Route is also a routing context. 26 Context 27 28 // GetOutboundGroupTags returns the detoured outbound group tags in sequence before a final outbound is chosen. 29 GetOutboundGroupTags() []string 30 31 // GetOutboundTag returns the tag of the outbound the connection was dispatched to. 32 GetOutboundTag() string 33 } 34 35 // RouterType return the type of Router interface. Can be used to implement common.HasType. 36 // 37 // xray:api:stable 38 func RouterType() interface{} { 39 return (*Router)(nil) 40 } 41 42 // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions. 43 type DefaultRouter struct{} 44 45 // Type implements common.HasType. 46 func (DefaultRouter) Type() interface{} { 47 return RouterType() 48 } 49 50 // PickRoute implements Router. 51 func (DefaultRouter) PickRoute(ctx Context) (Route, error) { 52 return nil, common.ErrNoClue 53 } 54 55 // AddRule implements Router. 56 func (DefaultRouter) AddRule(config *serial.TypedMessage, shouldAppend bool) error { 57 return common.ErrNoClue 58 } 59 60 // RemoveRule implements Router. 61 func (DefaultRouter) RemoveRule(tag string) error { 62 return common.ErrNoClue 63 } 64 65 // Start implements common.Runnable. 66 func (DefaultRouter) Start() error { 67 return nil 68 } 69 70 // Close implements common.Closable. 71 func (DefaultRouter) Close() error { 72 return nil 73 }