simplify port range

This commit is contained in:
v2ray
2016-01-15 13:39:36 +01:00
parent 5ceac7a6e2
commit 393a64820f
10 changed files with 38 additions and 81 deletions
+3 -3
View File
@@ -82,7 +82,7 @@ type FieldRule struct {
Rule
Domain []DomainMatcher
IP []*net.IPNet
Port v2net.PortRange
Port *v2net.PortRange
Network v2net.NetworkList
}
@@ -122,7 +122,7 @@ func (this *FieldRule) Apply(dest v2net.Destination) bool {
if this.Port != nil {
port := dest.Port()
if port.Value() < this.Port.From().Value() || port.Value() > this.Port.To().Value() {
if port.Value() < this.Port.From.Value() || port.Value() > this.Port.To.Value() {
return false
}
}
@@ -141,7 +141,7 @@ func (this *FieldRule) UnmarshalJSON(data []byte) error {
Rule
Domain *StringList `json:"domain"`
IP *StringList `json:"ip"`
Port *v2netjson.PortRange `json:"port"`
Port *v2net.PortRange `json:"port"`
Network *v2netjson.NetworkList `json:"network"`
}
rawFieldRule := RawFieldRule{}
+3 -4
View File
@@ -5,7 +5,6 @@ import (
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
@@ -47,9 +46,9 @@ func TestPortMatching(t *testing.T) {
v2testing.Current(t)
rule := &FieldRule{
Port: &v2nettesting.PortRange{
FromValue: 0,
ToValue: 100,
Port: &v2net.PortRange{
From: 0,
To: 100,
},
}
dest := v2net.TCPDestination(v2net.DomainAddress("www.v2ray.com"), 80)