diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 1edf22ea..595c2987 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -139,8 +139,8 @@ void BtSetup::setup(std::vector>& commands, if(DHTRegistry::isInitialized()) { auto command = make_unique (e->newCUID(), requestGroup, e); - command->setTaskQueue(DHTRegistry::getData().taskQueue); - command->setTaskFactory(DHTRegistry::getData().taskFactory); + command->setTaskQueue(DHTRegistry::getData().taskQueue.get()); + command->setTaskFactory(DHTRegistry::getData().taskFactory.get()); command->setBtRuntime(btRuntime); command->setPeerStorage(peerStorage); commands.push_back(std::move(command)); @@ -148,8 +148,8 @@ void BtSetup::setup(std::vector>& commands, if(DHTRegistry::isInitialized6()) { auto command = make_unique (e->newCUID(), requestGroup, e); - command->setTaskQueue(DHTRegistry::getData6().taskQueue); - command->setTaskFactory(DHTRegistry::getData6().taskFactory); + command->setTaskQueue(DHTRegistry::getData6().taskQueue.get()); + command->setTaskFactory(DHTRegistry::getData6().taskFactory.get()); command->setBtRuntime(btRuntime); command->setPeerStorage(peerStorage); commands.push_back(std::move(command)); diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index 05f04e4f..3e30e341 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -58,8 +58,9 @@ namespace aria2 { DHTAutoSaveCommand::DHTAutoSaveCommand (cuid_t cuid, DownloadEngine* e, int family, time_t interval) - : TimeBasedCommand(cuid, e, interval), - family_(family) + : TimeBasedCommand{cuid, e, interval}, + family_{family}, + routingTable_{nullptr} {} DHTAutoSaveCommand::~DHTAutoSaveCommand() {} @@ -122,8 +123,7 @@ void DHTAutoSaveCommand::setLocalNode(const std::shared_ptr& localNode) localNode_ = localNode; } -void DHTAutoSaveCommand::setRoutingTable -(const std::shared_ptr& routingTable) +void DHTAutoSaveCommand::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } diff --git a/src/DHTAutoSaveCommand.h b/src/DHTAutoSaveCommand.h index dd70040e..b1db5354 100644 --- a/src/DHTAutoSaveCommand.h +++ b/src/DHTAutoSaveCommand.h @@ -51,7 +51,7 @@ private: std::shared_ptr localNode_; - std::shared_ptr routingTable_; + DHTRoutingTable* routingTable_; void save(); public: @@ -66,7 +66,7 @@ public: void setLocalNode(const std::shared_ptr& localNode); - void setRoutingTable(const std::shared_ptr& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); }; } // namespace aria2 diff --git a/src/DHTBucketRefreshCommand.cc b/src/DHTBucketRefreshCommand.cc index e3001f78..eb9b2fac 100644 --- a/src/DHTBucketRefreshCommand.cc +++ b/src/DHTBucketRefreshCommand.cc @@ -43,8 +43,12 @@ namespace aria2 { DHTBucketRefreshCommand::DHTBucketRefreshCommand -(cuid_t cuid, DownloadEngine* e, time_t interval): - TimeBasedCommand(cuid, e, interval) {} +(cuid_t cuid, DownloadEngine* e, time_t interval) + : TimeBasedCommand{cuid, e, interval}, + routingTable_{nullptr}, + taskQueue_{nullptr}, + taskFactory_{nullptr} +{} DHTBucketRefreshCommand::~DHTBucketRefreshCommand() {} @@ -61,20 +65,17 @@ void DHTBucketRefreshCommand::process() taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask()); } -void DHTBucketRefreshCommand::setRoutingTable -(const std::shared_ptr& routingTable) +void DHTBucketRefreshCommand::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void DHTBucketRefreshCommand::setTaskQueue -(const std::shared_ptr& taskQueue) +void DHTBucketRefreshCommand::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void DHTBucketRefreshCommand::setTaskFactory -(const std::shared_ptr& taskFactory) +void DHTBucketRefreshCommand::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } diff --git a/src/DHTBucketRefreshCommand.h b/src/DHTBucketRefreshCommand.h index d29aff7b..ac1f1274 100644 --- a/src/DHTBucketRefreshCommand.h +++ b/src/DHTBucketRefreshCommand.h @@ -47,11 +47,11 @@ class DHTTaskFactory; class DHTBucketRefreshCommand:public TimeBasedCommand { private: - std::shared_ptr routingTable_; + DHTRoutingTable* routingTable_; - std::shared_ptr taskQueue_; + DHTTaskQueue* taskQueue_; - std::shared_ptr taskFactory_; + DHTTaskFactory* taskFactory_; public: DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e, time_t interval); @@ -61,11 +61,11 @@ public: virtual void process(); - void setRoutingTable(const std::shared_ptr& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const std::shared_ptr& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); }; } // namespace aria2 diff --git a/src/DHTEntryPointNameResolveCommand.cc b/src/DHTEntryPointNameResolveCommand.cc index 4b020602..201fe5af 100644 --- a/src/DHTEntryPointNameResolveCommand.cc +++ b/src/DHTEntryPointNameResolveCommand.cc @@ -58,15 +58,18 @@ namespace aria2 { DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand (cuid_t cuid, DownloadEngine* e, - const std::vector >& entryPoints): - Command(cuid), - e_(e), + const std::vector >& entryPoints) + : Command{cuid}, + e_{e}, #ifdef ENABLE_ASYNC_DNS - asyncNameResolverMan_(new AsyncNameResolverMan()), + asyncNameResolverMan_{make_unique()}, #endif // ENABLE_ASYNC_DNS - entryPoints_(entryPoints.begin(), entryPoints.end()), - numSuccess_(0), - bootstrapEnabled_(false) + taskQueue_{nullptr}, + taskFactory_{nullptr}, + routingTable_{nullptr}, + entryPoints_(std::begin(entryPoints), std::end(entryPoints)), + numSuccess_{0}, + bootstrapEnabled_{false} { #ifdef ENABLE_ASYNC_DNS configureAsyncNameResolverMan(asyncNameResolverMan_.get(), e_->getOption()); @@ -197,20 +200,19 @@ void DHTEntryPointNameResolveCommand::setBootstrapEnabled(bool f) bootstrapEnabled_ = f; } -void DHTEntryPointNameResolveCommand::setTaskQueue -(const std::shared_ptr& taskQueue) +void DHTEntryPointNameResolveCommand::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } void DHTEntryPointNameResolveCommand::setTaskFactory -(const std::shared_ptr& taskFactory) +(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } void DHTEntryPointNameResolveCommand::setRoutingTable -(const std::shared_ptr& routingTable) +(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } diff --git a/src/DHTEntryPointNameResolveCommand.h b/src/DHTEntryPointNameResolveCommand.h index fde848fc..e9a09350 100644 --- a/src/DHTEntryPointNameResolveCommand.h +++ b/src/DHTEntryPointNameResolveCommand.h @@ -62,15 +62,15 @@ private: std::shared_ptr asyncNameResolverMan_; #endif // ENABLE_ASYNC_DNS - std::shared_ptr taskQueue_; + DHTTaskQueue* taskQueue_; - std::shared_ptr taskFactory_; + DHTTaskFactory* taskFactory_; - std::shared_ptr routingTable_; + DHTRoutingTable* routingTable_; std::shared_ptr localNode_; - std::deque > entryPoints_; + std::deque> entryPoints_; int numSuccess_; @@ -94,11 +94,11 @@ public: void setBootstrapEnabled(bool f); - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const std::shared_ptr& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); - void setRoutingTable(const std::shared_ptr& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); void setLocalNode(const std::shared_ptr& localNode); }; diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc index 52686be9..345c5182 100644 --- a/src/DHTGetPeersCommand.cc +++ b/src/DHTGetPeersCommand.cc @@ -71,11 +71,13 @@ DHTGetPeersCommand::DHTGetPeersCommand (cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e) - : Command(cuid), - requestGroup_(requestGroup), - e_(e), - numRetry_(0), - lastGetPeerTime_(0) + : Command{cuid}, + requestGroup_{requestGroup}, + e_{e}, + taskQueue_{nullptr}, + taskFactory_{nullptr}, + numRetry_{0}, + lastGetPeerTime_{0} { requestGroup_->increaseNumCommand(); } @@ -130,12 +132,12 @@ bool DHTGetPeersCommand::execute() return false; } -void DHTGetPeersCommand::setTaskQueue(const std::shared_ptr& taskQueue) +void DHTGetPeersCommand::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void DHTGetPeersCommand::setTaskFactory(const std::shared_ptr& taskFactory) +void DHTGetPeersCommand::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } diff --git a/src/DHTGetPeersCommand.h b/src/DHTGetPeersCommand.h index 03ee64dc..f6e81517 100644 --- a/src/DHTGetPeersCommand.h +++ b/src/DHTGetPeersCommand.h @@ -62,9 +62,9 @@ private: DownloadEngine* e_; - std::shared_ptr taskQueue_; + DHTTaskQueue* taskQueue_; - std::shared_ptr taskFactory_; + DHTTaskFactory* taskFactory_; std::shared_ptr task_; @@ -79,9 +79,9 @@ public: virtual bool execute(); - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const std::shared_ptr& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); void setBtRuntime(const std::shared_ptr& btRuntime); diff --git a/src/DHTInteractionCommand.cc b/src/DHTInteractionCommand.cc index 31f84d74..fe193cd4 100644 --- a/src/DHTInteractionCommand.cc +++ b/src/DHTInteractionCommand.cc @@ -57,8 +57,11 @@ namespace aria2 { // TODO This name of this command is misleading, because now it also // handles UDP trackers as well as DHT. DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e) - : Command(cuid), - e_(e) + : Command{cuid}, + e_{e}, + dispatcher_{nullptr}, + receiver_{nullptr}, + taskQueue_{nullptr} {} DHTInteractionCommand::~DHTInteractionCommand() @@ -142,17 +145,18 @@ bool DHTInteractionCommand::execute() return false; } -void DHTInteractionCommand::setMessageDispatcher(const std::shared_ptr& dispatcher) +void DHTInteractionCommand::setMessageDispatcher +(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DHTInteractionCommand::setMessageReceiver(const std::shared_ptr& receiver) +void DHTInteractionCommand::setMessageReceiver(DHTMessageReceiver* receiver) { receiver_ = receiver; } -void DHTInteractionCommand::setTaskQueue(const std::shared_ptr& taskQueue) +void DHTInteractionCommand::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } diff --git a/src/DHTInteractionCommand.h b/src/DHTInteractionCommand.h index f9de06c9..38ba98a6 100644 --- a/src/DHTInteractionCommand.h +++ b/src/DHTInteractionCommand.h @@ -52,9 +52,9 @@ class UDPTrackerClient; class DHTInteractionCommand:public Command { private: DownloadEngine* e_; - std::shared_ptr dispatcher_; - std::shared_ptr receiver_; - std::shared_ptr taskQueue_; + DHTMessageDispatcher* dispatcher_; + DHTMessageReceiver* receiver_; + DHTTaskQueue* taskQueue_; std::shared_ptr readCheckSocket_; std::shared_ptr connection_; std::shared_ptr udpTrackerClient_; @@ -69,11 +69,11 @@ public: void disableReadCheckSocket(const std::shared_ptr& socket); - void setMessageDispatcher(const std::shared_ptr& dispatcher); + void setMessageDispatcher(DHTMessageDispatcher* dispatcher); - void setMessageReceiver(const std::shared_ptr& receiver); + void setMessageReceiver(DHTMessageReceiver* receiver); - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); void setConnection(const std::shared_ptr& connection); diff --git a/src/DHTMessageReceiver.cc b/src/DHTMessageReceiver.cc index c8062db7..b6c2cf49 100644 --- a/src/DHTMessageReceiver.cc +++ b/src/DHTMessageReceiver.cc @@ -58,7 +58,9 @@ namespace aria2 { DHTMessageReceiver::DHTMessageReceiver (const std::shared_ptr& tracker) - : tracker_{tracker} + : tracker_{tracker}, + factory_{nullptr}, + routingTable_{nullptr} {} std::unique_ptr DHTMessageReceiver::receiveMessage @@ -146,12 +148,12 @@ void DHTMessageReceiver::setConnection(const std::shared_ptr& con connection_ = connection; } -void DHTMessageReceiver::setMessageFactory(const std::shared_ptr& factory) +void DHTMessageReceiver::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } -void DHTMessageReceiver::setRoutingTable(const std::shared_ptr& routingTable) +void DHTMessageReceiver::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } diff --git a/src/DHTMessageReceiver.h b/src/DHTMessageReceiver.h index 64e21d92..04f5885b 100644 --- a/src/DHTMessageReceiver.h +++ b/src/DHTMessageReceiver.h @@ -55,9 +55,9 @@ private: std::shared_ptr connection_; - std::shared_ptr factory_; + DHTMessageFactory* factory_; - std::shared_ptr routingTable_; + DHTRoutingTable* routingTable_; std::unique_ptr handleUnknownMessage(const unsigned char* data, size_t length, @@ -85,9 +85,9 @@ public: void setConnection(const std::shared_ptr& connection); - void setMessageFactory(const std::shared_ptr& factory); + void setMessageFactory(DHTMessageFactory* factory); - void setRoutingTable(const std::shared_ptr& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); }; } // namespace aria2 diff --git a/src/DHTMessageTracker.cc b/src/DHTMessageTracker.cc index f41a2b5e..ae25ae76 100644 --- a/src/DHTMessageTracker.cc +++ b/src/DHTMessageTracker.cc @@ -52,7 +52,8 @@ namespace aria2 { DHTMessageTracker::DHTMessageTracker() - : factory_{nullptr} + : routingTable_{nullptr}, + factory_{nullptr} {} void DHTMessageTracker::addMessage @@ -173,8 +174,7 @@ size_t DHTMessageTracker::countEntry() const return entries_.size(); } -void DHTMessageTracker::setRoutingTable -(const std::shared_ptr& routingTable) +void DHTMessageTracker::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } diff --git a/src/DHTMessageTracker.h b/src/DHTMessageTracker.h index 0c375de0..0cb51fac 100644 --- a/src/DHTMessageTracker.h +++ b/src/DHTMessageTracker.h @@ -57,7 +57,7 @@ class DHTMessageTracker { private: std::deque> entries_; - std::shared_ptr routingTable_; + DHTRoutingTable* routingTable_; DHTMessageFactory* factory_; public: @@ -83,7 +83,7 @@ public: size_t countEntry() const; - void setRoutingTable(const std::shared_ptr& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); void setMessageFactory(DHTMessageFactory* factory); }; diff --git a/src/DHTPeerAnnounceCommand.cc b/src/DHTPeerAnnounceCommand.cc index 97945c01..43ce6701 100644 --- a/src/DHTPeerAnnounceCommand.cc +++ b/src/DHTPeerAnnounceCommand.cc @@ -45,7 +45,8 @@ namespace aria2 { DHTPeerAnnounceCommand::DHTPeerAnnounceCommand (cuid_t cuid, DownloadEngine* e, time_t interval) - : TimeBasedCommand(cuid, e, interval) + : TimeBasedCommand{cuid, e, interval}, + peerAnnounceStorage_{nullptr} {} DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {} @@ -68,7 +69,7 @@ void DHTPeerAnnounceCommand::process() } void DHTPeerAnnounceCommand::setPeerAnnounceStorage -(const std::shared_ptr& storage) +(DHTPeerAnnounceStorage* storage) { peerAnnounceStorage_ = storage; } diff --git a/src/DHTPeerAnnounceCommand.h b/src/DHTPeerAnnounceCommand.h index a704b8f8..9436c932 100644 --- a/src/DHTPeerAnnounceCommand.h +++ b/src/DHTPeerAnnounceCommand.h @@ -45,7 +45,7 @@ class DHTPeerAnnounceStorage; class DHTPeerAnnounceCommand:public TimeBasedCommand { private: - std::shared_ptr peerAnnounceStorage_; + DHTPeerAnnounceStorage* peerAnnounceStorage_; public: DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e, time_t interval); @@ -55,7 +55,7 @@ public: virtual void process(); - void setPeerAnnounceStorage(const std::shared_ptr& storage); + void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage); }; } // namespace aria2 diff --git a/src/DHTPeerAnnounceStorage.cc b/src/DHTPeerAnnounceStorage.cc index 11f38a80..cdd0c754 100644 --- a/src/DHTPeerAnnounceStorage.cc +++ b/src/DHTPeerAnnounceStorage.cc @@ -52,9 +52,10 @@ namespace aria2 { -DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() {} - -DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {} +DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() + : taskQueue_{nullptr}, + taskFactory_{nullptr} +{} bool DHTPeerAnnounceStorage::InfoHashLess::operator() (const std::shared_ptr& lhs, @@ -153,12 +154,12 @@ void DHTPeerAnnounceStorage::announcePeer() } } -void DHTPeerAnnounceStorage::setTaskQueue(const std::shared_ptr& taskQueue) +void DHTPeerAnnounceStorage::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void DHTPeerAnnounceStorage::setTaskFactory(const std::shared_ptr& taskFactory) +void DHTPeerAnnounceStorage::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } diff --git a/src/DHTPeerAnnounceStorage.h b/src/DHTPeerAnnounceStorage.h index a0f2dd22..64ba4fb9 100644 --- a/src/DHTPeerAnnounceStorage.h +++ b/src/DHTPeerAnnounceStorage.h @@ -62,14 +62,12 @@ private: std::shared_ptr getPeerAnnounceEntry(const unsigned char* infoHash); - std::shared_ptr taskQueue_; + DHTTaskQueue* taskQueue_; - std::shared_ptr taskFactory_; + DHTTaskFactory* taskFactory_; public: DHTPeerAnnounceStorage(); - ~DHTPeerAnnounceStorage(); - void addPeerAnnounce(const unsigned char* infoHash, const std::string& ipaddr, uint16_t port); @@ -87,9 +85,9 @@ public: // are excluded from announce. void announcePeer(); - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const std::shared_ptr& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); }; } // namespace aria2 diff --git a/src/DHTRegistry.h b/src/DHTRegistry.h index b8886844..60a5c94d 100644 --- a/src/DHTRegistry.h +++ b/src/DHTRegistry.h @@ -58,21 +58,21 @@ private: std::shared_ptr localNode; - std::shared_ptr routingTable; + std::unique_ptr routingTable; - std::shared_ptr taskQueue; + std::unique_ptr taskQueue; - std::shared_ptr taskFactory; + std::unique_ptr taskFactory; - std::shared_ptr peerAnnounceStorage; + std::unique_ptr peerAnnounceStorage; - std::shared_ptr tokenTracker; + std::unique_ptr tokenTracker; - std::shared_ptr messageDispatcher; + std::unique_ptr messageDispatcher; - std::shared_ptr messageReceiver; + std::unique_ptr messageReceiver; - std::shared_ptr messageFactory; + std::unique_ptr messageFactory; Data():initialized(false) {} }; diff --git a/src/DHTRoutingTable.cc b/src/DHTRoutingTable.cc index 24c91195..ebb8b2a3 100644 --- a/src/DHTRoutingTable.cc +++ b/src/DHTRoutingTable.cc @@ -53,7 +53,9 @@ DHTRoutingTable::DHTRoutingTable(const std::shared_ptr& localNode) : localNode_(localNode), root_(new DHTBucketTreeNode (std::shared_ptr(new DHTBucket(localNode_)))), - numBucket_(1) + numBucket_(1), + taskQueue_{nullptr}, + taskFactory_{nullptr} {} DHTRoutingTable::~DHTRoutingTable() @@ -164,12 +166,12 @@ void DHTRoutingTable::getBuckets dht::enumerateBucket(buckets, root_); } -void DHTRoutingTable::setTaskQueue(const std::shared_ptr& taskQueue) +void DHTRoutingTable::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void DHTRoutingTable::setTaskFactory(const std::shared_ptr& taskFactory) +void DHTRoutingTable::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } diff --git a/src/DHTRoutingTable.h b/src/DHTRoutingTable.h index a0708ac7..2ec822c7 100644 --- a/src/DHTRoutingTable.h +++ b/src/DHTRoutingTable.h @@ -57,9 +57,9 @@ private: int numBucket_; - std::shared_ptr taskQueue_; + DHTTaskQueue* taskQueue_; - std::shared_ptr taskFactory_; + DHTTaskFactory* taskFactory_; bool addNode(const std::shared_ptr& node, bool good); public: @@ -92,9 +92,9 @@ public: void getBuckets(std::vector >& buckets) const; - void setTaskQueue(const std::shared_ptr& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const std::shared_ptr& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); }; } // namespace aria2 diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc index 568c7542..c65baf97 100644 --- a/src/DHTSetup.cc +++ b/src/DHTSetup.cc @@ -111,7 +111,7 @@ std::vector> DHTSetup::setup } uint16_t port; - std::shared_ptr connection(new DHTConnectionImpl(family)); + auto connection = std::make_shared(family); { port = e->getBtRegistry()->getUdpPort(); const std::string& addr = @@ -137,27 +137,28 @@ std::vector> DHTSetup::setup } A2_LOG_DEBUG(fmt("Initialized local node ID=%s", util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str())); - std::shared_ptr routingTable(new DHTRoutingTable(localNode)); - - auto factory = std::make_shared(family); auto tracker = std::make_shared(); - auto dispatcher = std::make_shared(tracker); - auto receiver = std::make_shared(tracker); - auto taskQueue = std::make_shared(); - auto taskFactory = std::make_shared(); - auto peerAnnounceStorage = std::make_shared(); - auto tokenTracker = std::make_shared(); + auto routingTable = make_unique(localNode); + auto factory = make_unique(family); + auto dispatcher = make_unique(tracker); + auto receiver = make_unique(tracker); + auto taskQueue = make_unique(); + auto taskFactory = make_unique(); + auto peerAnnounceStorage = make_unique(); + auto tokenTracker = make_unique(); + // For now, UDPTrackerClient was enabled along with DHT + auto udpTrackerClient = std::make_shared(); const time_t messageTimeout = e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT); // wiring up - tracker->setRoutingTable(routingTable); + tracker->setRoutingTable(routingTable.get()); tracker->setMessageFactory(factory.get()); dispatcher->setTimeout(messageTimeout); receiver->setConnection(connection); - receiver->setMessageFactory(factory); - receiver->setRoutingTable(routingTable); + receiver->setMessageFactory(factory.get()); + receiver->setRoutingTable(routingTable.get()); taskFactory->setLocalNode(localNode); taskFactory->setRoutingTable(routingTable.get()); @@ -166,11 +167,11 @@ std::vector> DHTSetup::setup taskFactory->setTaskQueue(taskQueue.get()); taskFactory->setTimeout(messageTimeout); - routingTable->setTaskQueue(taskQueue); - routingTable->setTaskFactory(taskFactory); + routingTable->setTaskQueue(taskQueue.get()); + routingTable->setTaskFactory(taskFactory.get()); - peerAnnounceStorage->setTaskQueue(taskQueue); - peerAnnounceStorage->setTaskFactory(taskFactory); + peerAnnounceStorage->setTaskQueue(taskQueue.get()); + peerAnnounceStorage->setTaskFactory(taskFactory.get()); factory->setRoutingTable(routingTable.get()); factory->setConnection(connection.get()); @@ -179,43 +180,6 @@ std::vector> DHTSetup::setup factory->setTokenTracker(tokenTracker.get()); factory->setLocalNode(localNode); - // For now, UDPTrackerClient was enabled along with DHT - auto udpTrackerClient = std::make_shared(); - // assign them into DHTRegistry - if(family == AF_INET) { - 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; - e->getBtRegistry()->setUDPTrackerClient(udpTrackerClient); - } else { - DHTRegistry::getMutableData6().localNode = localNode; - DHTRegistry::getMutableData6().routingTable = routingTable; - DHTRegistry::getMutableData6().taskQueue = taskQueue; - DHTRegistry::getMutableData6().taskFactory = taskFactory; - DHTRegistry::getMutableData6().peerAnnounceStorage = peerAnnounceStorage; - DHTRegistry::getMutableData6().tokenTracker = tokenTracker; - DHTRegistry::getMutableData6().messageDispatcher = dispatcher; - DHTRegistry::getMutableData6().messageReceiver = receiver; - DHTRegistry::getMutableData6().messageFactory = factory; - } - // add deserialized nodes to routing table - auto& desnodes = deserializer.getNodes(); - for(auto& node : desnodes) { - routingTable->addNode(node); - } - if(!desnodes.empty()) { - auto task = std::static_pointer_cast - (taskFactory->createBucketRefreshTask()); - task->setForceRefresh(true); - taskQueue->addPeriodicTask1(task); - } - const Pref* prefEntryPointHost = family == AF_INET?PREF_DHT_ENTRY_POINT_HOST:PREF_DHT_ENTRY_POINT_HOST6; if(!e->getOption()->get(prefEntryPointHost).empty()) { @@ -231,9 +195,9 @@ std::vector> DHTSetup::setup auto command = make_unique (e->newCUID(), e, entryPoints); command->setBootstrapEnabled(true); - command->setTaskQueue(taskQueue); - command->setTaskFactory(taskFactory); - command->setRoutingTable(routingTable); + command->setTaskQueue(taskQueue.get()); + command->setTaskFactory(taskFactory.get()); + command->setRoutingTable(routingTable.get()); command->setLocalNode(localNode); tempCommands.push_back(std::move(command)); } @@ -242,9 +206,9 @@ std::vector> DHTSetup::setup } { auto command = make_unique(e->newCUID(), e); - command->setMessageDispatcher(dispatcher); - command->setMessageReceiver(receiver); - command->setTaskQueue(taskQueue); + command->setMessageDispatcher(dispatcher.get()); + command->setMessageReceiver(receiver.get()); + command->setTaskQueue(taskQueue.get()); command->setReadCheckSocket(connection->getSocket()); command->setConnection(connection); command->setUDPTrackerClient(udpTrackerClient); @@ -253,33 +217,66 @@ std::vector> DHTSetup::setup { auto command = make_unique (e->newCUID(), e, DHT_TOKEN_UPDATE_INTERVAL); - command->setTokenTracker(tokenTracker); + command->setTokenTracker(tokenTracker.get()); tempCommands.push_back(std::move(command)); } { auto command = make_unique (e->newCUID(), e, DHT_BUCKET_REFRESH_CHECK_INTERVAL); - command->setTaskQueue(taskQueue); - command->setRoutingTable(routingTable); - command->setTaskFactory(taskFactory); + command->setTaskQueue(taskQueue.get()); + command->setRoutingTable(routingTable.get()); + command->setTaskFactory(taskFactory.get()); tempCommands.push_back(std::move(command)); } { auto command = make_unique (e->newCUID(), e, DHT_PEER_ANNOUNCE_CHECK_INTERVAL); - command->setPeerAnnounceStorage(peerAnnounceStorage); + command->setPeerAnnounceStorage(peerAnnounceStorage.get()); tempCommands.push_back(std::move(command)); } { auto command = make_unique (e->newCUID(), e, family, 30*60); command->setLocalNode(localNode); - command->setRoutingTable(routingTable); + command->setRoutingTable(routingTable.get()); tempCommands.push_back(std::move(command)); } + // add deserialized nodes to routing table + auto& desnodes = deserializer.getNodes(); + for(auto& node : desnodes) { + routingTable->addNode(node); + } + if(!desnodes.empty()) { + auto task = std::static_pointer_cast + (taskFactory->createBucketRefreshTask()); + task->setForceRefresh(true); + taskQueue->addPeriodicTask1(task); + } + // assign them into DHTRegistry if(family == AF_INET) { + DHTRegistry::getMutableData().localNode = localNode; + DHTRegistry::getMutableData().routingTable = std::move(routingTable); + DHTRegistry::getMutableData().taskQueue = std::move(taskQueue); + DHTRegistry::getMutableData().taskFactory = std::move(taskFactory); + DHTRegistry::getMutableData().peerAnnounceStorage = + std::move(peerAnnounceStorage); + DHTRegistry::getMutableData().tokenTracker = std::move(tokenTracker); + DHTRegistry::getMutableData().messageDispatcher = std::move(dispatcher); + DHTRegistry::getMutableData().messageReceiver = std::move(receiver); + DHTRegistry::getMutableData().messageFactory = std::move(factory); + e->getBtRegistry()->setUDPTrackerClient(udpTrackerClient); DHTRegistry::setInitialized(true); } else { + DHTRegistry::getMutableData6().localNode = localNode; + DHTRegistry::getMutableData6().routingTable = std::move(routingTable); + DHTRegistry::getMutableData6().taskQueue = std::move(taskQueue); + DHTRegistry::getMutableData6().taskFactory = std::move(taskFactory); + DHTRegistry::getMutableData6().peerAnnounceStorage = + std::move(peerAnnounceStorage); + DHTRegistry::getMutableData6().tokenTracker = std::move(tokenTracker); + DHTRegistry::getMutableData6().messageDispatcher = std::move(dispatcher); + DHTRegistry::getMutableData6().messageReceiver = std::move(receiver); + DHTRegistry::getMutableData6().messageFactory = std::move(factory); DHTRegistry::setInitialized6(true); } if(e->getBtRegistry()->getUdpPort() == 0) { diff --git a/src/DHTTokenUpdateCommand.cc b/src/DHTTokenUpdateCommand.cc index d7ccb6d4..d2074223 100644 --- a/src/DHTTokenUpdateCommand.cc +++ b/src/DHTTokenUpdateCommand.cc @@ -45,7 +45,8 @@ namespace aria2 { DHTTokenUpdateCommand::DHTTokenUpdateCommand (cuid_t cuid, DownloadEngine* e, time_t interval) - : TimeBasedCommand(cuid, e, interval) + : TimeBasedCommand{cuid, e, interval}, + tokenTracker_{nullptr} {} DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {} @@ -67,7 +68,7 @@ void DHTTokenUpdateCommand::process() } } -void DHTTokenUpdateCommand::setTokenTracker(const std::shared_ptr& tokenTracker) +void DHTTokenUpdateCommand::setTokenTracker(DHTTokenTracker* tokenTracker) { tokenTracker_ = tokenTracker; } diff --git a/src/DHTTokenUpdateCommand.h b/src/DHTTokenUpdateCommand.h index cec5ca30..be81a5e4 100644 --- a/src/DHTTokenUpdateCommand.h +++ b/src/DHTTokenUpdateCommand.h @@ -45,7 +45,7 @@ class DHTTokenTracker; class DHTTokenUpdateCommand:public TimeBasedCommand { private: - std::shared_ptr tokenTracker_; + DHTTokenTracker* tokenTracker_; public: DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e, time_t interval); @@ -55,7 +55,7 @@ public: virtual void process(); - void setTokenTracker(const std::shared_ptr& tokenTracker); + void setTokenTracker(DHTTokenTracker* tokenTracker); }; } // namespace aria2 diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index d35e4967..c79b690e 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -447,9 +447,9 @@ void RequestGroup::createInitialCommand if(!nodes.empty() && DHTRegistry::isInitialized()) { auto command = make_unique (e->newCUID(), e, nodes); - command->setTaskQueue(DHTRegistry::getData().taskQueue); - command->setTaskFactory(DHTRegistry::getData().taskFactory); - command->setRoutingTable(DHTRegistry::getData().routingTable); + command->setTaskQueue(DHTRegistry::getData().taskQueue.get()); + command->setTaskFactory(DHTRegistry::getData().taskFactory.get()); + command->setRoutingTable(DHTRegistry::getData().routingTable.get()); command->setLocalNode(DHTRegistry::getData().localNode); e->addCommand(std::move(command)); } diff --git a/test/DHTMessageTrackerTest.cc b/test/DHTMessageTrackerTest.cc index 3c939f9d..1bf44cff 100644 --- a/test/DHTMessageTrackerTest.cc +++ b/test/DHTMessageTrackerTest.cc @@ -35,8 +35,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTMessageTrackerTest); void DHTMessageTrackerTest::testMessageArrived() { auto localNode = std::make_shared(); - auto routingTable = std::make_shared(localNode); - auto factory = std::make_shared(); + auto routingTable = make_unique(localNode); + auto factory = make_unique(); factory->setLocalNode(localNode); auto r1 = std::make_shared(); @@ -54,7 +54,7 @@ void DHTMessageTrackerTest::testMessageArrived() auto m3 = make_unique(localNode, r3); DHTMessageTracker tracker; - tracker.setRoutingTable(routingTable); + tracker.setRoutingTable(routingTable.get()); tracker.setMessageFactory(factory.get()); tracker.addMessage(m1.get(), DHT_MESSAGE_TIMEOUT); tracker.addMessage(m2.get(), DHT_MESSAGE_TIMEOUT); diff --git a/test/DHTRoutingTableTest.cc b/test/DHTRoutingTableTest.cc index b114d251..61bc66ca 100644 --- a/test/DHTRoutingTableTest.cc +++ b/test/DHTRoutingTableTest.cc @@ -35,16 +35,15 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTRoutingTableTest); void DHTRoutingTableTest::testAddNode() { - std::shared_ptr localNode(new DHTNode()); + auto localNode = std::make_shared(); DHTRoutingTable table(localNode); - std::shared_ptr taskFactory(new MockDHTTaskFactory()); - table.setTaskFactory(taskFactory); - std::shared_ptr taskQueue(new MockDHTTaskQueue()); - table.setTaskQueue(taskQueue); + auto taskFactory = make_unique(); + table.setTaskFactory(taskFactory.get()); + auto taskQueue = make_unique(); + table.setTaskQueue(taskQueue.get()); uint32_t count = 0; for(int i = 0; i < 100; ++i) { - std::shared_ptr node(new DHTNode()); - if(table.addNode(node)) { + if(table.addNode(std::make_shared())) { ++count; } } @@ -53,14 +52,14 @@ void DHTRoutingTableTest::testAddNode() void DHTRoutingTableTest::testAddNode_localNode() { - std::shared_ptr localNode(new DHTNode()); + auto localNode = std::make_shared(); DHTRoutingTable table(localNode); - std::shared_ptr taskFactory(new MockDHTTaskFactory()); - table.setTaskFactory(taskFactory); - std::shared_ptr taskQueue(new MockDHTTaskQueue()); - table.setTaskQueue(taskQueue); + auto taskFactory = make_unique(); + table.setTaskFactory(taskFactory.get()); + auto taskQueue = make_unique(); + table.setTaskQueue(taskQueue.get()); - std::shared_ptr newNode(new DHTNode(localNode->getID())); + auto newNode = std::make_shared(localNode->getID()); CPPUNIT_ASSERT(!table.addNode(newNode)); } @@ -77,7 +76,7 @@ void DHTRoutingTableTest::testGetClosestKNodes() { unsigned char id[DHT_ID_LENGTH]; createID(id, 0x81, 0); - std::shared_ptr localNode(new DHTNode(id)); + auto localNode = std::make_shared(id); DHTRoutingTable table(localNode); @@ -86,26 +85,27 @@ void DHTRoutingTableTest::testGetClosestKNodes() std::shared_ptr nodes3[8]; for(size_t i = 0; i < DHTBucket::K; ++i) { createID(id, 0xf0, i); - nodes1[i].reset(new DHTNode(id)); + nodes1[i] = std::make_shared(id); CPPUNIT_ASSERT(table.addNode(nodes1[i])); } for(size_t i = 0; i < DHTBucket::K; ++i) { createID(id, 0x80, i); - nodes2[i].reset(new DHTNode(id)); + nodes2[i] = std::make_shared(id); CPPUNIT_ASSERT(table.addNode(nodes2[i])); } for(size_t i = 0; i < DHTBucket::K; ++i) { createID(id, 0x70, i); - nodes3[i].reset(new DHTNode(id)); + nodes3[i] = std::make_shared(id); CPPUNIT_ASSERT(table.addNode(nodes3[i])); } { createID(id, 0x80, 0x10); - std::vector > nodes; + std::vector> nodes; table.getClosestKNodes(nodes, id); CPPUNIT_ASSERT_EQUAL((size_t)8, nodes.size()); for(size_t i = 0; i < nodes.size(); ++i) { - CPPUNIT_ASSERT(memcmp(nodes2[0]->getID(), nodes[0]->getID(), DHT_ID_LENGTH) == 0); + CPPUNIT_ASSERT(memcmp(nodes2[0]->getID(), nodes[0]->getID(), + DHT_ID_LENGTH) == 0); } } }