refractor exception -> localexception
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good Details

pull/47/head
Flavien Haas 5 years ago
parent 750788c1b3
commit 740e25546a

@ -6,22 +6,22 @@ import protocolP2P.ProtocolP2PPacketTCP;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import exception.InternalError; import localException.InternalError;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.EmptyFile; import remoteException.EmptyFile;
import exception.ProtocolError; import localException.ProtocolError;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.VersionRemoteError; import remoteException.VersionRemoteError;
import exception.TransmissionError; import localException.TransmissionError;
import remoteException.ProtocolRemoteError; import remoteException.ProtocolRemoteError;
import exception.VersionError; import localException.VersionError;
import exception.SizeError; import localException.SizeError;
import remoteException.NotFound; import remoteException.NotFound;
import java.nio.file.Files; import java.nio.file.Files;
import java.io.File; import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.io.IOException; import java.io.IOException;
import exception.SocketClosed; import localException.SocketClosed;
/** Class to download file parts on tcp. /** Class to download file parts on tcp.
* @author Louis Royer * @author Louis Royer

@ -6,16 +6,16 @@ import protocolP2P.ProtocolP2PPacketUDP;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import exception.InternalError; import localException.InternalError;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.EmptyFile; import remoteException.EmptyFile;
import exception.ProtocolError; import localException.ProtocolError;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.VersionRemoteError; import remoteException.VersionRemoteError;
import exception.TransmissionError; import localException.TransmissionError;
import remoteException.ProtocolRemoteError; import remoteException.ProtocolRemoteError;
import exception.VersionError; import localException.VersionError;
import exception.SizeError; import localException.SizeError;
import remoteException.NotFound; import remoteException.NotFound;
import java.nio.file.Files; import java.nio.file.Files;
import java.io.File; import java.io.File;
@ -165,7 +165,7 @@ public class ClientDownloadPartUDP implements Runnable {
if (p == null) { if (p == null) {
stop = true; stop = true;
} }
failed = downloadPart(p); failed = downloadPart(p);
if (failed) { if (failed) {
System.err.println("Error: DownloadPart failed."); System.err.println("Error: DownloadPart failed.");
@ -176,7 +176,7 @@ public class ClientDownloadPartUDP implements Runnable {
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
noTask = true; noTask = true;
} }
} }
} }

@ -16,11 +16,11 @@ import protocolP2P.HashResponse;
import protocolP2P.HashRequest; import protocolP2P.HashRequest;
import protocolP2P.ProtocolP2PPacketTCP; import protocolP2P.ProtocolP2PPacketTCP;
import protocolP2P.Payload; import protocolP2P.Payload;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.SizeError; import localException.SizeError;
import exception.VersionError; import localException.VersionError;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import java.io.IOException; import java.io.IOException;
@ -29,7 +29,7 @@ import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import exception.SocketClosed; import localException.SocketClosed;
/** Class to download file from tcp /** Class to download file from tcp
* @author Louis Royer * @author Louis Royer

@ -16,11 +16,11 @@ import protocolP2P.HashResponse;
import protocolP2P.HashRequest; import protocolP2P.HashRequest;
import protocolP2P.ProtocolP2PPacketUDP; import protocolP2P.ProtocolP2PPacketUDP;
import protocolP2P.Payload; import protocolP2P.Payload;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.SizeError; import localException.SizeError;
import exception.VersionError; import localException.VersionError;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import java.io.IOException; import java.io.IOException;
@ -70,7 +70,7 @@ public class ClientDownloadUDP implements Runnable {
public void setStop() { public void setStop() {
stop = true; stop = true;
} }
/** Runnable implementation /** Runnable implementation
*/ */
public void run() { public void run() {
@ -188,7 +188,7 @@ public class ClientDownloadUDP implements Runnable {
assert pHash instanceof HashResponse : "This payload must be instance of HashResponse"; assert pHash instanceof HashResponse : "This payload must be instance of HashResponse";
if (!(pHash instanceof HashResponse)) { if (!(pHash instanceof HashResponse)) {
throw new InternalError(); throw new InternalError();
} else { } else {
hash = ((HashResponse)pHash).getHash(HashAlgorithm.SHA512); hash = ((HashResponse)pHash).getHash(HashAlgorithm.SHA512);
} }
} catch (EmptyDirectory e) { } catch (EmptyDirectory e) {
@ -260,14 +260,14 @@ public class ClientDownloadUDP implements Runnable {
private void init() throws InternalError { private void init() throws InternalError {
// get size // get size
setSize(); setSize();
// get hashsum from 1st server in list // get hashsum from 1st server in list
hash512 = getHashSum512(hostList.get(0)); hash512 = getHashSum512(hostList.get(0));
if (hash512.length == 0) { if (hash512.length == 0) {
System.err.println("Error: no hash512sum support."); System.err.println("Error: no hash512sum support.");
throw new InternalError(); throw new InternalError();
} }
// Add tasks // Add tasks
if (!stop) { if (!stop) {
for(long i=MAX_PARTIAL_SIZE; i<size;i+=MAX_PARTIAL_SIZE) { for(long i=MAX_PARTIAL_SIZE; i<size;i+=MAX_PARTIAL_SIZE) {

@ -1,9 +1,9 @@
package clientP2P; package clientP2P;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import remoteException.EmptyFile; import remoteException.EmptyFile;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
@ -34,7 +34,7 @@ import protocolP2P.HashResponse;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import clientP2P.ClientDownloadTCP; import clientP2P.ClientDownloadTCP;
import exception.SocketClosed; import localException.SocketClosed;
/** Implementation of P2P-JAVA-PROJECT CLIENT /** Implementation of P2P-JAVA-PROJECT CLIENT
* @author Louis Royer * @author Louis Royer

@ -1,9 +1,9 @@
package clientP2P; package clientP2P;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import remoteException.EmptyFile; import remoteException.EmptyFile;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;

@ -1,4 +1,4 @@
package exception; package localException;
public class InternalError extends Exception { public class InternalError extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;
} }

@ -1,4 +1,4 @@
package exception; package localException;
public class ProtocolError extends Exception { public class ProtocolError extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;
} }

@ -1,4 +1,4 @@
package exception; package localException;
/** Used on reception side when size as set in Packet is too big, and we cant store this in a int/long as usual. */ /** Used on reception side when size as set in Packet is too big, and we cant store this in a int/long as usual. */
public class SizeError extends Exception { public class SizeError extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;

@ -1,4 +1,4 @@
package exception; package localException;
public class SocketClosed extends Exception { public class SocketClosed extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;
} }

@ -1,4 +1,4 @@
package exception; package localException;
public class TransmissionError extends Exception { public class TransmissionError extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;
} }

@ -1,4 +1,4 @@
package exception; package localException;
public class VersionError extends Exception { public class VersionError extends Exception {
private static final long serialVersionUID = 12L; private static final long serialVersionUID = 12L;
} }

@ -2,10 +2,10 @@ package protocolP2P;
import java.util.Arrays; import java.util.Arrays;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.RequestResponseCode; import protocolP2P.RequestResponseCode;
import exception.TransmissionError; import localException.TransmissionError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.SizeError; import localException.SizeError;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import tools.BytesArrayTools; import tools.BytesArrayTools;

@ -1,10 +1,10 @@
package protocolP2P; package protocolP2P;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.RequestResponseCode; import protocolP2P.RequestResponseCode;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import tools.BytesArrayTools; import tools.BytesArrayTools;
import java.util.Arrays; import java.util.Arrays;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -36,7 +36,7 @@ public class FilePart extends Payload {
super(RequestResponseCode.LOAD_RESPONSE); super(RequestResponseCode.LOAD_RESPONSE);
/* asserts to help debugging */ /* asserts to help debugging */
assert totalSize >= 0 : "totalSize cannot be negative"; assert totalSize >= 0 : "totalSize cannot be negative";
assert partialContent.length != 0 : "partialContent.length cannot be zero, see RRCode.EMPTY_FILE"; assert partialContent.length != 0 : "partialContent.length cannot be zero, see RRCode.EMPTY_FILE";
assert totalSize >= partialContent.length : "totalSize must be greater than partialContent.length"; assert totalSize >= partialContent.length : "totalSize must be greater than partialContent.length";
assert offset >= 0 : "offset cannot be negative"; assert offset >= 0 : "offset cannot be negative";
assert filename != null : "filename is required"; assert filename != null : "filename is required";

@ -2,10 +2,10 @@ package protocolP2P;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.HashAlgorithm; import protocolP2P.HashAlgorithm;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import exception.TransmissionError; import localException.TransmissionError;
import exception.SizeError; import localException.SizeError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import tools.BytesArrayTools; import tools.BytesArrayTools;
@ -21,12 +21,12 @@ public class HashRequest extends Payload {
private HashAlgorithm[] algoList; private HashAlgorithm[] algoList;
private static final int FILENAME_SIZE_POSITION = PAYLOAD_START_POSITION; private static final int FILENAME_SIZE_POSITION = PAYLOAD_START_POSITION;
private static final int FILENAME_POSITION = FILENAME_SIZE_POSITION + 4; private static final int FILENAME_POSITION = FILENAME_SIZE_POSITION + 4;
/** Constructor (typically used by the server) with a filename parameter. /** Constructor (typically used by the server) with a filename parameter.
* @param filename name of the file to download. Must not be empty. * @param filename name of the file to download. Must not be empty.
* @param algoList List of hash algorithms used * @param algoList List of hash algorithms used
* @throws InternalError * @throws InternalError
* *
*/ */
public HashRequest(String filename, HashAlgorithm[] algoList) throws InternalError { public HashRequest(String filename, HashAlgorithm[] algoList) throws InternalError {
super(RequestResponseCode.HASH_REQUEST); super(RequestResponseCode.HASH_REQUEST);

@ -3,10 +3,10 @@ import protocolP2P.Payload;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import exception.TransmissionError; import localException.TransmissionError;
import exception.SizeError; import localException.SizeError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import tools.BytesArrayTools; import tools.BytesArrayTools;
@ -22,12 +22,12 @@ public class HashResponse extends Payload {
private Map<HashAlgorithm, byte[]> hashes = new HashMap<>(); private Map<HashAlgorithm, byte[]> hashes = new HashMap<>();
private static final int FILENAME_SIZE_POSITION = PAYLOAD_START_POSITION; private static final int FILENAME_SIZE_POSITION = PAYLOAD_START_POSITION;
private static final int FILENAME_POSITION = FILENAME_SIZE_POSITION + 4; private static final int FILENAME_POSITION = FILENAME_SIZE_POSITION + 4;
/** Constructor (typically used by the server) with a filename parameter. /** Constructor (typically used by the server) with a filename parameter.
* @param filename name of the file to download. Must not be empty. * @param filename name of the file to download. Must not be empty.
* @param hashes HashMap containing hashes for file. * @param hashes HashMap containing hashes for file.
* @throws InternalError * @throws InternalError
* *
*/ */
public HashResponse(String filename, Map<HashAlgorithm, byte[]> hashes) throws InternalError { public HashResponse(String filename, Map<HashAlgorithm, byte[]> hashes) throws InternalError {
super(RequestResponseCode.HASH_RESPONSE); super(RequestResponseCode.HASH_RESPONSE);
@ -80,7 +80,7 @@ public class HashResponse extends Payload {
} }
start += hashSize; start += hashSize;
} while (start < size); } while (start < size);
} }
/** Returns a byte[] containing Packet with padding. /** Returns a byte[] containing Packet with padding.
@ -100,7 +100,7 @@ public class HashResponse extends Payload {
size += 4 + s.length; size += 4 + s.length;
} }
byte[] packet = new byte[size + 1]; // java initialize all to zero byte[] packet = new byte[size + 1]; // java initialize all to zero
// set request/response code // set request/response code
packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue; packet[RequestResponseCode.RRCODE_POSITION] = requestResponseCode.codeValue;
// set Payload size // set Payload size

@ -1,10 +1,10 @@
package protocolP2P; package protocolP2P;
import protocolP2P.Payload; import protocolP2P.Payload;
import protocolP2P.RequestResponseCode; import protocolP2P.RequestResponseCode;
import exception.TransmissionError; import localException.TransmissionError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.SizeError; import localException.SizeError;
import tools.BytesArrayTools; import tools.BytesArrayTools;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -61,7 +61,7 @@ public class LoadRequest extends Payload {
/* Read maxSizePartialContent */ /* Read maxSizePartialContent */
maxSizePartialContent = BytesArrayTools.readLong(packet, MAX_SIZE_PARTIAL_CONTENT_POSITION); maxSizePartialContent = BytesArrayTools.readLong(packet, MAX_SIZE_PARTIAL_CONTENT_POSITION);
/* Read filename */ /* Read filename */
int size = BytesArrayTools.readInt(packet, FILENAME_SIZE_POSITION); int size = BytesArrayTools.readInt(packet, FILENAME_SIZE_POSITION);
filename = BytesArrayTools.readString(packet, FILENAME_POSITION, size); filename = BytesArrayTools.readString(packet, FILENAME_POSITION, size);

@ -5,10 +5,10 @@ import protocolP2P.FileList;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import protocolP2P.HashRequest; import protocolP2P.HashRequest;
import protocolP2P.HashResponse; import protocolP2P.HashResponse;
import exception.ProtocolError; import localException.ProtocolError;
import exception.InternalError; import localException.InternalError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.SizeError; import localException.SizeError;
import tools.BytesArrayTools; import tools.BytesArrayTools;
/** Representation of payload. If payload has a size, use subclasses instead. /** Representation of payload. If payload has a size, use subclasses instead.
* @author Louis Royer * @author Louis Royer
@ -59,7 +59,7 @@ public class Payload {
/** Used to check RRCode used is compatible with this class use, or if a more specific subclass is required. /** Used to check RRCode used is compatible with this class use, or if a more specific subclass is required.
* @throws InternalError * @throws InternalError
*/ */
private void checkRequestResponseCode() throws InternalError { private void checkRequestResponseCode() throws InternalError {
/* Incorrect use cases (use subclasses instead) */ /* Incorrect use cases (use subclasses instead) */
if ((requestResponseCode == RequestResponseCode.LIST_RESPONSE && !(this instanceof FileList)) if ((requestResponseCode == RequestResponseCode.LIST_RESPONSE && !(this instanceof FileList))
@ -68,7 +68,7 @@ public class Payload {
throw new InternalError(); throw new InternalError();
} }
} }
/** Returns a byte[] containing Packet with padding. /** Returns a byte[] containing Packet with padding.
* This Packet is still incomplete and should not be send directly. * This Packet is still incomplete and should not be send directly.
* ProtocolP2PPacket will use this method to generate the complete Packet. * ProtocolP2PPacket will use this method to generate the complete Packet.
@ -90,7 +90,7 @@ public class Payload {
* @param size integer representing payload size * @param size integer representing payload size
* @param packet Packet to be completed * @param packet Packet to be completed
* @throws InternalError * @throws InternalError
*/ */
protected static void setPayloadSize(int size, byte[] packet) throws InternalError { protected static void setPayloadSize(int size, byte[] packet) throws InternalError {
/* assert to help debugging */ /* assert to help debugging */
assert size >= 0: "Payload size cannot be negative"; assert size >= 0: "Payload size cannot be negative";

@ -1,10 +1,10 @@
package protocolP2P; package protocolP2P;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import exception.SocketClosed; import localException.SocketClosed;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.NotFound; import remoteException.NotFound;
@ -88,7 +88,7 @@ public abstract class ProtocolP2PPacket {
* @throws SizeError * @throws SizeError
*/ */
protected ProtocolP2PPacket(byte[] packet) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError {} protected ProtocolP2PPacket(byte[] packet) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError {}
/** Returns Payload associated with the Packet. /** Returns Payload associated with the Packet.
* @return payload associated with the Packet. * @return payload associated with the Packet.
*/ */

@ -1,10 +1,10 @@
package protocolP2P; package protocolP2P;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import exception.SocketClosed; import localException.SocketClosed;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.NotFound; import remoteException.NotFound;
@ -30,10 +30,10 @@ import java.net.Socket;
* @version 1.0 * @version 1.0
*/ */
public class ProtocolP2PPacketTCP extends ProtocolP2PPacket { public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
private Socket responseSocket; // socket used to recept request and send response private Socket responseSocket; // socket used to recept request and send response
private Socket requestSocket; // socket used to send request and to reception response private Socket requestSocket; // socket used to send request and to reception response
/** Constructor with payload parameter (typically used when sending packet). /** Constructor with payload parameter (typically used when sending packet).
* @param payload the payload associated with the packet to send * @param payload the payload associated with the packet to send
*/ */

@ -1,10 +1,10 @@
package protocolP2P; package protocolP2P;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import exception.SocketClosed; import localException.SocketClosed;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.NotFound; import remoteException.NotFound;
@ -31,12 +31,12 @@ import java.io.IOException;
* @version 1.0 * @version 1.0
*/ */
public class ProtocolP2PPacketUDP extends ProtocolP2PPacket { public class ProtocolP2PPacketUDP extends ProtocolP2PPacket {
private final static int CHECKSUM_POSITION = 2; private final static int CHECKSUM_POSITION = 2;
private SocketAddress responseSocketAddress; // socket address used when receptionning request and to sending response private SocketAddress responseSocketAddress; // socket address used when receptionning request and to sending response
private DatagramSocket responseSocket; // socket used to recept request and send response private DatagramSocket responseSocket; // socket used to recept request and send response
private DatagramSocket requestSocket; // socket used to send request and to reception response private DatagramSocket requestSocket; // socket used to send request and to reception response
/** Constructor with payload parameter (typically used when sending packet). /** Constructor with payload parameter (typically used when sending packet).
* @param payload the payload associated with the packet to send * @param payload the payload associated with the packet to send
*/ */

@ -1,6 +1,6 @@
package protocolP2P; package protocolP2P;
import protocolP2P.CodeType; import protocolP2P.CodeType;
import exception.ProtocolError; import localException.ProtocolError;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.lang.Byte; import java.lang.Byte;
@ -24,7 +24,7 @@ public enum RequestResponseCode {
EMPTY_DIRECTORY(CodeType.ERROR, (byte)0xC3), EMPTY_DIRECTORY(CodeType.ERROR, (byte)0xC3),
NOT_FOUND(CodeType.ERROR, (byte)0xC4), NOT_FOUND(CodeType.ERROR, (byte)0xC4),
EMPTY_FILE(CodeType.ERROR, (byte)0xC5); EMPTY_FILE(CodeType.ERROR, (byte)0xC5);
public final CodeType codeType; public final CodeType codeType;
public final byte codeValue; public final byte codeValue;
protected final static int RRCODE_POSITION = 1; protected final static int RRCODE_POSITION = 1;
@ -62,7 +62,5 @@ public enum RequestResponseCode {
return r; return r;
} }
}
}

@ -17,12 +17,12 @@ import protocolP2P.Payload;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import protocolP2P.FileList; import protocolP2P.FileList;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import exception.SocketClosed; import localException.SocketClosed;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.NotFound; import remoteException.NotFound;
@ -106,7 +106,7 @@ public class ServerManagementTCP implements Runnable {
/** Implementation of runnable. This method allow to serve one client. /** Implementation of runnable. This method allow to serve one client.
*/ */
public void run() { public void run() {
boolean end = false; boolean end = false;
logger.writeTCP(addr + "New connection", LogLevel.Action); logger.writeTCP(addr + "New connection", LogLevel.Action);
do { do {
@ -176,7 +176,7 @@ public class ServerManagementTCP implements Runnable {
private void initSha512() { private void initSha512() {
for(String f: fileList) { for(String f: fileList) {
try { try {
MessageDigest md = MessageDigest.getInstance(HashAlgorithm.SHA512.getName()); MessageDigest md = MessageDigest.getInstance(HashAlgorithm.SHA512.getName());
sha512.put(f, md.digest(Files.readAllBytes(Paths.get(baseDirectory + f)))); sha512.put(f, md.digest(Files.readAllBytes(Paths.get(baseDirectory + f))));
md.reset(); md.reset();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
@ -254,7 +254,7 @@ public class ServerManagementTCP implements Runnable {
} }
} }
} }
/** Send response to load request /** Send response to load request
* @param pd Request received * @param pd Request received

@ -16,12 +16,12 @@ import protocolP2P.Payload;
import protocolP2P.LoadRequest; import protocolP2P.LoadRequest;
import protocolP2P.FileList; import protocolP2P.FileList;
import protocolP2P.FilePart; import protocolP2P.FilePart;
import exception.InternalError; import localException.InternalError;
import exception.ProtocolError; import localException.ProtocolError;
import exception.SizeError; import localException.SizeError;
import exception.TransmissionError; import localException.TransmissionError;
import exception.VersionError; import localException.VersionError;
import exception.SocketClosed; import localException.SocketClosed;
import remoteException.EmptyDirectory; import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError; import remoteException.InternalRemoteError;
import remoteException.NotFound; import remoteException.NotFound;
@ -116,7 +116,7 @@ public class ServerManagementUDP implements Runnable {
for (String f: fileList) { for (String f: fileList) {
logger.writeUDP("- " + f, LogLevel.Debug); logger.writeUDP("- " + f, LogLevel.Debug);
} }
throw new IOException(); // to send a NOT_FOUND in the catch block throw new IOException(); // to send a NOT_FOUND in the catch block
} }
} catch (IOException e) { } catch (IOException e) {
@ -182,7 +182,7 @@ public class ServerManagementUDP implements Runnable {
private void initSha512() { private void initSha512() {
for(String f: fileList) { for(String f: fileList) {
try { try {
MessageDigest md = MessageDigest.getInstance(HashAlgorithm.SHA512.getName()); MessageDigest md = MessageDigest.getInstance(HashAlgorithm.SHA512.getName());
sha512.put(f, md.digest(Files.readAllBytes(Paths.get(baseDirectory + f)))); sha512.put(f, md.digest(Files.readAllBytes(Paths.get(baseDirectory + f))));
md.reset(); md.reset();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
@ -192,7 +192,7 @@ public class ServerManagementUDP implements Runnable {
} }
} }
} }
/** Send an internal error message. /** Send an internal error message.
* @param pd ProtocolP2PPacketUDP to respond * @param pd ProtocolP2PPacketUDP to respond
*/ */
@ -245,4 +245,3 @@ public class ServerManagementUDP implements Runnable {
} }
} }

@ -1,6 +1,6 @@
package tools; package tools;
import exception.SizeError; import localException.SizeError;
import exception.ProtocolError; import localException.ProtocolError;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Arrays; import java.util.Arrays;

Loading…
Cancel
Save