mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 05:11:17 +08:00
Chore: code style
This commit is contained in:
parent
71e002c2ef
commit
ba7bcce895
20
README.md
20
README.md
@ -75,7 +75,7 @@ On Windows, you should download the [Wintun](https://www.wintun.net) driver and
|
||||
# Enable the TUN listener
|
||||
tun:
|
||||
enable: true
|
||||
stack: system # system or gvisor
|
||||
stack: gvisor # system or gvisor
|
||||
dns-listen: 0.0.0.0:53 # additional dns server listen on TUN
|
||||
auto-route: true # auto set global route
|
||||
```
|
||||
@ -93,7 +93,7 @@ rules:
|
||||
- DOMAIN-SUFFIX,example.com,DIRECT,tcp
|
||||
- DOMAIN-SUFFIX,example.com,REJECT,udp
|
||||
|
||||
# process(add 'P:' prefix) condition for all rules
|
||||
# process condition for all rules (add 'P:' prefix)
|
||||
- DOMAIN-SUFFIX,example.com,REJECT,P:Google Chrome Helper
|
||||
|
||||
# multiport condition for rules SRC-PORT and DST-PORT
|
||||
@ -108,19 +108,14 @@ rules:
|
||||
- GEOSITE,facebook,PROXY
|
||||
- GEOSITE,youtube,PROXY
|
||||
- GEOSITE,geolocation-cn,DIRECT
|
||||
- GEOSITE,gfw,PROXY
|
||||
- GEOSITE,greatfire,PROXY
|
||||
#- GEOSITE,geolocation-!cn,PROXY
|
||||
- GEOSITE,geolocation-!cn,PROXY
|
||||
|
||||
# source IPCIDR condition for all rules in gateway proxy
|
||||
#- GEOSITE,geolocation-!cn,REJECT,192.168.1.88/32,192.168.1.99/32
|
||||
|
||||
- GEOIP,telegram,PROXY,no-resolve
|
||||
- GEOIP,private,DIRECT,no-resolve
|
||||
- GEOIP,cn,DIRECT
|
||||
|
||||
# Not match condition for rule GEOIP
|
||||
#- GEOIP,!cn,PROXY
|
||||
|
||||
# source IPCIDR condition for all rules in gateway proxy
|
||||
#- GEOSITE,geolocation-!cn,REJECT,192.168.1.88/32,192.168.1.99/32
|
||||
|
||||
- MATCH,PROXY
|
||||
```
|
||||
@ -184,9 +179,6 @@ Add field `Process` to `Metadata` and prepare to get process name for Restful AP
|
||||
|
||||
To display process name in GUI please use https://yaling888.github.io/yacd/.
|
||||
|
||||
## Premium Release
|
||||
[Release](https://github.com/Dreamacro/clash/releases/tag/premium)
|
||||
|
||||
## Development
|
||||
If you want to build an application that uses clash as a library, check out the the [GitHub Wiki](https://github.com/Dreamacro/clash/wiki/use-clash-as-a-library)
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/Dreamacro/clash/adapter"
|
||||
@ -73,6 +72,8 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
|
||||
log.SetLevel(log.DEBUG)
|
||||
|
||||
updateUsers(cfg.Users)
|
||||
updateProxies(cfg.Proxies, cfg.Providers)
|
||||
updateRules(cfg.Rules)
|
||||
@ -82,6 +83,8 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||
updateDNS(cfg.DNS, cfg.General)
|
||||
updateGeneral(cfg.General, force)
|
||||
updateExperimental(cfg)
|
||||
|
||||
log.SetLevel(cfg.General.LogLevel)
|
||||
}
|
||||
|
||||
func GetGeneral() *config.General {
|
||||
@ -152,9 +155,7 @@ func updateDNS(c *config.DNS, general *config.General) {
|
||||
resolver.DefaultResolver = r
|
||||
resolver.MainResolver = mr
|
||||
resolver.DefaultHostMapper = m
|
||||
if general.Tun.Enable && strings.EqualFold(general.Tun.Stack, "system") {
|
||||
resolver.DefaultLocalServer = dns.NewLocalServer(r, m)
|
||||
}
|
||||
resolver.DefaultLocalServer = dns.NewLocalServer(r, m)
|
||||
|
||||
dns.ReCreateServer(c.Listen, r, m)
|
||||
}
|
||||
@ -172,7 +173,6 @@ func updateRules(rules []C.Rule) {
|
||||
}
|
||||
|
||||
func updateGeneral(general *config.General, force bool) {
|
||||
log.SetLevel(log.DEBUG)
|
||||
tunnel.SetMode(general.Mode)
|
||||
resolver.DisableIPv6 = !general.IPv6
|
||||
|
||||
@ -200,7 +200,6 @@ func updateGeneral(general *config.General, force bool) {
|
||||
iface.FlushCache()
|
||||
|
||||
if !force {
|
||||
log.SetLevel(general.LogLevel)
|
||||
return
|
||||
}
|
||||
|
||||
@ -219,8 +218,6 @@ func updateGeneral(general *config.General, force bool) {
|
||||
P.ReCreateTProxy(general.TProxyPort, tcpIn, udpIn)
|
||||
P.ReCreateMixed(general.MixedPort, tcpIn, udpIn)
|
||||
P.ReCreateTun(general.Tun, tcpIn, udpIn)
|
||||
|
||||
log.SetLevel(general.LogLevel)
|
||||
}
|
||||
|
||||
func updateUsers(users []auth.AuthUser) {
|
||||
@ -283,7 +280,10 @@ func updateIPTables(dns *config.DNS, general *config.General) {
|
||||
|
||||
tproxy.CleanUpTProxyLinuxIPTables()
|
||||
|
||||
dialer.DefaultRoutingMark.Store(2158)
|
||||
if dialer.DefaultRoutingMark.Load() == 0 {
|
||||
dialer.DefaultRoutingMark.Store(2158)
|
||||
}
|
||||
|
||||
err = tproxy.SetTProxyLinuxIPTables(general.Interface, general.TProxyPort, dnsPort)
|
||||
|
||||
if err != nil {
|
||||
@ -292,8 +292,8 @@ func updateIPTables(dns *config.DNS, general *config.General) {
|
||||
}
|
||||
}
|
||||
|
||||
func CleanUp() {
|
||||
P.CleanUp()
|
||||
func Cleanup() {
|
||||
P.Cleanup()
|
||||
|
||||
if runtime.GOOS == "linux" {
|
||||
tproxy.CleanUpTProxyLinuxIPTables()
|
||||
|
@ -49,6 +49,6 @@ func Parse(options ...Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CleanUp() {
|
||||
executor.CleanUp()
|
||||
func Cleanup() {
|
||||
executor.Cleanup()
|
||||
}
|
||||
|
@ -403,8 +403,8 @@ func genAddr(host string, port int, allowLan bool) string {
|
||||
return fmt.Sprintf("127.0.0.1:%d", port)
|
||||
}
|
||||
|
||||
// CleanUp clean up something
|
||||
func CleanUp() {
|
||||
// Cleanup clean up something
|
||||
func Cleanup() {
|
||||
if runtime.GOOS == "windows" {
|
||||
if tunAdapter != nil {
|
||||
tunAdapter.Close()
|
||||
|
6
main.go
6
main.go
@ -104,9 +104,9 @@ func main() {
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigCh
|
||||
|
||||
// clean up
|
||||
log.Warnln("Clash clean up")
|
||||
hub.CleanUp()
|
||||
// cleanup
|
||||
log.Warnln("Clash cleanup")
|
||||
hub.Cleanup()
|
||||
|
||||
log.Warnln("Clash shutting down")
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ var (
|
||||
// default timeout for UDP session
|
||||
udpTimeout = 60 * time.Second
|
||||
|
||||
preProcessCacheFinder, _ = R.NewProcess("", "", nil)
|
||||
// a default rule type of process, use to pre resolve process name
|
||||
defaultProcessRule, _ = R.NewProcess("", "", nil)
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -149,6 +150,9 @@ func preHandleMetadata(metadata *C.Metadata) error {
|
||||
}
|
||||
}
|
||||
|
||||
// pre resolve process name
|
||||
defaultProcessRule.Match(metadata)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -318,9 +322,6 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
|
||||
resolved = true
|
||||
}
|
||||
|
||||
// preset process name and cache it
|
||||
preProcessCacheFinder.Match(metadata)
|
||||
|
||||
for _, rule := range rules {
|
||||
if !resolved && shouldResolveIP(rule, metadata) {
|
||||
ip, err := resolver.ResolveIP(metadata.Host)
|
||||
|
Loading…
Reference in New Issue
Block a user