From 90bb8a1f787f49149efe173c3bf4552b482ef3e8 Mon Sep 17 00:00:00 2001
From: "isaacklugman@gmail.com" <ik1g19@soton.ac.uk>
Date: Sun, 2 May 2021 22:28:15 +0100
Subject: [PATCH] add most functionality to load operation

---
 ClientAndLoggers/ClientMain.class            | Bin 2520 -> 2868 bytes
 ClientAndLoggers/ClientMain.java             |  10 ++-
 Dstores/dstore/test2.txt                     |   0
 Dstores/dstore2/test2.txt                    |   0
 Dstores/dstore2/test3.txt                    |   0
 Dstores/dstore3/test2.txt                    |   0
 Dstores/dstore3/test3.txt                    |   0
 Dstores/dstore3/test4.txt                    |   0
 src/ftp/Controller.java                      |  55 +++++++++++-----
 src/ftp/{Dstore.java => DStore.java}         |  63 ++++++++++++-------
 src/ftp/DStoreConnection.java                |  53 ++++++++++++++++
 src/ftp/{DstoreFile.java => DStoreFile.java} |  23 +++++--
 src/ftp/DStoreIndex.java                     |  42 +++++++++++++
 src/ftp/DstoreConnection.java                |  39 ------------
 src/ftp/DstoreIndex.java                     |  29 ---------
 src/ftp/FileIndex.java                       |   8 +--
 src/ftp/Server.java                          |   6 +-
 17 files changed, 208 insertions(+), 120 deletions(-)
 delete mode 100644 Dstores/dstore/test2.txt
 delete mode 100644 Dstores/dstore2/test2.txt
 delete mode 100644 Dstores/dstore2/test3.txt
 delete mode 100644 Dstores/dstore3/test2.txt
 delete mode 100644 Dstores/dstore3/test3.txt
 delete mode 100644 Dstores/dstore3/test4.txt
 rename src/ftp/{Dstore.java => DStore.java} (72%)
 create mode 100644 src/ftp/DStoreConnection.java
 rename src/ftp/{DstoreFile.java => DStoreFile.java} (79%)
 create mode 100644 src/ftp/DStoreIndex.java
 delete mode 100644 src/ftp/DstoreConnection.java
 delete mode 100644 src/ftp/DstoreIndex.java

diff --git a/ClientAndLoggers/ClientMain.class b/ClientAndLoggers/ClientMain.class
index a51da4fd2f5f2b375bfa6a9dd450c8d797f44c1b..3c43107e0f47157f8c5d846fd50489c8ba1eb6a4 100644
GIT binary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_c*Ai}_`#Zbh+$WQ?$tH5LpLmdMH11MAIGt@IQI!H1!F|;tWF-QUcqgK}D

diff --git a/ClientAndLoggers/ClientMain.java b/ClientAndLoggers/ClientMain.java
index 3f79c95..849530b 100644
--- a/ClientAndLoggers/ClientMain.java
+++ b/ClientAndLoggers/ClientMain.java
@@ -11,6 +11,10 @@ public class ClientMain {
 		File downloadFolder = new File("downloads");
 		if (!downloadFolder.exists())
 			if (!downloadFolder.mkdir()) throw new RuntimeException("Cannot create download folder (folder absolute path: " + downloadFolder.getAbsolutePath() + ")");
+
+		File uploadFolder = new File("to_store");
+		if (!uploadFolder.exists())
+			throw new RuntimeException("to_store folder does not exist");
 		
 		
 		testClient(cport, timeout, downloadFolder);
@@ -30,6 +34,8 @@ public class ClientMain {
 //			try { list(client); } catch(IOException e) { e.printStackTrace(); }
 			
 			try { client.store(new File("test.txt")); } catch(IOException e) { e.printStackTrace(); }
+
+			try {Thread.sleep(10000);} catch (InterruptedException e) {System.out.println(e);}
 			
 //			try { client.store(new File("Clipboard01.pdf")); } catch(IOException e) { e.printStackTrace(); }
 //
@@ -38,9 +44,7 @@ public class ClientMain {
 //			String list[] = null;
 //			try { list = list(client); } catch(IOException e) { e.printStackTrace(); }
 //
-//			if (list != null)
-//				for (String filename : list)
-//					try { client.load(filename, downloadFolder); } catch(IOException e) { e.printStackTrace(); }
+			try { client.load("test.txt", downloadFolder); } catch(IOException e) { e.printStackTrace(); }
 			
 			/*if (list != null)
 				for (String filename : list)
diff --git a/Dstores/dstore/test2.txt b/Dstores/dstore/test2.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Dstores/dstore2/test2.txt b/Dstores/dstore2/test2.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Dstores/dstore2/test3.txt b/Dstores/dstore2/test3.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Dstores/dstore3/test2.txt b/Dstores/dstore3/test2.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Dstores/dstore3/test3.txt b/Dstores/dstore3/test3.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/Dstores/dstore3/test4.txt b/Dstores/dstore3/test4.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/src/ftp/Controller.java b/src/ftp/Controller.java
index 45b985e..0316c1d 100644
--- a/src/ftp/Controller.java
+++ b/src/ftp/Controller.java
@@ -1,10 +1,7 @@
 package ftp;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.nio.channels.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -15,7 +12,7 @@ public class Controller extends Server {
     private int rbPeriod;
     private int nextID = 0;
 
-    private DstoreIndex dstoreIndex;
+    private DStoreIndex dStoreIndex;
     private FileIndex fileIndex;
 
 
@@ -32,7 +29,7 @@ public class Controller extends Server {
         this.timeout = timeout;
         this.rbPeriod = rbPeriod;
 
-        dstoreIndex = new DstoreIndex();
+        dStoreIndex = new DStoreIndex();
         fileIndex = new FileIndex();
 
         start();
@@ -69,15 +66,26 @@ public class Controller extends Server {
 
             String files = readSocket(client);
 
-            // todo use stream instead
-            //
-            List<String[]> filesInfo = new ArrayList<String[]>() {{
-                String[] filesAndSizes = files.split("\\|");
-                for (String file : filesAndSizes) add(file.split(" "));
-            }};
+            DStoreConnection dStore;
+
+
+            if (!files.equals("empty")) {
+                List<DStoreFile> dStoreFiles = Arrays.stream(files.split("\\|")).
+                        map(x -> x.split(" ")).
+                        map(x -> new DStoreFile(x[0], Long.parseLong(x[1]))).
+                        collect(Collectors.toList());
+
+
+                dStore = new DStoreConnection(dStoreFiles, port, nextID);
+                dStoreFiles.stream().forEach(x -> x.addDstore(dStore));
+            }
+            else dStore = new DStoreConnection(port, nextID);
+
+
+            dStoreIndex.addDStore(dStore);
 
-            dstoreIndex.addDstore(filesInfo, port, nextID);
             threadIDOutput("New Dstore (ID: " + nextID + ") successfully joined");
+
             nextID++;
 
 
@@ -88,16 +96,20 @@ public class Controller extends Server {
             String filename = args[1];
             Long filesize = Long.parseLong(args[2]);
 
-            DstoreFile file = fileIndex.addFile(filename, filesize);
+            DStoreFile file = fileIndex.addFile(filename, filesize);
 
             file.setStoreInProgress(true);
 
 
-            List<DstoreConnection> dstores = dstoreIndex.getFirstN(r);
+            List<DStoreConnection> dStores = dStoreIndex.getFirstN(r);
 
-            dstores.stream().forEach(x -> x.addFile(file));
+            dStores.stream().
+                    forEach(x -> {
+                        x.addFile(file);
+                        file.addDstore(x);
+                    });
 
-            String ports = dstores.stream().
+            String ports = dStores.stream().
                     map(x -> Integer.toString(x.getPort())).
                     collect(Collectors.joining(" "));
 
@@ -109,7 +121,7 @@ public class Controller extends Server {
 
         else if (command.equals("STORE_ACK")) {
             String filename = args[1];
-            DstoreFile file = fileIndex.get(filename);
+            DStoreFile file = fileIndex.get(filename);
 
             file.storeAck();
 
@@ -120,6 +132,15 @@ public class Controller extends Server {
                 threadIDOutput("Store of file " + filename + " complete");
             }
         }
+
+        else if (command.equals("LOAD")) {
+            String filename = args[1];
+
+            DStoreFile file = fileIndex.get(filename);
+            int dStorePort = file.getDstore().getPort();
+
+            send("LOAD_FROM " + dStorePort + " " + file.getFilesize(), client);
+        }
     }
 
 }
\ No newline at end of file
diff --git a/src/ftp/Dstore.java b/src/ftp/DStore.java
similarity index 72%
rename from src/ftp/Dstore.java
rename to src/ftp/DStore.java
index 63af0af..c684ff1 100644
--- a/src/ftp/Dstore.java
+++ b/src/ftp/DStore.java
@@ -1,22 +1,14 @@
 package ftp;
 
-import ftp.DstoreConnection;
-import ftp.Server;
-
 import java.io.*;
-import java.net.InetSocketAddress;
 import java.net.Socket;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-public class Dstore extends Server {
+public class DStore extends Server {
 
     int cport;
     String file_folder;
@@ -29,7 +21,7 @@ public class Dstore extends Server {
      * @param timeout timeout (ms)
      * @param file_folder where to store data locally
      */
-    public Dstore(int port, int cport, int timeout, String file_folder) {
+    public DStore(int port, int cport, int timeout, String file_folder) {
 
         this.port = port;
         this.cport = cport;
@@ -79,7 +71,7 @@ public class Dstore extends Server {
                 .collect(Collectors.toList());
 
 
-        Dstore dstore = new Dstore(intArgs.get(0), intArgs.get(1), intArgs.get(2), args[3]);
+        DStore dStore = new DStore(intArgs.get(0), intArgs.get(1), intArgs.get(2), args[3]);
     }
 
 
@@ -94,20 +86,17 @@ public class Dstore extends Server {
         if (command.equals("LIST")) {
             File folder = new File(file_folder);
 
+            String fileMessage = "empty";
+
 
-            //todo use stream instead
-            //
-            List<String> files = new ArrayList<String>() {{
-                for (File file : folder.listFiles()) add(file.getName() + " " + file.length());
-            }};
+            if (folder.listFiles().length > 0) {
+                List<String> files = Arrays.stream(folder.listFiles()).
+                        map(x -> x.getName() + " " + x.length()).
+                        collect(Collectors.toList());
 
-            // todo use joining instead of reduce
-            //
-            String ident = files.get(0);
-            files.remove(0);
 
-            String fileMessage = files.stream()
-                    .reduce(ident, (file1, file2) -> (file1 + "|" + file2));
+                fileMessage = files.stream().collect(Collectors.joining("|"));
+            }
 
 
             send(fileMessage, client);
@@ -137,6 +126,17 @@ public class Dstore extends Server {
                     send("STORE_ACK " + filename, controller);
                 } else threadIDErr("Unable to connect to Controller");
             }
+
+        else if (command.equals("LOAD_DATA")) {
+            String filename = args[1];
+
+
+            try {
+                sendFile(client, file_folder + "\\" + filename);
+            } catch (IOException e) {
+                threadIDErr(e.getMessage());
+            }
+        }
     }
 
 
@@ -163,4 +163,23 @@ public class Dstore extends Server {
 
     }
 
+
+
+    public void sendFile(Socket client, String filepath) throws IOException {
+        File inputFile = new File(filepath);
+        FileInputStream inf = new FileInputStream(inputFile);
+
+        OutputStream out = client.getOutputStream();
+
+        byte[] buf = new byte[1000]; int buflen;
+
+
+        while ((buflen = inf.read(buf)) != -1) {
+            out.write(buf, 0, buflen);
+        }
+
+
+        inf.close(); client.close(); out.close();
+    }
+
 }
diff --git a/src/ftp/DStoreConnection.java b/src/ftp/DStoreConnection.java
new file mode 100644
index 0000000..7c0aa08
--- /dev/null
+++ b/src/ftp/DStoreConnection.java
@@ -0,0 +1,53 @@
+package ftp;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DStoreConnection {
+
+    private FileIndex file_index;
+    private int port;
+    private int id;
+
+
+
+//    public DStoreConnection(List<String[]> files, int port, int id) {
+//        this.port = port;
+//        this.id = id;
+//
+//        List<DStoreFile> dStoreFiles = files.stream()
+//                .map(x -> new DStoreFile(x[0],Long.parseLong(x[1])))
+//                .collect(Collectors.toList());
+//
+//        file_index = new FileIndex(dStoreFiles);
+//    }
+
+    public DStoreConnection(int port, int id) {
+        this.port = port;
+        this.id = id;
+
+        file_index = new FileIndex();
+    }
+
+    public DStoreConnection(List<DStoreFile> dStoreFiles, int port, int id) {
+        this.port = port;
+        this.id = id;
+
+        file_index = new FileIndex(dStoreFiles);
+    }
+
+
+
+    public void addFile(String filename, Long filesize) { DStoreFile file = file_index.addFile(filename,filesize); }
+
+    public void addFile(DStoreFile file) { file_index.put(file.getFilename(),file); }
+
+
+
+    public int getPort() { return port; }
+
+
+
+    public int getID() { return id; }
+
+}
diff --git a/src/ftp/DstoreFile.java b/src/ftp/DStoreFile.java
similarity index 79%
rename from src/ftp/DstoreFile.java
rename to src/ftp/DStoreFile.java
index 677a1f0..ae22dcf 100644
--- a/src/ftp/DstoreFile.java
+++ b/src/ftp/DStoreFile.java
@@ -1,6 +1,6 @@
 package ftp;
 
-public class DstoreFile {
+public class DStoreFile {
 
     private String filename;
     private Long filesize;
@@ -13,15 +13,15 @@ public class DstoreFile {
     private int storeAcksQuota;
     private int storeAcks = 0;
 
-    private DstoreIndex dstoreIndex;
+    private DStoreIndex dStoreIndex;
 
 
 
-    public DstoreFile(String filename, Long filesize) {
+    public DStoreFile(String filename, Long filesize) {
         this.filename = filename;
         this.filesize = filesize;
 
-        dstoreIndex = new DstoreIndex();
+        dStoreIndex = new DStoreIndex();
     }
 
 
@@ -31,6 +31,8 @@ public class DstoreFile {
     public boolean isRemoveInProgress() {return removeInProgress;}
     public boolean isRemoveComplete() {return removeComplete;}
 
+
+
     public void setStoreInProgress(Boolean store) { storeInProgress = store; }
     public void setStoreComplete(Boolean complete) { storeComplete = complete; }
     public void setRemoveInProgress(Boolean remove) { removeInProgress = remove; }
@@ -45,13 +47,24 @@ public class DstoreFile {
 
     public void setStoreAcksQuota(int quota) { storeAcksQuota = quota; }
     public int getStoreAcks() { return storeAcks; }
+
+
+
     public int storeAck() { return storeAcks++; }
 
+
+
     public Boolean storeAckCheck() { return storeAcks++ == storeAcksQuota; }
     public Boolean ackCheck() { return storeAcks == storeAcksQuota; }
 
 
 
-    public void addDstore(DstoreConnection dstore) { dstoreIndex.put(dstore.getID(),dstore); }
+    public void addDstore(DStoreConnection dStore) { dStoreIndex.put(dStore.getID(),dStore); }
+
+
+
+    public DStoreConnection getDstore() {
+        return dStoreIndex.getFirstAvailable();
+    }
 
 }
diff --git a/src/ftp/DStoreIndex.java b/src/ftp/DStoreIndex.java
new file mode 100644
index 0000000..5d4dcbd
--- /dev/null
+++ b/src/ftp/DStoreIndex.java
@@ -0,0 +1,42 @@
+package ftp;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DStoreIndex extends HashMap<Integer, DStoreConnection> {
+
+    public DStoreIndex() {}
+
+
+
+    public DStoreConnection addDStore(List<DStoreFile> files, int port, Integer id) {
+        DStoreConnection dStore = new DStoreConnection(files,port,id);
+        put(id, dStore);
+        return dStore;
+    }
+
+    public DStoreConnection addDStore(DStoreConnection dStore) {
+        put(dStore.getID(), dStore);
+        return dStore;
+    }
+
+
+
+    public List<DStoreConnection> getFirstN(int n) {
+        return entrySet().stream()
+                .map(x -> x.getValue())
+                .limit(n)
+                .collect(Collectors.toList());
+    }
+
+
+
+    public DStoreConnection getFirstAvailable() {
+        return entrySet().stream()
+                .map(x -> x.getValue())
+                .collect(Collectors.toList())
+        .get(0);
+    }
+
+}
diff --git a/src/ftp/DstoreConnection.java b/src/ftp/DstoreConnection.java
deleted file mode 100644
index b9ae671..0000000
--- a/src/ftp/DstoreConnection.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package ftp;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class DstoreConnection {
-
-    private FileIndex file_index;
-    private int port;
-    private int id;
-
-
-
-    public DstoreConnection(List<String[]> files, int port, int id) {
-        this.port = port;
-        this.id = id;
-
-        List<DstoreFile> dstoreFiles = files.stream()
-                .map(x -> new DstoreFile(x[0],Long.parseLong(x[1])))
-                .collect(Collectors.toList());
-
-        file_index = new FileIndex(dstoreFiles);
-    }
-
-
-
-    public void addFile(String filename, Long filesize) { DstoreFile file = file_index.addFile(filename,filesize); }
-
-    public void addFile(DstoreFile file) { file_index.put(file.getFilename(),file); }
-
-
-
-    public int getPort() { return port; }
-
-
-
-    public int getID() { return id; }
-
-}
diff --git a/src/ftp/DstoreIndex.java b/src/ftp/DstoreIndex.java
deleted file mode 100644
index 9a56ef1..0000000
--- a/src/ftp/DstoreIndex.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package ftp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class DstoreIndex extends HashMap<Integer,DstoreConnection> {
-
-    public DstoreIndex() {}
-
-
-
-    public DstoreConnection addDstore(List<String[]> files, int port, Integer id) {
-        DstoreConnection dstore = new DstoreConnection(files,port,id);
-        put(id, dstore);
-        return dstore;
-    }
-
-
-
-    public List<DstoreConnection> getFirstN(int n) {
-        return entrySet().stream()
-                .map(x -> x.getValue())
-                .limit(n)
-                .collect(Collectors.toList());
-    }
-
-}
diff --git a/src/ftp/FileIndex.java b/src/ftp/FileIndex.java
index 4e24832..dc38a14 100644
--- a/src/ftp/FileIndex.java
+++ b/src/ftp/FileIndex.java
@@ -3,18 +3,18 @@ package ftp;
 import java.util.HashMap;
 import java.util.List;
 
-public class FileIndex extends HashMap<String,DstoreFile> {
+public class FileIndex extends HashMap<String, DStoreFile> {
 
     public FileIndex() {}
 
-    public FileIndex(List<DstoreFile> list) {
+    public FileIndex(List<DStoreFile> list) {
         list.stream().forEach(x -> put(x.getFilename(),x));
     }
 
 
 
-    public DstoreFile addFile(String filename, Long filesize) {
-        DstoreFile file = new DstoreFile(filename,filesize);
+    public DStoreFile addFile(String filename, Long filesize) {
+        DStoreFile file = new DStoreFile(filename,filesize);
         put(filename,file);
         return file;
     }
diff --git a/src/ftp/Server.java b/src/ftp/Server.java
index 5a70e66..383dbb2 100644
--- a/src/ftp/Server.java
+++ b/src/ftp/Server.java
@@ -9,6 +9,7 @@ public abstract class Server {
     protected int timeout;
 
 
+
     protected void start() {
         try {
             ServerSocket ss = new ServerSocket(port);
@@ -40,9 +41,11 @@ public abstract class Server {
     }
 
 
+
     protected abstract void handleRequest(String request, Socket client);
 
 
+
     protected void send(String msg, Socket socket) {
         try {
             PrintWriter out = new PrintWriter(socket.getOutputStream());
@@ -55,7 +58,6 @@ public abstract class Server {
         }
     }
 
-
     protected void send(String msg, String hostname, int port) {
         try {
             Socket socket = new Socket(hostname, port);
@@ -70,6 +72,7 @@ public abstract class Server {
     }
 
 
+
     protected String readSocket(Socket socket) {
         String request = null;
 
@@ -86,6 +89,7 @@ public abstract class Server {
     }
 
 
+
     protected void threadIDOutput(String output) {
         System.out.println("Thread ID: " + Thread.currentThread().getId() + " " + output);
     }
-- 
GitLab