增加了发包的反编码测试(最后定位的问题是后台的NAT没开);目的标识的随机字段,由原来的.数字,修改为纯数字

This commit is contained in:
free will committed 2021-12-29 17:46:43 +08:00
1 parent 7eb9ea5775
commit 559a52e86b
5 files changed
+46 -1

No files matched your search

@@ -8,6 +8,7 @@ package com.pkusz.min_vpn_client.services.Runnables;
*/
import com.pkusz.min_vpn_client.services.ByteBufferPool;
import com.pkusz.min_vpn_client.utils.TLVDecoderHelper;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -15,9 +16,12 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import component.ComponentException;
import encoding.BlockException;
import logicface.LogicFace;
import logicface.LogicFaceException;
import packet.CPacket;
import packet.PacketException;
public class SendTask implements Runnable{
private ConcurrentLinkedQueue<CPacket> readTunCPackets;
@@ -52,6 +56,14 @@ public class SendTask implements Runnable{
try {
// face.sendCPacket(cPacket);
face.sendQuickCPacketV3(cPacket.getRawData());
// todo; 测试!!!
// try {
// CPacket hiPacket=TLVDecoderHelper.getCPacketFromBytes(cPacket.getRawData());
// System.out.println("测试神奇的外访!!(源):"+hiPacket.getSrcIdentifier().toUri());
// System.out.println("测试神奇的外访!!(目的):"+hiPacket.getDstIdentifier().toUri());
// } catch (BlockException | PacketException | ComponentException e) {
// e.printStackTrace();
// }
}catch (LogicFaceException e){
e.printStackTrace();
System.out.println("error: face发包出现问题,请及时修复(inner)!!!");
@@ -270,6 +270,9 @@ public class VpnExtranetPreparation implements VpnPreparationInterface{
// 3. 发送兴趣包到服务器,接收服务器发回来的数据包
String handshakeResponse;
try {
// todo:测试!!
// cPacket.encodeSelf();
// System.out.println("测试哇 cpacket bytes: "+ Arrays.toString(cPacket.getRawData()));
face.sendCPacket(cPacket);
CPacket data=face.receiveCPacket(10000);
ByteBuffer respondBuf = ByteBuffer.allocate(1024);
@@ -30,7 +30,7 @@ public class StringUtilForCPacketEncoding {
// 将获得的获得随机数转化为字符串
String fixLenthString = String.valueOf(pross);
// 返回固定的长度的随机数
return fixLenthString.substring(1, strLength + 1);
return fixLenthString.substring(2, strLength + 2);
}
//————————————————
// 版权声明:本文为CSDN博主「鸿鹰」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
@@ -8,6 +8,7 @@ package com.pkusz.min_vpn_client.utils;
*/
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import encoding.TLV;
import encoding.TLVException;
@@ -0,0 +1,29 @@
package com.pkusz.min_vpn_client.utils;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 17:06 2021/12/29
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
import encoding.Block;
import encoding.BlockException;
import packet.CPacket;
import packet.PacketException;
public class TLVDecoderHelper {
public static CPacket getCPacketFromBytes(byte[] rawbytes) throws BlockException, PacketException {
Block block=new Block(rawbytes,true);
if(!block.isValid()){
System.out.println("buf invalid");
return null;
}
CPacket cPacket=new CPacket();
if(!cPacket.wireDecode(block)){
System.out.println("parse to CPacket error");
return null;
}
return cPacket;
}
}