summaryrefslogtreecommitdiff
path: root/src/DHTMessageFactoryImpl.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-11 06:23:01 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-11 06:23:01 +0000
commit413cbe192b842c23759c9b31088b34e88ce96ed2 (patch)
tree21987616a5e43642d71bbb626f4ba4d7f9cb298c /src/DHTMessageFactoryImpl.cc
parent34e6a1dc9af8c2716bf5ffb6ea04c5fcc0a78844 (diff)
2008-02-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Adding handling of DHT error message. Just log error message and throw exception. * src/DHTMessageFactoryImpl.cc * test/DHTMessageFactoryImplTest.cc
Diffstat (limited to 'src/DHTMessageFactoryImpl.cc')
-rw-r--r--src/DHTMessageFactoryImpl.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc
index 6d5552d3..8eb55071 100644
--- a/src/DHTMessageFactoryImpl.cc
+++ b/src/DHTMessageFactoryImpl.cc
@@ -57,6 +57,7 @@
#include "BtRuntime.h"
#include "Util.h"
#include "Peer.h"
+#include "Logger.h"
#include <cstring>
#include <utility>
@@ -99,6 +100,17 @@ static const Data* getData(const Dictionary* d, const std::string& key)
}
}
+static const Data* getData(const List* l, size_t index)
+{
+ const Data* c = dynamic_cast<const Data*>(l->getList()[index]);
+ if(c) {
+ return c;
+ } else {
+ throw new DlAbortEx("Malformed DHT message. element[%u] is not Data.",
+ index);
+ }
+}
+
static const List* getList(const Dictionary* d, const std::string& key)
{
const List* l = dynamic_cast<const List*>(d->get(key));
@@ -187,12 +199,22 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createResponseMessage(const std:
{
const Data* t = getData(d, "t");
const Data* y = getData(d, "y");
- const Dictionary* r = getDictionary(d, "r");
- // TODO handle y == "e" case
- if(y->toString() != "r") {
+ if(y->toString() == "e") {
+ // for now, just report error message arrived and throw exception.
+ const List* e = getList(d, "e");
+ if(e->getList().size() == 2) {
+ _logger->info("Received Error DHT message. code=%s, msg=%s",
+ Util::urlencode(getData(e, 0)->toString()).c_str(),
+ Util::urlencode(getData(e, 1)->toString()).c_str());
+ } else {
+ _logger->debug("e doesn't have 2 elements.");
+ }
+ throw new DlAbortEx("Received Error DHT message.");
+ } else if(y->toString() != "r") {
throw new DlAbortEx("Malformed DHT message. y != r: y=%s",
Util::urlencode(y->toString()).c_str());
}
+ const Dictionary* r = getDictionary(d, "r");
const Data* id = getData(r, "id");
validateID(id);
validateIDMatch(remoteNode->getID(),