ソースを参照

Improve: should not reload profile on network changed

Kr328 4 年 前
コミット
b07f70ab0b

+ 12 - 7
core/src/main/golang/app/dns.go

@@ -1,15 +1,20 @@
 package app
 package app
 
 
-import "strings"
+import (
+	"strings"
 
 
-var systemDns []string
+	"github.com/Dreamacro/clash/dns"
+)
 
 
 func NotifyDnsChanged(dnsList string) {
 func NotifyDnsChanged(dnsList string) {
-	dns := strings.Split(dnsList, ",")
+	dL := strings.Split(dnsList, ",")
 
 
-	systemDns = dns
-}
+	ns := make([]dns.NameServer, 0, len(dnsList))
+	for _, d := range dL {
+		ns = append(ns, dns.NameServer{Addr: d})
+	}
 
 
-func SystemDns() []string {
-	return systemDns
+	dns.UpdateSystemDNS(dL)
+	dns.FlushCacheWithDefaultResolver()
 }
 }
+

+ 3 - 0
core/src/main/golang/config/load.go

@@ -3,6 +3,7 @@ package config
 import (
 import (
 	"io/ioutil"
 	"io/ioutil"
 	P "path"
 	P "path"
+	"runtime"
 	"strings"
 	"strings"
 
 
 	"gopkg.in/yaml.v2"
 	"gopkg.in/yaml.v2"
@@ -81,6 +82,8 @@ func Load(path string) error {
 
 
 	app.ApplySubtitlePattern(rawCfg.ClashForAndroid.UiSubtitlePattern)
 	app.ApplySubtitlePattern(rawCfg.ClashForAndroid.UiSubtitlePattern)
 
 
+	runtime.GC()
+
 	return nil
 	return nil
 }
 }
 
 

+ 1 - 2
core/src/main/golang/config/process.go

@@ -10,7 +10,6 @@ import (
 	"github.com/Dreamacro/clash/log"
 	"github.com/Dreamacro/clash/log"
 	"github.com/dlclark/regexp2"
 	"github.com/dlclark/regexp2"
 
 
-	"cfa/app"
 	"cfa/common"
 	"cfa/common"
 
 
 	"github.com/Dreamacro/clash/config"
 	"github.com/Dreamacro/clash/config"
@@ -76,7 +75,7 @@ func patchDns(cfg *config.RawConfig, _ string) error {
 	}
 	}
 
 
 	if cfg.ClashForAndroid.AppendSystemDNS {
 	if cfg.ClashForAndroid.AppendSystemDNS {
-		cfg.DNS.NameServer = append(cfg.DNS.NameServer, app.SystemDns()...)
+		cfg.DNS.NameServer = append(cfg.DNS.NameServer, "dhcp://" + dns.SystemDNSPlaceholder)
 	}
 	}
 
 
 	return nil
 	return nil

+ 1 - 1
core/src/main/golang/core/foss

@@ -1 +1 @@
-Subproject commit a918699140e9169f76600f2e7837ec6d69957fb5
+Subproject commit 006bce4436065b2173dad16ac154cc3824a34c79

+ 15 - 0
core/src/main/golang/go.mod

@@ -13,6 +13,21 @@ require (
 	gopkg.in/yaml.v2 v2.4.0
 	gopkg.in/yaml.v2 v2.4.0
 )
 )
 
 
+require (
+	github.com/Dreamacro/go-shadowsocks2 v0.1.7 // indirect
+	github.com/gofrs/uuid v4.0.0+incompatible // indirect
+	github.com/gorilla/websocket v1.4.2 // indirect
+	github.com/insomniacslk/dhcp v0.0.0-20210827173440-b95caade3eac // indirect
+	github.com/oschwald/maxminddb-golang v1.8.0 // indirect
+	github.com/sirupsen/logrus v1.8.1 // indirect
+	github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect
+	go.uber.org/atomic v1.9.0 // indirect
+	golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
+	golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
+	golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34 // indirect
+	golang.org/x/text v0.3.6 // indirect
+)
+
 replace github.com/Dreamacro/clash => ./core/foss
 replace github.com/Dreamacro/clash => ./core/foss
 
 
 replace cfa/blob => ../../../build/intermediates/golang_blob
 replace cfa/blob => ../../../build/intermediates/golang_blob

+ 3 - 2
core/src/main/golang/tun/dns.go

@@ -3,7 +3,8 @@ package tun
 import (
 import (
 	"net"
 	"net"
 
 
-	"github.com/Dreamacro/clash/component/resolver"
+	"github.com/Dreamacro/clash/dns"
+
 	D "github.com/miekg/dns"
 	D "github.com/miekg/dns"
 )
 )
 
 
@@ -21,7 +22,7 @@ func relayDns(payload []byte) ([]byte, error) {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	r, err := resolver.ServeMsg(msg)
+	r, err := dns.ServeDNSWithDefaultServer(msg)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 0 - 2
service/src/main/java/com/github/kr328/clash/service/ClashService.kt

@@ -54,8 +54,6 @@ class ClashService : BaseService() {
                         true
                         true
                     }
                     }
                     network.onEvent {
                     network.onEvent {
-                        config.reload()
-
                         false
                         false
                     }
                     }
                 }
                 }

+ 0 - 2
service/src/main/java/com/github/kr328/clash/service/TunService.kt

@@ -65,8 +65,6 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
                             setUnderlyingNetworks(e.network?.let { arrayOf(it) })
                             setUnderlyingNetworks(e.network?.let { arrayOf(it) })
                         }
                         }
 
 
-                        config.reload()
-
                         false
                         false
                     }
                     }
                 }
                 }

+ 0 - 4
service/src/main/java/com/github/kr328/clash/service/clash/module/ConfigurationModule.kt

@@ -73,8 +73,4 @@ class ConfigurationModule(service: Service) : Module<ConfigurationModule.LoadExc
             }
             }
         }
         }
     }
     }
-
-    fun reload() {
-        reload.trySend(Unit)
-    }
 }
 }