|
|
@ -243,9 +243,9 @@ public class ProtocolP2PDatagram {
|
|
|
|
this.hostR = hostR;
|
|
|
|
this.hostR = hostR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int computeCheckSum(byte [] datagram){
|
|
|
|
private int computeCheckSum(byte [] datagram) throws SizeError {
|
|
|
|
int checksum = 0;
|
|
|
|
int checksum = 0;
|
|
|
|
for (int i=CHECKSUM_POSITION+2; i<datagram.length; ++i){
|
|
|
|
for (int i=CHECKSUM_POSITION+2; i<CHECKSUM_POSITION+2+4+Payload.getPayloadSize(datagram); ++i){
|
|
|
|
checksum += BytesArrayTools.readInt16Bits(datagram,i);
|
|
|
|
checksum += BytesArrayTools.readInt16Bits(datagram,i);
|
|
|
|
checksum &= 0xffff;
|
|
|
|
checksum &= 0xffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -253,8 +253,8 @@ public class ProtocolP2PDatagram {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setCheckSum(byte [] datagram) throws InternalError {
|
|
|
|
private void setCheckSum(byte [] datagram) throws InternalError {
|
|
|
|
int checksum = computeCheckSum(datagram);
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
int checksum = computeCheckSum(datagram);
|
|
|
|
BytesArrayTools.write16Bits(datagram,CHECKSUM_POSITION,checksum);
|
|
|
|
BytesArrayTools.write16Bits(datagram,CHECKSUM_POSITION,checksum);
|
|
|
|
} catch (SizeError e) {
|
|
|
|
} catch (SizeError e) {
|
|
|
|
throw new InternalError();
|
|
|
|
throw new InternalError();
|
|
|
@ -262,10 +262,14 @@ public class ProtocolP2PDatagram {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkCheckSum(byte [] datagram) throws TransmissionError {
|
|
|
|
private void checkCheckSum(byte [] datagram) throws TransmissionError {
|
|
|
|
|
|
|
|
try {
|
|
|
|
int checksum = BytesArrayTools.readInt16Bits(datagram,CHECKSUM_POSITION);
|
|
|
|
int checksum = BytesArrayTools.readInt16Bits(datagram,CHECKSUM_POSITION);
|
|
|
|
int computedCheckSum = computeCheckSum(datagram);
|
|
|
|
int computedCheckSum = computeCheckSum(datagram);
|
|
|
|
if (computedCheckSum != checksum){
|
|
|
|
if (computedCheckSum != checksum){
|
|
|
|
throw new TransmissionError();
|
|
|
|
throw new TransmissionError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(SizeError e) {
|
|
|
|
|
|
|
|
throw new TransmissionError();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|