mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 18:36:30 +02:00
uwu
This commit is contained in:
@@ -224,19 +224,36 @@ public class NFController {
|
|||||||
*/
|
*/
|
||||||
boolean commandAllowed = true;
|
boolean commandAllowed = true;
|
||||||
switch (currentCommand) {
|
switch (currentCommand) {
|
||||||
case NFCommands.COM_MYFILES: {
|
//Comandos SIEMPRE permitidos
|
||||||
|
case NFCommands.COM_MYFILES:
|
||||||
|
case NFCommands.COM_QUIT:
|
||||||
|
case NFCommands.COM_HELP:
|
||||||
|
case NFCommands.COM_NICK:
|
||||||
commandAllowed = true;
|
commandAllowed = true;
|
||||||
break;
|
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;
|
||||||
case NFCommands.COM_PING: {
|
//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);
|
||||||
|
if (!commandAllowed) {
|
||||||
|
System.err.println("* Comando no permitido en estado OFFLINE. Haz un 'ping' primero.");
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// System.err.println("ERROR: undefined behaviour for " + currentCommand + "
|
commandAllowed = false;
|
||||||
// command!");
|
System.err.println("ERROR: undefined behaviour for " + currentCommand + " command!");
|
||||||
}
|
}
|
||||||
return commandAllowed;
|
return commandAllowed;
|
||||||
}
|
}
|
||||||
@@ -248,12 +265,27 @@ 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;
|
return; //Si falla, no cambiamos de estado
|
||||||
}
|
|
||||||
switch (currentCommand) {
|
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (currentCommand) {
|
||||||
|
case NFCommands.COM_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMyLocalFiles() {
|
private void showMyLocalFiles() {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public class PeerMessage {
|
|||||||
private byte filenameLong;
|
private byte filenameLong;
|
||||||
private String filenameVal;
|
private String filenameVal;
|
||||||
|
|
||||||
|
private byte[] fileData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -89,6 +91,14 @@ public class PeerMessage {
|
|||||||
this.filenameVal = filenameVal;
|
this.filenameVal = filenameVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getFileData() {
|
||||||
|
return fileData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileData(byte[] fileData) {
|
||||||
|
this.fileData = fileData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Método de clase para parsear los campos de un mensaje y construir el objeto
|
* Método de clase para parsear los campos de un mensaje y construir el objeto
|
||||||
* DirMessage que contiene los datos del mensaje recibido
|
* DirMessage que contiene los datos del mensaje recibido
|
||||||
@@ -138,6 +148,16 @@ public class PeerMessage {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PeerMessageOps.OPCODE_REQUEST_PEER_DL: {
|
||||||
|
int longitudSubHash = (int)dis.readByte();
|
||||||
|
byte[] subHash = new byte[longitudSubHash];
|
||||||
|
dis.readFully(subHash);
|
||||||
|
break;
|
||||||
|
// buscar archivo supongo
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ public class PeerMessageOps {
|
|||||||
public static final byte OPCODE_PEER_FILE = 2;
|
public static final byte OPCODE_PEER_FILE = 2;
|
||||||
public static final byte OPCODE_PEER_FILES_ERROR = 3;
|
public static final byte OPCODE_PEER_FILES_ERROR = 3;
|
||||||
|
|
||||||
|
public static final byte OPCODE_REQUEST_PEER_DL = 4;
|
||||||
|
public static final byte OPCODE_FILE_NOT_FOUND = 5;
|
||||||
|
public static final byte OPCODE_AMBIGUOUS = 6;
|
||||||
|
public static final byte OPCODE_PEER_DL = 7;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -26,12 +32,20 @@ public class PeerMessageOps {
|
|||||||
private static final Byte[] _valid_opcodes = { OPCODE_INVALID_CODE,
|
private static final Byte[] _valid_opcodes = { OPCODE_INVALID_CODE,
|
||||||
OPCODE_REQUEST_PEER_FILES,
|
OPCODE_REQUEST_PEER_FILES,
|
||||||
OPCODE_PEER_FILE,
|
OPCODE_PEER_FILE,
|
||||||
OPCODE_PEER_FILES_ERROR
|
OPCODE_PEER_FILES_ERROR,
|
||||||
|
OPCODE_REQUEST_PEER_DL,
|
||||||
|
OPCODE_FILE_NOT_FOUND,
|
||||||
|
OPCODE_AMBIGUOUS,
|
||||||
|
OPCODE_PEER_DL
|
||||||
};
|
};
|
||||||
private static final String[] _valid_operations_str = { "INVALID_OPCODE",
|
private static final String[] _valid_operations_str = { "INVALID_OPCODE",
|
||||||
"REQUEST_PEER_FILES",
|
"REQUEST_PEER_FILES",
|
||||||
"PEER_FILE",
|
"PEER_FILE",
|
||||||
"PEER_FILES_ERROR"
|
"PEER_FILES_ERROR",
|
||||||
|
"REQUEST_PEER_DL",
|
||||||
|
"FILE_NOT_FOUND",
|
||||||
|
"FILE_AMBIGUOUS",
|
||||||
|
"PEER_DL"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Map<String, Byte> _operation_to_opcode;
|
private static Map<String, Byte> _operation_to_opcode;
|
||||||
|
|||||||
Reference in New Issue
Block a user