简体   繁体   English

Android VPNService setBlocking(true) 中断 VPN

[英]Android VPNService setBlocking(true) Breaks VPN

I'm looking at trying to implement a VPNService on Android for packet filtering and reporting and I have initially been looking at this project:我正在尝试在 Android 上实施 VPNService 以进行数据包过滤和报告,我最初一直在关注这个项目:

https://github.com/hexene/LocalVPN https://github.com/hexene/LocalVPN

As well as this I have been looking at Google's ToyVpn as a basis to understand what I can and can't do with a VPNService.除此之外,我一直在查看 Google 的 ToyVpn 作为基础,以了解我可以使用 VPNService 做什么和不能做什么。 The only issue with both is that start a non-blocking VPN when building the VPNService and then poll the file descrptor and then wait something like 100ms.两者的唯一问题是在构建 VPNService 时启动非阻塞 VPN,然后轮询文件描述符,然后等待大约 100 毫秒。 Both have comments suggesting that this is not the way to do it.两者都有评论表明这不是这样做的方法。 I'm assuming they run a non-blocking VPN because a blocking VPN is much more complicated?我假设他们运行的是非阻塞 VPN,因为阻塞 VPN 要复杂得多?

I also assumed (wrongly) that adding the line我还假设(错误地)添加了这条线

builder.setBlocking(true);

would fix things, but instead whilst the VPN service seems to do something, it doesn't seem to do anything useful because if you connect to it and open a browser session everything times out.会解决问题,但相反,虽然 VPN 服务似乎做了一些事情,但它似乎没有做任何有用的事情,因为如果你连接到它并打开浏览器 session 一切都会超时。 It's almost as if adding this line causes packets to be dropped.几乎就像添加此行会导致数据包被丢弃一样。

The aim is to get this as a blocking VPN so that I can eliminate the need for polling the file descriptor which I am sure is bad for battery life.目的是将其作为阻塞 VPN,这样我就可以消除轮询文件描述符的需要,我确信这对电池寿命不利。

Just for anyone seeing this and having the same issue, this is a question that misses the mark.对于看到此问题并遇到相同问题的任何人来说,这是一个未解决问题的问题。 Turns out turning blocking on was OK, it's just that the polling loop was not setup to be blocking which causes deadlock.事实证明打开阻塞是可以的,只是轮询循环没有设置为阻塞导致死锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM