mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
0dcb41da49
commit
20c8ce4128
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue