1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-18 05:25:23 +00:00
This commit is contained in:
Darien Raymond 2017-05-08 11:48:41 +02:00
parent 5dbfd75542
commit a0ac334703
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 31 additions and 19 deletions

View File

@ -245,8 +245,14 @@ type UserMatcher struct {
}
func NewUserMatcher(users []string) *UserMatcher {
usersCopy := make([]string, 0, len(users))
for _, user := range users {
if len(user) > 0 {
usersCopy = append(usersCopy, user)
}
}
return &UserMatcher{
user: users,
user: usersCopy,
}
}
@ -268,8 +274,14 @@ type InboundTagMatcher struct {
}
func NewInboundTagMatcher(tags []string) *InboundTagMatcher {
tagsCopy := make([]string, 0, len(tags))
for _, tag := range tags {
if len(tag) > 0 {
tagsCopy = append(tagsCopy, tag)
}
}
return &InboundTagMatcher{
tags: tags,
tags: tagsCopy,
}
}

View File

@ -12,16 +12,16 @@ type Rule struct {
Condition Condition
}
func (v *Rule) Apply(ctx context.Context) bool {
return v.Condition.Apply(ctx)
func (r *Rule) Apply(ctx context.Context) bool {
return r.Condition.Apply(ctx)
}
func (v *RoutingRule) BuildCondition() (Condition, error) {
func (rr *RoutingRule) BuildCondition() (Condition, error) {
conds := NewConditionChan()
if len(v.Domain) > 0 {
if len(rr.Domain) > 0 {
anyCond := NewAnyCondition()
for _, domain := range v.Domain {
for _, domain := range rr.Domain {
if domain.Type == Domain_Plain {
anyCond.Add(NewPlainDomainMatcher(domain.Value))
} else {
@ -35,12 +35,12 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
conds.Add(anyCond)
}
if len(v.Cidr) > 0 {
if len(rr.Cidr) > 0 {
ipv4Net := v2net.NewIPNet()
ipv6Cond := NewAnyCondition()
hasIpv6 := false
for _, ip := range v.Cidr {
for _, ip := range rr.Cidr {
switch len(ip.Ip) {
case net.IPv4len:
ipv4Net.AddIP(ip.Ip, byte(ip.Prefix))
@ -68,20 +68,20 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
}
}
if v.PortRange != nil {
conds.Add(NewPortMatcher(*v.PortRange))
if rr.PortRange != nil {
conds.Add(NewPortMatcher(*rr.PortRange))
}
if v.NetworkList != nil {
conds.Add(NewNetworkMatcher(v.NetworkList))
if rr.NetworkList != nil {
conds.Add(NewNetworkMatcher(rr.NetworkList))
}
if len(v.SourceCidr) > 0 {
if len(rr.SourceCidr) > 0 {
ipv4Net := v2net.NewIPNet()
ipv6Cond := NewAnyCondition()
hasIpv6 := false
for _, ip := range v.SourceCidr {
for _, ip := range rr.SourceCidr {
switch len(ip.Ip) {
case net.IPv4len:
ipv4Net.AddIP(ip.Ip, byte(ip.Prefix))
@ -109,12 +109,12 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
}
}
if len(v.UserEmail) > 0 {
conds.Add(NewUserMatcher(v.UserEmail))
if len(rr.UserEmail) > 0 {
conds.Add(NewUserMatcher(rr.UserEmail))
}
if len(v.InboundTag) > 0 {
conds.Add(NewInboundTagMatcher(v.InboundTag))
if len(rr.InboundTag) > 0 {
conds.Add(NewInboundTagMatcher(rr.InboundTag))
}
if conds.Len() == 0 {