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
pull/1/head
Tatsuhiro Tsujikawa 2008-05-12 12:18:21 +00:00
parent 6ae07106d3
commit 41b6003cbd
7 changed files with 44 additions and 27 deletions

View File

@ -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> 2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method signature: Changed method signature:

View File

@ -73,8 +73,8 @@ public:
return _private; return _private;
} }
virtual std::deque<size_t> virtual void computeFastSet
computeFastSet(const std::string& ipaddr, size_t fastSetSize) = 0; (std::deque<size_t>& fastSet, const std::string& ipaddr, size_t fastSetSize) = 0;
virtual RequestGroup* getOwnerRequestGroup() = 0; virtual RequestGroup* getOwnerRequestGroup() = 0;

View File

@ -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)) { if(dynamic_cast<const List*>(obj)) {
const List* urlList = reinterpret_cast<const List*>(obj); const List* urlList = reinterpret_cast<const List*>(obj);
for(std::deque<MetaEntry*>::const_iterator itr = urlList->getList().begin(); 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); const Data* urlData = reinterpret_cast<const Data*>(obj);
uris.push_back(urlData->toString()); uris.push_back(urlData->toString());
} }
return uris;
} }
void DefaultBtContext::extractNodes(const List* nodes) void DefaultBtContext::extractNodes(const List* nodes)
@ -334,7 +333,8 @@ void DefaultBtContext::processRootDictionary(const Dictionary* rootDic, const st
// retrieve uri-list. // retrieve uri-list.
// This implemantation obeys HTTP-Seeding specification: // This implemantation obeys HTTP-Seeding specification:
// see http://www.getright.com/seedtorrent.html // 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 // retrieve file entries
extractFileEntries(infoDic, defaultName, urlList); extractFileEntries(infoDic, defaultName, urlList);
if((totalLength+pieceLength-1)/pieceLength != numPieces) { if((totalLength+pieceLength-1)/pieceLength != numPieces) {
@ -396,12 +396,12 @@ std::string DefaultBtContext::getActualBasePath() const
return _dir+"/"+name; 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]; unsigned char compact[6];
if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) { if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) {
return fastSet; return;
} }
unsigned char tx[24]; unsigned char tx[24];
memcpy(tx, compact, 4); 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)); MessageDigestHelper::digest(temp, sizeof(temp), "sha1", x, sizeof(x));
memcpy(x, temp, sizeof(x)); memcpy(x, temp, sizeof(x));
} }
return fastSet;
} }
std::ostream& operator<<(std::ostream& o, const DefaultBtContext& ctx) std::ostream& operator<<(std::ostream& o, const DefaultBtContext& ctx)

View File

@ -81,7 +81,7 @@ private:
void extractAnnounce(const Data* announceData); void extractAnnounce(const Data* announceData);
void extractAnnounceList(const List* announceListData); 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); void extractNodes(const List* nodes);
@ -143,7 +143,8 @@ private:
return reinterpret_cast<const unsigned char*>(peerId.c_str()); 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() virtual RequestGroup* getOwnerRequestGroup()
{ {

View File

@ -178,8 +178,8 @@ void DefaultBtInteractive::addBitfieldMessageToQueue() {
void DefaultBtInteractive::addAllowedFastMessageToQueue() { void DefaultBtInteractive::addAllowedFastMessageToQueue() {
if(peer->isFastExtensionEnabled()) { if(peer->isFastExtensionEnabled()) {
std::deque<size_t> fastSet = btContext->computeFastSet(peer->ipaddr, std::deque<size_t> fastSet;
allowedFastSetSize); btContext->computeFastSet(fastSet, peer->ipaddr, allowedFastSetSize);
for(std::deque<size_t>::const_iterator itr = fastSet.begin(); for(std::deque<size_t>::const_iterator itr = fastSet.begin();
itr != fastSet.end(); itr++) { itr != fastSet.end(); itr++) {
dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr)); dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr));

View File

@ -241,18 +241,23 @@ void DefaultBtContextTest::testComputeFastSet()
btContext.setInfoHash(infoHash); btContext.setInfoHash(infoHash);
btContext.setNumPieces(pieces); btContext.setNumPieces(pieces);
std::deque<size_t> fastSet = btContext.computeFastSet(ipaddr, fastSetSize); {
//for_each(fastSet.begin(), fastSet.end(), Printer()); std::deque<size_t> fastSet;
//cerr << endl; btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
size_t ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 }; //for_each(fastSet.begin(), fastSet.end(), Printer());
std::deque<size_t> ansSet1(&ans1[0], &ans1[10]); //cerr << endl;
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin())); 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"; 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> fastSet;
std::deque<size_t> ansSet2(&ans2[0], &ans2[10]); btContext.computeFastSet(fastSet, ipaddr, fastSetSize);
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin())); 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() { void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {

View File

@ -123,9 +123,10 @@ public:
memcpy(this->peerId, peerId, sizeof(this->peerId)); 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) void setFastSet(const std::deque<size_t>& fastSet)