mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 06:30:05 +08:00
fix 1.12 dns
This commit is contained in:
parent
e4d38ba44d
commit
893ba090f6
@ -21,6 +21,7 @@ import io.nekohasekai.sagernet.plugin.PluginManager
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import libcore.BoxInstance
|
import libcore.BoxInstance
|
||||||
import libcore.Libcore
|
import libcore.Libcore
|
||||||
|
import moe.matsuri.nb4a.net.LocalResolverImpl
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class BoxInstance(
|
abstract class BoxInstance(
|
||||||
@ -48,7 +49,7 @@ abstract class BoxInstance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected open suspend fun loadConfig() {
|
protected open suspend fun loadConfig() {
|
||||||
box = Libcore.newSingBoxInstance(config.config)
|
box = Libcore.newSingBoxInstance(config.config, LocalResolverImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
open suspend fun init() {
|
open suspend fun init() {
|
||||||
|
|||||||
@ -7,8 +7,6 @@ import io.nekohasekai.sagernet.database.ProxyEntity
|
|||||||
import io.nekohasekai.sagernet.ktx.Logs
|
import io.nekohasekai.sagernet.ktx.Logs
|
||||||
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
|
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import libcore.Libcore
|
|
||||||
import moe.matsuri.nb4a.net.LocalResolverImpl
|
|
||||||
import moe.matsuri.nb4a.utils.JavaUtil
|
import moe.matsuri.nb4a.utils.JavaUtil
|
||||||
|
|
||||||
class ProxyInstance(profile: ProxyEntity, var service: BaseService.Interface? = null) :
|
class ProxyInstance(profile: ProxyEntity, var service: BaseService.Interface? = null) :
|
||||||
@ -45,7 +43,6 @@ class ProxyInstance(profile: ProxyEntity, var service: BaseService.Interface? =
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun loadConfig() {
|
override suspend fun loadConfig() {
|
||||||
Libcore.registerLocalDNSTransport(LocalResolverImpl)
|
|
||||||
super.loadConfig()
|
super.loadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +56,6 @@ class ProxyInstance(profile: ProxyEntity, var service: BaseService.Interface? =
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
Libcore.registerLocalDNSTransport(null)
|
|
||||||
super.close()
|
super.close()
|
||||||
runBlocking {
|
runBlocking {
|
||||||
looper?.stop()
|
looper?.stop()
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import io.nekohasekai.sagernet.ktx.tryResume
|
|||||||
import io.nekohasekai.sagernet.ktx.tryResumeWithException
|
import io.nekohasekai.sagernet.ktx.tryResumeWithException
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import libcore.Libcore
|
import libcore.Libcore
|
||||||
|
import moe.matsuri.nb4a.net.LocalResolverImpl
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class TestInstance(profile: ProxyEntity, val link: String, private val timeout: Int) :
|
class TestInstance(profile: ProxyEntity, val link: String, private val timeout: Int) :
|
||||||
@ -46,7 +47,7 @@ class TestInstance(profile: ProxyEntity, val link: String, private val timeout:
|
|||||||
override suspend fun loadConfig() {
|
override suspend fun loadConfig() {
|
||||||
// don't call destroyAllJsi here
|
// don't call destroyAllJsi here
|
||||||
if (BuildConfig.DEBUG) Logs.d(config.config)
|
if (BuildConfig.DEBUG) Logs.d(config.config)
|
||||||
box = Libcore.newSingBoxInstance(config.config)
|
box = Libcore.newSingBoxInstance(config.config, LocalResolverImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,12 +79,15 @@ type BoxInstance struct {
|
|||||||
pauseManager pause.Manager
|
pauseManager pause.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingBoxInstance(config string) (b *BoxInstance, err error) {
|
func NewSingBoxInstance(config string, localTransport LocalDNSTransport) (b *BoxInstance, err error) {
|
||||||
defer device.DeferPanicToError("NewSingBoxInstance", func(err_ error) { err = err_ })
|
defer device.DeferPanicToError("NewSingBoxInstance", func(err_ error) { err = err_ })
|
||||||
|
|
||||||
// create box context
|
// create box context
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
ctx = box.Context(ctx, nekoboxAndroidInboundRegistry(), nekoboxAndroidOutboundRegistry(), nekoboxAndroidEndpointRegistry(), nekoboxAndroidDNSTransportRegistry(), nekoboxAndroidServiceRegistry())
|
ctx = box.Context(ctx,
|
||||||
|
nekoboxAndroidInboundRegistry(), nekoboxAndroidOutboundRegistry(), nekoboxAndroidEndpointRegistry(),
|
||||||
|
nekoboxAndroidDNSTransportRegistry(localTransport), nekoboxAndroidServiceRegistry(),
|
||||||
|
)
|
||||||
ctx = service.ContextWithDefaultRegistry(ctx)
|
ctx = service.ContextWithDefaultRegistry(ctx)
|
||||||
service.MustRegister[platform.Interface](ctx, boxPlatformInterfaceInstance)
|
service.MustRegister[platform.Interface](ctx, boxPlatformInterfaceInstance)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
package libcore
|
package libcore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/adapter"
|
||||||
"github.com/sagernet/sing-box/adapter/endpoint"
|
"github.com/sagernet/sing-box/adapter/endpoint"
|
||||||
"github.com/sagernet/sing-box/adapter/inbound"
|
"github.com/sagernet/sing-box/adapter/inbound"
|
||||||
"github.com/sagernet/sing-box/adapter/outbound"
|
"github.com/sagernet/sing-box/adapter/outbound"
|
||||||
@ -11,6 +14,8 @@ import (
|
|||||||
"github.com/sagernet/sing-box/dns/transport/hosts"
|
"github.com/sagernet/sing-box/dns/transport/hosts"
|
||||||
"github.com/sagernet/sing-box/dns/transport/local"
|
"github.com/sagernet/sing-box/dns/transport/local"
|
||||||
"github.com/sagernet/sing-box/dns/transport/quic"
|
"github.com/sagernet/sing-box/dns/transport/quic"
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing-box/protocol/anytls"
|
"github.com/sagernet/sing-box/protocol/anytls"
|
||||||
"github.com/sagernet/sing-box/protocol/block"
|
"github.com/sagernet/sing-box/protocol/block"
|
||||||
"github.com/sagernet/sing-box/protocol/direct"
|
"github.com/sagernet/sing-box/protocol/direct"
|
||||||
@ -35,7 +40,6 @@ import (
|
|||||||
|
|
||||||
_ "github.com/sagernet/sing-box/experimental/clashapi"
|
_ "github.com/sagernet/sing-box/experimental/clashapi"
|
||||||
_ "github.com/sagernet/sing-box/transport/v2rayquic"
|
_ "github.com/sagernet/sing-box/transport/v2rayquic"
|
||||||
_ "github.com/sagernet/sing-dns/quic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func nekoboxAndroidInboundRegistry() *inbound.Registry {
|
func nekoboxAndroidInboundRegistry() *inbound.Registry {
|
||||||
@ -92,7 +96,7 @@ func nekoboxAndroidEndpointRegistry() *endpoint.Registry {
|
|||||||
return registry
|
return registry
|
||||||
}
|
}
|
||||||
|
|
||||||
func nekoboxAndroidDNSTransportRegistry() *dns.TransportRegistry {
|
func nekoboxAndroidDNSTransportRegistry(localTransport LocalDNSTransport) *dns.TransportRegistry {
|
||||||
registry := dns.NewTransportRegistry()
|
registry := dns.NewTransportRegistry()
|
||||||
|
|
||||||
transport.RegisterTCP(registry)
|
transport.RegisterTCP(registry)
|
||||||
@ -100,12 +104,23 @@ func nekoboxAndroidDNSTransportRegistry() *dns.TransportRegistry {
|
|||||||
transport.RegisterTLS(registry)
|
transport.RegisterTLS(registry)
|
||||||
transport.RegisterHTTPS(registry)
|
transport.RegisterHTTPS(registry)
|
||||||
hosts.RegisterTransport(registry)
|
hosts.RegisterTransport(registry)
|
||||||
local.RegisterTransport(registry)
|
// local.RegisterTransport(registry)
|
||||||
fakeip.RegisterTransport(registry)
|
fakeip.RegisterTransport(registry)
|
||||||
|
|
||||||
quic.RegisterTransport(registry)
|
quic.RegisterTransport(registry)
|
||||||
quic.RegisterHTTP3Transport(registry)
|
quic.RegisterHTTP3Transport(registry)
|
||||||
|
|
||||||
|
if localTransport == nil {
|
||||||
|
local.RegisterTransport(registry)
|
||||||
|
} else {
|
||||||
|
dns.RegisterTransport(registry, "local", func(ctx context.Context, logger log.ContextLogger, tag string, options option.LocalDNSServerOptions) (adapter.DNSTransport, error) {
|
||||||
|
return &platformLocalDNSTransport{
|
||||||
|
iif: localTransport,
|
||||||
|
tag: tag,
|
||||||
|
}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return registry
|
return registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
dns "github.com/sagernet/sing-dns"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
"github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing-box/dns"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
@ -23,29 +25,12 @@ type LocalDNSTransport interface {
|
|||||||
Exchange(ctx *ExchangeContext, message []byte) error
|
Exchange(ctx *ExchangeContext, message []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterLocalDNSTransport(transport LocalDNSTransport) {
|
|
||||||
if transport == nil {
|
|
||||||
dns.RegisterTransport([]string{"local"}, dns.CreateTransport)
|
|
||||||
} else {
|
|
||||||
dns.RegisterTransport([]string{"local"}, func(options dns.TransportOptions) (dns.Transport, error) {
|
|
||||||
return &platformLocalDNSTransport{
|
|
||||||
iif: transport,
|
|
||||||
}, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ dns.Transport = (*platformLocalDNSTransport)(nil)
|
|
||||||
|
|
||||||
type platformLocalDNSTransport struct {
|
type platformLocalDNSTransport struct {
|
||||||
iif LocalDNSTransport
|
iif LocalDNSTransport
|
||||||
|
tag string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *platformLocalDNSTransport) Name() string {
|
func (p *platformLocalDNSTransport) Start(adapter.StartStage) error {
|
||||||
return "local"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *platformLocalDNSTransport) Start() error {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,12 +67,12 @@ func (p *platformLocalDNSTransport) Exchange(ctx context.Context, message *mDNS.
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *platformLocalDNSTransport) Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error) {
|
func (p *platformLocalDNSTransport) Lookup(ctx context.Context, domain string, strategy constant.DomainStrategy) ([]netip.Addr, error) {
|
||||||
var network string
|
var network string
|
||||||
switch strategy {
|
switch strategy {
|
||||||
case dns.DomainStrategyUseIPv4:
|
case constant.DomainStrategyIPv4Only:
|
||||||
network = "ip4"
|
network = "ip4"
|
||||||
case dns.DomainStrategyPreferIPv6:
|
case constant.DomainStrategyPreferIPv6:
|
||||||
network = "ip6"
|
network = "ip6"
|
||||||
default:
|
default:
|
||||||
network = "ip"
|
network = "ip"
|
||||||
@ -105,11 +90,11 @@ func (p *platformLocalDNSTransport) Lookup(ctx context.Context, domain string, s
|
|||||||
return response.error
|
return response.error
|
||||||
}
|
}
|
||||||
switch strategy {
|
switch strategy {
|
||||||
case dns.DomainStrategyUseIPv4:
|
case constant.DomainStrategyIPv4Only:
|
||||||
responseAddr = common.Filter(response.addresses, func(it netip.Addr) bool {
|
responseAddr = common.Filter(response.addresses, func(it netip.Addr) bool {
|
||||||
return it.Is4()
|
return it.Is4()
|
||||||
})
|
})
|
||||||
case dns.DomainStrategyPreferIPv6:
|
case constant.DomainStrategyPreferIPv6:
|
||||||
responseAddr = common.Filter(response.addresses, func(it netip.Addr) bool {
|
responseAddr = common.Filter(response.addresses, func(it netip.Addr) bool {
|
||||||
return it.Is6()
|
return it.Is6()
|
||||||
})
|
})
|
||||||
@ -123,6 +108,18 @@ func (p *platformLocalDNSTransport) Lookup(ctx context.Context, domain string, s
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *platformLocalDNSTransport) Tag() string {
|
||||||
|
return p.tag
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *platformLocalDNSTransport) Type() string {
|
||||||
|
return "local"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *platformLocalDNSTransport) Dependencies() []string {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Func interface {
|
type Func interface {
|
||||||
Invoke() error
|
Invoke() error
|
||||||
}
|
}
|
||||||
@ -157,7 +154,7 @@ func (c *ExchangeContext) RawSuccess(result []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ExchangeContext) ErrorCode(code int32) {
|
func (c *ExchangeContext) ErrorCode(code int32) {
|
||||||
c.error = dns.RCodeError(code)
|
c.error = dns.RcodeError(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ExchangeContext) ErrnoCode(code int32) {
|
func (c *ExchangeContext) ErrnoCode(code int32) {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ require (
|
|||||||
github.com/oschwald/maxminddb-golang v1.13.1
|
github.com/oschwald/maxminddb-golang v1.13.1
|
||||||
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28
|
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28
|
||||||
github.com/sagernet/sing-box v1.0.0 // replaced
|
github.com/sagernet/sing-box v1.0.0 // replaced
|
||||||
github.com/sagernet/sing-dns v0.4.1
|
|
||||||
github.com/sagernet/sing-tun v0.7.0-beta.1
|
github.com/sagernet/sing-tun v0.7.0-beta.1
|
||||||
github.com/ulikunitz/xz v0.5.11
|
github.com/ulikunitz/xz v0.5.11
|
||||||
golang.org/x/mobile v0.0.0-20231108233038-35478a0c49da
|
golang.org/x/mobile v0.0.0-20231108233038-35478a0c49da
|
||||||
@ -90,5 +89,3 @@ replace github.com/sagernet/sing-box => ../../sing-box
|
|||||||
// replace github.com/sagernet/sing-quic => ../../sing-quic
|
// replace github.com/sagernet/sing-quic => ../../sing-quic
|
||||||
|
|
||||||
// replace github.com/sagernet/sing => ../../sing
|
// replace github.com/sagernet/sing => ../../sing
|
||||||
|
|
||||||
// replace github.com/sagernet/sing-dns => ../../sing-dns
|
|
||||||
|
|||||||
@ -91,8 +91,6 @@ github.com/sagernet/quic-go v0.52.0-beta.1/go.mod h1:OV+V5kEBb8kJS7k29MzDu6oj9Gy
|
|||||||
github.com/sagernet/sing v0.6.9/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
github.com/sagernet/sing v0.6.9/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
||||||
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28 h1:C8Lnqd0Q+C15kwaMiDsfq5S45rhhaQMBG91TT+6oFVo=
|
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28 h1:C8Lnqd0Q+C15kwaMiDsfq5S45rhhaQMBG91TT+6oFVo=
|
||||||
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
github.com/sagernet/sing v0.7.6-0.20250825114712-2aeec120ce28/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
||||||
github.com/sagernet/sing-dns v0.4.1 h1:nozS7iqpxZ7aV73oHbkD/8haOvf3XXDCgT//8NdYirk=
|
|
||||||
github.com/sagernet/sing-dns v0.4.1/go.mod h1:dweQs54ng2YGzoJfz+F9dGuDNdP5pJ3PLeggnK5VWc8=
|
|
||||||
github.com/sagernet/sing-mux v0.3.3 h1:YFgt9plMWzH994BMZLmyKL37PdIVaIilwP0Jg+EcLfw=
|
github.com/sagernet/sing-mux v0.3.3 h1:YFgt9plMWzH994BMZLmyKL37PdIVaIilwP0Jg+EcLfw=
|
||||||
github.com/sagernet/sing-mux v0.3.3/go.mod h1:pht8iFY4c9Xltj7rhVd208npkNaeCxzyXCgulDPLUDA=
|
github.com/sagernet/sing-mux v0.3.3/go.mod h1:pht8iFY4c9Xltj7rhVd208npkNaeCxzyXCgulDPLUDA=
|
||||||
github.com/sagernet/sing-quic v0.5.0 h1:jNLIyVk24lFPvu8A4x+ZNEnZdI+Tg1rp7eCJ6v0Csak=
|
github.com/sagernet/sing-quic v0.5.0 h1:jNLIyVk24lFPvu8A4x+ZNEnZdI+Tg1rp7eCJ6v0Csak=
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
PACKAGE_NAME=moe.nb4a
|
PACKAGE_NAME=moe.nb4a
|
||||||
VERSION_NAME=1.3.9
|
VERSION_NAME=1.3.9
|
||||||
PRE_VERSION_NAME=pre-1.4.0-20250902-1
|
PRE_VERSION_NAME=pre-1.4.0-20250902-2
|
||||||
VERSION_CODE=43
|
VERSION_CODE=43
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user