2009-04-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use url-list (web-seeding) only for single-file torrent.  This
	is basically the same behavior with Metalink file with torrent
	and URIs.
	* src/RequestGroup.cc
	* src/DefaultBtContext.cc
	* test/DefaultBtContextTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-04-27 06:55:10 +00:00
parent 1ea7fca02b
commit d58742ad21
4 changed files with 49 additions and 2 deletions

View File

@ -1,3 +1,12 @@
2009-04-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use url-list (web-seeding) only for single-file torrent. This is
basically the same behavior with Metalink file with torrent and
URIs.
* src/RequestGroup.cc
* src/DefaultBtContext.cc
* test/DefaultBtContextTest.cc
2009-04-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten expr

View File

@ -183,9 +183,22 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
// Slice path by '/' just in case nasty ".." is included in name
std::deque<std::string> pathelems;
Util::slice(pathelems, name, '/');
// For each uri in urlList, if it ends with '/', then
// concatenate name to it. Specification just says so.
std::deque<std::string> uris;
for(std::deque<std::string>::const_iterator i = urlList.begin();
i != urlList.end(); ++i) {
if(Util::endsWith(*i, "/")) {
uris.push_back((*i)+name);
} else {
uris.push_back(*i);
}
}
SharedHandle<FileEntry> fileEntry
(new FileEntry(_dir+"/"+Util::joinPath(pathelems.begin(),pathelems.end()),
totalLength, 0, urlList));
totalLength, 0, uris));
fileEntries.push_back(fileEntry);
}
}

View File

@ -226,6 +226,12 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
_uris.clear();
_pieceStorage->setFileFilter(btContext->getFileFilter());
} else if(btContext->getFileEntries().size() == 1) {
// web-seeding is only enabled for single file torrent
SharedHandle<FileEntry> fileEntry = btContext->getFileEntries().front();
_uris.insert(_uris.end(),
fileEntry->getAssociatedUris().begin(),
fileEntry->getAssociatedUris().end());
}
SharedHandle<DefaultBtProgressInfoFile>

View File

@ -36,6 +36,7 @@ class DefaultBtContextTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testComputeFastSet);
CPPUNIT_TEST(testGetFileEntries_multiFileUrlList);
CPPUNIT_TEST(testGetFileEntries_singleFileUrlList);
CPPUNIT_TEST(testGetFileEntries_singleFileUrlListEndsWithSlash);
CPPUNIT_TEST(testLoadFromMemory);
CPPUNIT_TEST(testLoadFromMemory_somethingMissing);
CPPUNIT_TEST(testLoadFromMemory_overrideName);
@ -66,6 +67,7 @@ public:
void testComputeFastSet();
void testGetFileEntries_multiFileUrlList();
void testGetFileEntries_singleFileUrlList();
void testGetFileEntries_singleFileUrlListEndsWithSlash();
void testLoadFromMemory();
void testLoadFromMemory_somethingMissing();
void testLoadFromMemory_overrideName();
@ -317,7 +319,24 @@ void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
void DefaultBtContextTest::testGetFileEntries_singleFileUrlList() {
DefaultBtContext btContext;
btContext.load("url-list-singleFile.torrent");
// This is multi-file torrent.
// This is single-file torrent.
std::deque<SharedHandle<FileEntry> > fileEntries = btContext.getFileEntries();
// There are 1 file entries.
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries.size());
SharedHandle<FileEntry> fileEntry1 = fileEntries.front();
CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"),
fileEntry1->getPath());
std::deque<std::string> uris1 = fileEntry1->getAssociatedUris();
CPPUNIT_ASSERT_EQUAL((size_t)1, uris1.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/dist/aria2.tar.bz2"),
uris1[0]);
}
void DefaultBtContextTest::testGetFileEntries_singleFileUrlListEndsWithSlash() {
DefaultBtContext btContext;
btContext.load("url-list-singleFileEndsWithSlash.torrent");
// This is single-file torrent.
std::deque<SharedHandle<FileEntry> > fileEntries = btContext.getFileEntries();
// There are 1 file entries.
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries.size());