1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 15:26:29 -04:00
This commit is contained in:
Darien Raymond 2017-05-08 12:25:36 +02:00
parent 8879206252
commit 74b2734cb8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -65,17 +65,13 @@ func (v *AnyCondition) Len() int {
return len(*v) return len(*v)
} }
type PlainDomainMatcher struct { type PlainDomainMatcher string
pattern string
func NewPlainDomainMatcher(pattern string) Condition {
return PlainDomainMatcher(pattern)
} }
func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher { func (v PlainDomainMatcher) Apply(ctx context.Context) bool {
return &PlainDomainMatcher{
pattern: pattern,
}
}
func (v *PlainDomainMatcher) Apply(ctx context.Context) bool {
dest, ok := proxy.TargetFromContext(ctx) dest, ok := proxy.TargetFromContext(ctx)
if !ok { if !ok {
return false return false
@ -85,7 +81,7 @@ func (v *PlainDomainMatcher) Apply(ctx context.Context) bool {
return false return false
} }
domain := dest.Address.Domain() domain := dest.Address.Domain()
return strings.Contains(domain, v.pattern) return strings.Contains(domain, string(v))
} }
type RegexpDomainMatcher struct { type RegexpDomainMatcher struct {
@ -114,17 +110,13 @@ func (v *RegexpDomainMatcher) Apply(ctx context.Context) bool {
return v.pattern.MatchString(strings.ToLower(domain)) return v.pattern.MatchString(strings.ToLower(domain))
} }
type SubDomainMatcher struct { type SubDomainMatcher string
pattern string
func NewSubDomainMatcher(p string) Condition {
return SubDomainMatcher(p)
} }
func NewSubDomainMatcher(p string) *SubDomainMatcher { func (m SubDomainMatcher) Apply(ctx context.Context) bool {
return &SubDomainMatcher{
pattern: p,
}
}
func (m *SubDomainMatcher) Apply(ctx context.Context) bool {
dest, ok := proxy.TargetFromContext(ctx) dest, ok := proxy.TargetFromContext(ctx)
if !ok { if !ok {
return false return false
@ -133,10 +125,11 @@ func (m *SubDomainMatcher) Apply(ctx context.Context) bool {
return false return false
} }
domain := dest.Address.Domain() domain := dest.Address.Domain()
if !strings.HasSuffix(domain, m.pattern) { pattern := string(m)
if !strings.HasSuffix(domain, pattern) {
return false return false
} }
return len(domain) == len(m.pattern) || domain[len(domain)-len(m.pattern)-1] == '.' return len(domain) == len(pattern) || domain[len(domain)-len(pattern)-1] == '.'
} }
type CIDRMatcher struct { type CIDRMatcher struct {