mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
update Packet method: doDataField & add lf: LogicFace
This commit is contained in:
1 parent
7a3bbbc1a8
commit
0dc6bb3165
5 files changed
+305
-73
No files matched your search
@@ -1,7 +1,9 @@
|
||||
package logicface;
|
||||
|
||||
import component.Identifier;
|
||||
import packet.MINPacket;
|
||||
import encoding.TLV;
|
||||
import encoding.VlIntException;
|
||||
import packet.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
@@ -72,9 +74,130 @@ public class LogicFace {
|
||||
* 从 LogicFace 中接收一个网络包
|
||||
* @return 多标识网络包
|
||||
*/
|
||||
public MINPacket ReceivePacket() throws LogicFaceException {
|
||||
public MINPacket receivePacket() throws LogicFaceException {
|
||||
return this.linkService.receivePacket();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从 LogicFace 中接收一个普通推送式网络包, 如果收到的包不是普通推送式网络包,则这个包会被忽略
|
||||
* @return
|
||||
* @throws LogicFaceException
|
||||
*/
|
||||
public CPacket receiveCPacket() throws LogicFaceException {
|
||||
try {
|
||||
while (true){
|
||||
MINPacket minPacket=this.receivePacket();
|
||||
int packetType=minPacket.packetType.getVlIntValue2Int();
|
||||
if(packetType == TLV.TlvIdentifierCommon){
|
||||
CPacket cPacket=new CPacket().createCPacketByMINPacket(minPacket);
|
||||
return cPacket;
|
||||
}
|
||||
}
|
||||
} catch (VlIntException | PacketException e) {
|
||||
throw new LogicFaceException("LogicFace.receiveCPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 LogicFace 中接收一个普通推送式网络包, 如果收到的包不是普通推送式网络包,则这个包会被忽略
|
||||
* @return
|
||||
* @throws LogicFaceException
|
||||
*/
|
||||
public Interest receiveInterest() throws LogicFaceException {
|
||||
try {
|
||||
while (true){
|
||||
MINPacket minPacket=this.receivePacket();
|
||||
int packetType=minPacket.packetType.getVlIntValue2Int();
|
||||
if(packetType == TLV.TlvIdentifierContentInterest){
|
||||
Interest interest=new Interest().createInterestByMINPacket(minPacket);
|
||||
return interest;
|
||||
}
|
||||
}
|
||||
} catch (VlIntException | PacketException e) {
|
||||
throw new LogicFaceException("LogicFace.receiveInterest: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 LogicFace 中接收一个数据包, 如果收到的包不是数据包,则这个包会被忽略
|
||||
* @return
|
||||
*/
|
||||
public Data receiveData() throws LogicFaceException {
|
||||
try {
|
||||
while (true){
|
||||
MINPacket minPacket=this.receivePacket();
|
||||
int packetType=minPacket.packetType.getVlIntValue2Int();
|
||||
if(packetType == TLV.TlvIdentifierContentData){
|
||||
Data data=new Data().createDataByMINPacket(minPacket);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
} catch (VlIntException | PacketException e) {
|
||||
throw new LogicFaceException("LogicFace.receiveData: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个MIN包
|
||||
* @param minPacket
|
||||
* @return
|
||||
*/
|
||||
public boolean sendPacket(MINPacket minPacket) throws LogicFaceException {
|
||||
return this.linkService.sendMINPacket(minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个普通推送式网络包
|
||||
* @param cPacket
|
||||
* @return
|
||||
*/
|
||||
public boolean sendCPacket(CPacket cPacket) throws LogicFaceException {
|
||||
return this.linkService.sendCPacket(cPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个兴趣包
|
||||
* @param interest
|
||||
* @return
|
||||
* @throws LogicFaceException
|
||||
*/
|
||||
public boolean sendInterest(Interest interest) throws LogicFaceException {
|
||||
return this.linkService.sendInterest(interest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一个数据包
|
||||
* @return
|
||||
*/
|
||||
public boolean sendData(Data data) throws LogicFaceException {
|
||||
return this.linkService.sendData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭当前 LogicFace
|
||||
* @return
|
||||
*/
|
||||
public boolean shutDown(){
|
||||
if(this.state){
|
||||
this.transport.close();
|
||||
this.state=false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得本地地址
|
||||
* @return
|
||||
*/
|
||||
public String getLocalUri(){
|
||||
return this.transport.getLocalUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得对端地址
|
||||
* @return
|
||||
*/
|
||||
public String getRemoteUri(){
|
||||
return this.transport.getRemoteUri();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package packet;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Packet;
|
||||
import component.*;
|
||||
import encoding.*;
|
||||
|
||||
@@ -51,6 +52,18 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
this.ttl=ttl;
|
||||
}
|
||||
|
||||
public CPacket createCPacketByMINPacket(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
CPacket cPacket=new CPacket();
|
||||
if(!cPacket.doExtraDataFromFields(minPacket)){
|
||||
return null;
|
||||
}
|
||||
return cPacket;
|
||||
} catch (PacketException e) {
|
||||
throw new PacketException("CPacket.createCPacketByMINPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取源标识
|
||||
* @return
|
||||
@@ -123,48 +136,45 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 CPacket 的各项属性填充到 MINPacket 中定义的对应分区当中
|
||||
* 将 CPacket 的各项属性填充到目标 MINPacket 中定义的对应分区当中
|
||||
*
|
||||
* @return
|
||||
* @Description: // 1. 主要填充标识区、只读区和可变区
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
public boolean doFillDataToFields(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
// 可变区 => 受保护区(无)
|
||||
|
||||
// 填充可变区 => 非受保护区
|
||||
// 首先清除所有的Block
|
||||
this.minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
Block block = new SelfEncodingBase().selfWireEncode(this.ttl);
|
||||
if (block == null) {
|
||||
System.out.println("err 1");
|
||||
return false;
|
||||
}
|
||||
this.minPacket.mutableField.mutableDangerousField.addBlock(block);
|
||||
minPacket.mutableField.mutableDangerousField.addBlock(block);
|
||||
|
||||
// 填充只读区
|
||||
// 首先清除所有的Block
|
||||
this.minPacket.readOnlyField.clearBlocks();
|
||||
minPacket.readOnlyField.clearBlocks();
|
||||
block = new SelfEncodingBase().selfWireEncode(this.payload);
|
||||
if (block == null) {
|
||||
System.out.println("err 2");
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
|
||||
// 填充标识区
|
||||
// 首先清除所有的标识
|
||||
if((this.srcIdentifier==null)||(this.dstIdentifier==null)){
|
||||
throw new PacketException("CPacket.fillDataToFields: SrcIdentifier or DstIdentifier is null.");
|
||||
}
|
||||
this.minPacket.identifierField.clearIdentifiers();
|
||||
minPacket.identifierField.clearIdentifiers();
|
||||
IdentifierWrapper srcIdentifierWrapper =
|
||||
new IdentifierWrapper(new VlInt(TLV.TlvIdentifierCommon),this.srcIdentifier);
|
||||
IdentifierWrapper dstIdentifierWrapper =
|
||||
new IdentifierWrapper(new VlInt(TLV.TlvIdentifierCommon),this.dstIdentifier);
|
||||
this.minPacket.identifierField.addIdentifier(srcIdentifierWrapper);
|
||||
this.minPacket.identifierField.addIdentifier(dstIdentifierWrapper);
|
||||
minPacket.identifierField.addIdentifier(srcIdentifierWrapper);
|
||||
minPacket.identifierField.addIdentifier(dstIdentifierWrapper);
|
||||
|
||||
return true;
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
@@ -173,15 +183,23 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区当中提取出 CPacket 的各项属性
|
||||
* 将 CPacket 的各项属性填充到 MINPacket 中定义的对应分区当中
|
||||
* @return
|
||||
* @throws PacketException
|
||||
*/
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
return this.doFillDataToFields(this.minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从指定的 MINPacket 的分区当中提取出 CPacket 的各项属性
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
public boolean doExtraDataFromFields(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
// 提取 Payload
|
||||
Block payloadBlock = this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload));
|
||||
Block payloadBlock = minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload));
|
||||
if (payloadBlock == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -190,7 +208,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
|
||||
// 提取 TTL
|
||||
Block ttlBlock = this.minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
|
||||
Block ttlBlock = minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
|
||||
if (ttlBlock == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -199,11 +217,11 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
|
||||
// 提取标识
|
||||
IdentifierWrapper srcIdentifierWrapper = this.minPacket.identifierField.getIdentifier(0);
|
||||
IdentifierWrapper srcIdentifierWrapper = minPacket.identifierField.getIdentifier(0);
|
||||
if (srcIdentifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
IdentifierWrapper dstIdentifierWrapper = this.minPacket.identifierField.getIdentifier(1);
|
||||
IdentifierWrapper dstIdentifierWrapper = minPacket.identifierField.getIdentifier(1);
|
||||
if (dstIdentifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -216,6 +234,15 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区当中提取出 CPacket 的各项属性
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
return this.doExtraDataFromFields(this.minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 CPacket 编码成 TLV
|
||||
*
|
||||
|
||||
@@ -33,23 +33,40 @@ import encoding.*;
|
||||
// }
|
||||
//
|
||||
public class Data implements IEncodingAble, InteractWithField {
|
||||
public MINPacket minPacket=new MINPacket();
|
||||
public FreshnessPeriod freshnessPeriod=new FreshnessPeriod();
|
||||
public Payload payload=new Payload();
|
||||
public CongestionMark congestionMark=new CongestionMark();
|
||||
public NackHeader nackHeader=new NackHeader();
|
||||
public Identifier name=new Identifier();
|
||||
public MINPacket minPacket = new MINPacket();
|
||||
public FreshnessPeriod freshnessPeriod = new FreshnessPeriod();
|
||||
public Payload payload = new Payload();
|
||||
public CongestionMark congestionMark = new CongestionMark();
|
||||
public NackHeader nackHeader = new NackHeader();
|
||||
public Identifier name = new Identifier();
|
||||
|
||||
public Data(){
|
||||
public Data() {
|
||||
}
|
||||
|
||||
public Data(Identifier name,Payload payload,FreshnessPeriod freshnessPeriod,
|
||||
CongestionMark congestionMark,NackHeader nackHeader){
|
||||
this.name=name;
|
||||
this.payload=payload;
|
||||
this.freshnessPeriod=freshnessPeriod;
|
||||
this.congestionMark=congestionMark;
|
||||
this.nackHeader=nackHeader;
|
||||
public Data(Identifier name, Payload payload, FreshnessPeriod freshnessPeriod,
|
||||
CongestionMark congestionMark, NackHeader nackHeader) {
|
||||
this.name = name;
|
||||
this.payload = payload;
|
||||
this.freshnessPeriod = freshnessPeriod;
|
||||
this.congestionMark = congestionMark;
|
||||
this.nackHeader = nackHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个 MINPacket 创建一个 Data
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Data createDataByMINPacket(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
Data data = new Data();
|
||||
if (!data.doExtraDataFromFields(minPacket)) {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
} catch (PacketException e) {
|
||||
throw new PacketException("Data.createDataByMINPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +99,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
public boolean doFillDataToFields(MINPacket minPacket) throws PacketException {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充可变区
|
||||
// { => 可变区
|
||||
@@ -97,14 +113,14 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
/////////////////////////////////////////////////////////////\
|
||||
try {
|
||||
// 填充可变受保护区
|
||||
this.minPacket.mutableField.mutableProtectField.clearBlocks();
|
||||
minPacket.mutableField.mutableProtectField.clearBlocks();
|
||||
|
||||
// CongestionMark
|
||||
Block block = new SelfEncodingBase().selfWireEncode(this.congestionMark);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.mutableField.mutableProtectField.addBlock(block);
|
||||
minPacket.mutableField.mutableProtectField.addBlock(block);
|
||||
|
||||
// 填充可变非受保护区(无)
|
||||
|
||||
@@ -116,7 +132,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
// <Payload>
|
||||
// }
|
||||
/////////////////////////////////////////////////////////////
|
||||
this.minPacket.readOnlyField.clearBlocks();
|
||||
minPacket.readOnlyField.clearBlocks();
|
||||
|
||||
// FreshnessPeriod
|
||||
if (this.freshnessPeriod.isInitial()) {
|
||||
@@ -124,7 +140,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// NackHeader
|
||||
@@ -133,7 +149,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// Payload
|
||||
@@ -141,18 +157,18 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充标识区
|
||||
/////////////////////////////////////////////////////////////
|
||||
this.minPacket.identifierField.clearIdentifiers();
|
||||
minPacket.identifierField.clearIdentifiers();
|
||||
IdentifierWrapper identifierWrapper =
|
||||
new IdentifierWrapper().createContentInterestIdentifierByComponents(this.name.getComponents());
|
||||
if (identifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.identifierField.addIdentifier(identifierWrapper);
|
||||
minPacket.identifierField.addIdentifier(identifierWrapper);
|
||||
return true;
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("Data.fillDataToFields: " + e.getMessage());
|
||||
@@ -160,12 +176,21 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区中提取出 Data 的各项属性
|
||||
* 将 Data 的各项属性填充到 MINPacket 中定义的对应分区当中
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
return this.doFillDataToFields(this.minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区中提取出 Data 的各项属性
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean doExtraDataFromFields(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 解析可变区
|
||||
@@ -178,7 +203,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
// }
|
||||
// }
|
||||
/////////////////////////////////////////////////////////////
|
||||
Block block = this.minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
|
||||
Block block = minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
|
||||
if (block != null) {
|
||||
if (!this.congestionMark.wireDecode(block)) {
|
||||
return false;
|
||||
@@ -192,7 +217,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
// <Payload>
|
||||
// }
|
||||
/////////////////////////////////////////////////////////////
|
||||
ElementContainer elementContainer = this.minPacket.readOnlyField.getBlocks();
|
||||
ElementContainer elementContainer = minPacket.readOnlyField.getBlocks();
|
||||
int len = elementContainer.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Block newblock = elementContainer.getBlock(i);
|
||||
@@ -218,7 +243,7 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
//// 解析标识区
|
||||
/////////////////////////////////////////////////////////////
|
||||
IdentifierWrapper interestIdentifierWrapper =
|
||||
this.minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierContentInterest));
|
||||
minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierContentInterest));
|
||||
if (interestIdentifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -230,6 +255,17 @@ public class Data implements IEncodingAble, InteractWithField {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区中提取出 Data 的各项属性
|
||||
*
|
||||
* @return
|
||||
* @throws PacketException
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
return this.doExtraDataFromFields(this.minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Data 线速编码为一个 TLV
|
||||
*
|
||||
|
||||
@@ -68,6 +68,23 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
this.ttl=ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个 MINPacket 创建一个 Interest
|
||||
* @param minPacket
|
||||
* @return
|
||||
*/
|
||||
public Interest createInterestByMINPacket(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
Interest interest = new Interest();
|
||||
if (!interest.doExtraDataFromFields(minPacket)) {
|
||||
return null;
|
||||
}
|
||||
return interest;
|
||||
} catch (PacketException e) {
|
||||
throw new PacketException("Interest.createInterestByMINPacket: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容兴趣包的名字
|
||||
*
|
||||
@@ -130,36 +147,35 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
public boolean doFillDataToFields(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充可变区
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
// 填充可变受保护区
|
||||
this.minPacket.mutableField.mutableProtectField.clearBlocks();
|
||||
minPacket.mutableField.mutableProtectField.clearBlocks();
|
||||
|
||||
// CongestionMark
|
||||
Block block = new SelfEncodingBase().selfWireEncode(this.congestionMark);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.mutableField.mutableProtectField.addBlock(block);
|
||||
minPacket.mutableField.mutableProtectField.addBlock(block);
|
||||
|
||||
// 填充可变非受保护区(无)
|
||||
this.minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
// ttl
|
||||
block = new SelfEncodingBase().selfWireEncode(this.ttl);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.mutableField.mutableDangerousField.addBlock(block);
|
||||
minPacket.mutableField.mutableDangerousField.addBlock(block);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充只读区
|
||||
/////////////////////////////////////////////////////////////
|
||||
this.minPacket.readOnlyField.clearBlocks();
|
||||
minPacket.readOnlyField.clearBlocks();
|
||||
|
||||
// CanBePrefix
|
||||
if (this.canBePrefix.getCanBePrefix()) {
|
||||
@@ -167,7 +183,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// MustBeRefresh
|
||||
@@ -176,7 +192,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// InterestLifeTime
|
||||
@@ -188,7 +204,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
|
||||
// Nonce
|
||||
if (!this.nonce.isInitial()) {
|
||||
@@ -199,7 +215,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
|
||||
// HopLimit
|
||||
if (this.hopLimit.isInitial()) {
|
||||
@@ -207,7 +223,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// NackHeader
|
||||
@@ -216,7 +232,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
}
|
||||
|
||||
// Payload
|
||||
@@ -224,18 +240,18 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.readOnlyField.addBlock(block);
|
||||
minPacket.readOnlyField.addBlock(block);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充标识区
|
||||
/////////////////////////////////////////////////////////////
|
||||
this.minPacket.identifierField.clearIdentifiers();
|
||||
minPacket.identifierField.clearIdentifiers();
|
||||
IdentifierWrapper identifierWrapper =
|
||||
new IdentifierWrapper().createContentInterestIdentifierByComponents(this.name.getComponents());
|
||||
if (identifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
this.minPacket.identifierField.addIdentifier(identifierWrapper);
|
||||
minPacket.identifierField.addIdentifier(identifierWrapper);
|
||||
|
||||
return true;
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
@@ -243,13 +259,22 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Interest 的各项属性填充到 MINPacket 中定义的对应分区当中
|
||||
* @return
|
||||
* @throws PacketException
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
return this.doFillDataToFields(this.minPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区中提取出 Interest 的各项属性
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
public boolean doExtraDataFromFields(MINPacket minPacket) throws PacketException {
|
||||
try {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 解析可变区
|
||||
@@ -262,13 +287,13 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
// }
|
||||
// }
|
||||
/////////////////////////////////////////////////////////////
|
||||
Block block = this.minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
|
||||
Block block = minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
|
||||
if (block != null) {
|
||||
if (!this.congestionMark.wireDecode(block)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
block=this.minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
|
||||
block=minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
|
||||
if (block != null) {
|
||||
if (!this.ttl.wireDecode(block)) {
|
||||
return false;
|
||||
@@ -286,7 +311,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
// <Payload>
|
||||
// }
|
||||
/////////////////////////////////////////////////////////////
|
||||
ElementContainer elementContainer = this.minPacket.readOnlyField.getBlocks();
|
||||
ElementContainer elementContainer = minPacket.readOnlyField.getBlocks();
|
||||
int len = elementContainer.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Block newblock = elementContainer.getBlock(i);
|
||||
@@ -339,7 +364,7 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
//// 解析标识区
|
||||
/////////////////////////////////////////////////////////////
|
||||
IdentifierWrapper interestIdentifierWrapper =
|
||||
this.minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierContentInterest));
|
||||
minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierContentInterest));
|
||||
if (interestIdentifierWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -351,6 +376,16 @@ public class Interest implements InteractWithField, IEncodingAble {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区中提取出 Interest 的各项属性
|
||||
* @return
|
||||
* @throws PacketException
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
return this.doExtraDataFromFields(this.minPacket);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将 Interest 线速编码为一个 TLV
|
||||
|
||||
@@ -40,6 +40,17 @@ public class Nack implements IEncodingAble {
|
||||
this.setNackReason(reason);
|
||||
}
|
||||
|
||||
public Nack createNackByInterest(Interest interest){
|
||||
if(!interest.nackHeader.isInitial()){
|
||||
// NackHeader 没有初始化
|
||||
return null;
|
||||
}
|
||||
Nack nack=new Nack();
|
||||
nack.interest=interest;
|
||||
nack.setNackReason(interest.nackHeader.getNackReason());
|
||||
return nack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Nack 的原因
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user