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