|
|
|
@ -10,6 +10,7 @@ import remoteException.NotFound;
|
|
|
|
|
import remoteException.ProtocolRemoteError;
|
|
|
|
|
import remoteException.VersionRemoteError;
|
|
|
|
|
import remoteException.EmptyFile;
|
|
|
|
|
import tools.BytesArrayTools;
|
|
|
|
|
import protocolP2P.Payload;
|
|
|
|
|
import protocolP2P.RequestResponseCode;
|
|
|
|
|
import protocolP2P.LoadRequest;
|
|
|
|
@ -243,7 +244,7 @@ public class ProtocolP2PDatagram {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int computeCheckSum(byte [] datagram){
|
|
|
|
|
int checksum;
|
|
|
|
|
int checksum = 0;
|
|
|
|
|
for (int i=CHECKSUM_POSITION+2; i<datagram.length; ++i){
|
|
|
|
|
checksum += BytesArrayTools.readInt16Bits(datagram,i);
|
|
|
|
|
checksum &= 0xffff;
|
|
|
|
@ -251,16 +252,20 @@ public class ProtocolP2PDatagram {
|
|
|
|
|
return checksum ^ 0xffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setCheckSum(byte [] datagram){
|
|
|
|
|
private void setCheckSum(byte [] datagram) throws InternalError{
|
|
|
|
|
int checksum = computeCheckSum(datagram);
|
|
|
|
|
try{
|
|
|
|
|
BytesArrayTools.write16Bits(datagram,CHECKSUM_POSITION,checksum);
|
|
|
|
|
} catch (SizeError e) {
|
|
|
|
|
throw new InternalError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkCheckSum(byte [] datagram) throws TransmissionError{
|
|
|
|
|
int checksum = BytesArrayTools.readInt16Bits(datagram,CHECKSUM_POSITION);
|
|
|
|
|
int computedCheckSum = computeCheckSum(datagram);
|
|
|
|
|
if (computedCheckSum != checksum){
|
|
|
|
|
throws new TransmissionError();
|
|
|
|
|
throw new TransmissionError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|