code ready for selective routing

This commit is contained in:
V2Ray
2015-11-22 17:41:52 +01:00
parent f4ec19625e
commit 12e72509a5
8 changed files with 106 additions and 24 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ var (
)
type Router interface {
TakeDetour(v2net.Destination) (*config.DetourTag, error)
TakeDetour(v2net.Destination) (config.DetourTag, error)
}
type RouterFactory interface {
+2 -3
View File
@@ -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 {
+1 -1
View File
@@ -6,6 +6,6 @@ import (
)
type Rule interface {
Tag() *config.DetourTag
Tag() config.DetourTag
Apply(dest v2net.Destination) bool
}
+6 -4
View File
@@ -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 {