From f4f06b43f014c42fe13a076362059dac2180f414 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Thu, 22 May 2025 16:44:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../relationship_sync_mgr.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 428531518..039f1a17e 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -245,7 +245,7 @@ bool RelationShipChangeMsg::FromShareUnbindPayLoad(const cJSON *payloadJson) this->broadCastId = 0; for (uint32_t j = CREDID_PAYLOAD_LEN; j < SHARE_UNBIND_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { this->broadCastId |= (static_cast(payloadItem->valueint)) << ((j - CREDID_PAYLOAD_LEN) * BITS_PER_BYTE); @@ -466,7 +466,7 @@ bool RelationShipChangeMsg::FromAccountLogoutPayLoad(const cJSON *payloadJson) broadCastId = 0; for (uint32_t j = ACCOUNT_LOGOUT_BROADCAST_LEN; j < ACCOUNT_LOGOUT_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { broadCastId |= (static_cast(payloadItem->valueint)) << ((j - ACCOUNT_LOGOUT_BROADCAST_LEN) * BITS_PER_BYTE); @@ -497,7 +497,7 @@ bool RelationShipChangeMsg::FromDeviceUnbindPayLoad(const cJSON *payloadJson) broadCastId = 0; for (uint32_t j = USERID_PAYLOAD_LEN; j < DEVICE_UNBIND_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { broadCastId |= (static_cast(payloadItem->valueint)) << ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); @@ -545,7 +545,7 @@ bool RelationShipChangeMsg::FromAppUnbindPayLoad(const cJSON *payloadJson) broadCastId = 0; for (uint32_t j = BROADCAST_PAYLOAD_LEN; j < APP_UNBIND_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { broadCastId |= (static_cast(payloadItem->valueint)) << ((j - BROADCAST_PAYLOAD_LEN) * BITS_PER_BYTE); @@ -563,7 +563,7 @@ bool RelationShipChangeMsg::GetBroadCastId(const cJSON *payloadJson, uint32_t us { broadCastId = 0; cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, userIdNum * USERID_BYTES + 1); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { broadCastId |= static_cast(payloadItem->valueint); } @@ -649,7 +649,7 @@ bool RelationShipChangeMsg::FromDelUserPayLoad(const cJSON *payloadJson) this->broadCastId = 0; for (uint32_t j = USERID_PAYLOAD_LEN; j < DEL_USER_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { this->broadCastId |= (static_cast(payloadItem->valueint)) << ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); @@ -681,7 +681,7 @@ bool RelationShipChangeMsg::FromStopUserPayLoad(const cJSON *payloadJson) this->broadCastId = 0; for (uint32_t j = USERID_PAYLOAD_LEN; j < STOP_USER_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); - CHECK_NULL_RETURN(payloadItem, true); + CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { this->broadCastId |= (static_cast(payloadItem->valueint)) << ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); @@ -855,13 +855,16 @@ bool ReleationShipSyncMgr::GetCurrentTimeSec(int32_t &sec) return false; } sec = ltm.tm_sec % CURRENT_TIME_SEC_FLAG; + if (sec == 0) { + sec = CURRENT_TIME_SEC_FLAG; + } return true; } std::string ReleationShipSyncMgr::SyncTrustRelationShip(RelationShipChangeMsg &msg) { int32_t currentTimeSec = 0; - msg.broadCastId = static_cast(CURRENT_TIME_SEC_FLAG); + msg.broadCastId = static_cast(CURRENT_TIME_SEC_FLAG + 1); if (!GetCurrentTimeSec(currentTimeSec)) { LOGE("get current time failed, use default value"); return msg.ToJson(); @@ -881,11 +884,14 @@ RelationShipChangeMsg ReleationShipSyncMgr::ParseTrustRelationShipChange(const s bool ReleationShipSyncMgr::IsNewBroadCastId(const RelationShipChangeMsg &msg) { - if (timer_ == nullptr) { - timer_ = std::make_shared(); + if (msg.broadCastId == 0) { + return true; } std::string key = msg.ToMapKey(); std::lock_guard autoLock(lock_); + if (timer_ == nullptr) { + timer_ = std::make_shared(); + } auto iter = recvBroadCastIdMap_.find(key); if (iter == recvBroadCastIdMap_.end()) { recvBroadCastIdMap_[key] = msg.broadCastId; -- Gitee From acf379e997dbe5de1cf8448a5b168e45d02f5b30 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Sat, 24 May 2025 15:54:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=87=8D=E8=AF=95=E4=B8=89=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../src/authentication_v2/dm_auth_state.cpp | 14 +++++++--- .../relationship_sync_mgr.cpp | 28 +++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 16c19ae22..31d375249 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -46,6 +46,7 @@ const std::map TASK_TIME_OUT_MAP = { constexpr int32_t ONBINDRESULT_MAPPING_NUM = 2; constexpr int32_t MS_PER_SECOND = 1000; constexpr int32_t US_PER_MSECOND = 1000; +constexpr int32_t GET_SYSTEMTIME_MAX_NUM = 3; constexpr const static char* ONBINDRESULT_MAPPING_LIST[ONBINDRESULT_MAPPING_NUM] = { "CollaborationFwk", "cast_engine_service", @@ -376,11 +377,16 @@ uint64_t DmAuthState::GetSysTimeMs() struct timeval time; time.tv_sec = 0; time.tv_usec = 0; - if (gettimeofday(&time, nullptr) != 0) { - LOGE("GetSysTimeMs failed."); - return 0; + int32_t retryNum = 0; + while (retryNum < GET_SYSTEMTIME_MAX_NUM) { + if (gettimeofday(&time, nullptr) != 0) { + retryNum++; + LOGE("GetSysTimeMs failed. retryNum: %{public}d", retryNum); + continue; + } + return (uint64_t) time.tv_sec * MS_PER_SECOND + (uint64_t)time.tv_usec / US_PER_MSECOND; } - return (uint64_t) time.tv_sec * MS_PER_SECOND + (uint64_t)time.tv_usec / US_PER_MSECOND; + return 0; } void DmAuthState::DeleteAcl(std::shared_ptr context, diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 039f1a17e..391cd68a4 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -69,6 +69,7 @@ namespace { const int32_t BROADCAST_PAYLOAD_LEN = 10; const int32_t BROADCAST_TIMEOUT_S = 5; const int32_t CURRENT_TIME_SEC_FLAG = 10; + const int32_t GET_CURRENT_TIME_MAX_NUM = 3; const char * const MSG_TYPE = "TYPE"; const char * const MSG_VALUE = "VALUE"; @@ -846,25 +847,30 @@ void ReleationShipSyncMgr::HandleRecvBroadCastTimeout(const std::string &key) bool ReleationShipSyncMgr::GetCurrentTimeSec(int32_t &sec) { + int32_t retryNum = 0; time_t now; - time(&now); struct tm ltm; - struct tm *res = localtime_r(&now, <m); - if (res == nullptr) { - LOGE("get current time failed."); - return false; - } - sec = ltm.tm_sec % CURRENT_TIME_SEC_FLAG; - if (sec == 0) { - sec = CURRENT_TIME_SEC_FLAG; + while (retryNum < GET_CURRENT_TIME_MAX_NUM) { + time(&now); + struct tm *res = localtime_r(&now, <m); + if (res == nullptr) { + retryNum++; + LOGE("get current time failed. retryNum: %{public}d", retryNum); + continue; + } + sec = ltm.tm_sec % CURRENT_TIME_SEC_FLAG; + if (sec == 0) { + sec = CURRENT_TIME_SEC_FLAG; + } + return true; } - return true; + return false; } std::string ReleationShipSyncMgr::SyncTrustRelationShip(RelationShipChangeMsg &msg) { int32_t currentTimeSec = 0; - msg.broadCastId = static_cast(CURRENT_TIME_SEC_FLAG + 1); + msg.broadCastId = 0; if (!GetCurrentTimeSec(currentTimeSec)) { LOGE("get current time failed, use default value"); return msg.ToJson(); -- Gitee