• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <pthread.h>
20 #include <stdint.h>
21 
22 #include "bus_center_info_key.h"
23 #include "lnn_node_info.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define INT_TO_STR_SIZE 12
30 #define INVALID_CONNECTION_CODE_VALUE -1
31 #define SHORT_UDID_HASH_LEN 8
32 typedef struct {
33     InfoKey key;
34     int32_t (*getInfo)(const char *netWorkId, void *info, uint32_t len);
35 } DistributedLedgerKey;
36 
37 typedef enum {
38     CATEGORY_UDID,
39     CATEGORY_UUID,
40     CATEGORY_NETWORK_ID,
41 } IdCategory;
42 
43 typedef enum {
44     REPORT_NONE,
45     REPORT_CHANGE,
46     REPORT_ONLINE,
47     REPORT_OFFLINE,
48 } ReportCategory;
49 
50 int32_t LnnInitDistributedLedger(void);
51 void LnnDeinitDistributedLedger(void);
52 
53 ReportCategory LnnAddOnlineNode(NodeInfo *info);
54 ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int32_t authId);
55 void LnnRemoveNode(const char *udid);
56 NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
57 bool LnnSetDLDeviceInfoName(const char *udid, const char *name);
58 bool LnnSetDLP2pInfo(const char *networkId, const P2pInfo *info);
59 const char *LnnConvertDLidToUdid(const char *id, IdCategory type);
60 int32_t LnnConvertDlId(const char *srcId, IdCategory srcIdType, IdCategory dstIdType,
61     char *dstIdBuf, uint32_t dstIdBufLen);
62 short LnnGetCnnCode(const char *uuid, DiscoveryType type);
63 int32_t LnnGetBasicInfoByUdid(const char *udid, NodeBasicInfo *basicInfo);
64 int32_t LnnGetLaneCount(int32_t laneId);
65 int32_t LnnSetLaneCount(int32_t laneId, int32_t num);
66 int32_t LnnGetDLHeartbeatTimestamp(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, uint64_t connCapability);
71 int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, const char *addr);
72 int32_t LnnGetAllAuthSeq(const char *udid, int64_t *authSeq, uint32_t num);
73 const NodeInfo *LnnGetOnlineNodeByUdidHash(const char *recvUdidHash);
74 void LnnRefreshDeviceOnlineStateAndDevIdInfo(const char *pkgName, DeviceInfo *device,
75     const InnerDeviceInfoAddtions *addtions);
76 int32_t LnnUpdateNodeInfo(NodeInfo *newInfo);
77 int32_t LnnAddMetaInfo(NodeInfo *info);
78 int32_t LnnDeleteMetaInfo(const char *udid, ConnectionAddrType type);
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif // LNN_DISTRIBUTED_NET_LEDGER_H