DownloadEngine.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "DownloadEngine.h"
  36. #include <signal.h>
  37. #include <cstring>
  38. #include <cerrno>
  39. #include <algorithm>
  40. #include <numeric>
  41. #include <iterator>
  42. #include "StatCalc.h"
  43. #include "RequestGroup.h"
  44. #include "RequestGroupMan.h"
  45. #include "DownloadResult.h"
  46. #include "StatCalc.h"
  47. #include "LogFactory.h"
  48. #include "Logger.h"
  49. #include "SocketCore.h"
  50. #include "util.h"
  51. #include "a2functional.h"
  52. #include "DlAbortEx.h"
  53. #include "ServerStatMan.h"
  54. #include "CookieStorage.h"
  55. #include "A2STR.h"
  56. #include "AuthConfigFactory.h"
  57. #include "AuthConfig.h"
  58. #include "Request.h"
  59. #include "EventPoll.h"
  60. #include "Command.h"
  61. #include "FileAllocationEntry.h"
  62. #include "CheckIntegrityEntry.h"
  63. #include "BtProgressInfoFile.h"
  64. #include "DownloadContext.h"
  65. #include "fmt.h"
  66. #include "wallclock.h"
  67. #ifdef ENABLE_BITTORRENT
  68. # include "BtRegistry.h"
  69. #endif // ENABLE_BITTORRENT
  70. #ifdef ENABLE_WEBSOCKET
  71. # include "WebSocketSessionMan.h"
  72. #endif // ENABLE_WEBSOCKET
  73. #include "Option.h"
  74. #include "util_security.h"
  75. namespace aria2 {
  76. namespace global {
  77. // 0 ... running
  78. // 1 ... stop signal detected
  79. // 2 ... stop signal processed by DownloadEngine
  80. // 3 ... 2nd stop signal(force shutdown) detected
  81. // 4 ... 2nd stop signal processed by DownloadEngine
  82. // 5 ... main loop exited
  83. volatile sig_atomic_t globalHaltRequested = 0;
  84. } // namespace global
  85. DownloadEngine::DownloadEngine(std::unique_ptr<EventPoll> eventPoll)
  86. : eventPoll_(std::move(eventPoll)),
  87. haltRequested_(0),
  88. noWait_(true),
  89. refreshInterval_(DEFAULT_REFRESH_INTERVAL),
  90. lastRefresh_(0),
  91. cookieStorage_(new CookieStorage()),
  92. #ifdef ENABLE_BITTORRENT
  93. btRegistry_(make_unique<BtRegistry>()),
  94. #endif // ENABLE_BITTORRENT
  95. #ifdef HAVE_ARES_ADDR_NODE
  96. asyncDNSServers_(nullptr),
  97. #endif // HAVE_ARES_ADDR_NODE
  98. dnsCache_(make_unique<DNSCache>()),
  99. option_(nullptr)
  100. {
  101. unsigned char sessionId[20];
  102. util::generateRandomKey(sessionId);
  103. sessionId_.assign(&sessionId[0], & sessionId[sizeof(sessionId)]);
  104. }
  105. DownloadEngine::~DownloadEngine()
  106. {
  107. #ifdef HAVE_ARES_ADDR_NODE
  108. setAsyncDNSServers(nullptr);
  109. #endif // HAVE_ARES_ADDR_NODE
  110. }
  111. namespace {
  112. void executeCommand(std::deque<std::unique_ptr<Command>>& commands,
  113. Command::STATUS statusFilter)
  114. {
  115. size_t max = commands.size();
  116. for(size_t i = 0; i < max; ++i) {
  117. auto com = std::move(commands.front());
  118. commands.pop_front();
  119. if (!com->statusMatch(statusFilter)) {
  120. com->clearIOEvents();
  121. commands.push_back(std::move(com));
  122. continue;
  123. }
  124. com->transitStatus();
  125. if (com->execute()) {
  126. com.reset();
  127. }
  128. else {
  129. com->clearIOEvents();
  130. com.release();
  131. }
  132. }
  133. }
  134. } // namespace
  135. namespace {
  136. class GlobalHaltRequestedFinalizer {
  137. public:
  138. GlobalHaltRequestedFinalizer() {}
  139. ~GlobalHaltRequestedFinalizer()
  140. {
  141. global::globalHaltRequested = 5;
  142. }
  143. };
  144. } // namespace
  145. int DownloadEngine::run(bool oneshot)
  146. {
  147. GlobalHaltRequestedFinalizer ghrf;
  148. while(!commands_.empty() || !routineCommands_.empty()) {
  149. if(!commands_.empty()) {
  150. waitData();
  151. }
  152. noWait_ = false;
  153. global::wallclock().reset();
  154. calculateStatistics();
  155. if(lastRefresh_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS >=
  156. refreshInterval_) {
  157. refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
  158. lastRefresh_ = global::wallclock();
  159. executeCommand(commands_, Command::STATUS_ALL);
  160. } else {
  161. executeCommand(commands_, Command::STATUS_ACTIVE);
  162. }
  163. executeCommand(routineCommands_, Command::STATUS_ALL);
  164. afterEachIteration();
  165. if(!noWait_ && oneshot) {
  166. return 1;
  167. }
  168. }
  169. onEndOfRun();
  170. return 0;
  171. }
  172. void DownloadEngine::waitData()
  173. {
  174. struct timeval tv;
  175. if(noWait_) {
  176. tv.tv_sec = tv.tv_usec = 0;
  177. } else {
  178. lldiv_t qr = lldiv(refreshInterval_*1000, 1000000);
  179. tv.tv_sec = qr.quot;
  180. tv.tv_usec = qr.rem;
  181. }
  182. eventPoll_->poll(tv);
  183. }
  184. bool DownloadEngine::addSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
  185. Command* command)
  186. {
  187. return eventPoll_->addEvents(socket->getSockfd(), command,
  188. EventPoll::EVENT_READ);
  189. }
  190. bool DownloadEngine::deleteSocketForReadCheck(const std::shared_ptr<SocketCore>& socket,
  191. Command* command)
  192. {
  193. return eventPoll_->deleteEvents(socket->getSockfd(), command,
  194. EventPoll::EVENT_READ);
  195. }
  196. bool DownloadEngine::addSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
  197. Command* command)
  198. {
  199. return eventPoll_->addEvents(socket->getSockfd(), command,
  200. EventPoll::EVENT_WRITE);
  201. }
  202. bool DownloadEngine::deleteSocketForWriteCheck(const std::shared_ptr<SocketCore>& socket,
  203. Command* command)
  204. {
  205. return eventPoll_->deleteEvents(socket->getSockfd(), command,
  206. EventPoll::EVENT_WRITE);
  207. }
  208. void DownloadEngine::calculateStatistics()
  209. {
  210. if(statCalc_) {
  211. statCalc_->calculateStat(this);
  212. }
  213. }
  214. void DownloadEngine::onEndOfRun()
  215. {
  216. requestGroupMan_->removeStoppedGroup(this);
  217. requestGroupMan_->closeFile();
  218. requestGroupMan_->save();
  219. }
  220. void DownloadEngine::afterEachIteration()
  221. {
  222. if(global::globalHaltRequested == 1) {
  223. A2_LOG_NOTICE(_("Shutdown sequence commencing..."
  224. " Press Ctrl-C again for emergency shutdown."));
  225. requestHalt();
  226. global::globalHaltRequested = 2;
  227. setNoWait(true);
  228. setRefreshInterval(0);
  229. return;
  230. }
  231. if(global::globalHaltRequested == 3) {
  232. A2_LOG_NOTICE(_("Emergency shutdown sequence commencing..."));
  233. requestForceHalt();
  234. global::globalHaltRequested = 4;
  235. setNoWait(true);
  236. setRefreshInterval(0);
  237. return;
  238. }
  239. }
  240. void DownloadEngine::requestHalt()
  241. {
  242. haltRequested_ = std::max(haltRequested_, 1);
  243. requestGroupMan_->halt();
  244. }
  245. void DownloadEngine::requestForceHalt()
  246. {
  247. haltRequested_ = std::max(haltRequested_, 2);
  248. requestGroupMan_->forceHalt();
  249. }
  250. void DownloadEngine::setStatCalc(std::unique_ptr<StatCalc> statCalc)
  251. {
  252. statCalc_ = std::move(statCalc);
  253. }
  254. #ifdef ENABLE_ASYNC_DNS
  255. bool DownloadEngine::addNameResolverCheck
  256. (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
  257. {
  258. return eventPoll_->addNameResolver(resolver, command);
  259. }
  260. bool DownloadEngine::deleteNameResolverCheck
  261. (const std::shared_ptr<AsyncNameResolver>& resolver, Command* command)
  262. {
  263. return eventPoll_->deleteNameResolver(resolver, command);
  264. }
  265. #endif // ENABLE_ASYNC_DNS
  266. void DownloadEngine::setNoWait(bool b)
  267. {
  268. noWait_ = b;
  269. }
  270. void DownloadEngine::addRoutineCommand(std::unique_ptr<Command> command)
  271. {
  272. routineCommands_.push_back(std::move(command));
  273. }
  274. void DownloadEngine::poolSocket(const std::string& key,
  275. const SocketPoolEntry& entry)
  276. {
  277. A2_LOG_INFO(fmt("Pool socket for %s", key.c_str()));
  278. std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
  279. socketPool_.insert(p);
  280. if(lastSocketPoolScan_.difference(global::wallclock()) < 60) {
  281. return;
  282. }
  283. std::multimap<std::string, SocketPoolEntry> newPool;
  284. A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
  285. lastSocketPoolScan_ = global::wallclock();
  286. for(auto & elem : socketPool_) {
  287. if(!elem.second.isTimeout()) {
  288. newPool.insert(elem);
  289. }
  290. }
  291. A2_LOG_DEBUG(fmt("%lu entries removed.",
  292. static_cast<unsigned long>
  293. (socketPool_.size()-newPool.size())));
  294. socketPool_ = newPool;
  295. }
  296. namespace {
  297. std::string createSockPoolKey
  298. (const std::string& host, uint16_t port,
  299. const std::string& username,
  300. const std::string& proxyhost, uint16_t proxyport)
  301. {
  302. std::string key;
  303. if(!username.empty()) {
  304. key += util::percentEncode(username);
  305. key += "@";
  306. }
  307. key += fmt("%s(%u)", host.c_str(), port);
  308. if(!proxyhost.empty()) {
  309. key += fmt("/%s(%u)", proxyhost.c_str(), proxyport);
  310. }
  311. return key;
  312. }
  313. } // namespace
  314. void DownloadEngine::poolSocket
  315. (const std::string& ipaddr,
  316. uint16_t port,
  317. const std::string& username,
  318. const std::string& proxyhost,
  319. uint16_t proxyport,
  320. const std::shared_ptr<SocketCore>& sock,
  321. const std::string& options,
  322. time_t timeout)
  323. {
  324. SocketPoolEntry e(sock, options, timeout);
  325. poolSocket(createSockPoolKey(ipaddr, port, username, proxyhost, proxyport),e);
  326. }
  327. void DownloadEngine::poolSocket
  328. (const std::string& ipaddr,
  329. uint16_t port,
  330. const std::string& proxyhost,
  331. uint16_t proxyport,
  332. const std::shared_ptr<SocketCore>& sock,
  333. time_t timeout)
  334. {
  335. SocketPoolEntry e(sock, timeout);
  336. poolSocket(createSockPoolKey(ipaddr, port, A2STR::NIL,proxyhost,proxyport),e);
  337. }
  338. namespace {
  339. bool getPeerInfo(std::pair<std::string, uint16_t>& res,
  340. const std::shared_ptr<SocketCore>& socket)
  341. {
  342. try {
  343. socket->getPeerInfo(res);
  344. return true;
  345. } catch(RecoverableException& e) {
  346. // socket->getPeerInfo() can fail if the socket has been
  347. // disconnected.
  348. A2_LOG_INFO_EX("Getting peer info failed. Pooling socket canceled.", e);
  349. return false;
  350. }
  351. }
  352. } // namespace
  353. void DownloadEngine::poolSocket(const std::shared_ptr<Request>& request,
  354. const std::shared_ptr<Request>& proxyRequest,
  355. const std::shared_ptr<SocketCore>& socket,
  356. time_t timeout)
  357. {
  358. if(proxyRequest) {
  359. // If proxy is defined, then pool socket with its hostname.
  360. poolSocket(request->getHost(), request->getPort(),
  361. proxyRequest->getHost(), proxyRequest->getPort(),
  362. socket, timeout);
  363. return;
  364. }
  365. std::pair<std::string, uint16_t> peerInfo;
  366. if(getPeerInfo(peerInfo, socket)) {
  367. poolSocket(peerInfo.first, peerInfo.second,
  368. A2STR::NIL, 0, socket, timeout);
  369. }
  370. }
  371. void DownloadEngine::poolSocket
  372. (const std::shared_ptr<Request>& request,
  373. const std::string& username,
  374. const std::shared_ptr<Request>& proxyRequest,
  375. const std::shared_ptr<SocketCore>& socket,
  376. const std::string& options,
  377. time_t timeout)
  378. {
  379. if(proxyRequest) {
  380. // If proxy is defined, then pool socket with its hostname.
  381. poolSocket(request->getHost(), request->getPort(), username,
  382. proxyRequest->getHost(), proxyRequest->getPort(),
  383. socket, options, timeout);
  384. return;
  385. }
  386. std::pair<std::string, uint16_t> peerInfo;
  387. if(getPeerInfo(peerInfo, socket)) {
  388. poolSocket(peerInfo.first, peerInfo.second, username,
  389. A2STR::NIL, 0, socket, options, timeout);
  390. }
  391. }
  392. std::multimap<std::string, DownloadEngine::SocketPoolEntry>::iterator
  393. DownloadEngine::findSocketPoolEntry(const std::string& key)
  394. {
  395. std::pair<std::multimap<std::string, SocketPoolEntry>::iterator,
  396. std::multimap<std::string, SocketPoolEntry>::iterator> range =
  397. socketPool_.equal_range(key);
  398. for(auto i = range.first, eoi = range.second; i != eoi; ++i) {
  399. const SocketPoolEntry& e = (*i).second;
  400. // We assume that if socket is readable it means peer shutdowns
  401. // connection and the socket will receive EOF. So skip it.
  402. if(!e.isTimeout() && !e.getSocket()->isReadable(0)) {
  403. A2_LOG_INFO(fmt("Found socket for %s", key.c_str()));
  404. return i;
  405. }
  406. }
  407. return socketPool_.end();
  408. }
  409. std::shared_ptr<SocketCore>
  410. DownloadEngine::popPooledSocket
  411. (const std::string& ipaddr, uint16_t port,
  412. const std::string& proxyhost, uint16_t proxyport)
  413. {
  414. std::shared_ptr<SocketCore> s;
  415. auto i = findSocketPoolEntry(createSockPoolKey(ipaddr, port, A2STR::NIL,
  416. proxyhost, proxyport));
  417. if(i != socketPool_.end()) {
  418. s = (*i).second.getSocket();
  419. socketPool_.erase(i);
  420. }
  421. return s;
  422. }
  423. std::shared_ptr<SocketCore>
  424. DownloadEngine::popPooledSocket
  425. (std::string& options,
  426. const std::string& ipaddr, uint16_t port,
  427. const std::string& username,
  428. const std::string& proxyhost, uint16_t proxyport)
  429. {
  430. std::shared_ptr<SocketCore> s;
  431. auto i = findSocketPoolEntry(createSockPoolKey(ipaddr, port, username,
  432. proxyhost, proxyport));
  433. if(i != socketPool_.end()) {
  434. s = (*i).second.getSocket();
  435. options = (*i).second.getOptions();
  436. socketPool_.erase(i);
  437. }
  438. return s;
  439. }
  440. std::shared_ptr<SocketCore>
  441. DownloadEngine::popPooledSocket
  442. (const std::vector<std::string>& ipaddrs, uint16_t port)
  443. {
  444. std::shared_ptr<SocketCore> s;
  445. for(const auto & ipaddr : ipaddrs) {
  446. s = popPooledSocket(ipaddr, port, A2STR::NIL, 0);
  447. if(s) {
  448. break;
  449. }
  450. }
  451. return s;
  452. }
  453. std::shared_ptr<SocketCore>
  454. DownloadEngine::popPooledSocket
  455. (std::string& options,
  456. const std::vector<std::string>& ipaddrs, uint16_t port,
  457. const std::string& username)
  458. {
  459. std::shared_ptr<SocketCore> s;
  460. for(const auto & ipaddr : ipaddrs) {
  461. s = popPooledSocket(options, ipaddr, port, username, A2STR::NIL, 0);
  462. if(s) {
  463. break;
  464. }
  465. }
  466. return s;
  467. }
  468. DownloadEngine::SocketPoolEntry::SocketPoolEntry
  469. (const std::shared_ptr<SocketCore>& socket,
  470. const std::string& options,
  471. time_t timeout)
  472. : socket_(socket),
  473. options_(options),
  474. timeout_(timeout)
  475. {}
  476. DownloadEngine::SocketPoolEntry::SocketPoolEntry
  477. (const std::shared_ptr<SocketCore>& socket, time_t timeout)
  478. : socket_(socket),
  479. timeout_(timeout)
  480. {}
  481. DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
  482. bool DownloadEngine::SocketPoolEntry::isTimeout() const
  483. {
  484. return registeredTime_.difference(global::wallclock()) >= timeout_;
  485. }
  486. cuid_t DownloadEngine::newCUID()
  487. {
  488. return cuidCounter_.newID();
  489. }
  490. const std::string& DownloadEngine::findCachedIPAddress
  491. (const std::string& hostname, uint16_t port) const
  492. {
  493. return dnsCache_->find(hostname, port);
  494. }
  495. void DownloadEngine::cacheIPAddress
  496. (const std::string& hostname, const std::string& ipaddr, uint16_t port)
  497. {
  498. dnsCache_->put(hostname, ipaddr, port);
  499. }
  500. void DownloadEngine::markBadIPAddress
  501. (const std::string& hostname, const std::string& ipaddr, uint16_t port)
  502. {
  503. dnsCache_->markBad(hostname, ipaddr, port);
  504. }
  505. void DownloadEngine::removeCachedIPAddress
  506. (const std::string& hostname, uint16_t port)
  507. {
  508. dnsCache_->remove(hostname, port);
  509. }
  510. void DownloadEngine::setAuthConfigFactory
  511. (std::unique_ptr<AuthConfigFactory> factory)
  512. {
  513. authConfigFactory_ = std::move(factory);
  514. }
  515. const std::unique_ptr<AuthConfigFactory>&
  516. DownloadEngine::getAuthConfigFactory() const
  517. {
  518. return authConfigFactory_;
  519. }
  520. const std::unique_ptr<CookieStorage>& DownloadEngine::getCookieStorage() const
  521. {
  522. return cookieStorage_;
  523. }
  524. void DownloadEngine::setRefreshInterval(int64_t interval)
  525. {
  526. refreshInterval_ = std::min(static_cast<int64_t>(999), interval);
  527. }
  528. void DownloadEngine::addCommand
  529. (std::vector<std::unique_ptr<Command>> commands)
  530. {
  531. commands_.insert(commands_.end(),
  532. std::make_move_iterator(std::begin(commands)),
  533. std::make_move_iterator(std::end(commands)));
  534. }
  535. void DownloadEngine::addCommand(std::unique_ptr<Command> command)
  536. {
  537. commands_.push_back(std::move(command));
  538. }
  539. void DownloadEngine::setRequestGroupMan(std::unique_ptr<RequestGroupMan> rgman)
  540. {
  541. requestGroupMan_ = std::move(rgman);
  542. }
  543. void DownloadEngine::setFileAllocationMan
  544. (std::unique_ptr<FileAllocationMan> faman)
  545. {
  546. fileAllocationMan_ = std::move(faman);
  547. }
  548. void DownloadEngine::setCheckIntegrityMan
  549. (std::unique_ptr<CheckIntegrityMan> ciman)
  550. {
  551. checkIntegrityMan_ = std::move(ciman);
  552. }
  553. #ifdef HAVE_ARES_ADDR_NODE
  554. void DownloadEngine::setAsyncDNSServers(ares_addr_node* asyncDNSServers)
  555. {
  556. ares_addr_node* node = asyncDNSServers_;
  557. while(node) {
  558. ares_addr_node* next = node->next;
  559. delete node;
  560. node = next;
  561. }
  562. asyncDNSServers_ = asyncDNSServers;
  563. }
  564. #endif // HAVE_ARES_ADDR_NODE
  565. #ifdef ENABLE_WEBSOCKET
  566. void DownloadEngine::setWebSocketSessionMan
  567. (std::unique_ptr<rpc::WebSocketSessionMan> wsman)
  568. {
  569. webSocketSessionMan_ = std::move(wsman);
  570. }
  571. #endif // ENABLE_WEBSOCKET
  572. bool DownloadEngine::validateToken(const std::string& token)
  573. {
  574. using namespace util::security;
  575. if (!option_->defined(PREF_RPC_SECRET)) {
  576. return true;
  577. }
  578. if (!tokenHMAC_) {
  579. tokenHMAC_ = HMAC::createRandom();
  580. if (!tokenHMAC_) {
  581. A2_LOG_ERROR("Failed to create HMAC");
  582. return false;
  583. }
  584. tokenExpected_ = make_unique<HMACResult>(tokenHMAC_->getResult(
  585. option_->get(PREF_RPC_SECRET)));
  586. }
  587. return *tokenExpected_ == tokenHMAC_->getResult(token);
  588. }
  589. } // namespace aria2