This commit is contained in:
binlaab
2026-04-30 12:31:11 +02:00
parent 72899acd74
commit b87b710c50
6 changed files with 125 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package es.um.redes.nanoFiles.udp.server;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
@@ -278,6 +279,28 @@ public class NFDirectoryServer {
}
break;
}
case DirMessageOps.OPERATION_REQUEST_DIRDL: {
String hashSubstring = receivedMsg.getHash();
FileInfo[] found = FileInfo.lookupHashSubstring(directoryFiles, hashSubstring);
if (found.length > 1) {
msgToSend = new DirMessage(DirMessageOps.OPERATION_FILE_AMBIGUOUS);
} else if (found.length == 0) {
msgToSend = new DirMessage(DirMessageOps.OPERATION_FILE_NOT_FOUND);
} else {
FileInfo fi = found[0];
byte[] data = new byte[(int) fi.fileSize];
FileInputStream fis = new FileInputStream(fi.filePath);
fis.read(data);
fis.close();
String b64Data = java.util.Base64.getEncoder().encodeToString(data);
msgToSend = new DirMessage(DirMessageOps.OPERATION_DIRDL, fi.fileName, b64Data, fi.fileSize, fi.fileHash);
break;
}
}
default:
System.err.println("Unexpected message operation: \"" + operation + "\"");