/* */ #include "DHTTaskFactoryImpl.h" #include "DHTNode.h" #include "DHTRoutingTable.h" #include "DHTMessageDispatcher.h" #include "DHTMessageFactory.h" #include "DHTTaskQueue.h" #include "DHTPingTask.h" #include "DHTNodeLookupTask.h" #include "DHTBucketRefreshTask.h" #include "DHTPeerLookupTask.h" #include "DHTReplaceNodeTask.h" #include "Peer.h" #include "DHTNodeLookupEntry.h" #include "PeerStorage.h" #include "DHTMessageCallback.h" namespace aria2 { DHTTaskFactoryImpl::DHTTaskFactoryImpl() : routingTable_(nullptr), dispatcher_(nullptr), factory_(nullptr), taskQueue_(nullptr), timeout_(DHT_MESSAGE_TIMEOUT) { } DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {} std::shared_ptr DHTTaskFactoryImpl::createPingTask(const std::shared_ptr& remoteNode, int numRetry) { auto task = std::make_shared(remoteNode, numRetry); task->setTimeout(timeout_); setCommonProperty(task); return task; } std::shared_ptr DHTTaskFactoryImpl::createNodeLookupTask(const unsigned char* targetID) { auto task = std::make_shared(targetID); setCommonProperty(task); return task; } std::shared_ptr DHTTaskFactoryImpl::createBucketRefreshTask() { auto task = std::make_shared(); setCommonProperty(task); return task; } std::shared_ptr DHTTaskFactoryImpl::createPeerLookupTask( const std::shared_ptr& ctx, uint16_t tcpPort, const std::shared_ptr& peerStorage) { auto task = std::make_shared(ctx, tcpPort); // TODO this may be not freed by RequestGroup::releaseRuntimeResource() task->setPeerStorage(peerStorage); setCommonProperty(task); return task; } std::shared_ptr DHTTaskFactoryImpl::createPeerAnnounceTask(const unsigned char* infoHash) { // TODO return nullptr; } std::shared_ptr DHTTaskFactoryImpl::createReplaceNodeTask( const std::shared_ptr& bucket, const std::shared_ptr& newNode) { auto task = std::make_shared(bucket, newNode); task->setTimeout(timeout_); setCommonProperty(task); return task; } void DHTTaskFactoryImpl::setCommonProperty( const std::shared_ptr& task) { task->setRoutingTable(routingTable_); task->setMessageDispatcher(dispatcher_); task->setMessageFactory(factory_); task->setTaskQueue(taskQueue_); task->setLocalNode(localNode_); } void DHTTaskFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } void DHTTaskFactoryImpl::setMessageDispatcher(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } void DHTTaskFactoryImpl::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } void DHTTaskFactoryImpl::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } void DHTTaskFactoryImpl::setLocalNode(const std::shared_ptr& localNode) { localNode_ = localNode; } } // namespace aria2