mirror of
https://github.com/aria2/aria2.git
synced 2024-12-15 01:49:01 +00:00
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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
This commit is contained in:
parent
6ae07106d3
commit
41b6003cbd
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
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 <tujikawa at rednoah dot com>
|
||||
|
||||
Changed method signature:
|
||||
|
@ -73,8 +73,8 @@ public:
|
||||
return _private;
|
||||
}
|
||||
|
||||
virtual std::deque<size_t>
|
||||
computeFastSet(const std::string& ipaddr, size_t fastSetSize) = 0;
|
||||
virtual void computeFastSet
|
||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize) = 0;
|
||||
|
||||
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
||||
|
||||
|
@ -216,9 +216,9 @@ void DefaultBtContext::extractAnnounceList(const List* announceListData) {
|
||||
}
|
||||
}
|
||||
|
||||
std::deque<std::string> DefaultBtContext::extractUrlList(const MetaEntry* obj)
|
||||
void DefaultBtContext::extractUrlList(std::deque<std::string>& uris,
|
||||
const MetaEntry* obj)
|
||||
{
|
||||
std::deque<std::string> uris;
|
||||
if(dynamic_cast<const List*>(obj)) {
|
||||
const List* urlList = reinterpret_cast<const List*>(obj);
|
||||
for(std::deque<MetaEntry*>::const_iterator itr = urlList->getList().begin();
|
||||
@ -232,7 +232,6 @@ std::deque<std::string> DefaultBtContext::extractUrlList(const MetaEntry* obj)
|
||||
const Data* urlData = reinterpret_cast<const Data*>(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<std::string> urlList = extractUrlList(rootDic->get("url-list"));
|
||||
std::deque<std::string> 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<size_t> DefaultBtContext::computeFastSet(const std::string& ipaddr, size_t fastSetSize)
|
||||
void DefaultBtContext::computeFastSet
|
||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize)
|
||||
{
|
||||
std::deque<size_t> 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<size_t> 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)
|
||||
|
@ -81,7 +81,7 @@ private:
|
||||
void extractAnnounce(const Data* announceData);
|
||||
void extractAnnounceList(const List* announceListData);
|
||||
|
||||
std::deque<std::string> extractUrlList(const MetaEntry* obj);
|
||||
void extractUrlList(std::deque<std::string>& uris, const MetaEntry* obj);
|
||||
|
||||
void extractNodes(const List* nodes);
|
||||
|
||||
@ -143,7 +143,8 @@ private:
|
||||
return reinterpret_cast<const unsigned char*>(peerId.c_str());
|
||||
}
|
||||
|
||||
virtual std::deque<size_t> computeFastSet(const std::string& ipaddr, size_t fastSetSize);
|
||||
virtual void computeFastSet
|
||||
(std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize);
|
||||
|
||||
virtual RequestGroup* getOwnerRequestGroup()
|
||||
{
|
||||
|
@ -178,8 +178,8 @@ void DefaultBtInteractive::addBitfieldMessageToQueue() {
|
||||
|
||||
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
std::deque<size_t> fastSet = btContext->computeFastSet(peer->ipaddr,
|
||||
allowedFastSetSize);
|
||||
std::deque<size_t> fastSet;
|
||||
btContext->computeFastSet(fastSet, peer->ipaddr, allowedFastSetSize);
|
||||
for(std::deque<size_t>::const_iterator itr = fastSet.begin();
|
||||
itr != fastSet.end(); itr++) {
|
||||
dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr));
|
||||
|
@ -241,18 +241,23 @@ void DefaultBtContextTest::testComputeFastSet()
|
||||
btContext.setInfoHash(infoHash);
|
||||
btContext.setNumPieces(pieces);
|
||||
|
||||
std::deque<size_t> 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<size_t> ansSet1(&ans1[0], &ans1[10]);
|
||||
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin()));
|
||||
|
||||
{
|
||||
std::deque<size_t> 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<size_t> 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<size_t> ansSet2(&ans2[0], &ans2[10]);
|
||||
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin()));
|
||||
{
|
||||
std::deque<size_t> fastSet;
|
||||
btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
|
||||
size_t ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
|
||||
std::deque<size_t> ansSet2(&ans2[0], &ans2[10]);
|
||||
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
|
||||
|
@ -123,9 +123,10 @@ public:
|
||||
memcpy(this->peerId, peerId, sizeof(this->peerId));
|
||||
}
|
||||
|
||||
virtual std::deque<size_t> computeFastSet(const std::string& ipaddr, size_t fastSetSize)
|
||||
virtual void computeFastSet
|
||||
(std::deque<size_t>& 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<size_t>& fastSet)
|
||||
|
Loading…
Reference in New Issue
Block a user