mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 18:36:30 +02:00
'jars'
This commit is contained in:
@@ -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 + "\"");
|
||||
|
||||
Reference in New Issue
Block a user