tun2socks

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: GPL-3.0 Imports: 39 Imported by: 0

README

go-tun2socks-build

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

build

Setup

  • install go (only test under version 1.15.2)
  • install gomobile and init with gomobile init -v
  • install JDK 8 (not jre)
  • Download Android SDK and NDK (only test under SDK 29 and NDK r21b)

Build

# proxy
export http_proxy=http://127.0.0.1:8087
export https_proxy=http://127.0.0.1:8087
# go
export GOPATH="~/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-r21b


go get -d ./...

# Build an AAR
make android

# Build a Framework (not test)
make ios

# Both
make

Documentation

Index

Constants

View Source
const (
	Version5              = 0x05
	AuthMethodNotRequired = 0x00
	SocksCmdConnect       = 0x01
	AddrTypeIPv4          = 0x01
	AddrTypeFQDN          = 0x03
	AddrTypeIPv6          = 0x04
	StatusSucceeded       = 0x00
)
View Source
const (
	VMESS  protocol = protocol("vmess")
	VLESS  protocol = protocol("vless")
	TROJAN protocol = protocol("trojan")
)

Variables

This section is empty.

Functions

func CheckVersion

func CheckVersion() 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 QueryOutboundStats added in v0.8.0

func QueryOutboundStats(tag string, direct string) int64

add in v2ray-core v4.26.0

func QueryStats

func QueryStats(direct string) int64

~/go/src/v2ray.com/core/proxy/vmess/outbound/outbound.go

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 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,
	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 StartV2RayWithTunFd added in v0.8.0

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

TODO: support ipv6

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 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 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 TestVmessLatency

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

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 Trojan added in v0.8.0

type Trojan struct {
	Add            string
	Port           int
	Password       string
	SNI            string
	SkipCertVerify bool
	VmessOptions
}

func NewTrojan added in v0.8.0

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

type Vmess

type Vmess struct {
	Host     string
	Path     string
	TLS      string
	Add      string
	Port     int
	Aid      int
	Net      string
	ID       string
	Type     string // headerType
	Security string // vnext.Security
	Protocol protocol
	VmessOptions
	Trojan *Trojan
}

constructor export New

func ConvertJSONToVmess

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

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 struct {
	UseIPv6        bool   `json:"useIPv6"`
	Loglevel       string `json:"logLevel"`
	RouteMode      int    `json:"routeMode"` // for SSRRAY
	EnableSniffing bool   `json:"enableSniffing"`
	DNS            string `json:"dns"` // DNS Config
	AllowInsecure  bool   `json:"allowInsecure"`
}

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