Fix off by 1 lengths; fix debug color

pull/86/head
Louis Royer 4 years ago
parent d6fbfa6683
commit d9c4c8ba40

@ -50,8 +50,8 @@ public class DiscoverRequest extends Payload {
*/
protected byte[] toPacket() throws InternalError {
// compute total size
int size = PAYLOAD_START_POSITION + filename.length();
byte[] packet = new byte[size + 1]; // java initialize all to zero
int size = 1 + PAYLOAD_START_POSITION + filename.length();
byte[] packet = new byte[size]; // java initialize all to zero
// set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;
// set Payload size

@ -74,8 +74,8 @@ public class DiscoverResponse extends Payload {
hostListSize += (2 + hostItem.getHostname().length() + 1);
}
// compute total size
int size = FILENAME_POSITION + filename.length() + hostListSize;
byte[] packet = new byte[size + 1]; // java initialize all to zero
int size = 1 + FILENAME_POSITION + filename.length() + hostListSize;
byte[] packet = new byte[size]; // java initialize all to zero
// set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;
// set Payload size

@ -77,7 +77,7 @@ public class FilePart extends Payload {
protected byte[] toPacket() throws InternalError {
// compute total size
int size = FILENAME_POSITION + filename.length() + partialContent.length;
byte[] packet = new byte[size + 1]; // java initialize all to zero
byte[] packet = new byte[size]; // java initialize all to zero
// set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;
// set Payload size

@ -90,7 +90,7 @@ public class HashRequest extends Payload {
i++;
}
int size = FILENAME_POSITION + filenameSize + BytesArrayTools.computeStringArraySize(algoListStr, "\n");
byte[] packet = new byte[size + 1]; // java initialize all to zero
byte[] packet = new byte[size]; // java initialize all to zero
// set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;
// set Payload size

@ -98,7 +98,7 @@ public class HashResponse extends Payload {
for (byte[] s : hashes.values()) {
size += 4 + s.length;
}
byte[] packet = new byte[size + 1]; // java initialize all to zero
byte[] packet = new byte[size]; // java initialize all to zero
// set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;

@ -34,7 +34,7 @@ public class Logger {
* @param text Text to log
*/
public void write(String text, LogLevel logLevel) {
String colorize = "\u001B[0";
String colorize = "\u001B[0m";
String msg = "[" + new Timestamp(System.currentTimeMillis()) + "] " + text + "\n";
String level = null;
switch (logLevel) {
@ -55,6 +55,7 @@ public class Logger {
break;
case Debug:
level = "[Debug]";
colorize = "\u001B[36m"; // CYAN
break;
default:
System.err.println("Error: incorrect logLevel");

@ -86,11 +86,11 @@ public class TrackerManagementTCP extends TrackerManagement {
public void run() {
boolean end = false;
writeLog("[ " + addr + "] New connection", LogLevel.Action);
writeLog("[" + addr + "] New connection", LogLevel.Action);
do {
end = handleClientRequest();
} while(!end);
writeLog("[ " + addr + "] End of connection", LogLevel.Action);
writeLog("[" + addr + "] End of connection", LogLevel.Action);
}
/** Respond to next request incomming on socket s.

Loading…
Cancel
Save