public boolean connect(SharingPeer peer) {
		Socket socket = new Socket();
		if(socket == null){
			logger.error("Could not create socket!");
			return false;
		}
		
		InetSocketAddress address = new InetSocketAddress(peer.getIp(),
				peer.getPort());

		logger.debug("Connecting to {}...", peer);
		try {
			socket.connect(address, SOCKET_CONNECTION_TIMEOUT);
		} catch (IOException ioe) {
			// Could not connect to peer, abort
			logger.warn("Could not connect to {}: {}", peer, ioe.getMessage());
			return false;
		}

		try {
			socket.setSoTimeout(1000*SOCKET_READ_TIMEOUT_SECONDS);
			this.sendHandshake(socket);
			Handshake hs = this.validateHandshake(socket,
					(peer.hasPeerId() ? peer.getPeerId().array() : null));
			this.fireNewPeerConnection(socket, hs.getPeerId());
			return true;
		} catch (ParseException pe) {
			logger.error("Invalid handshake from {}: {}",
				this.socketRepr(socket), pe.getMessage());
			try { socket.close(); } catch (IOException e) { }
		} catch (IOException ioe) {
			logger.error("An error occured while reading an incoming " +
					"handshake: {}", ioe.getMessage());
			try {
				if (!socket.isClosed()) {
					socket.close();
				}
			} catch (IOException e) {
				// Ignore
			}
		}

		return false;
	}