@Override
	public void receiveFile(InetAddress sender, String fileName, boolean isOwner) {
		try {
			// If this node is the owner of the file and the file doesn't exist in the records, create a new record for it
			// and add the sender to the list of nodes where it is available
			int senderHash = nameServer.reverseLookupNode(sender.getHostAddress());
			if (isOwner) {
				boolean hasTheFile = false;
				int fileHash = nameServer.getShortHash(fileName);
				// Check if file exists in records
				for (FileRecord record : ownedFiles) {
					if (fileName.equals(record.getFileName())) {
						hasTheFile = true;
						record.addNode(senderHash);
						break;
					}
				}
				
				
				InetAddress previousNode = nameServer.lookupNode(previousNodeHash);

				// If file doesn't exists in records, create one and add sender to available locations
				if (!hasTheFile){
					FileRecord newRecord = new FileRecord(fileName, fileHash);
					newRecord.addNode(senderHash);
					ownedFiles.add(newRecord);
				}
				// Else file already exists in records, replicate this file to previous node (if that was not the sender)
				else if (!sender.equals(previousNode)) {
					File file = Paths.get(OWNED_FILE_PATH + fileName).toFile();
					try {
						tcp.sendFile(previousNode, file, false);
					} catch (IOException e) {
						// Remote node could not be reached and should be removed
						removeFailedNode(senderHash);
					}

				}
			}
			// If node is not the owner, add the file to the replicated files
			else {
				localFiles.add(fileName);
			}

			// If this node requested a lock for the file, request a release
			if (lockRequests.containsKey(fileName) && (lockRequests.get(fileName) == null)) {
				lockRequests.put(fileName, false);
			}
		} catch (RemoteException e) {
			System.err.println("Unable to contact nameServer");
			e.printStackTrace();
		}

	}