Add windows tun

Optimize android proxy

Optimize change profile

Update application ua

Optimize delay test
This commit is contained in:
chen08209
2024-06-29 21:42:00 +08:00
parent 07bd21580b
commit a923549ddf
24 changed files with 201 additions and 72 deletions

View File

@@ -340,8 +340,8 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
targetConfig.Mode = patchConfig.Mode
targetConfig.Tun.Enable = patchConfig.Tun.Enable
targetConfig.Tun.Device = patchConfig.Tun.Device
//targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
//targetConfig.Tun.Stack = patchConfig.Tun.Stack
targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
targetConfig.Tun.Stack = patchConfig.Tun.Stack
targetConfig.GeodataLoader = patchConfig.GeodataLoader
targetConfig.Profile.StoreSelected = false
if targetConfig.DNS.Enable == false {
@@ -396,7 +396,6 @@ func applyConfig(isPatch bool) {
if isPatch {
patchConfig(cfg.General)
} else {
executor.Shutdown()
runtime.GC()
hub.UltraApplyConfig(cfg, true)
}

View File

@@ -150,7 +150,7 @@ func getProxies() *C.char {
}
//export changeProxy
func changeProxy(s *C.char) bool {
func changeProxy(s *C.char) {
paramsString := C.GoString(s)
go func() {
var params = &ChangeProxyParams{}
@@ -158,22 +158,24 @@ func changeProxy(s *C.char) bool {
if err != nil {
log.Infoln("Unmarshal ChangeProxyParams %v", err)
}
groupName := *params.GroupName
proxyName := *params.ProxyName
proxies := tunnel.ProxiesWithProviders()
proxy := proxies[*params.GroupName]
if proxy == nil {
group := proxies[groupName]
if group == nil {
return
}
log.Infoln("change proxy %s", proxy.Name())
adapterProxy := proxy.(*adapter.Proxy)
adapterProxy := group.(*adapter.Proxy)
selector, ok := adapterProxy.ProxyAdapter.(*outboundgroup.Selector)
if !ok {
return
}
if err := selector.Set(*params.ProxyName); err != nil {
return
err = selector.Set(proxyName)
if err == nil {
log.Infoln("[Selector] %s selected %s", groupName, proxyName)
}
}()
return true
}
//export getTraffic

View File

@@ -18,6 +18,24 @@ import (
var tunLock sync.Mutex
var tun *t.Tun
type FdMap struct {
m sync.Map
}
func (cm *FdMap) Store(key int) {
cm.m.Store(key, nil)
}
func (cm *FdMap) Load(key int) bool {
_, ok := cm.m.Load(key)
if !ok {
return false
}
return true
}
var fdMap FdMap
//export startTUN
func startTUN(fd C.int) {
go func() {
@@ -63,16 +81,38 @@ func stopTun() {
var errBlocked = errors.New("blocked")
//export setFdMap
func setFdMap(fd C.long) {
fdInt := int(fd)
go func() {
fdMap.Store(fdInt)
}()
}
func init() {
dialer.DefaultSocketHook = func(network, address string, conn syscall.RawConn) error {
if platform.ShouldBlockConnection() {
return errBlocked
}
return conn.Control(func(fd uintptr) {
fdInt := int(fd)
timeout := time.After(100 * time.Millisecond)
if tun != nil {
tun.MarkSocket(int(fd))
time.Sleep(time.Millisecond * 100)
tun.MarkSocket(fdInt)
}
for {
select {
case <-timeout:
return
default:
exists := fdMap.Load(fdInt)
if exists {
return
}
time.Sleep(10 * time.Millisecond)
}
}
})
}
}