From fcaaa01b2d40011df650cd092cb841e825c4e49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Mon, 30 Oct 2017 12:47:46 -0400 Subject: [PATCH] network engine: add "value update" message type --- src/net.h | 3 ++- src/network_engine.cpp | 11 ++++++++++- src/parsed_message.h | 7 +++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/net.h b/src/net.h index b47eeb25..0aa9dda9 100644 --- a/src/net.h +++ b/src/net.h @@ -30,7 +30,8 @@ enum class MessageType { AnnounceValue, Refresh, Listen, - ValueData + ValueData, + ValueUpdate }; } /* namespace net */ diff --git a/src/network_engine.cpp b/src/network_engine.cpp index fa198730..cab07ec1 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -410,7 +410,16 @@ NetworkEngine::process(std::unique_ptr&& msg, const SockAddr& fro const auto& now = scheduler.time(); auto node = cache.getNode(msg->id, from, now, true, msg->is_client); - if (msg->type == MessageType::Error or msg->type == MessageType::Reply) { + if (msg->type == MessageType::ValueUpdate) { + auto rsocket = node->getSocket(msg->tid); + if (not rsocket) + throw DhtProtocolException {DhtProtocolException::UNKNOWN_TID, "Can't find socket", msg->id}; + node->received(now, {}); + onNewNode(node, 2); + deserializeNodes(*msg, from); + rsocket->on_receive(node, std::move(*msg)); + } + else if (msg->type == MessageType::Error or msg->type == MessageType::Reply) { auto rsocket = node->getSocket(msg->tid); auto req = node->getRequest(msg->tid); diff --git a/src/parsed_message.h b/src/parsed_message.h index f30f27b2..c4ac56cf 100644 --- a/src/parsed_message.h +++ b/src/parsed_message.h @@ -125,6 +125,7 @@ ParsedMessage::msgpack_unpack(msgpack::object msg) { auto y = findMapValue(msg, "y"); auto r = findMapValue(msg, "r"); + auto u = findMapValue(msg, "u"); auto e = findMapValue(msg, "e"); auto v = findMapValue(msg, "p"); @@ -153,6 +154,8 @@ ParsedMessage::msgpack_unpack(msgpack::object msg) type = MessageType::Reply; else if (v) type = MessageType::ValueData; + else if (u) + type = MessageType::ValueUpdate; else if (y and y->as() != "q") throw msgpack::type_error(); else if (q == "ping") @@ -185,9 +188,9 @@ ParsedMessage::msgpack_unpack(msgpack::object msg) } auto a = findMapValue(msg, "a"); - if (!a && !r && !e) + if (!a && !r && !e && !u) throw msgpack::type_error(); - auto& req = a ? *a : (r ? *r : *e); + auto& req = a ? *a : (r ? *r : (u ? *u : *e)); if (e) { if (e->type != msgpack::type::ARRAY)