mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-18 22:20:06 +08:00
update box
This commit is contained in:
parent
302ef4cc7f
commit
4ea5cc3d40
@ -268,7 +268,12 @@ class SagerNet : Application(),
|
||||
return DataStore.rulesProvider == 0
|
||||
}
|
||||
|
||||
override fun selector_OnProxySelected(tag: String) {
|
||||
override fun selector_OnProxySelected(selectorTag: String, tag: String) {
|
||||
if (selectorTag != "proxy") {
|
||||
Logs.d("other selector: $selectorTag")
|
||||
return
|
||||
}
|
||||
Libcore.resetAllConnections(true)
|
||||
DataStore.baseService?.apply {
|
||||
runOnDefaultDispatcher {
|
||||
val id = data.proxy!!.config.profileTagMap
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
if [ ! -z $ENV_NB4A ]; then
|
||||
export COMMIT_SING_BOX_EXTRA="a4eacbd0e54b6ec0a42096c42b6137a5be91a0bc"
|
||||
export COMMIT_SING_BOX_EXTRA="ae31f9f1f745c88fc9430ad5903116536e88bab4"
|
||||
fi
|
||||
|
||||
if [ ! -z $ENV_SING_BOX_EXTRA ]; then
|
||||
source libs/get_source_env.sh
|
||||
export COMMIT_SING_BOX="91495e813068294aae506fdd769437c41dd8d3a3"
|
||||
# export COMMIT_SING_BOX="91495e813068294aae506fdd769437c41dd8d3a3"
|
||||
fi
|
||||
|
||||
@ -67,7 +67,7 @@ func VersionBox() string {
|
||||
func ResetAllConnections(system bool) {
|
||||
if system {
|
||||
conntrack.Close()
|
||||
log.Println("Reset system connections done")
|
||||
log.Println("[Debug] Reset system connections done")
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,11 +206,7 @@ func (b *BoxInstance) QueryStats(tag, direct string) int64 {
|
||||
|
||||
func (b *BoxInstance) SelectOutbound(tag string) bool {
|
||||
if b.selector != nil {
|
||||
var result = b.selector.SelectOutbound(tag)
|
||||
if result {
|
||||
ResetAllConnections(true)
|
||||
}
|
||||
return result
|
||||
return b.selector.SelectOutbound(tag)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@ require (
|
||||
github.com/matsuridayo/libneko v1.0.0 // replaced
|
||||
github.com/matsuridayo/sing-box-extra v1.0.0 // replaced
|
||||
github.com/miekg/dns v1.1.53
|
||||
github.com/sagernet/sing v0.2.3
|
||||
github.com/sagernet/sing v0.2.4
|
||||
github.com/sagernet/sing-box v1.0.0 // replaced
|
||||
github.com/sagernet/sing-dns v1.0.0 // replaced
|
||||
github.com/sagernet/sing-tun v0.1.4-0.20230326080954-8848c0e4cbab
|
||||
github.com/sagernet/sing-tun v0.1.4
|
||||
github.com/ulikunitz/xz v0.5.10
|
||||
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105
|
||||
)
|
||||
@ -29,7 +29,6 @@ require (
|
||||
github.com/go-chi/cors v1.2.1 // indirect
|
||||
github.com/go-chi/render v1.0.2 // indirect
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||
github.com/gofrs/uuid v4.4.0+incompatible // indirect
|
||||
github.com/gofrs/uuid/v5 v5.0.0 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
@ -60,9 +59,9 @@ require (
|
||||
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 // indirect
|
||||
github.com/sagernet/quic-go v0.0.0-20230202071646-a8c8afb18b32 // indirect
|
||||
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 // indirect
|
||||
github.com/sagernet/sing-shadowsocks v0.2.0 // indirect
|
||||
github.com/sagernet/sing-shadowtls v0.1.0 // indirect
|
||||
github.com/sagernet/sing-vmess v0.1.3 // indirect
|
||||
github.com/sagernet/sing-shadowsocks v0.2.2-0.20230417102954-f77257340507 // indirect
|
||||
github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b // indirect
|
||||
github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3 // indirect
|
||||
github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 // indirect
|
||||
github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9 // indirect
|
||||
github.com/sagernet/utls v0.0.0-20230309024959-6732c2ab36f2 // indirect
|
||||
|
||||
@ -36,8 +36,6 @@ github.com/go-chi/render v1.0.2 h1:4ER/udB0+fMWB2Jlf15RV3F4A2FDuYi/9f+lFttR/Lg=
|
||||
github.com/go-chi/render v1.0.2/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
|
||||
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
|
||||
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
@ -115,16 +113,16 @@ github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byL
|
||||
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
|
||||
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||
github.com/sagernet/sing v0.1.8/go.mod h1:jt1w2u7lJQFFSGLiRrRIs5YWmx4kAPfWuOejuDW9qMk=
|
||||
github.com/sagernet/sing v0.2.3 h1:V50MvZ4c3Iij2lYFWPlzL1PyipwSzjGeN9x+Ox89vpk=
|
||||
github.com/sagernet/sing v0.2.3/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.0 h1:ILDWL7pwWfkPLEbviE/MyCgfjaBmJY/JVVY+5jhSb58=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.0/go.mod h1:ysYzszRLpNzJSorvlWRMuzU6Vchsp7sd52q+JNY4axw=
|
||||
github.com/sagernet/sing-shadowtls v0.1.0 h1:05MYce8aR5xfKIn+y7xRFsdKhKt44QZTSEQW+lG5IWQ=
|
||||
github.com/sagernet/sing-shadowtls v0.1.0/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc=
|
||||
github.com/sagernet/sing-tun v0.1.4-0.20230326080954-8848c0e4cbab h1:a9oeWuPBuIZ70qMhIIH6RrYhp886xN9jJIwsuu4ZFUo=
|
||||
github.com/sagernet/sing-tun v0.1.4-0.20230326080954-8848c0e4cbab/go.mod h1:4YxIDEkkCjGXDOTMPw1SXpLmCQUFAWuaQN250oo+928=
|
||||
github.com/sagernet/sing-vmess v0.1.3 h1:q/+tsF46dvvapL6CpQBgPHJ6nQrDUZqEtLHCbsjO7iM=
|
||||
github.com/sagernet/sing-vmess v0.1.3/go.mod h1:GVXqAHwe9U21uS+Voh4YBIrADQyE4F9v0ayGSixSQAE=
|
||||
github.com/sagernet/sing v0.2.4 h1:gC8BR5sglbJZX23RtMyFa8EETP9YEUADhfbEzU1yVbo=
|
||||
github.com/sagernet/sing v0.2.4/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.2-0.20230417102954-f77257340507 h1:bAHZCdWqJkb8LEW98+YsMVDXGRMUVjka8IC+St6ot88=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.2-0.20230417102954-f77257340507/go.mod h1:UJjvQGw0lyYaDGIDvUraL16fwaAEH1WFw1Y6sUcMPog=
|
||||
github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b h1:ouW/6IDCrxkBe19YSbdCd7buHix7b+UZ6BM4Zz74XF4=
|
||||
github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b/go.mod h1:oG8bPerYI6cZ74KquY3DvA7ynECyrILPBnce6wtBqeI=
|
||||
github.com/sagernet/sing-tun v0.1.4 h1:Fa6kgvuM2fPbPu3R97S8L8NgaD5lJq3wQorNuTb5oqo=
|
||||
github.com/sagernet/sing-tun v0.1.4/go.mod h1:7BrtP7NMp9FK5oVsZWg92b7yFrD+sM2+udapFurReyw=
|
||||
github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3 h1:BHOnxrbC929JonuKqFdJ7ZbDp7zs4oTlH5KFvKtWu9U=
|
||||
github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3/go.mod h1:yKrAr+dqZd64DxBXCHWrYicp+n4qbqO73mtwv3dck8U=
|
||||
github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 h1:HuE6xSwco/Xed8ajZ+coeYLmioq0Qp1/Z2zczFaV8as=
|
||||
github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37/go.mod h1:3skNSftZDJWTGVtVaM2jfbce8qHnmH/AGDRe62iNOg0=
|
||||
github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9 h1:2ItpW1nMNkPzmBTxV0/eClCklHrFSQMnUGcpUmJxVeE=
|
||||
|
||||
44
libcore/interface_monitor.go
Normal file
44
libcore/interface_monitor.go
Normal file
@ -0,0 +1,44 @@
|
||||
package libcore
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
tun "github.com/sagernet/sing-tun"
|
||||
"github.com/sagernet/sing/common/x/list"
|
||||
)
|
||||
|
||||
// wtf
|
||||
|
||||
type interfaceMonitor struct {
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) DefaultInterfaceName(destination netip.Addr) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) DefaultInterfaceIndex(destination netip.Addr) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) OverrideAndroidVPN() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) AndroidVPNEnabled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) RegisterCallback(callback tun.DefaultInterfaceUpdateCallback) *list.Element[tun.DefaultInterfaceUpdateCallback] {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *interfaceMonitor) UnregisterCallback(element *list.Element[tun.DefaultInterfaceUpdateCallback]) {
|
||||
}
|
||||
@ -3,12 +3,14 @@ package libcore
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"libcore/procfs"
|
||||
"log"
|
||||
"net/netip"
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/process"
|
||||
"github.com/sagernet/sing-box/experimental/libbox/platform"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
@ -22,6 +24,14 @@ var boxPlatformInterfaceInstance platform.Interface = &boxPlatformInterfaceWrapp
|
||||
|
||||
type boxPlatformInterfaceWrapper struct{}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) Initialize(ctx context.Context, router adapter.Router) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) UsePlatformAutoDetectInterfaceControl() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) AutoDetectInterfaceControl() control.Func {
|
||||
// "protect"
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
@ -31,7 +41,7 @@ func (w *boxPlatformInterfaceWrapper) AutoDetectInterfaceControl() control.Func
|
||||
}
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) OpenTun(options tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error) {
|
||||
func (w *boxPlatformInterfaceWrapper) OpenTun(options *tun.Options, platformOptions option.TunPlatformOptions) (tun.Tun, error) {
|
||||
if len(options.IncludeUID) > 0 || len(options.ExcludeUID) > 0 {
|
||||
return nil, E.New("android: unsupported uid options")
|
||||
}
|
||||
@ -51,19 +61,27 @@ func (w *boxPlatformInterfaceWrapper) OpenTun(options tun.Options, platformOptio
|
||||
}
|
||||
//
|
||||
options.FileDescriptor = int(tunFd)
|
||||
return tun.New(options)
|
||||
return tun.New(*options)
|
||||
}
|
||||
|
||||
var disableSingBoxLog = false
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) Write(p []byte) (n int, err error) {
|
||||
// use neko_log
|
||||
if !disableSingBoxLog {
|
||||
log.Print(string(p))
|
||||
}
|
||||
return len(p), nil
|
||||
func (w *boxPlatformInterfaceWrapper) UsePlatformDefaultInterfaceMonitor() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) CreateDefaultInterfaceMonitor(errorHandler E.Handler) tun.DefaultInterfaceMonitor {
|
||||
return &interfaceMonitor{}
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) UsePlatformInterfaceGetter() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) Interfaces() ([]platform.NetworkInterface, error) {
|
||||
return nil, errors.New("wtf")
|
||||
}
|
||||
|
||||
// process.Searcher
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*process.Info, error) {
|
||||
var uid int32
|
||||
if useProcfs {
|
||||
@ -90,3 +108,15 @@ func (w *boxPlatformInterfaceWrapper) FindProcessInfo(ctx context.Context, netwo
|
||||
packageName, _ := intfBox.PackageNameByUid(uid)
|
||||
return &process.Info{UserId: uid, PackageName: packageName}, nil
|
||||
}
|
||||
|
||||
// io.Writer
|
||||
|
||||
var disableSingBoxLog = false
|
||||
|
||||
func (w *boxPlatformInterfaceWrapper) Write(p []byte) (n int, err error) {
|
||||
// use neko_log
|
||||
if !disableSingBoxLog {
|
||||
log.Print(string(p))
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ var useProcfs bool
|
||||
|
||||
type NB4AInterface interface {
|
||||
UseOfficialAssets() bool
|
||||
Selector_OnProxySelected(tag string)
|
||||
Selector_OnProxySelected(selectorTag string, tag string)
|
||||
}
|
||||
|
||||
type LocalResolver interface {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user