mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
fix: windows localhost dns
This commit is contained in:
@@ -11,15 +11,28 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
|
v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/features/dns/localdns"
|
||||||
)
|
)
|
||||||
|
|
||||||
var instance *libcore.V2RayInstance
|
var instance *libcore.V2RayInstance
|
||||||
|
var getNekorayTunIndex = func() int { return 0 }
|
||||||
|
|
||||||
func setupCore() {
|
func setupCore() {
|
||||||
// TODO del
|
// TODO del
|
||||||
device.IsNekoray = true
|
device.IsNekoray = true
|
||||||
libcore.SetConfig("", false, true)
|
libcore.SetConfig("", false, true)
|
||||||
libcore.InitCore("", "", "", nil, ".", "moe.nekoray.pc:bg", true, 50)
|
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 {
|
neko_common.GetProxyHttpClient = func() *http.Client {
|
||||||
return getProxyHttpClient(instance)
|
return getProxyHttpClient(instance)
|
||||||
|
|||||||
@@ -47,11 +47,24 @@ func init() {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
//
|
||||||
updateRoutes()
|
updateRoutes()
|
||||||
iphlpapi.RegisterNotifyRouteChange2(func(callerContext uintptr, row uintptr, notificationType uint32) uintptr {
|
iphlpapi.RegisterNotifyRouteChange2(func(callerContext uintptr, row uintptr, notificationType uint32) uintptr {
|
||||||
updateRoutes()
|
updateRoutes()
|
||||||
return 0
|
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() {
|
func updateRoutes() {
|
||||||
@@ -85,7 +98,7 @@ func getBindInterfaceIndex(address string) uint32 {
|
|||||||
|
|
||||||
var nextInterface int
|
var nextInterface int
|
||||||
for i, intf := range interfaces {
|
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 {
|
if len(interfaces) > i+1 {
|
||||||
nextInterface = interfaces[i+1].Index
|
nextInterface = interfaces[i+1].Index
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ func ToolBox() {
|
|||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
log.Println(route)
|
log.Println(route)
|
||||||
}
|
}
|
||||||
|
log.Println("TUN:", getNekorayTunIndex())
|
||||||
log.Println("Upstream:", getBindInterfaceIndex("8.8.8.8:8888"))
|
log.Println("Upstream:", getBindInterfaceIndex("8.8.8.8:8888"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
ac454d7b46306ea0c4eaedd95ac7ea54fd1afa73
|
8b1a40059eee4eb7e3db559185aec224324f322c
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ namespace NekoRay::sys {
|
|||||||
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
||||||
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
|
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
|
||||||
}
|
}
|
||||||
env << "GODEBUG=netdns=go";
|
|
||||||
ExternalProcess::Start();
|
ExternalProcess::Start();
|
||||||
write((dataStore->core_token + "\n").toUtf8());
|
write((dataStore->core_token + "\n").toUtf8());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user