|
|
|
@ -5,21 +5,19 @@ import localException.SizeError;
|
|
|
|
|
import localException.TransmissionError;
|
|
|
|
|
import localException.VersionError;
|
|
|
|
|
import localException.SocketClosed;
|
|
|
|
|
import remoteException.NotATracker;
|
|
|
|
|
import remoteException.EmptyDirectory;
|
|
|
|
|
import remoteException.InternalRemoteError;
|
|
|
|
|
import remoteException.NotFound;
|
|
|
|
|
import remoteException.ProtocolRemoteError;
|
|
|
|
|
import remoteException.VersionRemoteError;
|
|
|
|
|
import remoteException.EmptyFile;
|
|
|
|
|
import tools.BytesArrayTools;
|
|
|
|
|
import tools.HostItem;
|
|
|
|
|
import protocolP2P.Payload;
|
|
|
|
|
import protocolP2P.RequestResponseCode;
|
|
|
|
|
import protocolP2P.LoadRequest;
|
|
|
|
|
import protocolP2P.FileList;
|
|
|
|
|
import protocolP2P.FilePart;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.lang.Byte;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.Socket;
|
|
|
|
@ -68,9 +66,9 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
socket.close();
|
|
|
|
|
} catch (IOException e2) {
|
|
|
|
|
System.err.println("Cannot close socket");
|
|
|
|
|
} finally {
|
|
|
|
|
throw new SocketClosed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -117,7 +115,6 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
ss.close();
|
|
|
|
|
} catch (IOException e2) {
|
|
|
|
|
System.err.println("Cannot close socket");
|
|
|
|
|
} finally {
|
|
|
|
|
throw new SocketClosed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -139,6 +136,8 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
case LOAD_RESPONSE:
|
|
|
|
|
case LIST_RESPONSE:
|
|
|
|
|
case HASH_RESPONSE:
|
|
|
|
|
case DISCOVER_RESPONSE:
|
|
|
|
|
case NOT_A_TRACKER:
|
|
|
|
|
// we were expecting a request, but we are receiving a response
|
|
|
|
|
throw new ProtocolError();
|
|
|
|
|
default :
|
|
|
|
@ -189,6 +188,7 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
* @return ProtocolP2PPacket received
|
|
|
|
|
* @throws EmptyFile
|
|
|
|
|
* @throws NotFound
|
|
|
|
|
* @throws NotATracker
|
|
|
|
|
* @throws EmptyDirectory
|
|
|
|
|
* @throws InternalRemoteError
|
|
|
|
|
* @throws VersionRemoteError
|
|
|
|
@ -201,7 +201,7 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws SocketClosed
|
|
|
|
|
*/
|
|
|
|
|
public ProtocolP2PPacket receiveResponse() throws EmptyFile, NotFound, EmptyDirectory, InternalRemoteError, VersionRemoteError, ProtocolRemoteError, TransmissionError, ProtocolError, VersionError, InternalError, SizeError, IOException, SocketClosed {
|
|
|
|
|
public ProtocolP2PPacket receiveResponse() throws EmptyFile, NotFound, NotATracker, EmptyDirectory, InternalRemoteError, VersionRemoteError, ProtocolRemoteError, TransmissionError, ProtocolError, VersionError, InternalError, SizeError, IOException, SocketClosed {
|
|
|
|
|
assert requestSocket != null : "Cannot receive response because request packet not sent.";
|
|
|
|
|
if (requestSocket == null) {
|
|
|
|
|
throw new InternalError();
|
|
|
|
@ -226,6 +226,8 @@ public class ProtocolP2PPacketTCP extends ProtocolP2PPacket {
|
|
|
|
|
throw new NotFound();
|
|
|
|
|
case EMPTY_FILE:
|
|
|
|
|
throw new EmptyFile();
|
|
|
|
|
case NOT_A_TRACKER:
|
|
|
|
|
throw new NotATracker();
|
|
|
|
|
default :
|
|
|
|
|
return (ProtocolP2PPacket)p;
|
|
|
|
|
}
|
|
|
|
|