This commit is contained in:
Mazeorz
2021-11-17 16:03:47 +08:00
parent 1f3968bd50
commit 900e852525
115 changed files with 9990 additions and 585 deletions

View File

@ -20,6 +20,7 @@ const (
Socks5
Http
Vmess
Vless
Trojan
Relay
@ -141,6 +142,8 @@ func (at AdapterType) String() string {
return "Http"
case Vmess:
return "Vmess"
case Vless:
return "Vless"
case Trojan:
return "Trojan"

View File

@ -14,6 +14,7 @@ const (
TCP NetWork = iota
UDP
ALLNet
HTTP Type = iota
HTTPCONNECT
@ -21,6 +22,7 @@ const (
SOCKS5
REDIR
TPROXY
TUN
)
type NetWork int
@ -28,8 +30,10 @@ type NetWork int
func (n NetWork) String() string {
if n == TCP {
return "tcp"
} else if n == UDP {
return "udp"
}
return "udp"
return "all"
}
func (n NetWork) MarshalJSON() ([]byte, error) {
@ -52,6 +56,8 @@ func (t Type) String() string {
return "Redir"
case TPROXY:
return "TProxy"
case TUN:
return "Tun"
default:
return "Unknown"
}
@ -71,6 +77,7 @@ type Metadata struct {
DstPort string `json:"destinationPort"`
AddrType int `json:"-"`
Host string `json:"host"`
Process string `json:"process"`
DNSMode DNSMode `json:"dnsMode"`
}

View File

@ -22,6 +22,7 @@ var Path = func() *path {
type path struct {
homeDir string
configFile string
scriptDir string
}
// SetHomeDir is used to set the configuration path
@ -62,3 +63,41 @@ func (p *path) OldCache() string {
func (p *path) Cache() string {
return P.Join(p.homeDir, "cache.db")
}
func (p *path) GeoIP() string {
return P.Join(p.homeDir, "geoip.dat")
}
func (p *path) GeoSite() string {
return P.Join(p.homeDir, "geosite.dat")
}
func (p *path) ScriptDir() string {
if len(p.scriptDir) != 0 {
return p.scriptDir
}
if dir, err := os.MkdirTemp("", Name+"-"); err == nil {
p.scriptDir = dir
} else {
p.scriptDir = P.Join(os.TempDir(), Name)
_ = os.MkdirAll(p.scriptDir, 0o644)
}
return p.scriptDir
}
func (p *path) Script() string {
return P.Join(p.ScriptDir(), "clash_script.py")
}
func (p *path) GetAssetLocation(file string) string {
return P.Join(p.homeDir, file)
}
func (p *path) GetExecutableFullPath() string {
exePath, err := os.Executable()
if err != nil {
return "clash"
}
res, _ := filepath.EvalSymlinks(exePath)
return res
}

View File

@ -5,12 +5,14 @@ const (
Domain RuleType = iota
DomainSuffix
DomainKeyword
GEOSITE
GEOIP
IPCIDR
SrcIPCIDR
SrcPort
DstPort
Process
Script
MATCH
)
@ -24,6 +26,8 @@ func (rt RuleType) String() string {
return "DomainSuffix"
case DomainKeyword:
return "DomainKeyword"
case GEOSITE:
return "GeoSite"
case GEOIP:
return "GeoIP"
case IPCIDR:
@ -36,6 +40,8 @@ func (rt RuleType) String() string {
return "DstPort"
case Process:
return "Process"
case Script:
return "Script"
case MATCH:
return "Match"
default:
@ -49,4 +55,5 @@ type Rule interface {
Adapter() string
Payload() string
ShouldResolveIP() bool
RuleExtra() *RuleExtra
}

35
constant/rule_extra.go Normal file
View File

@ -0,0 +1,35 @@
package constant
import (
"net"
"github.com/Dreamacro/clash/component/geodata/router"
)
var TunBroadcastAddr = net.IPv4(198, 18, 255, 255)
type RuleExtra struct {
Network NetWork
SourceIPs []*net.IPNet
}
func (re *RuleExtra) NotMatchNetwork(network NetWork) bool {
return re.Network != ALLNet && re.Network != network
}
func (re *RuleExtra) NotMatchSourceIP(srcIP net.IP) bool {
if re.SourceIPs == nil {
return false
}
for _, ips := range re.SourceIPs {
if ips.Contains(srcIP) {
return false
}
}
return true
}
type RuleGeoSite interface {
GetDomainMatcher() *router.DomainMatcher
}