|
@@ -69,8 +69,8 @@ namespace Chromium {
|
|
|
{
|
|
|
//存储的消息应具备时效性,保证一个hdl只有一个记录的消息
|
|
|
|
|
|
- auto it = m_msg_pool.find(entityName);
|
|
|
- if (it != m_msg_pool.end())
|
|
|
+ auto it = ConfigManager::getInstance().m_msg_pool.find(entityName);
|
|
|
+ if (it != ConfigManager::getInstance().m_msg_pool.end())
|
|
|
{
|
|
|
auto& curArr = it->second;
|
|
|
for (auto i = curArr.begin(); i != curArr.end(); i++)
|
|
@@ -88,38 +88,38 @@ namespace Chromium {
|
|
|
{
|
|
|
std::vector<std::pair<websocketpp::connection_hdl, std::string>> t_saveMsgs;
|
|
|
t_saveMsgs.emplace_back(std::make_pair(hdl, payload));
|
|
|
- m_msg_pool.insert(std::make_pair(entityName, t_saveMsgs));
|
|
|
+ ConfigManager::getInstance().m_msg_pool.insert(std::make_pair(entityName, t_saveMsgs));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::updateNotifyPool(unsigned hdl, unsigned transId)
|
|
|
{
|
|
|
- auto it = m_notifyPool.find(hdl);
|
|
|
- if (it != m_notifyPool.end())
|
|
|
+ auto it = ConfigManager::getInstance().m_notifyPool.find(hdl);
|
|
|
+ if (it != ConfigManager::getInstance().m_notifyPool.end())
|
|
|
{
|
|
|
if (transId == 0)
|
|
|
- m_notifyPool.erase(it);
|
|
|
+ ConfigManager::getInstance().m_notifyPool.erase(it);
|
|
|
else
|
|
|
it->second = transId;
|
|
|
}
|
|
|
else if (transId != 0)
|
|
|
- m_notifyPool.insert(std::make_pair(hdl, transId));
|
|
|
+ ConfigManager::getInstance().m_notifyPool.insert(std::make_pair(hdl, transId));
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::storeEntityWithCLass(std::string entityName, std::string entityClass)
|
|
|
{
|
|
|
- if (m_entityAndClass.end() == m_entityAndClass.find(entityName)) {
|
|
|
- m_entityAndClass.insert(std::make_pair(entityName, entityClass)); //not exist
|
|
|
+ if (ConfigManager::getInstance().m_entityAndClass.end() == ConfigManager::getInstance().m_entityAndClass.find(entityName)) {
|
|
|
+ ConfigManager::getInstance().m_entityAndClass.insert(std::make_pair(entityName, entityClass)); //not exist
|
|
|
//DbgEx("storeEntityWithCLass, %s:%s", entityName.c_str(), entityClass.c_str());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
std::pair<bool, std::string> CWebsocketServer::getEntityClass(std::string entityName)
|
|
|
{
|
|
|
- auto it = m_entityAndClass.find(entityName);
|
|
|
- if (m_entityAndClass.end() == it)
|
|
|
+ auto it = ConfigManager::getInstance().m_entityAndClass.find(entityName);
|
|
|
+ if (ConfigManager::getInstance().m_entityAndClass.end() == it)
|
|
|
return std::make_pair(false, "");
|
|
|
else
|
|
|
return std::make_pair(true, it->second);
|
|
@@ -128,7 +128,8 @@ namespace Chromium {
|
|
|
void CWebsocketServer::do_sendJsonStartSession(std::string entityName, std::string entityClass)
|
|
|
{
|
|
|
auto startSessionReq = m_esm->GetStartSessionRequest(entityName, entityClass);
|
|
|
- auto sessionBuf = this->m_serializer->JsonToBuffer(startSessionReq.second).second;
|
|
|
+ ws_msgInfo cur(startSessionReq.second, 0, 0);
|
|
|
+ auto sessionBuf = this->m_serializer->JsonToBuffer(startSessionReq.second, cur).second;
|
|
|
if (nullptr == sessionBuf)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("JsonToBuffer return NULL !");
|
|
@@ -140,9 +141,13 @@ namespace Chromium {
|
|
|
if (m_esm->checkBeginSession(entityName)) {
|
|
|
m_esm->updateBeginSessionTime(entityName);
|
|
|
WriteToFramework(sessionBuf);
|
|
|
+ LogManager::getInstance().logWebSocketBeginSession(-1, -1, cur.transId, cur.entityName, cur.className, 0, "auto_send", cur.payLoad);
|
|
|
}
|
|
|
else
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Already begin session in 5s, %s", entityName.c_str());
|
|
|
+ {
|
|
|
+ LogManager::getInstance().logWebSocketBeginSession(-1, -1, cur.transId, cur.entityName, cur.className, 1, "none", cur.payLoad,
|
|
|
+ Error_Duplication, "already begin session in 5 seconds");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::WriteToFramework(CMessage* msg)
|
|
@@ -224,7 +229,7 @@ namespace Chromium {
|
|
|
break;
|
|
|
}
|
|
|
DbgWithLink(changeMessageTypeToLogLevel(messageType), LOG_TYPE_BUSINESS_SYSTEM)
|
|
|
- .withLogProducer(logProducer).setAPI("logMsg").withExtendLog(false).setResultMsg(msg.second.GetData())();
|
|
|
+ .withLogProducer(ConfigManager::getInstance().getLogProducer()).setAPI("logMsg").withExtendLog(false).setResultMsg(msg.second.GetData())();
|
|
|
break;
|
|
|
}
|
|
|
case METHOD_SYSTEM_DETAIL_LOG_DEBUG:
|
|
@@ -263,7 +268,8 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
//create the logProduer if not exist
|
|
|
- if (g_logProducerArr.find(t_entityName.second.GetData()) == g_logProducerArr.end())//can not find the logProducer
|
|
|
+ auto t_logProducerArr = ConfigManager::getInstance().getLogProducerArr();
|
|
|
+ if (t_logProducerArr.find(t_entityName.second.GetData()) == t_logProducerArr.end())//can not find the logProducer
|
|
|
{
|
|
|
auto t_CmptId = json_deal::getStringFromCjsonObj(pJson.get(), msg_CmptId);
|
|
|
auto t_CmptName = json_deal::getStringFromCjsonObj(pJson.get(), msg_CmptName);
|
|
@@ -278,19 +284,19 @@ namespace Chromium {
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create producer sueccess, entityName:%s, CmptId:%s, t_CmptName:%s"
|
|
|
, t_entityName.second.GetData(), t_CmptId.second.GetData(), t_CmptName.second.GetData());
|
|
|
- g_logProducerArr.insert(std::make_pair(t_entityName.second.GetData(), t_producer));
|
|
|
+ t_logProducerArr.insert(std::make_pair(t_entityName.second.GetData(), t_producer));
|
|
|
}
|
|
|
- auto t_logProducer = g_logProducerArr[t_entityName.second.GetData()];
|
|
|
+ auto t_logProducer = t_logProducerArr[t_entityName.second.GetData()];
|
|
|
|
|
|
|
|
|
auto logType = json_deal::getStringFromCjsonObj(pJson.get(), msg_logType);//it can be equal to Sys/User/VTMWeb
|
|
|
- LOG_TYPE_E t_type = LOG_TYPE_SYSTEM;
|
|
|
+ LOG_TYPE_E t_type = LOG_TYPE_BUSINESS_SYSTEM;
|
|
|
if (logType.second.Compare("User", true) == 0)
|
|
|
- t_type = LOG_TYPE_USER;
|
|
|
+ t_type = LOG_TYPE_BUSINESS_USER;
|
|
|
else if (logType.second.Compare("VTMWeb", true) == 0)
|
|
|
t_type = LOG_TYPE_VTMWEB;
|
|
|
else if(logType.second.Compare("Sys", true) == 0)
|
|
|
- t_type = LOG_TYPE_SYSTEM;
|
|
|
+ t_type = LOG_TYPE_BUSINESS_SYSTEM;
|
|
|
|
|
|
//通过变量方式进行处理
|
|
|
DbgWithLink t_obj(changeMessageTypeToLogLevel(messageType), t_type);
|
|
@@ -478,25 +484,29 @@ namespace Chromium {
|
|
|
|
|
|
std::string js = CSimpleString::Format("{\"messageType\":5,\"errorCode\":\"%d\",\"errorMsg\":\"1537 session break\",\"sessionID\":-1,\"transID\":125}", Error_DevNotAvailable).GetData();
|
|
|
|
|
|
- js = restroreTransId(js);
|
|
|
+ auto dst_js = restroreTransId(js);
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("deal_sessionBreakMsg, len:%d, srcPayLoad:%s, ret:%s", payload.length()
|
|
|
- , payload.length() > 800 ? payload.substr(0, 800).append("...").c_str() : payload.c_str(), js.c_str());
|
|
|
+ , payload.length() > 800 ? payload.substr(0, 800).append("...").c_str() : payload.c_str(), dst_js.second.c_str());
|
|
|
do_send_msg(hdl, js);
|
|
|
}
|
|
|
|
|
|
|
|
|
- void CWebsocketServer::deal_msg(std::string& payload, websocketpp::connection_hdl hdl)
|
|
|
+ void CWebsocketServer::deal_msg(std::string& payload, websocketpp::connection_hdl hdl, int srcTransId)
|
|
|
{
|
|
|
boost::lock_guard<boost::mutex> lock(m_dealMsgLock); //在buffer和json处理时,deal_msg会调用多次,导致transId存在重复可能
|
|
|
- auto ret = this->m_serializer->JsonToBuffer(payload);
|
|
|
+ ws_msgInfo cur(payload, 0, 0);
|
|
|
+ cur.hdlId = (long)hdl.lock().get();
|
|
|
+ cur.transId = srcTransId;
|
|
|
+ auto ret = this->m_serializer->JsonToBuffer(payload, cur);
|
|
|
CMessage* p = ret.second;
|
|
|
- if (ret.first == Broadcast && nullptr == p)
|
|
|
+
|
|
|
+ if (ret.first == MessageType::Broadcast && nullptr == p)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("JsonToBuffer return NULL, perhaps an event happened");
|
|
|
do_sendJsonBroadcast(payload);
|
|
|
return;
|
|
|
}
|
|
|
- else if(ret.first == Request || ret.first == Info)
|
|
|
+ else if(ret.first == MessageType::Request || ret.first == MessageType::Info)
|
|
|
{
|
|
|
if(nullptr == p)
|
|
|
{
|
|
@@ -509,9 +519,9 @@ namespace Chromium {
|
|
|
if (transIdJson.first)
|
|
|
{
|
|
|
std::string errRetJs = "{\"messageType\":4,\"transID\":" + std::to_string((LONGLONG)transIdJson.second) + ",\"errorCode\":103,\"errorMsg\":\"can not find entity or class!\"}";
|
|
|
- auto js = restroreTransId(errRetJs);
|
|
|
+ auto dst_js = restroreTransId(errRetJs);
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("deal_msg %s get null msg, ret:%s", ret.first == Request ? "Request" : "Info", errRetJs.c_str());
|
|
|
- do_send_msg(hdl, js);
|
|
|
+ do_send_msg(hdl, dst_js.second);
|
|
|
}
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CWebsocketServer::deal_msg get transIdJson failed");
|
|
@@ -519,7 +529,7 @@ namespace Chromium {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- else if (ret.first == GetSession)
|
|
|
+ else if (ret.first == MessageType::GetSession)
|
|
|
{
|
|
|
std::shared_ptr<cJSON> pJson(cJSON_Parse(payload.c_str()), [](cJSON* p) {
|
|
|
if (nullptr != p)
|
|
@@ -536,19 +546,36 @@ namespace Chromium {
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("sessionJson:%s", sessionRet.second.c_str());
|
|
|
if (sessionRet.first)
|
|
|
{
|
|
|
- auto js = restroreTransId(sessionRet.second);
|
|
|
- do_send_msg(hdl, js);
|
|
|
+ auto dst_js = restroreTransId(sessionRet.second);
|
|
|
+ do_send_msg(hdl, dst_js.second);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CWebsocketServer::deal_msg get transIdJson failed");
|
|
|
return;
|
|
|
}
|
|
|
- else if (ret.first == BeginSession)
|
|
|
+ else if (ret.first == MessageType::WEB_GET_HTTP_HEADER)
|
|
|
+ {
|
|
|
+ CSystemStaticInfo staticInfo;
|
|
|
+ m_pEntity->GetFunction()->GetSystemStaticInfo(staticInfo);
|
|
|
+
|
|
|
+ std::string dst_js = "";
|
|
|
+
|
|
|
+ if (staticInfo.strTerminalID.GetLength() == 0) // terminalno is empty
|
|
|
+ dst_js = "";
|
|
|
+ else
|
|
|
+ dst_js = m_esm->Get_getconfig_ack(staticInfo.strTerminalID.GetData()).second;
|
|
|
+ do_send_msg(hdl, dst_js);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (ret.first == MessageType::BeginSession)
|
|
|
storeEntityWithCLass(m_serializer->GetEntityName(payload), m_serializer->GetClassName(payload));
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// Try to manage entity session
|
|
|
- RequestProcessType processType = this->m_esm->RequestProcess(p, m_serializer->GetEntityName(payload), (long)hdl.lock().get());
|
|
|
+ RequestProcessType processType = this->m_esm->RequestProcess(p, m_serializer->GetEntityName(payload), (long)hdl.lock().get(), cur);
|
|
|
|
|
|
switch (processType)
|
|
|
{
|
|
@@ -556,7 +583,6 @@ namespace Chromium {
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("do PROCESS_NOTHING");
|
|
|
return;
|
|
|
case Chromium::PROCESS_SEND:
|
|
|
- //DbgEx("do PROCESS_SEND");
|
|
|
if (nullptr != p)
|
|
|
WriteToFramework(p);
|
|
|
break;
|
|
@@ -577,8 +603,8 @@ namespace Chromium {
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("do PROCESS_FINDSESSION");
|
|
|
std::string js = m_esm->GetStartSessionAck(p, m_serializer->GetEntityName(payload));
|
|
|
- js = restroreTransId(js);
|
|
|
- do_send_msg(hdl, js);
|
|
|
+ auto dst_js = restroreTransId(js);
|
|
|
+ do_send_msg(hdl, dst_js.second);
|
|
|
}
|
|
|
break;
|
|
|
case Chromium::PROCESS_RECORDMSG:
|
|
@@ -613,7 +639,7 @@ namespace Chromium {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- switch (m_ws_sm2_hdls_manager[curHdl]->getState())
|
|
|
+ switch (ConfigManager::getInstance().m_ws_sm2_hdls_manager[curHdl]->getState())
|
|
|
{
|
|
|
case SM2ProtocolState::WAIT_KEY_EXCHANGE:
|
|
|
{
|
|
@@ -623,8 +649,8 @@ namespace Chromium {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("pubKey == null");
|
|
|
return;
|
|
|
}
|
|
|
- m_ws_sm2_hdls_manager[curHdl]->setOpposite(pubKey.second.GetData());
|
|
|
- auto encPub = m_ws_sm2_hdls_manager[curHdl]->GenerateEncPubKey();
|
|
|
+ ConfigManager::getInstance().m_ws_sm2_hdls_manager[curHdl]->setOpposite(pubKey.second.GetData());
|
|
|
+ auto encPub = ConfigManager::getInstance().m_ws_sm2_hdls_manager[curHdl]->GenerateEncPubKey();
|
|
|
if (!encPub.first)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CWebsocketServer -> message_handler_ws_sm2 err:%s", encPub.second.c_str());
|
|
@@ -634,7 +660,7 @@ namespace Chromium {
|
|
|
std::string js = CSimpleString::Format("{\"encPub\":\"%s\"}", encPub.second.c_str()).GetData();
|
|
|
//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CWebsocketServer -> message_handler_ws_sm2 send js:%s", js.c_str());
|
|
|
do_send_msg(hdl, js);
|
|
|
- m_ws_sm2_hdls_manager[curHdl]->setState(SM2ProtocolState::DATA_EXCHANGE);
|
|
|
+ ConfigManager::getInstance().m_ws_sm2_hdls_manager[curHdl]->setState(SM2ProtocolState::DATA_EXCHANGE);
|
|
|
}
|
|
|
break;
|
|
|
case SM2ProtocolState::DATA_EXCHANGE:
|
|
@@ -653,7 +679,7 @@ namespace Chromium {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- auto decMsg = m_ws_sm2_hdls_manager[curHdl]->DecryptMsg(sign.second.GetData(), msgData.second.GetData());
|
|
|
+ auto decMsg = ConfigManager::getInstance().m_ws_sm2_hdls_manager[curHdl]->DecryptMsg(sign.second.GetData(), msgData.second.GetData());
|
|
|
if(decMsg.first == false)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("DecryptMsg err:%s", decMsg.second.c_str());
|
|
@@ -708,9 +734,10 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
auto transIdJson = cJSON_GetObjectItem(pJson.get(), "transId");//不做相关改造,因为这里还使用了set
|
|
|
+ int transid = 0;
|
|
|
if (transIdJson != nullptr)
|
|
|
{
|
|
|
- int transid = transIdJson->valueint;
|
|
|
+ transid = transIdJson->valueint;
|
|
|
int modifyT = t_hdlArr[hdlPos] << 24;
|
|
|
int dstTransId = transid ^ modifyT;
|
|
|
cJSON_SetIntValue(transIdJson, dstTransId);
|
|
@@ -728,16 +755,20 @@ namespace Chromium {
|
|
|
delete[]unformateStr;
|
|
|
|
|
|
auto messageType = messageTypeJson.second;
|
|
|
- if (messageType < WEB_CHROMIUM_MSG_BEGIN)
|
|
|
+ if (messageType < MessageType::WEB_SPECICAL_MANAGE_END)
|
|
|
{
|
|
|
+ /*
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("deal_msg, messageType:%d(%s), len:%d, payload:%s", messageType, GetMessageTypeString(messageType).c_str(),
|
|
|
payload.length(), payload.length() > 800 ? payload.substr(0, 800).append("...").c_str() : payload.c_str());
|
|
|
- deal_msg(dstPayLoad, hdl);
|
|
|
+ */
|
|
|
+ deal_msg(dstPayLoad, hdl, transid);
|
|
|
}
|
|
|
else if (messageType > WEB_CHROMIUM_MSG_BEGIN && messageType < WEB_CHROMIUM_MSG_END)
|
|
|
{
|
|
|
+ /*
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("deal_webchromium_msg, messageType:%d(%s), len:%d, payload:%s", messageType, GetMessageTypeString(messageType).c_str(),
|
|
|
payload.length(), payload.length() > 800 ? payload.substr(0, 800).append("...").c_str() : payload.c_str());
|
|
|
+ */
|
|
|
deal_webchromium_msg(dstPayLoad, hdl, messageType);
|
|
|
}
|
|
|
else if (messageType > METHOD_SYSTEM_START && messageType < METHOD_SYSTEM_END)
|
|
@@ -749,61 +780,64 @@ namespace Chromium {
|
|
|
dealMsgThread.join();
|
|
|
}
|
|
|
|
|
|
- std::string CWebsocketServer::restroreTransId(std::string payLoad)
|
|
|
+ std::pair<int, std::string> CWebsocketServer::restroreTransId(std::string payLoad)
|
|
|
{
|
|
|
std::shared_ptr<cJSON> pJson(cJSON_Parse(payLoad.c_str()), [](cJSON* p) {
|
|
|
if (nullptr != p)
|
|
|
cJSON_Delete(p);
|
|
|
});
|
|
|
auto transIdJson = cJSON_GetObjectItem(pJson.get(), "transId");//不改动,因为需要set
|
|
|
+ int dstTransId = 0;
|
|
|
if (transIdJson != nullptr)
|
|
|
{
|
|
|
int transid = transIdJson->valueint;
|
|
|
- int dstTransId = transid & 0x00FFFFFF;
|
|
|
+ dstTransId = transid & 0x00FFFFFF;
|
|
|
cJSON_SetIntValue(transIdJson, dstTransId);
|
|
|
}
|
|
|
|
|
|
char* unformateStr = cJSON_PrintUnformatted(pJson.get());
|
|
|
std::string dstPayLoad = unformateStr;
|
|
|
delete[]unformateStr;
|
|
|
- return dstPayLoad;
|
|
|
+ return std::make_pair(dstTransId, dstPayLoad);
|
|
|
}
|
|
|
|
|
|
|
|
|
void CWebsocketServer::open_handler(websocketpp::connection_hdl hdl) {
|
|
|
// hand shake here
|
|
|
server::connection_ptr con = m_wsserver.get_con_from_hdl(hdl);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new ws connection to ws server : %u, isSecure:%d, url:%s", hdl.lock().get(), con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
-
|
|
|
- m_connection_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>((long)hdl.lock().get(), hdl));
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new ws connection to ws server : %u, isSecure:%d, url:%s", hdl.lock().get(), con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
+ LogManager::getInstance().logWebSocketBuild((uint64_t)hdl.lock().get(), con->get_uri()->str(), "unsafe");
|
|
|
+ ConfigManager::getInstance().m_connection_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>((long)hdl.lock().get(), hdl));
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::open_handler_wss(websocketpp::connection_hdl hdl) {
|
|
|
// hand shake here
|
|
|
auto con = m_server_wss.get_con_from_hdl(hdl);
|
|
|
unsigned int dstHdl = (long)hdl.lock().get();//start from 0, be different from ws
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new wss connection to ws server : %u, isSecure:%d, url:%s", dstHdl, con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
-
|
|
|
- m_connection_wss_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>((long)dstHdl, hdl));
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new wss connection to ws server : %u, isSecure:%d, url:%s", dstHdl, con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
+ LogManager::getInstance().logWebSocketBuild((uint64_t)hdl.lock().get(), con->get_uri()->str(), "wss");
|
|
|
+ ConfigManager::getInstance().m_connection_wss_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>((long)dstHdl, hdl));
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::open_handler_ws_sm2(websocketpp::connection_hdl hdl) {
|
|
|
// hand shake here
|
|
|
auto con = m_ws_sm2_server.get_con_from_hdl(hdl);
|
|
|
unsigned int dstHdl = (long)hdl.lock().get();//start from 0, be different from ws
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new ws by encrypt connection to ws server : %u, isSecure:%d, url:%s", dstHdl, con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
- m_connection_ws_sm2_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>(dstHdl, hdl));
|
|
|
- m_ws_sm2_hdls_manager.insert(std::make_pair(dstHdl, new SM2_Encrypt_Manager()));
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new ws by encrypt connection to ws server : %u, isSecure:%d, url:%s", dstHdl, con->get_uri()->get_secure(), con->get_uri()->str().c_str());
|
|
|
+ LogManager::getInstance().logWebSocketBuild((uint64_t)hdl.lock().get(), con->get_uri()->str(), "ws_sm2");
|
|
|
+ ConfigManager::getInstance().m_connection_ws_sm2_hdls.insert(std::pair<unsigned int, websocketpp::connection_hdl>(dstHdl, hdl));
|
|
|
+ ConfigManager::getInstance().m_ws_sm2_hdls_manager.insert(std::make_pair(dstHdl, new SM2_Encrypt_Manager()));
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::close_handler(websocketpp::connection_hdl hdl) {
|
|
|
// hand shake here
|
|
|
|
|
|
- auto connectionIter = m_connection_hdls.find((long)hdl.lock().get());
|
|
|
- if (m_connection_hdls.end() != connectionIter)
|
|
|
+ auto connectionIter = ConfigManager::getInstance().m_connection_hdls.find((long)hdl.lock().get());
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.end() != connectionIter)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws connection with ws server closed : %u", hdl.lock().get());
|
|
|
- m_connection_hdls.erase(connectionIter);
|
|
|
+ LogManager::getInstance().logWebSocketClose((uint64_t)hdl.lock().get());
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws connection with ws server closed : %u", hdl.lock().get());
|
|
|
+ ConfigManager::getInstance().m_connection_hdls.erase(connectionIter);
|
|
|
}
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws connection close erase failed : %u", hdl.lock().get());
|
|
@@ -813,11 +847,12 @@ namespace Chromium {
|
|
|
void CWebsocketServer::close_handler_wss(websocketpp::connection_hdl hdl) {
|
|
|
// hand shake here
|
|
|
|
|
|
- auto connectionIter = m_connection_wss_hdls.find((long)hdl.lock().get());
|
|
|
- if (m_connection_wss_hdls.end() != connectionIter)
|
|
|
+ auto connectionIter = ConfigManager::getInstance().m_connection_wss_hdls.find((long)hdl.lock().get());
|
|
|
+ if (ConfigManager::getInstance().m_connection_wss_hdls.end() != connectionIter)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wss connection with ws server closed : %u", hdl.lock().get());
|
|
|
- m_connection_wss_hdls.erase(connectionIter);
|
|
|
+ LogManager::getInstance().logWebSocketClose((uint64_t)hdl.lock().get());
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wss connection with ws server closed : %u", hdl.lock().get());
|
|
|
+ ConfigManager::getInstance().m_connection_wss_hdls.erase(connectionIter);
|
|
|
}
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wss connection close erase failed : %u", hdl.lock().get());
|
|
@@ -827,12 +862,13 @@ namespace Chromium {
|
|
|
{
|
|
|
// hand shake here
|
|
|
|
|
|
- auto connectionIter = m_connection_ws_sm2_hdls.find((long)hdl.lock().get());
|
|
|
- if (m_connection_ws_sm2_hdls.end() != connectionIter)
|
|
|
+ auto connectionIter = ConfigManager::getInstance().m_connection_ws_sm2_hdls.find((long)hdl.lock().get());
|
|
|
+ if (ConfigManager::getInstance().m_connection_ws_sm2_hdls.end() != connectionIter)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws sm2 connection with ws server closed : %u", hdl.lock().get());
|
|
|
- m_connection_ws_sm2_hdls.erase(connectionIter);
|
|
|
- m_ws_sm2_hdls_manager.erase((long)hdl.lock().get());
|
|
|
+ LogManager::getInstance().logWebSocketClose((uint64_t)hdl.lock().get());
|
|
|
+ //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws sm2 connection with ws server closed : %u", hdl.lock().get());
|
|
|
+ ConfigManager::getInstance().m_connection_ws_sm2_hdls.erase(connectionIter);
|
|
|
+ ConfigManager::getInstance().m_ws_sm2_hdls_manager.erase((long)hdl.lock().get());
|
|
|
}
|
|
|
else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws sm2 connection close erase failed : %u", hdl.lock().get());
|
|
@@ -940,7 +976,18 @@ namespace Chromium {
|
|
|
}
|
|
|
catch (...)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("exception in do_relink");
|
|
|
+ std::exception_ptr p = std::current_exception();
|
|
|
+ if (p) {
|
|
|
+ try {
|
|
|
+ std::rethrow_exception(p);
|
|
|
+ }
|
|
|
+ catch (const boost::thread_interrupted& e) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("thread interrupted");
|
|
|
+ }
|
|
|
+ catch (const std::exception& e) {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("exception: %s", e.what());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -985,9 +1032,9 @@ namespace Chromium {
|
|
|
|
|
|
void CWebsocketServer::do_sendJsonBroadcast(std::string js)
|
|
|
{
|
|
|
- js = restroreTransId(js);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message broadcast : json = %s", js.c_str());
|
|
|
- if (js.empty())
|
|
|
+ auto dst_js = restroreTransId(js);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message broadcast : json = %s", dst_js.second.c_str());
|
|
|
+ if (dst_js.second.empty())
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("string empty");
|
|
|
return;
|
|
@@ -1003,23 +1050,17 @@ namespace Chromium {
|
|
|
return ss.str();
|
|
|
};
|
|
|
|
|
|
- if (!sendBroadCast(m_connection_hdls, m_wsserver, js))
|
|
|
+ if (!sendBroadCast(ConfigManager::getInstance().m_connection_hdls, m_wsserver, dst_js.second))
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws server broadcast error");
|
|
|
}
|
|
|
|
|
|
- if (!sendBroadCast(m_connection_ws_sm2_hdls, m_ws_sm2_server, js))
|
|
|
+ if (!sendBroadCast(ConfigManager::getInstance().m_connection_ws_sm2_hdls, m_ws_sm2_server, dst_js.second))
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ws_sm2 server broadcast error");
|
|
|
}
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("do_sendJsonBroadcast: broadcasts have already send to these terminals, no_security:%s, security:%s",
|
|
|
- formatMapToString(m_connection_hdls).c_str(), formatMapToString(m_connection_ws_sm2_hdls).c_str());
|
|
|
- /*
|
|
|
- if (!sendBroadCast(m_connection_wss_hdls, m_server_wss, js))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("wss server broadcast error");
|
|
|
- }
|
|
|
- */
|
|
|
+ formatMapToString(ConfigManager::getInstance().m_connection_hdls).c_str(), formatMapToString(ConfigManager::getInstance().m_connection_ws_sm2_hdls).c_str());
|
|
|
}
|
|
|
|
|
|
void CWebsocketServer::do_send_msg(int hdl, std::string msg)
|
|
@@ -1027,8 +1068,8 @@ namespace Chromium {
|
|
|
//send ws
|
|
|
try
|
|
|
{
|
|
|
- std::map<unsigned int, websocketpp::connection_hdl>::iterator it = m_connection_hdls.find(hdl);
|
|
|
- if (m_connection_hdls.end() != it)
|
|
|
+ std::map<unsigned int, websocketpp::connection_hdl>::iterator it = ConfigManager::getInstance().m_connection_hdls.find(hdl);
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.end() != it)
|
|
|
{
|
|
|
do_send_msg(it->second, msg);
|
|
|
return;
|
|
@@ -1048,8 +1089,8 @@ namespace Chromium {
|
|
|
//send ws sm2
|
|
|
try
|
|
|
{
|
|
|
- std::map<unsigned int, websocketpp::connection_hdl>::iterator it = m_connection_ws_sm2_hdls.find(hdl);
|
|
|
- if (m_connection_ws_sm2_hdls.end() != it)
|
|
|
+ std::map<unsigned int, websocketpp::connection_hdl>::iterator it = ConfigManager::getInstance().m_connection_ws_sm2_hdls.find(hdl);
|
|
|
+ if (ConfigManager::getInstance().m_connection_ws_sm2_hdls.end() != it)
|
|
|
{
|
|
|
//DbgEx("Send....");
|
|
|
do_send_msg(it->second, msg);
|
|
@@ -1072,8 +1113,8 @@ namespace Chromium {
|
|
|
try
|
|
|
{
|
|
|
//DbgEx("do_send_notifyMsg Enter...");
|
|
|
- std::map<unsigned int, websocketpp::connection_hdl>::iterator it = m_connection_hdls.find(hdlID);
|
|
|
- if (m_connection_hdls.end() != it)
|
|
|
+ std::map<unsigned int, websocketpp::connection_hdl>::iterator it = ConfigManager::getInstance().m_connection_hdls.find(hdlID);
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.end() != it)
|
|
|
{
|
|
|
//DbgEx("Send....");
|
|
|
websocketpp::connection_hdl hdl = it->second;
|
|
@@ -1101,20 +1142,21 @@ namespace Chromium {
|
|
|
unsigned int dstHdl = (long)hdl.lock().get();
|
|
|
|
|
|
websocketpp::lib::error_code dstExption;
|
|
|
- if (m_connection_hdls.find(dstHdl) != m_connection_hdls.end())
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.find(dstHdl) != ConfigManager::getInstance().m_connection_hdls.end())
|
|
|
{
|
|
|
m_wsserver.send(hdl, msg, websocketpp::frame::opcode::TEXT, dstExption);
|
|
|
}
|
|
|
- else if (m_connection_ws_sm2_hdls.find(dstHdl) != m_connection_ws_sm2_hdls.end())
|
|
|
+ else if (ConfigManager::getInstance().m_connection_ws_sm2_hdls.find(dstHdl) != ConfigManager::getInstance().m_connection_ws_sm2_hdls.end())
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("dstHdl:%d, save:%d", dstHdl, m_connection_ws_sm2_hdls[dstHdl].lock().get());
|
|
|
- if(m_ws_sm2_hdls_manager[dstHdl]->getState() == SM2ProtocolState::WAIT_KEY_EXCHANGE)
|
|
|
- m_ws_sm2_server.send(m_connection_ws_sm2_hdls[dstHdl], msg, websocketpp::frame::opcode::TEXT, dstExption);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("dstHdl:%d, save:%d", dstHdl,
|
|
|
+ ConfigManager::getInstance().m_connection_ws_sm2_hdls[dstHdl].lock().get());
|
|
|
+ if(ConfigManager::getInstance().m_ws_sm2_hdls_manager[dstHdl]->getState() == SM2ProtocolState::WAIT_KEY_EXCHANGE)
|
|
|
+ m_ws_sm2_server.send(ConfigManager::getInstance().m_connection_ws_sm2_hdls[dstHdl], msg, websocketpp::frame::opcode::TEXT, dstExption);
|
|
|
else
|
|
|
{
|
|
|
- auto dst = m_ws_sm2_hdls_manager[dstHdl]->EncryptMsg(msg);
|
|
|
+ auto dst = ConfigManager::getInstance().m_ws_sm2_hdls_manager[dstHdl]->EncryptMsg(msg);
|
|
|
std::string js = CSimpleString::Format("{\"sign\":\"%s\",\"msg\":\"%s\"}", dst.first.c_str(), dst.second.c_str()).GetData();
|
|
|
- m_ws_sm2_server.send(m_connection_ws_sm2_hdls[dstHdl], js, websocketpp::frame::opcode::TEXT, dstExption);
|
|
|
+ m_ws_sm2_server.send(ConfigManager::getInstance().m_connection_ws_sm2_hdls[dstHdl], js, websocketpp::frame::opcode::TEXT, dstExption);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1135,32 +1177,87 @@ namespace Chromium {
|
|
|
|
|
|
|
|
|
|
|
|
- void CWebsocketServer::do_sendJson(std::string js, int messageType, int hdlID, unsigned int id)
|
|
|
+ void CWebsocketServer::do_sendJson(std::string js, int messageType, int hdlID, unsigned int id, socket_msgInfo& msgInfo)
|
|
|
{
|
|
|
- js = restroreTransId(js);
|
|
|
- if(g_withLinkLog)
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("WebSocket Search message_from_socket : json = %s", js.c_str());
|
|
|
- else if(messageType != MessageType::RequestAck && messageType != MessageType::Event)//do not upload message which messageType equals to RequestAck or Event
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("WebSocket Search message_from_socket : json = %s", js.c_str());
|
|
|
- if (js.empty())
|
|
|
+ auto dst_js = restroreTransId(js);
|
|
|
+ js = dst_js.second;
|
|
|
+
|
|
|
+ if (messageType == MessageType::RequestAck)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("string empty");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (m_connection_hdls.empty() && m_connection_ws_sm2_hdls.empty())
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket : no websocket client connection");
|
|
|
- else {
|
|
|
#if(defined _WIN32 || defined _WIN64)
|
|
|
js = string_to_utf8(js);
|
|
|
#endif
|
|
|
if (js.empty())
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("string empty 2");
|
|
|
+ LogManager::getInstance().logVtmRequestAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, msgInfo.functionName, 2, "none", msgInfo.payLoad, msgInfo.msgBytes, Error_Null, "string empty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.empty() && ConfigManager::getInstance().m_connection_ws_sm2_hdls.empty())
|
|
|
+ LogManager::getInstance().logVtmRequestAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, msgInfo.functionName, 2, "none", msgInfo.payLoad, msgInfo.msgBytes, Error_Null, "no websocket client connection");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(msgInfo.userCodeVal == 0)
|
|
|
+ LogManager::getInstance().logVtmRequestAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, msgInfo.functionName, 0, "send", msgInfo.payLoad, msgInfo.msgBytes);
|
|
|
+ else
|
|
|
+ LogManager::getInstance().logVtmRequestAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, msgInfo.functionName, 2, "send", msgInfo.payLoad, msgInfo.msgBytes, msgInfo.userCodeVal, msgInfo.warnMsg);
|
|
|
+ do_send_msg(hdlID, js);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (messageType == MessageType::SessionAck)
|
|
|
+ {
|
|
|
+ if (js.empty())
|
|
|
+ {
|
|
|
+ LogManager::getInstance().logVtmSessionAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId, msgInfo.entityName, 2, "none",
|
|
|
+ msgInfo.payLoad, msgInfo.msgBytes, Error_Null, "string empty");
|
|
|
return;
|
|
|
}
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.empty() && ConfigManager::getInstance().m_connection_ws_sm2_hdls.empty())
|
|
|
+ LogManager::getInstance().logVtmSessionAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, 2, "none", msgInfo.payLoad, msgInfo.msgBytes, Error_Null, "no websocket client connection");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(msgInfo.userCodeVal == 0)
|
|
|
+ LogManager::getInstance().logVtmSessionAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, 0, "send", msgInfo.payLoad, msgInfo.msgBytes);
|
|
|
+ else
|
|
|
+ LogManager::getInstance().logVtmSessionAck(hdlID, dst_js.first, msgInfo.inner_transID, msgInfo.sessionId,
|
|
|
+ msgInfo.entityName, 2, "send", msgInfo.payLoad, msgInfo.msgBytes, msgInfo.userCodeVal, msgInfo.warnMsg);
|
|
|
+
|
|
|
+ do_send_msg(hdlID, js);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ConfigManager::getInstance().m_withLinkLog)
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("WebSocket Search message_from_socket : json = %s", js.c_str());
|
|
|
+ else if (messageType != MessageType::RequestAck && messageType != MessageType::Event)//do not upload message which messageType equals to RequestAck or Event
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("WebSocket Search message_from_socket : json = %s", js.c_str());
|
|
|
+ if (js.empty())
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("string empty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ConfigManager::getInstance().m_connection_hdls.empty() && ConfigManager::getInstance().m_connection_ws_sm2_hdls.empty())
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket : no websocket client connection");
|
|
|
+ else {
|
|
|
+#if(defined _WIN32 || defined _WIN64)
|
|
|
+ js = string_to_utf8(js);
|
|
|
+#endif
|
|
|
+ if (js.empty())
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("string empty 2");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- do_send_msg(hdlID, js);
|
|
|
+ do_send_msg(hdlID, js);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// socket message handler
|
|
@@ -1188,12 +1285,12 @@ namespace Chromium {
|
|
|
replaceTransId = tmpReplace.first == true ? tmpReplace.second : 0;
|
|
|
}
|
|
|
// 处理session ack,获取hdlID
|
|
|
+ socket_msgInfo cur_from_socket(replaceTransId, msg.getTransID(), msg.getSessionID());
|
|
|
|
|
|
unsigned int hdlID = 0;
|
|
|
std::vector<std::pair<int, int>> sendArr;
|
|
|
if (MessageType::Event == msg.getMessageType())
|
|
|
{
|
|
|
-
|
|
|
auto formatVectorToString = [](const std::vector<std::pair<int, int>>& vec) -> std::string {
|
|
|
std::stringstream ss;
|
|
|
ss << "[";
|
|
@@ -1216,27 +1313,32 @@ namespace Chromium {
|
|
|
for (auto i = sendArr.begin(); i != sendArr.end(); i++)
|
|
|
{
|
|
|
msg.setTransID(i->first);
|
|
|
- std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), 0);
|
|
|
- do_sendJson(js, msg.getMessageType(), i->second, id);
|
|
|
+ std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), cur_from_socket, 0);
|
|
|
+ do_sendJson(js, msg.getMessageType(), i->second, id, cur_from_socket);
|
|
|
unaccurate_js = js;
|
|
|
}
|
|
|
auto signatureID = msg.getSignatureID();
|
|
|
+ auto sessionId = msg.getSessionID();
|
|
|
+ auto sessionEntityName = EntitySessionManager::FromSessionIdToEntityName(sessionId);
|
|
|
if (sendArr.size() == 0)
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket event sendArr.size() == 0");
|
|
|
+ LogManager::getInstance().logVtmEvent(-1, -1, sessionId, sessionEntityName.second, 0, "send", sendArr,
|
|
|
+ cur_from_socket.payLoad, cur_from_socket.msgBytes, Error_NotExist, "message_from_socket event sendArr.size() == 0");
|
|
|
else if (signatureID != eMsgSig_LogInfo && signatureID != eMsgSig_EntityStatus && signatureID != eMsgSig_PerformanceList)//fiter guiconsole msg
|
|
|
{
|
|
|
-#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
|
|
|
+ LogManager::getInstance().logVtmEvent(-1, -1, sessionId, sessionEntityName.second, 0, "send", sendArr,
|
|
|
+ cur_from_socket.payLoad, cur_from_socket.msgBytes);
|
|
|
+ /*
|
|
|
+#ifdef DEVOPS_ON_ST
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket event %s send to arr:%s"
|
|
|
, unaccurate_js.c_str(), formatVectorToString(sendArr).c_str());
|
|
|
-#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
|
|
|
+#elif defined(DEVOPS_ON_UAT)
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket event %s send to arr:%s"
|
|
|
, unaccurate_js.c_str(), formatVectorToString(sendArr).c_str());
|
|
|
#else
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_from_socket event send to arr:%s", formatVectorToString(sendArr).c_str());
|
|
|
#endif
|
|
|
+ */
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
else if (MessageType::EndSession == msg.getMessageType()) //session end
|
|
|
{
|
|
@@ -1244,10 +1346,9 @@ namespace Chromium {
|
|
|
|
|
|
auto ret = m_esm->DoSessionRemove(sessionId);
|
|
|
if (ret.first)
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("MessgeType:%s, detect session %s:%d lost!remove success", GetMessageTypeString(2).c_str(), ret.second.c_str(), sessionId);
|
|
|
+ LogManager::getInstance().logVtmEndSession(-1, ret.second, sessionId, 0, "clean", "", Error_Succeed, "remove session success");
|
|
|
else
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("MessgeType:%s, detect session %d lost!remove failed", GetMessageTypeString(2).c_str(), sessionId);
|
|
|
-
|
|
|
+ LogManager::getInstance().logVtmEndSession(-1, ret.second, sessionId, 1, "clean", "", Error_NotExist, "detect session lost!remove failed");
|
|
|
}
|
|
|
else if (MessageType::SessionAck == msg.getMessageType())
|
|
|
{//sessionAck
|
|
@@ -1255,25 +1356,26 @@ namespace Chromium {
|
|
|
auto sessionId = msg.getSessionID();
|
|
|
if (ACKPROCESS_NOTHING == ret.first)
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("MessgeType:%s, can not find save session, process noting, %s", GetMessageTypeString(2).c_str(), ret.second.c_str());//error
|
|
|
+ LogManager::getInstance().logVtmSessionAck(hdlID, -1, -1, sessionId, cur_from_socket.entityName, 2, "none", cur_from_socket.payLoad, cur_from_socket.msgBytes,
|
|
|
+ Error_NotExist, "can not find save session, process noting");
|
|
|
return;
|
|
|
}
|
|
|
if (0 != hdlID)
|
|
|
{//hdlId为0时,说明本地发起的session
|
|
|
- std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), replaceTransId);
|
|
|
- do_sendJson(js, msg.getMessageType(), hdlID, id); //发给首记录的CMessage
|
|
|
+ std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), cur_from_socket, replaceTransId);
|
|
|
+ do_sendJson(js, msg.getMessageType(), hdlID, id, cur_from_socket); //发给首记录的CMessage
|
|
|
}
|
|
|
|
|
|
- for (auto cur = m_msg_pool.begin(); cur != m_msg_pool.end(); cur++)
|
|
|
+ for (auto cur = ConfigManager::getInstance().m_msg_pool.begin(); cur != ConfigManager::getInstance().m_msg_pool.end(); cur++)
|
|
|
{//sessionId为-1时需处理,否则会引发消息风暴
|
|
|
if (cur->first == ret.second)
|
|
|
{
|
|
|
std::vector<std::pair<websocketpp::connection_hdl, std::string>> msgArr(cur->second);
|
|
|
- m_msg_pool.erase(cur); //为防止处理消息时引发消息风暴,拷贝并删除原msg_pool
|
|
|
+ ConfigManager::getInstance().m_msg_pool.erase(cur); //为防止处理消息时引发消息风暴,拷贝并删除原msg_pool
|
|
|
if (-1 != sessionId) {
|
|
|
DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Session with %s Make, deal with record Msg:%d", ret.second.c_str(), msgArr.size());
|
|
|
for (auto msg = msgArr.begin(); msg != msgArr.end(); msg++)
|
|
|
- deal_msg(msg->second, msg->first);
|
|
|
+ deal_msg(msg->second, msg->first, 1);
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
@@ -1296,8 +1398,8 @@ namespace Chromium {
|
|
|
else
|
|
|
{
|
|
|
m_esm->AckProcess(&msg, hdlID); //替换真实的transId,update session map
|
|
|
- std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), replaceTransId);
|
|
|
- do_sendJson(js, msg.getMessageType(), hdlID, id);
|
|
|
+ std::string js = this->m_serializer->BufferToJson(msg, boost::bind(&EntitySessionManager::doWithErrorCode, m_esm, _1, _2), cur_from_socket, replaceTransId);
|
|
|
+ do_sendJson(js, msg.getMessageType(), hdlID, id, cur_from_socket);
|
|
|
}
|
|
|
|
|
|
}
|