From 1e979a5fc1ba1c8e21c7d06920e4a659161ea897 Mon Sep 17 00:00:00 2001 From: js Date: Mon, 3 Feb 2020 15:19:45 +0100 Subject: [PATCH] add doc to checksum --- src/protocolP2P/ProtocolP2PDatagram.java | 25 +++++++++++++++++++++++- src/tools/BytesArrayTools.java | 4 ++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/protocolP2P/ProtocolP2PDatagram.java b/src/protocolP2P/ProtocolP2PDatagram.java index 079c0fd..cf2a02d 100644 --- a/src/protocolP2P/ProtocolP2PDatagram.java +++ b/src/protocolP2P/ProtocolP2PDatagram.java @@ -243,15 +243,33 @@ public class ProtocolP2PDatagram { this.hostR = hostR; } + /** Used to compute Checksum of a specific datagram + * @param datagram full datagram + * @return checksum + * @throws SizeError + */ + private int computeCheckSum(byte [] datagram) throws SizeError { + /* + * The checksum field is the 16 bit one’s complement of the one’s complement sum of all 16-bit words + * in the header and text. If a segment contains an odd number of header and text octets to be checksummed, + * the last octet is padded on the right with zeros to form a 16-bit word for checksum purposes. + * The pad is not transmitted as part of the segment. While computing the checksum, the checksum field + * itself is replaced with zeros. + */ int checksum = 0; - for (int i=CHECKSUM_POSITION+2; i