public void restoreSessionTotals(
      long _saved_data_bytes_downloaded,
      long _saved_data_bytes_uploaded,
      long _saved_discarded,
      long _saved_hashfails,
      long _saved_SecondsDownloading,
      long _saved_SecondsOnlySeeding) {
    saved_data_bytes_downloaded = _saved_data_bytes_downloaded;
    saved_data_bytes_uploaded = _saved_data_bytes_uploaded;
    saved_discarded = _saved_discarded;
    saved_hashfails = _saved_hashfails;
    saved_SecondsDownloading = _saved_SecondsDownloading;
    saved_SecondsOnlySeeding = _saved_SecondsOnlySeeding;

    session_start_data_bytes_downloaded = saved_data_bytes_downloaded;
    session_start_data_bytes_uploaded = _saved_data_bytes_uploaded;

    DownloadManagerState state = download_manager.getDownloadState();

    saved_SecondsSinceDownload = state.getIntAttribute(DownloadManagerState.AT_TIME_SINCE_DOWNLOAD);
    saved_SecondsSinceUpload = state.getIntAttribute(DownloadManagerState.AT_TIME_SINCE_UPLOAD);

    saved_peak_receive_rate = state.getLongAttribute(DownloadManagerState.AT_PEAK_RECEIVE_RATE);
    saved_peak_send_rate = state.getLongAttribute(DownloadManagerState.AT_PEAK_SEND_RATE);
  }
  public long getAvailWentBadTime() {
    PEPeerManager pm = download_manager.getPeerManager();

    if (pm != null) {

      long bad_time = pm.getAvailWentBadTime();

      if (bad_time > 0) {

        // valid last bad time

        return (bad_time);
      }

      if (pm.getMinAvailability() >= 1.0) {

        // we can believe the fact that it isn't bad (we want to ignore 0 results from
        // downloads that never get to a 1.0 availbility)

        return (0);
      }
    }

    DownloadManagerState state = download_manager.getDownloadState();

    return (state.getLongAttribute(DownloadManagerState.AT_AVAIL_BAD_TIME));
  }
  protected void saveSessionTotals() {
    // re-base the totals from current totals and session totals

    saved_data_bytes_downloaded = getTotalDataBytesReceived();
    saved_data_bytes_uploaded = getTotalDataBytesSent();

    saved_protocol_bytes_downloaded = getTotalProtocolBytesReceived();
    saved_protocol_bytes_uploaded = getTotalProtocolBytesSent();

    saved_discarded = getDiscarded();
    saved_hashfails = getHashFailBytes();

    saved_SecondsDownloading = getSecondsDownloading();
    saved_SecondsOnlySeeding = getSecondsOnlySeeding();

    saved_SecondsSinceDownload = getTimeSinceLastDataReceivedInSeconds();
    saved_SecondsSinceUpload = getTimeSinceLastDataSentInSeconds();

    saved_peak_receive_rate = getPeakDataReceiveRate();
    saved_peak_send_rate = getPeakDataSendRate();

    DownloadManagerState state = download_manager.getDownloadState();

    state.setIntAttribute(DownloadManagerState.AT_TIME_SINCE_DOWNLOAD, saved_SecondsSinceDownload);
    state.setIntAttribute(DownloadManagerState.AT_TIME_SINCE_UPLOAD, saved_SecondsSinceUpload);

    state.setLongAttribute(DownloadManagerState.AT_AVAIL_BAD_TIME, getAvailWentBadTime());

    state.setLongAttribute(DownloadManagerState.AT_PEAK_RECEIVE_RATE, saved_peak_receive_rate);
    state.setLongAttribute(DownloadManagerState.AT_PEAK_SEND_RATE, saved_peak_send_rate);
  }