mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 06:00:25 +08:00
add logicface: Transport
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import packet.Data;
|
||||
import packet.Interest;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import packet.Interest;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import packet.Interest;
|
||||
import packet.Nack;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import component.Identifier;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import component.Identifier;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package logicface;
|
||||
package logicface.CallbackInterface;
|
||||
|
||||
import packet.Interest;
|
||||
|
||||
@@ -5,6 +5,7 @@ import component.Identifier;
|
||||
import component.IdentifierWrapper;
|
||||
import encoding.TLV;
|
||||
import encoding.VlIntException;
|
||||
import logicface.CallbackInterface.*;
|
||||
import packet.*;
|
||||
import util.ConcurrentHelper;
|
||||
import util.TimeHelper;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package logicface;
|
||||
|
||||
import logicface.CallbackInterface.OnDataInterface;
|
||||
import logicface.CallbackInterface.OnNackInterface;
|
||||
import logicface.CallbackInterface.OnTimeoutInterface;
|
||||
import packet.Interest;
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package logicface;
|
||||
|
||||
import encoding.*;
|
||||
import packet.LpPacket;
|
||||
import packet.PacketException;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 19:22 2021/4/15
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Transport {
|
||||
public String localAddr;
|
||||
public String remoteAddr;
|
||||
public String localUri;
|
||||
public String remoteUri;
|
||||
|
||||
public LinkService linkService;
|
||||
// TODO 虽然第一个版本可能用不到linkService分包与合包功能,
|
||||
// 但以后可能需要客户端也能直接发出用以太网封装的MIN网络包,所以还是留着linkService
|
||||
|
||||
public void close(){
|
||||
throw new Error("implement me");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从[]byte中解析出LpPacket
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
public LpPacket parseByteArray2LpPacket(byte[] buf) throws LogicFaceException {
|
||||
try {
|
||||
Block block=new Block(buf,true);
|
||||
if(block.isValid()){
|
||||
return null;
|
||||
}
|
||||
LpPacket lpPacket=new LpPacket();
|
||||
if(!lpPacket.wireDecode(block)){
|
||||
return null;
|
||||
}
|
||||
return lpPacket;
|
||||
} catch (BlockException | PacketException e) {
|
||||
throw new LogicFaceException("Transport.parseByteArray2LpPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将lpPacket编码成byte数组
|
||||
* @param lpPacket
|
||||
* @return
|
||||
*/
|
||||
public byte[] encodeLpPacket2ByteArray(LpPacket lpPacket) throws LogicFaceException {
|
||||
try {
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
int encodeBufLen=lpPacket.wireEncode(encoder);
|
||||
if(encodeBufLen<0){
|
||||
return null;
|
||||
}
|
||||
byte[] encodeBuf=encoder.getBuffer();
|
||||
if(encodeBuf==null){
|
||||
return null;
|
||||
}
|
||||
return encodeBuf;
|
||||
} catch (EncoderException | PacketException e) {
|
||||
throw new LogicFaceException("Transport.encodeLpPacket2ByteArray: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String getRemoteUri(){
|
||||
return this.remoteUri;
|
||||
}
|
||||
|
||||
public String getLocalUri(){
|
||||
return this.localUri;
|
||||
}
|
||||
|
||||
public String getRemoteAddr(){
|
||||
return this.remoteAddr;
|
||||
}
|
||||
|
||||
public String getLocalAddr(){
|
||||
return this.localAddr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user