diff --git a/ChangeLog b/ChangeLog index c78ac941..77672c3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-05-11 Tatsuhiro Tsujikawa + + Changed method signature: + DHTPeerAnnounceStorage::getPeers, + DHTPeerAnnounceEntry::getPeers + * src/DHTGetPeersMessage.cc + * src/DHTPeerAnnounceEntry.cc + * src/DHTPeerAnnounceEntry.h + * src/DHTPeerAnnounceStorage.cc + * src/DHTPeerAnnounceStorage.h + * test/DHTAnnouncePeerMessageTest.cc + * test/DHTPeerAnnounceEntryTest.cc + * test/DHTPeerAnnounceStorageTest.cc + 2008-05-11 Tatsuhiro Tsujikawa Changed method signature: diff --git a/src/DHTGetPeersMessage.cc b/src/DHTGetPeersMessage.cc index 083a6bf0..f0333580 100644 --- a/src/DHTGetPeersMessage.cc +++ b/src/DHTGetPeersMessage.cc @@ -66,7 +66,8 @@ void DHTGetPeersMessage::doReceivedAction() _remoteNode->getIPAddress(), _remoteNode->getPort()); // Check to see localhost has the contents which has same infohash - Peers peers = _peerAnnounceStorage->getPeers(_infoHash); + std::deque > peers; + _peerAnnounceStorage->getPeers(peers, _infoHash); SharedHandle reply; if(peers.empty()) { std::deque > nodes; diff --git a/src/DHTPeerAnnounceEntry.cc b/src/DHTPeerAnnounceEntry.cc index 393d6cd0..c8b1f20a 100644 --- a/src/DHTPeerAnnounceEntry.cc +++ b/src/DHTPeerAnnounceEntry.cc @@ -102,9 +102,8 @@ bool DHTPeerAnnounceEntry::empty() const return _peerAddrEntries.empty() && _btCtx.isNull(); } -Peers DHTPeerAnnounceEntry::getPeers() const +void DHTPeerAnnounceEntry::getPeers(std::deque >& peers) const { - std::deque > peers; for(std::deque::const_iterator i = _peerAddrEntries.begin(); i != _peerAddrEntries.end(); ++i) { SharedHandle peer(new Peer((*i).getIPAddress(), (*i).getPort())); @@ -117,7 +116,6 @@ Peers DHTPeerAnnounceEntry::getPeers() const peers.insert(peers.end(), activePeers.begin(), activePeers.end()); } } - return peers; } void DHTPeerAnnounceEntry::notifyUpdate() diff --git a/src/DHTPeerAnnounceEntry.h b/src/DHTPeerAnnounceEntry.h index 25497d25..c91fdef2 100644 --- a/src/DHTPeerAnnounceEntry.h +++ b/src/DHTPeerAnnounceEntry.h @@ -87,7 +87,7 @@ public: return _infoHash; } - std::deque > getPeers() const; + void getPeers(std::deque >& peers) const; }; diff --git a/src/DHTPeerAnnounceStorage.cc b/src/DHTPeerAnnounceStorage.cc index 46fab662..ad27da5d 100644 --- a/src/DHTPeerAnnounceStorage.cc +++ b/src/DHTPeerAnnounceStorage.cc @@ -118,14 +118,14 @@ bool DHTPeerAnnounceStorage::contains(const unsigned char* infoHash) const std::find_if(_entries.begin(), _entries.end(), FindPeerAnnounceEntry(infoHash)) != _entries.end(); } -Peers DHTPeerAnnounceStorage::getPeers(const unsigned char* infoHash) +void DHTPeerAnnounceStorage::getPeers(std::deque >& peers, + const unsigned char* infoHash) { std::deque >::iterator i = std::find_if(_entries.begin(), _entries.end(), FindPeerAnnounceEntry(infoHash)); - if(i == _entries.end() || (*i)->empty()) { - return Peers(); + if(i != _entries.end() && !(*i)->empty()) { + (*i)->getPeers(peers); } - return (*i)->getPeers(); } void DHTPeerAnnounceStorage::handleTimeout() diff --git a/src/DHTPeerAnnounceStorage.h b/src/DHTPeerAnnounceStorage.h index 1e085ca3..d62d612a 100644 --- a/src/DHTPeerAnnounceStorage.h +++ b/src/DHTPeerAnnounceStorage.h @@ -76,7 +76,8 @@ public: bool contains(const unsigned char* infoHash) const; - std::deque > getPeers(const unsigned char* infoHash); + void getPeers(std::deque >& peers, + const unsigned char* infoHash); // drop peer announce entry which is not updated in the past // DHT_PEER_ANNOUNCE_PURGE_INTERVAL seconds. diff --git a/test/DHTAnnouncePeerMessageTest.cc b/test/DHTAnnouncePeerMessageTest.cc index 6a00a7e4..eddd3d2c 100644 --- a/test/DHTAnnouncePeerMessageTest.cc +++ b/test/DHTAnnouncePeerMessageTest.cc @@ -115,7 +115,8 @@ void DHTAnnouncePeerMessageTest::testDoReceivedAction() CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT_EQUAL(std::string("announce_peer"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(transactionID, m->getTransactionID()); - std::deque > peers = peerAnnounceStorage.getPeers(infoHash); + std::deque > peers; + peerAnnounceStorage.getPeers(peers, infoHash); CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size()); { SharedHandle peer = peers[0]; diff --git a/test/DHTPeerAnnounceEntryTest.cc b/test/DHTPeerAnnounceEntryTest.cc index 419fe0b0..16c4fccf 100644 --- a/test/DHTPeerAnnounceEntryTest.cc +++ b/test/DHTPeerAnnounceEntryTest.cc @@ -115,7 +115,8 @@ void DHTPeerAnnounceEntryTest::testGetPeers() DHTPeerAnnounceEntry entry(infohash); { - std::deque > peers = entry.getPeers(); + std::deque > peers; + entry.getPeers(peers); CPPUNIT_ASSERT_EQUAL((size_t)0, peers.size()); } @@ -123,7 +124,8 @@ void DHTPeerAnnounceEntryTest::testGetPeers() entry.addPeerAddrEntry(PeerAddrEntry("192.168.0.2", 6882)); { - std::deque > peers = entry.getPeers(); + std::deque > peers; + entry.getPeers(peers); CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size()); CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peers[0]->ipaddr); CPPUNIT_ASSERT_EQUAL((uint16_t)6881, peers[0]->port); @@ -132,7 +134,8 @@ void DHTPeerAnnounceEntryTest::testGetPeers() } entry.setBtContext(ctx); { - std::deque > peers = entry.getPeers(); + 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); diff --git a/test/DHTPeerAnnounceStorageTest.cc b/test/DHTPeerAnnounceStorageTest.cc index 8a11a28c..0f93a8a4 100644 --- a/test/DHTPeerAnnounceStorageTest.cc +++ b/test/DHTPeerAnnounceStorageTest.cc @@ -40,7 +40,8 @@ void DHTPeerAnnounceStorageTest::testAddAnnounce() storage.addPeerAnnounce(infohash2, "192.168.0.3", 6883); storage.addPeerAnnounce(infohash2, "192.168.0.4", 6884); - std::deque > peers = storage.getPeers(infohash2); + std::deque > peers; + storage.getPeers(peers, infohash2); CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size()); CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.3"), peers[0]->ipaddr);