def addTorrent(trackerclient, infoHash, info, magnet = nil)
      trackerclient.port = @port

      torrentData = @handler.addTrackerClient(infoHash, info, trackerclient)
      torrentData.magnet = magnet

      trackerclient.dynamicRequestParamsBuilder = Proc.new do
        torrentData = @handler.torrentData[infoHash]
        dataLength = (info ? info.dataLength : nil)
        result = TrackerDynamicRequestParams.new(dataLength)
        if torrentData && torrentData.blockState
          result.left = torrentData.blockState.totalLength - torrentData.blockState.completedLength
          result.downloaded = torrentData.bytesDownloadedDataOnly
          result.uploaded = torrentData.bytesUploadedDataOnly
        end
        result
      end

      # If we haven't started yet then add this trackerclient to a queue of 
      # trackerclients to start once we are started. If we start too soon we 
      # will connect to the tracker, and it will try to connect back to us before we are listening.
      if ! trackerclient.started?
        if @stopped
          @toStart.push trackerclient
        else
          trackerclient.start 
        end
      end

      torrentData.infoHash
    end
def addTorrent(trackerclient, infoHash, info, magnet = nil)
      trackerclient.port = @port

      torrentData = @handler.addTrackerClient(infoHash, info, trackerclient)
      torrentData.magnet = magnet

      trackerclient.dynamicRequestParamsBuilder = Proc.new do
        torrentData = @handler.torrentData[infoHash]
        dataLength = (info ? info.dataLength : nil)
        result = TrackerDynamicRequestParams.new(dataLength)
        if torrentData && torrentData.blockState
          result.left = torrentData.blockState.totalLength - torrentData.blockState.completedLength
          result.downloaded = torrentData.bytesDownloadedDataOnly
          result.uploaded = torrentData.bytesUploadedDataOnly
        end
        result
      end

      # If we haven't started yet then add this trackerclient to a queue of 
      # trackerclients to start once we are started. If we start too soon we 
      # will connect to the tracker, and it will try to connect back to us before we are listening.
      if ! trackerclient.started?
        if @stopped
          @toStart.push trackerclient
        else
          trackerclient.start 
        end
      end

      torrentData.infoHash
    end
Helper method for adding a torrent.