2010-06-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Rewritten DHTRegistry
	* src/BtSetup.cc
	* src/DHTRegistry.cc
	* src/DHTRegistry.h
	* src/DHTSetup.cc
	* src/PeerInteractionCommand.cc
	* src/RequestGroup.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-06-13 02:53:11 +00:00
parent 1dcf842ff4
commit 7584ad1437
7 changed files with 75 additions and 67 deletions

View File

@ -1,3 +1,13 @@
2010-06-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten DHTRegistry
* src/BtSetup.cc
* src/DHTRegistry.cc
* src/DHTRegistry.h
* src/DHTSetup.cc
* src/PeerInteractionCommand.cc
* src/RequestGroup.cc
2010-06-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables of XmlRpcResponse

View File

@ -129,8 +129,8 @@ void BtSetup::setup(std::vector<Command*>& commands,
DHTSetup::initialized()) {
DHTGetPeersCommand* command =
new DHTGetPeersCommand(e->newCUID(), requestGroup, e);
command->setTaskQueue(DHTRegistry::_taskQueue);
command->setTaskFactory(DHTRegistry::_taskFactory);
command->setTaskQueue(DHTRegistry::getData().taskQueue);
command->setTaskFactory(DHTRegistry::getData().taskFactory);
command->setBtRuntime(btRuntime);
command->setPeerStorage(peerStorage);
commands.push_back(command);

View File

@ -46,35 +46,20 @@
namespace aria2 {
SharedHandle<DHTNode> DHTRegistry::_localNode;
SharedHandle<DHTRoutingTable> DHTRegistry::_routingTable;
DHTRegistry::Data DHTRegistry::_data;
SharedHandle<DHTTaskQueue> DHTRegistry::_taskQueue;
SharedHandle<DHTTaskFactory> DHTRegistry::_taskFactory;
SharedHandle<DHTPeerAnnounceStorage> DHTRegistry::_peerAnnounceStorage;
SharedHandle<DHTTokenTracker> DHTRegistry::_tokenTracker;
SharedHandle<DHTMessageDispatcher> DHTRegistry::_messageDispatcher;
SharedHandle<DHTMessageReceiver> DHTRegistry::_messageReceiver;
SharedHandle<DHTMessageFactory> DHTRegistry::_messageFactory;
void DHTRegistry::clear()
void DHTRegistry::clearData()
{
_localNode.reset();
_routingTable.reset();
_taskQueue.reset();
_taskFactory.reset();
_peerAnnounceStorage.reset();
_tokenTracker.reset();
_messageDispatcher.reset();
_messageReceiver.reset();
_messageFactory.reset();
_data.localNode.reset();
_data.routingTable.reset();
_data.taskQueue.reset();
_data.taskFactory.reset();
_data.peerAnnounceStorage.reset();
_data.tokenTracker.reset();
_data.messageDispatcher.reset();
_data.messageReceiver.reset();
_data.messageFactory.reset();
}
} // namespace aria2

View File

@ -51,28 +51,41 @@ class DHTMessageReceiver;
class DHTMessageFactory;
class DHTRegistry {
public:
static SharedHandle<DHTNode> _localNode;
static SharedHandle<DHTRoutingTable> _routingTable;
static SharedHandle<DHTTaskQueue> _taskQueue;
static SharedHandle<DHTTaskFactory> _taskFactory;
static SharedHandle<DHTPeerAnnounceStorage> _peerAnnounceStorage;
static SharedHandle<DHTTokenTracker> _tokenTracker;
static SharedHandle<DHTMessageDispatcher> _messageDispatcher;
static SharedHandle<DHTMessageReceiver> _messageReceiver;
static SharedHandle<DHTMessageFactory> _messageFactory;
static void clear();
private:
struct Data {
SharedHandle<DHTNode> localNode;
SharedHandle<DHTRoutingTable> routingTable;
SharedHandle<DHTTaskQueue> taskQueue;
SharedHandle<DHTTaskFactory> taskFactory;
SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage;
SharedHandle<DHTTokenTracker> tokenTracker;
SharedHandle<DHTMessageDispatcher> messageDispatcher;
SharedHandle<DHTMessageReceiver> messageReceiver;
SharedHandle<DHTMessageFactory> messageFactory;
};
static Data _data;
DHTRegistry();
public:
static const Data& getData()
{
return _data;
}
static Data& getMutableData()
{
return _data;
}
static void clearData();
};
} // namespace aria2

View File

@ -178,15 +178,15 @@ void DHTSetup::setup(std::vector<Command*>& commands, DownloadEngine* e)
factory->setLocalNode(localNode);
// assign them into DHTRegistry
DHTRegistry::_localNode = localNode;
DHTRegistry::_routingTable = routingTable;
DHTRegistry::_taskQueue = taskQueue;
DHTRegistry::_taskFactory = taskFactory;
DHTRegistry::_peerAnnounceStorage = peerAnnounceStorage;
DHTRegistry::_tokenTracker = tokenTracker;
DHTRegistry::_messageDispatcher = dispatcher;
DHTRegistry::_messageReceiver = receiver;
DHTRegistry::_messageFactory = factory;
DHTRegistry::getMutableData().localNode = localNode;
DHTRegistry::getMutableData().routingTable = routingTable;
DHTRegistry::getMutableData().taskQueue = taskQueue;
DHTRegistry::getMutableData().taskFactory = taskFactory;
DHTRegistry::getMutableData().peerAnnounceStorage = peerAnnounceStorage;
DHTRegistry::getMutableData().tokenTracker = tokenTracker;
DHTRegistry::getMutableData().messageDispatcher = dispatcher;
DHTRegistry::getMutableData().messageReceiver = receiver;
DHTRegistry::getMutableData().messageFactory = factory;
// add deserialized nodes to routing table
const std::vector<SharedHandle<DHTNode> >& desnodes =
@ -265,7 +265,7 @@ void DHTSetup::setup(std::vector<Command*>& commands, DownloadEngine* e)
commands.insert(commands.end(), tempCommands.begin(), tempCommands.end());
} catch(RecoverableException& e) {
_logger->error("Exception caught while initializing DHT functionality. DHT is disabled.", e);
DHTRegistry::clear();
DHTRegistry::clearData();
std::for_each(tempCommands.begin(), tempCommands.end(), Deleter());
}
}

View File

@ -134,10 +134,10 @@ PeerInteractionCommand::PeerInteractionCommand
factory->setPeerStorage(peerStorage);
factory->setExtensionMessageFactory(extensionMessageFactory);
factory->setPeer(getPeer());
factory->setLocalNode(DHTRegistry::_localNode);
factory->setRoutingTable(DHTRegistry::_routingTable);
factory->setTaskQueue(DHTRegistry::_taskQueue);
factory->setTaskFactory(DHTRegistry::_taskFactory);
factory->setLocalNode(DHTRegistry::getData().localNode);
factory->setRoutingTable(DHTRegistry::getData().routingTable);
factory->setTaskQueue(DHTRegistry::getData().taskQueue);
factory->setTaskFactory(DHTRegistry::getData().taskFactory);
if(metadataGetMode) {
factory->enableMetadataGetMode();
}
@ -195,7 +195,7 @@ PeerInteractionCommand::PeerInteractionCommand
}
if(DHTSetup::initialized()) {
btInteractive->setDHTEnabled(true);
btInteractive->setLocalNode(DHTRegistry::_localNode);
btInteractive->setLocalNode(DHTRegistry::getData().localNode);
factory->setDHTEnabled(true);
}
}

View File

@ -353,10 +353,10 @@ void RequestGroup::createInitialCommand
}
DHTEntryPointNameResolveCommand* command =
new DHTEntryPointNameResolveCommand(e->newCUID(), e, entryPoints);
command->setTaskQueue(DHTRegistry::_taskQueue);
command->setTaskFactory(DHTRegistry::_taskFactory);
command->setRoutingTable(DHTRegistry::_routingTable);
command->setLocalNode(DHTRegistry::_localNode);
command->setTaskQueue(DHTRegistry::getData().taskQueue);
command->setTaskFactory(DHTRegistry::getData().taskFactory);
command->setRoutingTable(DHTRegistry::getData().routingTable);
command->setLocalNode(DHTRegistry::getData().localNode);
e->addCommand(command);
}
}