@Override
	public MessageResponse upload(UploadRequest request) throws IOException
	{
		setQuorums();
		if(username.equals(""))
		{
			return new MessageResponse("Please log in first.");
		}
		else
		{
			synchronized(serverIdentifier)
			{
				if(serverIdentifier.isEmpty())
				{
					return new MessageResponse("No servers available.");
				}
				int version = -10;
				synchronized(readQuorum)
				{
					for(FileServerInfo f : readQuorum.values())
					{
						version = Math.max(version, getVersionNumberFromFileServer(request.getFilename(), f));
					}
				}
				System.out.println("Version before " + version);
				if(version != -1)
				{
					version++;
				}
				else
				{
					version = 1;
				}
				System.out.println("Version after " + version);
				synchronized(writeQuorum)
				{
					for(FileServerInfo f : writeQuorum.values())
					{
						UploadRequest tmp = new UploadRequest("", request.getFilename(), version, request.getContent());
						UploadRequest updatedRequest = new UploadRequest(hMac.createHash(tmp.toString()), tmp.getFilename(), tmp.getVersion(), tmp.getContent());
						Socket socket = new Socket(f.getAddress(), f.getPort());
						ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
						oos.flush();
						ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
						String s = new String(updatedRequest.getContent());

						oos.writeObject(updatedRequest);
						oos.flush();

						try
						{
							MessageResponse response = (MessageResponse) ois.readObject();
							if(!hMac.verifyHash(response.gethMac(), response.toString()))
							{
								System.out.println("This message has been tampered with: " + response.toString());
							}
							if(response.getMessage().equals("!again"))
							{
								return upload(request);
							}
						} 
						catch (ClassNotFoundException e)
						{
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						long fileSize = s.length();
						synchronized(users)
						{
							UserInfo old = users.get(username);
							UserInfo info = new UserInfo(username, old.getCredits()+fileSize*2, old.isOnline());
							users.put(username, info);
						}
						oos.close();
						ois.close();
						socket.close();
						writeQuorum.put(f.getPort(), new FileServerInfo(f.getAddress(), f.getPort(), f.getUsage()+fileSize, true));
					}
				}
				synchronized(users)
				{
					return new MessageResponse("Uploaded file to server, new Credits: "+users.get(username).getCredits());
				}
			}
		}
	}