DHTFindNodeMessage.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "DHTFindNodeMessage.h"
  36. #include "DHTNode.h"
  37. #include "Data.h"
  38. #include "Dictionary.h"
  39. #include "DHTRoutingTable.h"
  40. #include "DHTMessageFactory.h"
  41. #include "DHTMessageDispatcher.h"
  42. #include "DHTMessageCallback.h"
  43. #include <cstring>
  44. namespace aria2 {
  45. DHTFindNodeMessage::DHTFindNodeMessage(const SharedHandle<DHTNode>& localNode,
  46. const SharedHandle<DHTNode>& remoteNode,
  47. const unsigned char* targetNodeID,
  48. const std::string& transactionID):
  49. DHTQueryMessage(localNode, remoteNode, transactionID)
  50. {
  51. memcpy(_targetNodeID, targetNodeID, DHT_ID_LENGTH);
  52. }
  53. DHTFindNodeMessage::~DHTFindNodeMessage() {}
  54. void DHTFindNodeMessage::doReceivedAction()
  55. {
  56. std::deque<SharedHandle<DHTNode> > nodes = _routingTable->getClosestKNodes(_targetNodeID);
  57. SharedHandle<DHTMessage> reply =
  58. _factory->createFindNodeReplyMessage(_remoteNode, nodes, _transactionID);
  59. _dispatcher->addMessageToQueue(reply);
  60. }
  61. Dictionary* DHTFindNodeMessage::getArgument()
  62. {
  63. Dictionary* a = new Dictionary();
  64. a->put("id", new Data(reinterpret_cast<const char*>(_localNode->getID()),
  65. DHT_ID_LENGTH));
  66. a->put("target", new Data(reinterpret_cast<const char*>(_targetNodeID),
  67. DHT_ID_LENGTH));
  68. return a;
  69. }
  70. std::string DHTFindNodeMessage::getMessageType() const
  71. {
  72. return "find_node";
  73. }
  74. void DHTFindNodeMessage::validate() const {}
  75. } // namespace aria2