2018-09-09 15:01:46 +08:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
2018-11-21 13:59:39 +08:00
|
|
|
"strings"
|
|
|
|
|
2018-09-09 15:01:46 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Domain struct {
|
|
|
|
domain string
|
|
|
|
adapter string
|
2021-07-01 22:49:29 +08:00
|
|
|
network C.NetWork
|
2018-09-09 15:01:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) RuleType() C.RuleType {
|
|
|
|
return C.Domain
|
|
|
|
}
|
|
|
|
|
2019-10-28 00:02:23 +08:00
|
|
|
func (d *Domain) Match(metadata *C.Metadata) bool {
|
2018-09-30 12:25:52 +08:00
|
|
|
if metadata.AddrType != C.AtypDomainName {
|
2018-09-09 15:01:46 +08:00
|
|
|
return false
|
|
|
|
}
|
2018-09-30 12:25:52 +08:00
|
|
|
return metadata.Host == d.domain
|
2018-09-09 15:01:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) Adapter() string {
|
|
|
|
return d.adapter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) Payload() string {
|
|
|
|
return d.domain
|
|
|
|
}
|
|
|
|
|
2020-07-27 11:57:55 +08:00
|
|
|
func (d *Domain) ShouldResolveIP() bool {
|
|
|
|
return false
|
2019-10-28 00:02:23 +08:00
|
|
|
}
|
|
|
|
|
2021-07-01 22:49:29 +08:00
|
|
|
func (d *Domain) NetWork() C.NetWork {
|
|
|
|
return d.network
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDomain(domain string, adapter string, network C.NetWork) *Domain {
|
2018-09-09 15:01:46 +08:00
|
|
|
return &Domain{
|
2018-11-21 13:59:39 +08:00
|
|
|
domain: strings.ToLower(domain),
|
2018-09-09 15:01:46 +08:00
|
|
|
adapter: adapter,
|
2021-07-01 22:49:29 +08:00
|
|
|
network: network,
|
2018-09-09 15:01:46 +08:00
|
|
|
}
|
|
|
|
}
|