Browse Source

Apply PREF_MAX_CONNECTION_PER_SERVER to BitTorrent WEB Seeding hosts.

Tatsuhiro Tsujikawa 14 năm trước cách đây
mục cha
commit
9e2624a265
2 tập tin đã thay đổi với 8 bổ sung0 xóa
  1. 3 0
      src/bittorrent_helper.cc
  2. 5 0
      test/BittorrentHelperTest.cc

+ 3 - 0
src/bittorrent_helper.cc

@@ -225,6 +225,7 @@ void extractFileEntries
     utf8Name = overrideName;
   }
   torrent->name = utf8Name;
+  int maxConn = option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER);
   std::vector<SharedHandle<FileEntry> > fileEntries;
   const List* filesList = downcast<List>(infoDict->get(C_FILES));
   if(filesList) {
@@ -289,6 +290,7 @@ void extractFileEntries
                                       util::escapePath(utf8Path)),
                        fileLengthData->i(), offset, uris));
       fileEntry->setOriginalName(utf8Path);
+      fileEntry->setMaxConnectionPerServer(maxConn);
       fileEntries.push_back(fileEntry);
       offset += fileEntry->getLength();
     }
@@ -318,6 +320,7 @@ void extractFileEntries
                                     util::escapePath(utf8Name)),
                      totalLength, 0, uris));
     fileEntry->setOriginalName(utf8Name);
+    fileEntry->setMaxConnectionPerServer(maxConn);
     fileEntries.push_back(fileEntry);
   }
   ctx->setFileEntries(fileEntries.begin(), fileEntries.end());

+ 5 - 0
test/BittorrentHelperTest.cc

@@ -162,6 +162,7 @@ void BittorrentHelperTest::testGetPieceHash() {
 
 void BittorrentHelperTest::testGetFileEntries() {
   SharedHandle<DownloadContext> dctx(new DownloadContext());
+  option_->put(PREF_MAX_CONNECTION_PER_SERVER, "10");
   load(A2_TEST_DIR"/test.torrent", dctx, option_);
   // This is multi-file torrent.
   std::vector<SharedHandle<FileEntry> > fileEntries = dctx->getFileEntries();
@@ -174,14 +175,17 @@ void BittorrentHelperTest::testGetFileEntries() {
                        fileEntry1->getPath());
   CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2/src/aria2c"),
                        fileEntry1->getOriginalName());
+  CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry1->getMaxConnectionPerServer());
   itr++;
   SharedHandle<FileEntry> fileEntry2 = *itr;
   CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2-0.2.2.tar.bz2"),
                        fileEntry2->getPath());
+  CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry2->getMaxConnectionPerServer());
 }
 
 void BittorrentHelperTest::testGetFileEntriesSingle() {
   SharedHandle<DownloadContext> dctx(new DownloadContext());
+  option_->put(PREF_MAX_CONNECTION_PER_SERVER, "10");
   load(A2_TEST_DIR"/single.torrent", dctx, option_);
   // This is multi-file torrent.
   std::vector<SharedHandle<FileEntry> > fileEntries = dctx->getFileEntries();
@@ -194,6 +198,7 @@ void BittorrentHelperTest::testGetFileEntriesSingle() {
                        fileEntry1->getPath());
   CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"),
                        fileEntry1->getOriginalName());
+  CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry1->getMaxConnectionPerServer());
 }
 
 void BittorrentHelperTest::testGetTotalLength() {