mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
9b89ff9f2d
rules: - SUB-RULE,(AND,((NETWORK,TCP),(DOMAIN-KEYWORD,google))),TEST2 - SUB-RULE,(GEOIP,!CN),TEST1 - MATCH,DIRECT sub-rules: TEST2: - MATCH,Proxy TEST1: - RULE-SET,Local,DIRECT,no-resolve - GEOSITE,CN,Domestic - GEOIP,CN,Domestic - MATCH,Proxy
51 lines
875 B
Go
51 lines
875 B
Go
package common
|
|
|
|
import (
|
|
"golang.org/x/net/idna"
|
|
"strings"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type Domain struct {
|
|
*Base
|
|
domain string
|
|
adapter string
|
|
isIDNA bool
|
|
}
|
|
|
|
func (d *Domain) RuleType() C.RuleType {
|
|
return C.Domain
|
|
}
|
|
|
|
func (d *Domain) Match(metadata *C.Metadata) (bool, string) {
|
|
if metadata.AddrType != C.AtypDomainName {
|
|
return false, ""
|
|
}
|
|
return metadata.Host == d.domain, d.adapter
|
|
}
|
|
|
|
func (d *Domain) Adapter() string {
|
|
return d.adapter
|
|
}
|
|
|
|
func (d *Domain) Payload() string {
|
|
domain := d.domain
|
|
if d.isIDNA {
|
|
domain, _ = idna.ToUnicode(domain)
|
|
}
|
|
return domain
|
|
}
|
|
|
|
func NewDomain(domain string, adapter string) *Domain {
|
|
actualDomain, _ := idna.ToASCII(domain)
|
|
return &Domain{
|
|
Base: &Base{},
|
|
domain: strings.ToLower(actualDomain),
|
|
adapter: adapter,
|
|
isIDNA: actualDomain != domain,
|
|
}
|
|
}
|
|
|
|
//var _ C.Rule = (*Domain)(nil)
|