def handleRemoveTorrent(infoHash, deleteFiles)
      torrentData = @torrentData.delete infoHash
      if ! torrentData
        @logger.warn "Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
        return
      end
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent.  #{deleteFiles ? "Will" : "Wont"} delete downloaded files."

      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.metainfoRequestTimer" if ! torrentData.metainfoRequestTimer
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.managePeersTimer" if ! torrentData.managePeersTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.checkMetadataPieceManagerTimer" if ! torrentData.checkMetadataPieceManagerTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.checkPieceManagerTimer" if ! torrentData.checkPieceManagerTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.requestBlocksTimer" if ! torrentData.requestBlocksTimer 


      # Stop all timers
      cancelTimer torrentData.metainfoRequestTimer if torrentData.metainfoRequestTimer
      cancelTimer torrentData.managePeersTimer if torrentData.managePeersTimer
      cancelTimer torrentData.checkMetadataPieceManagerTimer if torrentData.checkMetadataPieceManagerTimer
      cancelTimer torrentData.checkPieceManagerTimer if torrentData.checkPieceManagerTimer
      cancelTimer torrentData.requestBlocksTimer if torrentData.requestBlocksTimer

      torrentData.trackerClient.removePeersChangedListener(torrentData.peerChangeListener)

      # Remove all the peers for this torrent.
      torrentData.peers.all.each do |peer|
        if peer.state != :disconnected
          # Close socket 
          withPeersIo(peer, "when removing torrent") do |io|
            setPeerDisconnected(peer)
            close(io)
            @logger.debug "Closing connection to peer #{peer}"
          end
        end
        torrentData.peers.delete peer
      end

      # Stop tracker client
      torrentData.trackerClient.stop if torrentData.trackerClient

      # Stop PieceManagers
      torrentData.pieceManager.stop if torrentData.pieceManager
      torrentData.metainfoPieceState.stop if torrentData.metainfoPieceState

      # Remove metainfo file if it exists
      begin
        torrentData.metainfoPieceState.remove if torrentData.metainfoPieceState
      rescue
        @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleting metainfo file for torrent #{QuartzTorrent.bytesToHex(infoHash)} failed: #{$!}"  
      end

      if deleteFiles
        if torrentData.info
          begin
            path = @baseDirectory + File::SEPARATOR + torrentData.info.name
            if File.exists? path
              FileUtils.rm_r path
              @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleted #{path}"
            else
              @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleting '#{path}' for torrent #{QuartzTorrent.bytesToHex(infoHash)} failed: #{$!}"  
            end
          rescue
            @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: When removing torrent, deleting '#{path}' failed because it doesn't exist"  
          end
        end
      end

      dequeue
    end
def handleRemoveTorrent(infoHash, deleteFiles)
      torrentData = @torrentData.delete infoHash
      if ! torrentData
        @logger.warn "Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
        return
      end
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent.  #{deleteFiles ? "Will" : "Wont"} delete downloaded files."

      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.metainfoRequestTimer" if ! torrentData.metainfoRequestTimer
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.managePeersTimer" if ! torrentData.managePeersTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.checkMetadataPieceManagerTimer" if ! torrentData.checkMetadataPieceManagerTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.checkPieceManagerTimer" if ! torrentData.checkPieceManagerTimer 
      @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Removing torrent: no torrentData.requestBlocksTimer" if ! torrentData.requestBlocksTimer 


      # Stop all timers
      cancelTimer torrentData.metainfoRequestTimer if torrentData.metainfoRequestTimer
      cancelTimer torrentData.managePeersTimer if torrentData.managePeersTimer
      cancelTimer torrentData.checkMetadataPieceManagerTimer if torrentData.checkMetadataPieceManagerTimer
      cancelTimer torrentData.checkPieceManagerTimer if torrentData.checkPieceManagerTimer
      cancelTimer torrentData.requestBlocksTimer if torrentData.requestBlocksTimer

      torrentData.trackerClient.removePeersChangedListener(torrentData.peerChangeListener)

      # Remove all the peers for this torrent.
      torrentData.peers.all.each do |peer|
        if peer.state != :disconnected
          # Close socket 
          withPeersIo(peer, "when removing torrent") do |io|
            setPeerDisconnected(peer)
            close(io)
            @logger.debug "Closing connection to peer #{peer}"
          end
        end
        torrentData.peers.delete peer
      end

      # Stop tracker client
      torrentData.trackerClient.stop if torrentData.trackerClient

      # Stop PieceManagers
      torrentData.pieceManager.stop if torrentData.pieceManager
      torrentData.metainfoPieceState.stop if torrentData.metainfoPieceState

      # Remove metainfo file if it exists
      begin
        torrentData.metainfoPieceState.remove if torrentData.metainfoPieceState
      rescue
        @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleting metainfo file for torrent #{QuartzTorrent.bytesToHex(infoHash)} failed: #{$!}"  
      end

      if deleteFiles
        if torrentData.info
          begin
            path = @baseDirectory + File::SEPARATOR + torrentData.info.name
            if File.exists? path
              FileUtils.rm_r path
              @logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleted #{path}"
            else
              @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Deleting '#{path}' for torrent #{QuartzTorrent.bytesToHex(infoHash)} failed: #{$!}"  
            end
          rescue
            @logger.warn "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: When removing torrent, deleting '#{path}' failed because it doesn't exist"  
          end
        end
      end

      dequeue
    end
Remove a torrent that we are downloading.