コード例 #1
0
ファイル: Tests.cpp プロジェクト: PowerKiKi/D-LAN
void Tests::getHashesFromAFileEntry2()
{
   qDebug() << "===== getHashesFromAFileEntry2() =====";

   {
      QFile file1("sharedDirs/big2.bin");
      file1.open(QIODevice::WriteOnly);

      QFile file2("sharedDirs/big3.bin");
      file2.open(QIODevice::WriteOnly);

      file1.resize(128 * 1024 * 1024); // 128Mo
      file2.resize(128 * 1024 * 1024); // 128Mo
   }
   QTest::qWait(2000); // Begin the computing of the big2.bin hashes.

   Protos::Common::Entries sharedDirs = this->fileManager->getEntries();
   const string sharedDirId = sharedDirs.entry(1).shared_dir().id().hash();

   Protos::Common::Entry entry;
   entry.set_path("/");
   entry.set_name("big3.bin");
   entry.mutable_shared_dir()->mutable_id()->set_hash(sharedDirId);
   QSharedPointer<IGetHashesResult> result = this->fileManager->getHashes(entry);

   HashesReceiver hashesReceiver;
   connect(result.data(), SIGNAL(nextHash(Common::Hash)), &hashesReceiver, SLOT(nextHash(Common::Hash)));
   Protos::Core::GetHashesResult res = result->start(); // Should stop the computing of 'big2.bin' and switch to 'big3.bin'.
   QCOMPARE(res.status(), Protos::Core::GetHashesResult_Status_OK);

   QTest::qWait(4000);
}
コード例 #2
0
ファイル: DirDownload.cpp プロジェクト: Zorvalt/D-LAN
void DirDownload::result(const Protos::Core::GetEntriesResult& entries)
{
    Protos::Common::Entries entriesCopy;

    // We asked for one directory, we shouldn't have zero result.
    if (entries.entries_size() > 0)
    {
        // We need to specify the shared directory for each entry.
        entriesCopy.CopyFrom(entries.entries(0)); // We take the first one which should be the only set of entries.
        for (int i = 0; i < entriesCopy.entry_size(); i++)
            entriesCopy.mutable_entry(i)->mutable_shared_dir()->CopyFrom(this->remoteEntry.shared_dir());
    }

    this->getEntriesResult.clear();

    emit newEntries(entriesCopy);
}
コード例 #3
0
ファイル: DirDownload.cpp プロジェクト: hmartinet/D-LAN
void DirDownload::result(const Protos::Core::GetEntriesResult& entries)
{
   // We asked for one directory, we shouldn't have zero result.
   if (entries.result_size() > 0 && entries.result(0).status() == Protos::Core::GetEntriesResult::EntryResult::OK)
   {
      Protos::Common::Entries entriesCopy;

      if (entries.result(0).has_entries())
      {
         entriesCopy.CopyFrom(entries.result(0).entries());
         // We need to specify the shared directory for each entry.
         for (int i = 0; i < entriesCopy.entry_size(); i++)
            entriesCopy.mutable_entry(i)->mutable_shared_dir()->CopyFrom(this->remoteEntry.shared_dir());
      }

      this->getEntriesResult.clear();
      emit newEntries(entriesCopy);
   }
   else
   {
      if (entries.result_size() == 0 || entries.result(0).status() == Protos::Core::GetEntriesResult::EntryResult::DONT_HAVE)
      {
         L_DEBU("Unable to get the entries: ENTRY_NOT_FOUND");
         this->setStatus(ENTRY_NOT_FOUND);
      }
      else if (entries.result(0).status() == Protos::Core::GetEntriesResult::EntryResult::TIMEOUT_SCANNING_IN_PROGRESS)
      {
         L_DEBU("Unable to get the entries: DIRECTORY_SCANNING_IN_PROGRESS");
         this->setStatus(DIRECTORY_SCANNING_IN_PROGRESS);
      }
      else
      {
         L_DEBU("Unable to get the entries: UNABLE_TO_GET_ENTRIES");
         this->setStatus(UNABLE_TO_GET_ENTRIES);
      }

      this->getEntriesResult.clear();
      this->occupiedPeersAskingForEntries.setPeerAsFree(this->peerSource);
      QTimer::singleShot(RETRY_GET_ENTRIES_PERIOD, this, SLOT(retryToGetEntries()));
   }
}
コード例 #4
0
ファイル: DownloadManager.cpp プロジェクト: thexa4/D-LAN
/**
  * Called when a directory knows its children. The children replace the directory.
  * The directory is removed from the queue and deleted.
  */
void DownloadManager::newEntries(const Protos::Common::Entries& remoteEntries)
{
   DirDownload* dirDownload = static_cast<DirDownload*>(this->sender());
   int position = this->downloadQueue.find(dirDownload);
   if (position == -1)
      return;
   this->downloadQueue.remove(position);

   const Protos::Common::Entry& localEntry = dirDownload->getLocalEntry();
   const QString relativePath = Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::path).append(Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::name)).append("/");

   // Add files first then directories.
   for (auto type : QList<Protos::Common::Entry::Type> { Protos::Common::Entry::FILE, Protos::Common::Entry::DIR })
   {
      for (int n = 0; n < remoteEntries.entry_size(); n++)
         if (remoteEntries.entry(n).type() == type)
            this->addDownload(remoteEntries.entry(n), dirDownload->getPeerSource(), localEntry.has_shared_dir() ? localEntry.shared_dir().id().hash() : Common::Hash(), relativePath, Protos::Queue::Queue::Entry::QUEUED, position++);
   }

   delete dirDownload;
}
コード例 #5
0
ファイル: DownloadManager.cpp プロジェクト: omorel/D-LAN
/**
  * Called when a directory knows its children. The children replace the directory.
  * The directory is removed from the queue and deleted.
  */
void DownloadManager::newEntries(const Protos::Common::Entries& remoteEntries)
{
   DirDownload* dirDownload = dynamic_cast<DirDownload*>(this->sender());
   int position = this->downloadQueue.find(dirDownload);
   if (position == -1)
      return;
   this->downloadQueue.remove(position);

   // Add files first.
   for (int n = 0; n < remoteEntries.entry_size(); n++)
      if (remoteEntries.entry(n).type() == Protos::Common::Entry_Type_FILE)
      {
         const Protos::Common::Entry& localEntry = dirDownload->getLocalEntry();
         QString relativePath = Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::path).append(Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::name)).append("/");
         this->addDownload(remoteEntries.entry(n), dirDownload->getPeerSource(), localEntry.has_shared_dir() ? localEntry.shared_dir().id().hash() : Common::Hash(), relativePath, Protos::Queue::Queue::Entry::QUEUED, position++);
      }

   // Then directories. TODO: code to refactor with the one above.
   for (int n = 0; n < remoteEntries.entry_size(); n++)
      if (remoteEntries.entry(n).type() == Protos::Common::Entry_Type_DIR)
      {
         const Protos::Common::Entry& localEntry = dirDownload->getLocalEntry();
         QString relativePath = Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::path).append(Common::ProtoHelper::getStr(localEntry, &Protos::Common::Entry::name)).append("/");
         this->addDownload(remoteEntries.entry(n), dirDownload->getPeerSource(), localEntry.has_shared_dir() ? localEntry.shared_dir().id().hash() : Common::Hash(), relativePath, Protos::Queue::Queue::Entry::QUEUED, position++);
      }

   delete dirDownload;
}
コード例 #6
0
ファイル: Tests.cpp プロジェクト: PowerKiKi/D-LAN
void Tests::getHashesFromAFileEntry1()
{
   qDebug() << "===== getHashesFromAFileEntry1() =====";

   // Find the id of the first shared directory.
   Protos::Common::Entries sharedDirs = this->fileManager->getEntries();
   const string sharedDirId = sharedDirs.entry(1).shared_dir().id().hash();

   Protos::Common::Entry entry;
   entry.set_path("/share1/");
   entry.set_name("r.txt");
   entry.mutable_shared_dir()->mutable_id()->set_hash(sharedDirId);
   QSharedPointer<IGetHashesResult> result = this->fileManager->getHashes(entry);

   HashesReceiver hashesReceiver;
   connect(result.data(), SIGNAL(nextHash(Common::Hash)), &hashesReceiver, SLOT(nextHash(Common::Hash)));

   Protos::Core::GetHashesResult res = result->start();

   QCOMPARE(res.status(), Protos::Core::GetHashesResult_Status_OK);
   QVERIFY(hashesReceiver.waitToReceive(QList<Common::Hash>() << Common::Hash::fromStr("97d464813598e2e4299b5fe7db29aefffdf2641d"), 500));
}