diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-10-31 11:54:54 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-10-31 11:54:54 +0000 |
| commit | 20c8ce4128bb226d252159e135f8e0d3d0387bee (patch) | |
| tree | f35c632cef4a94f433cc1f8e2bddfe64ad7598ed | |
| parent | 0dcb41da49c41f0f76bb538b93796a4d0dda2146 (diff) | |
2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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
| -rw-r--r-- | ChangeLog | 14 | ||||
| -rw-r--r-- | src/BtSetup.cc | 2 | ||||
| -rw-r--r-- | src/DHTPeerAnnounceEntry.cc | 17 | ||||
| -rw-r--r-- | src/DHTPeerAnnounceEntry.h | 7 | ||||
| -rw-r--r-- | src/DHTPeerAnnounceStorage.cc | 29 | ||||
| -rw-r--r-- | src/DHTPeerAnnounceStorage.h | 9 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 4 | ||||
| -rw-r--r-- | test/DHTPeerAnnounceEntryTest.cc | 31 | ||||
| -rw-r--r-- | test/DHTPeerAnnounceStorageTest.cc | 28 |
9 files changed, 16 insertions, 125 deletions
@@ -1,5 +1,19 @@ 2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> + 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 <t-tujikawa@users.sourceforge.net> + Fixed the bug that in Windows environment new blank line is inserted when console readout is updated. * src/ConsoleStatCalc.cc 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<Command*>& 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 <algorithm> #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 = 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<SharedHandle<Peer> >& peers) const @@ -110,9 +98,6 @@ void DHTPeerAnnounceEntry::getPeers(std::deque<SharedHandle<Peer> >& peers) cons SharedHandle<Peer> 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<PeerAddrEntry> _peerAddrEntries; - SharedHandle<PeerStorage> _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>& peerStorage); - size_t countPeerAddrEntry() const; const std::deque<PeerAddrEntry>& 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>& peerStorage) -{ - _logger->debug("Adding localhost to peer announce list: infoHash=%s", - util::toHex(infoHash, DHT_ID_LENGTH).c_str()); - SharedHandle<DHTPeerAnnounceEntry> entry = - getPeerAnnounceEntry(infoHash); - entry->setPeerStorage(peerStorage); -} - -void DHTPeerAnnounceStorage::removeLocalPeerAnnounce -(const unsigned char* infoHash) -{ - SharedHandle<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash)); - - std::deque<SharedHandle<DHTPeerAnnounceEntry> >::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<DHTPeerAnnounceEntry> 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>& 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<SharedHandle<Peer> >& 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 { @@ -61,11 +61,6 @@ void DHTPeerAnnounceEntryTest::testEmpty() } { DHTPeerAnnounceEntry entry(infohash); - entry.setPeerStorage(SharedHandle<PeerStorage>(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<MockPeerStorage> peerStorage(new MockPeerStorage()); - { - SharedHandle<Peer> 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<SharedHandle<Peer> >(&activePeers[0], - &activePeers[2])); - } - DHTPeerAnnounceEntry entry(infohash); { std::deque<SharedHandle<Peer> > 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<SharedHandle<Peer> > 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<DownloadContext> 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<DownloadContext> ctx1 = createDownloadContext(infoHash1); - SharedHandle<DownloadContext> ctx2 = createDownloadContext(infoHash2); - - SharedHandle<MockPeerStorage> peerStorage1(new MockPeerStorage()); - SharedHandle<MockPeerStorage> 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 |
