1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LNN_DISTRIBUTED_NET_LEDGER_COMMON_H 17 #define LNN_DISTRIBUTED_NET_LEDGER_COMMON_H 18 19 #include "lnn_distributed_net_ledger.h" 20 #include "lnn_map.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define TIME_THOUSANDS_FACTOR (1000) 27 #define BLE_ADV_LOST_TIME 5000 28 #define LONG_TO_STRING_MAX_LEN 21 29 #define LNN_COMMON_LEN_64 8 30 #define SOFTBUS_BUSCENTER_DUMP_REMOTEDEVICEINFO "remote_device_info" 31 32 #define AONYMIZE(log, key) \ 33 do { \ 34 char *anonyKey = NULL; \ 35 Anonymize(key, &anonyKey); \ 36 LNN_LOGE(LNN_LEDGER, log, anonyKey); \ 37 AnonymizeFree(anonyKey); \ 38 } while (0) \ 39 40 #define GET_NODE(networkId, info) \ 41 do { \ 42 (info) = LnnGetNodeInfoById((networkId), (CATEGORY_NETWORK_ID)); \ 43 if ((info) == NULL) { \ 44 AONYMIZE("get node info fail. networkId=%{public}s", networkId); \ 45 return SOFTBUS_ERR; \ 46 } \ 47 } while (0) \ 48 49 #define RETURN_IF_GET_NODE_VALID(networkId, buf, info) \ 50 do { \ 51 if ((networkId) == NULL || (buf) == NULL) { \ 52 LNN_LOGE(LNN_LEDGER, "networkId or buf is invalid"); \ 53 return SOFTBUS_INVALID_PARAM; \ 54 } \ 55 GET_NODE(networkId, info); \ 56 } while (0) \ 57 58 #define CONNECTION_FREEZE_TIMEOUT_MILLIS (10 * 1000) 59 60 // softbus version for support initConnectFlag 61 #define SOFTBUS_VERSION_FOR_INITCONNECTFLAG "11.1.0.001" 62 63 typedef struct { 64 Map udidMap; 65 Map ipMap; 66 Map macMap; 67 } DoubleHashMap; 68 69 typedef enum { 70 DL_INIT_UNKNOWN = 0, 71 DL_INIT_FAIL, 72 DL_INIT_SUCCESS, 73 } DistributedLedgerStatus; 74 75 typedef struct { 76 Map connectionCode; 77 } ConnectionCode; 78 79 typedef struct { 80 DoubleHashMap distributedInfo; 81 ConnectionCode cnnCode; 82 int32_t countMax; 83 SoftBusMutex lock; 84 DistributedLedgerStatus status; 85 } DistributedNetLedger; 86 87 typedef struct { 88 bool isOffline; 89 bool oldWifiFlag; 90 bool oldBrFlag; 91 bool oldBleFlag; 92 bool isChanged; 93 bool isMigrateEvent; 94 bool isNetworkChanged; 95 bool newWifiFlag; 96 bool newBleBrFlag; 97 } NodeInfoAbility; 98 99 NodeInfo *GetNodeInfoFromMap(const DoubleHashMap *map, const char *id); 100 bool IsMetaNode(NodeInfo *info); 101 DistributedNetLedger* LnnGetDistributedNetLedger(void); 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif // LNN_DISTRIBUTED_NET_LEDGER_COMMON_H