/* */ #include "DHTAbstractMessage.h" #include #include "DHTNode.h" #include "DHTConnection.h" #include "DHTMessageDispatcher.h" #include "DHTMessageFactory.h" #include "DHTRoutingTable.h" #include "DHTMessageCallback.h" #include "bencode2.h" namespace aria2 { DHTAbstractMessage::DHTAbstractMessage(const SharedHandle& localNode, const SharedHandle& remoteNode, const std::string& transactionID): DHTMessage(localNode, remoteNode, transactionID), connection_(0), dispatcher_(0), factory_(0), routingTable_(0) {} DHTAbstractMessage::~DHTAbstractMessage() {} std::string DHTAbstractMessage::getBencodedMessage() { Dict msgDict; msgDict.put(T, getTransactionID()); msgDict.put(Y, getType()); msgDict.put(V, getVersion()); fillMessage(&msgDict); return bencode2::encode(&msgDict); } bool DHTAbstractMessage::send() { std::string message = getBencodedMessage(); ssize_t r = connection_->sendMessage (reinterpret_cast(message.c_str()), message.size(), getRemoteNode()->getIPAddress(), getRemoteNode()->getPort()); assert(r >= 0); return r == static_cast(message.size()); } void DHTAbstractMessage::setConnection(DHTConnection* connection) { connection_ = connection; } void DHTAbstractMessage::setMessageDispatcher(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } void DHTAbstractMessage::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } void DHTAbstractMessage::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } } // namespace aria2