2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

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
pull/1/head
Tatsuhiro Tsujikawa 2008-05-11 12:14:14 +00:00
parent 5e99846776
commit 33e916547a
9 changed files with 34 additions and 15 deletions

View File

@ -1,3 +1,17 @@
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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 <tujikawa at rednoah dot com>
Changed method signature:

View File

@ -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<SharedHandle<Peer> > peers;
_peerAnnounceStorage->getPeers(peers, _infoHash);
SharedHandle<DHTMessage> reply;
if(peers.empty()) {
std::deque<SharedHandle<DHTNode> > nodes;

View File

@ -102,9 +102,8 @@ bool DHTPeerAnnounceEntry::empty() const
return _peerAddrEntries.empty() && _btCtx.isNull();
}
Peers DHTPeerAnnounceEntry::getPeers() const
void DHTPeerAnnounceEntry::getPeers(std::deque<SharedHandle<Peer> >& peers) const
{
std::deque<SharedHandle<Peer> > peers;
for(std::deque<PeerAddrEntry>::const_iterator i = _peerAddrEntries.begin();
i != _peerAddrEntries.end(); ++i) {
SharedHandle<Peer> 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()

View File

@ -87,7 +87,7 @@ public:
return _infoHash;
}
std::deque<SharedHandle<Peer> > getPeers() const;
void getPeers(std::deque<SharedHandle<Peer> >& peers) const;
};

View File

@ -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<SharedHandle<Peer> >& peers,
const unsigned char* infoHash)
{
std::deque<SharedHandle<DHTPeerAnnounceEntry> >::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()

View File

@ -76,7 +76,8 @@ public:
bool contains(const unsigned char* infoHash) const;
std::deque<SharedHandle<Peer> > getPeers(const unsigned char* infoHash);
void getPeers(std::deque<SharedHandle<Peer> >& peers,
const unsigned char* infoHash);
// drop peer announce entry which is not updated in the past
// DHT_PEER_ANNOUNCE_PURGE_INTERVAL seconds.

View File

@ -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<SharedHandle<Peer> > peers = peerAnnounceStorage.getPeers(infoHash);
std::deque<SharedHandle<Peer> > peers;
peerAnnounceStorage.getPeers(peers, infoHash);
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
{
SharedHandle<Peer> peer = peers[0];

View File

@ -115,7 +115,8 @@ void DHTPeerAnnounceEntryTest::testGetPeers()
DHTPeerAnnounceEntry entry(infohash);
{
std::deque<SharedHandle<Peer> > peers = entry.getPeers();
std::deque<SharedHandle<Peer> > 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<SharedHandle<Peer> > peers = entry.getPeers();
std::deque<SharedHandle<Peer> > 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<SharedHandle<Peer> > peers = entry.getPeers();
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);

View File

@ -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<SharedHandle<Peer> > peers = storage.getPeers(infohash2);
std::deque<SharedHandle<Peer> > 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);