fix: windows localhost dns

This commit is contained in:
arm64v8a
2022-11-09 15:16:18 +09:00
parent 7a619a8e07
commit 3e0aac799c
5 changed files with 30 additions and 4 deletions

View File

@@ -11,15 +11,28 @@ import (
"time"
v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/features/dns/localdns"
)
var instance *libcore.V2RayInstance
var getNekorayTunIndex = func() int { return 0 }
func setupCore() {
// TODO del
device.IsNekoray = true
libcore.SetConfig("", false, true)
libcore.InitCore("", "", "", nil, ".", "moe.nekoray.pc:bg", true, 50)
// localdns setup
resolver_def := &net.Resolver{PreferGo: false}
resolver_go := &net.Resolver{PreferGo: true}
localdns.SetLookupFunc(func(network string, host string) ([]net.IP, error) {
// Normal mode use system resolver (go bug)
if getNekorayTunIndex() == 0 {
return resolver_def.LookupIP(context.Background(), network, host)
}
// VPN mode use Go resolver
return resolver_go.LookupIP(context.Background(), network, host)
})
//
neko_common.GetProxyHttpClient = func() *http.Client {
return getProxyHttpClient(instance)

View File

@@ -47,11 +47,24 @@ func init() {
}
return nil
})
//
updateRoutes()
iphlpapi.RegisterNotifyRouteChange2(func(callerContext uintptr, row uintptr, notificationType uint32) uintptr {
updateRoutes()
return 0
}, true)
}, false)
//
getNekorayTunIndex = func() (index int) {
lock.Lock()
defer lock.Unlock()
for _, intf := range interfaces {
if intf.Name == "nekoray-tun" {
index = intf.Index
return
}
}
return
}
}
func updateRoutes() {
@@ -85,7 +98,7 @@ func getBindInterfaceIndex(address string) uint32 {
var nextInterface int
for i, intf := range interfaces {
if intf.Name == "nekoray-tun" || intf.Name == "wintun" || intf.Name == "TunMax" {
if intf.Name == "nekoray-tun" {
if len(interfaces) > i+1 {
nextInterface = interfaces[i+1].Index
}

View File

@@ -20,6 +20,7 @@ func ToolBox() {
for _, route := range routes {
log.Println(route)
}
log.Println("TUN:", getNekorayTunIndex())
log.Println("Upstream:", getBindInterfaceIndex("8.8.8.8:8888"))
}
}

View File

@@ -1 +1 @@
ac454d7b46306ea0c4eaedd95ac7ea54fd1afa73
8b1a40059eee4eb7e3db559185aec224324f322c

View File

@@ -118,7 +118,6 @@ namespace NekoRay::sys {
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
}
env << "GODEBUG=netdns=go";
ExternalProcess::Start();
write((dataStore->core_token + "\n").toUtf8());
}