def requestMetadataPieces(infoHash)
      torrentData = @torrentData[infoHash]
      if ! torrentData
        @logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
        return
      end
      
      return if torrentData.paused || torrentData.queued

      # We may not have completed the extended handshake with the peer which specifies the torrent size.
      # In this case torrentData.metainfoPieceState is not yet set.
      return if ! torrentData.metainfoPieceState

      @logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Obtained all pieces of metainfo." if torrentData.metainfoPieceState.complete?

      pieces = torrentData.metainfoPieceState.findRequestablePieces
      classifiedPeers = ClassifiedPeers.new torrentData.peers.all
      peers = torrentData.metainfoPieceState.findRequestablePeers(classifiedPeers)
  
      if peers.size > 0
        # For now, just request all pieces from the first peer.
        pieces.each do |pieceIndex|
          msg = ExtendedMetaInfo.new
          msg.msgType = :request
          msg.piece = pieceIndex
          withPeersIo(peers.first, "requesting metadata piece") do |io|
            sendMessageToPeer msg, io, peers.first
            torrentData.metainfoPieceState.setPieceRequested(pieceIndex, true)
            @logger.debug "#{QuartzTorrent.bytesToHex(infoHash)}: Requesting metainfo piece from #{peers.first}: piece #{pieceIndex}"
          end
        end
      else
        @logger.error "#{QuartzTorrent.bytesToHex(infoHash)}: No peers found that have metadata."
      end

    end
def requestMetadataPieces(infoHash)
      torrentData = @torrentData[infoHash]
      if ! torrentData
        @logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
        return
      end
      
      return if torrentData.paused || torrentData.queued

      # We may not have completed the extended handshake with the peer which specifies the torrent size.
      # In this case torrentData.metainfoPieceState is not yet set.
      return if ! torrentData.metainfoPieceState

      @logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Obtained all pieces of metainfo." if torrentData.metainfoPieceState.complete?

      pieces = torrentData.metainfoPieceState.findRequestablePieces
      classifiedPeers = ClassifiedPeers.new torrentData.peers.all
      peers = torrentData.metainfoPieceState.findRequestablePeers(classifiedPeers)
  
      if peers.size > 0
        # For now, just request all pieces from the first peer.
        pieces.each do |pieceIndex|
          msg = ExtendedMetaInfo.new
          msg.msgType = :request
          msg.piece = pieceIndex
          withPeersIo(peers.first, "requesting metadata piece") do |io|
            sendMessageToPeer msg, io, peers.first
            torrentData.metainfoPieceState.setPieceRequested(pieceIndex, true)
            @logger.debug "#{QuartzTorrent.bytesToHex(infoHash)}: Requesting metainfo piece from #{peers.first}: piece #{pieceIndex}"
          end
        end
      else
        @logger.error "#{QuartzTorrent.bytesToHex(infoHash)}: No peers found that have metadata."
      end

    end
For a torrent where we don't have the metainfo, request metainfo pieces from peers.