From 41b6003cbde05956e195dc94d9ad5aee8420c1f3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 12 May 2008 12:18:21 +0000 Subject: [PATCH] 2008-05-12 Tatsuhiro Tsujikawa Changed method signature: BtContext::computeFastSet, DefaultBtContext::extractUrlList * src/BtContext.h * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/DefaultBtInteractive.cc * test/DefaultBtContextTest.cc * test/MockBtContext.h --- ChangeLog | 11 +++++++++++ src/BtContext.h | 4 ++-- src/DefaultBtContext.cc | 15 +++++++-------- src/DefaultBtContext.h | 5 +++-- src/DefaultBtInteractive.cc | 4 ++-- test/DefaultBtContextTest.cc | 27 ++++++++++++++++----------- test/MockBtContext.h | 5 +++-- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8351edf..8ac92a77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-05-12 Tatsuhiro Tsujikawa + + Changed method signature: + BtContext::computeFastSet, DefaultBtContext::extractUrlList + * src/BtContext.h + * src/DefaultBtContext.cc + * src/DefaultBtContext.h + * src/DefaultBtInteractive.cc + * test/DefaultBtContextTest.cc + * test/MockBtContext.h + 2008-05-12 Tatsuhiro Tsujikawa Changed method signature: diff --git a/src/BtContext.h b/src/BtContext.h index 62d8e5fe..56ad5cea 100644 --- a/src/BtContext.h +++ b/src/BtContext.h @@ -73,8 +73,8 @@ public: return _private; } - virtual std::deque - computeFastSet(const std::string& ipaddr, size_t fastSetSize) = 0; + virtual void computeFastSet + (std::deque& fastSet, const std::string& ipaddr, size_t fastSetSize) = 0; virtual RequestGroup* getOwnerRequestGroup() = 0; diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index 3753f4fd..d0bd748e 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -216,9 +216,9 @@ void DefaultBtContext::extractAnnounceList(const List* announceListData) { } } -std::deque DefaultBtContext::extractUrlList(const MetaEntry* obj) +void DefaultBtContext::extractUrlList(std::deque& uris, + const MetaEntry* obj) { - std::deque uris; if(dynamic_cast(obj)) { const List* urlList = reinterpret_cast(obj); for(std::deque::const_iterator itr = urlList->getList().begin(); @@ -232,7 +232,6 @@ std::deque DefaultBtContext::extractUrlList(const MetaEntry* obj) const Data* urlData = reinterpret_cast(obj); uris.push_back(urlData->toString()); } - return uris; } void DefaultBtContext::extractNodes(const List* nodes) @@ -334,7 +333,8 @@ void DefaultBtContext::processRootDictionary(const Dictionary* rootDic, const st // retrieve uri-list. // This implemantation obeys HTTP-Seeding specification: // see http://www.getright.com/seedtorrent.html - std::deque urlList = extractUrlList(rootDic->get("url-list")); + std::deque urlList; + extractUrlList(urlList, rootDic->get("url-list")); // retrieve file entries extractFileEntries(infoDic, defaultName, urlList); if((totalLength+pieceLength-1)/pieceLength != numPieces) { @@ -396,12 +396,12 @@ std::string DefaultBtContext::getActualBasePath() const return _dir+"/"+name; } -std::deque DefaultBtContext::computeFastSet(const std::string& ipaddr, size_t fastSetSize) +void DefaultBtContext::computeFastSet +(std::deque& fastSet, const std::string& ipaddr, size_t fastSetSize) { - std::deque fastSet; unsigned char compact[6]; if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) { - return fastSet; + return; } unsigned char tx[24]; memcpy(tx, compact, 4); @@ -429,7 +429,6 @@ std::deque DefaultBtContext::computeFastSet(const std::string& ipaddr, s MessageDigestHelper::digest(temp, sizeof(temp), "sha1", x, sizeof(x)); memcpy(x, temp, sizeof(x)); } - return fastSet; } std::ostream& operator<<(std::ostream& o, const DefaultBtContext& ctx) diff --git a/src/DefaultBtContext.h b/src/DefaultBtContext.h index b752b4d8..0d9ab2b7 100644 --- a/src/DefaultBtContext.h +++ b/src/DefaultBtContext.h @@ -81,7 +81,7 @@ private: void extractAnnounce(const Data* announceData); void extractAnnounceList(const List* announceListData); - std::deque extractUrlList(const MetaEntry* obj); + void extractUrlList(std::deque& uris, const MetaEntry* obj); void extractNodes(const List* nodes); @@ -143,7 +143,8 @@ private: return reinterpret_cast(peerId.c_str()); } - virtual std::deque computeFastSet(const std::string& ipaddr, size_t fastSetSize); + virtual void computeFastSet + (std::deque& fastSet, const std::string& ipaddr, size_t fastSetSize); virtual RequestGroup* getOwnerRequestGroup() { diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index 6f6d7870..f52ac292 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -178,8 +178,8 @@ void DefaultBtInteractive::addBitfieldMessageToQueue() { void DefaultBtInteractive::addAllowedFastMessageToQueue() { if(peer->isFastExtensionEnabled()) { - std::deque fastSet = btContext->computeFastSet(peer->ipaddr, - allowedFastSetSize); + std::deque fastSet; + btContext->computeFastSet(fastSet, peer->ipaddr, allowedFastSetSize); for(std::deque::const_iterator itr = fastSet.begin(); itr != fastSet.end(); itr++) { dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr)); diff --git a/test/DefaultBtContextTest.cc b/test/DefaultBtContextTest.cc index 88fd85a1..674889e0 100644 --- a/test/DefaultBtContextTest.cc +++ b/test/DefaultBtContextTest.cc @@ -241,18 +241,23 @@ void DefaultBtContextTest::testComputeFastSet() btContext.setInfoHash(infoHash); btContext.setNumPieces(pieces); - std::deque fastSet = btContext.computeFastSet(ipaddr, fastSetSize); - //for_each(fastSet.begin(), fastSet.end(), Printer()); - //cerr << endl; - size_t ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 }; - std::deque ansSet1(&ans1[0], &ans1[10]); - CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin())); - + { + std::deque fastSet; + btContext.computeFastSet(fastSet, ipaddr, fastSetSize); + //for_each(fastSet.begin(), fastSet.end(), Printer()); + //cerr << endl; + size_t ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 }; + std::deque ansSet1(&ans1[0], &ans1[10]); + CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin())); + } ipaddr = "10.0.0.1"; - fastSet = btContext.computeFastSet(ipaddr, fastSetSize); - size_t ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 }; - std::deque ansSet2(&ans2[0], &ans2[10]); - CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin())); + { + std::deque fastSet; + btContext.computeFastSet(fastSet, ipaddr, fastSetSize); + size_t ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 }; + std::deque ansSet2(&ans2[0], &ans2[10]); + CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin())); + } } void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() { diff --git a/test/MockBtContext.h b/test/MockBtContext.h index 9373e991..c13d7576 100644 --- a/test/MockBtContext.h +++ b/test/MockBtContext.h @@ -123,9 +123,10 @@ public: memcpy(this->peerId, peerId, sizeof(this->peerId)); } - virtual std::deque computeFastSet(const std::string& ipaddr, size_t fastSetSize) + virtual void computeFastSet + (std::deque& fastSet, const std::string& ipaddr, size_t fastSetSize) { - return fastSet; + fastSet.insert(fastSet.end(), this->fastSet.begin(), this->fastSet.end()); } void setFastSet(const std::deque& fastSet)