mirror of https://github.com/aria2/aria2
Use std::unique_ptr in DHTRegistry
parent
1a5d75e819
commit
f022402dc9
|
@ -139,8 +139,8 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||||
if(DHTRegistry::isInitialized()) {
|
if(DHTRegistry::isInitialized()) {
|
||||||
auto command = make_unique<DHTGetPeersCommand>
|
auto command = make_unique<DHTGetPeersCommand>
|
||||||
(e->newCUID(), requestGroup, e);
|
(e->newCUID(), requestGroup, e);
|
||||||
command->setTaskQueue(DHTRegistry::getData().taskQueue);
|
command->setTaskQueue(DHTRegistry::getData().taskQueue.get());
|
||||||
command->setTaskFactory(DHTRegistry::getData().taskFactory);
|
command->setTaskFactory(DHTRegistry::getData().taskFactory.get());
|
||||||
command->setBtRuntime(btRuntime);
|
command->setBtRuntime(btRuntime);
|
||||||
command->setPeerStorage(peerStorage);
|
command->setPeerStorage(peerStorage);
|
||||||
commands.push_back(std::move(command));
|
commands.push_back(std::move(command));
|
||||||
|
@ -148,8 +148,8 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||||
if(DHTRegistry::isInitialized6()) {
|
if(DHTRegistry::isInitialized6()) {
|
||||||
auto command = make_unique<DHTGetPeersCommand>
|
auto command = make_unique<DHTGetPeersCommand>
|
||||||
(e->newCUID(), requestGroup, e);
|
(e->newCUID(), requestGroup, e);
|
||||||
command->setTaskQueue(DHTRegistry::getData6().taskQueue);
|
command->setTaskQueue(DHTRegistry::getData6().taskQueue.get());
|
||||||
command->setTaskFactory(DHTRegistry::getData6().taskFactory);
|
command->setTaskFactory(DHTRegistry::getData6().taskFactory.get());
|
||||||
command->setBtRuntime(btRuntime);
|
command->setBtRuntime(btRuntime);
|
||||||
command->setPeerStorage(peerStorage);
|
command->setPeerStorage(peerStorage);
|
||||||
commands.push_back(std::move(command));
|
commands.push_back(std::move(command));
|
||||||
|
|
|
@ -58,8 +58,9 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTAutoSaveCommand::DHTAutoSaveCommand
|
DHTAutoSaveCommand::DHTAutoSaveCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, int family, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, int family, time_t interval)
|
||||||
: TimeBasedCommand(cuid, e, interval),
|
: TimeBasedCommand{cuid, e, interval},
|
||||||
family_(family)
|
family_{family},
|
||||||
|
routingTable_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DHTAutoSaveCommand::~DHTAutoSaveCommand() {}
|
DHTAutoSaveCommand::~DHTAutoSaveCommand() {}
|
||||||
|
@ -122,8 +123,7 @@ void DHTAutoSaveCommand::setLocalNode(const std::shared_ptr<DHTNode>& localNode)
|
||||||
localNode_ = localNode;
|
localNode_ = localNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAutoSaveCommand::setRoutingTable
|
void DHTAutoSaveCommand::setRoutingTable(DHTRoutingTable* routingTable)
|
||||||
(const std::shared_ptr<DHTRoutingTable>& routingTable)
|
|
||||||
{
|
{
|
||||||
routingTable_ = routingTable;
|
routingTable_ = routingTable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<DHTNode> localNode_;
|
std::shared_ptr<DHTNode> localNode_;
|
||||||
|
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable_;
|
DHTRoutingTable* routingTable_;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
public:
|
public:
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
|
|
||||||
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
||||||
|
|
||||||
void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
|
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -43,8 +43,12 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTBucketRefreshCommand::DHTBucketRefreshCommand
|
DHTBucketRefreshCommand::DHTBucketRefreshCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval):
|
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
||||||
TimeBasedCommand(cuid, e, interval) {}
|
: TimeBasedCommand{cuid, e, interval},
|
||||||
|
routingTable_{nullptr},
|
||||||
|
taskQueue_{nullptr},
|
||||||
|
taskFactory_{nullptr}
|
||||||
|
{}
|
||||||
|
|
||||||
DHTBucketRefreshCommand::~DHTBucketRefreshCommand() {}
|
DHTBucketRefreshCommand::~DHTBucketRefreshCommand() {}
|
||||||
|
|
||||||
|
@ -61,20 +65,17 @@ void DHTBucketRefreshCommand::process()
|
||||||
taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask());
|
taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTBucketRefreshCommand::setRoutingTable
|
void DHTBucketRefreshCommand::setRoutingTable(DHTRoutingTable* routingTable)
|
||||||
(const std::shared_ptr<DHTRoutingTable>& routingTable)
|
|
||||||
{
|
{
|
||||||
routingTable_ = routingTable;
|
routingTable_ = routingTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTBucketRefreshCommand::setTaskQueue
|
void DHTBucketRefreshCommand::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTBucketRefreshCommand::setTaskFactory
|
void DHTBucketRefreshCommand::setTaskFactory(DHTTaskFactory* taskFactory)
|
||||||
(const std::shared_ptr<DHTTaskFactory>& taskFactory)
|
|
||||||
{
|
{
|
||||||
taskFactory_ = taskFactory;
|
taskFactory_ = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,11 +47,11 @@ class DHTTaskFactory;
|
||||||
|
|
||||||
class DHTBucketRefreshCommand:public TimeBasedCommand {
|
class DHTBucketRefreshCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable_;
|
DHTRoutingTable* routingTable_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
public:
|
public:
|
||||||
DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
||||||
|
|
||||||
|
@ -61,11 +61,11 @@ public:
|
||||||
|
|
||||||
virtual void process();
|
virtual void process();
|
||||||
|
|
||||||
void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
|
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -58,15 +58,18 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand
|
DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand
|
||||||
(cuid_t cuid, DownloadEngine* e,
|
(cuid_t cuid, DownloadEngine* e,
|
||||||
const std::vector<std::pair<std::string, uint16_t> >& entryPoints):
|
const std::vector<std::pair<std::string, uint16_t> >& entryPoints)
|
||||||
Command(cuid),
|
: Command{cuid},
|
||||||
e_(e),
|
e_{e},
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
asyncNameResolverMan_(new AsyncNameResolverMan()),
|
asyncNameResolverMan_{make_unique<AsyncNameResolverMan>()},
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
entryPoints_(entryPoints.begin(), entryPoints.end()),
|
taskQueue_{nullptr},
|
||||||
numSuccess_(0),
|
taskFactory_{nullptr},
|
||||||
bootstrapEnabled_(false)
|
routingTable_{nullptr},
|
||||||
|
entryPoints_(std::begin(entryPoints), std::end(entryPoints)),
|
||||||
|
numSuccess_{0},
|
||||||
|
bootstrapEnabled_{false}
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
configureAsyncNameResolverMan(asyncNameResolverMan_.get(), e_->getOption());
|
configureAsyncNameResolverMan(asyncNameResolverMan_.get(), e_->getOption());
|
||||||
|
@ -197,20 +200,19 @@ void DHTEntryPointNameResolveCommand::setBootstrapEnabled(bool f)
|
||||||
bootstrapEnabled_ = f;
|
bootstrapEnabled_ = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTEntryPointNameResolveCommand::setTaskQueue
|
void DHTEntryPointNameResolveCommand::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTEntryPointNameResolveCommand::setTaskFactory
|
void DHTEntryPointNameResolveCommand::setTaskFactory
|
||||||
(const std::shared_ptr<DHTTaskFactory>& taskFactory)
|
(DHTTaskFactory* taskFactory)
|
||||||
{
|
{
|
||||||
taskFactory_ = taskFactory;
|
taskFactory_ = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTEntryPointNameResolveCommand::setRoutingTable
|
void DHTEntryPointNameResolveCommand::setRoutingTable
|
||||||
(const std::shared_ptr<DHTRoutingTable>& routingTable)
|
(DHTRoutingTable* routingTable)
|
||||||
{
|
{
|
||||||
routingTable_ = routingTable;
|
routingTable_ = routingTable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,15 +62,15 @@ private:
|
||||||
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
|
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
|
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable_;
|
DHTRoutingTable* routingTable_;
|
||||||
|
|
||||||
std::shared_ptr<DHTNode> localNode_;
|
std::shared_ptr<DHTNode> localNode_;
|
||||||
|
|
||||||
std::deque<std::pair<std::string, uint16_t> > entryPoints_;
|
std::deque<std::pair<std::string, uint16_t>> entryPoints_;
|
||||||
|
|
||||||
int numSuccess_;
|
int numSuccess_;
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ public:
|
||||||
|
|
||||||
void setBootstrapEnabled(bool f);
|
void setBootstrapEnabled(bool f);
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||||
|
|
||||||
void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
|
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||||
|
|
||||||
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,11 +71,13 @@ DHTGetPeersCommand::DHTGetPeersCommand
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e)
|
DownloadEngine* e)
|
||||||
: Command(cuid),
|
: Command{cuid},
|
||||||
requestGroup_(requestGroup),
|
requestGroup_{requestGroup},
|
||||||
e_(e),
|
e_{e},
|
||||||
numRetry_(0),
|
taskQueue_{nullptr},
|
||||||
lastGetPeerTime_(0)
|
taskFactory_{nullptr},
|
||||||
|
numRetry_{0},
|
||||||
|
lastGetPeerTime_{0}
|
||||||
{
|
{
|
||||||
requestGroup_->increaseNumCommand();
|
requestGroup_->increaseNumCommand();
|
||||||
}
|
}
|
||||||
|
@ -130,12 +132,12 @@ bool DHTGetPeersCommand::execute()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTGetPeersCommand::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
void DHTGetPeersCommand::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTGetPeersCommand::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
|
void DHTGetPeersCommand::setTaskFactory(DHTTaskFactory* taskFactory)
|
||||||
{
|
{
|
||||||
taskFactory_ = taskFactory;
|
taskFactory_ = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,9 @@ private:
|
||||||
|
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTask> task_;
|
std::shared_ptr<DHTTask> task_;
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ public:
|
||||||
|
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||||
|
|
||||||
void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
|
void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,11 @@ namespace aria2 {
|
||||||
// TODO This name of this command is misleading, because now it also
|
// TODO This name of this command is misleading, because now it also
|
||||||
// handles UDP trackers as well as DHT.
|
// handles UDP trackers as well as DHT.
|
||||||
DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e)
|
DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e)
|
||||||
: Command(cuid),
|
: Command{cuid},
|
||||||
e_(e)
|
e_{e},
|
||||||
|
dispatcher_{nullptr},
|
||||||
|
receiver_{nullptr},
|
||||||
|
taskQueue_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DHTInteractionCommand::~DHTInteractionCommand()
|
DHTInteractionCommand::~DHTInteractionCommand()
|
||||||
|
@ -142,17 +145,18 @@ bool DHTInteractionCommand::execute()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTInteractionCommand::setMessageDispatcher(const std::shared_ptr<DHTMessageDispatcher>& dispatcher)
|
void DHTInteractionCommand::setMessageDispatcher
|
||||||
|
(DHTMessageDispatcher* dispatcher)
|
||||||
{
|
{
|
||||||
dispatcher_ = dispatcher;
|
dispatcher_ = dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTInteractionCommand::setMessageReceiver(const std::shared_ptr<DHTMessageReceiver>& receiver)
|
void DHTInteractionCommand::setMessageReceiver(DHTMessageReceiver* receiver)
|
||||||
{
|
{
|
||||||
receiver_ = receiver;
|
receiver_ = receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTInteractionCommand::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
void DHTInteractionCommand::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,9 @@ class UDPTrackerClient;
|
||||||
class DHTInteractionCommand:public Command {
|
class DHTInteractionCommand:public Command {
|
||||||
private:
|
private:
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
std::shared_ptr<DHTMessageDispatcher> dispatcher_;
|
DHTMessageDispatcher* dispatcher_;
|
||||||
std::shared_ptr<DHTMessageReceiver> receiver_;
|
DHTMessageReceiver* receiver_;
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
std::shared_ptr<SocketCore> readCheckSocket_;
|
std::shared_ptr<SocketCore> readCheckSocket_;
|
||||||
std::shared_ptr<DHTConnection> connection_;
|
std::shared_ptr<DHTConnection> connection_;
|
||||||
std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
|
std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
|
||||||
|
@ -69,11 +69,11 @@ public:
|
||||||
|
|
||||||
void disableReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
void disableReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
||||||
|
|
||||||
void setMessageDispatcher(const std::shared_ptr<DHTMessageDispatcher>& dispatcher);
|
void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
|
||||||
|
|
||||||
void setMessageReceiver(const std::shared_ptr<DHTMessageReceiver>& receiver);
|
void setMessageReceiver(DHTMessageReceiver* receiver);
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setConnection(const std::shared_ptr<DHTConnection>& connection);
|
void setConnection(const std::shared_ptr<DHTConnection>& connection);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,9 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTMessageReceiver::DHTMessageReceiver
|
DHTMessageReceiver::DHTMessageReceiver
|
||||||
(const std::shared_ptr<DHTMessageTracker>& tracker)
|
(const std::shared_ptr<DHTMessageTracker>& tracker)
|
||||||
: tracker_{tracker}
|
: tracker_{tracker},
|
||||||
|
factory_{nullptr},
|
||||||
|
routingTable_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::unique_ptr<DHTMessage> DHTMessageReceiver::receiveMessage
|
std::unique_ptr<DHTMessage> DHTMessageReceiver::receiveMessage
|
||||||
|
@ -146,12 +148,12 @@ void DHTMessageReceiver::setConnection(const std::shared_ptr<DHTConnection>& con
|
||||||
connection_ = connection;
|
connection_ = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageReceiver::setMessageFactory(const std::shared_ptr<DHTMessageFactory>& factory)
|
void DHTMessageReceiver::setMessageFactory(DHTMessageFactory* factory)
|
||||||
{
|
{
|
||||||
factory_ = factory;
|
factory_ = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageReceiver::setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable)
|
void DHTMessageReceiver::setRoutingTable(DHTRoutingTable* routingTable)
|
||||||
{
|
{
|
||||||
routingTable_ = routingTable;
|
routingTable_ = routingTable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,9 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<DHTConnection> connection_;
|
std::shared_ptr<DHTConnection> connection_;
|
||||||
|
|
||||||
std::shared_ptr<DHTMessageFactory> factory_;
|
DHTMessageFactory* factory_;
|
||||||
|
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable_;
|
DHTRoutingTable* routingTable_;
|
||||||
|
|
||||||
std::unique_ptr<DHTUnknownMessage>
|
std::unique_ptr<DHTUnknownMessage>
|
||||||
handleUnknownMessage(const unsigned char* data, size_t length,
|
handleUnknownMessage(const unsigned char* data, size_t length,
|
||||||
|
@ -85,9 +85,9 @@ public:
|
||||||
|
|
||||||
void setConnection(const std::shared_ptr<DHTConnection>& connection);
|
void setConnection(const std::shared_ptr<DHTConnection>& connection);
|
||||||
|
|
||||||
void setMessageFactory(const std::shared_ptr<DHTMessageFactory>& factory);
|
void setMessageFactory(DHTMessageFactory* factory);
|
||||||
|
|
||||||
void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
|
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -52,7 +52,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTMessageTracker::DHTMessageTracker()
|
DHTMessageTracker::DHTMessageTracker()
|
||||||
: factory_{nullptr}
|
: routingTable_{nullptr},
|
||||||
|
factory_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void DHTMessageTracker::addMessage
|
void DHTMessageTracker::addMessage
|
||||||
|
@ -173,8 +174,7 @@ size_t DHTMessageTracker::countEntry() const
|
||||||
return entries_.size();
|
return entries_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTMessageTracker::setRoutingTable
|
void DHTMessageTracker::setRoutingTable(DHTRoutingTable* routingTable)
|
||||||
(const std::shared_ptr<DHTRoutingTable>& routingTable)
|
|
||||||
{
|
{
|
||||||
routingTable_ = routingTable;
|
routingTable_ = routingTable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class DHTMessageTracker {
|
||||||
private:
|
private:
|
||||||
std::deque<std::unique_ptr<DHTMessageTrackerEntry>> entries_;
|
std::deque<std::unique_ptr<DHTMessageTrackerEntry>> entries_;
|
||||||
|
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable_;
|
DHTRoutingTable* routingTable_;
|
||||||
|
|
||||||
DHTMessageFactory* factory_;
|
DHTMessageFactory* factory_;
|
||||||
public:
|
public:
|
||||||
|
@ -83,7 +83,7 @@ public:
|
||||||
|
|
||||||
size_t countEntry() const;
|
size_t countEntry() const;
|
||||||
|
|
||||||
void setRoutingTable(const std::shared_ptr<DHTRoutingTable>& routingTable);
|
void setRoutingTable(DHTRoutingTable* routingTable);
|
||||||
|
|
||||||
void setMessageFactory(DHTMessageFactory* factory);
|
void setMessageFactory(DHTMessageFactory* factory);
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,8 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
|
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
||||||
: TimeBasedCommand(cuid, e, interval)
|
: TimeBasedCommand{cuid, e, interval},
|
||||||
|
peerAnnounceStorage_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}
|
DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}
|
||||||
|
@ -68,7 +69,7 @@ void DHTPeerAnnounceCommand::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPeerAnnounceCommand::setPeerAnnounceStorage
|
void DHTPeerAnnounceCommand::setPeerAnnounceStorage
|
||||||
(const std::shared_ptr<DHTPeerAnnounceStorage>& storage)
|
(DHTPeerAnnounceStorage* storage)
|
||||||
{
|
{
|
||||||
peerAnnounceStorage_ = storage;
|
peerAnnounceStorage_ = storage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class DHTPeerAnnounceStorage;
|
||||||
|
|
||||||
class DHTPeerAnnounceCommand:public TimeBasedCommand {
|
class DHTPeerAnnounceCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage_;
|
DHTPeerAnnounceStorage* peerAnnounceStorage_;
|
||||||
public:
|
public:
|
||||||
DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
virtual void process();
|
virtual void process();
|
||||||
|
|
||||||
void setPeerAnnounceStorage(const std::shared_ptr<DHTPeerAnnounceStorage>& storage);
|
void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -52,9 +52,10 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() {}
|
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage()
|
||||||
|
: taskQueue_{nullptr},
|
||||||
DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {}
|
taskFactory_{nullptr}
|
||||||
|
{}
|
||||||
|
|
||||||
bool DHTPeerAnnounceStorage::InfoHashLess::operator()
|
bool DHTPeerAnnounceStorage::InfoHashLess::operator()
|
||||||
(const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
|
(const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
|
||||||
|
@ -153,12 +154,12 @@ void DHTPeerAnnounceStorage::announcePeer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPeerAnnounceStorage::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
void DHTPeerAnnounceStorage::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPeerAnnounceStorage::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
|
void DHTPeerAnnounceStorage::setTaskFactory(DHTTaskFactory* taskFactory)
|
||||||
{
|
{
|
||||||
taskFactory_ = taskFactory;
|
taskFactory_ = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,14 +62,12 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<DHTPeerAnnounceEntry> getPeerAnnounceEntry(const unsigned char* infoHash);
|
std::shared_ptr<DHTPeerAnnounceEntry> getPeerAnnounceEntry(const unsigned char* infoHash);
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
public:
|
public:
|
||||||
DHTPeerAnnounceStorage();
|
DHTPeerAnnounceStorage();
|
||||||
|
|
||||||
~DHTPeerAnnounceStorage();
|
|
||||||
|
|
||||||
void addPeerAnnounce(const unsigned char* infoHash,
|
void addPeerAnnounce(const unsigned char* infoHash,
|
||||||
const std::string& ipaddr, uint16_t port);
|
const std::string& ipaddr, uint16_t port);
|
||||||
|
|
||||||
|
@ -87,9 +85,9 @@ public:
|
||||||
// are excluded from announce.
|
// are excluded from announce.
|
||||||
void announcePeer();
|
void announcePeer();
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -58,21 +58,21 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<DHTNode> localNode;
|
std::shared_ptr<DHTNode> localNode;
|
||||||
|
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable;
|
std::unique_ptr<DHTRoutingTable> routingTable;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue;
|
std::unique_ptr<DHTTaskQueue> taskQueue;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory;
|
std::unique_ptr<DHTTaskFactory> taskFactory;
|
||||||
|
|
||||||
std::shared_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage;
|
std::unique_ptr<DHTPeerAnnounceStorage> peerAnnounceStorage;
|
||||||
|
|
||||||
std::shared_ptr<DHTTokenTracker> tokenTracker;
|
std::unique_ptr<DHTTokenTracker> tokenTracker;
|
||||||
|
|
||||||
std::shared_ptr<DHTMessageDispatcher> messageDispatcher;
|
std::unique_ptr<DHTMessageDispatcher> messageDispatcher;
|
||||||
|
|
||||||
std::shared_ptr<DHTMessageReceiver> messageReceiver;
|
std::unique_ptr<DHTMessageReceiver> messageReceiver;
|
||||||
|
|
||||||
std::shared_ptr<DHTMessageFactory> messageFactory;
|
std::unique_ptr<DHTMessageFactory> messageFactory;
|
||||||
|
|
||||||
Data():initialized(false) {}
|
Data():initialized(false) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,7 +53,9 @@ DHTRoutingTable::DHTRoutingTable(const std::shared_ptr<DHTNode>& localNode)
|
||||||
: localNode_(localNode),
|
: localNode_(localNode),
|
||||||
root_(new DHTBucketTreeNode
|
root_(new DHTBucketTreeNode
|
||||||
(std::shared_ptr<DHTBucket>(new DHTBucket(localNode_)))),
|
(std::shared_ptr<DHTBucket>(new DHTBucket(localNode_)))),
|
||||||
numBucket_(1)
|
numBucket_(1),
|
||||||
|
taskQueue_{nullptr},
|
||||||
|
taskFactory_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DHTRoutingTable::~DHTRoutingTable()
|
DHTRoutingTable::~DHTRoutingTable()
|
||||||
|
@ -164,12 +166,12 @@ void DHTRoutingTable::getBuckets
|
||||||
dht::enumerateBucket(buckets, root_);
|
dht::enumerateBucket(buckets, root_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTRoutingTable::setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue)
|
void DHTRoutingTable::setTaskQueue(DHTTaskQueue* taskQueue)
|
||||||
{
|
{
|
||||||
taskQueue_ = taskQueue;
|
taskQueue_ = taskQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTRoutingTable::setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory)
|
void DHTRoutingTable::setTaskFactory(DHTTaskFactory* taskFactory)
|
||||||
{
|
{
|
||||||
taskFactory_ = taskFactory;
|
taskFactory_ = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,9 @@ private:
|
||||||
|
|
||||||
int numBucket_;
|
int numBucket_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskQueue> taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
std::shared_ptr<DHTTaskFactory> taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
|
|
||||||
bool addNode(const std::shared_ptr<DHTNode>& node, bool good);
|
bool addNode(const std::shared_ptr<DHTNode>& node, bool good);
|
||||||
public:
|
public:
|
||||||
|
@ -92,9 +92,9 @@ public:
|
||||||
|
|
||||||
void getBuckets(std::vector<std::shared_ptr<DHTBucket> >& buckets) const;
|
void getBuckets(std::vector<std::shared_ptr<DHTBucket> >& buckets) const;
|
||||||
|
|
||||||
void setTaskQueue(const std::shared_ptr<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(DHTTaskQueue* taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const std::shared_ptr<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(DHTTaskFactory* taskFactory);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
129
src/DHTSetup.cc
129
src/DHTSetup.cc
|
@ -111,7 +111,7 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
std::shared_ptr<DHTConnectionImpl> connection(new DHTConnectionImpl(family));
|
auto connection = std::make_shared<DHTConnectionImpl>(family);
|
||||||
{
|
{
|
||||||
port = e->getBtRegistry()->getUdpPort();
|
port = e->getBtRegistry()->getUdpPort();
|
||||||
const std::string& addr =
|
const std::string& addr =
|
||||||
|
@ -137,27 +137,28 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
}
|
}
|
||||||
A2_LOG_DEBUG(fmt("Initialized local node ID=%s",
|
A2_LOG_DEBUG(fmt("Initialized local node ID=%s",
|
||||||
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str()));
|
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str()));
|
||||||
std::shared_ptr<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
|
|
||||||
|
|
||||||
auto factory = std::make_shared<DHTMessageFactoryImpl>(family);
|
|
||||||
auto tracker = std::make_shared<DHTMessageTracker>();
|
auto tracker = std::make_shared<DHTMessageTracker>();
|
||||||
auto dispatcher = std::make_shared<DHTMessageDispatcherImpl>(tracker);
|
auto routingTable = make_unique<DHTRoutingTable>(localNode);
|
||||||
auto receiver = std::make_shared<DHTMessageReceiver>(tracker);
|
auto factory = make_unique<DHTMessageFactoryImpl>(family);
|
||||||
auto taskQueue = std::make_shared<DHTTaskQueueImpl>();
|
auto dispatcher = make_unique<DHTMessageDispatcherImpl>(tracker);
|
||||||
auto taskFactory = std::make_shared<DHTTaskFactoryImpl>();
|
auto receiver = make_unique<DHTMessageReceiver>(tracker);
|
||||||
auto peerAnnounceStorage = std::make_shared<DHTPeerAnnounceStorage>();
|
auto taskQueue = make_unique<DHTTaskQueueImpl>();
|
||||||
auto tokenTracker = std::make_shared<DHTTokenTracker>();
|
auto taskFactory = make_unique<DHTTaskFactoryImpl>();
|
||||||
|
auto peerAnnounceStorage = make_unique<DHTPeerAnnounceStorage>();
|
||||||
|
auto tokenTracker = make_unique<DHTTokenTracker>();
|
||||||
|
// For now, UDPTrackerClient was enabled along with DHT
|
||||||
|
auto udpTrackerClient = std::make_shared<UDPTrackerClient>();
|
||||||
const time_t messageTimeout =
|
const time_t messageTimeout =
|
||||||
e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT);
|
e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT);
|
||||||
// wiring up
|
// wiring up
|
||||||
tracker->setRoutingTable(routingTable);
|
tracker->setRoutingTable(routingTable.get());
|
||||||
tracker->setMessageFactory(factory.get());
|
tracker->setMessageFactory(factory.get());
|
||||||
|
|
||||||
dispatcher->setTimeout(messageTimeout);
|
dispatcher->setTimeout(messageTimeout);
|
||||||
|
|
||||||
receiver->setConnection(connection);
|
receiver->setConnection(connection);
|
||||||
receiver->setMessageFactory(factory);
|
receiver->setMessageFactory(factory.get());
|
||||||
receiver->setRoutingTable(routingTable);
|
receiver->setRoutingTable(routingTable.get());
|
||||||
|
|
||||||
taskFactory->setLocalNode(localNode);
|
taskFactory->setLocalNode(localNode);
|
||||||
taskFactory->setRoutingTable(routingTable.get());
|
taskFactory->setRoutingTable(routingTable.get());
|
||||||
|
@ -166,11 +167,11 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
taskFactory->setTaskQueue(taskQueue.get());
|
taskFactory->setTaskQueue(taskQueue.get());
|
||||||
taskFactory->setTimeout(messageTimeout);
|
taskFactory->setTimeout(messageTimeout);
|
||||||
|
|
||||||
routingTable->setTaskQueue(taskQueue);
|
routingTable->setTaskQueue(taskQueue.get());
|
||||||
routingTable->setTaskFactory(taskFactory);
|
routingTable->setTaskFactory(taskFactory.get());
|
||||||
|
|
||||||
peerAnnounceStorage->setTaskQueue(taskQueue);
|
peerAnnounceStorage->setTaskQueue(taskQueue.get());
|
||||||
peerAnnounceStorage->setTaskFactory(taskFactory);
|
peerAnnounceStorage->setTaskFactory(taskFactory.get());
|
||||||
|
|
||||||
factory->setRoutingTable(routingTable.get());
|
factory->setRoutingTable(routingTable.get());
|
||||||
factory->setConnection(connection.get());
|
factory->setConnection(connection.get());
|
||||||
|
@ -179,43 +180,6 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
factory->setTokenTracker(tokenTracker.get());
|
factory->setTokenTracker(tokenTracker.get());
|
||||||
factory->setLocalNode(localNode);
|
factory->setLocalNode(localNode);
|
||||||
|
|
||||||
// For now, UDPTrackerClient was enabled along with DHT
|
|
||||||
auto udpTrackerClient = std::make_shared<UDPTrackerClient>();
|
|
||||||
// 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<DHTBucketRefreshTask>
|
|
||||||
(taskFactory->createBucketRefreshTask());
|
|
||||||
task->setForceRefresh(true);
|
|
||||||
taskQueue->addPeriodicTask1(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Pref* prefEntryPointHost =
|
const Pref* prefEntryPointHost =
|
||||||
family == AF_INET?PREF_DHT_ENTRY_POINT_HOST:PREF_DHT_ENTRY_POINT_HOST6;
|
family == AF_INET?PREF_DHT_ENTRY_POINT_HOST:PREF_DHT_ENTRY_POINT_HOST6;
|
||||||
if(!e->getOption()->get(prefEntryPointHost).empty()) {
|
if(!e->getOption()->get(prefEntryPointHost).empty()) {
|
||||||
|
@ -231,9 +195,9 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
||||||
(e->newCUID(), e, entryPoints);
|
(e->newCUID(), e, entryPoints);
|
||||||
command->setBootstrapEnabled(true);
|
command->setBootstrapEnabled(true);
|
||||||
command->setTaskQueue(taskQueue);
|
command->setTaskQueue(taskQueue.get());
|
||||||
command->setTaskFactory(taskFactory);
|
command->setTaskFactory(taskFactory.get());
|
||||||
command->setRoutingTable(routingTable);
|
command->setRoutingTable(routingTable.get());
|
||||||
command->setLocalNode(localNode);
|
command->setLocalNode(localNode);
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
}
|
}
|
||||||
|
@ -242,9 +206,9 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTInteractionCommand>(e->newCUID(), e);
|
auto command = make_unique<DHTInteractionCommand>(e->newCUID(), e);
|
||||||
command->setMessageDispatcher(dispatcher);
|
command->setMessageDispatcher(dispatcher.get());
|
||||||
command->setMessageReceiver(receiver);
|
command->setMessageReceiver(receiver.get());
|
||||||
command->setTaskQueue(taskQueue);
|
command->setTaskQueue(taskQueue.get());
|
||||||
command->setReadCheckSocket(connection->getSocket());
|
command->setReadCheckSocket(connection->getSocket());
|
||||||
command->setConnection(connection);
|
command->setConnection(connection);
|
||||||
command->setUDPTrackerClient(udpTrackerClient);
|
command->setUDPTrackerClient(udpTrackerClient);
|
||||||
|
@ -253,33 +217,66 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTTokenUpdateCommand>
|
auto command = make_unique<DHTTokenUpdateCommand>
|
||||||
(e->newCUID(), e, DHT_TOKEN_UPDATE_INTERVAL);
|
(e->newCUID(), e, DHT_TOKEN_UPDATE_INTERVAL);
|
||||||
command->setTokenTracker(tokenTracker);
|
command->setTokenTracker(tokenTracker.get());
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTBucketRefreshCommand>
|
auto command = make_unique<DHTBucketRefreshCommand>
|
||||||
(e->newCUID(), e, DHT_BUCKET_REFRESH_CHECK_INTERVAL);
|
(e->newCUID(), e, DHT_BUCKET_REFRESH_CHECK_INTERVAL);
|
||||||
command->setTaskQueue(taskQueue);
|
command->setTaskQueue(taskQueue.get());
|
||||||
command->setRoutingTable(routingTable);
|
command->setRoutingTable(routingTable.get());
|
||||||
command->setTaskFactory(taskFactory);
|
command->setTaskFactory(taskFactory.get());
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTPeerAnnounceCommand>
|
auto command = make_unique<DHTPeerAnnounceCommand>
|
||||||
(e->newCUID(), e, DHT_PEER_ANNOUNCE_CHECK_INTERVAL);
|
(e->newCUID(), e, DHT_PEER_ANNOUNCE_CHECK_INTERVAL);
|
||||||
command->setPeerAnnounceStorage(peerAnnounceStorage);
|
command->setPeerAnnounceStorage(peerAnnounceStorage.get());
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTAutoSaveCommand>
|
auto command = make_unique<DHTAutoSaveCommand>
|
||||||
(e->newCUID(), e, family, 30*60);
|
(e->newCUID(), e, family, 30*60);
|
||||||
command->setLocalNode(localNode);
|
command->setLocalNode(localNode);
|
||||||
command->setRoutingTable(routingTable);
|
command->setRoutingTable(routingTable.get());
|
||||||
tempCommands.push_back(std::move(command));
|
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<DHTBucketRefreshTask>
|
||||||
|
(taskFactory->createBucketRefreshTask());
|
||||||
|
task->setForceRefresh(true);
|
||||||
|
taskQueue->addPeriodicTask1(task);
|
||||||
|
}
|
||||||
|
// assign them into DHTRegistry
|
||||||
if(family == AF_INET) {
|
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);
|
DHTRegistry::setInitialized(true);
|
||||||
} else {
|
} 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);
|
DHTRegistry::setInitialized6(true);
|
||||||
}
|
}
|
||||||
if(e->getBtRegistry()->getUdpPort() == 0) {
|
if(e->getBtRegistry()->getUdpPort() == 0) {
|
||||||
|
|
|
@ -45,7 +45,8 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTTokenUpdateCommand::DHTTokenUpdateCommand
|
DHTTokenUpdateCommand::DHTTokenUpdateCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
||||||
: TimeBasedCommand(cuid, e, interval)
|
: TimeBasedCommand{cuid, e, interval},
|
||||||
|
tokenTracker_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}
|
DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}
|
||||||
|
@ -67,7 +68,7 @@ void DHTTokenUpdateCommand::process()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTTokenUpdateCommand::setTokenTracker(const std::shared_ptr<DHTTokenTracker>& tokenTracker)
|
void DHTTokenUpdateCommand::setTokenTracker(DHTTokenTracker* tokenTracker)
|
||||||
{
|
{
|
||||||
tokenTracker_ = tokenTracker;
|
tokenTracker_ = tokenTracker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class DHTTokenTracker;
|
||||||
|
|
||||||
class DHTTokenUpdateCommand:public TimeBasedCommand {
|
class DHTTokenUpdateCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DHTTokenTracker> tokenTracker_;
|
DHTTokenTracker* tokenTracker_;
|
||||||
public:
|
public:
|
||||||
DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
virtual void process();
|
virtual void process();
|
||||||
|
|
||||||
void setTokenTracker(const std::shared_ptr<DHTTokenTracker>& tokenTracker);
|
void setTokenTracker(DHTTokenTracker* tokenTracker);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -447,9 +447,9 @@ void RequestGroup::createInitialCommand
|
||||||
if(!nodes.empty() && DHTRegistry::isInitialized()) {
|
if(!nodes.empty() && DHTRegistry::isInitialized()) {
|
||||||
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
||||||
(e->newCUID(), e, nodes);
|
(e->newCUID(), e, nodes);
|
||||||
command->setTaskQueue(DHTRegistry::getData().taskQueue);
|
command->setTaskQueue(DHTRegistry::getData().taskQueue.get());
|
||||||
command->setTaskFactory(DHTRegistry::getData().taskFactory);
|
command->setTaskFactory(DHTRegistry::getData().taskFactory.get());
|
||||||
command->setRoutingTable(DHTRegistry::getData().routingTable);
|
command->setRoutingTable(DHTRegistry::getData().routingTable.get());
|
||||||
command->setLocalNode(DHTRegistry::getData().localNode);
|
command->setLocalNode(DHTRegistry::getData().localNode);
|
||||||
e->addCommand(std::move(command));
|
e->addCommand(std::move(command));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTMessageTrackerTest);
|
||||||
void DHTMessageTrackerTest::testMessageArrived()
|
void DHTMessageTrackerTest::testMessageArrived()
|
||||||
{
|
{
|
||||||
auto localNode = std::make_shared<DHTNode>();
|
auto localNode = std::make_shared<DHTNode>();
|
||||||
auto routingTable = std::make_shared<DHTRoutingTable>(localNode);
|
auto routingTable = make_unique<DHTRoutingTable>(localNode);
|
||||||
auto factory = std::make_shared<MockDHTMessageFactory>();
|
auto factory = make_unique<MockDHTMessageFactory>();
|
||||||
factory->setLocalNode(localNode);
|
factory->setLocalNode(localNode);
|
||||||
|
|
||||||
auto r1 = std::make_shared<DHTNode>();
|
auto r1 = std::make_shared<DHTNode>();
|
||||||
|
@ -54,7 +54,7 @@ void DHTMessageTrackerTest::testMessageArrived()
|
||||||
auto m3 = make_unique<MockDHTMessage>(localNode, r3);
|
auto m3 = make_unique<MockDHTMessage>(localNode, r3);
|
||||||
|
|
||||||
DHTMessageTracker tracker;
|
DHTMessageTracker tracker;
|
||||||
tracker.setRoutingTable(routingTable);
|
tracker.setRoutingTable(routingTable.get());
|
||||||
tracker.setMessageFactory(factory.get());
|
tracker.setMessageFactory(factory.get());
|
||||||
tracker.addMessage(m1.get(), DHT_MESSAGE_TIMEOUT);
|
tracker.addMessage(m1.get(), DHT_MESSAGE_TIMEOUT);
|
||||||
tracker.addMessage(m2.get(), DHT_MESSAGE_TIMEOUT);
|
tracker.addMessage(m2.get(), DHT_MESSAGE_TIMEOUT);
|
||||||
|
|
|
@ -35,16 +35,15 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTRoutingTableTest);
|
||||||
|
|
||||||
void DHTRoutingTableTest::testAddNode()
|
void DHTRoutingTableTest::testAddNode()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DHTNode> localNode(new DHTNode());
|
auto localNode = std::make_shared<DHTNode>();
|
||||||
DHTRoutingTable table(localNode);
|
DHTRoutingTable table(localNode);
|
||||||
std::shared_ptr<MockDHTTaskFactory> taskFactory(new MockDHTTaskFactory());
|
auto taskFactory = make_unique<MockDHTTaskFactory>();
|
||||||
table.setTaskFactory(taskFactory);
|
table.setTaskFactory(taskFactory.get());
|
||||||
std::shared_ptr<MockDHTTaskQueue> taskQueue(new MockDHTTaskQueue());
|
auto taskQueue = make_unique<MockDHTTaskQueue>();
|
||||||
table.setTaskQueue(taskQueue);
|
table.setTaskQueue(taskQueue.get());
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
for(int i = 0; i < 100; ++i) {
|
for(int i = 0; i < 100; ++i) {
|
||||||
std::shared_ptr<DHTNode> node(new DHTNode());
|
if(table.addNode(std::make_shared<DHTNode>())) {
|
||||||
if(table.addNode(node)) {
|
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,14 +52,14 @@ void DHTRoutingTableTest::testAddNode()
|
||||||
|
|
||||||
void DHTRoutingTableTest::testAddNode_localNode()
|
void DHTRoutingTableTest::testAddNode_localNode()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DHTNode> localNode(new DHTNode());
|
auto localNode = std::make_shared<DHTNode>();
|
||||||
DHTRoutingTable table(localNode);
|
DHTRoutingTable table(localNode);
|
||||||
std::shared_ptr<MockDHTTaskFactory> taskFactory(new MockDHTTaskFactory());
|
auto taskFactory = make_unique<MockDHTTaskFactory>();
|
||||||
table.setTaskFactory(taskFactory);
|
table.setTaskFactory(taskFactory.get());
|
||||||
std::shared_ptr<MockDHTTaskQueue> taskQueue(new MockDHTTaskQueue());
|
auto taskQueue = make_unique<MockDHTTaskQueue>();
|
||||||
table.setTaskQueue(taskQueue);
|
table.setTaskQueue(taskQueue.get());
|
||||||
|
|
||||||
std::shared_ptr<DHTNode> newNode(new DHTNode(localNode->getID()));
|
auto newNode = std::make_shared<DHTNode>(localNode->getID());
|
||||||
CPPUNIT_ASSERT(!table.addNode(newNode));
|
CPPUNIT_ASSERT(!table.addNode(newNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ void DHTRoutingTableTest::testGetClosestKNodes()
|
||||||
{
|
{
|
||||||
unsigned char id[DHT_ID_LENGTH];
|
unsigned char id[DHT_ID_LENGTH];
|
||||||
createID(id, 0x81, 0);
|
createID(id, 0x81, 0);
|
||||||
std::shared_ptr<DHTNode> localNode(new DHTNode(id));
|
auto localNode = std::make_shared<DHTNode>(id);
|
||||||
|
|
||||||
DHTRoutingTable table(localNode);
|
DHTRoutingTable table(localNode);
|
||||||
|
|
||||||
|
@ -86,26 +85,27 @@ void DHTRoutingTableTest::testGetClosestKNodes()
|
||||||
std::shared_ptr<DHTNode> nodes3[8];
|
std::shared_ptr<DHTNode> nodes3[8];
|
||||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||||
createID(id, 0xf0, i);
|
createID(id, 0xf0, i);
|
||||||
nodes1[i].reset(new DHTNode(id));
|
nodes1[i] = std::make_shared<DHTNode>(id);
|
||||||
CPPUNIT_ASSERT(table.addNode(nodes1[i]));
|
CPPUNIT_ASSERT(table.addNode(nodes1[i]));
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||||
createID(id, 0x80, i);
|
createID(id, 0x80, i);
|
||||||
nodes2[i].reset(new DHTNode(id));
|
nodes2[i] = std::make_shared<DHTNode>(id);
|
||||||
CPPUNIT_ASSERT(table.addNode(nodes2[i]));
|
CPPUNIT_ASSERT(table.addNode(nodes2[i]));
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||||
createID(id, 0x70, i);
|
createID(id, 0x70, i);
|
||||||
nodes3[i].reset(new DHTNode(id));
|
nodes3[i] = std::make_shared<DHTNode>(id);
|
||||||
CPPUNIT_ASSERT(table.addNode(nodes3[i]));
|
CPPUNIT_ASSERT(table.addNode(nodes3[i]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
createID(id, 0x80, 0x10);
|
createID(id, 0x80, 0x10);
|
||||||
std::vector<std::shared_ptr<DHTNode> > nodes;
|
std::vector<std::shared_ptr<DHTNode>> nodes;
|
||||||
table.getClosestKNodes(nodes, id);
|
table.getClosestKNodes(nodes, id);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)8, nodes.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)8, nodes.size());
|
||||||
for(size_t i = 0; i < nodes.size(); ++i) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue