mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 18:26:30 +02:00
ESTADO SERVING
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,7 @@ public class NFController {
|
||||
private static final byte END = 4;
|
||||
private static final byte WAIT_ACK_REQUESTDIRFILES = 5;
|
||||
private static final byte RETRY_REQUESTDIRFILES = 6;
|
||||
private static final byte SERVING = 7;
|
||||
|
||||
/*
|
||||
* DONE: (Boletín Autómatas) Añadir más constantes que representen los estados
|
||||
@@ -163,9 +164,9 @@ public class NFController {
|
||||
|
||||
//Comprobamos si ya estamos sirviendo
|
||||
if (controllerPeer.getServerPort() != 0) {
|
||||
System.err.println("* Ya existe un servidor de ficheros activo en el puerto " + controllerPeer.getServerPort());
|
||||
break;
|
||||
}
|
||||
System.err.println("* Ya existe un servidor de ficheros activo en el puerto " + controllerPeer.getServerPort());
|
||||
break;
|
||||
}
|
||||
if (NanoFiles.testModeTCP) {
|
||||
controllerPeer.testTCPServer();
|
||||
} else {
|
||||
@@ -220,6 +221,7 @@ public class NFController {
|
||||
* Método que comprueba si se puede procesar un comando introducidos por un
|
||||
* usuario, en función del estado del autómata en el que nos encontramos.
|
||||
*/
|
||||
|
||||
private boolean canProcessCommandInCurrentState() {
|
||||
/*
|
||||
* TODO: (Boletín Autómatas) Para cada comando tecleado en el shell
|
||||
@@ -228,43 +230,61 @@ public class NFController {
|
||||
* serán válidos en cualquier estado. Este método NO debe modificar
|
||||
* clientStatus.
|
||||
*/
|
||||
|
||||
boolean commandAllowed = true;
|
||||
switch (currentCommand) {
|
||||
//Comandos SIEMPRE permitidos
|
||||
case NFCommands.COM_MYFILES:
|
||||
case NFCommands.COM_QUIT:
|
||||
case NFCommands.COM_HELP:
|
||||
case NFCommands.COM_NICK:
|
||||
commandAllowed = true;
|
||||
break;
|
||||
//Comandos permitidos:OFFLINE
|
||||
case NFCommands.COM_PING:
|
||||
commandAllowed = (currentState == OFFLINE);
|
||||
if (!commandAllowed) {
|
||||
System.err.println("* Ya estás conectado al directorio. No necesitas hacer ping de nuevo.");
|
||||
}
|
||||
break;
|
||||
//Comandos permitidos:ONLINE
|
||||
case NFCommands.COM_FILELIST_DIR:
|
||||
case NFCommands.COM_PEERLIST:
|
||||
case NFCommands.COM_SERVE:
|
||||
case NFCommands.COM_DOWNLOAD_DIR:
|
||||
case NFCommands.COM_FILELIST_PEER:
|
||||
case NFCommands.COM_DOWNLOAD_PEER:
|
||||
commandAllowed = (currentState == ONLINE);
|
||||
System.out.println("allowed = " + commandAllowed);
|
||||
if (!commandAllowed) {
|
||||
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
commandAllowed = false;
|
||||
System.err.println("ERROR: undefined behaviour for " + currentCommand + " command!");
|
||||
}
|
||||
return commandAllowed;
|
||||
switch (currentCommand) {
|
||||
// Comandos SIEMPRE permitidos
|
||||
case NFCommands.COM_MYFILES:
|
||||
case NFCommands.COM_QUIT:
|
||||
case NFCommands.COM_HELP:
|
||||
commandAllowed = true;
|
||||
break;
|
||||
|
||||
// Comandos permitidos: solo en OFFLINE
|
||||
case NFCommands.COM_PING:
|
||||
commandAllowed = (currentState == OFFLINE);
|
||||
if (!commandAllowed) {
|
||||
System.err.println("* Ya estás conectado al directorio. No necesitas hacer ping de nuevo.");
|
||||
}
|
||||
break;
|
||||
|
||||
// Comandos permitidos: OFFLINE Y ONLINE (no en SERVING)
|
||||
case NFCommands.COM_NICK:
|
||||
commandAllowed = (currentState == OFFLINE || currentState == ONLINE);
|
||||
if (!commandAllowed) {
|
||||
System.err.println("* No puedes cambiar tu nick mientras estás sirviendo ficheros.");
|
||||
}
|
||||
break;
|
||||
|
||||
// Comandos permitidos: solo en ONLINE
|
||||
case NFCommands.COM_SERVE:
|
||||
commandAllowed = (currentState == ONLINE);
|
||||
if (currentState == OFFLINE) {
|
||||
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
|
||||
} else if (currentState == SERVING) {
|
||||
System.err.println("* Ya estás sirviendo ficheros. No puedes iniciar el servidor de nuevo.");
|
||||
}
|
||||
break;
|
||||
|
||||
// Comandos permitidos: ONLINE Y SERVING
|
||||
case NFCommands.COM_FILELIST_DIR:
|
||||
case NFCommands.COM_PEERLIST:
|
||||
case NFCommands.COM_DOWNLOAD_DIR:
|
||||
case NFCommands.COM_FILELIST_PEER:
|
||||
case NFCommands.COM_DOWNLOAD_PEER:
|
||||
commandAllowed = (currentState == ONLINE || currentState == SERVING);
|
||||
if (!commandAllowed) {
|
||||
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
commandAllowed = false;
|
||||
System.err.println("ERROR: undefined behaviour for " + currentCommand + " command!");
|
||||
}
|
||||
return commandAllowed;
|
||||
}
|
||||
|
||||
|
||||
private void updateCurrentState(boolean success) {
|
||||
/*
|
||||
* TODO: (Boletín Autómatas) Si el comando ha sido procesado con éxito, debemos
|
||||
@@ -272,28 +292,32 @@ public class NFController {
|
||||
* siguiente estado y así permitir unos u otros comandos en cada caso.
|
||||
*/
|
||||
if (!success) {
|
||||
return; //Si falla, no cambiamos de estado
|
||||
}
|
||||
|
||||
switch (currentCommand) {
|
||||
case NFCommands.COM_PING:
|
||||
System.out.println("updateCurrentState ping");
|
||||
currentState = ONLINE;
|
||||
break;
|
||||
|
||||
case NFCommands.COM_QUIT:
|
||||
currentState = OFFLINE;
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* Los únicos comandos que cambian el estado del autómata son el
|
||||
* 'ping' para ponerlo en ONLINE, y el 'quit' para ponerlo en
|
||||
* OFFLINE, por lo tanto, los demás comandos no alterarán el
|
||||
* estado del autómata
|
||||
*/
|
||||
break;
|
||||
}
|
||||
return; // Si falla, no cambiamos de estado
|
||||
}
|
||||
|
||||
switch (currentCommand) {
|
||||
case NFCommands.COM_PING:
|
||||
// System.out.println("updateCurrentState ping");
|
||||
currentState = ONLINE;
|
||||
break;
|
||||
|
||||
case NFCommands.COM_SERVE:
|
||||
currentState = SERVING;
|
||||
break;
|
||||
|
||||
case NFCommands.COM_QUIT:
|
||||
currentState = OFFLINE;
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* Los únicos comandos que cambian el estado del autómata son el
|
||||
* 'ping' para ponerlo en ONLINE, 'quit' para ponerlo en OFFLINE,
|
||||
* y 'serve', por lo tanto, los demás comandos no alterarán el
|
||||
* estado del autómata
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showMyLocalFiles() {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user