mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-02 08:20:25 +00:00
code ready for selective routing
This commit is contained in:
@@ -12,7 +12,7 @@ var (
|
||||
)
|
||||
|
||||
type Router interface {
|
||||
TakeDetour(v2net.Destination) (*config.DetourTag, error)
|
||||
TakeDetour(v2net.Destination) (config.DetourTag, error)
|
||||
}
|
||||
|
||||
type RouterFactory interface {
|
||||
|
||||
@@ -10,9 +10,8 @@ type Rule struct {
|
||||
OutboundTag string `json:"outboundTag"`
|
||||
}
|
||||
|
||||
func (this *Rule) Tag() *config.DetourTag {
|
||||
detourTag := config.DetourTag(this.OutboundTag)
|
||||
return &detourTag
|
||||
func (this *Rule) Tag() config.DetourTag {
|
||||
return config.DetourTag(this.OutboundTag)
|
||||
}
|
||||
|
||||
func (this *Rule) Apply(dest v2net.Destination) bool {
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
)
|
||||
|
||||
type Rule interface {
|
||||
Tag() *config.DetourTag
|
||||
Tag() config.DetourTag
|
||||
Apply(dest v2net.Destination) bool
|
||||
}
|
||||
|
||||
@@ -11,21 +11,23 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
InvalidRule = errors.New("Invalid Rule")
|
||||
EmptyTag = pointconfig.DetourTag("")
|
||||
InvalidRule = errors.New("Invalid Rule")
|
||||
NoRuleApplicable = errors.New("No rule applicable")
|
||||
|
||||
EmptyTag = pointconfig.DetourTag("")
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
rules []config.Rule
|
||||
}
|
||||
|
||||
func (this *Router) TakeDetour(dest v2net.Destination) (*pointconfig.DetourTag, error) {
|
||||
func (this *Router) TakeDetour(dest v2net.Destination) (pointconfig.DetourTag, error) {
|
||||
for _, rule := range this.rules {
|
||||
if rule.Apply(dest) {
|
||||
return rule.Tag(), nil
|
||||
}
|
||||
}
|
||||
return &EmptyTag, nil
|
||||
return EmptyTag, NoRuleApplicable
|
||||
}
|
||||
|
||||
type RouterFactory struct {
|
||||
|
||||
Reference in New Issue
Block a user