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