/* */ #include "DHTFindNodeMessage.h" #include #include "DHTNode.h" #include "DHTRoutingTable.h" #include "DHTMessageFactory.h" #include "DHTMessageDispatcher.h" #include "DHTMessageCallback.h" #include "util.h" 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::vector > nodes; getRoutingTable()->getClosestKNodes(nodes, targetNodeID_); SharedHandle reply = getMessageFactory()->createFindNodeReplyMessage (getRemoteNode(), nodes, getTransactionID()); getMessageDispatcher()->addMessageToQueue(reply); } SharedHandle DHTFindNodeMessage::getArgument() { SharedHandle aDict = Dict::g(); aDict->put(DHTMessage::ID, String::g(getLocalNode()->getID(), DHT_ID_LENGTH)); aDict->put(TARGET_NODE, String::g(targetNodeID_, DHT_ID_LENGTH)); return aDict; } const std::string& DHTFindNodeMessage::getMessageType() const { return FIND_NODE; } std::string DHTFindNodeMessage::toStringOptional() const { return "targetNodeID="+util::toHex(targetNodeID_, DHT_ID_LENGTH); } } // namespace aria2