Browse Source

rename reverse match to inverse match

Shelikhoo 4 years ago
parent
commit
6246b97494
4 changed files with 16 additions and 16 deletions
  1. 6 6
      app/router/condition_geoip.go
  2. 5 5
      app/router/config.pb.go
  3. 1 1
      app/router/config.proto
  4. 4 4
      infra/conf/rule/rule.go

+ 6 - 6
app/router/condition_geoip.go

@@ -14,7 +14,7 @@ type ipv6 struct {
 
 type GeoIPMatcher struct {
 	countryCode  string
-	reverseMatch bool
+	inverseMatch bool
 	ip4          []uint32
 	prefix4      []uint8
 	ip6          []ipv6
@@ -82,7 +82,7 @@ func (m *GeoIPMatcher) Init(cidrs []*CIDR) error {
 }
 
 func (m *GeoIPMatcher) SetReverseMatch(isReverseMatch bool) {
-	m.reverseMatch = isReverseMatch
+	m.inverseMatch = isReverseMatch
 }
 
 func (m *GeoIPMatcher) match4(ip uint32) bool {
@@ -152,12 +152,12 @@ func (m *GeoIPMatcher) match6(ip ipv6) bool {
 func (m *GeoIPMatcher) Match(ip net.IP) bool {
 	switch len(ip) {
 	case 4:
-		if m.reverseMatch {
+		if m.inverseMatch {
 			return !m.match4(binary.BigEndian.Uint32(ip))
 		}
 		return m.match4(binary.BigEndian.Uint32(ip))
 	case 16:
-		if m.reverseMatch {
+		if m.inverseMatch {
 			return !m.match6(ipv6{
 				a: binary.BigEndian.Uint64(ip[0:8]),
 				b: binary.BigEndian.Uint64(ip[8:16]),
@@ -182,7 +182,7 @@ type GeoIPMatcherContainer struct {
 func (c *GeoIPMatcherContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
 	if len(geoip.CountryCode) > 0 {
 		for _, m := range c.matchers {
-			if m.countryCode == geoip.CountryCode && m.reverseMatch == geoip.ReverseMatch {
+			if m.countryCode == geoip.CountryCode && m.inverseMatch == geoip.InverseMatch {
 				return m, nil
 			}
 		}
@@ -190,7 +190,7 @@ func (c *GeoIPMatcherContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
 
 	m := &GeoIPMatcher{
 		countryCode:  geoip.CountryCode,
-		reverseMatch: geoip.ReverseMatch,
+		inverseMatch: geoip.InverseMatch,
 	}
 	if err := m.Init(geoip.Cidr); err != nil {
 		return nil, err

+ 5 - 5
app/router/config.pb.go

@@ -267,7 +267,7 @@ type GeoIP struct {
 
 	CountryCode  string  `protobuf:"bytes,1,opt,name=country_code,json=countryCode,proto3" json:"country_code,omitempty"`
 	Cidr         []*CIDR `protobuf:"bytes,2,rep,name=cidr,proto3" json:"cidr,omitempty"`
-	ReverseMatch bool    `protobuf:"varint,3,opt,name=reverse_match,json=reverseMatch,proto3" json:"reverse_match,omitempty"`
+	InverseMatch bool    `protobuf:"varint,3,opt,name=inverse_match,json=inverseMatch,proto3" json:"inverse_match,omitempty"`
 }
 
 func (x *GeoIP) Reset() {
@@ -316,9 +316,9 @@ func (x *GeoIP) GetCidr() []*CIDR {
 	return nil
 }
 
-func (x *GeoIP) GetReverseMatch() bool {
+func (x *GeoIP) GetInverseMatch() bool {
 	if x != nil {
-		return x.ReverseMatch
+		return x.InverseMatch
 	}
 	return false
 }
@@ -1174,8 +1174,8 @@ var file_app_router_config_proto_rawDesc = []byte{
 	0x2f, 0x0a, 0x04, 0x63, 0x69, 0x64, 0x72, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e,
 	0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72,
 	0x6f, 0x75, 0x74, 0x65, 0x72, 0x2e, 0x43, 0x49, 0x44, 0x52, 0x52, 0x04, 0x63, 0x69, 0x64, 0x72,
-	0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x5f, 0x6d, 0x61, 0x74, 0x63,
-	0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65,
+	0x12, 0x23, 0x0a, 0x0d, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65, 0x5f, 0x6d, 0x61, 0x74, 0x63,
+	0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x65,
 	0x4d, 0x61, 0x74, 0x63, 0x68, 0x22, 0x3f, 0x0a, 0x09, 0x47, 0x65, 0x6f, 0x49, 0x50, 0x4c, 0x69,
 	0x73, 0x74, 0x12, 0x32, 0x0a, 0x05, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28,
 	0x0b, 0x32, 0x1c, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61,

+ 1 - 1
app/router/config.proto

@@ -55,7 +55,7 @@ message CIDR {
 message GeoIP {
   string country_code = 1;
   repeated CIDR cidr = 2;
-  bool reverse_match = 3;
+  bool inverse_match = 3;
 }
 
 message GeoIPList {

+ 4 - 4
infra/conf/rule/rule.go

@@ -135,7 +135,7 @@ func toCidrList(ctx context.Context, ips cfgcommon.StringList) ([]*router.GeoIP,
 			geoipList = append(geoipList, &router.GeoIP{
 				CountryCode:  strings.ToUpper(country),
 				Cidr:         geoip,
-				ReverseMatch: isReverseMatch,
+				InverseMatch: isReverseMatch,
 			})
 
 			continue
@@ -165,10 +165,10 @@ func toCidrList(ctx context.Context, ips cfgcommon.StringList) ([]*router.GeoIP,
 				return nil, newError("empty filename or empty country in rule")
 			}
 
-			isReverseMatch := false
+			isInverseMatch := false
 			if strings.HasPrefix(country, "!") {
 				country = country[1:]
-				isReverseMatch = true
+				isInverseMatch = true
 			}
 			geoip, err := geoLoader.LoadIP(filename, country)
 			if err != nil {
@@ -178,7 +178,7 @@ func toCidrList(ctx context.Context, ips cfgcommon.StringList) ([]*router.GeoIP,
 			geoipList = append(geoipList, &router.GeoIP{
 				CountryCode:  strings.ToUpper(filename + "_" + country),
 				Cidr:         geoip,
-				ReverseMatch: isReverseMatch,
+				InverseMatch: isInverseMatch,
 			})
 
 			continue