   require Bitwise
   require Logger
   require IEx
+  alias BittorrentClient.TCPConn, as: TCPConn
   alias BittorrentClient.Peer.Data, as: PeerData
   alias BittorrentClient.Peer.TorrentTrackingInfo, as: TorrentTrackingInfo
   alias BittorrentClient.Peer.Protocol, as: PeerProtocol

         ) do
      {:ok, next_piece_index} ->
        next_sub_piece_index = 0
        Logger.debug(fn -> "attempting to get #{next_piece_index}:#{next_sub_piece_index}" end)
        msg2 =
          PeerProtocol.encode(:request, next_piece_index, next_sub_piece_index)


    peer_data
  end

  @spec loop_msgs(list(map()), TCPConn.t, PeerData.t)  :: PeerData.t
  def loop_msgs([msg | msgs], socket, peer_data) do
    new_peer_data = handle_message(msg.type, msg, socket, peer_data)
    loop_msgs(msgs, socket, new_peer_data)
  end

  def loop_msgs([], _, peer_data) do
    peer_data
  end

