mirror of https://github.com/aria2/aria2
2009-06-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten BtRegistry * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/ConsoleStatCalc.cc * src/PeerInteractionCommand.cc * src/PeerReceiveHandshakeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/XmlRpcMethodImpl.cc * test/BtRegistryTest.ccpull/1/head
parent
5e835ae885
commit
eaf5217de7
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2009-06-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Rewritten BtRegistry
|
||||||
|
* src/BtRegistry.cc
|
||||||
|
* src/BtRegistry.h
|
||||||
|
* src/BtSetup.cc
|
||||||
|
* src/ConsoleStatCalc.cc
|
||||||
|
* src/PeerInteractionCommand.cc
|
||||||
|
* src/PeerReceiveHandshakeCommand.cc
|
||||||
|
* src/ReceiverMSEHandshakeCommand.cc
|
||||||
|
* src/RequestGroup.cc
|
||||||
|
* src/XmlRpcMethodImpl.cc
|
||||||
|
* test/BtRegistryTest.cc
|
||||||
|
|
||||||
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Used array_ptr for savedInfoHash, savedBitfield and pieceBitfield.
|
Used array_ptr for savedInfoHash, savedBitfield and pieceBitfield.
|
||||||
|
|
|
@ -43,103 +43,36 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
BtRegistry::BtRegistry() {}
|
SharedHandle<BtContext>
|
||||||
|
BtRegistry::getBtContext(const std::string& infoHash) const
|
||||||
PeerStorageHandle BtRegistry::getPeerStorage(const std::string& key)
|
|
||||||
{
|
{
|
||||||
return peerStorageMap.getHandle(key);
|
return get(infoHash)._btContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistry::registerPeerStorage(const std::string& key,
|
void BtRegistry::put(const std::string& infoHash, const BtObject& obj)
|
||||||
const PeerStorageHandle& peerStorage)
|
|
||||||
{
|
{
|
||||||
peerStorageMap.registerHandle(key, peerStorage);
|
remove(infoHash);
|
||||||
|
std::map<std::string, BtObject>::value_type p(infoHash, obj);
|
||||||
|
_pool.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceStorageHandle
|
BtObject BtRegistry::get(const std::string& infoHash) const
|
||||||
BtRegistry::getPieceStorage(const std::string& key)
|
|
||||||
{
|
{
|
||||||
return pieceStorageMap.getHandle(key);
|
std::map<std::string, BtObject>::const_iterator i = _pool.find(infoHash);
|
||||||
|
if(i == _pool.end()) {
|
||||||
|
return BtObject();
|
||||||
|
} else {
|
||||||
|
return (*i).second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool BtRegistry::remove(const std::string& infoHash)
|
||||||
BtRegistry::registerPieceStorage(const std::string& key,
|
|
||||||
const PieceStorageHandle& pieceStorage)
|
|
||||||
{
|
{
|
||||||
pieceStorageMap.registerHandle(key, pieceStorage);
|
return _pool.erase(infoHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
BtRuntimeHandle BtRegistry::getBtRuntime(const std::string& key)
|
void BtRegistry::removeAll() {
|
||||||
{
|
_pool.clear();
|
||||||
return btRuntimeMap.getHandle(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
BtRegistry::registerBtRuntime(const std::string& key,
|
|
||||||
const BtRuntimeHandle& btRuntime)
|
|
||||||
{
|
|
||||||
btRuntimeMap.registerHandle(key, btRuntime);
|
|
||||||
}
|
|
||||||
|
|
||||||
BtAnnounceHandle BtRegistry::getBtAnnounce(const std::string& key)
|
|
||||||
{
|
|
||||||
return btAnnounceMap.getHandle(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
BtRegistry::registerBtAnnounce(const std::string& key,
|
|
||||||
const BtAnnounceHandle& btAnnounce)
|
|
||||||
{
|
|
||||||
btAnnounceMap.registerHandle(key, btAnnounce);
|
|
||||||
}
|
|
||||||
|
|
||||||
BtProgressInfoFileHandle BtRegistry::getBtProgressInfoFile(const std::string& key)
|
|
||||||
{
|
|
||||||
return btProgressInfoFileMap.getHandle(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
BtRegistry::registerBtProgressInfoFile(const std::string& key,
|
|
||||||
const BtProgressInfoFileHandle& btProgressInfoFile)
|
|
||||||
{
|
|
||||||
btProgressInfoFileMap.registerHandle(key, btProgressInfoFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
BtContextHandle
|
|
||||||
BtRegistry::getBtContext(const std::string& key)
|
|
||||||
{
|
|
||||||
return btContextMap.getHandle(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
BtRegistry::registerBtContext(const std::string& key,
|
|
||||||
const BtContextHandle& btContext)
|
|
||||||
{
|
|
||||||
btContextMap.registerHandle(key, btContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::deque<SharedHandle<BtContext> > BtRegistry::getAllBtContext()
|
|
||||||
{
|
|
||||||
return btContextMap.getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BtRegistry::unregisterAll() {
|
|
||||||
btContextMap.clear();
|
|
||||||
peerStorageMap.clear();
|
|
||||||
pieceStorageMap.clear();
|
|
||||||
btAnnounceMap.clear();
|
|
||||||
btRuntimeMap.clear();
|
|
||||||
btProgressInfoFileMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BtRegistry::unregister(const std::string& key)
|
|
||||||
{
|
|
||||||
btContextMap.unregisterHandle(key);
|
|
||||||
peerStorageMap.unregisterHandle(key);
|
|
||||||
pieceStorageMap.unregisterHandle(key);
|
|
||||||
btAnnounceMap.unregisterHandle(key);
|
|
||||||
btRuntimeMap.unregisterHandle(key);
|
|
||||||
btProgressInfoFileMap.unregisterHandle(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -39,9 +39,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "HandleRegistry.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -52,54 +52,62 @@ class BtRuntime;
|
||||||
class BtProgressInfoFile;
|
class BtProgressInfoFile;
|
||||||
class BtContext;
|
class BtContext;
|
||||||
|
|
||||||
typedef HandleRegistry<std::string, PeerStorage> PeerStorageMap;
|
struct BtObject {
|
||||||
typedef HandleRegistry<std::string, PieceStorage> PieceStorageMap;
|
SharedHandle<BtContext> _btContext;
|
||||||
typedef HandleRegistry<std::string, BtAnnounce> BtAnnounceMap;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
typedef HandleRegistry<std::string, BtRuntime> BtRuntimeMap;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
typedef HandleRegistry<std::string, BtProgressInfoFile> BtProgressInfoFileMap;
|
SharedHandle<BtAnnounce> _btAnnounce;
|
||||||
typedef HandleRegistry<std::string, BtContext> BtContextMap;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
|
SharedHandle<BtProgressInfoFile> _btProgressInfoFile;
|
||||||
|
|
||||||
|
BtObject(const SharedHandle<BtContext>& btContext,
|
||||||
|
const SharedHandle<PieceStorage>& pieceStorage,
|
||||||
|
const SharedHandle<PeerStorage>& peerStorage,
|
||||||
|
const SharedHandle<BtAnnounce>& btAnnounce,
|
||||||
|
const SharedHandle<BtRuntime>& btRuntime,
|
||||||
|
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile):
|
||||||
|
_btContext(btContext),
|
||||||
|
_pieceStorage(pieceStorage),
|
||||||
|
_peerStorage(peerStorage),
|
||||||
|
_btAnnounce(btAnnounce),
|
||||||
|
_btRuntime(btRuntime),
|
||||||
|
_btProgressInfoFile(btProgressInfoFile) {}
|
||||||
|
|
||||||
|
BtObject() {}
|
||||||
|
|
||||||
|
bool isNull() const
|
||||||
|
{
|
||||||
|
return _btContext.isNull() &&
|
||||||
|
_pieceStorage.isNull() &&
|
||||||
|
_peerStorage.isNull() &&
|
||||||
|
_btAnnounce.isNull() &&
|
||||||
|
_btRuntime.isNull() &&
|
||||||
|
_btProgressInfoFile.isNull();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class BtRegistry {
|
class BtRegistry {
|
||||||
private:
|
private:
|
||||||
BtContextMap btContextMap;
|
std::map<std::string, BtObject> _pool;
|
||||||
PeerStorageMap peerStorageMap;
|
|
||||||
PieceStorageMap pieceStorageMap;
|
|
||||||
BtAnnounceMap btAnnounceMap;
|
|
||||||
BtRuntimeMap btRuntimeMap;
|
|
||||||
BtProgressInfoFileMap btProgressInfoFileMap;
|
|
||||||
public:
|
public:
|
||||||
BtRegistry();
|
SharedHandle<BtContext> getBtContext(const std::string& infoHash) const;
|
||||||
|
|
||||||
SharedHandle<BtContext> getBtContext(const std::string& key);
|
void put(const std::string& infoHash, const BtObject& obj);
|
||||||
void registerBtContext(const std::string& key,
|
|
||||||
const SharedHandle<BtContext>& btContext);
|
|
||||||
|
|
||||||
SharedHandle<PeerStorage> getPeerStorage(const std::string& key);
|
BtObject get(const std::string& infoHash) const;
|
||||||
void registerPeerStorage(const std::string& key,
|
|
||||||
const SharedHandle<PeerStorage>& peer);
|
|
||||||
|
|
||||||
SharedHandle<PieceStorage> getPieceStorage(const std::string& key);
|
template<typename OutputIterator>
|
||||||
void registerPieceStorage(const std::string& key,
|
void getAllBtContext(OutputIterator dest)
|
||||||
const SharedHandle<PieceStorage>& pieceStorage);
|
{
|
||||||
|
for(std::map<std::string, BtObject>::const_iterator i = _pool.begin();
|
||||||
|
i != _pool.end(); ++i) {
|
||||||
|
*dest++ = (*i).second._btContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedHandle<BtRuntime> getBtRuntime(const std::string& key);
|
void removeAll();
|
||||||
void registerBtRuntime(const std::string& key,
|
|
||||||
const SharedHandle<BtRuntime>& btRuntime);
|
|
||||||
|
|
||||||
SharedHandle<BtAnnounce> getBtAnnounce(const std::string& key);
|
bool remove(const std::string& infoHash);
|
||||||
void registerBtAnnounce(const std::string& key,
|
|
||||||
const SharedHandle<BtAnnounce>& btAnnounce);
|
|
||||||
|
|
||||||
SharedHandle<BtProgressInfoFile>
|
|
||||||
getBtProgressInfoFile(const std::string& key);
|
|
||||||
void registerBtProgressInfoFile(const std::string& key,
|
|
||||||
const SharedHandle<BtProgressInfoFile>& file);
|
|
||||||
|
|
||||||
std::deque<SharedHandle<BtContext> > getAllBtContext();
|
|
||||||
|
|
||||||
void unregisterAll();
|
|
||||||
|
|
||||||
void unregister(const std::string& key);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -72,16 +72,11 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
if(btContext.isNull()) {
|
if(btContext.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
|
BtObject btObject = e->getBtRegistry()->get(btContext->getInfoHashAsString());
|
||||||
SharedHandle<PieceStorage> pieceStorage =
|
SharedHandle<PieceStorage> pieceStorage = btObject._pieceStorage;
|
||||||
btRegistry->getPieceStorage(btContext->getInfoHashAsString());
|
SharedHandle<PeerStorage> peerStorage = btObject._peerStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage =
|
SharedHandle<BtRuntime> btRuntime = btObject._btRuntime;
|
||||||
btRegistry->getPeerStorage(btContext->getInfoHashAsString());
|
SharedHandle<BtAnnounce> btAnnounce = btObject._btAnnounce;
|
||||||
SharedHandle<BtRuntime> btRuntime =
|
|
||||||
btRegistry->getBtRuntime(btContext->getInfoHashAsString());
|
|
||||||
SharedHandle<BtAnnounce> btAnnounce =
|
|
||||||
btRegistry->getBtAnnounce(btContext->getInfoHashAsString());
|
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
{
|
{
|
||||||
TrackerWatcherCommand* c =
|
TrackerWatcherCommand* c =
|
||||||
|
|
|
@ -116,7 +116,7 @@ static void printProgress
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(!btctx.isNull()) {
|
if(!btctx.isNull()) {
|
||||||
SharedHandle<PeerStorage> ps =
|
SharedHandle<PeerStorage> ps =
|
||||||
e->getBtRegistry()->getPeerStorage(btctx->getInfoHashAsString());
|
e->getBtRegistry()->get(btctx->getInfoHashAsString())._peerStorage;
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
ps->getActivePeers(peers);
|
ps->getActivePeers(peers);
|
||||||
o << " " << "SEED:"
|
o << " " << "SEED:"
|
||||||
|
|
|
@ -100,7 +100,7 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
|
|
||||||
SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
|
SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
|
||||||
SharedHandle<PeerStorage> peerStorage =
|
SharedHandle<PeerStorage> peerStorage =
|
||||||
btRegistry->getPeerStorage(_btContext->getInfoHashAsString());
|
btRegistry->get(_btContext->getInfoHashAsString())._peerStorage;
|
||||||
|
|
||||||
SharedHandle<ExtensionMessageRegistry> exMsgRegistry
|
SharedHandle<ExtensionMessageRegistry> exMsgRegistry
|
||||||
(new ExtensionMessageRegistry());
|
(new ExtensionMessageRegistry());
|
||||||
|
|
|
@ -93,13 +93,11 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
||||||
// check info_hash
|
// check info_hash
|
||||||
std::string infoHash = Util::toHex(&data[28], INFO_HASH_LENGTH);
|
std::string infoHash = Util::toHex(&data[28], INFO_HASH_LENGTH);
|
||||||
|
|
||||||
SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
|
BtObject btObject = e->getBtRegistry()->get(infoHash);
|
||||||
SharedHandle<BtContext> btContext = btRegistry->getBtContext(infoHash);
|
SharedHandle<BtContext> btContext = btObject._btContext;
|
||||||
SharedHandle<BtRuntime> btRuntime = btRegistry->getBtRuntime(infoHash);
|
SharedHandle<BtRuntime> btRuntime = btObject._btRuntime;
|
||||||
SharedHandle<PieceStorage> pieceStorage =
|
SharedHandle<PieceStorage> pieceStorage = btObject._pieceStorage;
|
||||||
btRegistry->getPieceStorage(infoHash);
|
SharedHandle<PeerStorage> peerStorage = btObject._peerStorage;
|
||||||
SharedHandle<PeerStorage> peerStorage =
|
|
||||||
btRegistry->getPeerStorage(infoHash);
|
|
||||||
|
|
||||||
if(btContext.isNull() || !btRuntime->ready()) {
|
if(btContext.isNull() || !btRuntime->ready()) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
|
|
@ -135,8 +135,9 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RECEIVER_RECEIVE_PAD_C_LENGTH: {
|
case RECEIVER_RECEIVE_PAD_C_LENGTH: {
|
||||||
if(_mseHandshake->receiveReceiverHashAndPadCLength
|
std::deque<SharedHandle<BtContext> > btContexts;
|
||||||
(e->getBtRegistry()->getAllBtContext())) {
|
e->getBtRegistry()->getAllBtContext(std::back_inserter(btContexts));
|
||||||
|
if(_mseHandshake->receiveReceiverHashAndPadCLength(btContexts)) {
|
||||||
_sequence = RECEIVER_RECEIVE_PAD_C;
|
_sequence = RECEIVER_RECEIVE_PAD_C;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -244,19 +244,9 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
||||||
_pieceStorage,
|
_pieceStorage,
|
||||||
_option.get()));
|
_option.get()));
|
||||||
|
|
||||||
btRegistry->registerBtContext(btContext->getInfoHashAsString(),
|
|
||||||
btContext);
|
|
||||||
btRegistry->registerPieceStorage(btContext->getInfoHashAsString(),
|
|
||||||
_pieceStorage);
|
|
||||||
btRegistry->registerBtProgressInfoFile(btContext->getInfoHashAsString(),
|
|
||||||
progressInfoFile);
|
|
||||||
|
|
||||||
|
|
||||||
BtRuntimeHandle btRuntime(new BtRuntime());
|
BtRuntimeHandle btRuntime(new BtRuntime());
|
||||||
btRuntime->setListenPort(_option->getAsInt(PREF_LISTEN_PORT));
|
btRuntime->setListenPort(_option->getAsInt(PREF_LISTEN_PORT));
|
||||||
btRuntime->setMaxPeers(_option->getAsInt(PREF_BT_MAX_PEERS));
|
btRuntime->setMaxPeers(_option->getAsInt(PREF_BT_MAX_PEERS));
|
||||||
btRegistry->registerBtRuntime(btContext->getInfoHashAsString(),
|
|
||||||
btRuntime);
|
|
||||||
_btRuntime = btRuntime;
|
_btRuntime = btRuntime;
|
||||||
progressInfoFile->setBtRuntime(btRuntime);
|
progressInfoFile->setBtRuntime(btRuntime);
|
||||||
|
|
||||||
|
@ -264,8 +254,6 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
||||||
(new DefaultPeerStorage(btContext, _option.get()));
|
(new DefaultPeerStorage(btContext, _option.get()));
|
||||||
peerStorage->setBtRuntime(btRuntime);
|
peerStorage->setBtRuntime(btRuntime);
|
||||||
peerStorage->setPieceStorage(_pieceStorage);
|
peerStorage->setPieceStorage(_pieceStorage);
|
||||||
btRegistry->registerPeerStorage(btContext->getInfoHashAsString(),
|
|
||||||
peerStorage);
|
|
||||||
_peerStorage = peerStorage;
|
_peerStorage = peerStorage;
|
||||||
progressInfoFile->setPeerStorage(peerStorage);
|
progressInfoFile->setPeerStorage(peerStorage);
|
||||||
|
|
||||||
|
@ -276,10 +264,16 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
||||||
btAnnounce->setPeerStorage(peerStorage);
|
btAnnounce->setPeerStorage(peerStorage);
|
||||||
btAnnounce->setUserDefinedInterval
|
btAnnounce->setUserDefinedInterval
|
||||||
(_option->getAsInt(PREF_BT_TRACKER_INTERVAL));
|
(_option->getAsInt(PREF_BT_TRACKER_INTERVAL));
|
||||||
btRegistry->registerBtAnnounce(btContext->getInfoHashAsString(),
|
|
||||||
btAnnounce);
|
|
||||||
btAnnounce->shuffleAnnounce();
|
btAnnounce->shuffleAnnounce();
|
||||||
|
|
||||||
|
btRegistry->put(btContext->getInfoHashAsString(),
|
||||||
|
BtObject(btContext,
|
||||||
|
_pieceStorage,
|
||||||
|
peerStorage,
|
||||||
|
btAnnounce,
|
||||||
|
btRuntime,
|
||||||
|
progressInfoFile));
|
||||||
|
|
||||||
// Remove the control file if download file doesn't exist
|
// Remove the control file if download file doesn't exist
|
||||||
if(progressInfoFile->exists() && !_pieceStorage->getDiskAdaptor()->fileExists()) {
|
if(progressInfoFile->exists() && !_pieceStorage->getDiskAdaptor()->fileExists()) {
|
||||||
progressInfoFile->removeFile();
|
progressInfoFile->removeFile();
|
||||||
|
@ -828,7 +822,7 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
|
||||||
if(!btContextInReg.isNull() &&
|
if(!btContextInReg.isNull() &&
|
||||||
btContextInReg->getOwnerRequestGroup()->getGID() ==
|
btContextInReg->getOwnerRequestGroup()->getGID() ==
|
||||||
btContext->getOwnerRequestGroup()->getGID()) {
|
btContext->getOwnerRequestGroup()->getGID()) {
|
||||||
btRegistry->unregister(btContext->getInfoHashAsString());
|
btRegistry->remove(btContext->getInfoHashAsString());
|
||||||
if(!DHTRegistry::_peerAnnounceStorage.isNull()) {
|
if(!DHTRegistry::_peerAnnounceStorage.isNull()) {
|
||||||
DHTRegistry::_peerAnnounceStorage->
|
DHTRegistry::_peerAnnounceStorage->
|
||||||
removeLocalPeerAnnounce(btContext->getInfoHash());
|
removeLocalPeerAnnounce(btContext->getInfoHash());
|
||||||
|
|
|
@ -292,7 +292,7 @@ static void gatherProgressBitTorrent
|
||||||
entryDict["infoHash"] = btctx->getInfoHashAsString();
|
entryDict["infoHash"] = btctx->getInfoHashAsString();
|
||||||
|
|
||||||
SharedHandle<PeerStorage> peerStorage =
|
SharedHandle<PeerStorage> peerStorage =
|
||||||
btreg->getPeerStorage(btctx->getInfoHashAsString());
|
btreg->get(btctx->getInfoHashAsString())._peerStorage;
|
||||||
assert(!peerStorage.isNull());
|
assert(!peerStorage.isNull());
|
||||||
|
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
|
@ -460,7 +460,7 @@ BDE GetPeersXmlRpcMethod::process
|
||||||
if(!btctx.isNull()) {
|
if(!btctx.isNull()) {
|
||||||
SharedHandle<BtRegistry> btreg = e->getBtRegistry();
|
SharedHandle<BtRegistry> btreg = e->getBtRegistry();
|
||||||
SharedHandle<PeerStorage> peerStorage =
|
SharedHandle<PeerStorage> peerStorage =
|
||||||
btreg->getPeerStorage(btctx->getInfoHashAsString());
|
btreg->get(btctx->getInfoHashAsString())._peerStorage;
|
||||||
assert(!peerStorage.isNull());
|
assert(!peerStorage.isNull());
|
||||||
BDE entry = BDE::dict();
|
BDE entry = BDE::dict();
|
||||||
gatherPeer(peers, peerStorage);
|
gatherPeer(peers, peerStorage);
|
||||||
|
|
|
@ -17,21 +17,17 @@ class BtRegistryTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(BtRegistryTest);
|
CPPUNIT_TEST_SUITE(BtRegistryTest);
|
||||||
CPPUNIT_TEST(testGetBtContext);
|
CPPUNIT_TEST(testGetBtContext);
|
||||||
CPPUNIT_TEST(testGetPeerStorage);
|
CPPUNIT_TEST(testGetAllBtContext);
|
||||||
CPPUNIT_TEST(testGetPieceStorage);
|
CPPUNIT_TEST(testRemove);
|
||||||
CPPUNIT_TEST(testGetBtRuntime);
|
CPPUNIT_TEST(testRemoveAll);
|
||||||
CPPUNIT_TEST(testGetBtAnnounce);
|
|
||||||
CPPUNIT_TEST(testGetBtProgressInfoFile);
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void testGetBtContext();
|
void testGetBtContext();
|
||||||
void testGetPeerStorage();
|
void testGetAllBtContext();
|
||||||
void testGetPieceStorage();
|
void testRemove();
|
||||||
void testGetBtRuntime();
|
void testRemoveAll();
|
||||||
void testGetBtAnnounce();
|
|
||||||
void testGetBtProgressInfoFile();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,64 +38,51 @@ void BtRegistryTest::testGetBtContext()
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
CPPUNIT_ASSERT(btRegistry.getBtContext("test").isNull());
|
CPPUNIT_ASSERT(btRegistry.getBtContext("test").isNull());
|
||||||
SharedHandle<BtContext> btContext(new MockBtContext());
|
SharedHandle<BtContext> btContext(new MockBtContext());
|
||||||
btRegistry.registerBtContext("test", btContext);
|
BtObject btObject;
|
||||||
|
btObject._btContext = btContext;
|
||||||
|
btRegistry.put("test", btObject);
|
||||||
CPPUNIT_ASSERT_EQUAL(btContext.get(),
|
CPPUNIT_ASSERT_EQUAL(btContext.get(),
|
||||||
btRegistry.getBtContext("test").get());
|
btRegistry.getBtContext("test").get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistryTest::testGetPeerStorage() {
|
static void addTwoBtContext(BtRegistry& btRegistry)
|
||||||
BtRegistry btRegistry;
|
{
|
||||||
CPPUNIT_ASSERT(!btRegistry.getPeerStorage("test").get());
|
SharedHandle<BtContext> btContext1(new MockBtContext());
|
||||||
|
SharedHandle<BtContext> btContext2(new MockBtContext());
|
||||||
SharedHandle<PeerStorage> peerStorage(new MockPeerStorage());
|
BtObject btObject1;
|
||||||
|
btObject1._btContext = btContext1;
|
||||||
btRegistry.registerPeerStorage("test", peerStorage);
|
BtObject btObject2;
|
||||||
CPPUNIT_ASSERT_EQUAL(peerStorage.get(),
|
btObject2._btContext = btContext2;
|
||||||
btRegistry.getPeerStorage("test").get());
|
btRegistry.put("ctx1", btObject1);
|
||||||
|
btRegistry.put("ctx2", btObject2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistryTest::testGetPieceStorage() {
|
void BtRegistryTest::testGetAllBtContext()
|
||||||
|
{
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
CPPUNIT_ASSERT(!btRegistry.getPieceStorage("test").get());
|
addTwoBtContext(btRegistry);
|
||||||
|
|
||||||
SharedHandle<PieceStorage> pieceStorage(new MockPieceStorage());
|
std::vector<SharedHandle<BtContext> > result;
|
||||||
|
btRegistry.getAllBtContext(std::back_inserter(result));
|
||||||
btRegistry.registerPieceStorage("test", pieceStorage);
|
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(pieceStorage.get(),
|
|
||||||
btRegistry.getPieceStorage("test").get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistryTest::testGetBtRuntime() {
|
void BtRegistryTest::testRemove()
|
||||||
|
{
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
CPPUNIT_ASSERT(!btRegistry.getBtRuntime("test").get());
|
addTwoBtContext(btRegistry);
|
||||||
|
CPPUNIT_ASSERT(btRegistry.remove("ctx1"));
|
||||||
SharedHandle<BtRuntime> runtime;
|
CPPUNIT_ASSERT(btRegistry.get("ctx1").isNull());
|
||||||
|
CPPUNIT_ASSERT(!btRegistry.get("ctx2").isNull());
|
||||||
btRegistry.registerBtRuntime("test", runtime);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(runtime.get(),
|
|
||||||
btRegistry.getBtRuntime("test").get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtRegistryTest::testGetBtAnnounce() {
|
void BtRegistryTest::testRemoveAll()
|
||||||
|
{
|
||||||
BtRegistry btRegistry;
|
BtRegistry btRegistry;
|
||||||
CPPUNIT_ASSERT(!btRegistry.getBtAnnounce("test").get());
|
addTwoBtContext(btRegistry);
|
||||||
|
btRegistry.removeAll();
|
||||||
SharedHandle<BtAnnounce> btAnnounce(new MockBtAnnounce());
|
CPPUNIT_ASSERT(btRegistry.get("ctx1").isNull());
|
||||||
|
CPPUNIT_ASSERT(btRegistry.get("ctx2").isNull());
|
||||||
btRegistry.registerBtAnnounce("test", btAnnounce);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(btAnnounce.get(),
|
|
||||||
btRegistry.getBtAnnounce("test").get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void BtRegistryTest::testGetBtProgressInfoFile() {
|
|
||||||
BtRegistry btRegistry;
|
|
||||||
CPPUNIT_ASSERT(!btRegistry.getBtProgressInfoFile("test").get());
|
|
||||||
|
|
||||||
SharedHandle<BtProgressInfoFile> btProgressInfoFile(new MockBtProgressInfoFile());
|
|
||||||
|
|
||||||
btRegistry.registerBtProgressInfoFile("test", btProgressInfoFile);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(btProgressInfoFile.get(),
|
|
||||||
btRegistry.getBtProgressInfoFile("test").get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue