Esempio n. 1
0
void Sender::endCurTransfer() {
    endTime_ = Clock::now();
    LOG(INFO) << "Last thread finished " << durationSeconds(endTime_ - startTime_)
              << " for transfer id " << getTransferId();
    setTransferStatus(FINISHED);
    if (throttler_) {
        throttler_->deRegisterTransfer();
    }
}
Esempio n. 2
0
ErrorCode Receiver::start() {
  WDT_CHECK_EQ(getTransferStatus(), NOT_STARTED)
      << "There is already a transfer running on this instance of receiver";
  startTime_ = Clock::now();
  WLOG(INFO) << "Starting (receiving) server on ports [ "
             << transferRequest_.ports << "] Target dir : " << destDir_;
  // TODO do the init stuff here
  if (!throttler_) {
    configureThrottler();
  } else {
    WLOG(INFO) << "Throttler set externally. Throttler : " << *throttler_;
  }
  setTransferStatus(ONGOING);
  while (true) {
    for (auto &receiverThread : receiverThreads_) {
      receiverThread->startThread();
    }
    if (isJoinable_) {
      break;
    }
    // If it is long running mode, finish the threads
    // processing the current transfer and re spawn them again
    // with the same sockets
    for (auto &receiverThread : receiverThreads_) {
      receiverThread->finish();
      receiverThread->reset();
    }
    threadsController_->reset();
    // reset transfer status
    setTransferStatus(NOT_STARTED);
    continue;
  }
  if (isJoinable_) {
    if (progressReporter_) {
      progressReporter_->start();
    }
    std::thread trackerThread(&Receiver::progressTracker, this);
    progressTrackerThread_ = std::move(trackerThread);
  }
  return OK;
}
void GaduFileTransferService::fileTransferReceived(Contact peer, QString downloadId, QString fileName)
{
	auto transfer = FileTransfer::create();
	transfer.setPeer(peer);
	transfer.setTransferDirection(FileTransferDirection::Incoming);
	transfer.setTransferType(FileTransferType::Url);
	transfer.setTransferStatus(FileTransferStatus::ReadyToDownload);
	transfer.setRemoteFileName(QUrl::fromPercentEncoding(fileName.toUtf8()));
	transfer.setFileSize(0); // we don't know file size yet
	transfer.addProperty("gg:downloadId", downloadId, CustomProperties::Storable);
	transfer.addProperty("gg:remoteFileName", fileName, CustomProperties::Storable);

	emit incomingFileTransfer(transfer);
}
Esempio n. 4
0
void Receiver::endCurGlobalSession() {
  setTransferStatus(FINISHED);
  if (!hasNewTransferStarted_) {
    WLOG(WARNING) << "WDT transfer did not start, no need to end session";
    return;
  }
  WLOG(INFO) << "Ending the transfer " << getTransferId();
  if (throttler_) {
    throttler_->deRegisterTransfer();
  }
  checkpoints_.clear();
  if (fileCreator_) {
    fileCreator_->clearAllocationMap();
  }
  // TODO might consider moving closing the transfer log here
  hasNewTransferStarted_.store(false);
}
Esempio n. 5
0
std::unique_ptr<TransferReport> Receiver::finish() {
  std::unique_lock<std::mutex> instanceLock(instanceManagementMutex_);
  TransferStatus status = getTransferStatus();
  if (status == NOT_STARTED) {
    WLOG(WARNING) << "Even though transfer has not started, finish is called";
    // getTransferReport will set the error code to ERROR
    return getTransferReport();
  }
  if (status == THREADS_JOINED) {
    WLOG(WARNING) << "Threads have already been joined. Returning the "
                  << "transfer report";
    return getTransferReport();
  }
  if (!isJoinable_) {
    // TODO: don't complain about this when coming from runForever()
    WLOG(WARNING) << "The receiver is not joinable. The threads will never"
                  << " finish and this method will never return";
  }
  for (auto &receiverThread : receiverThreads_) {
    receiverThread->finish();
  }

  setTransferStatus(THREADS_JOINED);

  if (isJoinable_) {
    // Make sure to join the progress thread.
    progressTrackerThread_.join();
  }
  std::unique_ptr<TransferReport> report = getTransferReport();
  auto &summary = report->getSummary();
  bool transferSuccess = (report->getSummary().getErrorCode() == OK);
  fixAndCloseTransferLog(transferSuccess);
  auto totalSenderBytes = summary.getTotalSenderBytes();
  if (progressReporter_ && totalSenderBytes >= 0) {
    report->setTotalFileSize(totalSenderBytes);
    report->setTotalTime(durationSeconds(Clock::now() - startTime_));
    progressReporter_->end(report);
  }
  logPerfStats();

  WLOG(WARNING) << "WDT receiver's transfer has been finished";
  WLOG(INFO) << *report;
  return report;
}
void JabberFileTransferService::fileReceived(QXmppTransferJob *transferJob)
{
    auto jid = Jid::parse(transferJob->jid());
    auto peer = m_contactManager->byId(m_account, jid.bare(), ActionCreateAndAdd);

    auto transfer = m_fileTransferStorage->create();
    transfer.setPeer(peer);
    transfer.setTransferDirection(FileTransferDirection::Incoming);
    transfer.setTransferType(FileTransferType::Stream);
    transfer.setTransferStatus(FileTransferStatus::WaitingForAccept);
    transfer.setRemoteFileName(transferJob->fileName());
    transfer.setFileSize(transferJob->fileSize());

    if (!m_fileTransferHandlerManager->ensureHandler(transfer))
        return;

    auto handler = qobject_cast<JabberStreamIncomingFileTransferHandler *>(transfer.handler());
    if (handler)
        handler->setTransferJob(transferJob);

    emit incomingFileTransfer(transfer);
}
Esempio n. 7
0
std::unique_ptr<TransferReport> Sender::finish() {
    std::unique_lock<std::mutex> instanceLock(instanceManagementMutex_);
    VLOG(1) << "Sender::finish()";
    TransferStatus status = getTransferStatus();
    if (status == NOT_STARTED) {
        LOG(WARNING) << "Even though transfer has not started, finish is called";
        // getTransferReport will set the error code to ERROR
        return getTransferReport();
    }
    if (status == THREADS_JOINED) {
        VLOG(1) << "Threads have already been joined. Returning the"
                << " existing transfer report";
        return getTransferReport();
    }
    const bool twoPhases = options_.two_phases;
    bool progressReportEnabled =
        progressReporter_ && progressReportIntervalMillis_ > 0;
    for (auto &senderThread : senderThreads_) {
        senderThread->finish();
    }
    if (!twoPhases) {
        dirThread_.join();
    }
    WDT_CHECK(numActiveThreads_ == 0);
    setTransferStatus(THREADS_JOINED);
    if (progressReportEnabled) {
        progressReporterThread_.join();
    }
    std::vector<TransferStats> threadStats;
    for (auto &senderThread : senderThreads_) {
        threadStats.push_back(senderThread->moveStats());
    }

    bool allSourcesAcked = false;
    for (auto &senderThread : senderThreads_) {
        auto &stats = senderThread->getTransferStats();
        if (stats.getErrorCode() == OK) {
            // at least one thread finished correctly
            // that means all transferred sources are acked
            allSourcesAcked = true;
            break;
        }
    }

    std::vector<TransferStats> transferredSourceStats;
    for (auto port : transferRequest_.ports) {
        auto &transferHistory =
            transferHistoryController_->getTransferHistory(port);
        if (allSourcesAcked) {
            transferHistory.markAllAcknowledged();
        } else {
            transferHistory.returnUnackedSourcesToQueue();
        }
        if (options_.full_reporting) {
            std::vector<TransferStats> stats = transferHistory.popAckedSourceStats();
            transferredSourceStats.insert(transferredSourceStats.end(),
                                          std::make_move_iterator(stats.begin()),
                                          std::make_move_iterator(stats.end()));
        }
    }
    if (options_.full_reporting) {
        validateTransferStats(transferredSourceStats,
                              dirQueue_->getFailedSourceStats());
    }
    int64_t totalFileSize = dirQueue_->getTotalSize();
    double totalTime = durationSeconds(endTime_ - startTime_);
    std::unique_ptr<TransferReport> transferReport =
        folly::make_unique<TransferReport>(
            transferredSourceStats, dirQueue_->getFailedSourceStats(),
            threadStats, dirQueue_->getFailedDirectories(), totalTime,
            totalFileSize, dirQueue_->getCount());

    if (progressReportEnabled) {
        progressReporter_->end(transferReport);
    }
    if (options_.enable_perf_stat_collection) {
        PerfStatReport report(options_);
        for (auto &senderThread : senderThreads_) {
            report += senderThread->getPerfReport();
        }
        report += dirQueue_->getPerfReport();
        LOG(INFO) << report;
    }
    double directoryTime;
    directoryTime = dirQueue_->getDirectoryTime();
    LOG(INFO) << "Total sender time = " << totalTime << " seconds ("
              << directoryTime << " dirTime)"
              << ". Transfer summary : " << *transferReport
              << "\nTotal sender throughput = "
              << transferReport->getThroughputMBps() << " Mbytes/sec ("
              << transferReport->getSummary().getEffectiveTotalBytes() /
              (totalTime - directoryTime) / kMbToB
              << " Mbytes/sec pure transfer rate)";
    return transferReport;
}