!8242 fix: modify net_builder errcode

Merge pull request !8242 from xingchu/master
This commit is contained in:
openharmony_ci 2024-11-21 02:01:06 +00:00 committed by Gitee
commit 718bd4cab3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 304 additions and 233 deletions

View File

@ -117,6 +117,7 @@ static int32_t DBDeviceNameInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName,
static int32_t DBDeviceBasicInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName, const char *value, size_t valueLength)
{
int32_t ret = SOFTBUS_OK;
if (strcmp(fieldName, DEVICE_INFO_DEVICE_UDID) == 0 && valueLength < UDID_BUF_LEN) {
if (strcpy_s(cacheInfo->deviceInfo.deviceUdid, UDID_BUF_LEN, value) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s deviceUdid fail");
@ -144,9 +145,9 @@ static int32_t DBDeviceBasicInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName
Anonymize(cacheInfo->uuid, &anoyUuid);
LNN_LOGI(LNN_BUILDER, "success, uuid=%{public}s", AnonymizeWrapper(anoyUuid));
AnonymizeFree(anoyUuid);
} else if (DBDeviceNameInfoSyncToCache(cacheInfo, fieldName, value, valueLength) != SOFTBUS_OK) {
} else if ((ret = DBDeviceNameInfoSyncToCache(cacheInfo, fieldName, value, valueLength)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:DB device name info sync to cache fail");
return SOFTBUS_ERR;
return ret;
}
LNN_LOGD(LNN_BUILDER, "success.");
return SOFTBUS_OK;
@ -215,6 +216,7 @@ static int32_t DBConnectMacInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName,
static int32_t DBConnectInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName, const char *value, size_t valueLength)
{
int32_t ret = SOFTBUS_OK;
if (strcmp(fieldName, DEVICE_INFO_NETWORK_ID) == 0 && valueLength < NETWORK_ID_BUF_LEN) {
if (strcpy_s(cacheInfo->networkId, NETWORK_ID_BUF_LEN, value) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s networkid fail");
@ -234,9 +236,9 @@ static int32_t DBConnectInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName, co
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s softbusVersion fail");
return SOFTBUS_STRCPY_ERR;
}
} else if (DBConnectMacInfoSyncToCache(cacheInfo, fieldName, value, valueLength) != SOFTBUS_OK) {
} else if ((ret = DBConnectMacInfoSyncToCache(cacheInfo, fieldName, value, valueLength)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:DB ConnectMacInfo Sync To Cache fail");
return SOFTBUS_ERR;
return ret;
}
LNN_LOGD(LNN_BUILDER, "success.");
return SOFTBUS_OK;
@ -313,25 +315,30 @@ static int32_t DBDataChangeBatchSyncToCacheInternal(
LNN_LOGE(LNN_BUILDER, "fail:invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_OK;
if (JudgeFieldNameIsDeviceBasicInfo(fieldName)) {
if (DBDeviceBasicInfoSyncToCache(cacheInfo, fieldName, value, valueLength) != SOFTBUS_OK) {
ret = DBDeviceBasicInfoSyncToCache(cacheInfo, fieldName, value, valueLength);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s device basic info to cache fail");
return SOFTBUS_ERR;
return ret;
}
} else if (JudgeFieldNameIsNumInfo(fieldName)) {
if (DBNumInfoSyncToCache(cacheInfo, fieldName, value) != SOFTBUS_OK) {
ret = DBNumInfoSyncToCache(cacheInfo, fieldName, value);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s device name fail");
return SOFTBUS_ERR;
return ret;
}
} else if (JudgeFieldNameIsConnectInfo(fieldName)) {
if (DBConnectInfoSyncToCache(cacheInfo, fieldName, value, valueLength) != SOFTBUS_OK) {
ret = DBConnectInfoSyncToCache(cacheInfo, fieldName, value, valueLength);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s connect info fail");
return SOFTBUS_ERR;
return ret;
}
} else if (JudgeFieldNameIsCipherInfo(fieldName)) {
if (DBCipherInfoSyncToCache(cacheInfo, fieldName, value, valueLength, udid) != SOFTBUS_OK) {
ret = DBCipherInfoSyncToCache(cacheInfo, fieldName, value, valueLength, udid);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s cipher info fail");
return SOFTBUS_ERR;
return ret;
}
} else if (strcmp(fieldName, DEVICE_INFO_BLE_P2P) == 0) {
if (strcmp(value, "true") == 0) {
@ -401,13 +408,15 @@ static int32_t SplitString(char splitKey[SPLIT_KEY_NUM][SPLIT_MAX_LEN], char spl
LNN_LOGE(LNN_BUILDER, "fail:invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (SplitKeyOrValue(key, splitKey, SPLIT_KEY_NUM) != SOFTBUS_OK) {
int32_t ret = SplitKeyOrValue(key, splitKey, SPLIT_KEY_NUM);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "split key error");
return SOFTBUS_ERR;
return ret;
}
if (SplitKeyOrValue(value, splitValue, SPLIT_VALUE_NUM) != SOFTBUS_OK) {
ret = SplitKeyOrValue(value, splitValue, SPLIT_VALUE_NUM);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "split value error");
return SOFTBUS_ERR;
return ret;
}
parseValue->stateVersion = atoi(splitValue[1]);
parseValue->timestamp = strtoull(splitValue[SPLIT_VALUE_NUM - 1], NULL, SOFTBUS_STRTOLL_BASE);
@ -421,39 +430,43 @@ static int32_t HandleDBAddChangeInternal(const char *key, const char *value, Nod
LNN_LOGE(LNN_BUILDER, "fail:invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_OK;
int64_t accountId = 0;
char deviceUdid[UDID_BUF_LEN] = { 0 };
char fieldName[FIELDNAME_MAX_LEN] = { 0 };
CloudSyncValue parseValue = { 0 };
char splitKey[SPLIT_KEY_NUM][SPLIT_MAX_LEN] = { 0 };
char splitValue[SPLIT_VALUE_NUM][SPLIT_MAX_LEN] = { 0 };
if (SplitString(splitKey, splitValue, key, value, &parseValue) != SOFTBUS_OK) {
ret = SplitString(splitKey, splitValue, key, value, &parseValue);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "split string error");
return SOFTBUS_ERR;
return ret;
}
if (GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName) != SOFTBUS_OK) {
ret = GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get info from splitkey error");
return SOFTBUS_ERR;
return ret;
}
char trueValue[SPLIT_MAX_LEN] = { 0 };
if (strcpy_s(trueValue, SPLIT_MAX_LEN, splitValue[0]) != EOK) {
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s true value fail.");
return SOFTBUS_STRCPY_ERR;
}
NodeInfo localCaheInfo = { 0 };
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) != SOFTBUS_OK) {
NodeInfo localCacheInfo = { 0 };
ret = LnnGetLocalCacheNodeInfo(&localCacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local cache node info fail");
return SOFTBUS_ERR;
return ret;
}
if (strcmp(deviceUdid, localCaheInfo.deviceInfo.deviceUdid) == 0) {
if (strcmp(deviceUdid, localCacheInfo.deviceInfo.deviceUdid) == 0) {
return SOFTBUS_OK;
}
if (DBDataChangeBatchSyncToCacheInternal(cacheInfo, fieldName, trueValue, strlen(trueValue), deviceUdid) !=
SOFTBUS_OK) {
ret = DBDataChangeBatchSyncToCacheInternal(cacheInfo, fieldName, trueValue, strlen(trueValue), deviceUdid);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:DB data change batch sync to cache fail");
return SOFTBUS_ERR;
return ret;
}
cacheInfo->localStateVersion = localCaheInfo.stateVersion;
cacheInfo->localStateVersion = localCacheInfo.stateVersion;
cacheInfo->updateTimestamp = parseValue.timestamp;
return SOFTBUS_OK;
}
@ -463,22 +476,22 @@ static int32_t SetDBNameDataToDLedger(NodeInfo *cacheInfo, char *deviceUdid, cha
if (strcmp(fieldName, DEVICE_INFO_DEVICE_NAME) == 0) {
if (!LnnSetDLDeviceInfoName(deviceUdid, cacheInfo->deviceInfo.deviceName)) {
LNN_LOGE(LNN_BUILDER, "set device name to distributedLedger fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR;
}
} else if (strcmp(fieldName, DEVICE_INFO_UNIFIED_DEVICE_NAME) == 0) {
if (LnnSetDLUnifiedDeviceName(deviceUdid, cacheInfo->deviceInfo.unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedName to distributedLedger fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR;
}
} else if (strcmp(fieldName, DEVICE_INFO_UNIFIED_DEFAULT_DEVICE_NAME) == 0) {
if (LnnSetDLUnifiedDefaultDeviceName(deviceUdid, cacheInfo->deviceInfo.unifiedDefaultName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedDefaultName to distributedLedger fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR;
}
} else if (strcmp(fieldName, DEVICE_INFO_SETTINGS_NICK_NAME) == 0) {
if (LnnSetDLDeviceNickNameByUdid(deviceUdid, cacheInfo->deviceInfo.nickName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device nickName to distributedLedger fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR;
}
} else {
LNN_LOGD(LNN_BUILDER, "%{public}s no need update to DLedger", fieldName);
@ -493,29 +506,34 @@ static int32_t SetDBDataToDistributedLedger(NodeInfo *cacheInfo, char *deviceUdi
LNN_LOGE(LNN_BUILDER, "fail:invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_OK;
if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_KEY) == 0) {
if (LnnSetDLDeviceBroadcastCipherKey(deviceUdid, cacheInfo->cipherInfo.key) != SOFTBUS_OK) {
ret = LnnSetDLDeviceBroadcastCipherKey(deviceUdid, cacheInfo->cipherInfo.key);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device cipherkey to distributedLedger fail");
return SOFTBUS_ERR;
return ret;
}
} else if (strcmp(fieldName, DEVICE_INFO_BROADCAST_CIPHER_IV) == 0) {
if (LnnSetDLDeviceBroadcastCipherIv(deviceUdid, cacheInfo->cipherInfo.iv) != SOFTBUS_OK) {
ret = LnnSetDLDeviceBroadcastCipherIv(deviceUdid, cacheInfo->cipherInfo.iv);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device cipheriv to distributedLedger fail");
return SOFTBUS_ERR;
return ret;
}
} else if (strcmp(fieldName, DEVICE_INFO_NETWORK_ID) == 0) {
if (LnnUpdateNetworkId(cacheInfo) != SOFTBUS_OK) {
ret = LnnUpdateNetworkId(cacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device networkId to distributedLedger fail");
return SOFTBUS_ERR;
return ret;
}
} else if (strcmp(fieldName, DEVICE_INFO_STATE_VERSION) == 0) {
if (LnnSetDLDeviceStateVersion(deviceUdid, cacheInfo->stateVersion) != SOFTBUS_OK) {
ret = LnnSetDLDeviceStateVersion(deviceUdid, cacheInfo->stateVersion);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device stateversion to distributedLedger fail");
return SOFTBUS_ERR;
return ret;
}
} else if (SetDBNameDataToDLedger(cacheInfo, deviceUdid, fieldName) != SOFTBUS_OK) {
} else if ((ret = SetDBNameDataToDLedger(cacheInfo, deviceUdid, fieldName)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set DB name data to distributedLedger fail");
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -560,7 +578,7 @@ static int32_t HandleDBUpdateInternal(
char udidHash[UDID_HASH_HEX_LEN + 1] = { 0 };
if (LnnGenerateHexStringHash((const unsigned char *)deviceUdid, udidHash, UDID_HASH_HEX_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "Generate UDID HexStringHash fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR;
}
NodeInfo cacheInfo = { 0 };
if (LnnRetrieveDeviceInfo(udidHash, &cacheInfo) != SOFTBUS_OK) {
@ -582,12 +600,26 @@ static int32_t HandleDBUpdateInternal(
return SOFTBUS_OK;
}
static void PrintDeviceUdidAndTrueValue(char *deviceUdid, char *fieldName, char *trueValue, int32_t stateVersion)
{
char *anonyDeviceUdid = NULL;
Anonymize(deviceUdid, &anonyDeviceUdid);
char *anonyTrueValue = NULL;
Anonymize(trueValue, &anonyTrueValue);
LNN_LOGI(LNN_BUILDER,
"deviceUdid=%{public}s, fieldName=%{public}s update to %{public}s success, stateVersion=%{public}d",
AnonymizeWrapper(anonyDeviceUdid), fieldName, AnonymizeWrapper(anonyTrueValue), stateVersion);
AnonymizeFree(anonyDeviceUdid);
AnonymizeFree(anonyTrueValue);
}
static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
{
if (key == NULL || value == NULL) {
LNN_LOGE(LNN_BUILDER, "fail:invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_OK;
int64_t accountId = 0;
char deviceUdid[UDID_BUF_LEN] = { 0 };
char fieldName[FIELDNAME_MAX_LEN] = { 0 };
@ -596,18 +628,20 @@ static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
char splitValue[SPLIT_VALUE_NUM][SPLIT_MAX_LEN] = { 0 };
if (SplitString(splitKey, splitValue, key, value, &parseValue) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "split string error");
return SOFTBUS_ERR;
return SOFTBUS_SPLIT_STRING_FAIL;
}
if (GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName) != SOFTBUS_OK) {
ret = GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get info from splitkey error");
return SOFTBUS_ERR;
return ret;
}
NodeInfo localCaheInfo = { 0 };
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) != SOFTBUS_OK) {
NodeInfo localCacheInfo = { 0 };
ret = LnnGetLocalCacheNodeInfo(&localCacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local cache node info fail");
return SOFTBUS_ERR;
return ret;
}
if (strcmp(deviceUdid, localCaheInfo.deviceInfo.deviceUdid) == 0) {
if (strcmp(deviceUdid, localCacheInfo.deviceInfo.deviceUdid) == 0) {
return SOFTBUS_OK;
}
char trueValue[SPLIT_MAX_LEN] = { 0 };
@ -615,21 +649,13 @@ static int32_t HandleDBUpdateChangeInternal(const char *key, const char *value)
LNN_LOGE(LNN_BUILDER, "fail:strcpy_s true value fail.");
return SOFTBUS_STRCPY_ERR;
}
if (HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localCaheInfo.stateVersion) !=
SOFTBUS_OK) {
ret = HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localCacheInfo.stateVersion);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "handle DB update change internal fail");
(void)memset_s(trueValue, strlen(trueValue), 0, strlen(trueValue));
return SOFTBUS_ERR;
return ret;
}
char *anonyDeviceUdid = NULL;
Anonymize(deviceUdid, &anonyDeviceUdid);
char *anonyTrueValue = NULL;
Anonymize(trueValue, &anonyTrueValue);
LNN_LOGI(LNN_BUILDER,
"deviceUdid=%{public}s, fieldName=%{public}s update to %{public}s success, stateVersion=%{public}d",
AnonymizeWrapper(anonyDeviceUdid), fieldName, AnonymizeWrapper(anonyTrueValue), parseValue.stateVersion);
AnonymizeFree(anonyDeviceUdid);
AnonymizeFree(anonyTrueValue);
PrintDeviceUdidAndTrueValue(deviceUdid, fieldName, trueValue, parseValue.stateVersion);
(void)memset_s(trueValue, strlen(trueValue), 0, strlen(trueValue));
return SOFTBUS_OK;
}
@ -645,18 +671,20 @@ static int32_t HandleDBDeleteChangeInternal(const char *key, const char *value)
char deviceUdid[UDID_BUF_LEN] = { 0 };
char fieldName[FIELDNAME_MAX_LEN] = { 0 };
char splitKey[SPLIT_KEY_NUM][SPLIT_MAX_LEN] = { 0 };
if (SplitKeyOrValue(key, splitKey, SPLIT_KEY_NUM) != SOFTBUS_OK) {
int32_t ret = SplitKeyOrValue(key, splitKey, SPLIT_KEY_NUM);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "split key error");
return SOFTBUS_ERR;
return ret;
}
if (GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName) != SOFTBUS_OK) {
ret = GetInfoFromSplitKey(splitKey, &accountId, deviceUdid, fieldName);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get info from splitkey error");
return SOFTBUS_ERR;
return ret;
}
char udidHash[UDID_HASH_HEX_LEN + 1] = { 0 };
if (LnnGenerateHexStringHash((const unsigned char *)deviceUdid, udidHash, UDID_HASH_HEX_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "Generate UDID HexStringHash fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR;
}
NodeInfo cacheInfo = { 0 };
if (LnnRetrieveDeviceInfo(udidHash, &cacheInfo) != SOFTBUS_OK) {
@ -688,7 +716,7 @@ static void FreeKeyOrValue(const char **object, int32_t size)
SoftBusFree(object);
}
int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int32_t keySize)
static int32_t CheckParamValidity(const char **key, const char **value, int32_t keySize)
{
if (key == NULL || value == NULL || keySize == 0) {
LNN_LOGE(LNN_BUILDER, "invalid param or keySize is none");
@ -699,13 +727,23 @@ int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int3
}
return SOFTBUS_INVALID_PARAM;
}
return SOFTBUS_OK;
}
int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int32_t keySize)
{
int32_t ret = CheckParamValidity(key, value, keySize);
if (ret != SOFTBUS_OK) {
return ret;
}
NodeInfo cacheInfo = { 0 };
for (int32_t i = 0; i < keySize; i++) {
if (HandleDBAddChangeInternal(key[i], value[i], &cacheInfo) != SOFTBUS_OK) {
ret = HandleDBAddChangeInternal(key[i], value[i], &cacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:handle db data add change internal fail");
FreeKeyAndValue(key, value, keySize);
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
return ret;
}
}
FreeKeyAndValue(key, value, keySize);
@ -713,13 +751,13 @@ int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int3
if (LnnGenerateHexStringHash((const unsigned char *)cacheInfo.deviceInfo.deviceUdid, udidHash, UDID_HASH_HEX_LEN) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "Generate UDID HexStringHash fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR;
}
NodeInfo oldCacheInfo = { 0 };
if (LnnRetrieveDeviceInfo(udidHash, &oldCacheInfo) == SOFTBUS_OK &&
IsIgnoreUpdate(oldCacheInfo.stateVersion, oldCacheInfo.updateTimestamp, cacheInfo.stateVersion,
cacheInfo.updateTimestamp)) {
return SOFTBUS_ERR;
return SOFTBUS_KV_IGNORE_OLD_DEVICE_INFO;
}
(void)LnnSaveRemoteDeviceInfo(&cacheInfo);
char *anonyUdid = NULL;
@ -729,10 +767,11 @@ int32_t LnnDBDataAddChangeSyncToCache(const char **key, const char **value, int3
"" PRIu64, AnonymizeWrapper(anonyUdid), cacheInfo.stateVersion, cacheInfo.localStateVersion,
cacheInfo.updateTimestamp);
AnonymizeFree(anonyUdid);
if (LnnUpdateDistributedNodeInfo(&cacheInfo, cacheInfo.deviceInfo.deviceUdid) != SOFTBUS_OK) {
ret = LnnUpdateDistributedNodeInfo(&cacheInfo, cacheInfo.deviceInfo.deviceUdid);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:Cache info add sync to Ledger fail");
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
return ret;
}
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
@ -934,12 +973,13 @@ int32_t LnnDBDataChangeSyncToCacheInner(const char *key, const char *value)
cJSON *json = cJSON_Parse(value);
if (json == NULL) {
LNN_LOGE(LNN_BUILDER, "parse json fail");
return SOFTBUS_ERR;
return SOFTBUS_PARSE_JSON_ERR;
}
NodeInfo cacheInfo = { 0 };
if (LnnUnPackCloudSyncDeviceInfo(json, &cacheInfo) != SOFTBUS_OK) {
int32_t ret = LnnUnPackCloudSyncDeviceInfo(json, &cacheInfo);
if (ret != SOFTBUS_OK) {
cJSON_Delete(json);
return SOFTBUS_ERR;
return ret;
}
cJSON_Delete(json);
PrintSyncNodeInfo(&cacheInfo);
@ -947,18 +987,19 @@ int32_t LnnDBDataChangeSyncToCacheInner(const char *key, const char *value)
if (LnnGenerateHexStringHash((const unsigned char *)cacheInfo.deviceInfo.deviceUdid, udidHash, UDID_HASH_HEX_LEN) !=
SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "Generate UDID HexStringHash fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR;
}
NodeInfo oldCacheInfo = { 0 };
if (LnnRetrieveDeviceInfo(udidHash, &oldCacheInfo) == SOFTBUS_OK &&
IsIgnoreUpdate(oldCacheInfo.stateVersion, oldCacheInfo.updateTimestamp, cacheInfo.stateVersion,
cacheInfo.updateTimestamp)) {
return SOFTBUS_ERR;
return SOFTBUS_KV_IGNORE_OLD_DEVICE_INFO;
}
if (LnnSaveAndUpdateDistributedNode(&cacheInfo, &oldCacheInfo) != SOFTBUS_OK) {
ret = LnnSaveAndUpdateDistributedNode(&cacheInfo, &oldCacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "save and update distribute node info fail");
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_ERR;
return ret;
}
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
return SOFTBUS_OK;
@ -976,14 +1017,14 @@ int32_t LnnDBDataChangeSyncToCache(const char *key, const char *value, ChangeTyp
ret = HandleDBUpdateChangeInternal(key, value);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:handle db data update change internal fail");
return SOFTBUS_ERR;
return ret;
}
break;
case DB_DELETE:
ret = HandleDBDeleteChangeInternal(key, value);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:handle db data delete change internal fail");
return SOFTBUS_ERR;
return ret;
}
break;
default:
@ -1000,36 +1041,37 @@ int32_t LnnLedgerDataChangeSyncToDB(const char *key, const char *value, size_t v
LNN_LOGE(LNN_BUILDER, "fail:Ledger param is invalid.");
return SOFTBUS_INVALID_PARAM;
}
NodeInfo localCaheInfo = { 0 };
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) != SOFTBUS_OK) {
NodeInfo localCacheInfo = { 0 };
int32_t ret = LnnGetLocalCacheNodeInfo(&localCacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local cache node info fail");
return SOFTBUS_ERR;
return ret;
}
if (localCaheInfo.accountId == 0) {
if (localCacheInfo.accountId == 0) {
LNN_LOGI(LNN_LEDGER, "no account info. no need sync to DB");
return SOFTBUS_OK;
}
uint64_t nowTime = SoftBusGetSysTimeMs();
char putKey[KEY_MAX_LEN] = { 0 };
if (sprintf_s(putKey, KEY_MAX_LEN, "%ld#%s#%s", localCaheInfo.accountId, localCaheInfo.deviceInfo.deviceUdid, key) <
0) {
if (sprintf_s(putKey, KEY_MAX_LEN, "%ld#%s#%s", localCacheInfo.accountId, localCacheInfo.deviceInfo.deviceUdid,
key) < 0) {
LNN_LOGE(LNN_BUILDER, "sprintf_s key fail");
return SOFTBUS_ERR;
return SOFTBUS_SPRINTF_ERR;
}
char putValue[PUT_VALUE_MAX_LEN] = { 0 };
if (sprintf_s(putValue, PUT_VALUE_MAX_LEN, "%s#%d#%llu", value, localCaheInfo.stateVersion, nowTime) < 0) {
if (sprintf_s(putValue, PUT_VALUE_MAX_LEN, "%s#%d#%llu", value, localCacheInfo.stateVersion, nowTime) < 0) {
LNN_LOGE(LNN_BUILDER, "sprintf_s value fail");
return SOFTBUS_ERR;
return SOFTBUS_SPRINTF_ERR;
}
int32_t dbId = g_dbId;
int32_t ret = LnnPutDBData(dbId, putKey, strlen(putKey), putValue, strlen(putValue));
ret = LnnPutDBData(dbId, putKey, strlen(putKey), putValue, strlen(putValue));
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "fail:data sync to DB fail, errorcode=%{public}d", ret);
return ret;
}
LNN_LOGI(LNN_BUILDER, "Lnn ledger %{public}s change sync to DB success. stateVersion=%{public}d", key,
localCaheInfo.stateVersion);
localCacheInfo.stateVersion);
ret = LnnCloudSync(dbId);
if (ret != SOFTBUS_OK) {
@ -1134,19 +1176,20 @@ int32_t LnnAsyncCallLedgerAllDataSyncToDB(NodeInfo *info)
int32_t LnnDeleteSyncToDB(void)
{
NodeInfo localCaheInfo = { 0 };
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) != SOFTBUS_OK) {
NodeInfo localCacheInfo = { 0 };
int32_t ret = LnnGetLocalCacheNodeInfo(&localCacheInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local cache node info fail");
return SOFTBUS_ERR;
return ret;
}
char key[KEY_MAX_LEN] = { 0 };
if (sprintf_s(key, KEY_MAX_LEN, "%ld#%s", localCaheInfo.accountId, localCaheInfo.deviceInfo.deviceUdid) < 0) {
if (sprintf_s(key, KEY_MAX_LEN, "%ld#%s", localCacheInfo.accountId, localCacheInfo.deviceInfo.deviceUdid) < 0) {
LNN_LOGE(LNN_BUILDER, "sprintf_s key fail");
return SOFTBUS_ERR;
return SOFTBUS_SPRINTF_ERR;
}
int32_t dbId = g_dbId;
int32_t ret = LnnDeleteDBDataByPrefix(dbId, key, strlen(key));
ret = LnnDeleteDBDataByPrefix(dbId, key, strlen(key));
if (ret != 0) {
LNN_LOGE(LNN_BUILDER, "fail:data delete sync to DB fail");
return ret;

View File

@ -51,17 +51,17 @@ static int32_t LnnSyncDeviceName(const char *networkId)
const NodeInfo *info = LnnGetLocalNodeInfo();
if (info == NULL) {
LNN_LOGE(LNN_BUILDER, "get local node info fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GET_LOCAL_NODE_INFO_ERR;
}
deviceName = LnnGetDeviceName(&info->deviceInfo);
if (deviceName == NULL) {
LNN_LOGE(LNN_BUILDER, "get device name fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_GET_DEVICE_INFO_ERR;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_DEVICE_NAME, networkId, (const uint8_t *)deviceName,
strlen(deviceName) + 1, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send sync device name fail");
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_SEND_SYNC_INFO_FAILED;
}
return SOFTBUS_OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -128,7 +128,7 @@ int32_t PostBuildMessageToHandler(int32_t msgType, void *para)
SoftBusMessage *msg = CreateNetBuilderMessage(msgType, para);
if (msg == NULL) {
LNN_LOGE(LNN_BUILDER, "create softbus message failed");
return SOFTBUS_ERR;
return SOFTBUS_MALLOC_ERR;
}
g_netBuilder.looper->PostMessage(g_netBuilder.looper, msg);
return SOFTBUS_OK;
@ -192,13 +192,13 @@ int32_t SyncElectMessage(const char *networkId)
!AddNumberToJsonObject(json, JSON_KEY_MASTER_WEIGHT, masterWeight)) {
LNN_LOGE(LNN_BUILDER, "add elect info to json failed");
cJSON_Delete(json);
return SOFTBUS_ERR;
return SOFTBUS_ADD_INFO_TO_JSON_FAIL;
}
data = cJSON_PrintUnformatted(json);
cJSON_Delete(json);
if (data == NULL) {
LNN_LOGE(LNN_BUILDER, "format elect packet fail");
return SOFTBUS_ERR;
return SOFTBUS_CREATE_JSON_ERR;
}
rc = LnnSendSyncInfoMsg(LNN_INFO_TYPE_MASTER_ELECT, networkId, (uint8_t *)data, strlen(data) + 1, NULL);
cJSON_free(data);
@ -279,7 +279,7 @@ int32_t TrySendJoinLNNRequest(const JoinLnnMsgPara *para, bool needReportFailure
FreeJoinLnnMsgPara(para);
if (AuthStartVerify(&authConn, requestId, LnnGetReAuthVerifyCallback(), AUTH_MODULE_LNN, false) != SOFTBUS_OK) {
LNN_LOGI(LNN_BUILDER, "AuthStartVerify error");
return SOFTBUS_ERR;
return SOFTBUS_AUTH_START_VERIFY_FAIL;
}
return SOFTBUS_OK;
}
@ -978,13 +978,13 @@ int32_t JoinLnnWithNodeInfo(ConnectionAddr *addr, NodeInfo *info)
if (para->dupInfo == NULL) {
LNN_LOGE(LNN_BUILDER, "join with nodeinfo dup node info fail");
SoftBusFree(para);
return SOFTBUS_MALLOC_ERR;
return SOFTBUS_MEM_ERR;
}
if (PostBuildMessageToHandler(MSG_TYPE_DISCOVERY_DEVICE, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post notify discovery device message failed");
SoftBusFree(para->dupInfo);
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1062,7 +1062,7 @@ int32_t LnnNotifyDiscoveryDevice(
if (PostBuildMessageToHandler(MSG_TYPE_DISCOVERY_DEVICE, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post notify discovery device message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1090,7 +1090,7 @@ int32_t LnnRequestLeaveInvalidConn(const char *oldNetworkId, ConnectionAddrType
if (PostBuildMessageToHandler(MSG_TYPE_LEAVE_INVALID_CONN, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post leave invalid connection message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1101,7 +1101,7 @@ int32_t LnnRequestCleanConnFsm(uint16_t connFsmId)
if (g_netBuilder.isInit == false) {
LNN_LOGE(LNN_BUILDER, "no init");
return SOFTBUS_ERR;
return SOFTBUS_NO_INIT;
}
para = (uint16_t *)SoftBusMalloc(sizeof(uint16_t));
if (para == NULL) {
@ -1112,7 +1112,7 @@ int32_t LnnRequestCleanConnFsm(uint16_t connFsmId)
if (PostBuildMessageToHandler(MSG_TYPE_CLEAN_CONN_FSM, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post request clean connectionlnn message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1155,7 +1155,7 @@ int32_t LnnNotifyNodeStateChanged(const ConnectionAddr *addr)
if (PostBuildMessageToHandler(MSG_TYPE_NODE_STATE_CHANGED, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post node state changed message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1181,13 +1181,13 @@ int32_t LnnNotifyMasterElect(const char *networkId, const char *masterUdid, int3
strncpy_s(para->masterUdid, UDID_BUF_LEN, masterUdid, strlen(masterUdid)) != EOK) {
LNN_LOGE(LNN_BUILDER, "copy udid and maser udid failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
para->masterWeight = masterWeight;
if (PostBuildMessageToHandler(MSG_TYPE_MASTER_ELECT, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post elect message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1227,7 +1227,7 @@ int32_t LnnRequestLeaveByAddrType(const bool *type, uint32_t typeLen)
bool *para = NULL;
if (typeLen != CONNECTION_ADDR_MAX) {
LNN_LOGE(LNN_BUILDER, "invalid typeLen");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGD(LNN_BUILDER, "wlan=%{public}d, br=%{public}d, ble=%{public}d, eth=%{public}d", type[CONNECTION_ADDR_WLAN],
type[CONNECTION_ADDR_BR], type[CONNECTION_ADDR_BLE], type[CONNECTION_ADDR_ETH]);
@ -1248,7 +1248,7 @@ int32_t LnnRequestLeaveByAddrType(const bool *type, uint32_t typeLen)
if (PostBuildMessageToHandler(MSG_TYPE_LEAVE_BY_ADDR_TYPE, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post leave by addr type message failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1278,7 +1278,7 @@ int32_t LnnRequestLeaveSpecific(const char *networkId, ConnectionAddrType addrTy
if (PostBuildMessageToHandler(MSG_TYPE_LEAVE_SPECIFIC, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post leave specific msg failed");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1295,7 +1295,7 @@ int32_t LnnNotifyLeaveLnnByAuthHandle(AuthHandle *authHandle)
if (PostBuildMessageToHandler(MSG_TYPE_DEVICE_DISCONNECT, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post device disconnect fail");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}
@ -1312,7 +1312,7 @@ int32_t LnnNotifyEmptySessionKey(int64_t authId)
if (PostBuildMessageToHandler(MSG_TYPE_LEAVE_BY_AUTH_ID, para) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "post empty sessionKey msg fail");
SoftBusFree(para);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_POST_MSG_FAIL;
}
return SOFTBUS_OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -218,7 +218,7 @@ int32_t PostJoinRequestToConnFsm(LnnConnectionFsm *connFsm, const JoinLnnMsgPara
--LnnGetNetBuilder()->connCount;
LnnDestroyConnectionFsm(connFsm);
}
rc = SOFTBUS_ERR;
rc = SOFTBUS_NETWORK_JOIN_REQUEST_ERR;
}
if (rc == SOFTBUS_OK) {
connFsm->connInfo.infoReport = para->infoReport;
@ -499,33 +499,40 @@ static void NetBuilderConfigInit(void)
static int32_t InitNodeInfoSync(void)
{
if (LnnInitP2p() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init lnn p2p fail");
return SOFTBUS_ERR;
int32_t rc = LnnInitP2p();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init lnn p2p fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitNetworkInfo() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitNetworkInfo fail");
return SOFTBUS_ERR;
rc = LnnInitNetworkInfo();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitNetworkInfo fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitDevicename() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitDeviceName fail");
return SOFTBUS_ERR;
rc = LnnInitDevicename();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitDeviceName fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitOffline() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitOffline fail");
return SOFTBUS_ERR;
rc = LnnInitOffline();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitOffline fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitBatteryInfo() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitBatteryInfo fail");
return SOFTBUS_ERR;
rc = LnnInitBatteryInfo();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitBatteryInfo fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitCipherKeyManager() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitCipherKeyManager fail");
return SOFTBUS_ERR;
rc = LnnInitCipherKeyManager();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "LnnInitCipherKeyManager fail, rc=%{public}d", rc);
return rc;
}
if (LnnInitWifiDirect() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init lnn wifidirect addr fail");
return SOFTBUS_ERR;
rc = LnnInitWifiDirect();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init lnn wifidirect addr fail, rc=%{public}d", rc);
return rc;
}
return SOFTBUS_OK;
}
@ -756,6 +763,21 @@ static int32_t InitNetBuilderLooper(void)
LNN_LOGI(LNN_INIT, "init net builder looper success");
return SOFTBUS_OK;
}
static int32_t InitSyncInfoReg(void)
{
int32_t rc = LnnRegSyncInfoHandler(LNN_INFO_TYPE_MASTER_ELECT, OnReceiveMasterElectMsg);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register sync master elect msg fail, rc=%{public}d", rc);
return rc;
}
rc = LnnRegSyncInfoHandler(LNN_INFO_TYPE_NODE_ADDR, OnReceiveNodeAddrChangedMsg);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register node addr changed msg fail, rc=%{public}d", rc);
return rc;
}
return SOFTBUS_OK;
}
int32_t LnnInitNetBuilder(void)
{
@ -763,9 +785,10 @@ int32_t LnnInitNetBuilder(void)
LNN_LOGI(LNN_INIT, "init net builder repeatly");
return SOFTBUS_OK;
}
if (LnnInitSyncInfoManager() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init sync info manager fail");
return SOFTBUS_ERR;
int32_t rc = LnnInitSyncInfoManager();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "init sync info manager fail, rc=%{public}d", rc);
return rc;
}
LnnInitTopoManager();
UpdateLocalNetCapability();
@ -775,29 +798,29 @@ int32_t LnnInitNetBuilder(void)
if (LnnLinkFinderInit() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "link finder init fail");
}
if (RegAuthVerifyListener(&g_verifyListener) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register auth verify listener fail");
return SOFTBUS_ERR;
rc = RegAuthVerifyListener(&g_verifyListener);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register auth verify listener fail, rc=%{public}d", rc);
return rc;
}
if (LnnRegSyncInfoHandler(LNN_INFO_TYPE_MASTER_ELECT, OnReceiveMasterElectMsg) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register sync master elect msg fail");
return SOFTBUS_ERR;
rc = InitSyncInfoReg();
if (rc != SOFTBUS_OK) {
return rc;
}
if (LnnRegSyncInfoHandler(LNN_INFO_TYPE_NODE_ADDR, OnReceiveNodeAddrChangedMsg) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "register node addr changed msg fail");
return SOFTBUS_ERR;
rc = ConifgLocalLedger();
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "config local ledger fail, rc=%{public}d", rc);
return rc;
}
if (ConifgLocalLedger() != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "config local ledger fail");
return SOFTBUS_ERR;
rc = LnnRegisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, AccountStateChangeHandler);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "regist account change evt handler fail, rc=%{public}d", rc);
return rc;
}
if (LnnRegisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, AccountStateChangeHandler) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "regist account change evt handler fail!");
return SOFTBUS_ERR;
}
if (LnnRegisterEventHandler(LNN_EVENT_USER_SWITCHED, UserSwitchedHandler) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "regist user switch evt handler fail!");
return SOFTBUS_ERR;
rc = LnnRegisterEventHandler(LNN_EVENT_USER_SWITCHED, UserSwitchedHandler);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "regist user switch evt handler fail, rc=%{public}d", rc);
return rc;
}
if (!LnnSubcribeKvStoreService()) {
LNN_LOGE(LNN_INIT, "regist kv store service fail!");
@ -817,9 +840,10 @@ int32_t LnnInitNetBuilderDelay(void)
}
LnnSetLocalStrInfo(STRING_KEY_MASTER_NODE_UDID, udid);
LnnSetLocalNumInfo(NUM_KEY_MASTER_NODE_WEIGHT, LnnGetLocalWeight());
if (LnnInitFastOffline() != SOFTBUS_OK) {
ret = LnnInitFastOffline();
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "fast offline init fail!");
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -204,19 +204,20 @@ static int32_t CreatePassiveConnectionFsm(const DeviceVerifyPassMsgPara *msgPara
connFsm = StartNewConnectionFsm(&msgPara->addr, DEFAULT_PKG_NAME, true);
if (connFsm == NULL) {
LNN_LOGE(LNN_BUILDER, "start new connection fsm fail, authId=%{public}" PRId64, msgPara->authHandle.authId);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_FSM_START_FAIL;
}
connFsm->connInfo.authHandle = msgPara->authHandle;
connFsm->connInfo.nodeInfo = msgPara->nodeInfo;
connFsm->connInfo.flag |= LNN_CONN_INFO_FLAG_JOIN_PASSIVE;
LNN_LOGI(LNN_BUILDER, "fsmId=%{public}u start a passive connection fsm, type=%{public}d, authId=%{public}" PRId64,
connFsm->id, msgPara->authHandle.type, msgPara->authHandle.authId);
if (LnnSendAuthResultMsgToConnFsm(connFsm, SOFTBUS_OK) != SOFTBUS_OK) {
int32_t ret = LnnSendAuthResultMsgToConnFsm(connFsm, SOFTBUS_OK);
if (ret != SOFTBUS_OK) {
connFsm->connInfo.nodeInfo = NULL;
StopConnectionFsm(connFsm);
LNN_LOGE(LNN_BUILDER, "fsmId=%{public}u post auth result to connection fsm fail, authId=%{public}" PRId64,
connFsm->id, msgPara->authHandle.authId);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -261,7 +262,7 @@ static int32_t ProcessCleanConnectionFsm(const void *para)
{
uint16_t connFsmId;
LnnConnectionFsm *connFsm = NULL;
int32_t rc = SOFTBUS_ERR;
int32_t rc = SOFTBUS_NETWORK_FSM_CLEAN_FAILED;
if (para == NULL) {
LNN_LOGW(LNN_BUILDER, "connFsmId is null");
@ -310,19 +311,18 @@ static int32_t ProcessVerifyResult(const void *para)
if (msgPara->nodeInfo == NULL) {
LNN_LOGE(LNN_BUILDER, "msgPara node Info is null, stop fsm [id=%{public}u]", connFsm->id);
StopConnectionFsm(connFsm);
rc = SOFTBUS_ERR;
rc = SOFTBUS_INVALID_PARAM;
break;
}
connFsm->connInfo.authHandle = msgPara->authHandle;
connFsm->connInfo.nodeInfo = msgPara->nodeInfo;
}
if (LnnSendAuthResultMsgToConnFsm(connFsm, msgPara->retCode) != SOFTBUS_OK) {
rc = LnnSendAuthResultMsgToConnFsm(connFsm, msgPara->retCode);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send auth result to connection failed. [id=%{public}u]", connFsm->id);
connFsm->connInfo.nodeInfo = NULL;
rc = SOFTBUS_ERR;
break;
}
rc = SOFTBUS_OK;
} while (false);
if (rc != SOFTBUS_OK && msgPara->nodeInfo != NULL) {
@ -364,7 +364,7 @@ static int32_t ProcessDeviceVerifyPass(const void *para)
}
LNN_LOGI(LNN_BUILDER, "fsmId=%{public}u connection fsm exist, ignore VerifyPass authId=%{public}" PRId64,
connFsm->id, msgPara->authHandle.authId);
rc = SOFTBUS_ERR;
rc = SOFTBUS_ALREADY_EXISTED;
} while (false);
if (rc != SOFTBUS_OK && msgPara->nodeInfo != NULL) {
@ -394,12 +394,11 @@ static int32_t ProcessDeviceDisconnect(const void *para)
}
LNN_LOGI(LNN_BUILDER, "fsmId=%{public}u device disconnect, authId=%{public}" PRId64,
connFsm->id, authHandle->authId);
if (LnnSendDisconnectMsgToConnFsm(connFsm) != SOFTBUS_OK) {
rc = LnnSendDisconnectMsgToConnFsm(connFsm);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send disconnect to connection failed. fsmId=%{public}u", connFsm->id);
rc = SOFTBUS_ERR;
break;
}
rc = SOFTBUS_OK;
} while (false);
SoftBusFree((void *)authHandle);
return rc;
@ -442,7 +441,7 @@ static int32_t ProcessLeaveLNNRequest(const void *para)
{
const char *networkId = (const char *)para;
LnnConnectionFsm *item = NULL;
int rc = SOFTBUS_ERR;
int rc = SOFTBUS_NETWORK_NOT_FOUND;
if (networkId == NULL) {
LNN_LOGW(LNN_BUILDER, "leave networkId is null");
@ -453,10 +452,10 @@ static int32_t ProcessLeaveLNNRequest(const void *para)
if (strcmp(networkId, item->connInfo.peerNetworkId) != 0 || item->isDead) {
continue;
}
if (LnnSendLeaveRequestToConnFsm(item) != SOFTBUS_OK) {
rc = LnnSendLeaveRequestToConnFsm(item);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send leave LNN msg to connection failed. fsmId=%{public}u", item->id);
} else {
rc = SOFTBUS_OK;
item->connInfo.flag |= LNN_CONN_INFO_FLAG_LEAVE_REQUEST;
LNN_LOGI(LNN_BUILDER, "send leave LNN msg to connection success. fsmId=%{public}u", item->id);
}
@ -515,7 +514,7 @@ static int32_t ProcessLeaveInvalidConn(const void *para)
if (strncpy_s(item->connInfo.cleanInfo->networkId, NETWORK_ID_BUF_LEN,
msgPara->newNetworkId, strlen(msgPara->newNetworkId)) != EOK) {
LNN_LOGE(LNN_BUILDER, "copy new networkId failed. fsmId=%{public}u", item->id);
rc = SOFTBUS_ERR;
rc = SOFTBUS_STRCPY_ERR;
SoftBusFree(item->connInfo.cleanInfo);
item->connInfo.cleanInfo = NULL;
continue;
@ -542,7 +541,7 @@ static int32_t ProcessNodeStateChanged(const void *para)
{
const ConnectionAddr *addr = (const ConnectionAddr *)para;
LnnConnectionFsm *connFsm = NULL;
int32_t rc = SOFTBUS_ERR;
int32_t rc = SOFTBUS_NETWORK_NOT_FOUND;
bool isOnline = false;
if (addr == NULL) {
@ -578,7 +577,7 @@ static int32_t ProcessMasterElect(const void *para)
char localMasterUdid[UDID_BUF_LEN] = { 0 };
int32_t localMasterWeight;
int32_t compareRet;
int32_t rc = SOFTBUS_ERR;
int32_t rc = SOFTBUS_NETWORK_NOT_FOUND;
if (msgPara == NULL) {
LNN_LOGW(LNN_BUILDER, "elect msg para is null");
@ -727,9 +726,9 @@ static int32_t ProcessLeaveByAuthId(const void *para)
continue;
}
LNN_LOGI(LNN_BUILDER, "[id=%{public}u]leave reqeust, authId: %{public}" PRId64, item->id, *authId);
if (LnnSendLeaveRequestToConnFsm(item) != SOFTBUS_OK) {
rc = LnnSendLeaveRequestToConnFsm(item);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send leaveReqeust to connection fsm[id=%{public}u] failed", item->id);
rc = SOFTBUS_ERR;
}
}
SoftBusFree((void *) authId);

View File

@ -180,6 +180,7 @@ enum SoftBusErrNo {
SOFTBUS_DEFLATE_FAIL,
SOFTBUS_INFLATE_FAIL,
SOFTBUS_GET_IRK_FAIL,
SOFTBUS_SPLIT_STRING_FAIL,
/* errno begin: -((203 << 21) | (5 << 16) | 0xFFFF) */
SOFTBUS_TRANS_ERR_BASE = SOFTBUS_ERRNO(TRANS_SUB_MODULE_CODE),
@ -678,6 +679,8 @@ enum SoftBusErrNo {
SOFTBUS_NETWORK_REGISTER_MLPS_LISTENER_FAILED,
SOFTBUS_NETWORK_REGISTER_SERVICE_FAILED,
SOFTBUS_NETWORK_UNREGISTER_SERVICE_FAILED,
SOFTBUS_NETWORK_FSM_CLEAN_FAILED,
SOFTBUS_KV_IGNORE_OLD_DEVICE_INFO,
/* errno begin: -((203 << 21) | (4 << 16) | (1 << 12) | 0x0FFF) */
SOFTBUS_LANE_ERR_BASE = SOFTBUS_SUB_ERRNO(LNN_SUB_MODULE_CODE, LNN_LANE_MODULE_CODE),

View File

@ -369,7 +369,7 @@ HWTEST_F(LNNDataCloudSyncMockTest, HandleDBAddChangeInternal_Test_001, TestSize.
NodeInfo cacheInfo;
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
EXPECT_EQ(HandleDBAddChangeInternal(key, value, &cacheInfo), SOFTBUS_ERR);
EXPECT_EQ(HandleDBAddChangeInternal(key, value, &cacheInfo), SOFTBUS_ERR);
EXPECT_EQ(HandleDBAddChangeInternal(key, value, &cacheInfo), SOFTBUS_INVALID_PARAM);
}
/*
@ -381,13 +381,13 @@ HWTEST_F(LNNDataCloudSyncMockTest, HandleDBAddChangeInternal_Test_001, TestSize.
HWTEST_F(LNNDataCloudSyncMockTest, SetDBNameDataToDLedger_Test_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> NetLedgerMock;
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceInfoName).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceInfoName).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetLedgerMock, LnnSetDLUnifiedDeviceName).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLUnifiedDeviceName).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetLedgerMock, LnnSetDLUnifiedDefaultDeviceName).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLUnifiedDefaultDeviceName).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceNickNameByUdid).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceNickNameByUdid).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
NodeInfo cacheInfo;
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
@ -395,15 +395,15 @@ HWTEST_F(LNNDataCloudSyncMockTest, SetDBNameDataToDLedger_Test_001, TestSize.Lev
char fieldName[FIELDNAME_MAX_LEN] = { 0 };
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_DEVICE_NAME));
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_OK);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_UNIFIED_DEVICE_NAME));
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_UNIFIED_DEFAULT_DEVICE_NAME));
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_SETTINGS_NICK_NAME));
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_NETWORK_SET_LEDGER_INFO_ERR);
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_DISTRIBUTED_SWITCH));
EXPECT_EQ(SetDBNameDataToDLedger(&cacheInfo, deviceUdid, fieldName), SOFTBUS_OK);
@ -418,30 +418,30 @@ HWTEST_F(LNNDataCloudSyncMockTest, SetDBNameDataToDLedger_Test_001, TestSize.Lev
HWTEST_F(LNNDataCloudSyncMockTest, SetDBDataToDistributedLedger_Test_001, TestSize.Level1)
{
NiceMock<LnnNetLedgertInterfaceMock> NetLedgerMock;
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceBroadcastCipherKey).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceBroadcastCipherKey).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceBroadcastCipherIv).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceBroadcastCipherIv).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceStateVersion).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(NetLedgerMock, LnnSetDLDeviceStateVersion).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillRepeatedly(Return(SOFTBUS_OK));
NiceMock<LnnDataCloudSyncInterfaceMock> DataCloudSyncMock;
EXPECT_CALL(DataCloudSyncMock, LnnUpdateNetworkId).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(DataCloudSyncMock, LnnUpdateNetworkId).WillOnce(Return(SOFTBUS_MEM_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
NodeInfo cacheInfo;
(void)memset_s(&cacheInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
char deviceUdid[UDID_BUF_LEN] = { 0 };
char fieldName[FIELDNAME_MAX_LEN] = { 0 };
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_BROADCAST_CIPHER_KEY));
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_NOT_FIND);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_BROADCAST_CIPHER_IV));
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_NOT_FIND);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_NETWORK_ID));
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_MEM_ERR);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_STATE_VERSION));
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_ERR);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_NOT_FIND);
EXPECT_EQ(SetDBDataToDistributedLedger(&cacheInfo, deviceUdid, 0, fieldName), SOFTBUS_OK);
EXPECT_EQ(EOK, strcpy_s(fieldName, FIELDNAME_MAX_LEN, DEVICE_INFO_DISTRIBUTED_SWITCH));
const char *value = "value";
@ -486,7 +486,7 @@ HWTEST_F(LNNDataCloudSyncMockTest, IsIgnoreUpdate_Test_001, TestSize.Level1)
HWTEST_F(LNNDataCloudSyncMockTest, HandleDBUpdateInternal_Test_001, TestSize.Level1)
{
NiceMock<LnnDataCloudSyncInterfaceMock> DataCloudSyncMock;
EXPECT_CALL(DataCloudSyncMock, LnnGenerateHexStringHash).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(DataCloudSyncMock, LnnGenerateHexStringHash).WillOnce(Return(SOFTBUS_ENCRYPT_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(DataCloudSyncMock, LnnRetrieveDeviceInfo).WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
@ -496,7 +496,8 @@ HWTEST_F(LNNDataCloudSyncMockTest, HandleDBUpdateInternal_Test_001, TestSize.Lev
CloudSyncValue parseValue;
char trueValue[SPLIT_MAX_LEN] = { 0 };
int32_t localStateVersion = 0;
EXPECT_EQ(HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localStateVersion), SOFTBUS_ERR);
EXPECT_EQ(HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localStateVersion),
SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR);
EXPECT_EQ(HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localStateVersion), SOFTBUS_OK);
EXPECT_EQ(HandleDBUpdateInternal(deviceUdid, fieldName, trueValue, &parseValue, localStateVersion), SOFTBUS_OK);
EXPECT_EQ(HandleDBUpdateInternal(nullptr, fieldName, trueValue, &parseValue, localStateVersion),
@ -552,7 +553,7 @@ HWTEST_F(LNNDataCloudSyncMockTest, LnnDBDataChangeSyncToCacheInner_Test_001, Tes
const char *key = "key";
const char *value = TMPMSG;
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_ERR);
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_ERR);
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_NETWORK_GENERATE_STR_HASH_ERR);
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_ERR);
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_OK);
EXPECT_EQ(LnnDBDataChangeSyncToCacheInner(key, value), SOFTBUS_OK);

View File

@ -110,11 +110,11 @@ HWTEST_F(LNNDataCloudSyncTest, LnnDBDataChangeSyncToCache_Test_003, TestSize.Lev
int32_t ret = LnnDBDataChangeSyncToCache(key, value, type);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = LnnDBDataChangeSyncToCache(RIGHT_KEY, value, type);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = LnnDBDataChangeSyncToCache(RIGHT_KEY, VALUE, type);
NodeInfo localCaheInfo;
if (LnnGetLocalCacheNodeInfo(&localCaheInfo) == SOFTBUS_NOT_IMPLEMENT) {
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_NOT_IMPLEMENT);
} else {
EXPECT_EQ(ret, SOFTBUS_OK);
}

View File

@ -132,14 +132,15 @@ HWTEST_F(LNNDeviceNameInfoTest, LNN_SYNC_DEVICE_NAME_TEST_001, TestSize.Level1)
EXPECT_CALL(ledgerMock, LnnGetDeviceName).WillOnce(Return(DEVICE_NAME1))
.WillRepeatedly(Return(DEVICE_NAME2));
NiceMock<LnnSyncInfoInterfaceMock> lnnSyncInfoMock;
EXPECT_CALL(lnnSyncInfoMock, LnnSendSyncInfoMsg).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(lnnSyncInfoMock, LnnSendSyncInfoMsg)
.WillOnce(Return(SOFTBUS_NETWORK_SEND_SYNC_INFO_FAILED))
.WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnSyncDeviceName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_TRUE(ret == SOFTBUS_NETWORK_GET_LOCAL_NODE_INFO_ERR);
ret = LnnSyncDeviceName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_TRUE(ret == SOFTBUS_NETWORK_GET_DEVICE_INFO_ERR);
ret = LnnSyncDeviceName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_TRUE(ret == SOFTBUS_NETWORK_SEND_SYNC_INFO_FAILED);
ret = LnnSyncDeviceName(NETWORKID);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
@ -222,10 +223,10 @@ HWTEST_F(LNNDeviceNameInfoTest, NOTIFY_DEVICE_DISPLAY_NAME_CHANGE_TEST_001, Test
HWTEST_F(LNNDeviceNameInfoTest, LNN_INIT_DEVICE_NAME_TEST_001, TestSize.Level1)
{
NiceMock<LnnSyncInfoInterfaceMock> lnnSyncInfoMock;
EXPECT_CALL(lnnSyncInfoMock, LnnRegSyncInfoHandler).WillOnce(Return(SOFTBUS_ERR))
EXPECT_CALL(lnnSyncInfoMock, LnnRegSyncInfoHandler).WillOnce(Return(SOFTBUS_LOCK_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = LnnInitDevicename();
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
ret = LnnInitDevicename();
EXPECT_EQ(ret, SOFTBUS_OK);
ret = LnnInitDevicename();

View File

@ -119,7 +119,7 @@ HWTEST_F(LNNNetBuilderMockTest, LNN_INIT_NET_BUILDER_TEST_001, TestSize.Level1)
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_NOT_FIND);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_LOOPER_ERR);
}
@ -403,7 +403,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_ELETE_TEST_001, TestSize.Level1)
EXPECT_TRUE(ProcessMasterElect(nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnInitBusCenterEvent() == SOFTBUS_OK);
EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_OK);
EXPECT_TRUE(ProcessMasterElect(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessMasterElect(para) == SOFTBUS_NETWORK_NOT_FOUND);
LnnDeinitNetBuilder();
LnnDeinitBusCenterEvent();
}
@ -420,7 +420,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_NODE_STATE_CHANGED_TEST_001, TestSize.Le
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_TRUE(ProcessNodeStateChanged(nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(ProcessNodeStateChanged(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessNodeStateChanged(para) == SOFTBUS_NETWORK_NOT_FOUND);
}
/*
@ -616,10 +616,10 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_001, TestSize.Lev
{
void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_ERR));
EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_NETWORK_NOT_FOUND));
EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
EXPECT_TRUE(ProcessLeaveLNNRequest(nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_NETWORK_NOT_FOUND);
}
/*
@ -705,7 +705,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_CLEAN_CONNECTION_FSM_TEST_001, TestSize.
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_TRUE(ProcessCleanConnectionFsm(nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(ProcessCleanConnectionFsm(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessCleanConnectionFsm(para) == SOFTBUS_NETWORK_FSM_CLEAN_FAILED);
}
/*
@ -1105,7 +1105,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_002, TestSize.Le
g_netBuilder.connCount = CURRENT_COUNT;
g_netBuilder.maxConnCount = CONN_COUNT;
void *para = reinterpret_cast<void *>(msgPara);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_NETWORK_FSM_START_FAIL);
ListDelete(&connFsm->node);
SoftBusFree(connFsm);
}
@ -1135,7 +1135,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_003, TestSize.Le
g_netBuilder.connCount = CURRENT_COUNT;
g_netBuilder.maxConnCount = CONN_COUNT;
void *para = reinterpret_cast<void *>(msgPara);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_NETWORK_FSM_START_FAIL);
ListDelete(&connFsm->node);
SoftBusFree(connFsm);
}
@ -1163,7 +1163,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_004, TestSize.Le
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
void *para = reinterpret_cast<void *>(msgPara);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessDeviceVerifyPass(para) != SOFTBUS_OK);
ListDelete(&connFsm->node);
SoftBusFree(connFsm);
}
@ -1211,7 +1211,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_002, TestSize.Lev
void *para = reinterpret_cast<void *>(msgPara);
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_NETWORK_NOT_FOUND);
ListDelete(&connFsm->node);
SoftBusFree(connFsm);
}
@ -1236,7 +1236,7 @@ HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_003, TestSize.Lev
void *para = reinterpret_cast<void *>(msgPara);
NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_NETWORK_NOT_FOUND);
ListDelete(&connFsm->node);
SoftBusFree(connFsm);
}
@ -1440,7 +1440,7 @@ HWTEST_F(LNNNetBuilderMockTest, TRY_SEND_JOIN_LNN_REQUEST_TEST_001, TestSize.Lev
para->dupInfo = NULL;
(void)strcpy_s(para->pkgName, PKG_NAME_SIZE_MAX, "pkgName");
EXPECT_TRUE(TrySendJoinLNNRequest(nullptr, true, false) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_ERR);
EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_NETWORK_JOIN_REQUEST_ERR);
DfxRecordLnnAuthStart(nullptr, para, 0);
ListDelete(&connFsm->node);
@ -1824,14 +1824,14 @@ HWTEST_F(LNNNetBuilderMockTest, CREATE_PASSIVE_CONNECTION_FSM_TEST_001, TestSize
(void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE2_BR_MAC);
connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
EXPECT_CALL(NetBuilderMock, LnnCreateConnectionFsm).WillRepeatedly(Return(connFsm));
EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_NETWORK_FSM_START_FAIL));
EXPECT_CALL(NetBuilderMock, LnnDestroyConnectionFsm).WillRepeatedly(Return());
fsm = StartNewConnectionFsm(&addr, pkgName, false);
EXPECT_TRUE(fsm == nullptr);
DeviceVerifyPassMsgPara msgPara;
EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_NETWORK_FSM_START_FAIL));
int32_t ret = CreatePassiveConnectionFsm(&msgPara);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_NETWORK_FSM_START_FAIL);
ClearNetBuilderFsmList();
}