* refactor go files, add headless telemost support * js crap -> ts crap * docker-build (#32) Co-authored-by: Mimocro <suzumagefag@gmail.com> * add headless telemost for creator app * UX improvements (#39) * Add search in split tunneling app list * Add captcha detection * Add autoclick settings * headless vk joiner * add headless telemost joiner * refactor go modules * redesign settings dialog * headless option in settings * headless joiner support in MainActivity * display headless vk status in statusBar * update ux for headless in creator app * fix double log render for headless mode in creator * unicode for cyrillic * add socks auth * put socksPort inf prefs, verify that port is free on start * proxy only mode * mask addresses in go network errors * update docker build, add file write logic for headless * increment release version, add make-release script --------- Co-authored-by: kulikov <user@Mac.lan> Co-authored-by: Mimocro <67226986+Mimocro@users.noreply.github.com> Co-authored-by: Mimocro <suzumagefag@gmail.com> Co-authored-by: senya <76913432+senya-sh@users.noreply.github.com>
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
//go:build android
|
|
|
|
package mobile
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
"syscall"
|
|
|
|
"github.com/xjasonlyu/tun2socks/v2/engine"
|
|
)
|
|
|
|
var (
|
|
tunReady sync.WaitGroup
|
|
tunOrigFd int = -1
|
|
)
|
|
|
|
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@127.0.0.1:%d", socksUser, socksPass, socksPort)
|
|
} else {
|
|
proxy = fmt.Sprintf("socks5://127.0.0.1:%d", socksPort)
|
|
}
|
|
logMsg("tun2socks: starting fd=%d (dup=%d) mtu=%d proxy=%s", fd, dupFd, mtu, proxy)
|
|
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
|
key := &engine.Key{
|
|
Proxy: proxy,
|
|
Device: fmt.Sprintf("fd://%d", dupFd),
|
|
MTU: mtu,
|
|
}
|
|
tunReady.Add(1)
|
|
engine.Insert(key)
|
|
engine.Start()
|
|
tunReady.Done()
|
|
logMsg("tun2socks: running")
|
|
return nil
|
|
}
|
|
|
|
func StopTun2Socks() {
|
|
tunReady.Wait()
|
|
engine.Stop()
|
|
// now safe to close the original - gvisor goroutines are done
|
|
if tunOrigFd >= 0 {
|
|
syscall.Close(tunOrigFd)
|
|
tunOrigFd = -1
|
|
}
|
|
logMsg("tun2socks: stopped")
|
|
}
|