Index: Server.java
===================================================================
--- Server.java	(revision 1)
+++ Server.java	(revision 2)
@@ -50,7 +50,8 @@
     // State Restore
     public boolean restoring;
     public AtomicBoolean waitRestoreReply = new AtomicBoolean(false);
-    public ConcurrentHashMap<String, Chunk> recoveredChunks = new ConcurrentHashMap<String, Chunk>(); // ChunkNo -> Chunk
+    public ConcurrentHashMap<String, Chunk> recoveredChunks = new ConcurrentHashMap<String, Chunk>(); // ChunkNo ->
+                                                                                                      // Chunk
 
     // Service Management Information
     public ConcurrentHashMap<String, Chunk> chunks = new ConcurrentHashMap<String, Chunk>(); // fileId-ChunkNo
@@ -85,8 +86,6 @@
     // Backup Protocol
     public void backup(String path, int replications) throws RemoteException {
 
-        // TODO is file backed up already?
-
         // Start backup
         this.doingBackUp = true;
 
@@ -94,11 +93,15 @@
         int index = path.lastIndexOf("\\");
         String fileName = path.substring(index + 1);
 
-        // Generate Hash
-        // TODO dont use just file name for hashing(multiple file versions with same
-        // name problem)
-        String fileId = FileManager.hash(fileName);
+        // Generate Hash from file name and date
+        String fileId = FileManager.hash(fileName + Long.toString(new File(path).lastModified()));
 
+        // Is file backed up already?
+        if (this.files.get(fileId) != null) {
+            System.out.println("File already backed up");
+            return;
+        }
+
         // Add to file list
         this.files.put(fileId, fileName);
 
@@ -161,10 +164,8 @@
         int index = path.lastIndexOf("\\");
         String fileName = path.substring(index + 1);
 
-        // Generate Hash
-        // TODO dont use just file name for hashing(multiple file versions with same
-        // name problem)
-        String fileId = FileManager.hash(fileName);
+        // Generate Hash from file name and date
+        String fileId = FileManager.hash(fileName + Long.toString(new File(path).lastModified()));
 
         // Find in list of backed up
         String name = this.files.get(fileId);
@@ -171,6 +172,7 @@
 
         // File not backed up yet, just return
         if (name == null) {
+            System.out.println("File not backed up by this peer");
             return;
         }
 
@@ -200,12 +202,18 @@
 
                 // Wait for response
                 this.waitRestoreReply.set(true);
+                long time = System.nanoTime();
                 while (this.waitRestoreReply.get()) {
+                    // Restore timeout
+                    if (TimeUnit.NANOSECONDS.toMillis(time) - TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) > 1000) {
+                        System.out.println("Restore timeout, missing chunks");
+                        return;
+                    }
                 }
 
-            }      
+            }
 
-            //Get simple list from recovered chunks
+            // Get simple list from recovered chunks
             List<Chunk> list = new ArrayList<Chunk>(this.recoveredChunks.values());
 
             // Sort chunks
@@ -248,11 +256,15 @@
         int index = path.lastIndexOf("\\");
         String fileName = path.substring(index + 1);
 
-        // Generate Hash
-        // TODO dont use just file name for hashing(multiple file versions with same
-        // name problem)
-        String fileId = FileManager.hash(fileName);
+        // Generate Hash from file name and date
+        String fileId = FileManager.hash(fileName + Long.toString(new File(path).lastModified()));
 
+        // Remove from list of backed up
+        String name = this.files.get(fileId);
+        if (name != null) {
+            this.files.remove(fileId);
+        }
+
         try {
 
             // Prepare message
@@ -307,7 +319,8 @@
 
                 // Remove from file system
                 Path current = Paths.get("");
-                String place = current.toAbsolutePath().toString() + "\\peer" + id + "\\backup\\" + entry.getValue().fileId + "\\chk" + entry.getValue().chunkN + ".chk";
+                String place = current.toAbsolutePath().toString() + "\\peer" + id + "\\backup\\"
+                        + entry.getValue().fileId + "\\chk" + entry.getValue().chunkN + ".chk";
                 File toDelete = new File(place);
                 toDelete.delete();
 
@@ -437,28 +450,34 @@
 
     public static void main(String args[]) {
 
-        // TODO Arguments are not correct, need to receive all the specific socket
-        // arguments too, version and server(RMI)
+        try {
 
-        // Check arguments
-        if (args.length < 1) {
-            System.err.println("Invalid number of arguments");
-            return;
-        }
+            // Server object
+            Server obj;
 
-        try {
+            // Basic (version id)
+            if (args.length == 2) {
+                obj = new Server(args[1]);
+            }
+            // Full (version id access port mc port mdb port mdr)
+            else if (args.length == 9) {
+                obj = new Server(args[1], Integer.parseInt(args[3]), args[4], Integer.parseInt(args[5]), args[6],
+                        Integer.parseInt(args[7]), args[8]);
+            }
+            // Invalid arguments
+            else {
+                System.out.println("java Server <version> <server id>");
+                System.out.println(
+                        "java Server <version> <server id> <access_point> <MC_port> <MC_IP_address> <MDB_port> <MDB_IP_address> <MDR_port> <MDR_IP_address>");
+                return;
+            }
 
-            // Create Server
-            Server obj = new Server(args[0]);
-
             // Bind the server as a registry
             PeerInterface stub = (PeerInterface) UnicastRemoteObject.exportObject(obj, 0);
 
             // Bind the remote object's stub in the registry
-
-            // TODO Get registry what port?
             Registry registry = LocateRegistry.getRegistry();
-            registry.bind(args[0], stub);
+            registry.bind(obj.id, stub);
 
             System.err.println("Server ready");
 
