Git Product home page Git Product logo

androidlibv2ray's People

Contributors

2dust avatar ariselia avatar darienraymond avatar liberal-boy avatar xiaokangwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidlibv2ray's Issues

CoreI/Status.go中的getDataDir()函数可能需要修改

Android 6.0以后系统支持多用户,分别为"主要用户"、"次要用户"、“访客”。以前的手机用户内置存储区在/data/data/packagename/中。但是现在的用户内置存储区在/data/user/userId/packagename/目录。比如,“主要用户”的userid为0,则它的私人内部存储区在/data/user/0/com.v2ray.ang/目录,而第一个“次要用户”的userid为10,它的私人内部存储区在/data/user/10/com.v2ray.ang/目录,以此类推。手机/data/data/packagename/目录仍然存在,应该是为了兼容性考虑,但是这个目录只有“主要用户”可以访问。所以导致了“次要用户”安装这个应用的时候,无法成功启动vpn服务。通过logcat可以看到,提示“fork exec /data/data/tun2sock : permission denied”。
希望作者能修改这个问题,让多用户的手机也可以安装使用。

获取用户内部存储目录有相关函数,但方便起见我做了如下修改,并测试,已经测试通过。“主要用户”、“次要用户”都可以成功运行。用户的userid可以通过uid/100000得到。CoreI/Status.go中的getDataDir()函数修改如下:

func (v *Status) getDataDir() string {
var datadir = "/data/data/org.kkdev.v2raygo/"
if v.PackageName != "" {
datadir = "/data/user/" + strconv.Itoa(os.Getuid()/100000) + "/" + v.PackageName + "/"
}
return datadir
}

真机上可以正常运行,在多款模拟器运行进程会被杀

在模拟器(Nexus 6P API 27(Android 8.1.0,API 27))上运行一会之后,vpnservice会被杀,期间网络不能正常访问。已测试多款模拟器,都出现该情况。但真机实测是正常的。出现的崩溃日志如下:

11-13 01:00:37.957 8316-0/com.package.test:V2RayVPN E/Go: (0x0,0x0)
11-13 01:00:37.957 8316-8354/com.package.test:V2RayVPN E/GoLog: (0x0,0x0)
11-13 01:00:37.961 8316-0/com.package.test:V2RayVPN E/Go: panic: runtime error: invalid memory address or nil pointer dereference
11-13 01:00:37.962 8316-0/com.package.test:V2RayVPN E/Go: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xccdd50f7]
goroutine 15 [running]:
os.(*Process).signal(0x0, 0xcd612170, 0xcda3f034, 0x0, 0x0)
11-13 01:00:37.963 8316-0/com.package.test:V2RayVPN E/Go: /usr/local/go/src/os/exec_unix.go:56 +0x27
os.(*Process).Signal(0x0, 0xcd612170, 0xcda3f034, 0x9c49c000, 0x2)
11-13 01:00:37.966 8316-0/com.package.test:V2RayVPN E/Go: /usr/local/go/src/os/exec.go:131 +0x2b
11-13 01:00:37.967 8316-0/com.package.test:V2RayVPN E/Go: os.(*Process).kill(0x0, 0x0, 0x0)
/usr/local/go/src/os/exec_posix.go:54 +0x33
11-13 01:00:37.967 8316-0/com.package.test:V2RayVPN E/Go: os.(*Process).Kill(0x0, 0x1, 0x1)
11-13 01:00:37.968 8316-0/com.package.test:V2RayVPN E/Go: /usr/local/go/src/os/exec.go:116 +0x1b
11-13 01:00:37.968 8316-8354/com.package.test:V2RayVPN E/GoLog: panic: runtime error: invalid memory address or nil pointer dereference
11-13 01:00:37.968 8316-0/com.package.test:V2RayVPN E/Go: github.com/xiaokangwang/AndroidLibV2ray/Process/Escort.(*Escorting).EscortingDown(0x9c5e6040)
11-13 01:00:37.969 8316-0/com.package.test:V2RayVPN E/Go: /Users/uimeet/go/src/github.com/xiaokangwang/AndroidLibV2ray/Process/Escort/escort.go:104 +0x8b
github.com/xiaokangwang/AndroidLibV2ray/VPN.(*VPNSupport).VpnShutdown(0x9c49a840)
11-13 01:00:37.971 8316-0/com.package.test:V2RayVPN E/Go: /Users/uimeet/go/src/github.com/xiaokangwang/AndroidLibV2ray/VPN/vpnservice_interact.go:74 +0xb3
github.com/xiaokangwang/AndroidLibV2ray.(*V2RayPoint).stopLoopW(0x9c4bc230)
11-13 01:00:37.972 8316-0/com.package.test:V2RayVPN E/Go: /Users/uimeet/go/src/github.com/xiaokangwang/AndroidLibV2ray/interact.go:259 +0x82
created by github.com/xiaokangwang/AndroidLibV2ray.(*V2RayPoint).StopLoop
/Users/uimeet/go/src/github.com/xiaokangwang/AndroidLibV2ray/interact.go:279 +0x59

--------- beginning of crash

11-13 01:00:37.972 8316-8360/com.package.test:V2RayVPN A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 8360 (Thread-9), pid 8316 (.tunan:V2RayVPN)

最新版的MIUI开发版在分应用代理下会Crash

你好,昨天更新 Android 系统后,发现市面上两款 V2Ray Android App 在分应用代理模式下,都会产生相同的Crash。根据 Crash Report 的 backtrace 看见是 Crash 在 libgojni.so ,所以猜测可能是底层的 AndroidLibV2ray 产生了问题。但是由于个人不是很熟悉 Kotlin 和 Android App 开发,所以没怎么看懂关于分应用代理这块是怎么处理的,具体的 Crash Report 如下,

10-19 00:47:09.841  5050  5078 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 5078 (Thread-3)
10-19 00:47:09.913  5097  5097 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-19 00:47:09.914  5097  5097 F DEBUG   : Build fingerprint: 'Xiaomi/lithium/lithium:7.0/NRD90M/7.10.18:user/release-keys'
10-19 00:47:09.914  5097  5097 F DEBUG   : Revision: '0'
10-19 00:47:09.914  5097  5097 F DEBUG   : ABI: 'arm64'
10-19 00:47:09.914  5097  5097 F DEBUG   : pid: 5050, tid: 5078, name: Thread-3  >>> com.v2ray.actinium:RunSoLibV2RayDaemon <<<
10-19 00:47:09.914  5097  5097 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
10-19 00:47:09.919  5097  5097 F DEBUG   : Abort message: 'Unknown reference: 42'
10-19 00:47:09.919  5097  5097 F DEBUG   :     x0   0000000000000000  x1   00000000000013d6  x2   0000000000000006  x3   0000000000000008
10-19 00:47:09.919  5097  5097 F DEBUG   :     x4   0000000000000000  x5   0000000000000000  x6   0000007f9994e000  x7   0000000000000000
10-19 00:47:09.919  5097  5097 F DEBUG   :     x8   0000000000000083  x9   ffffffffffffffdf  x10  0000000000000000  x11  0000000000000001
10-19 00:47:09.919  5097  5097 F DEBUG   :     x12  ffffffffffffffff  x13  0000000000000000  x14  0000000000000000  x15  003229893a4b8818
10-19 00:47:09.919  5097  5097 F DEBUG   :     x16  0000007f97418ed0  x17  0000007f973c2638  x18  00000000ebad6082  x19  0000007f79a6e4f8
10-19 00:47:09.919  5097  5097 F DEBUG   :     x20  0000000000000006  x21  0000007f79a6e450  x22  000000000000000b  x23  0000007f8d60c4a0
10-19 00:47:09.920  5097  5097 F DEBUG   :     x24  0000007f79a6e4d0  x25  00000000000fd000  x26  0000007f7a644880  x27  0000000000000190
10-19 00:47:09.920  5097  5097 F DEBUG   :     x28  0000004420001d40  x29  0000007f79a6e1a0  x30  0000007f973bfac8
10-19 00:47:09.920  5097  5097 F DEBUG   :     sp   0000007f79a6e180  pc   0000007f973c2640  pstate 0000000060000000
10-19 00:47:09.934  5097  5097 F DEBUG   : 
10-19 00:47:09.934  5097  5097 F DEBUG   : backtrace:
10-19 00:47:09.935  5097  5097 F DEBUG   :     #00 pc 000000000006b640  /system/lib64/libc.so (tgkill+8)
10-19 00:47:09.935  5097  5097 F DEBUG   :     #01 pc 0000000000068ac4  /system/lib64/libc.so (pthread_kill+64)
10-19 00:47:09.935  5097  5097 F DEBUG   :     #02 pc 0000000000024010  /system/lib64/libc.so (raise+24)
10-19 00:47:09.935  5097  5097 F DEBUG   :     #03 pc 000000000001ca94  /system/lib64/libc.so (abort+52)
10-19 00:47:09.935  5097  5097 F DEBUG   :     #04 pc 0000000000518e9c  /data/app/com.v2ray.actinium-1/lib/arm64/libgojni.so (go_seq_from_refnum+144)

相关 issue: V2Ray-Android/Actinium#33

How about ship dnscache replace pdnsd?

How about ship dnscache replace pdnsd?

I see android libv2ray shipped with pdnsd.

How about ship dnscache bind with libv2ray?

I am the author of dnscache https://github.com/netroby/dnscache

It was a very small dns cached resolver written with golang.

libv2ray using gomobile, i thought it will be very easy to integrate with my dnscache.

libv2ray处理DNS请求的方式有问题

在Android中,开启VPN后,OS仍会负责发起域名解析请求。libv2ray会将DNS请求当作UDP报文直接进行路由,而在默认使用8.8.8.8访问geoip:cn的情况下,在远端发送DNS请求会导致返回不适合本地的IP地址,导致网页访问缓慢或者返回了面向海外的页面。而在PC上,Socks客户端向服务端发送的只有域名信息,域名的解析由v2ray全权负责。tun2socks虽然将tun界面转换为了socks界面,却并不能良好的处理DNS请求,导致DNS请求全部被无脑转发、返回了不适合直连的CDN。比如,通过Actinium访问淘宝,在全局代理下会被重定向到国际版,而在PC上是正常的。原文一开始发在了v2ray/core下,但我感觉应该是libv2ray的实现方式有问题,和v2ray本身应该没有关系。所以稍加编辑、发在了这里。

环境:

  • 服务器端:2.47
  • PC端:2.47,传入连接使用Socks协议。
  • Android端:2.50+libv2ray 25+Actinium。

下面是我的猜测。
首先,Firefox在创建连接时是直接向v2ray发送的域名,本身并没有生成DNS请求。Socks协议允许客户端建立TCP连接时直接请求域名而无须预先将域名解析成IP地址,而Firefox则完全没有参与域名的解析过程,在访问某个页面时只是把域名直接发送给了Socks服务器。若访问的域名属于geosite:cn,则wireshark中可发现对该网站的DNS请求。若访问的域名不属于geosite:cn,wireshark中就不能发现对该网站的DNS请求,而v2ray的log中可见通过隧道向8.8.8.8:53发起的的DNS请求。真正生成DNS请求的应该是v2ray本身。V2ray将会通过路由规则来选择将DNS请求送给OS中设置的DNS服务器或v2ray的配置文件中指定的DNS服务器。

PC环境下Wireshark所获取的Socks报文如下。

Transmission Control Protocol, Src Port: 14696, Dst Port: 1082, Seq: 1, Ack: 1, Len: 3
Socks Protocol
    Version: 5
    Client Authentication Methods

Transmission Control Protocol, Src Port: 1082, Dst Port: 14696, Seq: 1, Ack: 4, Len: 2
Socks Protocol
    Version: 5
    Accepted Auth Method: 0x0 (No authentication)

Transmission Control Protocol, Src Port: 14696, Dst Port: 1082, Seq: 4, Ack: 3, Len: 17
Socks Protocol
    Version: 5
    Command: Connect (1)
    Reserved: 0
    Address Type: Domain Name (3)(注意这一行)
    Remote name: google.com(注意这一行)
    Port: 80

……

通过v2ray访问twitter和淘宝的日志输出如下(测试前已清空DNS缓存)。

2017/11/23 11:22:11 [Info]Proxy|Socks: TCP Connect request to tcp:twitter.com:443
2017/11/23 11:22:11 [Info]App|Router: looking up IP for tcp:twitter.com:443
2017/11/23 11:22:11 [Debug]App|DNS|Server: add pending request id 64489
2017/11/23 11:22:11 [Debug]Transport|Internet|UDP: dispatch request to: udp:8.8.8.8:53
2017/11/23 11:22:11 [Info]Transport|Internet|UDP: establishing new connection for udp:8.8.8.8:53
2017/11/23 11:22:11 [Info]App|Dispatcher|Default: default route for udp:8.8.8.8:53
2017/11/23 11:22:11 [Info]App|Proxyman|Mux: dispatching request to udp:8.8.8.8:53
2017/11/23 11:22:11 [Debug]App|DNS|Server: handling response for id 64489 content: ;; opcode: QUERY, status: NOERROR, id: 64489
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;twitter.com.   IN       A

;; ANSWER SECTION:
twitter.com.    466     IN      A       104.244.42.1
twitter.com.    466     IN      A       104.244.42.193

2017/11/23 11:22:11 [Debug]App|DNS|Server: returning 2 IPs for domain twitter.com.
2017/11/23 11:22:11 [Info]App|Dispatcher|Default: default route for tcp:twitter.com:443
2017/11/23 11:22:11 [Info]App|Proxyman|Mux: dispatching request to tcp:twitter.com:443
2017/11/23 11:22:11 [Info]Proxy|Socks: TCP Connect request to tcp:twitter.com:443
2017/11/23 11:22:11 [Info]App|Router: looking up IP for tcp:twitter.com:443
2017/11/23 11:22:11 [Info]App|Dispatcher|Default: default route for tcp:twitter.com:443
2017/11/23 11:24:06 [Info]Proxy|Socks: TCP Connect request to tcp:taobao.com:80
2017/11/23 11:24:06 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:taobao.com:80]
2017/11/23 11:24:06 [Info]Proxy|Freedom: opening connection to tcp:taobao.com:80
2017/11/23 11:24:06 [Info]Transport|Internet|TCP: dailing TCP to tcp:taobao.com:80
2017/11/23 11:24:07 [Info]Proxy|Socks: TCP Connect request to tcp:taobao.com:80
2017/11/23 11:24:07 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:taobao.com:80]
2017/11/23 11:24:07 [Info]Proxy|Freedom: opening connection to tcp:taobao.com:80
2017/11/23 11:24:07 [Info]Transport|Internet|TCP: dailing TCP to tcp:taobao.com:80
2017/11/23 11:24:07 [Info]Proxy|Socks: TCP Connect request to tcp:www.taobao.com:443
2017/11/23 11:24:07 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:www.taobao.com:443]
2017/11/23 11:24:07 [Info]Proxy|Freedom: opening connection to tcp:www.taobao.com:443
2017/11/23 11:24:07 [Info]Transport|Internet|TCP: dailing TCP to tcp:www.taobao.com:443
2017/11/23 11:24:08 [Info]Proxy|Socks: TCP Connect request to tcp:www.taobao.com:443
2017/11/23 11:24:08 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:www.taobao.com:443]
2017/11/23 11:24:08 [Info]Proxy|Freedom: opening connection to tcp:www.taobao.com:443

但是在Android平台上,建立TCP链接的流程与PC+Firefox+v2ray有者很大的差别。libv2ray是通过tun2socks将隧道设备转换为socks链接的,而Android OS本身依旧在按照正常的流程(DNS解析、建立连接)对外建立TCP链接,所有的DNS请求都是由OS本身发出的,v2ray本身只能将DNS报文当作普通的UDP报文、按照路由设置机械的转发。Android在建立连接时将会直接使用IP建立连接。

通过v2ray访问twitter和淘宝的日志输出如下。

2017/11/23 05:21:30 [Info]Proxy|Socks: client UDP connection from udp:127.0.0.1:43520
2017/11/23 05:21:30 [Debug]Proxy|Socks: send packet to udp:8.8.8.8:53 with 28 bytes
2017/11/23 05:21:30 [Debug]Transport|Internet|UDP: dispatch request to: udp:8.8.8.8:53
2017/11/23 05:21:30 [Info]Transport|Internet|UDP: establishing new connection for udp:8.8.8.8:53
2017/11/23 05:21:30 [Info]App|Dispatcher|Default: default route for udp:8.8.8.8:53
2017/11/23 05:21:30 [Info]App|Proxyman|Mux: dispatching request to udp:8.8.8.8:53
………………
2017/11/23 05:21:30 [Info]Proxy|Socks: TCP Connect request to tcp:202.47.28.119:443
2017/11/23 05:21:30 [Info]App|Dispatcher|Default: sniffed domain: taobao.com
2017/11/23 05:21:30 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:taobao.com:80]
2017/11/23 05:21:30 [Info]Proxy|Freedom: opening connection to tcp:taobao.com:80
2017/11/23 05:21:30 [Info]Transport|Internet|TCP: dailing TCP to tcp:taobao.com:80
………………
2017/11/23 05:21:30 [Info]Proxy|Socks: TCP Connect request to tcp:47.89.66.254:443
2017/11/23 05:21:31 [Info]App|Dispatcher|Default: sniffed domain: m.taobao.com
2017/11/23 05:21:31 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:m.taobao.com:443]
2017/11/23 05:21:31 [Info]Proxy|Freedom: opening connection to tcp:m.taobao.com:443
2017/11/23 05:21:31 [Info]Transport|Internet|TCP: dailing TCP to tcp:m.taobao.com:443
………………
2017/11/23 05:21:38 [Info]Proxy|Socks: client UDP connection from udp:127.0.0.1:55957
2017/11/23 05:21:38 [Debug]Proxy|Socks: send packet to udp:8.8.8.8:53 with 19 bytes
2017/11/23 05:21:38 [Debug]Transport|Internet|UDP: dispatch request to: udp:8.8.8.8:53
2017/11/23 05:21:38 [Info]Transport|Internet|UDP: establishing new connection for udp:8.8.8.8:53
2017/11/23 05:21:38 [Info]App|Dispatcher|Default: default route for udp:8.8.8.8:53
2017/11/23 05:21:38 [Info]App|Proxyman|Mux: dispatching request to udp:8.8.8.8:53
2017/11/23 05:21:38 [Info]App|Dispatcher|Default: sniffed domain: m.intl.taobao.com
2017/11/23 05:21:38 [Info]App|Dispatcher|Default: taking detour [direct] for [tcp:m.intl.taobao.com:443]
2017/11/23 05:21:38 [Info]Proxy|Freedom: opening connection to tcp:m.intl.taobao.com:443
2017/11/23 05:21:38 [Info]Transport|Internet|TCP: dailing TCP to tcp:m.intl.taobao.com:443
2017/11/23 04:47:54 [Info]Proxy|Socks: client UDP connection from udp:127.0.0.1:35010
2017/11/23 04:47:54 [Info]Transport|Internet|UDP: establishing new connection for udp:8.8.8.8:53
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: default route for udp:8.8.8.8:53
2017/11/23 04:47:54 [Info]App|Proxyman|Mux: dispatching request to udp:8.8.8.8:53
2017/11/23 04:47:54 [Info]Proxy|Socks: TCP Connect request to tcp:104.244.42.65:443
2017/11/23 04:47:54 [Info]Proxy|Socks: TCP Connect request to tcp:104.244.42.65:443
2017/11/23 04:47:54 [Info]Proxy|Socks: TCP Connect request to tcp:104.244.42.65:443
2017/11/23 04:47:54 [Info]Proxy|Socks: TCP Connect request to tcp:104.244.42.65:443
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: sniffed domain: twitter.com
2017/11/23 04:47:54 [Info]App|Router: looking for IP for domain: twitter.com
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: default route for tcp:twitter.com:443
2017/11/23 04:47:54 [Info]App|Proxyman|Mux: dispatching request to tcp:twitter.com:443
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: sniffed domain: twitter.com
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: sniffed domain: twitter.com
2017/11/23 04:47:54 [Info]App|Router: looking for IP for domain: twitter.com
2017/11/23 04:47:54 [Info]App|Router: looking for IP for domain: twitter.com
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: default route for tcp:twitter.com:443
2017/11/23 04:47:54 [Info]App|Proxyman|Mux: dispatching request to tcp:twitter.com:443
2017/11/23 04:47:54 [Info]App|Router: looking for IP for domain: twitter.com
2017/11/23 04:47:54 [Info]App|Dispatcher|Default: default route for tcp:twitter.com:443
2017/11/23 04:47:54 [Info]App|Proxyman|Mux: dispatching request to tcp:twitter.com:443
2017/11/23 04:47:54 [Info]Transport|Internet|WebSocket: creating connection to tcp:wodeipdizhi:80
2017/11/23 04:47:55 [Info]Proxy|VMess|Outbound: tunneling request to tcp:v1.mux.cool:9527 via tcp:wodeipdizhi:80

因此v2ray在这个情况下就不能将域名与按照路由规则送给不同的服务器解析。如果DNS设置为海外的服务器就会导致淘宝返回海外版页面。即使是设置了domainOverride也只能是在建立连接时再通过嗅探选择直连或走隧道,无法解决问题。

Android端配置文件

{
  "port": 10808,
  "log": {
    "loglevel": "debug"
  },
  "inbound": {
    "domainOverride": [
        "http",
        "tls"
    ],
    "listen": "127.0.0.1",
    "protocol": "socks",
    "settings": {
      "auth": "noauth",
      "udp": true
    },
    "allowPassive": true
  },
  "inboundDetour": [
    {
      "protocol": "http",
      "port": 10845,
      "settings": {},
      "listen": "127.0.0.1"
    },
    {
      "protocol": "dokodemo-door",
      "port": 10846,
      "listen": "0.0.0.0",
      "settings": {
        "network": "tcp",
        "timeout": 0,
        "followRedirect": true
      }
    }
  ],
  "outbound": {
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "<ws.address>",
          "port": <ws.port>,
          "users": [
            {
              "id": "<id>",
              "alterId": 64,
              "security": "auto"
            }
          ]
        }
      ]
    },
    "mux":{
      "enabled":true
    }
  },
  "outboundDetour": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    }
  ],
  "dns": {
    "servers": [
      "8.8.8.8",
      "8.8.4.4",
      "localhost"
    ]
  },
  "routing": {
    "strategy": "rules",
    "settings": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "type": "field",
          "port": "1-52",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "54-79",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "81-442",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "444-65535",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "domain": ["geosite:cn"],
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "ip": [
            "0.0.0.0/8",
            "10.0.0.0/8",
            "100.64.0.0/10",
            "127.0.0.0/8",
            "169.254.0.0/16",
            "172.16.0.0/12",
            "192.0.0.0/24",
            "192.0.2.0/24",
            "192.168.0.0/16",
            "198.18.0.0/15",
            "198.51.100.0/24",
            "203.0.113.0/24",
            "::1/128",
            "fc00::/7",
            "fe80::/10",
            "geoip:cn"
          ],
          "outboundTag": "direct"
        }
      ]
    }
  },
  "transport": {},
  "#lib2ray": {
    "enabled": true,
    "listener": {
      "onUp": "#none",
      "onDown": "#none"
    },
    "env": [
      "V2RayDNSPort=5353",
      "DNSForwardingProxyPort=5350",
      "V2RaySocksPort=10808"
    ],
    "render": [],
    "escort": [],
    "vpnservice": {
      "Target": "${datadir}tun2socks",
      "Args": [
        "--netif-ipaddr",
        "26.26.26.2",
        "--netif-netmask",
        "255.255.255.0",
        "--socks-server-addr",
        "127.0.0.1:$V2RaySocksPort",
        "--tunfd",
        "3",
        "--tunmtu",
        "1500",
        "--sock-path",
        "/dev/null",
        "--loglevel",
        "4",
        "--enable-udprelay"
      ],
      "VPNSetupArg": "m,1500 a,26.26.26.1,24 r,0.0.0.0,0 d,208.67.222.222"
    },
    "preparedDomainName": {
      "domainName": [
        "<ws.address>:<ws.port>"
      ],
      "tcpVersion": "tcp4",
      "udpVersion": "udp4"
    }
  }
}

PC端配置文件

{
  "log": {
    "loglevel": "debug"
  },
  "inbound": {
    "port": 1082,
    "listen": "127.0.0.1",
    "protocol": "socks",
    "settings": {
      "auth": "noauth",
      "udp": true,
      "ip": "127.0.0.1",
      "timeout": 0
    
    }
  },
  "outbound": {
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "<ws.address>",
          "port": <ws.port>,
          "users": [
            {
              "id": "<id>",
              "alterId": 64,
              "security": "auto"
            }
          ]
        }
      ]
    },
    "mux":{
      "enabled":true
    }
  },
  "outboundDetour": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    }
  ],
  "dns": {
    "servers": [
      "8.8.8.8",
      "8.8.4.4",
      "localhost"
    ]
  },
  "routing": {
    "strategy": "rules",
    "settings": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "type": "field",
          "port": "1-52",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "54-79",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "81-442",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "444-65535",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "domain": ["geosite:cn"],
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "ip": [
            "0.0.0.0/8",
            "10.0.0.0/8",
            "100.64.0.0/10",
            "127.0.0.0/8",
            "169.254.0.0/16",
            "172.16.0.0/12",
            "192.0.0.0/24",
            "192.0.2.0/24",
            "192.168.0.0/16",
            "198.18.0.0/15",
            "198.51.100.0/24",
            "203.0.113.0/24",
            "::1/128",
            "fc00::/7",
            "fe80::/10",
            "geoip:cn"
          ],
          "outboundTag": "direct"
        }
      ]
    }
  }
}

(两者的路由、DNS、传出规则都是一致的)

请问是怎么调用android的vpnservice的?

不是很了解V2ray,纯粹是为了看看用golang怎么在Andorid里面调用VPN service而不需要手机root才能使用vpn。AndroidLibV2ray用go get 拿不下来,也没有详细的readme告知怎么用。

看代码是不是主要在 EscortRun 里面创建vpn的? file := os.NewFile(uintptr(tapfd), "/dev/tap0"), 这个用法貌似不能在非root的android里面成功吧?而且跟官方文档的做法不太像: https://developer.android.com/reference/android/net/VpnService.html, 那里讲是要用Builder, prepare,establish等过程...

请你能解释一下你是怎么做的吗?

谢谢

the purpose of using unix.Connect and its FileConn?

hello, could you please say the purpose of specifying the unix socket to return the conn? i found the simply net.Dialer.Dial done this as well.

great thanks for this repo.

sa := new(unix.SockaddrInet6)
spew.Dump(addr, sDialer.vp.prepareddomain.tcpprepared)
sa.Port = addr.Port
sa.ZoneId = uint32(zoneToInt(addr.Zone))
//fmt.Println(addr.IP.To16())
copy(sa.Addr[:], addr.IP.To16())
//fmt.Println(sa.Addr)
err = unix.Connect(fd, sa)
if err != nil {
return nil, err
}
file := os.NewFile(uintptr(fd), "Socket")
conn, err := net.FileConn(file)
if err != nil {
return nil, err
}
return conn, nil

var dialer = &net.Dialer{
    // dialer simply get and protect the fd in addition
    Control: func(fd uintptr) { protect(fd) }
}

return dialer.DialContext(ctx, network, dest)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.