lichao
2021-05-21 1c92e4cbc85f9501660444cb76ebb06770da9376
reserve #xxx proc id for internal use.
4个文件已修改
23 ■■■■ 已修改文件
box/center_topic_node.cpp 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/topic_node.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/topic_node.h 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utest/api_test.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
box/center_topic_node.cpp
@@ -79,7 +79,7 @@
    ProcInfo info;
    info.set_proc_id("#center.node");
    info.set_name("center node");
    if (!pnode_->Register(info, reply, timeout)) {
    if (!pnode_->UniRegister(true, info, reply, timeout)) {
        throw std::runtime_error("center node register failed.");
    }
@@ -92,7 +92,14 @@
    auto onRequest = [this](void *src_info, std::string &client_proc_id, MsgRequestTopic &request) {
        auto reply = MakeReply<MsgRequestTopicReply>(eSuccess);
        if (request.topic() == kTopicQueryProc) {
            auto data = (*pscenter_)->QueryProc(request.data());
            std::string id;
            if (!request.data().empty()) {
                Json json;
                if (json.parse(request.data())) {
                    id = json.get("proc_id", "");
                }
            }
            auto data = (*pscenter_)->QueryProc(id);
            *reply.mutable_errmsg() = data.errmsg();
            reply.set_data(ToJson(data));
        } else {
src/topic_node.cpp
@@ -143,8 +143,14 @@
    for (auto &p : sockets_) { p->Stop(); }
}
bool TopicNode::Register(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms)
bool TopicNode::UniRegister(const bool internal, ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms)
{
    auto ValidUserProcId = [](const std::string &id) { return !id.empty() && id[0] != '#'; };
    if (!internal && !ValidUserProcId(proc.proc_id())) {
        SetLastError(eInvalidInput, "invalid proc id :'" + proc.proc_id() + "'");
        return false;
    }
    {
        std::lock_guard<std::mutex> lk(mutex_);
        info_ = proc;
src/topic_node.h
@@ -43,7 +43,8 @@
    ~TopicNode();
    // topic node
    bool Register(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms);
    bool Register(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms) { return UniRegister(false, proc, reply_body, timeout_ms); }
    bool UniRegister(const bool internal, ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms);
    bool Unregister(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms);
    bool Heartbeat(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms);
    bool Heartbeat(const int timeout_ms);
utest/api_test.cpp
@@ -206,6 +206,7 @@
        // query procs with normal topic request
        MsgRequestTopic req;
        req.set_topic("@center_query_procs");
        // req.set_data("{\"proc_id\":\"#center.node\"}");
        std::string s(req.SerializeAsString());
        // Sleep(10ms, false);
        std::string dest(BHAddress().SerializeAsString());