mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-26 13:56:12 -04:00
faster check in field rule
This commit is contained in:
parent
dc69dfb3e1
commit
f6c486327f
@ -59,6 +59,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
|
|||||||
for _, domain := range *this.Domain {
|
for _, domain := range *this.Domain {
|
||||||
if strings.Contains(address.Domain(), domain) {
|
if strings.Contains(address.Domain(), domain) {
|
||||||
foundMatch = true
|
foundMatch = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundMatch {
|
if !foundMatch {
|
||||||
@ -74,6 +75,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
|
|||||||
for _, ipnet := range this.IP {
|
for _, ipnet := range this.IP {
|
||||||
if ipnet.Contains(address.IP()) {
|
if ipnet.Contains(address.IP()) {
|
||||||
foundMatch = true
|
foundMatch = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundMatch {
|
if !foundMatch {
|
||||||
|
@ -65,6 +65,19 @@ func TestIPMatching(t *testing.T) {
|
|||||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIPListMatching(t *testing.T) {
|
||||||
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
|
rawJson := `{
|
||||||
|
"type": "field",
|
||||||
|
"ip": ["10.0.0.0/8", "192.168.0.0/16"],
|
||||||
|
"tag": "test"
|
||||||
|
}`
|
||||||
|
rule := parseRule([]byte(rawJson))
|
||||||
|
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{192, 168, 1, 1}, 80))
|
||||||
|
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||||
|
}
|
||||||
|
|
||||||
func TestPortNotMatching(t *testing.T) {
|
func TestPortNotMatching(t *testing.T) {
|
||||||
assert := unit.Assert(t)
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user