diff --git a/ChangeLog b/ChangeLog index f7a484bf..93c5982b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-06-13 Tatsuhiro Tsujikawa + + 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 Renamed member variables of XmlRpcResponse diff --git a/src/BtSetup.cc b/src/BtSetup.cc index b0db3795..3da46902 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -129,8 +129,8 @@ void BtSetup::setup(std::vector& 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); diff --git a/src/DHTRegistry.cc b/src/DHTRegistry.cc index 5168911c..782c12d9 100644 --- a/src/DHTRegistry.cc +++ b/src/DHTRegistry.cc @@ -46,35 +46,20 @@ namespace aria2 { -SharedHandle DHTRegistry::_localNode; -SharedHandle DHTRegistry::_routingTable; +DHTRegistry::Data DHTRegistry::_data; -SharedHandle DHTRegistry::_taskQueue; - -SharedHandle DHTRegistry::_taskFactory; - -SharedHandle DHTRegistry::_peerAnnounceStorage; - -SharedHandle DHTRegistry::_tokenTracker; - -SharedHandle DHTRegistry::_messageDispatcher; - -SharedHandle DHTRegistry::_messageReceiver; - -SharedHandle 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 diff --git a/src/DHTRegistry.h b/src/DHTRegistry.h index 885f1d53..44dae9e2 100644 --- a/src/DHTRegistry.h +++ b/src/DHTRegistry.h @@ -51,28 +51,41 @@ class DHTMessageReceiver; class DHTMessageFactory; class DHTRegistry { -public: - static SharedHandle _localNode; - - static SharedHandle _routingTable; - - static SharedHandle _taskQueue; - - static SharedHandle _taskFactory; - - static SharedHandle _peerAnnounceStorage; - - static SharedHandle _tokenTracker; - - static SharedHandle _messageDispatcher; - - static SharedHandle _messageReceiver; - - static SharedHandle _messageFactory; - - static void clear(); private: + struct Data { + SharedHandle localNode; + + SharedHandle routingTable; + + SharedHandle taskQueue; + + SharedHandle taskFactory; + + SharedHandle peerAnnounceStorage; + + SharedHandle tokenTracker; + + SharedHandle messageDispatcher; + + SharedHandle messageReceiver; + + SharedHandle messageFactory; + }; + + static Data _data; DHTRegistry(); +public: + static const Data& getData() + { + return _data; + } + + static Data& getMutableData() + { + return _data; + } + + static void clearData(); }; } // namespace aria2 diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc index b3f5d769..045f28e1 100644 --- a/src/DHTSetup.cc +++ b/src/DHTSetup.cc @@ -178,15 +178,15 @@ void DHTSetup::setup(std::vector& 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 >& desnodes = @@ -265,7 +265,7 @@ void DHTSetup::setup(std::vector& 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()); } } diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index dc654c0a..468c5c98 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -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); } } diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 0c0ce2f2..9d45b645 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -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); } }