1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-16 04:35:24 +00:00

faster check in field rule

This commit is contained in:
Darien Raymond 2015-11-30 12:46:09 +00:00
parent dc69dfb3e1
commit f6c486327f
2 changed files with 15 additions and 0 deletions

View File

@ -59,6 +59,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
for _, domain := range *this.Domain {
if strings.Contains(address.Domain(), domain) {
foundMatch = true
break
}
}
if !foundMatch {
@ -74,6 +75,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
for _, ipnet := range this.IP {
if ipnet.Contains(address.IP()) {
foundMatch = true
break
}
}
if !foundMatch {

View File

@ -65,6 +65,19 @@ func TestIPMatching(t *testing.T) {
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) {
assert := unit.Assert(t)