tun2socks

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2022 License: GPL-3.0 Imports: 50 Imported by: 0

README

go-tun2socks-build

Building and using go-tun2socks for V2Ray on Android. This library is used in shadowsocksr-v2ray-trojan-android for support V2Ray.

build

Setup

  • install go (test under version 1.18.1)
  • install gomobile and init with gomobile init -v
  • install JDK 8 (not jre)
  • Download Android SDK and NDK (test under SDK 30 and NDK r21e)

Build

export GOPROXY=https://goproxy.cn
# go
export GOPATH="/home/xxx/go"
export PATH=$PATH:/usr/local/go/bin:~/go/bin
# android
export ANDROID_HOME=/path/to/Android/Sdk
export ANDROID_NDK_HOME=/path/to/Android/android-ndk-r21d

go get -d ./...

# Build an AAR
make android

Documentation

Index

Constants

View Source
const (
	Version5              = 0x05
	AuthMethodNotRequired = 0x00
	SocksCmdConnect       = 0x01
	AddrTypeIPv4          = 0x01
	AddrTypeFQDN          = 0x03
	AddrTypeIPv6          = 0x04
	StatusSucceeded       = 0x00
)

Variables

This section is empty.

Functions

func BatchRenderTestDownload added in v0.9.0

func BatchRenderTestDownload(link string, concurrency int, fontPath string, pngPath string, language string, urlGroup string, testDownload TestDownload) error

func BatchTestDownload added in v0.9.0

func BatchTestDownload(link string, concurrency int, testDownload TestDownload) error

func BatchTestLatency added in v0.9.0

func BatchTestLatency(link string, concurrency int, testLatency TestLatency)

func BatchTestVmessCoreLatency added in v0.9.0

func BatchTestVmessCoreLatency(link string, concurrency int, testLatency TestLatency)

FIXME: block on startup

func CheckVersion

func CheckVersion() string

func CheckXVersion added in v0.9.0

func CheckXVersion() string

func CopyAssets

func CopyAssets(assetDir string, force bool) error

TODO: update base on version

func DecodeJSONConfig

func DecodeJSONConfig(reader io.Reader) (*conf.Config, error)

func GenerateVmessString

func GenerateVmessString(profile *Vmess) (string, error)

func GetFreePort

func GetFreePort() (int, error)

func InputPacket

func InputPacket(data []byte)

Write IP packets to the lwIP stack. Call this function in the main loop of the VpnService in Java/Kotlin, which should reads packets from the TUN fd.

func ParseClash added in v0.9.0

func ParseClash(message string) (string, error)

convert clash file to vmess/trojan links, links are separated by newline(\n)

func PeekClash added in v0.9.0

func PeekClash(message string, n int) (string, error)

get top n links of clash file

func QueryOutboundStats added in v0.8.0

func QueryOutboundStats(tag string, direct string) int64

add in v2ray-core v4.26.0

func QueryOutboundXStats added in v0.9.0

func QueryOutboundXStats(tag string, direct string) int64

func QueryStats

func QueryStats(direct string) int64

~/go/src/github.com/v2fly/v2ray-core/v4/proxy/vmess/outbound/outbound.go

func Resolve added in v0.9.0

func Resolve(addr string, enableIPv6 bool, hostname string) (string, error)

resolve dns

func SetLocalDNS

func SetLocalDNS(dns string)

SetLocalDNS sets the DNS server that used by Go's default resolver, it accepts string in the form "host:port", e.g. 223.5.5.5:53

func SetNonblock

func SetNonblock(fd int, nonblocking bool) bool

SetNonblock puts the fd in blocking or non-blocking mode.

func StartShadowsocksTunFd added in v0.9.0

func StartShadowsocksTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	shadowsocks *Shadowsocks,
	assetPath string) error

func StartTrojan added in v0.8.0

func StartTrojan(
	packetFlow PacketFlow,
	vpnService VpnService,
	logService LogService,
	trojan *Trojan,
	assetPath string) error

func StartTrojanTunFd added in v0.8.0

func StartTrojanTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	trojan *Trojan,
	assetPath string) error

func StartV2Ray

func StartV2Ray(
	packetFlow PacketFlow,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	configBytes []byte,
	assetPath string) error

StartV2Ray sets up lwIP stack, starts a V2Ray instance and registers the instance as the connection handler for tun2socks.

func StartV2RayLiteWithTunFd added in v0.9.0

func StartV2RayLiteWithTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	profile *Vmess,
	assetPath string) error

func StartV2RayWithTunFd added in v0.8.0

func StartV2RayWithTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	profile *Vmess,
	assetPath string) error

func StartV2RayWithVmess

func StartV2RayWithVmess(
	packetFlow PacketFlow,
	vpnService VpnService,
	logService LogService,
	profile *Vmess,
	assetPath string) error

StartV2Ray sets up lwIP stack, starts a V2Ray instance and registers the instance as the connection handler for tun2socks.

func StartXRay added in v0.9.0

func StartXRay(
	packetFlow PacketFlow,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	configBytes []byte,
	assetPath string) error

func StartXRayWithTunFd added in v0.9.0

func StartXRayWithTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	profile *Vmess,
	assetPath string) error

func StartXShadowsocksTunFd added in v0.9.0

func StartXShadowsocksTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	shadowsocks *Shadowsocks,
	assetPath string) error

func StartXTrojanTunFd added in v0.9.0

func StartXTrojanTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	trojan *Trojan,
	assetPath string) error

func StartXVlessTunFd added in v0.9.0

func StartXVlessTunFd(
	tunFd int,
	vpnService VpnService,
	logService LogService,
	querySpeed QuerySpeed,
	vl *Vless,
	assetPath string) error

func StopV2Ray

func StopV2Ray()

StopV2Ray stop v2ray

func TestConfig

func TestConfig(ConfigureFileContent string, assetperfix string) error

func TestConfigLatency

func TestConfigLatency(configBytes []byte, assetPath string) (int64, error)

func TestLinkDownloadSpeed added in v0.9.0

func TestLinkDownloadSpeed(link string, cb TestLatencyStop) (int64, error)

func TestTCPPing

func TestTCPPing(host string, port int) (int64, error)

func TestTrojanLatency added in v0.8.0

func TestTrojanLatency(trojan *Trojan) (int64, error)

func TestURLLatency

func TestURLLatency(url string) (int64, error)

func TestVmessDownload added in v0.9.0

func TestVmessDownload(profile *Vmess, timeout time.Duration, cb TestLatency) (int64, error)

func TestVmessLatency

func TestVmessLatency(profile *Vmess, port int) (int64, error)

func TestVmessLatencyDirect added in v0.9.0

func TestVmessLatencyDirect(profile *Vmess) (int64, error)

TODO: support more protocol

Types

type LogService

type LogService interface {
	WriteLog(s string) error
}

type PacketFlow

type PacketFlow interface {
	// WritePacket should writes packets to the TUN fd.
	WritePacket(packet []byte)
}

PacketFlow should be implemented in Java/Kotlin.

type QuerySpeed added in v0.8.0

type QuerySpeed interface {
	UpdateTraffic(up int64, down int64)
}

type Shadowsocks added in v0.9.0

type Shadowsocks features.Shadowsocks

func NewShadowSocks added in v0.9.0

func NewShadowSocks(Add string, Port int, Password string, Method string, opt []byte) *Shadowsocks

type TestDownload added in v0.9.0

type TestDownload interface {
	UpdateSpeed(id int, speed int64, elapse int64)
	UpdateTraffic(id int, traffic int64)
}

type TestLatency added in v0.9.0

type TestLatency interface {
	UpdateLatency(id int, elapsed int64)
}

type TestLatencyStop added in v0.9.0

type TestLatencyStop interface {
	UpdateLatency(id int, elapsed int64) bool
}

type Trojan added in v0.8.0

type Trojan features.Trojan

func NewTrojan added in v0.8.0

func NewTrojan(Add string, Port int, Password string, SNI string, SkipCertVerify bool, Net string, Path string, Host string, opt []byte) *Trojan

type Vless added in v0.9.0

type Vless features.Vless

func NewVless added in v0.9.0

func NewVless(Add string, Port int, ID string, TLS string, HeaderType string, Encryption string, Net string, Flow string, Security string, Path string, Host string, SNI string, opt []byte) *Vless

type Vmess

type Vmess features.Vmess

func ConvertJSONToVmess

func ConvertJSONToVmess(configBytes []byte) (*Vmess, error)

func NewLiteShadowSocks added in v0.9.0

func NewLiteShadowSocks(Add string, Port int, ID string, Security string, opt []byte) *Vmess

func NewVmess

func NewVmess(Host string, Path string, TLS string, Add string, Port int, Aid int, Net string, ID string, Type string, Security string, opt []byte) *Vmess

TODO: default value

type VmessOptions added in v0.8.0

type VmessOptions features.VmessOptions

type VpnService

type VpnService interface {
	// Protect is just a proxy to the VpnService.protect() method.
	// See also: https://developer.android.com/reference/android/net/VpnService.html#protect(int)
	Protect(fd int) bool
}

VpnService should be implemented in Java/Kotlin.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL