From ce2e36f431c60723c3d7f64bb323cd440c09796f Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 28 Apr 2025 17:00:36 +0800 Subject: [PATCH] =?UTF-8?q?2.4|=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/spd_logger_cfg.json | 8 ++++++++ src/configs/version.hpp | 2 +- src/service/extapi_service.cpp | 21 +++++++++++++++++---- src/service/wbesocket_connect_mgr_service.cpp | 2 +- src/service/wbesocket_connect_mgr_service.hpp | 15 ++++++++++++++- tools/deply.sh | 2 ++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/resources/spd_logger_cfg.json b/resources/spd_logger_cfg.json index 1d1ca4a..a3df2cf 100644 --- a/resources/spd_logger_cfg.json +++ b/resources/spd_logger_cfg.json @@ -20,6 +20,14 @@ "type": "stdout_color_sink_mt" }, { + "name": "ZCanReceiverHost", + "level": 0 + }, + { + "name": "ExtAPIService", + "level": 0 + }, + { "name": "root", "type": "logger", "level": 2, diff --git a/src/configs/version.hpp b/src/configs/version.hpp index 28d3f8e..5e6344d 100644 --- a/src/configs/version.hpp +++ b/src/configs/version.hpp @@ -1,2 +1,2 @@ #pragma once -#define VERSION "2.3" \ No newline at end of file +#define VERSION "2.4" \ No newline at end of file diff --git a/src/service/extapi_service.cpp b/src/service/extapi_service.cpp index 18dd10d..e651bab 100644 --- a/src/service/extapi_service.cpp +++ b/src/service/extapi_service.cpp @@ -119,8 +119,17 @@ void ExtAPIService::initialize() { logger->info("\t{}: {}", it.first, it.second); } - string chname = webSocket.getUrl().substr(1); - WbesocketConnectMgrService::insertNewClient(chname, findws(&webSocket), make_shared(connectionState->getRemoteIp())); + string chname = webSocket.getUrl().substr(1); + static int id; + + auto cinfo = make_shared( // + msg->openInfo.uri, // url + connectionState->getRemoteIp(), // ip + chname, // chanme + fmt::format("{}{}({})", chname, id++, connectionState->getRemoteIp()) // + ); + + WbesocketConnectMgrService::insertNewClient(chname, findws(&webSocket), cinfo); } else if (msg->type == ix::WebSocketMessageType::Message) { string chname = webSocket.getUrl().substr(1); auto channel = DataChannelMgr::findByChannel(chname); @@ -143,6 +152,8 @@ void ExtAPIService::initialize() { WbesocketConnectMgrService::findClientByName(fromch->getAlias(), clients); for (auto ch : clients) { if (ch) { + shared_ptr cinfo = WbesocketConnectMgrService::findwsinfo(ch); + WebSocketSendInfo sendInfo; if (binary) { sendInfo = ch->sendBinary(string(data, len)); @@ -150,8 +161,10 @@ void ExtAPIService::initialize() { sendInfo = ch->sendText(string(data, len)); } - if (!sendInfo.success) { - logger->error("send data to client {} failed", (int64_t)ch.get()); + if (sendInfo.success) { + logger->debug("send data to client {} {} success", cinfo->getConnUniqueId(), binary ? StringUtils().bytesToString(data, len) : string(data, len)); + } else { + logger->error("send data to client {} failed", cinfo->getConnUniqueId()); } } } diff --git a/src/service/wbesocket_connect_mgr_service.cpp b/src/service/wbesocket_connect_mgr_service.cpp index 1343bcf..cf8f766 100644 --- a/src/service/wbesocket_connect_mgr_service.cpp +++ b/src/service/wbesocket_connect_mgr_service.cpp @@ -11,7 +11,7 @@ static map>> wsClients; static map> wsClientsInfo; static std::mutex wsClientsLock; -shared_ptr findwsinfo(shared_ptr client) { +shared_ptr WbesocketConnectMgrService::findwsinfo(shared_ptr client) { if (client == nullptr) return nullptr; auto it = wsClientsInfo.find((void *)client.get()); if (it == wsClientsInfo.end()) return nullptr; diff --git a/src/service/wbesocket_connect_mgr_service.hpp b/src/service/wbesocket_connect_mgr_service.hpp index f4e52dc..eec74fc 100644 --- a/src/service/wbesocket_connect_mgr_service.hpp +++ b/src/service/wbesocket_connect_mgr_service.hpp @@ -31,12 +31,23 @@ using namespace nlohmann; using namespace ix; class WebSocketConnectInfo { + string url; string remoteIp; + string chname; + string connUniqueId; public: WebSocketConnectInfo() {} - WebSocketConnectInfo(string ip) : remoteIp(ip) {} + WebSocketConnectInfo(string url, string remoteIp, string chname, string connUniqueId) { + this->url = url; + this->remoteIp = remoteIp; + this->chname = chname; + this->connUniqueId = connUniqueId; + } string getRemoteIp() { return remoteIp; } + string getUrl() { return url; } + string getChannelName() { return chname; } + string getConnUniqueId() { return connUniqueId; } }; class WbesocketConnectMgrService { @@ -47,6 +58,8 @@ class WbesocketConnectMgrService { static json getConnectionList(); static void updateConnectList(); + + static shared_ptr findwsinfo(shared_ptr client); }; } // namespace iflytop diff --git a/tools/deply.sh b/tools/deply.sh index b048c52..a1d06cc 100755 --- a/tools/deply.sh +++ b/tools/deply.sh @@ -9,7 +9,9 @@ fi server=$1 ssh $server 'mkdir -p /iflytopd/iflytophald/' +ssh $server 'systemctl stop iflytophald' scp ./build/app/iflytophald $server:/iflytopd/iflytophald/ # scp ./resources/iflytophald.service $server:/lib/systemd/system/ # scp ./resources/config.ini $server:/iflytopd/iflytophald/ scp ./resources/spd_logger_cfg.json $server:/iflytopd/iflytophald/ +ssh $server 'systemctl start iflytophald' \ No newline at end of file