1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-26 09:25:23 +00: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)
}
type PlainDomainMatcher struct {
pattern string
type PlainDomainMatcher string
func NewPlainDomainMatcher(pattern string) Condition {
return PlainDomainMatcher(pattern)
}
func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher {
return &PlainDomainMatcher{
pattern: pattern,
}
}
func (v *PlainDomainMatcher) Apply(ctx context.Context) bool {
func (v PlainDomainMatcher) Apply(ctx context.Context) bool {
dest, ok := proxy.TargetFromContext(ctx)
if !ok {
return false
@ -85,7 +81,7 @@ func (v *PlainDomainMatcher) Apply(ctx context.Context) bool {
return false
}
domain := dest.Address.Domain()
return strings.Contains(domain, v.pattern)
return strings.Contains(domain, string(v))
}
type RegexpDomainMatcher struct {
@ -114,17 +110,13 @@ func (v *RegexpDomainMatcher) Apply(ctx context.Context) bool {
return v.pattern.MatchString(strings.ToLower(domain))
}
type SubDomainMatcher struct {
pattern string
type SubDomainMatcher string
func NewSubDomainMatcher(p string) Condition {
return SubDomainMatcher(p)
}
func NewSubDomainMatcher(p string) *SubDomainMatcher {
return &SubDomainMatcher{
pattern: p,
}
}
func (m *SubDomainMatcher) Apply(ctx context.Context) bool {
func (m SubDomainMatcher) Apply(ctx context.Context) bool {
dest, ok := proxy.TargetFromContext(ctx)
if !ok {
return false
@ -133,10 +125,11 @@ func (m *SubDomainMatcher) Apply(ctx context.Context) bool {
return false
}
domain := dest.Address.Domain()
if !strings.HasSuffix(domain, m.pattern) {
pattern := string(m)
if !strings.HasSuffix(domain, pattern) {
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 {