Преглед на файлове

Shuffle web-seeding URIs

Tatsuhiro Tsujikawa преди 10 години
родител
ревизия
4cf0bb742f
променени са 3 файла, в които са добавени 13 реда и са изтрити 0 реда
  1. 6 0
      src/BtDependency.cc
  2. 6 0
      src/download_helper.cc
  3. 1 0
      test/DownloadHelperTest.cc

+ 6 - 0
src/BtDependency.cc

@@ -49,6 +49,7 @@
 #include "DlAbortEx.h"
 #include "fmt.h"
 #include "FileEntry.h"
+#include "SimpleRandomizer.h"
 
 namespace aria2 {
 
@@ -117,6 +118,11 @@ bool BtDependency::resolve()
       }
       const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
         context->getFileEntries();
+      for (auto &fe : fileEntries) {
+        auto &uri = fe->getRemainingUris();
+        std::random_shuffle(std::begin(uri), std::end(uri),
+                            *SimpleRandomizer::getInstance());
+      }
       const std::vector<std::shared_ptr<FileEntry> >& dependantFileEntries =
         dependant_->getDownloadContext()->getFileEntries();
       // If dependant's FileEntry::getOriginalName() is empty, we

+ 6 - 0
src/download_helper.cc

@@ -62,6 +62,7 @@
 #include "OptionParser.h"
 #include "SegList.h"
 #include "download_handlers.h"
+#include "SimpleRandomizer.h"
 #ifdef ENABLE_BITTORRENT
 #  include "bittorrent_helper.h"
 #  include "BtConstants.h"
@@ -197,6 +198,11 @@ createBtRequestGroup(const std::string& metaInfoUri,
   // may throw exception
   bittorrent::loadFromMemory(torrent, dctx, option, auxUris,
                              metaInfoUri.empty() ? "default" : metaInfoUri);
+  for (auto &fe : dctx->getFileEntries()) {
+    auto &uris = fe->getRemainingUris();
+    std::random_shuffle(std::begin(uris), std::end(uris),
+                        *SimpleRandomizer::getInstance());
+  }
   if(metaInfoUri.empty()) {
     rg->setMetadataInfo(createMetadataInfoDataOnly());
   } else {

+ 1 - 0
test/DownloadHelperTest.cc

@@ -324,6 +324,7 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
     std::shared_ptr<RequestGroup> group = result[0];
     auto uris =
       group->getDownloadContext()->getFirstFileEntry()->getUris();
+    std::sort(std::begin(uris), std::end(uris));
     // See -s option is ignored. See processRootDictionary() in
     // bittorrent_helper.cc
     CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());