2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Made string literal to static const std::string
	* src/DHTAbstractMessage.cc
	* src/DHTAnnouncePeerMessage.cc
	* src/DHTAnnouncePeerMessage.h
	* src/DHTAnnouncePeerReplyMessage.cc
	* src/DHTAnnouncePeerReplyMessage.h
	* src/DHTFindNodeMessage.cc
	* src/DHTFindNodeMessage.h
	* src/DHTFindNodeReplyMessage.cc
	* src/DHTFindNodeReplyMessage.h
	* src/DHTGetPeersMessage.cc
	* src/DHTGetPeersMessage.h
	* src/DHTGetPeersReplyMessage.cc
	* src/DHTGetPeersReplyMessage.h
	* src/DHTMessage.cc
	* src/DHTMessage.h
	* src/DHTMessageFactoryImpl.cc
	* src/DHTMessageReceiver.cc
	* src/DHTPingMessage.cc
	* src/DHTPingMessage.h
	* src/DHTPingReplyMessage.cc
	* src/DHTPingReplyMessage.h
	* src/DHTQueryMessage.cc
	* src/DHTQueryMessage.h
	* src/DHTResponseMessage.cc
	* src/DHTResponseMessage.h
	* src/DHTUnknownMessage.cc
	* src/DHTUnknownMessage.h
pull/1/head
Tatsuhiro Tsujikawa 2008-05-13 15:55:05 +00:00
parent 5c8db1cc20
commit 898b807ba2
28 changed files with 207 additions and 71 deletions

View File

@ -1,3 +1,34 @@
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made string literal to static const std::string
* src/DHTAbstractMessage.cc
* src/DHTAnnouncePeerMessage.cc
* src/DHTAnnouncePeerMessage.h
* src/DHTAnnouncePeerReplyMessage.cc
* src/DHTAnnouncePeerReplyMessage.h
* src/DHTFindNodeMessage.cc
* src/DHTFindNodeMessage.h
* src/DHTFindNodeReplyMessage.cc
* src/DHTFindNodeReplyMessage.h
* src/DHTGetPeersMessage.cc
* src/DHTGetPeersMessage.h
* src/DHTGetPeersReplyMessage.cc
* src/DHTGetPeersReplyMessage.h
* src/DHTMessage.cc
* src/DHTMessage.h
* src/DHTMessageFactoryImpl.cc
* src/DHTMessageReceiver.cc
* src/DHTPingMessage.cc
* src/DHTPingMessage.h
* src/DHTPingReplyMessage.cc
* src/DHTPingReplyMessage.h
* src/DHTQueryMessage.cc
* src/DHTQueryMessage.h
* src/DHTResponseMessage.cc
* src/DHTResponseMessage.h
* src/DHTUnknownMessage.cc
* src/DHTUnknownMessage.h
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made string literal to static const std::string

View File

@ -55,8 +55,8 @@ DHTAbstractMessage::~DHTAbstractMessage() {}
std::string DHTAbstractMessage::getBencodedMessage()
{
SharedHandle<Dictionary> msg(new Dictionary());
msg->put(std::string("t"), new Data(_transactionID));
msg->put(std::string("y"), new Data(getType()));
msg->put(DHTMessage::T, new Data(_transactionID));
msg->put(DHTMessage::Y, new Data(getType()));
fillMessage(msg.get());
BencodeVisitor v;

View File

@ -50,6 +50,14 @@
namespace aria2 {
const std::string DHTAnnouncePeerMessage::ANNOUNCE_PEER("announce_peer");
const std::string DHTAnnouncePeerMessage::INFO_HASH("info_hash");
const std::string DHTAnnouncePeerMessage::PORT("port");
const std::string DHTAnnouncePeerMessage::TOKEN("token");
DHTAnnouncePeerMessage::DHTAnnouncePeerMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
@ -78,19 +86,19 @@ void DHTAnnouncePeerMessage::doReceivedAction()
Dictionary* DHTAnnouncePeerMessage::getArgument()
{
Dictionary* a = new Dictionary();
a->put("id", new Data(reinterpret_cast<const char*>(_localNode->getID()),
a->put(DHTMessage::ID, new Data(reinterpret_cast<const char*>(_localNode->getID()),
DHT_ID_LENGTH));
a->put("info_hash", new Data(reinterpret_cast<const char*>(_infoHash),
a->put(INFO_HASH, new Data(reinterpret_cast<const char*>(_infoHash),
DHT_ID_LENGTH));
a->put("port", new Data(Util::uitos(_tcpPort), true));
a->put("token", new Data(_token));
a->put(PORT, new Data(Util::uitos(_tcpPort), true));
a->put(TOKEN, new Data(_token));
return a;
}
std::string DHTAnnouncePeerMessage::getMessageType() const
{
return "announce_peer";
return ANNOUNCE_PEER;
}
void DHTAnnouncePeerMessage::validate() const

View File

@ -93,6 +93,14 @@ public:
void setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
static const std::string ANNOUNCE_PEER;
static const std::string INFO_HASH;
static const std::string PORT;
static const std::string TOKEN;
};
} // namespace aria2

View File

@ -39,6 +39,8 @@
namespace aria2 {
const std::string DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER("announce_peer");
DHTAnnouncePeerReplyMessage::DHTAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -51,13 +53,13 @@ void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
Dictionary* DHTAnnouncePeerReplyMessage::getResponse()
{
Dictionary* r = new Dictionary();
r->put("id", new Data(_localNode->getID(), DHT_ID_LENGTH));
r->put(DHTMessage::ID, new Data(_localNode->getID(), DHT_ID_LENGTH));
return r;
}
std::string DHTAnnouncePeerReplyMessage::getMessageType() const
{
return "announce_peer";
return ANNOUNCE_PEER;
}
void DHTAnnouncePeerReplyMessage::validate() const {}

View File

@ -54,6 +54,8 @@ public:
virtual std::string getMessageType() const;
virtual void validate() const;
static const std::string ANNOUNCE_PEER;
};
} // namespace aria2

View File

@ -45,6 +45,10 @@
namespace aria2 {
const std::string DHTFindNodeMessage::FIND_NODE("find_node");
const std::string DHTFindNodeMessage::TARGET_NODE("target");
DHTFindNodeMessage::DHTFindNodeMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
@ -68,16 +72,16 @@ void DHTFindNodeMessage::doReceivedAction()
Dictionary* DHTFindNodeMessage::getArgument()
{
Dictionary* a = new Dictionary();
a->put("id", new Data(reinterpret_cast<const char*>(_localNode->getID()),
a->put(DHTMessage::ID, new Data(reinterpret_cast<const char*>(_localNode->getID()),
DHT_ID_LENGTH));
a->put("target", new Data(reinterpret_cast<const char*>(_targetNodeID),
a->put(TARGET_NODE, new Data(reinterpret_cast<const char*>(_targetNodeID),
DHT_ID_LENGTH));
return a;
}
std::string DHTFindNodeMessage::getMessageType() const
{
return "find_node";
return FIND_NODE;
}
void DHTFindNodeMessage::validate() const {}

View File

@ -65,6 +65,11 @@ public:
{
return _targetNodeID;
}
static const std::string FIND_NODE;
// We want "TARGET", but it is defined by macro.
static const std::string TARGET_NODE;
};
} // namespace aria2

View File

@ -47,6 +47,10 @@
namespace aria2 {
const std::string DHTFindNodeReplyMessage::FIND_NODE("find_node");
const std::string DHTFindNodeReplyMessage::NODES("nodes");
DHTFindNodeReplyMessage::DHTFindNodeReplyMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -66,7 +70,7 @@ void DHTFindNodeReplyMessage::doReceivedAction()
Dictionary* DHTFindNodeReplyMessage::getResponse()
{
Dictionary* a = new Dictionary();
a->put("id", new Data(_localNode->getID(), DHT_ID_LENGTH));
a->put(DHTMessage::ID, new Data(_localNode->getID(), DHT_ID_LENGTH));
size_t offset = 0;
unsigned char buffer[DHTBucket::K*26];
// TODO if _closestKNodes.size() > DHTBucket::K ??
@ -77,13 +81,13 @@ Dictionary* DHTFindNodeReplyMessage::getResponse()
offset += 26;
}
}
a->put("nodes", new Data(buffer, offset));
a->put(NODES, new Data(buffer, offset));
return a;
}
std::string DHTFindNodeReplyMessage::getMessageType() const
{
return "find_node";
return FIND_NODE;
}
void DHTFindNodeReplyMessage::validate() const {}

View File

@ -63,6 +63,10 @@ public:
const std::deque<SharedHandle<DHTNode> >& getClosestKNodes() const;
void setClosestKNodes(const std::deque<SharedHandle<DHTNode> >& closestKNodes);
static const std::string FIND_NODE;
static const std::string NODES;
};
} // namespace aria2

View File

@ -49,6 +49,10 @@
namespace aria2 {
const std::string DHTGetPeersMessage::GET_PEERS("get_peers");
const std::string DHTGetPeersMessage::INFO_HASH("info_hash");
DHTGetPeersMessage::DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
@ -86,14 +90,14 @@ void DHTGetPeersMessage::doReceivedAction()
Dictionary* DHTGetPeersMessage::getArgument()
{
Dictionary* a = new Dictionary();
a->put("id", new Data(_localNode->getID(), DHT_ID_LENGTH));
a->put("info_hash", new Data(_infoHash, DHT_ID_LENGTH));
a->put(DHTMessage::ID, new Data(_localNode->getID(), DHT_ID_LENGTH));
a->put(INFO_HASH, new Data(_infoHash, DHT_ID_LENGTH));
return a;
}
std::string DHTGetPeersMessage::getMessageType() const
{
return "get_peers";
return GET_PEERS;
}
void DHTGetPeersMessage::validate() const {}

View File

@ -78,6 +78,11 @@ public:
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
static const std::string GET_PEERS;
static const std::string INFO_HASH;
};
} // namespace aria2

View File

@ -50,6 +50,14 @@
namespace aria2 {
const std::string DHTGetPeersReplyMessage::GET_PEERS("get_peers");
const std::string DHTGetPeersReplyMessage::TOKEN("token");
const std::string DHTGetPeersReplyMessage::VALUES("values");
const std::string DHTGetPeersReplyMessage::NODES("nodes");
DHTGetPeersReplyMessage::DHTGetPeersReplyMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& token,
@ -67,11 +75,11 @@ void DHTGetPeersReplyMessage::doReceivedAction()
Dictionary* DHTGetPeersReplyMessage::getResponse()
{
Dictionary* r = new Dictionary();
r->put("id", new Data(_localNode->getID(), DHT_ID_LENGTH));
r->put("token", new Data(_token));
r->put(DHTMessage::ID, new Data(_localNode->getID(), DHT_ID_LENGTH));
r->put(TOKEN, new Data(_token));
if(_values.size()) {
List* valuesList = new List();
r->put("values", valuesList);
r->put(VALUES, valuesList);
for(std::deque<SharedHandle<Peer> >::const_iterator i = _values.begin(); i != _values.end(); ++i) {
const SharedHandle<Peer>& peer = *i;
unsigned char buffer[6];
@ -89,14 +97,14 @@ Dictionary* DHTGetPeersReplyMessage::getResponse()
offset += 26;
}
}
r->put("nodes", new Data(buffer, offset));
r->put(NODES, new Data(buffer, offset));
}
return r;
}
std::string DHTGetPeersReplyMessage::getMessageType() const
{
return "get_peers";
return GET_PEERS;
}
void DHTGetPeersReplyMessage::validate() const {}

View File

@ -80,6 +80,14 @@ public:
{
return _token;
}
static const std::string GET_PEERS;
static const std::string TOKEN;
static const std::string VALUES;
static const std::string NODES;
};
} // namespace aria2

View File

@ -38,6 +38,12 @@
namespace aria2 {
const std::string DHTMessage::Y("y");
const std::string DHTMessage::T("t");
const std::string DHTMessage::ID("id");
DHTMessage::DHTMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -67,5 +73,4 @@ SharedHandle<DHTNode> DHTMessage::getRemoteNode() const
return _remoteNode;
}
} // namespace aria2

View File

@ -80,6 +80,12 @@ public:
virtual std::string getMessageType() const = 0;
virtual std::string toString() const = 0;
static const std::string Y;
static const std::string T;
static const std::string ID;
};
} // namespace aria2

View File

@ -160,36 +160,36 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createQueryMessage(const Diction
const std::string& ipaddr,
uint16_t port)
{
const Data* q = getData(d, "q");
const Data* t = getData(d, "t");
const Data* y = getData(d, "y");
const Dictionary* a = getDictionary(d, "a");
if(y->toString() != "q") {
const Data* q = getData(d, DHTQueryMessage::Q);
const Data* t = getData(d, DHTMessage::T);
const Data* y = getData(d, DHTMessage::Y);
const Dictionary* a = getDictionary(d, DHTQueryMessage::A);
if(y->toString() != DHTQueryMessage::Q) {
throw DlAbortEx("Malformed DHT message. y != q");
}
const Data* id = getData(getDictionary(d, "a"), "id");
const Data* id = getData(getDictionary(d, DHTQueryMessage::A), DHTMessage::ID);
validateID(id);
SharedHandle<DHTNode> remoteNode = getRemoteNode(id->getData(), ipaddr, port);
std::string messageType = q->toString();
std::string transactionID = t->toString();
if(messageType == "ping") {
if(messageType == DHTPingMessage::PING) {
return createPingMessage(remoteNode, transactionID);
} else if(messageType == "find_node") {
const Data* targetNodeID = getData(a, "target");
} else if(messageType == DHTFindNodeMessage::FIND_NODE) {
const Data* targetNodeID = getData(a, DHTFindNodeMessage::TARGET_NODE);
validateID(targetNodeID);
return createFindNodeMessage(remoteNode, targetNodeID->getData(),
transactionID);
} else if(messageType == "get_peers") {
const Data* infoHash = getData(a, "info_hash");
} else if(messageType == DHTGetPeersMessage::GET_PEERS) {
const Data* infoHash = getData(a, DHTGetPeersMessage::INFO_HASH);
validateID(infoHash);
return createGetPeersMessage(remoteNode,
infoHash->getData(), transactionID);
} else if(messageType == "announce_peer") {
const Data* infoHash = getData(a, "info_hash");
} else if(messageType == DHTAnnouncePeerMessage::ANNOUNCE_PEER) {
const Data* infoHash = getData(a, DHTAnnouncePeerMessage::INFO_HASH);
validateID(infoHash);
const Data* port = getData(a, "port");
const Data* port = getData(a, DHTAnnouncePeerMessage::PORT);
validatePort(port);
const Data* token = getData(a, "token");
const Data* token = getData(a, DHTAnnouncePeerMessage::TOKEN);
return createAnnouncePeerMessage(remoteNode, infoHash->getData(),
static_cast<uint16_t>(port->toInt()),
token->toString(), transactionID);
@ -204,11 +204,11 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
const Dictionary* d,
const SharedHandle<DHTNode>& remoteNode)
{
const Data* t = getData(d, "t");
const Data* y = getData(d, "y");
if(y->toString() == "e") {
const Data* t = getData(d, DHTMessage::T);
const Data* y = getData(d, DHTMessage::Y);
if(y->toString() == DHTUnknownMessage::E) {
// for now, just report error message arrived and throw exception.
const List* e = getList(d, "e");
const List* e = getList(d, DHTUnknownMessage::E);
if(e->getList().size() == 2) {
_logger->info("Received Error DHT message. code=%s, msg=%s",
Util::urlencode(getData(e, 0)->toString()).c_str(),
@ -217,34 +217,35 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
_logger->debug("e doesn't have 2 elements.");
}
throw DlAbortEx("Received Error DHT message.");
} else if(y->toString() != "r") {
} else if(y->toString() != DHTResponseMessage::R) {
throw DlAbortEx
(StringFormat("Malformed DHT message. y != r: y=%s",
Util::urlencode(y->toString()).c_str()).str());
}
const Dictionary* r = getDictionary(d, "r");
const Data* id = getData(r, "id");
const Dictionary* r = getDictionary(d, DHTResponseMessage::R);
const Data* id = getData(r, DHTMessage::ID);
validateID(id);
validateIDMatch(remoteNode->getID(), id->getData());
std::string transactionID = t->toString();
if(messageType == "ping") {
if(messageType == DHTPingReplyMessage::PING) {
return createPingReplyMessage(remoteNode,
id->getData(), transactionID);
} else if(messageType == "find_node") {
} else if(messageType == DHTFindNodeReplyMessage::FIND_NODE) {
return createFindNodeReplyMessage(remoteNode, d, transactionID);
} else if(messageType == "get_peers") {
const List* values = dynamic_cast<const List*>(r->get("values"));
} else if(messageType == DHTGetPeersReplyMessage::GET_PEERS) {
const List* values =
dynamic_cast<const List*>(r->get(DHTGetPeersReplyMessage::VALUES));
if(values) {
return createGetPeersReplyMessageWithValues(remoteNode, d, transactionID);
} else {
const Data* nodes = dynamic_cast<const Data*>(r->get("nodes"));
const Data* nodes = dynamic_cast<const Data*>(r->get(DHTGetPeersReplyMessage::NODES));
if(nodes) {
return createGetPeersReplyMessageWithNodes(remoteNode, d, transactionID);
} else {
throw DlAbortEx("Malformed DHT message: missing nodes/values");
}
}
} else if(messageType == "announce_peer") {
} else if(messageType == DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER) {
return createAnnouncePeerReplyMessage(remoteNode, transactionID);
} else {
throw DlAbortEx
@ -325,7 +326,7 @@ DHTMessageFactoryImpl::createFindNodeReplyMessage(const SharedHandle<DHTNode>& r
const Dictionary* d,
const std::string& transactionID)
{
const Data* nodesData = getData(getDictionary(d, "r"), "nodes");
const Data* nodesData = getData(getDictionary(d, DHTResponseMessage::R), DHTFindNodeReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData->getData(), nodesData->getLen());
return createFindNodeReplyMessage(remoteNode, nodes, transactionID);
}
@ -350,10 +351,10 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithNodes(const SharedHandle<DH
const Dictionary* d,
const std::string& transactionID)
{
const Dictionary* r = getDictionary(d, "r");
const Data* nodesData = getData(r, "nodes");
const Dictionary* r = getDictionary(d, DHTResponseMessage::R);
const Data* nodesData = getData(r, DHTGetPeersReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData->getData(), nodesData->getLen());
const Data* token = getData(r, "token");
const Data* token = getData(r, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, nodes, token->toString(),
transactionID);
}
@ -376,8 +377,8 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues(const SharedHandle<D
const Dictionary* d,
const std::string& transactionID)
{
const Dictionary* r = getDictionary(d, "r");
const List* valuesList = getList(r, "values");
const Dictionary* r = getDictionary(d, DHTResponseMessage::R);
const List* valuesList = getList(r, DHTGetPeersReplyMessage::VALUES);
std::deque<SharedHandle<Peer> > peers;
for(std::deque<MetaEntry*>::const_iterator i = valuesList->getList().begin(); i != valuesList->getList().end(); ++i) {
const Data* data = dynamic_cast<const Data*>(*i);
@ -387,7 +388,7 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues(const SharedHandle<D
peers.push_back(peer);
}
}
const Data* token = getData(r, "token");
const Data* token = getData(r, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, peers, token->toString(),
transactionID);
}

View File

@ -36,6 +36,8 @@
#include "DHTMessageTracker.h"
#include "DHTConnection.h"
#include "DHTMessage.h"
#include "DHTResponseMessage.h"
#include "DHTUnknownMessage.h"
#include "DHTMessageFactory.h"
#include "DHTRoutingTable.h"
#include "DHTNode.h"
@ -74,9 +76,10 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
MetaEntryHandle msgroot(MetaFileUtil::bdecoding(data, length));
const Dictionary* d = dynamic_cast<const Dictionary*>(msgroot.get());
if(d) {
const Data* y = dynamic_cast<const Data*>(d->get("y"));
const Data* y = dynamic_cast<const Data*>(d->get(DHTMessage::Y));
if(y) {
if(y->toString() == "r" || y->toString() == "e") {
if(y->toString() == DHTResponseMessage::R ||
y->toString() == DHTUnknownMessage::E) {
isReply = true;
}
} else {

View File

@ -43,6 +43,8 @@
namespace aria2 {
const std::string DHTPingMessage::PING("ping");
DHTPingMessage::DHTPingMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -60,14 +62,14 @@ void DHTPingMessage::doReceivedAction()
Dictionary* DHTPingMessage::getArgument()
{
Dictionary* a = new Dictionary();
a->put("id", new Data(reinterpret_cast<const char*>(_localNode->getID()),
a->put(DHTMessage::ID, new Data(reinterpret_cast<const char*>(_localNode->getID()),
DHT_ID_LENGTH));
return a;
}
std::string DHTPingMessage::getMessageType() const
{
return "ping";
return PING;
}
void DHTPingMessage::validate() const {}

View File

@ -55,6 +55,8 @@ public:
virtual std::string getMessageType() const;
virtual void validate() const;
static const std::string PING;
};
} // namespace aria2

View File

@ -40,6 +40,8 @@
namespace aria2 {
const std::string DHTPingReplyMessage::PING("ping");
DHTPingReplyMessage::DHTPingReplyMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const unsigned char* id,
@ -56,13 +58,13 @@ void DHTPingReplyMessage::doReceivedAction() {}
Dictionary* DHTPingReplyMessage::getResponse()
{
Dictionary* r = new Dictionary();
r->put("id", new Data(_id, DHT_ID_LENGTH));
r->put(DHTMessage::ID, new Data(_id, DHT_ID_LENGTH));
return r;
}
std::string DHTPingReplyMessage::getMessageType() const
{
return "ping";
return PING;
}
void DHTPingReplyMessage::validate() const {}

View File

@ -63,6 +63,8 @@ public:
{
return _id;
}
static const std::string PING;
};
} // namespace aria2

View File

@ -40,6 +40,10 @@
namespace aria2 {
const std::string DHTQueryMessage::Q("q");
const std::string DHTQueryMessage::A("a");
DHTQueryMessage::DHTQueryMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -49,13 +53,13 @@ DHTQueryMessage::~DHTQueryMessage() {}
std::string DHTQueryMessage::getType() const
{
return "q";
return Q;
}
void DHTQueryMessage::fillMessage(Dictionary* message)
{
message->put("q", new Data(getMessageType()));
message->put("a", getArgument());
message->put(Q, new Data(getMessageType()));
message->put(A, getArgument());
}
bool DHTQueryMessage::isReply() const

View File

@ -59,6 +59,10 @@ public:
virtual bool isReply() const;
virtual std::string toString() const;
static const std::string Q;
static const std::string A;
};
} // namespace aria2

View File

@ -40,6 +40,8 @@
namespace aria2 {
const std::string DHTResponseMessage::R("r");
DHTResponseMessage::DHTResponseMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID):
@ -49,12 +51,12 @@ DHTResponseMessage::~DHTResponseMessage() {}
std::string DHTResponseMessage::getType() const
{
return "r";
return R;
}
void DHTResponseMessage::fillMessage(Dictionary* message)
{
message->put("r", getResponse());
message->put(R, getResponse());
}
bool DHTResponseMessage::isReply() const

View File

@ -59,6 +59,8 @@ public:
virtual bool isReply() const;
virtual std::string toString() const;
static const std::string R;
};
} // namespace aria2

View File

@ -39,6 +39,10 @@
namespace aria2 {
const std::string DHTUnknownMessage::E("e");
const std::string DHTUnknownMessage::UNKNOWN("unknown");
DHTUnknownMessage::DHTUnknownMessage(const SharedHandle<DHTNode>& localNode,
const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port):
@ -73,7 +77,7 @@ void DHTUnknownMessage::validate() const {}
std::string DHTUnknownMessage::getMessageType() const
{
return "unknown";
return UNKNOWN;
}
std::string DHTUnknownMessage::toString() const

View File

@ -69,6 +69,10 @@ public:
// show some sample bytes
virtual std::string toString() const;
static const std::string E;
static const std::string UNKNOWN;
};
} // namespace aria2