Index: src/chunk/Chunk.java
===================================================================
--- src/chunk/Chunk.java	(revision 2)
+++ src/chunk/Chunk.java	(revision 3)
@@ -1,147 +1,147 @@
-package chunk;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.RandomAccessFile;
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import javax.xml.bind.DatatypeConverter;
-
-public class Chunk {
-    public static final int CHUNK_MAX_SIZE = 64000;
-
-    private int chunkNo;
-    private String fileID;
-
-    private int repDegree;
-
-    private byte[] data;
-
-    public Chunk(String fileID, int chunkNo, int repDegree, byte[] data) {
-        this.chunkNo = chunkNo;
-        this.fileID = fileID;
-        this.data = data;
-        this.repDegree = repDegree;
-    }
-
-    /**
-     * @return The chunk's file ID
-     */
-    public String getFileID() {
-        return fileID;
-    }
-
-    /**
-     * @return The chunk number
-     */
-    public int getChunkNo() {
-        return chunkNo;
-    }
-
-    /**
-     * @return The chunk replication degree
-     */
-    public int getRepDegree() {
-        return repDegree;
-    }
-
-    /**
-     * @return The chunk data byte array
-     */
-    public byte[] getData() {
-        return data;
-    }
-
-    public static Chunk[] splitFile(String path, int repDegree) {
-        File file = new File(path);
-        return splitFile(file, repDegree);
-    }
-
-    public static int getNumberOfFileChunks(File file) {
-        long nFileBytes = file.length();
-        return (int) ((nFileBytes - 1) / CHUNK_MAX_SIZE + 1);
-    }
-
-    public static Chunk[] splitFile(File file, int repDegree) {
-        if (!file.isFile()) {
-            return null;
-        }
-        long nFileBytes = file.length();
-        int nChunks = getNumberOfFileChunks(file);
-        Chunk[] chunks = new Chunk[nChunks];
-        String fileId = generateFileId(file);
-        try (RandomAccessFile data = new RandomAccessFile(file, "r")) {
-            int nReadBytes = 0;
-            for (int i = 0; i < nChunks; i++) {
-                int nBytesToRead;
-                int nBytesMissing = (int) (nFileBytes - nReadBytes);
-                if (nBytesMissing < CHUNK_MAX_SIZE) {
-                    nBytesToRead = nBytesMissing;
-                } else {
-                    nBytesToRead = CHUNK_MAX_SIZE;
-                }
-                byte[] newData = new byte[nBytesToRead];
-                data.readFully(newData);
-                Chunk newChunk = new Chunk(generateFileId(file), i + 1, repDegree, newData);
-                chunks[i] = newChunk;
-                nReadBytes += CHUNK_MAX_SIZE;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return chunks;
-    }
-
-    public static String generateFileId(File file) {
-        MessageDigest digest;
-        try {
-            digest = MessageDigest.getInstance("SHA-256");
-        } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
-            return null;
-        }
-        String toEncode = file.getName() + Long.toString(file.length());
-        byte[] encodedhash;
-        try {
-            encodedhash = digest.digest(toEncode.getBytes("UTF-8"));
-            return DatatypeConverter.printBase64Binary(encodedhash);
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        }
-        return "invalid";
-    }
-
-    public static void sortChunkArray(Chunk[] chunks) {
-        for (int i = 0; i < chunks.length; i++) {
-            Chunk currChunk = chunks[i];
-            int nCurrChunk = currChunk.getChunkNo();
-            if (nCurrChunk != i + 1) {
-                Chunk tempChunk = chunks[i];
-                chunks[i] = chunks[nCurrChunk - 1];
-                chunks[nCurrChunk - 1] = tempChunk;
-            }
-        }
-    }
-
-    public static void restoreFile(Chunk[] chunks, String filePath) {
-        sortChunkArray(chunks);
-        try (FileOutputStream fos = new FileOutputStream(filePath)) {
-            for (int i = 0; i < chunks.length; i++) {
-                fos.write(chunks[i].getData());
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        final Chunk c = (Chunk) obj;
-        return (c.chunkNo == chunkNo && c.fileID.equals(fileID) && c.repDegree == repDegree);
-    }
-}
+package chunk;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import java.util.Base64;
+
+public class Chunk {
+    public static final int CHUNK_MAX_SIZE = 64000;
+
+    private int chunkNo;
+    private String fileID;
+
+    private int repDegree;
+
+    private byte[] data;
+
+    public Chunk(String fileID, int chunkNo, int repDegree, byte[] data) {
+        this.chunkNo = chunkNo;
+        this.fileID = fileID;
+        this.data = data;
+        this.repDegree = repDegree;
+    }
+
+    /**
+     * @return The chunk's file ID
+     */
+    public String getFileID() {
+        return fileID;
+    }
+
+    /**
+     * @return The chunk number
+     */
+    public int getChunkNo() {
+        return chunkNo;
+    }
+
+    /**
+     * @return The chunk replication degree
+     */
+    public int getRepDegree() {
+        return repDegree;
+    }
+
+    /**
+     * @return The chunk data byte array
+     */
+    public byte[] getData() {
+        return data;
+    }
+
+    public static Chunk[] splitFile(String path, int repDegree) {
+        File file = new File(path);
+        return splitFile(file, repDegree);
+    }
+
+    public static int getNumberOfFileChunks(File file) {
+        long nFileBytes = file.length();
+        return (int) ((nFileBytes - 1) / CHUNK_MAX_SIZE + 1);
+    }
+
+    public static Chunk[] splitFile(File file, int repDegree) {
+        if (!file.isFile()) {
+            return null;
+        }
+        long nFileBytes = file.length();
+        int nChunks = getNumberOfFileChunks(file);
+        Chunk[] chunks = new Chunk[nChunks];
+        String fileId = generateFileId(file);
+        try (RandomAccessFile data = new RandomAccessFile(file, "r")) {
+            int nReadBytes = 0;
+            for (int i = 0; i < nChunks; i++) {
+                int nBytesToRead;
+                int nBytesMissing = (int) (nFileBytes - nReadBytes);
+                if (nBytesMissing < CHUNK_MAX_SIZE) {
+                    nBytesToRead = nBytesMissing;
+                } else {
+                    nBytesToRead = CHUNK_MAX_SIZE;
+                }
+                byte[] newData = new byte[nBytesToRead];
+                data.readFully(newData);
+                Chunk newChunk = new Chunk(generateFileId(file), i + 1, repDegree, newData);
+                chunks[i] = newChunk;
+                nReadBytes += CHUNK_MAX_SIZE;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return chunks;
+    }
+
+    public static String generateFileId(File file) {
+        MessageDigest digest;
+        try {
+            digest = MessageDigest.getInstance("SHA-256");
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+            return null;
+        }
+        String toEncode = file.getName() + Long.toString(file.length());
+        byte[] encodedhash;
+        try {
+            encodedhash = digest.digest(toEncode.getBytes("UTF-8"));
+            return Base64.getEncoder().withoutPadding().encodeToString(encodedhash);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return "invalid";
+    }
+
+    public static void sortChunkArray(Chunk[] chunks) {
+        for (int i = 0; i < chunks.length; i++) {
+            Chunk currChunk = chunks[i];
+            int nCurrChunk = currChunk.getChunkNo();
+            if (nCurrChunk != i + 1) {
+                Chunk tempChunk = chunks[i];
+                chunks[i] = chunks[nCurrChunk - 1];
+                chunks[nCurrChunk - 1] = tempChunk;
+            }
+        }
+    }
+
+    public static void restoreFile(Chunk[] chunks, String filePath) {
+        //sortChunkArray(chunks);
+        try (FileOutputStream fos = new FileOutputStream(filePath)) {
+            for (int i = 0; i < chunks.length; i++) {
+                fos.write(chunks[i].getData());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        final Chunk c = (Chunk) obj;
+        return (c.chunkNo == chunkNo && c.fileID.equals(fileID) && c.repDegree == repDegree);
+    }
+}
Index: src/client/TestApp.java
===================================================================
--- src/client/TestApp.java	(revision 2)
+++ src/client/TestApp.java	(revision 3)
@@ -1,186 +1,186 @@
-package client;
-
-import utils.Utils;
-
-import java.lang.Integer;
-import java.rmi.NotBoundException;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
-
-import peer.PeerInterface;
-
-import java.lang.Float;
-
-/**
- * TestApp
- */
-public class TestApp {
-
-    private String peer_ap;
-    private String operation;
-    private String filePath;
-    private float diskSpace;
-    private int replicationDeg;
-    private PeerInterface pInterface;
-
-    public static void main(String[] args){
-        TestApp app = new TestApp(args);
-        app.processRequest();
-    }
-
-    public TestApp(String[] args) {
-        if (!handleInputs(args)) {
-            usage();
-            return;
-        }
-
-        connect();
-    }
-
-    public void processRequest(){
-        switch (operation) {
-            case "BACKUP":
-                System.out.println("BACKUP:\n\tFile: " + filePath + "\n\tReplication Degree: " + replicationDeg);
-                try {
-                    pInterface.backup(filePath, replicationDeg);
-                } catch (RemoteException e) {
-                    System.out.println("BACKUP ERROR!");
-                    e.printStackTrace();
-                }
-                System.out.println("BACKUP SUCCESSFUL!");
-                break;
-            case "RESTORE":
-                System.out.println("RESTORE:\n\tFile: " + filePath);
-                try {
-                    pInterface.restore(filePath);
-                } catch (RemoteException e) {
-                    System.out.println("RESTORE ERROR!");
-                    e.printStackTrace();
-                }
-                System.out.println("RESTORE SUCCESSFUL!");
-                break;
-            case "DELETE":
-                System.out.println("DELETE:\n\tFile: " + filePath);
-                try {
-                    pInterface.delete(filePath);
-                } catch (RemoteException e) {
-                    System.out.println("DELETE ERROR!");
-                    e.printStackTrace();
-                }
-                System.out.println("DELETE SUCCESSFUL!");
-                break;
-            case "RECLAIM":
-                System.out.println("RECLAIM:\n\tDisk Space: " + diskSpace);
-                try {
-                    pInterface.reclaim(diskSpace);
-                } catch (RemoteException e) {
-                    System.out.println("RECLAIM ERROR!");
-                    e.printStackTrace();
-                }
-                System.out.println("RECLAIM SUCCESSFUL!");
-                break;
-            case "STATE":
-                System.out.println("STATE:");
-                try {
-                    pInterface.state();
-                } catch (RemoteException e) {
-                    System.out.println("STATE ERROR!");
-                    e.printStackTrace();
-                }
-                System.out.println("STATE SUCCESSFUL!");
-                    break;
-            default:
-                break;
-            }
-    }
-        
-    
-
-    private boolean handleInputs(String[] args) {
-        if (args.length < 2) {
-            System.out.println("Error: Invalid number of arguments!");
-            return false;
-        }
-
-        this.peer_ap = args[0];
-        
-        this.operation = args[1].toUpperCase();
-        switch (operation) {
-        case "BACKUP":
-            if (args.length != 4) {
-                System.out.println(operation + " error: Invalid number of arguments!");
-                return false;
-            }
-            if (!Utils.fileExists(args[2])) {
-                System.out.println(operation + " error: File doesn't exist!");
-                return false;
-            }
-            this.filePath = args[2];
-            if (!Utils.isInteger(args[3])) {
-                System.out.println(operation + " error: Replication Degree invalid!");
-                return false;
-            }
-            this.replicationDeg = Integer.parseInt(args[3]);
-            break;
-        case "RESTORE":
-            if (args.length != 3) {
-                System.out.println(operation + " error: Invalid number of arguments!");
-                return false;
-            }
-            if (!Utils.fileExists(args[2])) {
-                System.out.println(operation + " error: File doesn't exist!");
-                return false;
-            }
-            this.filePath = args[2];
-            break;
-        case "DELETE":
-            if (args.length != 3) {
-                System.out.println(operation + " error: Invalid number of arguments!");
-                return false;
-            }
-            if (!Utils.fileExists(args[2])) {
-                System.out.println(operation + " error: File doesn't exist!");
-                return false;
-            }
-            this.filePath = args[2];
-            break;
-        case "RECLAIM":
-            if (args.length != 3) {
-                System.out.println(operation + " error: Invalid number of arguments!");
-                return false;
-            }
-            if (!Utils.isFloat(args[2])) {
-                System.out.println(operation + " error: Maximum amount of disk space invalid!");
-                return false;
-            }
-            this.diskSpace = Float.parseFloat(args[2]);
-            break;
-        case "STATE":
-            if (args.length != 2) {
-                System.out.println(operation + " error: Invalid number of arguments!");
-                return false;
-            }
-            break;
-        default:
-            System.out.println("Error: Invalid operation!");
-            return false;
-        }
-        return true;
-    }
-
-    private static void usage() {
-        System.out.println(
-                "Usage:\n\tjava TestApp <peer_ap> <operation> <opnd_1> <opnd2>\n\t\t<peer_app>: Peer's access point;\n\t\t<operation>: Operation the peer of backup service must execute. It must be one of: BACKUP, RESTORE, DELETE, RECLAIM, STATE;\n\t\t<opnd_1>: Path Name of the file in case of operations BACKUP, RESTORE or DELETE or maximum amount of disk space (in KByte) in case of operation RECLAIM\n\t\t<opnd_2>: Integer that specifies the desired replication degree for operation BACKUP");
-        return;
-    }
-
-    public void connect() {
-        try {
-            Registry rmiReg = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
-            this.pInterface = (PeerInterface) rmiReg.lookup(this.peer_ap);
-        } catch (RemoteException | NotBoundException e) {
-            e.printStackTrace();
-        }
-    }
+package client;
+
+import utils.Utils;
+
+import java.lang.Integer;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+import peer.PeerInterface;
+
+import java.lang.Float;
+
+/**
+ * TestApp
+ */
+public class TestApp {
+
+    private String peer_ap;
+    private String operation;
+    private String filePath;
+    private float diskSpace;
+    private int replicationDeg;
+    private PeerInterface pInterface;
+
+    public static void main(String[] args){
+        TestApp app = new TestApp(args);
+        app.processRequest();
+    }
+
+    public TestApp(String[] args) {
+        if (!handleInputs(args)) {
+            usage();
+            return;
+        }
+
+        connect();
+    }
+
+    public void processRequest(){
+        switch (operation) {
+            case "BACKUP":
+                System.out.println("BACKUP:\n\tFile: " + filePath + "\n\tReplication Degree: " + replicationDeg);
+                try {
+                    pInterface.backup(filePath, replicationDeg);
+                } catch (RemoteException e) {
+                    System.out.println("BACKUP ERROR!");
+                    e.printStackTrace();
+                }
+                System.out.println("BACKUP SUCCESSFUL!");
+                break;
+            case "RESTORE":
+                System.out.println("RESTORE:\n\tFile: " + filePath);
+                try {
+                    pInterface.restore(filePath);
+                } catch (RemoteException e) {
+                    System.out.println("RESTORE ERROR!");
+                    e.printStackTrace();
+                }
+                System.out.println("RESTORE SUCCESSFUL!");
+                break;
+            case "DELETE":
+                System.out.println("DELETE:\n\tFile: " + filePath);
+                try {
+                    pInterface.delete(filePath);
+                } catch (RemoteException e) {
+                    System.out.println("DELETE ERROR!");
+                    e.printStackTrace();
+                }
+                System.out.println("DELETE SUCCESSFUL!");
+                break;
+            case "RECLAIM":
+                System.out.println("RECLAIM:\n\tDisk Space: " + diskSpace);
+                try {
+                    pInterface.reclaim(diskSpace);
+                } catch (RemoteException e) {
+                    System.out.println("RECLAIM ERROR!");
+                    e.printStackTrace();
+                }
+                System.out.println("RECLAIM SUCCESSFUL!");
+                break;
+            case "STATE":
+                System.out.println("STATE:");
+                try {
+                    pInterface.state();
+                } catch (RemoteException e) {
+                    System.out.println("STATE ERROR!");
+                    e.printStackTrace();
+                }
+                System.out.println("STATE SUCCESSFUL!");
+                    break;
+            default:
+                break;
+            }
+    }
+        
+    
+
+    private boolean handleInputs(String[] args) {
+        if (args.length < 2) {
+            System.out.println("Error: Invalid number of arguments!");
+            return false;
+        }
+
+        this.peer_ap = args[0];
+        
+        this.operation = args[1].toUpperCase();
+        switch (operation) {
+        case "BACKUP":
+            if (args.length != 4) {
+                System.out.println(operation + " error: Invalid number of arguments!");
+                return false;
+            }
+            if (!Utils.fileExists(args[2])) {
+                System.out.println(operation + " error: File doesn't exist!");
+                return false;
+            }
+            this.filePath = args[2];
+            if (!Utils.isInteger(args[3])) {
+                System.out.println(operation + " error: Replication Degree invalid!");
+                return false;
+            }
+            this.replicationDeg = Integer.parseInt(args[3]);
+            break;
+        case "RESTORE":
+            if (args.length != 3) {
+                System.out.println(operation + " error: Invalid number of arguments!");
+                return false;
+            }
+            if (!Utils.fileExists(args[2])) {
+                System.out.println(operation + " error: File doesn't exist!");
+                return false;
+            }
+            this.filePath = args[2];
+            break;
+        case "DELETE":
+            if (args.length != 3) {
+                System.out.println(operation + " error: Invalid number of arguments!");
+                return false;
+            }
+            if (!Utils.fileExists(args[2])) {
+                System.out.println(operation + " error: File doesn't exist!");
+                return false;
+            }
+            this.filePath = args[2];
+            break;
+        case "RECLAIM":
+            if (args.length != 3) {
+                System.out.println(operation + " error: Invalid number of arguments!");
+                return false;
+            }
+            if (!Utils.isFloat(args[2])) {
+                System.out.println(operation + " error: Maximum amount of disk space invalid!");
+                return false;
+            }
+            this.diskSpace = Float.parseFloat(args[2]);
+            break;
+        case "STATE":
+            if (args.length != 2) {
+                System.out.println(operation + " error: Invalid number of arguments!");
+                return false;
+            }
+            break;
+        default:
+            System.out.println("Error: Invalid operation!");
+            return false;
+        }
+        return true;
+    }
+
+    private static void usage() {
+        System.out.println(
+                "Usage:\n\tjava TestApp <peer_ap> <operation> <opnd_1> <opnd2>\n\t\t<peer_app>: Peer's access point;\n\t\t<operation>: Operation the peer of backup service must execute. It must be one of: BACKUP, RESTORE, DELETE, RECLAIM, STATE;\n\t\t<opnd_1>: Path Name of the file in case of operations BACKUP, RESTORE or DELETE or maximum amount of disk space (in KByte) in case of operation RECLAIM\n\t\t<opnd_2>: Integer that specifies the desired replication degree for operation BACKUP");
+        return;
+    }
+
+    public void connect() {
+        try {
+            Registry rmiReg = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
+            this.pInterface = (PeerInterface) rmiReg.lookup(this.peer_ap);
+        } catch (RemoteException | NotBoundException e) {
+            e.printStackTrace();
+        }
+    }
 }
\ No newline at end of file
Index: src/disk/ChunkManagement.java
===================================================================
--- src/disk/ChunkManagement.java	(revision 2)
+++ src/disk/ChunkManagement.java	(revision 3)
@@ -1,86 +1,85 @@
-package disk;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingDeque;
-
-import chunk.Chunk;
-import javafx.util.Pair;
-
-/**
- * ChunkManagement
- */
-public class ChunkManagement {
-
-	private static ChunkManagement chunkManagementInstance = null;
-
-	private Map<String, Map<Integer, Integer>> storesCounter;
-
-	private BlockingQueue<Chunk> restoreChunks;
-
-	private ChunkManagement() {
-		storesCounter = new HashMap<String, Map<Integer, Integer>>();
-		restoreChunks = new LinkedBlockingDeque<Chunk>();
-	}
-
-	public static ChunkManagement getInstance() {
-		if (chunkManagementInstance == null) {
-			chunkManagementInstance = new ChunkManagement();
-		}
-		return chunkManagementInstance;
-	}
-
-	public int getStores(String fileId, int chunkNo) {
-		if (!storesCounter.containsKey(fileId)){
-			return 0;
-		}
-		if (!storesCounter.get(fileId).containsKey(chunkNo)){
-			return 0;
-		}
-		return storesCounter.get(fileId).get(chunkNo);
-	}
-
-	public int registerStored(String fileId, int chunkNo) {
-		if (!storesCounter.containsKey(fileId)) {
-			storesCounter.put(fileId, new HashMap<Integer, Integer>());
-		}
-		if (!storesCounter.get(fileId).containsKey(chunkNo)) {
-			storesCounter.get(fileId).put(chunkNo, 1);
-		} else {
-			int nStores = storesCounter.get(fileId).get(chunkNo);
-			storesCounter.get(fileId).put(chunkNo, nStores + 1);
-		}
-		return storesCounter.get(fileId).get(chunkNo);
-	}
-
-	public int registerRemoved(String fileId, int chunkNo) {
-		if (!storesCounter.containsKey(fileId)) {
-			return 0;
-		}
-		if (!storesCounter.get(fileId).containsKey(chunkNo)) {
-			return 0;
-		} else {
-			int nStores = storesCounter.get(fileId).get(chunkNo);
-			storesCounter.get(fileId).put(chunkNo, nStores - 1);
-			return storesCounter.get(fileId).get(chunkNo);
-		}
-	}
-
-	public void deleteStores(String fileId) {
-		storesCounter.remove(fileId);
-	}
-
-	public void addRestoreChunk(Chunk chunk) {
-		restoreChunks.add(chunk);
-	}
-
-	/**
-	 * @return the restoreChunks
-	 */
-	public BlockingQueue<Chunk> getRestoreChunks() {
-		return restoreChunks;
-	}
-
-}
\ No newline at end of file
+package disk;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingDeque;
+
+import chunk.Chunk;
+
+/**
+ * ChunkManagement
+ */
+public class ChunkManagement {
+
+	private static ChunkManagement chunkManagementInstance = null;
+
+	private Map<String, Map<Integer, Integer>> storesCounter;
+
+	private BlockingQueue<Chunk> restoreChunks;
+
+	private ChunkManagement() {
+		storesCounter = new HashMap<String, Map<Integer, Integer>>();
+		restoreChunks = new LinkedBlockingDeque<Chunk>();
+	}
+
+	public static ChunkManagement getInstance() {
+		if (chunkManagementInstance == null) {
+			chunkManagementInstance = new ChunkManagement();
+		}
+		return chunkManagementInstance;
+	}
+
+	public int getStores(String fileId, int chunkNo) {
+		if (!storesCounter.containsKey(fileId)){
+			return 0;
+		}
+		if (!storesCounter.get(fileId).containsKey(chunkNo)){
+			return 0;
+		}
+		return storesCounter.get(fileId).get(chunkNo);
+	}
+
+	public int registerStored(String fileId, int chunkNo) {
+		if (!storesCounter.containsKey(fileId)) {
+			storesCounter.put(fileId, new HashMap<Integer, Integer>());
+		}
+		if (!storesCounter.get(fileId).containsKey(chunkNo)) {
+			storesCounter.get(fileId).put(chunkNo, 1);
+		} else {
+			int nStores = storesCounter.get(fileId).get(chunkNo);
+			storesCounter.get(fileId).put(chunkNo, nStores + 1);
+		}
+		return storesCounter.get(fileId).get(chunkNo);
+	}
+
+	public int registerRemoved(String fileId, int chunkNo) {
+		if (!storesCounter.containsKey(fileId)) {
+			return 0;
+		}
+		if (!storesCounter.get(fileId).containsKey(chunkNo)) {
+			return 0;
+		} else {
+			int nStores = storesCounter.get(fileId).get(chunkNo);
+			storesCounter.get(fileId).put(chunkNo, nStores - 1);
+			return storesCounter.get(fileId).get(chunkNo);
+		}
+	}
+
+	public void deleteStores(String fileId) {
+		storesCounter.remove(fileId);
+	}
+
+	public void addRestoreChunk(Chunk chunk) {
+		restoreChunks.add(chunk);
+	}
+
+	/**
+	 * @return the restoreChunks
+	 */
+	public BlockingQueue<Chunk> getRestoreChunks() {
+		return restoreChunks;
+	}
+
+}
Index: src/disk/Disk.java
===================================================================
--- src/disk/Disk.java	(revision 2)
+++ src/disk/Disk.java	(revision 3)
@@ -1,237 +1,237 @@
-package disk;
-
-import chunk.*;
-import utils.Utils;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-/**
- * Disk
- */
-public class Disk {
-
-	public static final String fileSeparator = System.getProperty("file.separator");
-	public static final String filesPath = "." + fileSeparator + "files" + fileSeparator;
-	public static final String resourcesPath = filesPath + "resources" + fileSeparator;
-	public static final String defaultDiskLocation = filesPath + "peers" + fileSeparator;
-	public static final long defaultDiskSize = 10000000; /* Disk size in KBytes */
-
-	private long size; /* Disk size in bytes */
-	private String diskLocation;
-	private File directory;
-	private File backupDirectory, restoredDirectory;
-
-	public void restoreFile(Chunk[] chunks, String fileName) {
-		Chunk.restoreFile(chunks, getRestoredDirectoryPath() + fileSeparator + fileName);
-	}
-
-	public Disk(String diskName) {
-		this(diskName, defaultDiskSize);
-	}
-
-	public Disk(String diskName, float size) {
-		this.diskLocation = defaultDiskLocation + diskName;
-		this.size = (long) (size * 1000);
-		createDiskDirectory();
-	}
-
-	/**
-	 * @return the backupDirectory
-	 */
-	public File getBackupDirectory() {
-		return backupDirectory;
-	}
-
-	/**
-	 * @return the defaultDiskLocation
-	 */
-	public static String getDefaultDiskLocation() {
-		return defaultDiskLocation;
-	}
-
-	/**
-	 * @return the directory
-	 */
-	public File getDirectory() {
-		return directory;
-	}
-
-	/**
-	 * @return the restoredDirectory
-	 */
-	public File getRestoredDirectory() {
-		return restoredDirectory;
-	}
-
-	public String getRestoredDirectoryPath() {
-		return restoredDirectory.getAbsolutePath();
-	}
-
-	public boolean createDiskDirectory() {
-		directory = new File(this.diskLocation);
-		directory.mkdirs();
-		createBackupDirectory();
-		createRestoredDirectory();
-		return true;
-	}
-
-	public boolean createBackupDirectory() {
-		backupDirectory = new File(this.diskLocation + fileSeparator + "backup");
-		if (backupDirectory.mkdirs()) {
-			return true;
-		}
-		return false;
-	}
-
-	public boolean createRestoredDirectory() {
-		restoredDirectory = new File(this.diskLocation + fileSeparator + "restored");
-		if (restoredDirectory.mkdirs()) {
-			return true;
-		}
-		return false;
-	}
-
-	public String getDiskLocation() {
-		return diskLocation;
-	}
-
-	public long getSize() {
-		return size;
-	}
-
-	public long getOccupiedSpace() {
-		return folderSize(this.directory);
-	}
-
-	public long getFreeSpace() {
-		return size - getOccupiedSpace();
-	}
-
-	public static long folderSize(File directory) {
-		long length = 0;
-		for (File file : directory.listFiles()) {
-			if (file.isFile())
-				length += file.length();
-			else
-				length += folderSize(file);
-		}
-		return length;
-	}
-
-	public File createFileFolder(String fileId) {
-		File fileFolder = new File(backupDirectory.getPath() + fileSeparator + fileId);
-		fileFolder.mkdirs();
-		return fileFolder;
-	}
-
-	public boolean storeChunk(Chunk chunk) {
-		String fileName = chunk.getChunkNo() + "-" + chunk.getRepDegree();
-
-		File folder = createFileFolder(chunk.getFileID());
-
-		File chunkFile = new File(folder.getPath() + fileSeparator + fileName);
-
-		if (chunkFile.exists()) {
-			return false;
-		}
-
-		try (FileOutputStream fos = new FileOutputStream(chunkFile)) {
-			fos.write(chunk.getData());
-		} catch (Exception e) {
-			e.printStackTrace();
-			return false;
-		}
-
-		return true;
-	}
-
-	public File[] getFileChunkFiles(String fileId) {
-		File fileChunkDirectory = getFileChunkDirectory(fileId);
-		return fileChunkDirectory.listFiles();
-	}
-
-	public Chunk[] getFileChunks(String fileId) {
-		File chunkFiles[] = getFileChunkFiles(fileId);
-
-		Chunk[] chunks = new Chunk[chunkFiles.length];
-
-		for (int i = 0; i < chunkFiles.length; i++) {
-			chunks[i] = parseFileToChunk(fileId, chunkFiles[i]);
-		}
-
-		return chunks;
-	}
-
-	public File getChunkFile(String fileId, int chunkId) {
-		File chunkFiles[] = getFileChunkFiles(fileId);
-		for (File chunkFile : chunkFiles) {
-			if (chunkFile.getName().startsWith(chunkId + "-")) {
-				return chunkFile;
-			}
-		}
-		return null;
-	}
-
-	public Chunk getChunk(String fileId, int chunkId) {
-		Chunk[] chunks = getFileChunks(fileId);
-
-		for (Chunk chunk : chunks) {
-			if (chunk.getChunkNo() == chunkId) {
-				return chunk;
-			}
-		}
-		return null;
-	}
-
-	public File getFileChunkDirectory(String fileId) {
-		return new File(backupDirectory.getPath() + fileSeparator + fileId);
-	}
-
-	public static Chunk parseFileToChunk(String fileId, File chunkFile) {
-		String fileName = chunkFile.getName();
-		String parsedName[] = fileName.split("-");
-
-		int chunkId = Integer.parseInt(parsedName[0]);
-		int repDegree = Integer.parseInt(parsedName[1]);
-
-		byte[] data = new byte[(int) chunkFile.length()];
-
-		try (FileInputStream fis = new FileInputStream(chunkFile)) {
-			fis.read(data);
-		} catch (Exception e) {
-
-		}
-
-		Chunk chunk = new Chunk(fileId, chunkId, repDegree, data);
-
-		return chunk;
-	}
-
-	public void deleteFileDirectory(String fileId) {
-		//File fileDir = getFileChunkDirectory(fileId);
-		/*try {
-			Utils.deleteDirectoryRecursively(fileDir);
-		} catch (IOException e) {
-			e.printStackTrace();
-			return false;
-		}
-		return true;
-		*/
-		File fileDir = new File(backupDirectory + "\\" + fileId);
-		System.out.println("FileDir: \"" + fileDir + "\"");
-		Utils.deleteDirectoryRecursively(fileDir);
-	}
-
-	public boolean deleteChunk(String fileId, int chunkId) {
-		File chunkFile = getChunkFile(fileId, chunkId);
-		if (!chunkFile.delete()) {
-			System.out.println("Failed to delete " + chunkFile);
-			return false;
-		}
-		return true;
-	}
-
-}
+package disk;
+
+import chunk.*;
+import utils.Utils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+/**
+ * Disk
+ */
+public class Disk {
+
+	public static final String fileSeparator = System.getProperty("file.separator");
+	public static final String filesPath = "." + fileSeparator + "files" + fileSeparator;
+	public static final String resourcesPath = filesPath + "resources" + fileSeparator;
+	public static final String defaultDiskLocation = filesPath + "peers" + fileSeparator;
+	public static final long defaultDiskSize = 10000000; /* Disk size in KBytes */
+
+	private long size; /* Disk size in bytes */
+	private String diskLocation;
+	private File directory;
+	private File backupDirectory, restoredDirectory;
+
+	public void restoreFile(Chunk[] chunks, String fileName) {
+		Chunk.restoreFile(chunks, getRestoredDirectoryPath() + fileSeparator + fileName);
+	}
+
+	public Disk(String diskName) {
+		this(diskName, defaultDiskSize);
+	}
+
+	public Disk(String diskName, float size) {
+		this.diskLocation = defaultDiskLocation + diskName;
+		this.size = (long) (size * 1000);
+		createDiskDirectory();
+	}
+
+	/**
+	 * @return the backupDirectory
+	 */
+	public File getBackupDirectory() {
+		return backupDirectory;
+	}
+
+	/**
+	 * @return the defaultDiskLocation
+	 */
+	public static String getDefaultDiskLocation() {
+		return defaultDiskLocation;
+	}
+
+	/**
+	 * @return the directory
+	 */
+	public File getDirectory() {
+		return directory;
+	}
+
+	/**
+	 * @return the restoredDirectory
+	 */
+	public File getRestoredDirectory() {
+		return restoredDirectory;
+	}
+
+	public String getRestoredDirectoryPath() {
+		return restoredDirectory.getAbsolutePath();
+	}
+
+	public boolean createDiskDirectory() {
+		directory = new File(this.diskLocation);
+		directory.mkdirs();
+		createBackupDirectory();
+		createRestoredDirectory();
+		return true;
+	}
+
+	public boolean createBackupDirectory() {
+		backupDirectory = new File(this.diskLocation + fileSeparator + "backup");
+		if (backupDirectory.mkdirs()) {
+			return true;
+		}
+		return false;
+	}
+
+	public boolean createRestoredDirectory() {
+		restoredDirectory = new File(this.diskLocation + fileSeparator + "restored");
+		if (restoredDirectory.mkdirs()) {
+			return true;
+		}
+		return false;
+	}
+
+	public String getDiskLocation() {
+		return diskLocation;
+	}
+
+	public long getSize() {
+		return size;
+	}
+
+	public long getOccupiedSpace() {
+		return folderSize(this.directory);
+	}
+
+	public long getFreeSpace() {
+		return size - getOccupiedSpace();
+	}
+
+	public static long folderSize(File directory) {
+		long length = 0;
+		for (File file : directory.listFiles()) {
+			if (file.isFile())
+				length += file.length();
+			else
+				length += folderSize(file);
+		}
+		return length;
+	}
+
+	public File createFileFolder(String fileId) {
+		File fileFolder = new File(backupDirectory.getPath() + fileSeparator + fileId);
+		fileFolder.mkdirs();
+		return fileFolder;
+	}
+
+	public boolean storeChunk(Chunk chunk) {
+		String fileName = chunk.getChunkNo() + "-" + chunk.getRepDegree();
+
+		File folder = createFileFolder(chunk.getFileID());
+
+		File chunkFile = new File(folder.getPath() + fileSeparator + fileName);
+
+		if (chunkFile.exists()) {
+			return false;
+		}
+
+		try (FileOutputStream fos = new FileOutputStream(chunkFile)) {
+			fos.write(chunk.getData());
+		} catch (Exception e) {
+			e.printStackTrace();
+			return false;
+		}
+
+		return true;
+	}
+
+	public File[] getFileChunkFiles(String fileId) {
+		File fileChunkDirectory = getFileChunkDirectory(fileId);
+		return fileChunkDirectory.listFiles();
+	}
+
+	public Chunk[] getFileChunks(String fileId) {
+		File chunkFiles[] = getFileChunkFiles(fileId);
+
+		Chunk[] chunks = new Chunk[chunkFiles.length];
+
+		for (int i = 0; i < chunkFiles.length; i++) {
+			chunks[i] = parseFileToChunk(fileId, chunkFiles[i]);
+		}
+
+		return chunks;
+	}
+
+	public File getChunkFile(String fileId, int chunkId) {
+		File chunkFiles[] = getFileChunkFiles(fileId);
+		for (File chunkFile : chunkFiles) {
+			if (chunkFile.getName().startsWith(chunkId + "-")) {
+				return chunkFile;
+			}
+		}
+		return null;
+	}
+
+	public Chunk getChunk(String fileId, int chunkId) {
+		Chunk[] chunks = getFileChunks(fileId);
+
+		for (Chunk chunk : chunks) {
+			if (chunk.getChunkNo() == chunkId) {
+				return chunk;
+			}
+		}
+		return null;
+	}
+
+	public File getFileChunkDirectory(String fileId) {
+		return new File(backupDirectory.getPath() + fileSeparator + fileId);
+	}
+
+	public static Chunk parseFileToChunk(String fileId, File chunkFile) {
+		String fileName = chunkFile.getName();
+		String parsedName[] = fileName.split("-");
+
+		int chunkId = Integer.parseInt(parsedName[0]);
+		int repDegree = Integer.parseInt(parsedName[1]);
+
+		byte[] data = new byte[(int) chunkFile.length()];
+
+		try (FileInputStream fis = new FileInputStream(chunkFile)) {
+			fis.read(data);
+		} catch (Exception e) {
+
+		}
+
+		Chunk chunk = new Chunk(fileId, chunkId, repDegree, data);
+
+		return chunk;
+	}
+
+	public void deleteFileDirectory(String fileId) {
+		//File fileDir = getFileChunkDirectory(fileId);
+		/*try {
+			Utils.deleteDirectoryRecursively(fileDir);
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+		*/
+		File fileDir = new File(backupDirectory + fileSeparator + fileId);
+		System.out.println("FileDir: \"" + fileDir + "\"");
+		Utils.deleteDirectoryRecursively(fileDir);
+	}
+
+	public boolean deleteChunk(String fileId, int chunkId) {
+		File chunkFile = getChunkFile(fileId, chunkId);
+		if (!chunkFile.delete()) {
+			System.out.println("Failed to delete " + chunkFile);
+			return false;
+		}
+		return true;
+	}
+
+}
Index: src/disk/DiskFailedToInitialize.java
===================================================================
--- src/disk/DiskFailedToInitialize.java	(revision 2)
+++ src/disk/DiskFailedToInitialize.java	(revision 3)
@@ -1,12 +1,12 @@
-package disk;
-
-/**
- * DiskFailedToInitialize
- */
-public class DiskFailedToInitialize extends Exception {
-
-	public DiskFailedToInitialize() {
-		super();
-	}
-
+package disk;
+
+/**
+ * DiskFailedToInitialize
+ */
+public class DiskFailedToInitialize extends Exception {
+
+	public DiskFailedToInitialize() {
+		super();
+	}
+
 }
\ No newline at end of file
Index: src/message/InvalidHeaderParameters.java
===================================================================
--- src/message/InvalidHeaderParameters.java	(revision 2)
+++ src/message/InvalidHeaderParameters.java	(revision 3)
@@ -1,11 +1,11 @@
-package message;
-
-/**
- * InvalidHeaderParameters
- */
-public class InvalidHeaderParameters extends Exception {
-
-	private static final long serialVersionUID = -1129574923771068119L;
-
-		
+package message;
+
+/**
+ * InvalidHeaderParameters
+ */
+public class InvalidHeaderParameters extends Exception {
+
+	private static final long serialVersionUID = -1129574923771068119L;
+
+		
 }
\ No newline at end of file
Index: src/message/InvalidSenderProtocolVersion.java
===================================================================
--- src/message/InvalidSenderProtocolVersion.java	(revision 2)
+++ src/message/InvalidSenderProtocolVersion.java	(revision 3)
@@ -1,7 +1,7 @@
-package message;
-
-public class InvalidSenderProtocolVersion extends Exception {
-
-	private static final long serialVersionUID = -6896672292724504010L;
-
-}
+package message;
+
+public class InvalidSenderProtocolVersion extends Exception {
+
+	private static final long serialVersionUID = -6896672292724504010L;
+
+}
Index: src/message/Message.java
===================================================================
--- src/message/Message.java	(revision 2)
+++ src/message/Message.java	(revision 3)
@@ -1,110 +1,110 @@
-package message;
-
-import chunk.Chunk;
-import peer.Peer;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-public class Message {
-
-    public static final int MESSAGE_PACKET_MAX_SIZE = Chunk.CHUNK_MAX_SIZE + MessageHeader.MESSAGE_HEADER_MAX_SIZE;
-
-    private MessageHeader header;
-    private byte[] body;
-
-    public Message(byte[] data) {
-        String rawMessage = new String(data);
-        int index = rawMessage.indexOf(MessageHeader.CRLF) + 4;
-        byte[] rawHeader = new byte[index+1];
-        System.arraycopy(data, 0, rawHeader, 0, index - 4);
-        header = new MessageHeader(new String(rawHeader));
-        int bodyLength = data.length - index;
-        body = new byte[bodyLength];
-        System.arraycopy(data, index, body, 0, bodyLength);
-    }
-
-    public Message(MessageHeader header, byte[] body) {
-        this.header = header;
-        this.body = body;
-    }
-
-    public byte[] toBytes() throws IOException {
-        byte[] result;
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        bos.write(header.toString().getBytes());
-        if (body != null)
-            bos.write(body);
-        result = bos.toByteArray();
-        return result;
-    }
-
-    public MessageHeader getHeader() {
-        return header;
-    }
-
-    public byte[] getBody() {
-        return body;
-    }
-
-    /*
-     * public static boolean isValid(String message) { String myString =
-     * message.substring(0,message.indexOf("\r\n\r\n"));
-     * 
-     * return
-     * myString.matches(".* [0-9].[0-9] [0-9]+ .{32} .{6} [0-9]\r\n\r\n(.*)?"); }
-     */
-
-    public static Message parsePutChunkMessage(Chunk chunk, Peer peer) {
-        MessageHeader header = new MessageHeader("PUTCHUNK", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo(),
-                chunk.getRepDegree());
-        Message message = new Message(header, chunk.getData());
-
-        return message;
-    }
-
-    public static Message parseStoredMessage(Chunk chunk, Peer peer) {
-        try {
-            MessageHeader header = new MessageHeader("STORED", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo());
-            Message message = new Message(header, null);
-            return message;
-        } catch (InvalidHeaderParameters e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    public static Message parseDeleteMessage(String fileId, Peer peer) {
-        try {
-            MessageHeader header = new MessageHeader("DELETE", peer.getpVersion(), peer.getPeerId(), fileId);
-            Message message = new Message(header, null);
-            return message;
-        } catch (InvalidHeaderParameters e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    public static Message parseGetChunkMessage(String fileId, int chunkNo, Peer peer) {
-        try {
-            MessageHeader header = new MessageHeader("GETCHUNK", peer.getpVersion(), peer.getPeerId(), fileId, chunkNo);
-            Message message = new Message(header, null);
-            return message;
-        } catch (InvalidHeaderParameters e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-	public static Message parseChunkMessage(Chunk chunk, Peer peer) {
-		try {
-            MessageHeader header = new MessageHeader("CHUNK", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo());
-            Message message = new Message(header, chunk.getData());
-            return message;
-        } catch (InvalidHeaderParameters e) {
-            e.printStackTrace();
-        }
-        return null;
-	}
-
+package message;
+
+import chunk.Chunk;
+import peer.Peer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class Message {
+
+    public static final int MESSAGE_PACKET_MAX_SIZE = Chunk.CHUNK_MAX_SIZE + MessageHeader.MESSAGE_HEADER_MAX_SIZE;
+
+    private MessageHeader header;
+    private byte[] body;
+
+    public Message(byte[] data) {
+        String rawMessage = new String(data);
+        int index = rawMessage.indexOf(MessageHeader.CRLF) + 4;
+        byte[] rawHeader = new byte[index+1];
+        System.arraycopy(data, 0, rawHeader, 0, index - 4);
+        header = new MessageHeader(new String(rawHeader));
+        int bodyLength = data.length - index;
+        body = new byte[bodyLength];
+        System.arraycopy(data, index, body, 0, bodyLength);
+    }
+
+    public Message(MessageHeader header, byte[] body) {
+        this.header = header;
+        this.body = body;
+    }
+
+    public byte[] toBytes() throws IOException {
+        byte[] result;
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        bos.write(header.toString().getBytes());
+        if (body != null)
+            bos.write(body);
+        result = bos.toByteArray();
+        return result;
+    }
+
+    public MessageHeader getHeader() {
+        return header;
+    }
+
+    public byte[] getBody() {
+        return body;
+    }
+
+    /*
+     * public static boolean isValid(String message) { String myString =
+     * message.substring(0,message.indexOf("\r\n\r\n"));
+     * 
+     * return
+     * myString.matches(".* [0-9].[0-9] [0-9]+ .{32} .{6} [0-9]\r\n\r\n(.*)?"); }
+     */
+
+    public static Message parsePutChunkMessage(Chunk chunk, Peer peer) {
+        MessageHeader header = new MessageHeader("PUTCHUNK", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo(),
+                chunk.getRepDegree());
+        Message message = new Message(header, chunk.getData());
+
+        return message;
+    }
+
+    public static Message parseStoredMessage(Chunk chunk, Peer peer) {
+        try {
+            MessageHeader header = new MessageHeader("STORED", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo());
+            Message message = new Message(header, null);
+            return message;
+        } catch (InvalidHeaderParameters e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static Message parseDeleteMessage(String fileId, Peer peer) {
+        try {
+            MessageHeader header = new MessageHeader("DELETE", peer.getpVersion(), peer.getPeerId(), fileId);
+            Message message = new Message(header, null);
+            return message;
+        } catch (InvalidHeaderParameters e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static Message parseGetChunkMessage(String fileId, int chunkNo, Peer peer) {
+        try {
+            MessageHeader header = new MessageHeader("GETCHUNK", peer.getpVersion(), peer.getPeerId(), fileId, chunkNo);
+            Message message = new Message(header, null);
+            return message;
+        } catch (InvalidHeaderParameters e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+	public static Message parseChunkMessage(Chunk chunk, Peer peer) {
+		try {
+            MessageHeader header = new MessageHeader("CHUNK", peer.getpVersion(), peer.getPeerId(), chunk.getFileID(), chunk.getChunkNo());
+            Message message = new Message(header, chunk.getData());
+            return message;
+        } catch (InvalidHeaderParameters e) {
+            e.printStackTrace();
+        }
+        return null;
+	}
+
 }
\ No newline at end of file
Index: src/message/MessageHeader.java
===================================================================
--- src/message/MessageHeader.java	(revision 2)
+++ src/message/MessageHeader.java	(revision 3)
@@ -1,113 +1,113 @@
-package message;
-
-public class MessageHeader {
-
-    public static final String CRLF = "\r\n\r\n";
-    public static final int MESSAGE_HEADER_MAX_SIZE = 1000;
-
-    private String messageType, version, fileId;
-    private int senderId, chunkNo, replicaDeg;
-
-    public MessageHeader(String rawHeader) {
-        System.out.println("Messageheader: " + rawHeader);
-        String[] sArray = rawHeader.trim().split(" ");
-        this.messageType = sArray[0];
-        this.version = sArray[1];
-        this.senderId = Integer.parseInt(sArray[2]);
-        this.fileId = sArray[3];
-        System.out.println("fileid: " + fileId);
-        if (this.messageType.equals("PUTCHUNK") || this.messageType.equals("STORED")
-                || this.messageType.equals("GETCHUNK") || this.messageType.equals("REMOVED")
-                || this.messageType.equals("CHUNK")) {
-            String cn = sArray[4].replaceAll("[^\\d]", "");
-            this.chunkNo = Integer.parseInt(cn);
-        }
-        if (this.messageType.equals("PUTCHUNK")) {
-            String rep = sArray[5].replaceAll("[^\\d]", "");
-            this.replicaDeg = Integer.parseInt(rep);
-        }
-    }
-
-    public MessageHeader(String messageType, String version, int senderId, String fileId, int chunkNo)
-            throws InvalidHeaderParameters {
-        this.messageType = messageType;
-        if (this.messageType.equals("PUTCHUNK")) {
-            throw new InvalidHeaderParameters();
-        }
-        this.version = version;
-        this.senderId = senderId;
-        this.fileId = fileId;
-        this.chunkNo = chunkNo;
-    }
-
-    public MessageHeader(String messageType, String version, int senderId, String fileId, int chunkNo, int replicaDeg) {
-        this.messageType = messageType;
-        this.version = version;
-        this.senderId = senderId;
-        this.fileId = fileId;
-        this.chunkNo = chunkNo;
-        this.replicaDeg = replicaDeg;
-    }
-
-    public MessageHeader(String messageType, String version, int senderId, String fileId)
-            throws InvalidHeaderParameters {
-        this.messageType = messageType;
-        if (!this.messageType.equals("DELETE")) {
-            throw new InvalidHeaderParameters();
-        }
-        this.version = version;
-        this.senderId = senderId;
-        this.fileId = fileId;
-    }
-
-    public String getMessageType() {
-        return this.messageType;
-    }
-
-    public String getVersion() {
-        return this.version;
-    }
-
-    public int getSenderId() {
-        return this.senderId;
-    }
-
-    public String getFileId() {
-        return this.fileId;
-    }
-
-    public int getChunkNo() {
-        return this.chunkNo;
-    }
-
-    public int getReplicaDeg() {
-        return this.replicaDeg;
-    }
-
-    @Override
-    public String toString() {
-        switch (messageType) {
-        case "GETCHUNK":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + " " + Integer.toString(this.chunkNo) + CRLF;
-        case "PUTCHUNK":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + " " + Integer.toString(this.chunkNo) + " " + Integer.toString(this.replicaDeg) + CRLF;
-        case "STORED":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + " " + Integer.toString(this.chunkNo) + CRLF;
-        case "CHUNK":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + " " + Integer.toString(this.chunkNo) + CRLF;
-        case "DELETE":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + CRLF;
-        case "REMOVED":
-            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
-                    + " " + Integer.toString(this.chunkNo) + CRLF;
-        default:
-            return "";
-
-        }
-    }
-}
+package message;
+
+public class MessageHeader {
+
+    public static final String CRLF = "\r\n\r\n";
+    public static final int MESSAGE_HEADER_MAX_SIZE = 1000;
+
+    private String messageType, version, fileId;
+    private int senderId, chunkNo, replicaDeg;
+
+    public MessageHeader(String rawHeader) {
+        System.out.println("Messageheader: " + rawHeader);
+        String[] sArray = rawHeader.trim().split(" ");
+        this.messageType = sArray[0];
+        this.version = sArray[1];
+        this.senderId = Integer.parseInt(sArray[2]);
+        this.fileId = sArray[3];
+        System.out.println("fileid: " + fileId);
+        if (this.messageType.equals("PUTCHUNK") || this.messageType.equals("STORED")
+                || this.messageType.equals("GETCHUNK") || this.messageType.equals("REMOVED")
+                || this.messageType.equals("CHUNK")) {
+            String cn = sArray[4].replaceAll("[^\\d]", "");
+            this.chunkNo = Integer.parseInt(cn);
+        }
+        if (this.messageType.equals("PUTCHUNK")) {
+            String rep = sArray[5].replaceAll("[^\\d]", "");
+            this.replicaDeg = Integer.parseInt(rep);
+        }
+    }
+
+    public MessageHeader(String messageType, String version, int senderId, String fileId, int chunkNo)
+            throws InvalidHeaderParameters {
+        this.messageType = messageType;
+        if (this.messageType.equals("PUTCHUNK")) {
+            throw new InvalidHeaderParameters();
+        }
+        this.version = version;
+        this.senderId = senderId;
+        this.fileId = fileId;
+        this.chunkNo = chunkNo;
+    }
+
+    public MessageHeader(String messageType, String version, int senderId, String fileId, int chunkNo, int replicaDeg) {
+        this.messageType = messageType;
+        this.version = version;
+        this.senderId = senderId;
+        this.fileId = fileId;
+        this.chunkNo = chunkNo;
+        this.replicaDeg = replicaDeg;
+    }
+
+    public MessageHeader(String messageType, String version, int senderId, String fileId)
+            throws InvalidHeaderParameters {
+        this.messageType = messageType;
+        if (!this.messageType.equals("DELETE")) {
+            throw new InvalidHeaderParameters();
+        }
+        this.version = version;
+        this.senderId = senderId;
+        this.fileId = fileId;
+    }
+
+    public String getMessageType() {
+        return this.messageType;
+    }
+
+    public String getVersion() {
+        return this.version;
+    }
+
+    public int getSenderId() {
+        return this.senderId;
+    }
+
+    public String getFileId() {
+        return this.fileId;
+    }
+
+    public int getChunkNo() {
+        return this.chunkNo;
+    }
+
+    public int getReplicaDeg() {
+        return this.replicaDeg;
+    }
+
+    @Override
+    public String toString() {
+        switch (messageType) {
+        case "GETCHUNK":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + " " + Integer.toString(this.chunkNo) + CRLF;
+        case "PUTCHUNK":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + " " + Integer.toString(this.chunkNo) + " " + Integer.toString(this.replicaDeg) + CRLF;
+        case "STORED":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + " " + Integer.toString(this.chunkNo) + CRLF;
+        case "CHUNK":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + " " + Integer.toString(this.chunkNo) + CRLF;
+        case "DELETE":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + CRLF;
+        case "REMOVED":
+            return this.messageType + " " + this.version + " " + Integer.toString(this.senderId) + " " + this.fileId
+                    + " " + Integer.toString(this.chunkNo) + CRLF;
+        default:
+            return "";
+
+        }
+    }
+}
Index: src/peer/channels/Handler.java
===================================================================
--- src/peer/channels/Handler.java	(revision 2)
+++ src/peer/channels/Handler.java	(revision 3)
@@ -1,118 +1,119 @@
-package peer.channels;
-
-import java.net.DatagramPacket;
-
-import chunk.Chunk;
-import disk.ChunkManagement;
-import peer.Peer;
-import peer.protocols.backup.Store;
-import peer.protocols.reclaim.Reclaim;
-import peer.protocols.restore.GetChunk;
-import message.*;
-
-public class Handler implements Runnable {
-
-    Peer peer;
-    DatagramPacket packet;
-    Message msg;
-    MessageHeader msgHeader;
-
-    public Handler(Peer peer, DatagramPacket packet) {
-        this.peer = peer;
-        this.packet = packet;
-    }
-
-    public void parsePacket() {
-        int packetLength = packet.getLength();
-        byte[] rawData = new byte[packetLength];
-        byte[] packetData = this.packet.getData();
-        System.arraycopy(packetData, packet.getOffset(), rawData, 0, packetLength);
-        this.msg = new Message(rawData);
-        this.msgHeader = msg.getHeader();
-    }
-
-    @Override
-    public void run() {
-
-        parsePacket();
-
-        if (this.peer.getPeerId() != this.msgHeader.getSenderId())
-            switch (this.msgHeader.getMessageType()) {
-            case "PUTCHUNK":
-                handlePUTCHUNK();
-                break;
-            case "GETCHUNK":
-                handleGETCHUNK();
-                break;
-            case "CHUNK":
-                handleCHUNK();
-                break;
-            case "DELETE":
-                handleDELETE();
-                break;
-            case "REMOVED":
-                handleREMOVED();
-                break;
-            default:
-                break;
-            }
-    }
-
-    private void handleREMOVED() {
-        String fileId = this.msgHeader.getFileId();
-        int chunkNo = this.msgHeader.getChunkNo();
-        ChunkManagement.getInstance().registerRemoved(fileId, chunkNo);
-
-        Thread t = new Thread(new Reclaim(peer, fileId, chunkNo));
-        t.start();
-        try {
-            t.join();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public void handlePUTCHUNK() {
-        if (this.peer.getDisk().getFreeSpace() < (packet.getLength())) {
-            System.out.println("Peer " + this.peer.getPeerId() + "- PUTCHUNK request: Not enough space to store chunk");
-            return;
-        }
-
-        Chunk chunk = new Chunk(this.msgHeader.getFileId(), this.msgHeader.getChunkNo(), this.msgHeader.getReplicaDeg(),
-                this.msg.getBody());
-
-        Thread t = new Thread(new Store(peer, chunk));
-        t.start();
-        try {
-            t.join();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-
-    }
-
-    public void handleGETCHUNK() {
-        String fileId = this.msgHeader.getFileId();
-        int chunkNo = this.msgHeader.getChunkNo();
-        Thread t = new Thread(new GetChunk(peer, fileId, chunkNo));
-        t.start();
-        try {
-            t.join();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public void handleCHUNK() {
-        Chunk chunk = new Chunk(this.msgHeader.getFileId(), this.msgHeader.getChunkNo(), this.msgHeader.getReplicaDeg(),
-                this.msg.getBody());
-
-        ChunkManagement.getInstance().addRestoreChunk(chunk);
-    }
-
-    public void handleDELETE() {
-        String fileID = msgHeader.getFileId();
-        this.peer.getDisk().deleteFileDirectory(fileID);
-        ChunkManagement.getInstance().deleteStores(fileID);
-    }
+package peer.channels;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import peer.Peer;
+import peer.protocols.backup.Store;
+import peer.protocols.reclaim.Reclaim;
+import peer.protocols.restore.GetChunk;
+import message.*;
+
+public class Handler implements Runnable {
+
+    Peer peer;
+    DatagramPacket packet;
+    Message msg;
+    MessageHeader msgHeader;
+
+    public Handler(Peer peer, DatagramPacket packet) {
+        this.peer = peer;
+        this.packet = packet;
+    }
+
+    public void parsePacket() {
+        int packetLength = packet.getLength();
+        byte[] rawData = new byte[packetLength];
+        byte[] packetData = this.packet.getData();
+        System.arraycopy(packetData, packet.getOffset(), rawData, 0, packetLength);
+        this.msg = new Message(rawData);
+        this.msgHeader = msg.getHeader();
+    }
+
+    @Override
+    public void run() {
+
+        parsePacket();
+
+        if (this.peer.getPeerId() != this.msgHeader.getSenderId())
+            switch (this.msgHeader.getMessageType()) {
+            case "PUTCHUNK":
+                handlePUTCHUNK();
+                break;
+            case "GETCHUNK":
+                handleGETCHUNK();
+                break;
+            case "CHUNK":
+                handleCHUNK();
+                break;
+            case "DELETE":
+                handleDELETE();
+                break;
+            case "REMOVED":
+                handleREMOVED();
+                break;
+            default:
+                break;
+            }
+    }
+
+    private void handleREMOVED() {
+        String fileId = this.msgHeader.getFileId();
+        int chunkNo = this.msgHeader.getChunkNo();
+        ChunkManagement.getInstance().registerRemoved(fileId, chunkNo);
+
+        Thread t = new Thread(new Reclaim(peer, fileId, chunkNo));
+        t.start();
+        try {
+            t.join();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void handlePUTCHUNK() {
+        if (this.peer.getDisk().getFreeSpace() < (packet.getLength())) {
+            System.out.println("Peer " + this.peer.getPeerId() + "- PUTCHUNK request: Not enough space to store chunk");
+            return;
+        }
+
+        Chunk chunk = new Chunk(this.msgHeader.getFileId(), this.msgHeader.getChunkNo(), this.msgHeader.getReplicaDeg(),
+                this.msg.getBody());
+
+        Thread t = new Thread(new Store(peer, chunk));
+        t.start();
+        try {
+            t.join();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public void handleGETCHUNK() {
+        String fileId = this.msgHeader.getFileId();
+        int chunkNo = this.msgHeader.getChunkNo();
+        Thread t = new Thread(new GetChunk(peer, fileId, chunkNo));
+        t.start();
+        try {
+            t.join();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void handleCHUNK() {
+        Chunk chunk = new Chunk(this.msgHeader.getFileId(), this.msgHeader.getChunkNo(), this.msgHeader.getReplicaDeg(),
+                this.msg.getBody());
+
+        ChunkManagement.getInstance().addRestoreChunk(chunk);
+    }
+
+    public void handleDELETE() {
+        String fileID = msgHeader.getFileId();
+        this.peer.getDisk().deleteFileDirectory(fileID);
+        ChunkManagement.getInstance().deleteStores(fileID);
+    }
 }
\ No newline at end of file
Index: src/peer/channels/Listener.java
===================================================================
--- src/peer/channels/Listener.java	(revision 2)
+++ src/peer/channels/Listener.java	(revision 3)
@@ -1,93 +1,93 @@
-package peer.channels;
-
-import peer.Peer;
-import peer.channels.Handler;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
-import java.net.UnknownHostException;
-
-import message.Message;
-
-import java.net.DatagramPacket;
-
-public class Listener implements Runnable {
-
-    private MulticastSocket socket;
-    private InetAddress address;
-    private int port;
-
-    private Peer peer;
-
-    public Listener(Peer peer, String address, int port) {
-        try {
-            this.address = InetAddress.getByName(address);
-        } catch (UnknownHostException e) {
-            e.printStackTrace();
-        }
-        this.port = port;
-        this.peer = peer;
-    }
-
-    @Override
-    public void run() {
-        try {
-            this.socket = new MulticastSocket(port);
-            socket.setTimeToLive(1);
-            socket.joinGroup(address);
-        } catch (IOException e) {
-            e.printStackTrace();
-            System.exit(1);
-        }
-
-        while (true) {
-            byte[] buf = new byte[Message.MESSAGE_PACKET_MAX_SIZE];
-
-            DatagramPacket packet = new DatagramPacket(buf, buf.length);
-            try {
-                socket.receive(packet);
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            System.out.println("MC Listener: Packet Received!");
-            Thread handler = new Thread(new Handler(peer, packet));
-            handler.start();
-            try {
-                handler.join();
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-        
-    }
-
-    /**
-     * @return the socket
-     */
-    public MulticastSocket getSocket() {
-        return socket;
-    }
-
-    /**
-     * @return the address
-     */
-    public InetAddress getAddress() {
-        return address;
-    }
-
-    /**
-     * @return the port
-     */
-    public int getPort() {
-        return port;
-    }
-
-    /**
-     * @return the peer
-     */
-    public Peer getPeer() {
-        return peer;
-    }
-}
-
+package peer.channels;
+
+import peer.Peer;
+import peer.channels.Handler;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.UnknownHostException;
+
+import message.Message;
+
+import java.net.DatagramPacket;
+
+public class Listener implements Runnable {
+
+    private MulticastSocket socket;
+    private InetAddress address;
+    private int port;
+
+    private Peer peer;
+
+    public Listener(Peer peer, String address, int port) {
+        try {
+            this.address = InetAddress.getByName(address);
+        } catch (UnknownHostException e) {
+            e.printStackTrace();
+        }
+        this.port = port;
+        this.peer = peer;
+    }
+
+    @Override
+    public void run() {
+        try {
+            this.socket = new MulticastSocket(port);
+            socket.setTimeToLive(1);
+            socket.joinGroup(address);
+        } catch (IOException e) {
+            e.printStackTrace();
+            System.exit(1);
+        }
+
+        while (true) {
+            byte[] buf = new byte[Message.MESSAGE_PACKET_MAX_SIZE];
+
+            DatagramPacket packet = new DatagramPacket(buf, buf.length);
+            try {
+                socket.receive(packet);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            System.out.println("MC Listener: Packet Received!");
+            Thread handler = new Thread(new Handler(peer, packet));
+            handler.start();
+            try {
+                handler.join();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        
+    }
+
+    /**
+     * @return the socket
+     */
+    public MulticastSocket getSocket() {
+        return socket;
+    }
+
+    /**
+     * @return the address
+     */
+    public InetAddress getAddress() {
+        return address;
+    }
+
+    /**
+     * @return the port
+     */
+    public int getPort() {
+        return port;
+    }
+
+    /**
+     * @return the peer
+     */
+    public Peer getPeer() {
+        return peer;
+    }
+}
+
Index: src/peer/channels/Sender.java
===================================================================
--- src/peer/channels/Sender.java	(revision 2)
+++ src/peer/channels/Sender.java	(revision 3)
@@ -1,15 +1,15 @@
-package peer.channels;
-
-import java.net.InetAddress;
-
-/**
- * Sender
- */
-public interface Sender {
-
-	public void send(byte[] message);
-
-	public void init(InetAddress address, int port);
-
-	public void destroy();
+package peer.channels;
+
+import java.net.InetAddress;
+
+/**
+ * Sender
+ */
+public interface Sender {
+
+	public void send(byte[] message);
+
+	public void init(InetAddress address, int port);
+
+	public void destroy();
 }
\ No newline at end of file
Index: src/peer/channels/SenderTCP.java
===================================================================
--- src/peer/channels/SenderTCP.java	(revision 2)
+++ src/peer/channels/SenderTCP.java	(revision 3)
@@ -1,38 +1,38 @@
-package peer.channels;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-
-/**
- * SenderTCP
- */
-public class SenderTCP implements Sender {
-
-	private Socket socket;
-
-	public SenderTCP() {
-		
-	}
-
-	@Override
-	public void send(byte[] message) {
-		
-	}
-
-	@Override
-	public void init(InetAddress address, int port) {
-		try {
-			socket = new Socket(address, port);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void destroy() {
-
-	}
-
-	
+package peer.channels;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+
+/**
+ * SenderTCP
+ */
+public class SenderTCP implements Sender {
+
+	private Socket socket;
+
+	public SenderTCP() {
+		
+	}
+
+	@Override
+	public void send(byte[] message) {
+		
+	}
+
+	@Override
+	public void init(InetAddress address, int port) {
+		try {
+			socket = new Socket(address, port);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void destroy() {
+
+	}
+
+	
 }
\ No newline at end of file
Index: src/peer/channels/SenderUDP.java
===================================================================
--- src/peer/channels/SenderUDP.java	(revision 2)
+++ src/peer/channels/SenderUDP.java	(revision 3)
@@ -1,45 +1,45 @@
-package peer.channels;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.SocketException;
-
-/**
- * SenderUDP
- */
-public class SenderUDP implements Sender {
-
-	private DatagramSocket socket;
-
-	public SenderUDP() {
-	}
-
-	@Override
-	public void send(byte[] message) {
-		DatagramPacket packet = new DatagramPacket(message, message.length);
-		try {
-			socket.send(packet);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void init(InetAddress address, int port) {
-		try {
-			socket = new DatagramSocket(port, address);
-		} catch (SocketException e) {
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void destroy() {
-		socket.disconnect();
-	}
-
-
-
+package peer.channels;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+
+/**
+ * SenderUDP
+ */
+public class SenderUDP implements Sender {
+
+	private DatagramSocket socket;
+
+	public SenderUDP() {
+	}
+
+	@Override
+	public void send(byte[] message) {
+		DatagramPacket packet = new DatagramPacket(message, message.length);
+		try {
+			socket.send(packet);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void init(InetAddress address, int port) {
+		try {
+			socket = new DatagramSocket(port, address);
+		} catch (SocketException e) {
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void destroy() {
+		socket.disconnect();
+	}
+
+
+
 }
\ No newline at end of file
Index: src/peer/protocols/backup/Backup.java
===================================================================
--- src/peer/protocols/backup/Backup.java	(revision 2)
+++ src/peer/protocols/backup/Backup.java	(revision 3)
@@ -1,36 +1,36 @@
-package peer.protocols.backup;
-
-import java.io.File;
-
-import chunk.Chunk;
-import peer.Peer;
-
-/**
- * Backup
- */
-public class Backup implements Runnable {
-
-	private Peer peer;
-	private File file;
-	private int repDegree;
-
-	public Backup(Peer peer, String path, int repDegree) {
-		file = new 	File(path);
-		this.peer = peer;
-		this.repDegree = repDegree;
-	}
-
-	public void backupFile() {
-		Chunk[] chunks = Chunk.splitFile(file, repDegree);
-		for (int i = 0;i<chunks.length;i++){
-			BackupChunk backupChunk = new BackupChunk(peer, chunks[i]);
-			Thread bThread = new Thread(backupChunk);
-			bThread.start();
-		}
-	}
-
-	@Override
-	public void run() {
-		backupFile();
-	}
+package peer.protocols.backup;
+
+import java.io.File;
+
+import chunk.Chunk;
+import peer.Peer;
+
+/**
+ * Backup
+ */
+public class Backup implements Runnable {
+
+	private Peer peer;
+	private File file;
+	private int repDegree;
+
+	public Backup(Peer peer, String path, int repDegree) {
+		file = new 	File(path);
+		this.peer = peer;
+		this.repDegree = repDegree;
+	}
+
+	public void backupFile() {
+		Chunk[] chunks = Chunk.splitFile(file, repDegree);
+		for (int i = 0;i<chunks.length;i++){
+			BackupChunk backupChunk = new BackupChunk(peer, chunks[i]);
+			Thread bThread = new Thread(backupChunk);
+			bThread.start();
+		}
+	}
+
+	@Override
+	public void run() {
+		backupFile();
+	}
 }
\ No newline at end of file
Index: src/peer/protocols/backup/BackupChunk.java
===================================================================
--- src/peer/protocols/backup/BackupChunk.java	(revision 2)
+++ src/peer/protocols/backup/BackupChunk.java	(revision 3)
@@ -1,67 +1,67 @@
-package peer.protocols.backup;
-
-import java.io.IOException;
-
-import chunk.Chunk;
-import disk.ChunkManagement;
-import message.Message;
-import peer.Peer;
-
-/**
- * BackupChunk
- */
-public class BackupChunk implements Runnable {
-
-	public static final int backupTries = 10;
-
-	private Chunk chunk;
-	private Peer peer;
-
-	public BackupChunk(Peer peer, Chunk chunk) {
-		this.chunk = chunk;
-		this.peer = peer;
-	}
-
-	public void sendPutChunk() {
-		Message message = Message.parsePutChunkMessage(chunk, peer);
-		try {
-			peer.sendToMdb(message);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public boolean backupChunk() {
-		sendPutChunk();
-		try {
-			Thread.sleep(400);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		if (ChunkManagement.getInstance().getStores(chunk.getFileID(), chunk.getChunkNo()) >= chunk.getRepDegree()) {
-			return true;
-		}
-		return false;
-	}
-
-	@Override
-	public void run() {
-		try {
-			Thread.sleep(400 * chunk.getChunkNo());
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		boolean done = false;
-		int tries = 0;
-		while(!done) {
-			done = backupChunk();
-			if (!done) {
-				tries++;
-				if (tries > backupTries) {
-					break;
-				}
-			}
-		}
-	}
+package peer.protocols.backup;
+
+import java.io.IOException;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import message.Message;
+import peer.Peer;
+
+/**
+ * BackupChunk
+ */
+public class BackupChunk implements Runnable {
+
+	public static final int backupTries = 10;
+
+	private Chunk chunk;
+	private Peer peer;
+
+	public BackupChunk(Peer peer, Chunk chunk) {
+		this.chunk = chunk;
+		this.peer = peer;
+	}
+
+	public void sendPutChunk() {
+		Message message = Message.parsePutChunkMessage(chunk, peer);
+		try {
+			peer.sendToMdb(message);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public boolean backupChunk() {
+		sendPutChunk();
+		try {
+			Thread.sleep(400);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		if (ChunkManagement.getInstance().getStores(chunk.getFileID(), chunk.getChunkNo()) >= chunk.getRepDegree()) {
+			return true;
+		}
+		return false;
+	}
+
+	@Override
+	public void run() {
+		try {
+			Thread.sleep(400 * chunk.getChunkNo());
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		boolean done = false;
+		int tries = 0;
+		while(!done) {
+			done = backupChunk();
+			if (!done) {
+				tries++;
+				if (tries > backupTries) {
+					break;
+				}
+			}
+		}
+	}
 }
\ No newline at end of file
Index: src/peer/protocols/backup/Store.java
===================================================================
--- src/peer/protocols/backup/Store.java	(revision 2)
+++ src/peer/protocols/backup/Store.java	(revision 3)
@@ -1,52 +1,52 @@
-package peer.protocols.backup;
-
-import java.io.IOException;
-
-import chunk.Chunk;
-import disk.ChunkManagement;
-import message.Message;
-import peer.Peer;
-
-/**
- * Store
- */
-public class Store implements Runnable {
-
-	private Peer peer;
-	private Chunk chunk;
-
-	public Store(Peer peer, Chunk chunk) {
-		this.peer = peer;
-		this.chunk = chunk;
-	}
-
-	public void sendStored() {
-		Message storedMessage = Message.parseStoredMessage(chunk, peer);
-		try {
-			peer.sendToMc(storedMessage);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public boolean storeChunk() {
-		try {
-			Thread.sleep((long) (Math.random() * 400 + 1));
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		if (ChunkManagement.getInstance().getStores(chunk.getFileID(), chunk.getChunkNo()) < chunk.getRepDegree()) {
-			if (peer.getDisk().storeChunk(chunk)) {
-				sendStored();
-				return true;
-			}
-		}
-		return false;
-	}
-
-	@Override
-	public void run() {
-		storeChunk();
-	}
-
+package peer.protocols.backup;
+
+import java.io.IOException;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import message.Message;
+import peer.Peer;
+
+/**
+ * Store
+ */
+public class Store implements Runnable {
+
+	private Peer peer;
+	private Chunk chunk;
+
+	public Store(Peer peer, Chunk chunk) {
+		this.peer = peer;
+		this.chunk = chunk;
+	}
+
+	public void sendStored() {
+		Message storedMessage = Message.parseStoredMessage(chunk, peer);
+		try {
+			peer.sendToMc(storedMessage);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public boolean storeChunk() {
+		try {
+			Thread.sleep((long) (Math.random() * 400 + 1));
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		if (ChunkManagement.getInstance().getStores(chunk.getFileID(), chunk.getChunkNo()) < chunk.getRepDegree()) {
+			if (peer.getDisk().storeChunk(chunk)) {
+				sendStored();
+				return true;
+			}
+		}
+		return false;
+	}
+
+	@Override
+	public void run() {
+		storeChunk();
+	}
+
 }
\ No newline at end of file
Index: src/peer/protocols/delete/Delete.java
===================================================================
--- src/peer/protocols/delete/Delete.java	(revision 2)
+++ src/peer/protocols/delete/Delete.java	(revision 3)
@@ -1,43 +1,43 @@
-package peer.protocols.delete;
-
-import java.io.File;
-import java.io.IOException;
-
-import chunk.Chunk;
-import message.Message;
-import peer.Peer;
-
-/**
- * Delete
- */
-public class Delete implements Runnable {
-
-	private Peer peer;
-	private String fileId;
-
-	public Delete(Peer peer, String fileId) {
-		this.peer = peer;
-		File originalFile = new File(fileId);
-		this.fileId = Chunk.generateFileId(originalFile);
-	}
-
-	public void sendDelete() {
-		Message message = Message.parseDeleteMessage(fileId, peer);
-		try {
-			peer.sendToMc(message);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void delete() {
-		peer.getDisk().deleteFileDirectory(fileId);
-		sendDelete();
-	}
-
-	@Override
-	public void run() {
-		delete();
-	}
-
+package peer.protocols.delete;
+
+import java.io.File;
+import java.io.IOException;
+
+import chunk.Chunk;
+import message.Message;
+import peer.Peer;
+
+/**
+ * Delete
+ */
+public class Delete implements Runnable {
+
+	private Peer peer;
+	private String fileId;
+
+	public Delete(Peer peer, String fileId) {
+		this.peer = peer;
+		File originalFile = new File(fileId);
+		this.fileId = Chunk.generateFileId(originalFile);
+	}
+
+	public void sendDelete() {
+		Message message = Message.parseDeleteMessage(fileId, peer);
+		try {
+			peer.sendToMc(message);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void delete() {
+		peer.getDisk().deleteFileDirectory(fileId);
+		sendDelete();
+	}
+
+	@Override
+	public void run() {
+		delete();
+	}
+
 }
\ No newline at end of file
Index: src/peer/protocols/reclaim/Reclaim.java
===================================================================
--- src/peer/protocols/reclaim/Reclaim.java	(revision 2)
+++ src/peer/protocols/reclaim/Reclaim.java	(revision 3)
@@ -1,31 +1,45 @@
-package peer.protocols.reclaim;
-
-import disk.ChunkManagement;
-import peer.Peer;
-
-/**
- * Reclaim
- */
-public class Reclaim implements Runnable {
-
-    private Peer peer;
-    private String fileId;
-    private int chunkNo;
-
-    public Reclaim(Peer peer, String fileId, int chunkNo) {
-        this.peer = peer;
-        this.fileId = fileId;
-        this.chunkNo = chunkNo;
-    }
-
-    public void reclaim() {
-        
-    }
-
-    @Override
-    public void run() {
-        reclaim();
-    }
-
-    
+package peer.protocols.reclaim;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import peer.Peer;
+import peer.protocols.backup.BackupChunk;
+
+/**
+ * Reclaim
+ */
+public class Reclaim implements Runnable {
+
+    private Peer peer;
+    private String fileId;
+    private int chunkNo;
+
+    public Reclaim(Peer peer, String fileId, int chunkNo) {
+        this.peer = peer;
+        this.fileId = fileId;
+        this.chunkNo = chunkNo;
+    }
+
+    public void reclaim() {
+        Chunk chunk = peer.getDisk().getChunk(fileId, chunkNo);
+        if (chunk != null) {
+            try {
+                Thread.sleep((long) (Math.random() * 400 + 1));
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            if (ChunkManagement.getInstance().getStores(fileId, chunkNo) < chunk.getRepDegree()) {
+                BackupChunk backupChunk = new BackupChunk(peer, chunk);
+                Thread bThread = new Thread(backupChunk);
+                bThread.start();
+            }
+        }
+
+    }
+
+    @Override
+    public void run() {
+        reclaim();
+    }
+
 }
\ No newline at end of file
Index: src/peer/protocols/restore/GetChunk.java
===================================================================
--- src/peer/protocols/restore/GetChunk.java	(revision 2)
+++ src/peer/protocols/restore/GetChunk.java	(revision 3)
@@ -1,58 +1,58 @@
-package peer.protocols.restore;
-
-import java.io.IOException;
-
-import chunk.Chunk;
-import disk.ChunkManagement;
-import message.Message;
-import peer.Peer;
-
-/**
- * GetChunk
- */
-public class GetChunk implements Runnable{
-
-    private Peer peer;
-    private String fileId;
-    private int chunkNo;
-
-	public GetChunk(Peer peer, String fileId, int chunkNo) {
-		this.peer = peer;
-        this.fileId = fileId;
-        this.chunkNo = chunkNo;
-    }
-
-    public void sendChunk(Chunk chunk) {
-        Message message = Message.parseChunkMessage(chunk,peer);
-        try {
-			peer.sendToMc(message);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-    }
-    
-    public boolean getChunk() {
-        Chunk chunk = peer.getDisk().getChunk(fileId, chunkNo);
-        if (chunk!= null){
-            try {
-                Thread.sleep((long) (Math.random() * 400 + 1));
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-            if (ChunkManagement.getInstance().getRestoreChunks().contains(chunk)){
-                ChunkManagement.getInstance().getRestoreChunks().remove(chunk);
-                return false;
-            }
-            sendChunk(chunk);
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public void run() {
-        getChunk();
-    }
-
-    
+package peer.protocols.restore;
+
+import java.io.IOException;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import message.Message;
+import peer.Peer;
+
+/**
+ * GetChunk
+ */
+public class GetChunk implements Runnable{
+
+    private Peer peer;
+    private String fileId;
+    private int chunkNo;
+
+	public GetChunk(Peer peer, String fileId, int chunkNo) {
+		this.peer = peer;
+        this.fileId = fileId;
+        this.chunkNo = chunkNo;
+    }
+
+    public void sendChunk(Chunk chunk) {
+        Message message = Message.parseChunkMessage(chunk,peer);
+        try {
+			peer.sendToMc(message);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+    }
+    
+    public boolean getChunk() {
+        Chunk chunk = peer.getDisk().getChunk(fileId, chunkNo);
+        if (chunk!= null){
+            try {
+                Thread.sleep((long) (Math.random() * 400 + 1));
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            if (ChunkManagement.getInstance().getRestoreChunks().contains(chunk)){
+                ChunkManagement.getInstance().getRestoreChunks().remove(chunk);
+                return false;
+            }
+            sendChunk(chunk);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void run() {
+        getChunk();
+    }
+
+    
 }
\ No newline at end of file
Index: src/peer/protocols/restore/Restore.java
===================================================================
--- src/peer/protocols/restore/Restore.java	(revision 2)
+++ src/peer/protocols/restore/Restore.java	(revision 3)
@@ -1,72 +1,71 @@
-package peer.protocols.restore;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.concurrent.BlockingQueue;
-
-import chunk.Chunk;
-import disk.ChunkManagement;
-import message.Message;
-import peer.Peer;
-import peer.channels.Sender;
-import peer.channels.SenderUDP;
-
-/**
- * Restore
- */
-public class Restore implements Runnable {
-
-	private Peer peer;
-	private String filePath;
-	private File file;
-
-	public Restore(Peer peer, String filePath) {
-		this.peer = peer;
-		this.filePath = filePath;
-		file = new File(filePath);
-	}
-
-	public void sendGetChunk(int chunkNo) {
-		Message message = Message.parseGetChunkMessage(Chunk.generateFileId(file), chunkNo, peer);
-		try {
-			peer.sendToMc(message);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void restore() {
-		File originalFile = new File(filePath);
-		if (!originalFile.exists()) {
-			System.out.println("file not found");
-			return;
-		}
-		int chunksNo = Chunk.getNumberOfFileChunks(originalFile);
-		Chunk[] chunks = new Chunk[chunksNo];
-		String fileId = Chunk.generateFileId(originalFile);
-		for (int i = 0; i < chunksNo; i++) {
-			sendGetChunk(i + 1);
-			BlockingQueue<Chunk> queue = ChunkManagement.getInstance().getRestoreChunks();
-			try {
-				System.out.println("Waiting for chunk " + (i+1));
-				Chunk chunk = queue.take();
-				if (chunk.getFileID().equals(fileId)){
-					chunks[i] = chunk;
-					System.out.println("received chunk " + chunk.getChunkNo());
-				}
-				else {
-					queue.put(chunk);
-				}
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-		peer.getDisk().restoreFile(chunks,originalFile.getName());
-	}
-
-	@Override
-	public void run() {
-		restore();
-	}
-
-}
\ No newline at end of file
+package peer.protocols.restore;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.BlockingQueue;
+
+import chunk.Chunk;
+import disk.ChunkManagement;
+import message.Message;
+import peer.Peer;
+import peer.channels.Sender;
+import peer.channels.SenderUDP;
+
+/**
+ * Restore
+ */
+public class Restore implements Runnable {
+
+	private Peer peer;
+	private String filePath;
+	private File file;
+
+	public Restore(Peer peer, String filePath) {
+		this.peer = peer;
+		this.filePath = filePath;
+		file = new File(filePath);
+	}
+
+	public void sendGetChunk(int chunkNo) {
+		Message message = Message.parseGetChunkMessage(Chunk.generateFileId(file), chunkNo, peer);
+		try {
+			peer.sendToMc(message);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void restore() {
+		File originalFile = new File(filePath);
+		if (!originalFile.exists()) {
+			System.out.println("file not found");
+			return;
+		}
+		int chunksNo = Chunk.getNumberOfFileChunks(originalFile);
+		Chunk[] chunks = new Chunk[chunksNo];
+		String fileId = Chunk.generateFileId(originalFile);
+		int i=0;
+		while (i < chunksNo) {
+			sendGetChunk(i + 1);
+			BlockingQueue<Chunk> queue = ChunkManagement.getInstance().getRestoreChunks();
+			try {
+				System.out.println("Waiting for chunk " + (i+1));
+				Chunk chunk = queue.take();
+				if (chunk.getFileID().equals(fileId) && chunk.getChunkNo() == i+1){
+					chunks[i] = chunk;
+					i++;
+					System.out.println("received chunk " + chunk.getChunkNo());
+				}
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		peer.getDisk().restoreFile(chunks,originalFile.getName());
+	}
+
+	@Override
+	public void run() {
+		restore();
+	}
+
+}
Index: src/peer/Peer.java
===================================================================
--- src/peer/Peer.java	(revision 2)
+++ src/peer/Peer.java	(revision 3)
@@ -1,300 +1,300 @@
-package peer;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
-import java.net.UnknownHostException;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
-import java.rmi.server.UnicastRemoteObject;
-
-import disk.Disk;
-import message.Message;
-import peer.channels.Listener;
-import peer.protocols.backup.Backup;
-import peer.protocols.delete.Delete;
-import peer.protocols.restore.Restore;
-
-public class Peer /*extends UnicastRemoteObject*/ implements PeerInterface {
-
-	//private static final long serialVersionUID = 4988282307993613946L;
-
-	private int peerId;
-	private Disk disk;
-
-	private Registry rmiReg;
-
-	private String pVersion;
-	private String accessPoint;
-
-	private MulticastSocket socket;
-
-	private InetAddress mcAddress;
-	private InetAddress mdbAddress;
-	private InetAddress mdrAddress;
-	private int mcPort;
-	private int mdbPort;
-	private int mdrPort;
-
-	private Listener mcChannel;
-	private Listener mdbChannel;
-	private Listener mdrChannel;
-
-	public Peer(String pVersion, int sid, String accessPoint, String mcAddress, int mcPort, String mdbAddress,
-			int mdbPort, String mdrAddress, int mdrPort) throws RemoteException {
-		
-		this.peerId = sid;
-
-		try {
-			this.mcAddress = InetAddress.getByName(mcAddress);
-			this.mdbAddress = InetAddress.getByName(mdbAddress);
-			this.mdrAddress = InetAddress.getByName(mdrAddress);
-		} catch (UnknownHostException e1) {
-			e1.printStackTrace();
-		}
-
-		this.mcPort = mcPort;
-		this.mdbPort = mdbPort;
-		this.mdrPort = mdrPort;
-
-		this.disk = new Disk("peer" + peerId);
-		this.pVersion = pVersion;
-		this.accessPoint = accessPoint;
-		this.rmiReg = null;
-		try {
-			this.socket = new MulticastSocket();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-
-		this.startRMI();
-
-		try {
-			this.startChannels(mcAddress, mcPort, mdbAddress, mdbPort, mdrAddress, mdrPort);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-
-		System.out.println("Peer " + this.peerId + " running...");
-	}
-
-	public static void main(String[] args) {
-		int id = Integer.parseInt(args[1]);
-		int mcPort = Integer.parseInt(args[4]);
-		int mdbPort = Integer.parseInt(args[6]);
-		int mdrPort = Integer.parseInt(args[8]);
-		Peer peer;
-		try {
-			peer = new Peer(args[0], id, args[2], args[3], mcPort, args[5], mdbPort, args[7], mdrPort);
-		} catch (RemoteException e) {
-			e.printStackTrace();
-			return;
-		}
-		//String filePath = Disk.resourcesPath + "loremipsum.pdf";
-		
-	}
-
-	public void startRMI() {
-		try {
-			try {
-				this.rmiReg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
-			} catch(Exception e) {
-				this.rmiReg = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
-			}
-			PeerInterface stub = (PeerInterface) UnicastRemoteObject.exportObject(this, 0);
-			rmiReg.rebind(this.accessPoint, stub);
-		} catch (RemoteException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void startChannels(String mcA, int mcP, String mdbA, int mdbP, String mdrA, int mdrP) throws IOException {
-
-		this.mcChannel = new Listener(this, mcA, mcP);
-		this.mdbChannel = new Listener(this, mdbA, mdbP);
-		this.mdrChannel = new Listener(this, mdrA, mdrP);
-
-		Thread mcListener = new Thread(this.mcChannel);
-		Thread mdbListener = new Thread(this.mdbChannel);
-		Thread mdrListener = new Thread(this.mdrChannel);
-
-		mcListener.start();
-		mdbListener.start();
-		mdrListener.start();
-	}
-
-	public void backup(String path, int replicationDeg) {
-		Thread t = new Thread(new Backup(this, path, replicationDeg));
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void delete(String path) {
-		Thread t = new Thread(new Delete(this, path));
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void restore(String path) {
-		Thread t = new Thread(new Restore(this, path));
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void reclaim(float space) {
-
-	}
-
-	public String state() {
-		return "test";
-	}
-
-	public void sendToMc(Message m) throws IOException {
-
-		byte[] buf = m.toBytes();
-
-		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mcChannel.getAddress(),
-				this.mcChannel.getPort());
-		socket.send(packet);
-
-	}
-
-	public void sendToMdb(Message m) throws IOException {
-
-		byte[] buf = m.toBytes();
-
-		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mdbChannel.getAddress(),
-				this.mdbChannel.getPort());
-		socket.send(packet);
-	}	
-
-	public void sendToMdr(Message m) throws IOException {
-
-		byte[] buf = m.toBytes();
-
-		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mdrChannel.getAddress(),
-				this.mdrChannel.getPort());
-		socket.send(packet);
-
-	}
-
-	/**
-	 * @return the peerId
-	 */
-	public int getPeerId() {
-		return peerId;
-	}
-
-	/**
-	 * @return the disk
-	 */
-	public Disk getDisk() {
-		return disk;
-	}
-
-	/**
-	 * @return the rmiReg
-	 */
-	public Registry getRmiReg() {
-		return rmiReg;
-	}
-
-	/**
-	 * @return the pVersion
-	 */
-	public String getpVersion() {
-		return pVersion;
-	}
-
-	/**
-	 * @return the accessPoint
-	 */
-	public String getAccessPoint() {
-		return accessPoint;
-	}
-
-	/**
-	 * @return the socket
-	 */
-	public MulticastSocket getSocket() {
-		return socket;
-	}
-
-	/**
-	 * @return the mcChannel
-	 */
-	public Listener getMcChannel() {
-		return mcChannel;
-	}
-
-	/**
-	 * @return the mdbChannel
-	 */
-	public Listener getMdbChannel() {
-		return mdbChannel;
-	}
-
-	/**
-	 * @return the mdrChannel
-	 */
-	public Listener getMdrChannel() {
-		return mdrChannel;
-	}
-
-	/**
-	 * @return the mcAddress
-	 */
-	public InetAddress getMcAddress() {
-		return mcAddress;
-	}
-
-	/**
-	 * @return the mcPort
-	 */
-	public int getMcPort() {
-		return mcPort;
-	}
-
-	/**
-	 * @return the mdbAddress
-	 */
-	public InetAddress getMdbAddress() {
-		return mdbAddress;
-	}
-
-	/**
-	 * @return the mdbPort
-	 */
-	public int getMdbPort() {
-		return mdbPort;
-	}
-
-	/**
-	 * @return the mdrAddress
-	 */
-	public InetAddress getMdrAddress() {
-		return mdrAddress;
-	}
-
-	/**
-	 * @return the mdrPort
-	 */
-	public int getMdrPort() {
-		return mdrPort;
-	}
-
+package peer;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.UnknownHostException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+
+import disk.Disk;
+import message.Message;
+import peer.channels.Listener;
+import peer.protocols.backup.Backup;
+import peer.protocols.delete.Delete;
+import peer.protocols.restore.Restore;
+
+public class Peer /*extends UnicastRemoteObject*/ implements PeerInterface {
+
+	//private static final long serialVersionUID = 4988282307993613946L;
+
+	private int peerId;
+	private Disk disk;
+
+	private Registry rmiReg;
+
+	private String pVersion;
+	private String accessPoint;
+
+	private MulticastSocket socket;
+
+	private InetAddress mcAddress;
+	private InetAddress mdbAddress;
+	private InetAddress mdrAddress;
+	private int mcPort;
+	private int mdbPort;
+	private int mdrPort;
+
+	private Listener mcChannel;
+	private Listener mdbChannel;
+	private Listener mdrChannel;
+
+	public Peer(String pVersion, int sid, String accessPoint, String mcAddress, int mcPort, String mdbAddress,
+			int mdbPort, String mdrAddress, int mdrPort) throws RemoteException {
+		
+		this.peerId = sid;
+
+		try {
+			this.mcAddress = InetAddress.getByName(mcAddress);
+			this.mdbAddress = InetAddress.getByName(mdbAddress);
+			this.mdrAddress = InetAddress.getByName(mdrAddress);
+		} catch (UnknownHostException e1) {
+			e1.printStackTrace();
+		}
+
+		this.mcPort = mcPort;
+		this.mdbPort = mdbPort;
+		this.mdrPort = mdrPort;
+
+		this.disk = new Disk("peer" + peerId);
+		this.pVersion = pVersion;
+		this.accessPoint = accessPoint;
+		this.rmiReg = null;
+		try {
+			this.socket = new MulticastSocket();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		this.startRMI();
+
+		try {
+			this.startChannels(mcAddress, mcPort, mdbAddress, mdbPort, mdrAddress, mdrPort);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		System.out.println("Peer " + this.peerId + " running...");
+	}
+
+	public static void main(String[] args) {
+		int id = Integer.parseInt(args[1]);
+		int mcPort = Integer.parseInt(args[4]);
+		int mdbPort = Integer.parseInt(args[6]);
+		int mdrPort = Integer.parseInt(args[8]);
+		Peer peer;
+		try {
+			peer = new Peer(args[0], id, args[2], args[3], mcPort, args[5], mdbPort, args[7], mdrPort);
+		} catch (RemoteException e) {
+			e.printStackTrace();
+			return;
+		}
+		//String filePath = Disk.resourcesPath + "loremipsum.pdf";
+		
+	}
+
+	public void startRMI() {
+		try {
+			try {
+				this.rmiReg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
+			} catch(Exception e) {
+				this.rmiReg = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
+			}
+			PeerInterface stub = (PeerInterface) UnicastRemoteObject.exportObject(this, 0);
+			rmiReg.rebind(this.accessPoint, stub);
+		} catch (RemoteException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void startChannels(String mcA, int mcP, String mdbA, int mdbP, String mdrA, int mdrP) throws IOException {
+
+		this.mcChannel = new Listener(this, mcA, mcP);
+		this.mdbChannel = new Listener(this, mdbA, mdbP);
+		this.mdrChannel = new Listener(this, mdrA, mdrP);
+
+		Thread mcListener = new Thread(this.mcChannel);
+		Thread mdbListener = new Thread(this.mdbChannel);
+		Thread mdrListener = new Thread(this.mdrChannel);
+
+		mcListener.start();
+		mdbListener.start();
+		mdrListener.start();
+	}
+
+	public void backup(String path, int replicationDeg) {
+		Thread t = new Thread(new Backup(this, path, replicationDeg));
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void delete(String path) {
+		Thread t = new Thread(new Delete(this, path));
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void restore(String path) {
+		Thread t = new Thread(new Restore(this, path));
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void reclaim(float space) {
+
+	}
+
+	public String state() {
+		return "test";
+	}
+
+	public void sendToMc(Message m) throws IOException {
+
+		byte[] buf = m.toBytes();
+
+		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mcChannel.getAddress(),
+				this.mcChannel.getPort());
+		socket.send(packet);
+
+	}
+
+	public void sendToMdb(Message m) throws IOException {
+
+		byte[] buf = m.toBytes();
+
+		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mdbChannel.getAddress(),
+				this.mdbChannel.getPort());
+		socket.send(packet);
+	}	
+
+	public void sendToMdr(Message m) throws IOException {
+
+		byte[] buf = m.toBytes();
+
+		DatagramPacket packet = new DatagramPacket(buf, buf.length, this.mdrChannel.getAddress(),
+				this.mdrChannel.getPort());
+		socket.send(packet);
+
+	}
+
+	/**
+	 * @return the peerId
+	 */
+	public int getPeerId() {
+		return peerId;
+	}
+
+	/**
+	 * @return the disk
+	 */
+	public Disk getDisk() {
+		return disk;
+	}
+
+	/**
+	 * @return the rmiReg
+	 */
+	public Registry getRmiReg() {
+		return rmiReg;
+	}
+
+	/**
+	 * @return the pVersion
+	 */
+	public String getpVersion() {
+		return pVersion;
+	}
+
+	/**
+	 * @return the accessPoint
+	 */
+	public String getAccessPoint() {
+		return accessPoint;
+	}
+
+	/**
+	 * @return the socket
+	 */
+	public MulticastSocket getSocket() {
+		return socket;
+	}
+
+	/**
+	 * @return the mcChannel
+	 */
+	public Listener getMcChannel() {
+		return mcChannel;
+	}
+
+	/**
+	 * @return the mdbChannel
+	 */
+	public Listener getMdbChannel() {
+		return mdbChannel;
+	}
+
+	/**
+	 * @return the mdrChannel
+	 */
+	public Listener getMdrChannel() {
+		return mdrChannel;
+	}
+
+	/**
+	 * @return the mcAddress
+	 */
+	public InetAddress getMcAddress() {
+		return mcAddress;
+	}
+
+	/**
+	 * @return the mcPort
+	 */
+	public int getMcPort() {
+		return mcPort;
+	}
+
+	/**
+	 * @return the mdbAddress
+	 */
+	public InetAddress getMdbAddress() {
+		return mdbAddress;
+	}
+
+	/**
+	 * @return the mdbPort
+	 */
+	public int getMdbPort() {
+		return mdbPort;
+	}
+
+	/**
+	 * @return the mdrAddress
+	 */
+	public InetAddress getMdrAddress() {
+		return mdrAddress;
+	}
+
+	/**
+	 * @return the mdrPort
+	 */
+	public int getMdrPort() {
+		return mdrPort;
+	}
+
 }
\ No newline at end of file
Index: src/peer/PeerInterface.java
===================================================================
--- src/peer/PeerInterface.java	(revision 2)
+++ src/peer/PeerInterface.java	(revision 3)
@@ -1,12 +1,12 @@
-package peer;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-
-public interface PeerInterface extends Remote {
-    void backup(String path,int replicationDeg) throws RemoteException;
-    void delete(String path) throws RemoteException;
-    void restore(String path) throws RemoteException;
-    void reclaim(float space) throws RemoteException;
-    String state() throws  RemoteException;
+package peer;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface PeerInterface extends Remote {
+    void backup(String path,int replicationDeg) throws RemoteException;
+    void delete(String path) throws RemoteException;
+    void restore(String path) throws RemoteException;
+    void reclaim(float space) throws RemoteException;
+    String state() throws  RemoteException;
 }
\ No newline at end of file
Index: src/utils/Utils.java
===================================================================
--- src/utils/Utils.java	(revision 2)
+++ src/utils/Utils.java	(revision 3)
@@ -1,49 +1,60 @@
-package utils;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Utils
- */
-public class Utils {
-
-    public static boolean isInteger(String s) {
-        if (s.isEmpty())
-            return false;
-        for (int i = 0; i < s.length(); i++) {
-            if (i == 0 && s.charAt(i) == '-') {
-                if (s.length() == 1)
-                    return false;
-                else
-                    continue;
-            }
-            if (Character.digit(s.charAt(i), 10) < 0)
-                return false;
-        }
-        return true;
-    }
-
-    public static boolean fileExists(String filePath) {
-        return new File(filePath).isFile();
-    }
-
-    public static boolean isFloat(String s) {
-        return s.matches("[0-9]*\\.?[0-9]+");
-    }
-
-    public static boolean deleteDirectoryRecursively(File file) /*throws IOException */{
-        
-        File[] files = file.listFiles();
-        if(files!=null) {
-            for(File f: files) {
-                if(f.isDirectory()) {
-                    deleteDirectoryRecursively(f);
-                } else {
-                    f.delete();
-                }
-            }
-        }
-        return file.delete();
-    }
+package utils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Utils
+ */
+public class Utils {
+
+    public static boolean isInteger(String s) {
+        if (s.isEmpty())
+            return false;
+        for (int i = 0; i < s.length(); i++) {
+            if (i == 0 && s.charAt(i) == '-') {
+                if (s.length() == 1)
+                    return false;
+                else
+                    continue;
+            }
+            if (Character.digit(s.charAt(i), 10) < 0)
+                return false;
+        }
+        return true;
+    }
+
+    public static boolean fileExists(String filePath) {
+        return new File(filePath).isFile();
+    }
+
+    public static boolean isFloat(String s) {
+        return s.matches("[0-9]*\\.?[0-9]+");
+    }
+
+    public static boolean deleteDirectoryRecursively(File file) /*throws IOException */{
+        /*if (file.isDirectory()) {
+            File[] entries = file.listFiles();
+            if (entries != null) {
+                for (File entry : entries) {
+                    deleteDirectoryRecursively(entry);
+                }
+            }
+        }
+        return file.delete();
+        if (!file.delete()) {
+            throw new IOException("Failed to delete " + file);
+        }*/
+        File[] files = file.listFiles();
+        if(files!=null) {
+            for(File f: files) {
+                if(f.isDirectory()) {
+                    deleteDirectoryRecursively(f);
+                } else {
+                    f.delete();
+                }
+            }
+        }
+        return file.delete();
+    }
 }
\ No newline at end of file
Index: compile.sh
===================================================================
--- compile.sh	(nonexistent)
+++ compile.sh	(revision 3)
@@ -0,0 +1,2 @@
+find -name *.java > sources.txt
+javac @sources.txt -d ./bin

Property changes on: compile.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
