1 /* 2 * Copyright (c) 2021 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_H 17 #define LNN_DISTRIBUTED_NET_LEDGER_H 18 19 #include "auth_interface.h" 20 #include "bus_center_info_key.h" 21 #include "lnn_node_info.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define INT_TO_STR_SIZE 12 28 #define INVALID_CONNECTION_CODE_VALUE -1 29 #define SHORT_UDID_HASH_LEN 8 30 typedef struct { 31 InfoKey key; 32 int32_t (*getInfo)(const char *netWorkId, void *info, uint32_t len); 33 } DistributedLedgerKey; 34 35 typedef enum { 36 CATEGORY_UDID, 37 CATEGORY_UUID, 38 CATEGORY_NETWORK_ID, 39 } IdCategory; 40 41 typedef enum { 42 REPORT_NONE, 43 REPORT_CHANGE, 44 REPORT_ONLINE, 45 REPORT_OFFLINE, 46 } ReportCategory; 47 48 int32_t LnnInitDistributedLedger(void); 49 void LnnDeinitDistributedLedger(void); 50 51 ReportCategory LnnAddOnlineNode(NodeInfo *info); 52 ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int32_t authId); 53 int32_t LnnSetAuthTypeValue(uint32_t *authTypeValue, AuthType type); 54 int32_t LnnClearAuthTypeValue(uint32_t *authTypeValue, AuthType type); 55 void LnnRemoveNode(const char *udid); 56 int32_t LnnGetRemoteNodeInfoById(const char *id, IdCategory type, NodeInfo *info); 57 int32_t LnnGetRemoteNodeInfoByKey(const char *key, NodeInfo *info); /* key means udid/uuid/networkId/macAddr/ip */ 58 bool LnnSetDLDeviceInfoName(const char *udid, const char *name); 59 bool LnnSetDLP2pInfo(const char *networkId, const P2pInfo *info); 60 const char *LnnConvertDLidToUdid(const char *id, IdCategory type); 61 int32_t LnnConvertDlId(const char *srcId, IdCategory srcIdType, IdCategory dstIdType, 62 char *dstIdBuf, uint32_t dstIdBufLen); 63 short LnnGetCnnCode(const char *uuid, DiscoveryType type); 64 int32_t LnnGetBasicInfoByUdid(const char *udid, NodeBasicInfo *basicInfo); 65 int32_t LnnGetDLHeartbeatTimestamp(const char *networkId, uint64_t *timestamp); 66 int32_t LnnGetDLOnlineTimestamp(const char *networkId, uint64_t *timestamp); 67 int32_t LnnSetDLHeartbeatTimestamp(const char *networkId, const uint64_t timestamp); 68 bool LnnGetOnlineStateById(const char *id, IdCategory type); 69 int32_t LnnGetLnnRelation(const char *id, IdCategory type, uint8_t *relation, uint32_t len); 70 int32_t LnnSetDLConnCapability(const char *networkId, uint32_t connCapability); 71 int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, const char *addr); 72 int32_t LnnSetDLBatteryInfo(const char *networkId, const BatteryInfo *info); 73 int32_t LnnSetDLBssTransInfo(const char *networkId, const BssTransInfo *info); 74 int32_t LnnGetAllAuthSeq(const char *udid, int64_t *authSeq, uint32_t num); 75 const NodeInfo *LnnGetOnlineNodeByUdidHash(const char *recvUdidHash); 76 void LnnRefreshDeviceOnlineStateAndDevIdInfo(const char *pkgName, DeviceInfo *device, 77 const InnerDeviceInfoAddtions *addtions); 78 int32_t LnnUpdateNodeInfo(NodeInfo *newInfo); 79 int32_t LnnAddMetaInfo(NodeInfo *info); 80 int32_t LnnDeleteMetaInfo(const char *udid, ConnectionAddrType type); 81 int32_t LnnUpdateGroupType(const NodeInfo *info); 82 int32_t LnnUpdateAccountInfo(const NodeInfo *info); 83 int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort); 84 int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort); 85 int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort); 86 NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type); 87 #ifdef __cplusplus 88 } 89 #endif 90 91 #endif // LNN_DISTRIBUTED_NET_LEDGER_H