summaryrefslogtreecommitdiff
path: root/src/DHTEntryPointNameResolveCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-13 15:17:08 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-13 15:17:08 +0000
commit13021233680e3fb3650075e2a71c1f234acb1803 (patch)
treee79c0138e86071486e18a0814df377b47050a0d0 /src/DHTEntryPointNameResolveCommand.cc
parentbfcc3006703924fade80cbf41b4d682481618690 (diff)
2008-02-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added the ability to load nodes from torrent file. These nodes are added to the routing table when downloading that torrent. * src/BtContext.h * src/DefaultBtContext.{h, cc} * src/DHTSetup.cc * src/DHTEntryPointNameResolveCommand.{h, cc}: Now accepts list of hostname and port pair, and resolves all of them. * src/NameResolver.{h, cc}: Added reset(). * src/RequestGroup.cc * test/DefaultBtContextTest.cc * test/MockBtContext.h Removed assert() from DefaultBtContext and throw exception instead. * src/DefaultBtContext.cc
Diffstat (limited to 'src/DHTEntryPointNameResolveCommand.cc')
-rw-r--r--src/DHTEntryPointNameResolveCommand.cc76
1 files changed, 58 insertions, 18 deletions
diff --git a/src/DHTEntryPointNameResolveCommand.cc b/src/DHTEntryPointNameResolveCommand.cc
index 5de627a7..3ffe73cc 100644
--- a/src/DHTEntryPointNameResolveCommand.cc
+++ b/src/DHTEntryPointNameResolveCommand.cc
@@ -44,19 +44,23 @@
#include "DHTNode.h"
#include "DHTTaskQueue.h"
#include "DHTTaskFactory.h"
+#include "DHTRoutingTable.h"
#include "DHTTask.h"
#include "RequestGroupMan.h"
#include "Logger.h"
namespace aria2 {
-DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand(int32_t cuid, DownloadEngine* e):
+DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand(int32_t cuid, DownloadEngine* e, const std::deque<std::pair<std::string, uint16_t> >& entryPoints):
Command(cuid),
_e(e),
_resolver(new NameResolver()),
_taskQueue(0),
_taskFactory(0),
- _localNode(0)
+ _routingTable(0),
+ _localNode(0),
+ _entryPoints(entryPoints),
+ _bootstrapEnabled(false)
{}
DHTEntryPointNameResolveCommand::~DHTEntryPointNameResolveCommand()
@@ -71,25 +75,42 @@ bool DHTEntryPointNameResolveCommand::execute()
if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) {
return true;
}
-
try {
- std::string hostname = _e->option->get(PREF_DHT_ENTRY_POINT_HOST);
- if(!Util::isNumbersAndDotsNotation(hostname)) {
- if(resolveHostname(hostname, _resolver)) {
- hostname = _resolver->getAddrString();
- } else {
- _e->commands.push_back(this);
- return false;
+ while(_entryPoints.size()) {
+ std::string hostname = _entryPoints.front().first;
+ try {
+ if(Util::isNumbersAndDotsNotation(hostname)) {
+ std::pair<std::string, uint16_t> p(hostname,
+ _entryPoints.front().second);
+ _resolvedEntryPoints.push_back(p);
+ _entryPoints.erase(_entryPoints.begin());
+ addPingTask(p);
+ } else {
+ if(resolveHostname(hostname, _resolver)) {
+ hostname = _resolver->getAddrString();
+ _resolver->reset();
+ std::pair<std::string, uint16_t> p(hostname,
+ _entryPoints.front().second);
+ _resolvedEntryPoints.push_back(p);
+ _entryPoints.erase(_entryPoints.begin());
+ addPingTask(p);
+ } else {
+ _e->commands.push_back(this);
+ return false;
+ }
+ }
+ } catch(RecoverableException* e) {
+ logger->error(EX_EXCEPTION_CAUGHT, e);
+ delete e;
+ _entryPoints.erase(_entryPoints.begin());
+ _resolver->reset();
}
}
-
- SharedHandle<DHTNode> entryNode = new DHTNode();
- entryNode->setIPAddress(hostname);
- entryNode->setPort(_e->option->getAsInt(PREF_DHT_ENTRY_POINT_PORT));
-
- _taskQueue->addPeriodicTask1(_taskFactory->createPingTask(entryNode, 10));
- _taskQueue->addPeriodicTask1(_taskFactory->createNodeLookupTask(_localNode->getID()));
- _taskQueue->addPeriodicTask1(_taskFactory->createBucketRefreshTask());
+
+ if(_bootstrapEnabled && _resolvedEntryPoints.size()) {
+ _taskQueue->addPeriodicTask1(_taskFactory->createNodeLookupTask(_localNode->getID()));
+ _taskQueue->addPeriodicTask1(_taskFactory->createBucketRefreshTask());
+ }
} catch(RecoverableException* e) {
logger->error(EX_EXCEPTION_CAUGHT, e);
delete e;
@@ -97,6 +118,15 @@ bool DHTEntryPointNameResolveCommand::execute()
return true;
}
+void DHTEntryPointNameResolveCommand::addPingTask(const std::pair<std::string, uint16_t>& addr)
+{
+ SharedHandle<DHTNode> entryNode = new DHTNode();
+ entryNode->setIPAddress(addr.first);
+ entryNode->setPort(addr.second);
+
+ _taskQueue->addPeriodicTask1(_taskFactory->createPingTask(entryNode, 10));
+}
+
bool DHTEntryPointNameResolveCommand::resolveHostname(const std::string& hostname,
const NameResolverHandle& resolver)
{
@@ -148,6 +178,11 @@ void DHTEntryPointNameResolveCommand::disableNameResolverCheck(const SharedHandl
}
#endif // ENABLE_ASYNC_DNS
+void DHTEntryPointNameResolveCommand::setBootstrapEnabled(bool f)
+{
+ _bootstrapEnabled = f;
+}
+
void DHTEntryPointNameResolveCommand::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
{
_taskQueue = taskQueue;
@@ -158,6 +193,11 @@ void DHTEntryPointNameResolveCommand::setTaskFactory(const SharedHandle<DHTTaskF
_taskFactory = taskFactory;
}
+void DHTEntryPointNameResolveCommand::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
+{
+ _routingTable = routingTable;
+}
+
void DHTEntryPointNameResolveCommand::setLocalNode(const SharedHandle<DHTNode>& localNode)
{
_localNode = localNode;