From e4fcf5bdeafb6ad63973620032aee20d4992af94 Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Mon, 6 Nov 2023 14:07:32 +0800 Subject: [PATCH] feat: tarsnode auto set locator when tarsregistry locator changed --- NodeServer/NodeServer.cpp | 109 ++------------------------------------ 1 file changed, 3 insertions(+), 106 deletions(-) diff --git a/NodeServer/NodeServer.cpp b/NodeServer/NodeServer.cpp index 9c9f8ba..b411cef 100644 --- a/NodeServer/NodeServer.cpp +++ b/NodeServer/NodeServer.cpp @@ -283,111 +283,6 @@ string tostr(const set& setStr) return str; } -//string NodeServer::host2Ip(const string& host) -//{ -// struct in_addr stSinAddr; -// TC_Socket::parseAddr(host, stSinAddr); -// -// char ip[INET_ADDRSTRLEN] = "\0"; -// inet_ntop(AF_INET, &stSinAddr, ip, INET_ADDRSTRLEN); -// -// return ip; -//} -// -//bool NodeServer::isValid(const string& ip) -//{ -// static time_t g_tTime = 0; -// static set g_ipSet; -// -// time_t tNow = TNOW; -// -// // TLOG_DEBUG("NodeServer::isValid ip:" << ip << " -> dst:" << dst << endl); -// -// static TC_ThreadLock g_tMutex; -// -// TC_ThreadLock::Lock lock(g_tMutex); -// if (tNow - g_tTime > 60) -// { -// string objs = g_pconf->get("/tars/node", "tars.tarsregistry.AdminRegObj:tars.tarsAdminRegistry.AdminRegObj"); -// string ips = g_pconf->get("/tars/node", ""); -// -// if(!ips.empty()) -// { -// ips += ":"; -// } -// ips += string("127.0.0.1:") + host2Ip(ServerConfig::LocalIp); -// -// TLOG_DEBUG("NodeServer::isValid objs:" << objs << "|ips:" << ips << endl); -// -// vector vObj = TC_Common::sepstr(objs, ":"); -// -// vector vIp = TC_Common::sepstr(ips, ":"); -// for (size_t i = 0; i < vIp.size(); i++) -// { -// g_ipSet.insert(vIp[i]); -// LOG->debug() << ips << ", g_ipSet insert ip:" << vIp[i] << endl; -// } -// -// map context; -// //获取实际ip, 穿透代理, 给TarsCloud云使用 -// context["TARS_REAL"] = "true"; -// -// QueryFPrx queryPrx = AdminProxy::getInstance()->getQueryProxy(); -// -// for (size_t i = 0; i < vObj.size(); i++) -// { -// set tempSet; -// string obj = vObj[i]; -// try -// { -// -// vector vActiveEp, vInactiveEp; -// queryPrx->findObjectById4All(obj, vActiveEp, vInactiveEp, context); -// -// for (unsigned i = 0; i < vActiveEp.size(); i++) -// { -// tempSet.insert(host2Ip(vActiveEp[i].host)); -// } -// -// for (unsigned i = 0; i < vInactiveEp.size(); i++) -// { -// tempSet.insert(host2Ip(vInactiveEp[i].host)); -// } -// -// TLOG_DEBUG("NodeServer::isValid "<< obj << "|tempSet.size():" << tempSet.size() << "|" << tostr(tempSet) << endl); -// } -// catch (exception& e) -// { -// TLOG_ERROR("NodeServer::isValid catch error: " << e.what() << endl); -// } -// catch (...) -// { -// TLOG_ERROR("NodeServer::isValid catch error: " << endl); -// } -// -// if (tempSet.size() > 0) -// { -// g_ipSet.insert(tempSet.begin(), tempSet.end()); -// } -// } -// -// TLOG_DEBUG("NodeServer::isValid g_ipSet.size():" << g_ipSet.size() << "|" << tostr(g_ipSet) << endl); -// g_tTime = tNow; -// } -// -// if (g_ipSet.count(ip) > 0) -// { -// return true; -// } -// -// if (g_sNodeIp == ip || ServerConfig::LocalIp == ip) -// { -// return true; -// } -// -// return false; -//} - void NodeServer::reportServer(const string& sServerId, const string &sSet, const string &sNodeName, const string& sResult) { try @@ -530,9 +425,11 @@ int NodeServer::onUpdateConfig(const string &nodeId, const string &sConfigFile, } string nNewLocator = getQueryEndpoint(); - if(!nNewLocator.empty()) + if(!nNewLocator.empty() && nNewLocator != sLocator) { sLocator = nNewLocator; + CommunicatorFactory::getInstance()->getCommunicator()->setProperty("locator", sLocator); + CommunicatorFactory::getInstance()->getCommunicator()->reloadLocator(); } sTemplate = TC_Common::replace(sTemplate, "${enableset}", config.get("/tars/application/server", "n"));