mirror of
https://gitee.com/willfree/min-vpn-client_v2.git
synced 2026-10-04 19:42:00 +08:00
解决“外访与内访互相切换时,切换后不能正常访问”的问题。原因是少关闭了一个数据结构
This commit is contained in:
1 parent
ec7b37509b
commit
beb7f4c413
1 file changed
+18
-4
@@ -67,18 +67,20 @@ public class MINVpnService extends VpnService implements Handler.Callback{
|
||||
public static final String ACTION_DISCONNECT = "com.pkusz.min_vpn_client.STOP";
|
||||
|
||||
private Handler mHandler;
|
||||
AtomicReference<VpnPreparationInterface> vpnPreparation = new AtomicReference<>(); // 握手工具类
|
||||
AtomicReference<VpnPreparationInterface> vpnPreparation; // 握手工具类
|
||||
|
||||
// 标记是否在运行
|
||||
private static boolean isRunning = false;
|
||||
// tun文件操作符
|
||||
private ParcelFileDescriptor vpnInterface = null;
|
||||
// 缓冲队列
|
||||
private ConcurrentLinkedQueue<ByteBuffer> readTunDataQueue; // 读tun数据放入此队列
|
||||
private ConcurrentLinkedQueue<CPacket> readTunCPackets; // 读tun数据加工的包放入此队列
|
||||
private ConcurrentLinkedQueue<ByteBuffer> readTunDataQueue; // 读tun数据放入此队列
|
||||
private ConcurrentLinkedQueue<CPacket> readTunCPackets; // 读tun数据加工的包放入此队列
|
||||
// private ConcurrentLinkedQueue<CPacket> writeTunCPackets; // 写tun数据未拆解的包放入此队列
|
||||
private ConcurrentLinkedQueue<LpPacket> writeTunLpPackets; // 写tun数据未拆解的包放入此队列
|
||||
private ConcurrentLinkedQueue<ByteBuffer> writeTunDataQueue; // 写tun数据放入此队列
|
||||
private ConcurrentLinkedQueue<ByteBuffer> writeTunDataQueue; // 写tun数据放入此队列
|
||||
// 收发包face
|
||||
private LogicFace face;
|
||||
// Java官方提供的并发池
|
||||
private ExecutorService executorService;
|
||||
// 通信intent
|
||||
@@ -235,6 +237,7 @@ public class MINVpnService extends VpnService implements Handler.Callback{
|
||||
System.out.println("new 4");
|
||||
// 3. 开启线程池,进入数据中转阶段
|
||||
vpnInterface=connectionInfo.mParcelFileDescriptor;
|
||||
face=connectionInfo.face;
|
||||
// vpnInterface=null;
|
||||
setupVPN(connectionInfo,false);
|
||||
}
|
||||
@@ -249,6 +252,8 @@ public class MINVpnService extends VpnService implements Handler.Callback{
|
||||
final boolean isSM4,
|
||||
final String allocatedAddressFromInner,
|
||||
boolean isInner){
|
||||
// 初始化VpnPreparation(非常重要,用于将连接状态通过intent通知给界面)
|
||||
vpnPreparation = new AtomicReference<>();
|
||||
Thread netRequestThread = new Thread(() -> {
|
||||
if(isInner) { // 内网
|
||||
vpnPreparation.set(new VpnIntranetPreparation(this, vpnServerInfo, sharedSecret,
|
||||
@@ -441,12 +446,21 @@ public class MINVpnService extends VpnService implements Handler.Callback{
|
||||
writeTunDataQueue = null;
|
||||
writeTunLpPackets = null;
|
||||
ByteBufferPool.clear();
|
||||
// 关闭tun网卡
|
||||
try {
|
||||
vpnInterface.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("vpnInterface close error");
|
||||
}
|
||||
vpnInterface=null;
|
||||
// 关闭face
|
||||
if(face!=null){
|
||||
face.shutDown();
|
||||
face=null;
|
||||
}
|
||||
// 关闭vpnPreparation
|
||||
vpnPreparation = null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user