обновление для приложения (#118)
* feat(android): rename to whitelistbypass and implement various UI, settings, and service enhancements * fix(android): prevent crash on service stop * Fix PORT_BUSY uncaught exception crash * fix(android): improve app stability and fix port 1080 busy * final fix * sync with main branch * fix(android): harden disconnect and session shutdown * cleanup imports/callbacks * more refactor * edit profiles for a specific call via settings, resolve errors/issues during ide analysis * fix callback in main fragment --------- Co-authored-by: kulikov0 <19497634+kulikov0@users.noreply.github.com>
This commit is contained in:
1 parent
dfdc494340
commit
98525f333c
39 files changed
+1712
-434
No files matched your search
@@ -2,11 +2,24 @@
|
||||
|
||||
package androidbind
|
||||
|
||||
/*
|
||||
#include <stdint.h>
|
||||
|
||||
void disable_fdsan() {
|
||||
#ifdef __ANDROID__
|
||||
extern void android_fdsan_set_error_level(uint32_t) __attribute__((weak));
|
||||
if (android_fdsan_set_error_level) {
|
||||
android_fdsan_set_error_level(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/v2/engine"
|
||||
|
||||
@@ -14,48 +27,34 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
tunReady sync.WaitGroup
|
||||
tunOrigFd int = -1
|
||||
tunReady sync.WaitGroup
|
||||
)
|
||||
|
||||
func StartTun2Socks(fd, mtu, socksPort int, socksUser, socksPass string) error {
|
||||
// dup the fd: tun2socks will close the dup on Stop(),
|
||||
// we keep the original open to prevent the kernel from
|
||||
// recycling the fd number while gvisor goroutines drain
|
||||
dupFd, err := syscall.Dup(fd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dup tun fd: %w", err)
|
||||
}
|
||||
tunOrigFd = fd
|
||||
|
||||
var proxy string
|
||||
if socksUser != "" {
|
||||
proxy = fmt.Sprintf("socks5://%s:%s@%s:%d", socksUser, socksPass, common.SocksLocalhostIP, socksPort)
|
||||
} else {
|
||||
proxy = fmt.Sprintf("socks5://%s:%d", common.SocksLocalhostIP, socksPort)
|
||||
}
|
||||
logMsg("tun2socks: starting fd=%d (dup=%d) mtu=%d proxy=%s", fd, dupFd, mtu, proxy)
|
||||
logMsg("tun2socks: starting fd=%d mtu=%d proxy=%s", fd, mtu, proxy)
|
||||
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
||||
tunReady.Add(1)
|
||||
defer tunReady.Done()
|
||||
key := &engine.Key{
|
||||
Proxy: proxy,
|
||||
Device: fmt.Sprintf("fd://%d", dupFd),
|
||||
Device: fmt.Sprintf("fd://%d", fd),
|
||||
MTU: mtu,
|
||||
}
|
||||
tunReady.Add(1)
|
||||
engine.Insert(key)
|
||||
engine.Start()
|
||||
tunReady.Done()
|
||||
logMsg("tun2socks: running")
|
||||
return nil
|
||||
}
|
||||
|
||||
func StopTun2Socks() {
|
||||
tunReady.Wait()
|
||||
C.disable_fdsan()
|
||||
engine.Stop()
|
||||
// now safe to close the original - gvisor goroutines are done
|
||||
if tunOrigFd >= 0 {
|
||||
syscall.Close(tunOrigFd)
|
||||
tunOrigFd = -1
|
||||
}
|
||||
logMsg("tun2socks: stopped")
|
||||
}
|
||||
Reference in new issue
Block a user