From 0e31f38fc37216e1376d8101d1bcf7a3779279dc Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 20 五月 2021 15:29:16 +0800 Subject: [PATCH] add center topic node. --- box/node_center.cpp | 68 ++++++++++++++++++---------------- 1 files changed, 36 insertions(+), 32 deletions(-) diff --git a/box/node_center.cpp b/box/node_center.cpp index b970d44..cefb138 100644 --- a/box/node_center.cpp +++ b/box/node_center.cpp @@ -350,44 +350,48 @@ return MakeReply(eSuccess); }); } -MsgQueryProcReply NodeCenter::QueryProc(const BHMsgHead &head, const MsgQueryProc &req) + +MsgQueryProcReply NodeCenter::QueryProc(const std::string &proc_id) { typedef MsgQueryProcReply Reply; - auto query = [&](Node self) -> Reply { - auto Add1 = [](Reply &reply, Node node) { - auto info = reply.add_proc_list(); - *info->mutable_proc() = node->proc_; - info->set_online(node->state_.flag_ == kStateNormal); - for (auto &addr_topics : node->services_) { - for (auto &topic : addr_topics.second) { - info->mutable_topics()->add_topic_list(topic); - } + auto Add1 = [](Reply &reply, Node node) { + auto info = reply.add_proc_list(); + *info->mutable_proc() = node->proc_; + info->mutable_proc()->clear_private_info(); + info->set_online(node->state_.flag_ == kStateNormal); + for (auto &addr_topics : node->services_) { + for (auto &topic : addr_topics.second) { + info->mutable_topics()->add_topic_list(topic); } - }; - - if (!req.proc_id().empty()) { - auto pos = online_node_addr_map_.find(req.proc_id()); - if (pos == online_node_addr_map_.end()) { - return MakeReply<Reply>(eNotFound, "proc not found."); - } else { - auto node_pos = nodes_.find(pos->second); - if (node_pos == nodes_.end()) { - return MakeReply<Reply>(eNotFound, "proc node not found."); - } else { - auto reply = MakeReply<Reply>(eSuccess); - Add1(reply, node_pos->second); - return reply; - } - } - } else { - Reply reply(MakeReply<Reply>(eSuccess)); - for (auto &kv : nodes_) { - Add1(reply, kv.second); - } - return reply; } }; + if (!proc_id.empty()) { + auto pos = online_node_addr_map_.find(proc_id); + if (pos == online_node_addr_map_.end()) { + return MakeReply<Reply>(eNotFound, "proc not found."); + } else { + auto node_pos = nodes_.find(pos->second); + if (node_pos == nodes_.end()) { + return MakeReply<Reply>(eNotFound, "proc node not found."); + } else { + auto reply = MakeReply<Reply>(eSuccess); + Add1(reply, node_pos->second); + return reply; + } + } + } else { + Reply reply(MakeReply<Reply>(eSuccess)); + for (auto &kv : nodes_) { + Add1(reply, kv.second); + } + return reply; + } +} +MsgQueryProcReply NodeCenter::QueryProc(const BHMsgHead &head, const MsgQueryProc &req) +{ + typedef MsgQueryProcReply Reply; + auto query = [&](Node self) -> Reply { return this->QueryProc(req.proc_id()); }; return HandleMsg<Reply>(head, query); } -- Gitblit v1.8.0