1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-30 02:55:23 +00:00

rename reverse match to inverse match

This commit is contained in:
Shelikhoo 2021-09-06 15:37:47 +01:00
parent 31f3edd481
commit 6246b97494
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
4 changed files with 16 additions and 16 deletions

View File

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

View File

@ -267,7 +267,7 @@ type GeoIP struct {
CountryCode string `protobuf:"bytes,1,opt,name=country_code,json=countryCode,proto3" json:"country_code,omitempty"` 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"` 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() { func (x *GeoIP) Reset() {
@ -316,9 +316,9 @@ func (x *GeoIP) GetCidr() []*CIDR {
return nil return nil
} }
func (x *GeoIP) GetReverseMatch() bool { func (x *GeoIP) GetInverseMatch() bool {
if x != nil { if x != nil {
return x.ReverseMatch return x.InverseMatch
} }
return false 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, 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, 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, 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, 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, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 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, 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, 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, 0x0b, 0x32, 0x1c, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61,

View File

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

View File

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