/* */ #include "DHTFindNodeMessage.h" #include "DHTNode.h" #include "Data.h" #include "Dictionary.h" #include "DHTRoutingTable.h" #include "DHTMessageFactory.h" #include "DHTMessageDispatcher.h" #include "DHTMessageCallback.h" #include "Util.h" #include namespace aria2 { const std::string DHTFindNodeMessage::FIND_NODE("find_node"); const std::string DHTFindNodeMessage::TARGET_NODE("target"); DHTFindNodeMessage::DHTFindNodeMessage(const SharedHandle& localNode, const SharedHandle& remoteNode, const unsigned char* targetNodeID, const std::string& transactionID): DHTQueryMessage(localNode, remoteNode, transactionID) { memcpy(_targetNodeID, targetNodeID, DHT_ID_LENGTH); } DHTFindNodeMessage::~DHTFindNodeMessage() {} void DHTFindNodeMessage::doReceivedAction() { std::deque > nodes; _routingTable->getClosestKNodes(nodes, _targetNodeID); SharedHandle reply = _factory->createFindNodeReplyMessage(_remoteNode, nodes, _transactionID); _dispatcher->addMessageToQueue(reply); } Dictionary* DHTFindNodeMessage::getArgument() { Dictionary* a = new Dictionary(); a->put(DHTMessage::ID, new Data(reinterpret_cast(_localNode->getID()), DHT_ID_LENGTH)); a->put(TARGET_NODE, new Data(reinterpret_cast(_targetNodeID), DHT_ID_LENGTH)); return a; } std::string DHTFindNodeMessage::getMessageType() const { return FIND_NODE; } void DHTFindNodeMessage::validate() const {} std::string DHTFindNodeMessage::toStringOptional() const { return "targetNodeID="+Util::toHex(_targetNodeID, DHT_ID_LENGTH); } } // namespace aria2