mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
fixed error handle
This commit is contained in:
1 parent
7bf0906291
commit
adf834a4e9
10 files changed
+31
-67
No files matched your search
@@ -193,11 +193,7 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
|
||||
// 编码 TLV-VALUE
|
||||
for (int i = 0; i < components.length(); i++) {
|
||||
int tmpLen= 0;
|
||||
try {
|
||||
tmpLen = components.getElement(i).wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("Identifier.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmpLen = components.getElement(i).wireEncode(encoder);
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -149,11 +149,7 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for (int i = this.identifiers.length()-1; i >= 0; i--) {
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = this.identifiers.getElement(i).wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("IdentifierField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmplen = this.identifiers.getElement(i).wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,7 @@ public class MutableField implements TlvComponentBase,IEncodingAble {
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
try {
|
||||
tmplen=this.mutableProtectField.wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmplen=this.mutableProtectField.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -113,20 +113,12 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
for(int i=signatures.length()-1;i>=0;i--){
|
||||
Signature newSignature=signatures.getElement(i);
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = newSignature.getSigValue().wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmplen = newSignature.getSigValue().wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
try {
|
||||
tmplen=newSignature.getSigInfo().wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmplen=newSignature.getSigInfo().wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -192,16 +184,12 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
for (int i = 0; i < subElementNum; i+=2) {
|
||||
// 第奇数个子 TLV 解析为 SignatureInfo
|
||||
SignatureInfo signatureInfo= null;
|
||||
try {
|
||||
signatureInfo = new SignatureInfo(subElements.getBlock(i));
|
||||
// 第偶数个子 TLV 解析为 SignatureValue
|
||||
SignatureValue signatureValue=new SignatureValue(subElements.getBlock(i+1));
|
||||
// 构造Signature
|
||||
Signature signature=new Signature(signatureInfo,signatureValue);
|
||||
signatureContainer.addElement(signature);
|
||||
} catch (VlIntException e) {
|
||||
throw new ComponentException("SignatureField.wireDecode: "+e.getMessage());
|
||||
}
|
||||
signatureInfo = new SignatureInfo(subElements.getBlock(i));
|
||||
// 第偶数个子 TLV 解析为 SignatureValue
|
||||
SignatureValue signatureValue=new SignatureValue(subElements.getBlock(i+1));
|
||||
// 构造Signature
|
||||
Signature signature=new Signature(signatureInfo,signatureValue);
|
||||
signatureContainer.addElement(signature);
|
||||
}
|
||||
// 赋值
|
||||
signatures.clear();
|
||||
|
||||
@@ -117,11 +117,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = this.signatureType.wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureInfo.wireEncode: "+e.getMessage());
|
||||
}
|
||||
tmplen = this.signatureType.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -185,12 +181,8 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
}
|
||||
switch (type){
|
||||
case TLV.TlvSignatureType:
|
||||
try {
|
||||
if(!this.signatureType.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
} catch (VlIntException e) {
|
||||
throw new ComponentException("SignatureInfo.wireDecode: "+e.getMessage());
|
||||
if(!this.signatureType.wireDecode(cacheBlock)){
|
||||
return false;
|
||||
}
|
||||
findSignatureType=true;
|
||||
case TLV.TlvKeyLocator:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package encoding;
|
||||
|
||||
import component.CanBePrefix;
|
||||
import component.ComponentException;
|
||||
import packet.PacketException;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
@@ -44,7 +46,7 @@ public class SelfEncodingBase {
|
||||
* @param iEncodingAble
|
||||
* @return
|
||||
*/
|
||||
public Block selfWireEncode(IEncodingAble iEncodingAble) throws EncoderException, BlockException {
|
||||
public Block selfWireEncode(IEncodingAble iEncodingAble) throws EncoderException, BlockException, ComponentException, PacketException {
|
||||
// this.setiEncodingAble(iEncodingAble);
|
||||
if((this.rawBlock!=null)&&this.rawBlock.isValid()){
|
||||
return this.rawBlock;
|
||||
@@ -64,7 +66,7 @@ public class SelfEncodingBase {
|
||||
* @param iEncodingAble
|
||||
* @return
|
||||
*/
|
||||
private Block easyEncoder(IEncodingAble iEncodingAble) throws EncoderException, BlockException {
|
||||
private Block easyEncoder(IEncodingAble iEncodingAble) throws PacketException, ComponentException, EncoderException, BlockException {
|
||||
Encoder encoder=new Encoder();
|
||||
|
||||
// 首先测量目标 TLV 的大小
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
Block block= null;
|
||||
try {
|
||||
block = new SelfEncodingBase().selfWireEncode(this.ttl);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("CPacket.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
@@ -74,7 +74,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
this.minPacket.readOnlyField.clearBlocks();
|
||||
try {
|
||||
block=new SelfEncodingBase().selfWireEncode(this.payload);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("CPacket.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
@@ -151,11 +151,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
// 指定包类型
|
||||
this.minPacket.packetType=new VlInt(TLV.TlvPacketMINCommon);
|
||||
|
||||
try {
|
||||
return this.minPacket.wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new PacketException("CPacket.wireEncode: "+e.getMessage());
|
||||
}
|
||||
return this.minPacket.wireEncode(encoder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,12 +161,8 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws PacketException {
|
||||
try {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
} catch (VlIntException e) {
|
||||
throw new PacketException("CPacket.wireDecode: "+e.getMessage());
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
return this.extraDataFromFields();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
Block block= null;
|
||||
try {
|
||||
block = new SelfEncodingBase().selfWireEncode(this.congestionMark);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
@@ -111,7 +111,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
if(this.freshnessPeriod.isInitial()){
|
||||
try {
|
||||
block=new SelfEncodingBase().selfWireEncode(this.freshnessPeriod);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
@@ -124,7 +124,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
if(this.nackHeader.isInitial()){
|
||||
try {
|
||||
block=new SelfEncodingBase().selfWireEncode(this.nackHeader);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
@@ -136,7 +136,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
// Payload
|
||||
try {
|
||||
block=new SelfEncodingBase().selfWireEncode(this.payload);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
} catch (EncoderException | BlockException | ComponentException e) {
|
||||
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Interest implements InteractWithField,IEncodingAble{
|
||||
|
||||
|
||||
return true;
|
||||
}catch (EncoderException | BlockException e){
|
||||
}catch (EncoderException | BlockException | ComponentException e){
|
||||
throw new PacketException("Interest.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package others;
|
||||
|
||||
import component.CanBePrefix;
|
||||
import component.ComponentException;
|
||||
import encoding.Block;
|
||||
import encoding.BlockException;
|
||||
import encoding.EncoderException;
|
||||
import encoding.SelfEncodingBase;
|
||||
import packet.PacketException;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
@@ -14,7 +16,7 @@ import encoding.SelfEncodingBase;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestCallBack {
|
||||
public static void main(String[] args) throws EncoderException, BlockException {
|
||||
public static void main(String[] args) throws EncoderException, BlockException, PacketException, ComponentException {
|
||||
CanBePrefix canBePrefix=new CanBePrefix();
|
||||
Block block=new SelfEncodingBase().selfWireEncode(canBePrefix);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user