public void initalizeConnection(byte [] announcedMap,Torrent t){
		peerBitMap = new BitMap(t.totalBytes,t.pieceLength);
		metaData = t.meta;//must be initialized
		if(conState != ConnectionState.uninitialized){throw new RuntimeException("Invalid State Exception");}
		conState = ConnectionState.pending;
		if(sock == null){ //Outbound connection.
			sock = new Socket();
			
			//Threading the connect phase.
			//TODO: Check conventions if this is ok.
			new Thread(){
				@Override
				public void run(){
					try {
						sock.setKeepAlive(true);
						sock.setSoTimeout(2*60*1000);//2 min timeout
						sock.setReceiveBufferSize(1024*1024*2);
						sock.setSendBufferSize(1024*1024*2);
						sock.connect(new InetSocketAddress(ip, port));//BLOCKS!
						sockOut = sock.getOutputStream();
						sockIn = sock.getInputStream();
						if(sock.isConnected()){
							conState = ConnectionState.connected;
						}else{
							//should have thrown error.
							conState = ConnectionState.closed;
						}
					} catch (IOException e) {
						e.printStackTrace();
						conState = ConnectionState.closed;
					}
				}
			}.start();
		}else if(recvHandShake==true){//Inbound connection
			try {
				sockOut = sock.getOutputStream();
				sockIn = sock.getInputStream();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
			
			conState = ConnectionState.connected;
			sentHandShake=true;
			try{
			mp.sendHandShake(sockOut, t.getInfoHash(), t.getPeerID());
			mp.bitfield(sockOut, announcedMap);
			}catch(IOException io){
				conState = ConnectionState.closed;
			}
		}else{
			throw new RuntimeException("State uknown");
		}
		
		if(announcedMap==null || announcedMap.length!=peerBitMap.getLength()){
			throw new RuntimeException("Invalid announced map. Either null or incorrect length!");
		}
		this.announcedMap=announcedMap;
	}