From 20c8ce4128bb226d252159e135f8e0d3d0387bee Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 31 Oct 2009 11:54:54 +0000 Subject: [PATCH] 2009-10-31 Tatsuhiro Tsujikawa Removed peerStorage from DHTPeerAnnounceEntry. It is unlikely to receive get_peers request for torrent which the client is now downloading. * src/BtSetup.cc * src/DHTPeerAnnounceEntry.cc * src/DHTPeerAnnounceEntry.h * src/DHTPeerAnnounceStorage.cc * src/DHTPeerAnnounceStorage.h * src/RequestGroup.cc * test/DHTPeerAnnounceEntryTest.cc * test/DHTPeerAnnounceStorageTest.cc --- ChangeLog | 14 ++++++++++++++ src/BtSetup.cc | 2 -- src/DHTPeerAnnounceEntry.cc | 17 +--------------- src/DHTPeerAnnounceEntry.h | 7 ------- src/DHTPeerAnnounceStorage.cc | 29 ---------------------------- src/DHTPeerAnnounceStorage.h | 9 --------- src/RequestGroup.cc | 4 ---- test/DHTPeerAnnounceEntryTest.cc | 31 +----------------------------- test/DHTPeerAnnounceStorageTest.cc | 28 --------------------------- 9 files changed, 16 insertions(+), 125 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a63c206..871dfb36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-10-31 Tatsuhiro Tsujikawa + + Removed peerStorage from DHTPeerAnnounceEntry. It is unlikely to + receive get_peers request for torrent which the client is now + downloading. + * src/BtSetup.cc + * src/DHTPeerAnnounceEntry.cc + * src/DHTPeerAnnounceEntry.h + * src/DHTPeerAnnounceStorage.cc + * src/DHTPeerAnnounceStorage.h + * src/RequestGroup.cc + * test/DHTPeerAnnounceEntryTest.cc + * test/DHTPeerAnnounceStorageTest.cc + 2009-10-31 Tatsuhiro Tsujikawa Fixed the bug that in Windows environment new blank line is diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 46ac3bfe..af3ef582 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -112,8 +112,6 @@ void BtSetup::setup(std::deque& commands, } if(torrentAttrs[bittorrent::PRIVATE].i() == 0 && DHTSetup::initialized()) { - DHTRegistry::_peerAnnounceStorage->addPeerAnnounce - (torrentAttrs[bittorrent::INFO_HASH].uc(), peerStorage); DHTGetPeersCommand* command = new DHTGetPeersCommand(e->newCUID(), requestGroup, e); command->setTaskQueue(DHTRegistry::_taskQueue); diff --git a/src/DHTPeerAnnounceEntry.cc b/src/DHTPeerAnnounceEntry.cc index e05806ba..8b854ce9 100644 --- a/src/DHTPeerAnnounceEntry.cc +++ b/src/DHTPeerAnnounceEntry.cc @@ -38,7 +38,6 @@ #include #include "Peer.h" -#include "PeerStorage.h" namespace aria2 { @@ -60,17 +59,6 @@ void DHTPeerAnnounceEntry::addPeerAddrEntry(const PeerAddrEntry& entry) notifyUpdate(); } -void DHTPeerAnnounceEntry::clearLocal() -{ - _peerStorage.reset(); -} - -void DHTPeerAnnounceEntry::setPeerStorage -(const SharedHandle& peerStorage) -{ - _peerStorage = peerStorage; -} - size_t DHTPeerAnnounceEntry::countPeerAddrEntry() const { return _peerAddrEntries.size(); @@ -100,7 +88,7 @@ void DHTPeerAnnounceEntry::removeStalePeerAddrEntry(time_t timeout) bool DHTPeerAnnounceEntry::empty() const { - return _peerAddrEntries.empty() && _peerStorage.isNull(); + return _peerAddrEntries.empty(); } void DHTPeerAnnounceEntry::getPeers(std::deque >& peers) const @@ -110,9 +98,6 @@ void DHTPeerAnnounceEntry::getPeers(std::deque >& peers) cons SharedHandle peer(new Peer((*i).getIPAddress(), (*i).getPort())); peers.push_back(peer); } - if(!_peerStorage.isNull()) { - _peerStorage->getActivePeers(peers); - } } void DHTPeerAnnounceEntry::notifyUpdate() diff --git a/src/DHTPeerAnnounceEntry.h b/src/DHTPeerAnnounceEntry.h index d9f66239..168534fa 100644 --- a/src/DHTPeerAnnounceEntry.h +++ b/src/DHTPeerAnnounceEntry.h @@ -47,7 +47,6 @@ namespace aria2 { class Peer; -class PeerStorage; class DHTPeerAnnounceEntry { private: @@ -55,8 +54,6 @@ private: std::deque _peerAddrEntries; - SharedHandle _peerStorage; - Time _lastUpdated; public: DHTPeerAnnounceEntry(const unsigned char* infoHash); @@ -67,10 +64,6 @@ public: // if it already exists, update "Last Updated" property. void addPeerAddrEntry(const PeerAddrEntry& entry); - void clearLocal(); - - void setPeerStorage(const SharedHandle& peerStorage); - size_t countPeerAddrEntry() const; const std::deque& getPeerAddrEntries() const diff --git a/src/DHTPeerAnnounceStorage.cc b/src/DHTPeerAnnounceStorage.cc index 6229e703..8bbbd65d 100644 --- a/src/DHTPeerAnnounceStorage.cc +++ b/src/DHTPeerAnnounceStorage.cc @@ -39,7 +39,6 @@ #include "DHTPeerAnnounceEntry.h" #include "Peer.h" -#include "PeerStorage.h" #include "DHTConstants.h" #include "DHTTaskQueue.h" #include "DHTTaskFactory.h" @@ -92,34 +91,6 @@ DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash, getPeerAnnounceEntry(infoHash)->addPeerAddrEntry(PeerAddrEntry(ipaddr, port)); } -// add peer announce as localhost downloading the content -void DHTPeerAnnounceStorage::addPeerAnnounce -(const unsigned char* infoHash, const SharedHandle& peerStorage) -{ - _logger->debug("Adding localhost to peer announce list: infoHash=%s", - util::toHex(infoHash, DHT_ID_LENGTH).c_str()); - SharedHandle entry = - getPeerAnnounceEntry(infoHash); - entry->setPeerStorage(peerStorage); -} - -void DHTPeerAnnounceStorage::removeLocalPeerAnnounce -(const unsigned char* infoHash) -{ - SharedHandle entry(new DHTPeerAnnounceEntry(infoHash)); - - std::deque >::iterator i = - std::lower_bound(_entries.begin(), _entries.end(), entry, InfoHashLess()); - - if(i != _entries.end() && - memcmp(infoHash, (*i)->getInfoHash(), DHT_ID_LENGTH) == 0) { - (*i)->clearLocal(); - if((*i)->empty()) { - _entries.erase(i); - } - } -} - bool DHTPeerAnnounceStorage::contains(const unsigned char* infoHash) const { SharedHandle entry(new DHTPeerAnnounceEntry(infoHash)); diff --git a/src/DHTPeerAnnounceStorage.h b/src/DHTPeerAnnounceStorage.h index 0d9ce87c..8b08b839 100644 --- a/src/DHTPeerAnnounceStorage.h +++ b/src/DHTPeerAnnounceStorage.h @@ -41,7 +41,6 @@ namespace aria2 { -class PeerStorage; class Peer; class DHTPeerAnnounceEntry; class DHTTaskQueue; @@ -67,14 +66,6 @@ public: void addPeerAnnounce(const unsigned char* infoHash, const std::string& ipaddr, uint16_t port); - // add peer announce as localhost downloading the content - void addPeerAnnounce(const unsigned char* infoHash, - const SharedHandle& peerStorage); - - // Call DHTPeerAnnounceEntry::clearLocal() for infoHash if found. - // If DHTPeerAnnounceEntry is empty, it is erased. - void removeLocalPeerAnnounce(const unsigned char* infoHash); - bool contains(const unsigned char* infoHash) const; void getPeers(std::deque >& peers, diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 7f98e7d6..8317592c 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -764,10 +764,6 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e) if(!contextInReg.isNull() && contextInReg->getOwnerRequestGroup()->getGID() == _gid) { btRegistry->remove(infoHash); - if(!DHTRegistry::_peerAnnounceStorage.isNull()) { - DHTRegistry::_peerAnnounceStorage->removeLocalPeerAnnounce - (torrentAttrs[bittorrent::INFO_HASH].uc()); - } } } #endif // ENABLE_BITTORRENT diff --git a/test/DHTPeerAnnounceEntryTest.cc b/test/DHTPeerAnnounceEntryTest.cc index cc79afce..a7cc91af 100644 --- a/test/DHTPeerAnnounceEntryTest.cc +++ b/test/DHTPeerAnnounceEntryTest.cc @@ -6,8 +6,8 @@ #include "Exception.h" #include "util.h" -#include "MockPeerStorage.h" #include "FileEntry.h" +#include "Peer.h" namespace aria2 { @@ -59,11 +59,6 @@ void DHTPeerAnnounceEntryTest::testEmpty() entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.1", 6881)); CPPUNIT_ASSERT(!entry.empty()); } - { - DHTPeerAnnounceEntry entry(infohash); - entry.setPeerStorage(SharedHandle(new MockPeerStorage())); - CPPUNIT_ASSERT(!entry.empty()); - } { DHTPeerAnnounceEntry entry(infohash); CPPUNIT_ASSERT(entry.empty()); @@ -92,16 +87,6 @@ void DHTPeerAnnounceEntryTest::testGetPeers() unsigned char infohash[DHT_ID_LENGTH]; memset(infohash, 0xff, DHT_ID_LENGTH); - SharedHandle peerStorage(new MockPeerStorage()); - { - SharedHandle activePeers[2]; - activePeers[0].reset(new Peer("192.168.0.3", 6883)); - activePeers[1].reset(new Peer("192.168.0.4", 6884)); - - peerStorage->setActivePeers(std::deque >(&activePeers[0], - &activePeers[2])); - } - DHTPeerAnnounceEntry entry(infohash); { std::deque > peers; @@ -121,20 +106,6 @@ void DHTPeerAnnounceEntryTest::testGetPeers() CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peers[1]->ipaddr); CPPUNIT_ASSERT_EQUAL((uint16_t)6882, peers[1]->port); } - entry.setPeerStorage(peerStorage); - { - std::deque > peers; - entry.getPeers(peers); - CPPUNIT_ASSERT_EQUAL((size_t)4, peers.size()); - CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peers[0]->ipaddr); - CPPUNIT_ASSERT_EQUAL((uint16_t)6881, peers[0]->port); - CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peers[1]->ipaddr); - CPPUNIT_ASSERT_EQUAL((uint16_t)6882, peers[1]->port); - CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.3"), peers[2]->ipaddr); - CPPUNIT_ASSERT_EQUAL((uint16_t)6883, peers[2]->port); - CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.4"), peers[3]->ipaddr); - CPPUNIT_ASSERT_EQUAL((uint16_t)6884, peers[3]->port); - } } } // namespace aria2 diff --git a/test/DHTPeerAnnounceStorageTest.cc b/test/DHTPeerAnnounceStorageTest.cc index 48a3d71a..d53f7b51 100644 --- a/test/DHTPeerAnnounceStorageTest.cc +++ b/test/DHTPeerAnnounceStorageTest.cc @@ -7,7 +7,6 @@ #include "Exception.h" #include "util.h" #include "DownloadContext.h" -#include "MockPeerStorage.h" #include "DHTConstants.h" #include "Peer.h" #include "FileEntry.h" @@ -19,11 +18,9 @@ class DHTPeerAnnounceStorageTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DHTPeerAnnounceStorageTest); CPPUNIT_TEST(testAddAnnounce); - CPPUNIT_TEST(testRemovePeerAnnounce); CPPUNIT_TEST_SUITE_END(); public: void testAddAnnounce(); - void testRemovePeerAnnounce(); }; @@ -61,29 +58,4 @@ static SharedHandle createDownloadContext return dctx; } -void DHTPeerAnnounceStorageTest::testRemovePeerAnnounce() -{ - unsigned char infoHash1[DHT_ID_LENGTH]; - memset(infoHash1, 0xff, DHT_ID_LENGTH); - unsigned char infoHash2[DHT_ID_LENGTH]; - memset(infoHash2, 0xf0, DHT_ID_LENGTH); - DHTPeerAnnounceStorage storage; - - SharedHandle ctx1 = createDownloadContext(infoHash1); - SharedHandle ctx2 = createDownloadContext(infoHash2); - - SharedHandle peerStorage1(new MockPeerStorage()); - SharedHandle peerStorage2(new MockPeerStorage()); - - storage.addPeerAnnounce(infoHash1, "192.168.0.1", 6881); - storage.addPeerAnnounce(infoHash1, peerStorage1); - storage.addPeerAnnounce(infoHash2, peerStorage2); - - storage.removeLocalPeerAnnounce(bittorrent::getInfoHash(ctx2)); - CPPUNIT_ASSERT(!storage.contains(infoHash2)); - - storage.removeLocalPeerAnnounce(bittorrent::getInfoHash(ctx1)); - CPPUNIT_ASSERT(storage.contains(infoHash1)); -} - } // namespace aria2