!3778 异构路由需求的权限相关配置修改合入

Merge pull request !3778 from 郭春婷/songxinyi
This commit is contained in:
openharmony_ci 2023-07-04 03:41:00 +00:00 committed by Gitee
commit 032c37ac4d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
74 changed files with 735 additions and 189 deletions

View File

@ -47,6 +47,7 @@ extern "C" {
int32_t SoftBusReadFile(int32_t fd, void *readBuf, uint32_t maxLen);
int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen);
int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len);
int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len);
int32_t SoftBusOpenFile(const char *fileName, int32_t flags);
int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t perms);
void SoftBusRemoveFile(const char *fileName);

View File

@ -85,6 +85,14 @@ int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t le
return SOFTBUS_OK;
}
int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len)
{
(void)fd;
(void)writeBuf;
(void)len;
return SOFTBUS_INVALID_FD;
}
int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
{
(void)fileName;

View File

@ -138,6 +138,18 @@ int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t le
return SOFTBUS_OK;
}
int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len)
{
if (writeBuf == NULL || len == 0) {
return SOFTBUS_FILE_ERR;
}
int32_t ret = write(fd, writeBuf, len);
if (ret != (int32_t)len) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "WriteFileFd write fail");
}
return ret;
}
int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
{
if (fileName == NULL) {

View File

@ -59,6 +59,7 @@ bool CheckActiveAuthConnection(const AuthConnInfo *connInfo);
const char *GetConnTypeStr(uint64_t connId);
uint32_t GetConnId(uint64_t connId);
int32_t GetConnType(uint64_t connId);
uint64_t GenConnId(int32_t connType, int32_t id);
uint32_t GetAuthDataSize(uint32_t len);
int32_t PackAuthData(const AuthDataHead *head, const uint8_t *data, uint8_t *buf, uint32_t size);

View File

@ -61,7 +61,7 @@ void AuthManagerSetAuthFinished(int64_t authSeq, const AuthSessionInfo *info);
/* Note: must call DelAuthManager to free. */
AuthManager *GetAuthManagerByAuthId(int64_t authId);
void DelAuthManager(AuthManager *auth, bool removeAuthFromList);
void RemoveAuthManagerByAuthId(int64_t authId);
int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback);
int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo);
void AuthDeviceCloseConn(int64_t authId);
@ -71,6 +71,7 @@ int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo);
int64_t AuthDeviceGetLatestIdByUuid(const char *uuid, bool isIpConnection);
int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer);
int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer);
AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info);
int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen);
int32_t AuthDeviceDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen);

View File

@ -29,21 +29,23 @@ extern "C" {
#define AUTH_INVALID_FD (-1)
typedef struct {
void (*onConnected)(int32_t fd, bool isClient);
void (*onConnected)(ListenerModule module, int32_t fd, bool isClient);
void (*onDisconnected)(int32_t fd);
void (*onDataReceived)(int32_t fd, const AuthDataHead *head, const uint8_t *data);
void (*onDataReceived)(ListenerModule module, int32_t fd, const AuthDataHead *head, const uint8_t *data);
} SocketCallback;
int32_t SetSocketCallback(const SocketCallback *cb);
void UnsetSocketCallback(void);
// connect succ, return fd; otherwise, return -1.
int32_t SocketConnectDevice(const char *ip, int32_t port, bool isBlockMode);
void SocketDisconnectDevice(int32_t fd);
int32_t NipSocketConnectDevice(ListenerModule module, const char *addr, int32_t port, bool isBlockMode);
void SocketDisconnectDevice(ListenerModule module, int32_t fd);
int32_t SocketPostBytes(int32_t fd, const AuthDataHead *head, const uint8_t *data);
int32_t SocketGetConnInfo(int32_t fd, AuthConnInfo *connInfo, bool *isServer);
int32_t StartSocketListening(const char *ip, int32_t port);
int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *info);
void StopSocketListening(void);
#ifdef __cplusplus

View File

@ -45,8 +45,16 @@ typedef struct {
static ListNode g_connRequestList = { &g_connRequestList, &g_connRequestList };
static AuthConnListener g_listener = { 0 };
void __attribute__((weak)) RouteBuildClientAuthManager(int32_t cfd)
{
(void)cfd;
}
void __attribute__((weak)) RouteClearAuthChannelId(int32_t cfd)
{
(void)cfd;
}
static uint64_t GenConnId(int32_t connType, int32_t id)
uint64_t GenConnId(int32_t connType, int32_t id)
{
uint64_t connId = (uint64_t)connType;
connId = (connId << INT32_BIT_NUM) & MASK_UINT64_H32;
@ -233,7 +241,7 @@ static void HandleConnConnectTimeout(const void *para)
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "AuthConn: connect timeout, requestId=%u.", requestId);
ConnRequest *item = FindConnRequestByRequestId(requestId);
if (item != NULL) {
SocketDisconnectDevice(item->fd);
SocketDisconnectDevice(AUTH, item->fd);
DelConnRequest(item);
}
NotifyClientConnected(requestId, 0, SOFTBUS_AUTH_CONN_TIMEOUT, NULL);
@ -281,6 +289,7 @@ static void HandleConnConnectResult(const void *para)
{
CHECK_NULL_PTR_RETURN_VOID(para);
int32_t fd = *(int32_t *)(para);
RouteBuildClientAuthManager(fd);
ConnRequest *item = FindConnRequestByFd(fd);
if (item == NULL) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "ConnRequest not found, fd=%d.", fd);
@ -292,7 +301,7 @@ static void HandleConnConnectResult(const void *para)
}
/* WiFi Connection */
static void OnWiFiConnected(int32_t fd, bool isClient)
static void OnWiFiConnected(ListenerModule module, int32_t fd, bool isClient)
{
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "OnWiFiConnected: fd=%d, side=%s.", fd,
isClient ? "client" : "server(ignored)");
@ -310,12 +319,17 @@ static void OnWiFiDisconnected(int32_t fd)
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
connInfo.type = AUTH_LINK_TYPE_WIFI;
NotifyDisconnected(GenConnId(connInfo.type, fd), &connInfo);
RouteClearAuthChannelId(fd);
}
static void OnWiFiDataReceived(int32_t fd, const AuthDataHead *head, const uint8_t *data)
static void OnWiFiDataReceived(ListenerModule module, int32_t fd, const AuthDataHead *head, const uint8_t *data)
{
CHECK_NULL_PTR_RETURN_VOID(head);
CHECK_NULL_PTR_RETURN_VOID(data);
if (module != AUTH && module != AUTH_P2P) {
return;
}
bool fromServer = false;
AuthConnInfo connInfo;
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
@ -590,7 +604,7 @@ NO_SANITIZE("cfi") void DisconnectAuthDevice(uint64_t connId)
GetConnId(connId));
switch (GetConnType(connId)) {
case AUTH_LINK_TYPE_WIFI:
SocketDisconnectDevice(GetFd(connId));
SocketDisconnectDevice(AUTH, GetFd(connId));
break;
case AUTH_LINK_TYPE_BLE:
case AUTH_LINK_TYPE_BR:
@ -662,8 +676,23 @@ NO_SANITIZE("cfi") int32_t AuthStartListening(AuthLinkType type, const char *ip,
}
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "start auth listening, type=%d, port=%d.", type, port);
switch (type) {
case AUTH_LINK_TYPE_WIFI:
return StartSocketListening(ip, port);
case AUTH_LINK_TYPE_WIFI: {
LocalListenerInfo info = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = port,
.moduleId = AUTH,
.protocol = LNN_PROTOCOL_IP,
},
};
if (strcpy_s(info.socketOption.addr, sizeof(info.socketOption.addr), ip) != EOK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "strcpy_s ip fail.");
return SOFTBUS_MEM_ERR;
}
return StartSocketListening(AUTH, &info);
}
case AUTH_LINK_TYPE_P2P: {
LocalListenerInfo local = {
.type = CONNECT_TCP,

View File

@ -44,7 +44,7 @@ static AuthVerifyListener g_verifyListener = { 0 };
static GroupChangeListener g_groupChangeListener = { 0 };
static AuthTransCallback g_transCallback = { 0 };
/* Auth Manager */
static AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
NO_SANITIZE("cfi") AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info)
{
AuthManager *auth = (AuthManager *)SoftBusMalloc(sizeof(AuthManager));
if (auth == NULL) {
@ -210,7 +210,7 @@ static int32_t UpdateAuthManagerByAuthId(
return SOFTBUS_OK;
}
static void RemoveAuthManagerByAuthId(int64_t authId)
NO_SANITIZE("cfi") void RemoveAuthManagerByAuthId(int64_t authId)
{
if (!RequireAuthLock()) {
return;

View File

@ -59,6 +59,12 @@ static SocketCallback g_callback = {NULL, NULL, NULL};
static void NotifyChannelDisconnected(int32_t channelId);
static void NotifyChannelDataReceived(int32_t channelId, const SocketPktHead *head, const uint8_t *data);
int32_t __attribute__((weak)) RouteBuildServerAuthManager(int32_t cfd, const ConnectOption *clientAddr)
{
(void)cfd;
(void)clientAddr;
return SOFTBUS_OK;
}
static uint32_t GetSocketPktSize(uint32_t len)
{
@ -109,10 +115,10 @@ static int32_t UnpackSocketPkt(const uint8_t *data, uint32_t len, SocketPktHead
return SOFTBUS_OK;
}
NO_SANITIZE("cfi") static void NotifyConnected(int32_t fd, bool isClient)
NO_SANITIZE("cfi") static void NotifyConnected(ListenerModule module, int32_t fd, bool isClient)
{
if (g_callback.onConnected != NULL) {
g_callback.onConnected(fd, isClient);
g_callback.onConnected(module, fd, isClient);
}
}
@ -139,7 +145,8 @@ static uint32_t ModuleToDataType(int32_t module)
return DATA_TYPE_CONNECTION;
}
NO_SANITIZE("cfi") static void NotifyDataReceived(int32_t fd, const SocketPktHead *pktHead, const uint8_t *data)
NO_SANITIZE("cfi") static void NotifyDataReceived(ListenerModule module, int32_t fd,
const SocketPktHead *pktHead, const uint8_t *data)
{
if (pktHead->module == MODULE_AUTH_CHANNEL || pktHead->module == MODULE_AUTH_MSG) {
NotifyChannelDataReceived(fd, pktHead, data);
@ -153,18 +160,18 @@ NO_SANITIZE("cfi") static void NotifyDataReceived(int32_t fd, const SocketPktHea
.len = pktHead->len,
};
if (g_callback.onDataReceived != NULL) {
g_callback.onDataReceived(fd, &head, data);
g_callback.onDataReceived(module, fd, &head, data);
}
}
static int32_t RecvPacketHead(int32_t fd, SocketPktHead *head)
static int32_t RecvPacketHead(ListenerModule module, int32_t fd, SocketPktHead *head)
{
uint8_t buf[AUTH_PKT_HEAD_LEN] = {0};
ssize_t len = ConnRecvSocketData(fd, (char *)&buf[0], sizeof(buf), 0);
if (len < AUTH_PKT_HEAD_LEN) {
if (len < 0) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "recv head fail(=%d).", ConnGetSocketError(fd));
(void)DelTrigger(AUTH, fd, READ_TRIGGER);
(void)DelTrigger(module, fd, READ_TRIGGER);
NotifyDisconnected(fd);
}
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "head not enough, len=%d, abandon it.", len);
@ -193,11 +200,11 @@ static uint8_t *RecvPacketData(int32_t fd, uint32_t len)
return data;
}
static int32_t ProcessSocketOutEvent(int32_t fd)
static int32_t ProcessSocketOutEvent(ListenerModule module, int32_t fd)
{
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "socket client connect succ: fd=%d.", fd);
(void)DelTrigger(AUTH, fd, WRITE_TRIGGER);
if (AddTrigger(AUTH, fd, READ_TRIGGER) != SOFTBUS_OK) {
(void)DelTrigger(module, fd, WRITE_TRIGGER);
if (AddTrigger(module, fd, READ_TRIGGER) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "AddTrigger fail.");
goto FAIL;
}
@ -205,20 +212,20 @@ static int32_t ProcessSocketOutEvent(int32_t fd)
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "set none block mode fail.");
goto FAIL;
}
NotifyConnected(fd, true);
NotifyConnected(module, fd, true);
return SOFTBUS_OK;
FAIL:
(void)DelTrigger(AUTH, fd, READ_TRIGGER);
(void)DelTrigger(module, fd, READ_TRIGGER);
ConnShutdownSocket(fd);
NotifyDisconnected(fd);
return SOFTBUS_ERR;
}
static int32_t ProcessSocketInEvent(int32_t fd)
static int32_t ProcessSocketInEvent(ListenerModule module, int32_t fd)
{
SocketPktHead head = {0};
if (RecvPacketHead(fd, &head) != SOFTBUS_OK) {
if (RecvPacketHead(module, fd, &head) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO,
@ -236,15 +243,14 @@ static int32_t ProcessSocketInEvent(int32_t fd)
if (data == NULL) {
return SOFTBUS_ERR;
}
NotifyDataReceived(fd, &head, data);
NotifyDataReceived(module, fd, &head, data);
SoftBusFree(data);
return SOFTBUS_OK;
}
NO_SANITIZE("cfi") static int32_t OnConnectEvent(ListenerModule module, int32_t cfd, const ConnectOption *clientAddr)
NO_SANITIZE("cfi") static int32_t OnConnectEvent(ListenerModule module,
int32_t cfd, const ConnectOption *clientAddr)
{
(void)module;
(void)clientAddr;
if (cfd < 0) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
return SOFTBUS_INVALID_PARAM;
@ -254,12 +260,22 @@ NO_SANITIZE("cfi") static int32_t OnConnectEvent(ListenerModule module, int32_t
ConnShutdownSocket(cfd);
return SOFTBUS_ERR;
}
if (AddTrigger(AUTH, cfd, READ_TRIGGER) != SOFTBUS_OK) {
if (AddTrigger(module, cfd, READ_TRIGGER) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "AddTrigger fail.");
ConnShutdownSocket(cfd);
return SOFTBUS_ERR;
}
NotifyConnected(cfd, false);
if (module != AUTH && module != AUTH_P2P) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "newip auth process");
if (RouteBuildServerAuthManager(cfd, clientAddr) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "build auth manager fail.");
(void)DelTrigger(module, cfd, READ_TRIGGER);
ConnShutdownSocket(cfd);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
NotifyConnected(module, cfd, false);
return SOFTBUS_OK;
}
@ -267,9 +283,9 @@ NO_SANITIZE("cfi") static int32_t OnDataEvent(ListenerModule module, int32_t eve
{
(void)module;
if (events == SOFTBUS_SOCKET_OUT) {
return ProcessSocketOutEvent(fd);
return ProcessSocketOutEvent(module, fd);
} else if (events == SOFTBUS_SOCKET_IN) {
return ProcessSocketInEvent(fd);
return ProcessSocketInEvent(module, fd);
}
return SOFTBUS_ERR;
}
@ -289,28 +305,13 @@ NO_SANITIZE("cfi") void UnsetSocketCallback(void)
(void)memset_s(&g_callback, sizeof(SocketCallback), 0, sizeof(SocketCallback));
}
NO_SANITIZE("cfi") int32_t StartSocketListening(const char *ip, int32_t port)
NO_SANITIZE("cfi") int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *info)
{
CHECK_NULL_PTR_RETURN_VALUE(ip, SOFTBUS_INVALID_PARAM);
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "start socket listening.");
LocalListenerInfo info = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = port,
.moduleId = AUTH,
.protocol = LNN_PROTOCOL_IP
}
};
if (strcpy_s(info.socketOption.addr, sizeof(info.socketOption.addr), ip) != EOK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "strcpy_s ip fail.");
return SOFTBUS_MEM_ERR;
}
SoftbusBaseListener listener = {
.onConnectEvent = OnConnectEvent,
.onDataEvent = OnDataEvent,
};
port = StartBaseListener(&info, &listener);
int32_t port = StartBaseListener(info, &listener);
if (port <= 0) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "StartBaseListener fail(=%d).", port);
return SOFTBUS_ERR;
@ -366,12 +367,48 @@ NO_SANITIZE("cfi") int32_t SocketConnectDevice(const char *ip, int32_t port, boo
return fd;
}
NO_SANITIZE("cfi") void SocketDisconnectDevice(int32_t fd)
NO_SANITIZE("cfi") int32_t NipSocketConnectDevice(ListenerModule module,
const char *addr, int32_t port, bool isBlockMode)
{
ConnectOption option = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = port,
.moduleId = module,
.protocol = LNN_PROTOCOL_NIP
}
};
if (strcpy_s(option.socketOption.addr, sizeof(option.socketOption.addr), addr) != EOK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "copy remote ip fail.");
return AUTH_INVALID_FD;
}
int32_t fd = ConnOpenClientSocket(&option, BIND_ADDR_ALL, !isBlockMode);
if (fd < 0) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "ConnOpenClientSocket fail.");
return AUTH_INVALID_FD;
}
TriggerType triggerMode = isBlockMode ? READ_TRIGGER : WRITE_TRIGGER;
if (AddTrigger(module, fd, triggerMode) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "AddTrigger fail.");
ConnShutdownSocket(fd);
return AUTH_INVALID_FD;
}
if (ConnSetTcpKeepAlive(fd, AUTH_KEEP_ALIVE_TIME_INTERVAL) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "set tcp keep alive fail.");
(void)DelTrigger(module, fd, triggerMode);
ConnShutdownSocket(fd);
return AUTH_INVALID_FD;
}
return fd;
}
NO_SANITIZE("cfi") void SocketDisconnectDevice(ListenerModule module, int32_t fd)
{
if (fd < 0) {
return;
}
(void)DelTrigger(AUTH, fd, RW_TRIGGER);
(void)DelTrigger(module, fd, RW_TRIGGER);
ConnShutdownSocket(fd);
}
@ -523,7 +560,7 @@ NO_SANITIZE("cfi") int32_t AuthOpenChannel(const char *ip, int32_t port)
NO_SANITIZE("cfi") void AuthCloseChannel(int32_t channelId)
{
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "AuthChannel: close auth channel, id=%d.", channelId);
SocketDisconnectDevice(channelId);
SocketDisconnectDevice(AUTH, channelId);
}
NO_SANITIZE("cfi") int32_t AuthPostChannelData(int32_t channelId, const AuthChannelData *data)

View File

@ -74,8 +74,9 @@ int32_t SocketConnectDevice(const char *ip, int32_t port, bool isBlockMode)
return SOFTBUS_NOT_IMPLEMENT;
}
void SocketDisconnectDevice(int32_t fd)
void SocketDisconnectDevice(ListenerModule module, int32_t fd)
{
(void)module;
(void)fd;
return;
}
@ -96,10 +97,10 @@ int32_t SocketGetConnInfo(int32_t fd, AuthConnInfo *connInfo, bool *isServer)
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t StartSocketListening(const char *ip, int32_t port)
int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *info)
{
(void)ip;
(void)port;
(void)module;
(void)info;
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_WARN, "%s not implement.", __func__);
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -112,7 +112,7 @@ if (defined(ohos_lite)) {
}
native_source_path = rebase_path("$dsoftbus_root_path")
agcr_dir = "dsoftbus_enhance/components/agcr"
agcr_dir = "dsoftbus_enhance/components/newip/agcr"
agcr_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
@ -122,8 +122,40 @@ agcr_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
if (agcr_enhanced) {
import(
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/agcr/agcr.gni")
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/agcr/agcr.gni")
bus_center_server_src += agcr_src
bus_center_server_inc += agcr_inc
}
route_dir = "dsoftbus_enhance/components/newip/route"
route_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
"$route_dir",
],
"value")
if (route_enhanced) {
import(
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/route/route.gni")
bus_center_server_src += route_src
bus_center_server_inc += route_inc
}
btn_dir = "dsoftbus_enhance/components/newip/btn"
btn_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
"$btn_dir",
],
"value")
if (btn_enhanced) {
import(
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/btn/btn.gni")
bus_center_server_src += btn_src
bus_center_server_inc += btn_inc
}

View File

@ -69,6 +69,7 @@ int32_t LnnGetLocalNum16Info(InfoKey key, int16_t *info);
int32_t LnnSetLocalNum16Info(InfoKey key, int16_t info);
int32_t LnnSetLocalByteInfo(InfoKey key, const uint8_t *info, uint32_t len);
int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len);
bool LnnIsLSANode(const NodeBasicInfo *info);
int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum);
int32_t LnnGetAllOnlineAndMetaNodeInfo(NodeBasicInfo **info, int32_t *infoNum);
int32_t LnnGetAllOnlineNodeNum(int32_t *nodeNum);

View File

@ -183,6 +183,9 @@ static void HbSendCheckOffLineMessage(LnnHeartbeatType hbType)
return;
}
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
(void)LnnStopScreenChangeOfflineTiming(info[i].networkId, LnnConvertHbTypeToConnAddrType(hbType));
if (LnnStartScreenChangeOfflineTiming(info[i].networkId,
LnnConvertHbTypeToConnAddrType(hbType)) != SOFTBUS_OK) {
@ -355,6 +358,9 @@ static void HbRemoveCheckOffLineMessage(LnnHeartbeatType hbType)
return;
}
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnStopScreenChangeOfflineTiming(info[i].networkId, LnnConvertHbTypeToConnAddrType(hbType)) != SOFTBUS_OK) {
LLOGE("HB stop check offline target msg failed, networkId:%s", AnonymizesNetworkID(info[i].networkId));
}

View File

@ -960,7 +960,6 @@ static int32_t OnCheckDevStatus(FsmStateMachine *fsm, int32_t msgType, void *par
int32_t i, infoNum;
NodeBasicInfo *info = NULL;
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB check dev status get online node info fail");
break;
}
if (info == NULL || infoNum == 0) {
@ -969,6 +968,9 @@ static int32_t OnCheckDevStatus(FsmStateMachine *fsm, int32_t msgType, void *par
break;
}
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
CheckDevStatusByNetworkId(hbFsm, info[i].networkId, msgPara->hbType, nowTime);
}
SoftBusFree(info);
@ -1014,6 +1016,9 @@ static int32_t OnScreeOffCheckDevStatus(FsmStateMachine *fsm, int32_t msgType, v
break;
}
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
CheckDevStatusForScreenOff(hbFsm, info[i].networkId, msgPara->hbType, nowTime);
}
SoftBusFree(info);
@ -1136,6 +1141,7 @@ NO_SANITIZE("cfi") int32_t LnnPostNextSendOnceMsgToHbFsm(LnnHeartbeatFsm *hbFsm,
SoftBusFree(dupPara);
return SOFTBUS_ERR;
}
LnnNotifyHBRepeat();
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB post next loop msg, delayMillis: %" PRIu64, delayMillis);
return SOFTBUS_OK;
}

View File

@ -140,6 +140,9 @@ static int32_t HbGetOnlineNodeByRecvInfo(const char *recvUdidHash,
}
DiscoveryType discType = LnnConvAddrTypeToDiscType(recvAddrType);
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnGetRemoteNodeInfoById(info[i].networkId, CATEGORY_NETWORK_ID, nodeInfo) != SOFTBUS_OK) {
LLOGD("HB get nodeInfo fail");
continue;

View File

@ -143,6 +143,7 @@ typedef struct {
int32_t pid;
LanePreferredLinkList expectedLink;
bool networkDelegate;
ProtocolType acceptableProtocols;
} TransOption;
typedef struct {

View File

@ -32,6 +32,7 @@ typedef struct {
bool networkDelegate;
LaneTransType transType;
LaneLinkType linkType;
ProtocolType acceptableProtocols;
} LinkRequest;
typedef struct {

View File

@ -445,16 +445,21 @@ NO_SANITIZE("cfi") static int32_t LaneLinkOfWlan(uint32_t reqId, const LinkReque
LLOGW("can not get peer node");
return SOFTBUS_ERR;
}
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI)) {
if (!LnnHasDiscoveryType(&node, DISCOVERY_TYPE_WIFI) && !LnnHasDiscoveryType(&node, DISCOVERY_TYPE_LSA)) {
LLOGE("peer node is not wifi online");
return SOFTBUS_ERR;
}
ProtocolType acceptableProtocols = LNN_PROTOCOL_ALL;
if (reqInfo->transType != LANE_T_MSG && reqInfo->transType != LANE_T_BYTE) {
acceptableProtocols ^= LNN_PROTOCOL_NIP;
ProtocolType acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
if (reqInfo->transType == LANE_T_MSG || reqInfo->transType == LANE_T_BYTE) {
acceptableProtocols |= LNN_PROTOCOL_NIP;
}
acceptableProtocols = acceptableProtocols & reqInfo->acceptableProtocols;
ProtocolType protocol =
LnnLaneSelectProtocol(LNN_NETIF_TYPE_WLAN | LNN_NETIF_TYPE_ETH, reqInfo->peerNetworkId, acceptableProtocols);
if (protocol == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "protocal is invalid!");
return SOFTBUS_ERR;
}
if (protocol == LNN_PROTOCOL_IP) {
ret = LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_WLAN_IP, linkInfo.linkInfo.wlan.connInfo.addr,
sizeof(linkInfo.linkInfo.wlan.connInfo.addr));

View File

@ -33,6 +33,7 @@
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "softbus_utils.h"
#include "softbus_protocol_def.h"
typedef enum {
MSG_TYPE_LANE_TRIGGER_LINK = 0,
@ -180,7 +181,7 @@ static int32_t TriggerLink(uint32_t laneId, TransOption *request,
}
ListTailInsert(&g_multiLinkList, &linkNode->node);
Unlock();
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, 0, NULL) != SOFTBUS_OK) {
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, request->acceptableProtocols, NULL) != SOFTBUS_OK) {
DeleteLaneLinkNode(laneId);
return SOFTBUS_ERR;
}
@ -440,6 +441,7 @@ static LaneLinkNodeInfo *GetLaneLinkNodeWithoutLock(uint32_t laneId)
static void LaneTriggerLink(SoftBusMessage *msg)
{
uint32_t laneId = msg->arg1;
ProtocolType acceptableProtocols = (ProtocolType)msg->arg2;
LaneLinkCb linkCb = {
.OnLaneLinkSuccess = LinkSuccess,
.OnLaneLinkFail = LinkFail,
@ -465,6 +467,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
Unlock();
requestInfo.pid = nodeInfo->pid;
requestInfo.transType = nodeInfo->transType;
requestInfo.acceptableProtocols = acceptableProtocols;
if (memcpy_s(requestInfo.peerNetworkId, sizeof(requestInfo.peerNetworkId),
nodeInfo->networkId, sizeof(nodeInfo->networkId)) != EOK) {
return;
@ -473,7 +476,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
if (ret == SOFTBUS_OK) {
return;
}
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, ret, NULL) != SOFTBUS_OK) {
if (PostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneId, acceptableProtocols, NULL) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post laneLinkFail msg err");
}
}
@ -495,7 +498,7 @@ static void LaneLinkSuccess(SoftBusMessage *msg)
static void LaneLinkFail(SoftBusMessage *msg)
{
uint32_t laneId = (uint32_t)msg->arg1;
int32_t reason = (int32_t)msg->arg2;
int32_t reason = SOFTBUS_ERR;
if (Lock() != SOFTBUS_OK) {
return;
}
@ -513,7 +516,11 @@ static void LaneLinkFail(SoftBusMessage *msg)
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "Continue to build link");
Unlock();
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, 0, NULL) != SOFTBUS_OK) {
ProtocolType acceptableProtocols = (ProtocolType)msg->arg2;
if (msg->arg2 == (uint64_t)SOFTBUS_ERR) {
acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
}
if (PostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneId, acceptableProtocols, NULL) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "post triggerLink msg fail");
return;
}

View File

@ -31,6 +31,19 @@ typedef enum {
NODE_TYPE_L
} NodeType;
#define JSON_KEY_NODE_CODE "NODE_CODE"
#define JSON_KEY_NODE_ADDR "NODE_ADDR"
#define JSON_KEY_NODE_PROXY_PORT "PROXY_PORT"
#define JSON_KEY_NODE_SESSION_PORT "SESSION_PORT"
typedef struct {
int32_t code;
char nodeAddr[SHORT_ADDRESS_MAX_LEN];
int32_t proxyPort;
int32_t sessionPort;
int32_t authPort;
} LnnNodeAddr;
typedef struct {
ListNode node;
ConnectionAddr addr;

View File

@ -39,6 +39,7 @@ typedef enum {
LNN_INFO_TYPE_NODE_ADDR,
LNN_INFO_TYPE_NODE_ADDR_DETECTION,
LNN_INFO_TYPE_SYNC_CIPHERKEY,
LNN_INFO_TYPE_ROUTE_LSU,
LNN_INFO_TYPE_COUNT,
//LNN_INFO_TYPE_P2P_ROLE = 256,
} LnnSyncInfoType;

View File

@ -30,6 +30,13 @@ typedef struct {
uint8_t relation[CONNECTION_ADDR_MAX];
} LnnRelation;
typedef struct {
ConnectionAddrType type;
uint8_t relation;
bool isJoin;
char udid[UDID_BUF_LEN];
} LnnRelationChangedMsg;
int32_t LnnInitTopoManager(void);
void LnnDeinitTopoManager(void);

View File

@ -118,6 +118,9 @@ static void HandlerGetDeviceName(const char *deviceName)
return;
}
for (int32_t i = 0; i < infoNum; i++) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnSyncDeviceName(info[i].networkId) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "LnnSyncDeviceName fail");
}

View File

@ -172,6 +172,12 @@ typedef struct {
static NetBuilder g_netBuilder;
static bool g_watchdogFlag = true;
void __attribute__((weak)) SfcSyncNodeAddrHandle(const char *networkId, int32_t code)
{
(void)networkId;
(void)code;
}
NO_SANITIZE("cfi") void SetWatchdogFlag(bool flag)
{
g_watchdogFlag = flag;
@ -2043,70 +2049,85 @@ static void OnReceiveMasterElectMsg(LnnSyncInfoType type, const char *networkId,
}
}
static void OnReceiveNodeAddrChangedMsg(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t size)
static int32_t LnnUnpackNodeAddr(const uint8_t *data, uint32_t dataLen, LnnNodeAddr *addr)
{
(void)type;
size_t addrLen = strnlen((const char *)msg, size);
if (addrLen != size - 1 || addrLen == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:bad addr received!networkId=%s", __func__,
AnonymizesNetworkID(networkId));
return;
cJSON *json = cJSON_Parse((char *)data);
if (json == NULL) {
LLOGE("json parse failed");
return SOFTBUS_ERR;
}
int ret = LnnSetDLNodeAddr(networkId, CATEGORY_NETWORK_ID, (const char *)msg);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:update node addr failed!networkId=%s,ret=%d", __func__,
AnonymizesNetworkID(networkId), ret);
}
}
int32_t LnnUpdateNodeAddr(const char *addr)
{
if (addr == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:null ptr!", __func__);
return SOFTBUS_INVALID_PARAM;
}
NodeBasicInfo *info = NULL;
int32_t infoNum, i;
char localNetworkId[NETWORK_ID_BUF_LEN] = {0};
char addrHis[SHORT_ADDRESS_MAX_LEN];
if (LnnGetLocalStrInfo(STRING_KEY_NODE_ADDR, addrHis, SHORT_ADDRESS_MAX_LEN) == SOFTBUS_OK) {
if (strlen(addr) == strlen(addrHis) && (strcmp(addr, addrHis) == 0)) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "%s update the same node addr", __func__);
}
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "%s start updating node addr", __func__);
int32_t ret = LnnGetLocalStrInfo(STRING_KEY_NETWORKID, localNetworkId, sizeof(localNetworkId));
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:get local network id failed!", __func__);
if (!GetJsonObjectNumberItem(json, JSON_KEY_NODE_CODE, &addr->code) ||
!GetJsonObjectStringItem(json, JSON_KEY_NODE_ADDR, addr->nodeAddr, SHORT_ADDRESS_MAX_LEN) ||
!GetJsonObjectNumberItem(json, JSON_KEY_NODE_PROXY_PORT, &addr->proxyPort) ||
!GetJsonObjectNumberItem(json, JSON_KEY_NODE_SESSION_PORT, &addr->sessionPort)) {
LLOGE("parse addr info failed");
cJSON_Delete(json);
return SOFTBUS_ERR;
}
ret = LnnSetLocalStrInfo(STRING_KEY_NODE_ADDR, addr);
cJSON_Delete(json);
return SOFTBUS_OK;
}
static void OnReceiveNodeAddrChangedMsg(LnnSyncInfoType type, const char *networkId,
const uint8_t *msg, uint32_t size)
{
if (type != LNN_INFO_TYPE_NODE_ADDR) {
return;
}
size_t addrLen = strnlen((const char *)msg, size);
if (addrLen != size - 1 || addrLen == 0) {
return;
}
LLOGI("networkId=%s", AnonymizesNetworkID(networkId));
LnnNodeAddr addr;
(void)memset_s(&addr, sizeof(LnnNodeAddr), 0, sizeof(LnnNodeAddr));
if (LnnUnpackNodeAddr(msg, size, &addr) != SOFTBUS_OK) {
return;
}
SfcSyncNodeAddrHandle(networkId, addr.code);
if (LnnSetDLNodeAddr(networkId, CATEGORY_NETWORK_ID, addr.nodeAddr) != SOFTBUS_OK) {
return;
}
if (addr.proxyPort > 0) {
(void)LnnSetDLProxyPort(networkId, CATEGORY_NETWORK_ID, addr.proxyPort);
}
if (addr.sessionPort > 0) {
(void)LnnSetDLSessionPort(networkId, CATEGORY_NETWORK_ID, addr.sessionPort);
}
if (addr.authPort > 0) {
(void)LnnSetDLAuthPort(networkId, CATEGORY_NETWORK_ID, addr.authPort);
}
LnnNotifyNodeAddressChanged(addr.nodeAddr, networkId, false);
}
NO_SANITIZE("cfi") int32_t LnnUpdateNodeAddr(const char *addr)
{
if (addr == NULL) {
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = LnnSetLocalStrInfo(STRING_KEY_NODE_ADDR, addr);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:set local node addr failed!ret=%d", __func__, ret);
LLOGE("set local node addr failed");
return ret;
}
ret = LnnGetAllOnlineNodeInfo(&info, &infoNum);
char localNetworkId[NETWORK_ID_BUF_LEN] = {0};
ret = LnnGetLocalStrInfo(STRING_KEY_NETWORKID, localNetworkId, sizeof(localNetworkId));
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:get all online node info fail", __func__);
} else {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "%s:online nodes count=%d", __func__, infoNum);
for (i = 0; i < infoNum; ++i) {
if (strcmp(localNetworkId, info[i].networkId) == 0) {
continue;
}
SoftBusLog(
SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "sync node address to %s", AnonymizesNetworkID(info[i].networkId));
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_NODE_ADDR, info[i].networkId, (const uint8_t *)addr, strlen(addr) + 1,
NULL) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "sync node address to %s failed",
AnonymizesNetworkID(info[i].networkId));
}
}
SoftBusFree(info);
LLOGE("get local network id failed");
return SOFTBUS_ERR;
}
LnnNotifyNodeAddressChanged(addr);
LnnNotifyNodeAddressChanged(addr, localNetworkId, true);
return SOFTBUS_OK;
}

View File

@ -165,6 +165,9 @@ static void SendNetCapabilityToRemote(uint32_t netCapability, uint32_t type)
}
NodeInfo nodeInfo = {0};
for (int32_t i = 0; i< infoNum; i++) {
if (LnnIsLSANode(&netInfo[i])) {
continue;
}
if (LnnGetRemoteNodeInfoById(netInfo[i].networkId, CATEGORY_NETWORK_ID, &nodeInfo) != SOFTBUS_OK) {
continue;
}

View File

@ -116,6 +116,9 @@ static void ProcessSyncP2pInfo(void *para)
}
len = strlen(msg) + 1; /* add 1 for '\0' */
for (i = 0; i < infoNum; i++) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_P2P_INFO, info[i].networkId, (uint8_t *)msg, len, NULL) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "sync p2p info to %s fail.", info[i].deviceName);
}

View File

@ -50,13 +50,6 @@
#define TOPO_HASH_TABLE_SIZE 16
typedef struct {
ConnectionAddrType type;
uint8_t relation;
bool isJoin;
char udid[UDID_BUF_LEN];
} RelationChangedMsg;
typedef enum {
TOPO_MSG_TYPE_UPDATE,
} TopoUpdateMsgType;
@ -88,6 +81,11 @@ typedef struct {
static TopoHashTable g_topoTable;
void __attribute__((weak)) RouteLnnRelationEventHandler(const LnnRelationChangedMsg *msg)
{
(void)msg;
}
static bool IsSameRelation(const uint8_t *newRelation, const uint8_t *oldRelation, uint32_t len)
{
uint32_t i;
@ -434,6 +432,9 @@ static void ForwardTopoMsgToAll(const char *networkId, const uint8_t *msg, uint3
return;
}
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (strcmp(networkId, info[i].networkId) == 0) {
continue;
}
@ -607,6 +608,9 @@ static void NotifyLnnRelationChange(const char *localUdid, const char *udid,
}
msgLen = strlen(msg) + 1;
for (i = 0; i < infoNum; ++i) {
if (LnnIsLSANode(&info[i])) {
continue;
}
if (strcmp(networkId, info[i].networkId) == 0) {
continue;
}
@ -667,19 +671,21 @@ static void ProcessLnnRelationChange(const char *udid, const uint8_t *relation,
static void OnLnnRelationChangedDelay(void *para)
{
uint8_t newRelation[CONNECTION_ADDR_MAX] = {0};
int32_t rc;
RelationChangedMsg *msg = (RelationChangedMsg *)para;
LnnRelationChangedMsg *msg = (LnnRelationChangedMsg *)para;
if (msg == NULL) {
return;
}
RouteLnnRelationEventHandler(msg);
SoftBusFree(msg);
return;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "OnLnnRelationChangedDelay: %d", msg->type);
if (msg->type == CONNECTION_ADDR_MAX) {
SoftBusFree(msg);
return;
}
rc = LnnGetLnnRelation(msg->udid, CATEGORY_UDID, newRelation, CONNECTION_ADDR_MAX);
uint8_t newRelation[CONNECTION_ADDR_MAX] = {0};
int32_t rc = LnnGetLnnRelation(msg->udid, CATEGORY_UDID, newRelation, CONNECTION_ADDR_MAX);
if (rc != SOFTBUS_OK && rc != SOFTBUS_NOT_FIND) { // NOT_FIND means node is offline
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get new lnn relation fail");
SoftBusFree(msg);
@ -706,10 +712,8 @@ static void OnLnnRelationChangedDelay(void *para)
static void OnLnnRelationChanged(const LnnEventBasicInfo *info)
{
LLOGI("ignore topo change event");
return;
const LnnRelationChanedEventInfo *eventInfo = (const LnnRelationChanedEventInfo *)info;
RelationChangedMsg *msg = NULL;
LnnRelationChangedMsg *msg = NULL;
if (info == NULL || info->event != LNN_EVENT_RELATION_CHANGED) {
return;
@ -718,7 +722,7 @@ static void OnLnnRelationChanged(const LnnEventBasicInfo *info)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid relation changed params");
return;
}
msg = (RelationChangedMsg *)SoftBusMalloc(sizeof(RelationChangedMsg));
msg = (LnnRelationChangedMsg *)SoftBusMalloc(sizeof(LnnRelationChangedMsg));
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc relation changed msg fail");
return;

View File

@ -59,7 +59,8 @@ typedef VisitNextChoice (*VisitNetifCallback)(const LnnNetIfMgr *, void *);
typedef enum {
LNN_LISTENER_MODE_PROXY,
LNN_LISTENER_MODE_DIRECT
LNN_LISTENER_MODE_DIRECT,
LNN_LISTENER_MODE_AUTH
} ListenerMode;
typedef struct LnnProtocolManager {

View File

@ -32,7 +32,7 @@ if (dsoftbus_feature_conn_br || dsoftbus_feature_conn_ble) {
bus_center_net_mgr_deps = []
native_source_path = rebase_path("$dsoftbus_root_path")
newip_dir = "dsoftbus_enhance/components/newip"
newip_dir = "dsoftbus_enhance/components/newip/network"
newip_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
@ -42,7 +42,7 @@ newip_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
if (newip_enhanced) {
import(
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/newip.gni")
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/network/network.gni")
bus_center_net_mgr_src += newip_manager_src
bus_center_net_mgr_inc += newip_manager_include

View File

@ -147,17 +147,26 @@ static int32_t OpenAuthPort(void)
int32_t port;
char localIp[MAX_ADDR_LEN] = {0};
int32_t authPort;
if (LnnGetLocalNumInfo(NUM_KEY_AUTH_PORT, &authPort) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get port failed");
authPort = 0;
}
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, localIp, MAX_ADDR_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get local ip failed");
return SOFTBUS_ERR;
}
port = AuthStartListening(AUTH_LINK_TYPE_WIFI, localIp, 0);
port = AuthStartListening(AUTH_LINK_TYPE_WIFI, localIp, authPort);
if (port < 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "AuthStartListening failed");
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "open auth port listening on ip:%s", AnonymizesIp(localIp));
return LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, port);
if (authPort == 0) {
return LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, port);
}
return SOFTBUS_OK;
}
static void CloseAuthPort(void)
@ -168,12 +177,18 @@ static void CloseAuthPort(void)
static int32_t OpenSessionPort(void)
{
int32_t sessionPort;
if (LnnGetLocalNumInfo(NUM_KEY_SESSION_PORT, &sessionPort) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get port failed");
sessionPort = 0;
}
int32_t port;
LocalListenerInfo info = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = 0,
.port = sessionPort,
.moduleId = DIRECT_CHANNEL_SERVER_WIFI,
.protocol = LNN_PROTOCOL_IP,
}
@ -187,7 +202,11 @@ static int32_t OpenSessionPort(void)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open session server failed");
return SOFTBUS_ERR;
}
return LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, port);
if (sessionPort == 0) {
return LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, port);
}
return SOFTBUS_OK;
}
static void CloseSessionPort(void)
@ -198,11 +217,17 @@ static void CloseSessionPort(void)
static void OpenProxyPort(void)
{
int32_t proxyPort;
if (LnnGetLocalNumInfo(NUM_KEY_PROXY_PORT, &proxyPort) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get port failed");
proxyPort = 0;
}
LocalListenerInfo listenerInfo = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "",
.port = 0,
.port = proxyPort,
.moduleId = PROXY,
.protocol = LNN_PROTOCOL_IP,
}
@ -218,7 +243,9 @@ static void OpenProxyPort(void)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open proxy server failed");
return;
}
(void)LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, port);
if (proxyPort == 0) {
(void)LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, port);
}
}
static void CloseProxyPort(void)

View File

@ -70,7 +70,7 @@ int32_t __attribute__((weak)) RegistNewIPProtocolManager(void)
return SOFTBUS_OK;
}
int32_t __attribute__ ((weak)) RegistBtProtocolManager(void)
int32_t __attribute__((weak)) RegistBtProtocolManager(void)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "regist virtual bt protocol manager");
return SOFTBUS_OK;

View File

@ -23,7 +23,7 @@
#include "softbus_errcode.h"
#include "softbus_log.h"
#define MAX_SUPPORTED_PHYSICAL_SUBNET 4
#define MAX_SUPPORTED_PHYSICAL_SUBNET 6
static SoftBusMutex g_physicalSubnetsLock;
static LnnPhysicalSubnet *g_physicalSubnets[MAX_SUPPORTED_PHYSICAL_SUBNET];

View File

@ -51,6 +51,7 @@ typedef enum {
DISCOVERY_TYPE_BLE,
DISCOVERY_TYPE_BR,
DISCOVERY_TYPE_P2P,
DISCOVERY_TYPE_LSA,
DISCOVERY_TYPE_COUNT,
} DiscoveryType;
@ -124,6 +125,7 @@ typedef struct {
const char *LnnGetDeviceUdid(const NodeInfo *info);
int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid);
const char *LnnGetDeviceUuid(const NodeInfo *info);
bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type);
int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type);
int32_t LnnClearDiscoveryType(NodeInfo *info, DiscoveryType type);

View File

@ -99,6 +99,8 @@ static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *i
return LnnGetLocalNumInfo(NUM_KEY_DISCOVERY_TYPE, (int32_t *)info);
case NODE_KEY_DATA_CHANGE_FLAG:
return LnnGetLocalNum16Info(NUM_KEY_DATA_CHANGE_FLAG, (int16_t *)info);
case NODE_KEY_NODE_ADDRESS:
return LnnGetLocalStrInfo(STRING_KEY_NODE_ADDR, (char *)info, infoLen);
default:
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key);
return SOFTBUS_ERR;
@ -130,6 +132,8 @@ static int32_t LnnGetNodeKeyInfoRemote(const char *networkId, int key, uint8_t *
return LnnGetRemoteNumInfo(networkId, NUM_KEY_DISCOVERY_TYPE, (int32_t *)info);
case NODE_KEY_DATA_CHANGE_FLAG:
return LnnGetRemoteNum16Info(networkId, NUM_KEY_DATA_CHANGE_FLAG, (int16_t *)info);
case NODE_KEY_NODE_ADDRESS:
return LnnGetRemoteStrInfo(networkId, STRING_KEY_NODE_ADDR, (char *)info, infoLen);
default:
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key);
return SOFTBUS_ERR;
@ -201,6 +205,8 @@ NO_SANITIZE("cfi") int32_t LnnGetNodeKeyInfoLen(int32_t key)
return LNN_COMMON_LEN;
case NODE_KEY_DATA_CHANGE_FLAG:
return DATA_CHANGE_FLAG_BUF_LEN;
case NODE_KEY_NODE_ADDRESS:
return SHORT_ADDRESS_MAX_LEN;
default:
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key);
return SOFTBUS_ERR;

View File

@ -55,6 +55,14 @@ NO_SANITIZE("cfi") int32_t LnnSetDeviceUdid(NodeInfo *info, const char *udid)
return SOFTBUS_OK;
}
NO_SANITIZE("cfi") const char *LnnGetDeviceUuid(const NodeInfo *info)
{
if (info == NULL) {
return NULL;
}
return info->uuid;
}
NO_SANITIZE("cfi") int32_t LnnSetDiscoveryType(NodeInfo *info, DiscoveryType type)
{
if (info == NULL || type >= DISCOVERY_TYPE_COUNT) {
@ -321,7 +329,7 @@ NO_SANITIZE("cfi") const char *LnnGetP2pGoMac(const NodeInfo *info)
NO_SANITIZE("cfi") uint64_t LnnGetSupportedProtocols(const NodeInfo *info)
{
if (info == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para error!");
return 0;
}
return info->supportedProtocols;

View File

@ -78,6 +78,10 @@ void LnnRefreshDeviceOnlineStateAndDevIdInfo(const char *pkgName, DeviceInfo *de
int32_t LnnUpdateNodeInfo(NodeInfo *newInfo);
int32_t LnnAddMetaInfo(NodeInfo *info);
int32_t LnnDeleteMetaInfo(const char *udid, ConnectionAddrType type);
int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort);
int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort);
int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort);
NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
#ifdef __cplusplus
}
#endif

View File

@ -50,8 +50,6 @@
#define LNN_COMMON_LEN_64 8
#define SOFTBUS_BUSCENTER_DUMP_REMOTEDEVICEINFO "remote_device_info"
static NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
#define RETURN_IF_GET_NODE_VALID(networkId, buf, info) do { \
if ((networkId) == NULL || (buf) == NULL) { \
return SOFTBUS_INVALID_PARAM; \
@ -387,7 +385,7 @@ void PostOnlineNodesToCb(const INodeStateCb *callBack)
LnnMapDeinitIterator(it);
}
NO_SANITIZE("cfi") static NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type)
NO_SANITIZE("cfi") NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type)
{
NodeInfo *info = NULL;
DoubleHashMap *map = &g_distributedNetLedger.distributedInfo;
@ -1098,7 +1096,8 @@ NO_SANITIZE("cfi") int32_t LnnUpdateNodeInfo(NodeInfo *newInfo)
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_ERR;
}
if (LnnHasDiscoveryType(newInfo, DISCOVERY_TYPE_WIFI)) {
if (LnnHasDiscoveryType(newInfo, DISCOVERY_TYPE_WIFI) ||
LnnHasDiscoveryType(newInfo, DISCOVERY_TYPE_LSA)) {
oldInfo->discoveryType = newInfo->discoveryType | oldInfo->discoveryType;
oldInfo->connectInfo.authPort = newInfo->connectInfo.authPort;
oldInfo->connectInfo.proxyPort = newInfo->connectInfo.proxyPort;
@ -1801,6 +1800,15 @@ static int32_t GetAllOnlineAndMetaNodeInfo(NodeBasicInfo **info, int32_t *infoNu
return ret;
}
NO_SANITIZE("cfi") bool LnnIsLSANode(const NodeBasicInfo *info)
{
NodeInfo *nodeInfo = LnnGetNodeInfoById(info->networkId, CATEGORY_NETWORK_ID);
if (nodeInfo != NULL && LnnHasDiscoveryType(nodeInfo, DISCOVERY_TYPE_LSA)) {
return true;
}
return false;
}
int32_t LnnGetAllOnlineNodeNum(int32_t *nodeNum)
{
if (nodeNum == NULL) {
@ -2128,6 +2136,57 @@ NO_SANITIZE("cfi") int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, con
return ret == EOK ? SOFTBUS_OK : SOFTBUS_ERR;
}
int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort)
{
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "lock mutex fail!");
return SOFTBUS_ERR;
}
NodeInfo *nodeInfo = LnnGetNodeInfoById(id, type);
if (nodeInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get info fail");
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_ERR;
}
nodeInfo->connectInfo.proxyPort = proxyPort;
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_OK;
}
int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort)
{
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "lock mutex fail!");
return SOFTBUS_ERR;
}
NodeInfo *nodeInfo = LnnGetNodeInfoById(id, type);
if (nodeInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get info fail");
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_ERR;
}
nodeInfo->connectInfo.sessionPort = sessionPort;
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_OK;
}
int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort)
{
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "lock mutex fail!");
return SOFTBUS_ERR;
}
NodeInfo *nodeInfo = LnnGetNodeInfoById(id, type);
if (nodeInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get info fail");
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_ERR;
}
nodeInfo->connectInfo.authPort = authPort;
(void)SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return SOFTBUS_OK;
}
int32_t SoftBusDumpBusCenterRemoteDeviceInfo(int32_t fd)
{
SOFTBUS_DPRINTF(fd, "-----RemoteDeviceInfo-----\n");

View File

@ -45,6 +45,12 @@ int32_t LnnGetDLNumInfo(const char *networkId, InfoKey key, int32_t *info)
return SOFTBUS_NOT_IMPLEMENT;
}
bool LnnIsLSANode(const NodeBasicInfo *info)
{
(void)info;
return true;
}
int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum)
{
(void)info;

View File

@ -1089,6 +1089,10 @@ NO_SANITIZE("cfi") int32_t LnnInitLocalLedger(void)
if (InitOfflineCode(nodeInfo) != SOFTBUS_OK) {
goto EXIT;
}
if (strcpy_s(nodeInfo->nodeAddress, sizeof(nodeInfo->nodeAddress), NODE_ADDR_LOOPBACK) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail:strncpy_s fail!");
goto EXIT;
}
if (InitLocalDeviceInfo(deviceInfo) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init local device info error!");
goto EXIT;

View File

@ -48,6 +48,7 @@ typedef enum {
LNN_EVENT_NODE_MASTER_STATE_CHANGED,
LNN_EVENT_NODE_ADDR_CHANGED,
LNN_EVENT_NETWORK_STATE_CHANGED,
LNN_EVENT_NODE_HB_REPEAT_CYCLE,
LNN_EVENT_TYPE_MAX,
} LnnEventType;
@ -188,7 +189,9 @@ typedef struct {
typedef struct {
LnnEventBasicInfo basic;
char addr[SHORT_ADDRESS_MAX_LEN];
char networkId[NETWORK_ID_BUF_LEN];
bool delFlag;
bool isLocal;
} LnnNodeAddrChangedEvent;
typedef void (*LnnEventHandler)(const LnnEventBasicInfo *info);
@ -229,9 +232,10 @@ void LnnNotifyTimeSyncResult(const char *pkgName, int32_t pid, const TimeSyncRes
void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, int32_t weight);
void LnnNotifyNodeAddressChanged(const char* addr);
void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool isLocal);
void LnnNotifyNetworkStateChanged(SoftBusNetworkState state);
void LnnNotifyHBRepeat(void);
#ifdef __cplusplus
}

View File

@ -515,17 +515,17 @@ NO_SANITIZE("cfi") void LnnNotifyMasterNodeChanged(bool isMaster, const char *ma
NotifyEvent((const LnnEventBasicInfo *)&event);
}
NO_SANITIZE("cfi") void LnnNotifyNodeAddressChanged(const char *addr)
NO_SANITIZE("cfi") void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool isLocal)
{
if (addr == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:nullptr!", __func__);
return;
}
LnnNodeAddrChangedEvent eventInfo;
(void)memset_s(&eventInfo, sizeof(eventInfo), 0, sizeof(eventInfo));
eventInfo.basic.event = LNN_EVENT_NODE_ADDR_CHANGED;
if (strcpy_s(eventInfo.addr, sizeof(eventInfo.addr), addr) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:strcpy_s failed", __func__);
if (strcpy_s(eventInfo.addr, sizeof(eventInfo.addr), addr) != EOK ||
strcpy_s(eventInfo.networkId, NETWORK_ID_BUF_LEN, networkId) != EOK) {
return;
}
if (strcmp(addr, NODE_ADDR_LOOPBACK) == 0) {
@ -533,9 +533,18 @@ NO_SANITIZE("cfi") void LnnNotifyNodeAddressChanged(const char *addr)
} else {
eventInfo.delFlag = false;
}
eventInfo.isLocal = isLocal;
NotifyEvent((LnnEventBasicInfo *)&eventInfo);
}
NO_SANITIZE("cfi") void LnnNotifyHBRepeat(void)
{
LnnEventBasicInfo event;
event.event = LNN_EVENT_NODE_HB_REPEAT_CYCLE;
NotifyEvent(&event);
}
NO_SANITIZE("cfi") void LnnNotifyNetworkStateChanged(SoftBusNetworkState state)
{
if (state < SOFTBUS_WIFI_NETWORKD_ENABLE || state >= SOFTBUS_NETWORKD_UNKNOWN) {

View File

@ -46,6 +46,12 @@ int32_t __attribute__((weak)) InitNodeAddrAllocator(void)
}
void __attribute__((weak)) DeinitNodeAddrAllocator(void) {}
int32_t __attribute__((weak)) RouteLSInit(void)
{
return SOFTBUS_OK;
}
void __attribute__((weak)) RouteLSDeinit(void) {}
typedef int32_t (*LnnInitDelayImpl)(void);
typedef enum {
@ -192,6 +198,10 @@ NO_SANITIZE("cfi") int32_t BusCenterServerInit(void)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init nodeAddr failed.");
return SOFTBUS_ERR;
}
if (RouteLSInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init route failed.");
return SOFTBUS_ERR;
}
if (StartDelayInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start delay init fail!");
return SOFTBUS_ERR;
@ -202,6 +212,7 @@ NO_SANITIZE("cfi") int32_t BusCenterServerInit(void)
NO_SANITIZE("cfi") void BusCenterServerDeinit(void)
{
RouteLSDeinit();
DeinitNodeAddrAllocator();
LnnDeinitLaneHub();
LnnDeinitNetBuilder();

View File

@ -51,6 +51,7 @@ typedef enum {
SOFTBUS_UDP_CHANNEL_TIMER_FUN,
SOFTBUS_TIME_SYNC_TIMER_FUN,
SOFTBUS_PROXY_SENDFILE_TIMER_FUN,
SOFTBUS_NIP_NODE_AGING_TIMER_FUN,
SOFTBUS_MAX_TIMER_FUN_NUM
} SoftBusTimerFunEnum;

View File

@ -34,6 +34,7 @@ extern "C" {
#define BR_CONNECTION_PEND_TIMEOUT_MAX_MILLIS (20 * 1000)
#define BR_CONNECTION_ACL_CONNECT_COLLISION_MILLIS (6 * 1000)
#define BR_WAIT_BLE_DISCONNECTED_PEND_MILLIS (20 * 1000)
#define BR_NIP_SEQ (0xeaddeaddeaddeadd)
enum ConnBrDeviceState {
BR_DEVICE_STATE_INIT,

View File

@ -70,6 +70,7 @@ typedef struct {
} ConnBrTransEventListener;
int32_t ConnBrTransReadOneFrame(uint32_t connectionId, int32_t socketHandle, LimitedBuffer *buffer, uint8_t **outData);
int32_t BrTransSend(uint32_t connectionId, int32_t socketHandle, uint32_t mtu, const uint8_t *data, uint32_t dataLen);
int64_t ConnBrPackCtlMessage(BrCtlMessageSerializationContext ctx, uint8_t **outData, uint32_t *outLen);
int32_t ConnBrPostBytes(
uint32_t connectionId, uint8_t *data, uint32_t len, int32_t pid, int32_t flag, int32_t module, int64_t seq);

View File

@ -93,6 +93,23 @@ static SoftBusHandlerWrapper g_brManagerAsyncHandler = {
.eventCompareFunc = BrCompareManagerLooperEventFunc,
};
void __attribute__((weak)) NipRecvDataFromBr(uint32_t connId, const char *buf, int32_t len)
{
(void)connId;
(void)buf;
}
void __attribute__((weak)) NipConnectDevice(uint32_t connId, const char *mac)
{
(void)connId;
(void)mac;
}
void __attribute__((weak)) NipDisconnectDevice(uint32_t connId)
{
(void)connId;
}
static void DfxRecordBrConnectFail(uint32_t reqId, uint32_t pId, ConnBrDevice *device,
const ConnectStatistics *statistics, int32_t reason)
{
@ -242,6 +259,12 @@ static void NotifyDeviceConnectResult(
return;
}
if (reason == 0) {
NipConnectDevice(connection->connectionId, connection->addr);
} else {
NipDisconnectDevice(connection->connectionId);
}
ConnectionInfo info = { 0 };
int32_t status = Convert2ConnectionInfo(connection, &info);
if (status != SOFTBUS_OK) {
@ -748,6 +771,8 @@ static void DataReceived(ConnBrDataReceivedContext *ctx)
ctx->connectionId, ctx->dataLen, head->flag, head->module, head->seq);
if (head->module == MODULE_CONNECTION) {
ReceivedControlData(connection, ctx->data + ConnGetHeadSize(), ctx->dataLen - ConnGetHeadSize());
} else if (head->module == MODULE_NIP_BR_CHANNEL && head->seq == (int64_t)BR_NIP_SEQ) {
NipRecvDataFromBr(ctx->connectionId, (char *)ctx->data, ctx->dataLen);
} else {
g_connectCallback.OnDataReceived(
ctx->connectionId, (ConnModule)head->module, head->seq, (char *)ctx->data, ctx->dataLen);
@ -1421,6 +1446,7 @@ static int32_t BrDisconnectDevice(uint32_t connectionId)
"br disconnect device failed: connection not exist, connection id=%u", connectionId);
char animizeAddress[BT_MAC_LEN] = { 0 };
ConvertAnonymizeMacAddress(animizeAddress, BT_MAC_LEN, connection->addr, BT_MAC_LEN);
NipDisconnectDevice(connectionId);
ConnBrReturnConnection(&connection);
int32_t status = ConnPostMsgToLooper(&g_brManagerAsyncHandler, MGR_DISCONNECT_REQUEST, connectionId, 0, NULL, 0);
CLOGI("br disconnect device, connection id=%u, address=%s, status=%d", connectionId, animizeAddress, status);
@ -1442,6 +1468,7 @@ static int32_t BrDisconnectDeviceNow(const ConnectOption *option)
CONN_CHECK_AND_RETURN_RET_LOG(connection != NULL, SOFTBUS_CONN_BR_CONNECTION_NOT_EXIST_ERR,
"br disconnect device now failed: connection is not exist, address=%s, side=%d", animizeAddress,
option->brOption.sideType);
NipDisconnectDevice(connection->connectionId);
ConnBrDisconnectNow(connection);
ConnBrReturnConnection(&connection);
return SOFTBUS_OK;

View File

@ -107,7 +107,7 @@ int32_t ConnBrTransReadOneFrame(uint32_t connectionId, int32_t socketHandle, Lim
}
}
static int32_t BrTransSend(
NO_SANITIZE("cfi") int32_t BrTransSend(
uint32_t connectionId, int32_t socketHandle, uint32_t mtu, const uint8_t *data, uint32_t dataLen)
{
uint32_t waitWriteLen = dataLen;

View File

@ -27,7 +27,7 @@ conn_common_inc = [
]
native_source_path = rebase_path("$dsoftbus_root_path")
newip_dir = "dsoftbus_enhance/components/newip"
newip_dir = "dsoftbus_enhance/components/newip/network"
newip_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
@ -37,7 +37,7 @@ newip_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
if (newip_enhanced) {
import(
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/newip.gni")
"//foundation/communication/dsoftbus/dsoftbus_enhance/components/newip/network/network.gni")
conn_common_src += newip_connection_src
conn_common_inc += newip_connection_include

View File

@ -47,6 +47,7 @@ typedef enum {
MODULE_META_AUTH = 21,
MODULE_BLE_NET = 100,
MODULE_BLE_CONN = 101,
MODULE_NIP_BR_CHANNEL = 201,
MODULE_OLD_NEARBY = 300,
} ConnModule;

View File

@ -27,6 +27,7 @@
#include "softbus_log.h"
#include "softbus_utils.h"
#include "trans_session_manager.h"
#include "lnn_distributed_net_ledger.h"
#define TRANS_REQUEST_PENDING_TIMEOUT (5000)
#define SESSION_NAME_PHONEPAD "com.huawei.pcassistant.phonepad-connect-channel"
@ -328,6 +329,13 @@ static int32_t GetRequestOptionBySessionParam(const SessionParam *param, LaneReq
}
requestOption->requestInfo.trans.transType = transType;
requestOption->requestInfo.trans.expectedBw = 0; /* init expectBW */
requestOption->requestInfo.trans.acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
NodeInfo *info = LnnGetNodeInfoById(requestOption->requestInfo.trans.networkId, CATEGORY_NETWORK_ID);
if (info != NULL && LnnHasDiscoveryType(info, DISCOVERY_TYPE_LSA)) {
requestOption->requestInfo.trans.acceptableProtocols |= LNN_PROTOCOL_NIP;
}
int32_t uid;
if (TransGetUidAndPid(param->sessionName, &uid, &(requestOption->requestInfo.trans.pid)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "transGetUidAndPid failed.");

View File

@ -40,6 +40,7 @@
#include "trans_udp_channel_manager.h"
#include "trans_udp_negotiation.h"
#include "trans_tcp_direct_sessionconn.h"
#include "lnn_network_manager.h"
#define MIGRATE_ENABLE 2
#define MIGRATE_SUPPORTED 1
@ -323,6 +324,18 @@ NO_SANITIZE("cfi") static void FillAppInfo(AppInfo *appInfo, ConnectOption *conn
appInfo->channelType = transInfo->channelType;
}
static void TransOpenChannelSetModule(int32_t channelType, ConnectOption *connOpt)
{
if (connOpt->type != CONNECT_TCP || connOpt->socketOption.protocol != LNN_PROTOCOL_NIP ||
channelType != CHANNEL_TYPE_PROXY) {
return;
}
int32_t module = LnnGetProtocolListenerModule(connOpt->socketOption.protocol, LNN_LISTENER_MODE_PROXY);
if (module != UNUSE_BUTT) {
connOpt->socketOption.moduleId = module;
}
}
NO_SANITIZE("cfi") int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
{
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "server TransOpenChannel");
@ -349,6 +362,7 @@ NO_SANITIZE("cfi") int32_t TransOpenChannel(const SessionParam *param, TransInfo
goto EXIT_ERR;
}
FillAppInfo(appInfo, &connOpt, param, transInfo, &connInfo);
TransOpenChannelSetModule(transInfo->channelType, &connOpt);
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "lane[%u] get channel type[%u].", laneId, transInfo->channelType);
if (TransOpenChannelProc((ChannelType)transInfo->channelType, appInfo, &connOpt,
&(transInfo->channelId)) != SOFTBUS_OK) {

View File

@ -232,6 +232,7 @@ static int32_t TransGetConnectOption(const char *peerNetworkId, ConnectOption *c
option.requestInfo.trans.pid = DEFAULT_PID;
option.requestInfo.trans.transType = LANE_T_MSG;
option.requestInfo.trans.expectedBw = 0;
option.requestInfo.trans.acceptableProtocols = LNN_PROTOCOL_ALL ^ LNN_PROTOCOL_NIP;
if (memcpy_s(option.requestInfo.trans.networkId, NETWORK_ID_BUF_LEN,
peerNetworkId, NETWORK_ID_BUF_LEN) != EOK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "memcpy networkId failed.");

View File

@ -721,7 +721,14 @@ NO_SANITIZE("cfi") int32_t TransProxyOpenConnChannel(const AppInfo *appInfo, con
ret = TransProxyOpenNewConnChannel(PROXY, appInfo, connInfo, chanNewId);
}
} else {
ret = TransProxyOpenNewConnChannel(PROXY, appInfo, connInfo, chanNewId);
ListenerModule module = PROXY;
if (connInfo->type == CONNECT_TCP) {
module = LnnGetProtocolListenerModule(connInfo->socketOption.protocol, LNN_LISTENER_MODE_PROXY);
if (module == UNUSE_BUTT) {
return SOFTBUS_INVALID_PARAM;
}
}
ret = TransProxyOpenNewConnChannel(module, appInfo, connInfo, chanNewId);
if ((ret == SOFTBUS_TRANS_PROXY_CONN_REPEAT) && (TransGetConn(connInfo, &conn) == SOFTBUS_OK)) {
ret = TransProxyConnExistProc(&conn, appInfo, chanNewId);
}

View File

@ -63,6 +63,12 @@ NO_SANITIZE("cfi") int32_t OpenTcpDirectChannel(const AppInfo *appInfo, const Co
ListenerModule module = connInfo->type == CONNECT_P2P_REUSE ?
DIRECT_CHANNEL_SERVER_P2P : DIRECT_CHANNEL_SERVER_WIFI;
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "%s:get listener module %d!", __func__, module);
if (module == DIRECT_CHANNEL_SERVER_WIFI) {
module = LnnGetProtocolListenerModule(connInfo->socketOption.protocol, LNN_LISTENER_MODE_DIRECT);
if (module == UNUSE_BUTT) {
return SOFTBUS_INVALID_PARAM;
}
}
SessionConn *newConn = CreateNewSessinConn(module, false);
if (newConn == NULL) {

View File

@ -156,6 +156,7 @@ typedef enum {
NODE_KEY_NETWORK_TYPE, /**< Network type in number format */
NODE_KEY_BLE_OFFLINE_CODE, /**< Ble offlinecode in string format */
NODE_KEY_DATA_CHANGE_FLAG,
NODE_KEY_NODE_ADDRESS, /**< Node address in string format */
} NodeDeviceInfoKey;
/**

View File

@ -189,7 +189,7 @@ extern "C" {
* @brief Indicates the maximum length of the node address.
*
*/
#define SHORT_ADDRESS_MAX_LEN 8
#define SHORT_ADDRESS_MAX_LEN 20
/**
* @brief Indicates the maximum num of the node status.

View File

@ -158,6 +158,16 @@ bool LnnPeerHasExchangeDiscoveryType(const NodeInfo *info, DiscoveryType type)
{
return GetNetLedgerInterface()->LnnPeerHasExchangeDiscoveryType(info, type);
}
void RouteBuildClientAuthManager(int32_t cfd)
{
return GetNetLedgerInterface()->RouteBuildClientAuthManager(cfd);
}
void RouteClearAuthChannelId(int32_t cfd)
{
return GetNetLedgerInterface()->RouteClearAuthChannelId(cfd);
}
}
char *AuthNetLedgertInterfaceMock::Pack(int64_t authSeq, const AuthSessionInfo *info, AuthDataHead &head)

View File

@ -58,6 +58,8 @@ public:
virtual int32_t LnnSetSupportDiscoveryType(char *info, const char *type) = 0;
virtual bool LnnHasSupportDiscoveryType(const char *destType, const char *type) = 0;
virtual bool LnnPeerHasExchangeDiscoveryType(const NodeInfo *info, DiscoveryType type) = 0;
virtual void RouteBuildClientAuthManager(int32_t cfd) = 0;
virtual void RouteClearAuthChannelId(int32_t cfd) = 0;
};
class AuthNetLedgertInterfaceMock : public AuthNetLedgerInterface {
public:
@ -85,6 +87,8 @@ public:
MOCK_METHOD2(LnnSetSupportDiscoveryType, int32_t(char *, const char *));
MOCK_METHOD2(LnnHasSupportDiscoveryType, bool(const char *, const char *));
MOCK_METHOD2(LnnPeerHasExchangeDiscoveryType, bool(const NodeInfo *, DiscoveryType));
MOCK_METHOD1(RouteBuildClientAuthManager, void (int32_t));
MOCK_METHOD1(RouteClearAuthChannelId, void (int32_t));
static inline bool isRuned;
static inline SoftBusMutex mutex;

View File

@ -212,9 +212,9 @@ HWTEST_F(AuthOtherTest, ON_WIFI_DATA_RECEIVED_TEST_001, TestSize.Level1)
const uint8_t data[TEST_DATA_LEN] = { 0 };
(void)memset_s(&head, sizeof(AuthDataHead), 0, sizeof(AuthDataHead));
OnWiFiDataReceived(fd, nullptr, data);
OnWiFiDataReceived(fd, &head, nullptr);
OnWiFiDataReceived(fd, &head, data);
OnWiFiDataReceived(AUTH, fd, nullptr, data);
OnWiFiDataReceived(AUTH, fd, &head, nullptr);
OnWiFiDataReceived(AUTH, fd, &head, data);
}
/*

View File

@ -101,7 +101,7 @@ HWTEST_F(AuthTcpConnectionTest, RECV_PACKET_HEAD_TEST_001, TestSize.Level1)
int32_t fd = 0;
SocketPktHead pktHead;
(void)memset_s(&pktHead, sizeof(SocketPktHead), 0, sizeof(SocketPktHead));
int32_t ret = RecvPacketHead(fd, &pktHead);
int32_t ret = RecvPacketHead(AUTH, fd, &pktHead);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
@ -118,11 +118,11 @@ HWTEST_F(AuthTcpConnectionTest, RECV_PACKET_DATA_TEST_001, TestSize.Level1)
uint8_t data[TEST_DATA_LEN] = { 0 };
(void)memset_s(&pktHead, sizeof(SocketPktHead), 0, sizeof(SocketPktHead));
pktHead.module = MODULE_AUTH_CHANNEL;
NotifyDataReceived(fd, &pktHead, data);
NotifyDataReceived(AUTH, fd, &pktHead, data);
pktHead.module = MODULE_AUTH_MSG;
NotifyDataReceived(fd, &pktHead, data);
NotifyDataReceived(AUTH, fd, &pktHead, data);
pktHead.module = MODULE_CONNECTION;
NotifyDataReceived(fd, &pktHead, data);
NotifyDataReceived(AUTH, fd, &pktHead, data);
uint32_t len = TEST_DATA_LEN;
uint8_t *packetData = RecvPacketData(fd, len);
@ -139,11 +139,11 @@ HWTEST_F(AuthTcpConnectionTest, PROCESS_SOCKET_OUT_EVENT_TEST_001, TestSize.Leve
{
int32_t fd = 0;
bool isClient = true;
NotifyConnected(fd, isClient);
NotifyConnected(AUTH, fd, isClient);
NotifyDisconnected(fd);
StopSocketListening();
int32_t ret = ProcessSocketOutEvent(fd);
int32_t ret = ProcessSocketOutEvent(AUTH, fd);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
@ -163,7 +163,7 @@ HWTEST_F(AuthTcpConnectionTest, PROCESS_SOCKET_IN_EVENT_TEST_001, TestSize.Level
NotifyChannelDataReceived(channelId, &head, data);
NotifyChannelDisconnected(channelId);
int32_t ret = ProcessSocketInEvent(fd);
int32_t ret = ProcessSocketInEvent(AUTH, fd);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
@ -217,9 +217,16 @@ HWTEST_F(AuthTcpConnectionTest, ON_DATA_EVENT_TEST_001, TestSize.Level1)
*/
HWTEST_F(AuthTcpConnectionTest, START_SOCKET_LISTENING_TEST_001, TestSize.Level1)
{
const char *ip = "192.168.12.1";
int32_t port = 22;
int32_t ret = StartSocketListening(ip, port);
LocalListenerInfo info = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "192.168.12.1",
.port = 22,
.moduleId = AUTH,
.protocol = LNN_PROTOCOL_IP,
},
};
int32_t ret = StartSocketListening(AUTH, &info);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}

View File

@ -522,10 +522,16 @@ HWTEST_F(AuthTest, POST_VERIFY_DEVICE_MESSAGE_001, TestSize.Level1)
*/
HWTEST_F(AuthTest, START_SOCKET_LISTENING_Test_001, TestSize.Level1)
{
const char *ip = "192.168.12.1";
int32_t port = 22;
int32_t ret = StartSocketListening(ip, port);
LocalListenerInfo info = {
.type = CONNECT_TCP,
.socketOption = {
.addr = "192.168.12.1",
.port = 22,
.moduleId = AUTH,
.protocol = LNN_PROTOCOL_IP,
},
};
int32_t ret = StartSocketListening(AUTH, &info);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}

View File

@ -109,6 +109,9 @@ public:
virtual int32_t LnnGenLocalUuid(char *uuid, uint32_t len);
virtual int32_t LnnGenLocalNetworkId(char *networkId, uint32_t len);
virtual int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, const char *addr);
virtual int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort);
virtual int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort);
virtual int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort);
virtual int32_t LnnInitP2p(void);
virtual void LnnDeinitP2p(void);
virtual int32_t LnnInitNetworkInfo(void);
@ -141,7 +144,8 @@ public:
virtual void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, int32_t weight);
virtual int32_t LnnInitFastOffline(void);
virtual int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum);
virtual void LnnNotifyNodeAddressChanged(const char* addr);
virtual bool LnnIsLSANode(const NodeBasicInfo *info) = 0;
virtual void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool isLocal);
virtual int32_t LnnInitOffline(void);
virtual void LnnDeinitOffline(void);
};
@ -200,6 +204,9 @@ public:
MOCK_METHOD2(LnnGenLocalUuid, int32_t (char *, uint32_t));
MOCK_METHOD2(LnnGenLocalNetworkId, int32_t (char *, uint32_t));
MOCK_METHOD3(LnnSetDLNodeAddr, int32_t (const char *, IdCategory, const char *));
MOCK_METHOD3(LnnSetDLProxyPort, int32_t (const char *, IdCategory, int32_t));
MOCK_METHOD3(LnnSetDLSessionPort, int32_t (const char *, IdCategory, int32_t));
MOCK_METHOD3(LnnSetDLAuthPort, int32_t (const char *, IdCategory, int32_t));
MOCK_METHOD0(LnnInitP2p, int32_t ());
MOCK_METHOD0(LnnDeinitP2p, void ());
MOCK_METHOD0(LnnInitNetworkInfo, int32_t ());
@ -232,7 +239,8 @@ public:
MOCK_METHOD3(LnnNotifyMasterNodeChanged, void (bool, const char*, int32_t));
MOCK_METHOD0(LnnInitFastOffline, int32_t ());
MOCK_METHOD2(LnnGetAllOnlineNodeInfo, int32_t (NodeBasicInfo **, int32_t *));
MOCK_METHOD1(LnnNotifyNodeAddressChanged, void (const char*));
MOCK_METHOD1(LnnIsLSANode, bool(const NodeBasicInfo *));
MOCK_METHOD3(LnnNotifyNodeAddressChanged, void (const char *, const char *, bool));
MOCK_METHOD0(LnnInitOffline, int32_t ());
MOCK_METHOD0(LnnDeinitOffline, void ());

View File

@ -59,6 +59,7 @@ public:
virtual int32_t LnnSetP2pGoMac(NodeInfo *info, const char *goMac) = 0;
virtual int32_t LnnGetAllOnlineAndMetaNodeInfo(NodeBasicInfo **info, int32_t *infoNum) = 0;
virtual int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum) = 0;
virtual bool LnnIsLSANode(const NodeBasicInfo *info) = 0;
virtual NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type) = 0;
virtual int32_t LnnGetLnnRelation(const char *id, IdCategory type, uint8_t *relation, uint32_t len) = 0;
virtual int32_t LnnSetDLConnCapability(const char *networkId, uint64_t connCapability) = 0;
@ -110,6 +111,7 @@ public:
MOCK_METHOD2(LnnSetP2pGoMac, int32_t (NodeInfo *, const char *));
MOCK_METHOD2(LnnGetAllOnlineAndMetaNodeInfo, int32_t (NodeBasicInfo **, int32_t *));
MOCK_METHOD2(LnnGetAllOnlineNodeInfo, int32_t (NodeBasicInfo **, int32_t *));
MOCK_METHOD1(LnnIsLSANode, bool(const NodeBasicInfo *));
MOCK_METHOD2(LnnGetNodeInfoById, NodeInfo *(const char *, IdCategory));
MOCK_METHOD4(LnnGetLnnRelation, int32_t(const char *, IdCategory, uint8_t *, uint32_t));
MOCK_METHOD2(LnnSetDLConnCapability, int32_t (const char *, uint64_t));

View File

@ -306,6 +306,21 @@ int32_t LnnSetDLNodeAddr(const char *id, IdCategory type, const char *addr)
return GetNetBuilderDepsInterface()->LnnSetDLNodeAddr(id, type, addr);
}
int32_t LnnSetDLProxyPort(const char *id, IdCategory type, int32_t proxyPort)
{
return GetNetBuilderDepsInterface()->LnnSetDLProxyPort(id, type, proxyPort);
}
int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort)
{
return GetNetBuilderDepsInterface()->LnnSetDLSessionPort(id, type, sessionPort);
}
int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort)
{
return GetNetBuilderDepsInterface()->LnnSetDLAuthPort(id, type, authPort);
}
int32_t LnnInitP2p(void)
{
return GetNetBuilderDepsInterface()->LnnInitP2p();
@ -466,9 +481,14 @@ int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum)
return GetNetBuilderDepsInterface()->LnnGetAllOnlineNodeInfo(info, infoNum);
}
void LnnNotifyNodeAddressChanged(const char* addr)
bool LnnIsLSANode(const NodeBasicInfo *info)
{
return GetNetBuilderDepsInterface()->LnnNotifyNodeAddressChanged(addr);
return GetNetBuilderDepsInterface()->LnnIsLSANode(info);
}
void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool isLocal)
{
return GetNetBuilderDepsInterface()->LnnNotifyNodeAddressChanged(addr, networkId, isLocal);
}
int32_t LnnInitOffline(void)

View File

@ -245,7 +245,9 @@ HWTEST_F(LNNNetBuilderMockTest, LNN_UPDATE_NODE_ADDR_TEST_001, TestSize.Level1)
EXPECT_CALL(NetBuilderMock, LnnGetAllOnlineNodeInfo(_, _))
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(NetBuilderMock, LnnNotifyNodeAddressChanged(_)).WillRepeatedly(Return());
EXPECT_CALL(NetBuilderMock, LnnNotifyNodeAddressChanged(_, _, _))
.WillOnce(Return())
.WillRepeatedly(Return());
EXPECT_TRUE(LnnUpdateNodeAddr(nullptr) == SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) == SOFTBUS_ERR);
EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) == SOFTBUS_OK);

View File

@ -313,6 +313,11 @@ int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum)
return GetNetLedgerInterface()->LnnGetAllOnlineNodeInfo(info, infoNum);
}
bool LnnIsLSANode(const NodeBasicInfo *info)
{
return GetNetLedgerInterface()->LnnIsLSANode(info);
}
NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type)
{
return GetNetLedgerInterface()->LnnGetNodeInfoById(id, type);

View File

@ -35,6 +35,7 @@ public:
virtual int32_t MetaNodeServerLeave(const char *networkId) = 0;
virtual int32_t LnnServerLeave(const char *networkId, const char *pkgName) = 0;
virtual int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum) = 0;
virtual bool LnnIsLSANode(const NodeBasicInfo *info) = 0;
virtual int32_t LnnGetLocalDeviceInfo(NodeBasicInfo *info) = 0;
virtual int32_t LnnGetNodeKeyInfo(const char *networkId, int key, uint8_t *info, uint32_t infoLen) = 0;
virtual int32_t LnnSetNodeDataChangeFlag(const char *networkId, uint16_t dataChangeFlag) = 0;
@ -80,6 +81,7 @@ public:
MOCK_METHOD2(LnnServerLeave, int32_t(const char *, const char *));
MOCK_METHOD1(MetaNodeServerLeave, int32_t(const char *));
MOCK_METHOD2(LnnGetAllOnlineNodeInfo, int32_t(NodeBasicInfo **, int32_t *));
MOCK_METHOD1(LnnIsLSANode, bool(const NodeBasicInfo *));
MOCK_METHOD1(LnnGetLocalDeviceInfo, int32_t(NodeBasicInfo *));
MOCK_METHOD4(LnnGetNodeKeyInfo, int32_t(const char *, int, uint8_t *, uint32_t));
MOCK_METHOD2(LnnSetNodeDataChangeFlag, int32_t(const char *, uint16_t));

View File

@ -35,6 +35,7 @@ public:
virtual int32_t LnnNotifyDiscoveryDevice(const ConnectionAddr *addr) = 0;
virtual int32_t LnnSetHbAsMasterNodeState(bool isMasterNode) = 0;
virtual int32_t LnnNotifyMasterElect(const char *networkId, const char *masterUdid, int32_t masterWeight) = 0;
virtual void LnnNotifyHBRepeat(void);
virtual int32_t LnnStartHbByTypeAndStrategy(
LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType, bool isRelay) = 0;
virtual int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type) = 0;
@ -67,6 +68,7 @@ public:
MOCK_METHOD1(LnnNotifyDiscoveryDevice, int32_t(const ConnectionAddr *));
MOCK_METHOD3(LnnNotifyMasterElect, int32_t(const char *, const char *, int32_t));
MOCK_METHOD1(LnnSetHbAsMasterNodeState, int32_t(bool));
MOCK_METHOD0(LnnNotifyHBRepeat, void ());
MOCK_METHOD3(LnnStartHbByTypeAndStrategy, int32_t(LnnHeartbeatType, LnnHeartbeatStrategyType, bool));
MOCK_METHOD1(LnnHbMediumMgrStop, int32_t(LnnHeartbeatType *));
MOCK_METHOD0(LnnDumpHbMgrRecvList, void(void));

View File

@ -62,6 +62,11 @@ int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum)
return BusCenterIpcInterfaceInstance()->LnnGetAllOnlineNodeInfo(info, infoNum);
}
bool LnnIsLSANode(const NodeBasicInfo *info)
{
return BusCenterIpcInterfaceInstance()->LnnIsLSANode(info);
}
int32_t LnnGetLocalDeviceInfo(NodeBasicInfo *info)
{
return BusCenterIpcInterfaceInstance()->LnnGetLocalDeviceInfo(info);

View File

@ -62,6 +62,11 @@ int32_t LnnSetHbAsMasterNodeState(bool isMasterNode)
return HeartBeatFSMInterfaceInstance()->LnnSetHbAsMasterNodeState(isMasterNode);
}
void LnnNotifyHBRepeat(void)
{
return HeartBeatFSMInterfaceInstance()->LnnNotifyHBRepeat();
}
int32_t LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType, bool isRelay)
{
return HeartBeatFSMInterfaceInstance()->LnnStartHbByTypeAndStrategy(hbType, strategyType, isRelay);

View File

@ -20,6 +20,9 @@
#include "softbus_conn_interface.h"
#include "p2plink_interface.h"
#include "lnn_node_info.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_network_manager.h"
namespace OHOS {
class TransConnInterface {
@ -55,6 +58,12 @@ public:
virtual bool CheckActiveConnection(const ConnectOption *option) = 0;
virtual int32_t ConnSetConnectCallback(ConnModule moduleId, const ConnectCallback *callback) = 0;
virtual uint32_t ConnGetHeadSize(void) = 0;
virtual void NipRecvDataFromBr(uint32_t connId, const char *buf) = 0;
virtual void NipConnectDevice(uint32_t connId, const char *mac) = 0;
virtual void NipDisconnectDevice(uint32_t connId) = 0;
virtual ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode mode) = 0;
virtual NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type) = 0;
virtual bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type) = 0;
};
class TransConnInterfaceMock : public TransConnInterface {
@ -87,6 +96,12 @@ public:
MOCK_METHOD0(ConnGetHeadSize, uint32_t (void));
MOCK_METHOD2(ConnSetConnectCallback, int32_t (ConnModule, const ConnectCallback *));
MOCK_METHOD2(NipRecvDataFromBr, void (uint32_t, const char *));
MOCK_METHOD2(NipConnectDevice, void (uint32_t, const char *));
MOCK_METHOD1(NipDisconnectDevice, void (uint32_t));
MOCK_METHOD2(LnnGetProtocolListenerModule, ListenerModule (ProtocolType, ListenerMode));
MOCK_METHOD2(LnnGetNodeInfoById, NodeInfo* (const char *, IdCategory));
MOCK_METHOD2(LnnHasDiscoveryType, bool (const NodeInfo *, DiscoveryType));
};
} // namespace OHOS

View File

@ -19,5 +19,10 @@ trans_comm_mock_src = [
"$trans_comm_mock_path/src/trans_conn_mock.cpp",
"$trans_comm_mock_path/src/trans_auth_mock.cpp",
]
trans_comm_mock_inc = [ "$trans_comm_mock_path/include" ]
trans_comm_mock_inc = [
"$trans_comm_mock_path/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
]
trans_comm_mock_deps = []

View File

@ -142,5 +142,34 @@ int32_t ConnSetConnectCallback(ConnModule moduleId, const ConnectCallback *callb
{
return GetConnectInterface()->ConnSetConnectCallback(moduleId, callback);
}
void NipRecvDataFromBr(uint32_t connId, const char *buf)
{
return GetConnectInterface()->NipRecvDataFromBr(connId, buf);
}
void NipConnectDevice(uint32_t connId, const char *mac)
{
return GetConnectInterface()->NipConnectDevice(connId, mac);
}
void NipDisconnectDevice(uint32_t connId)
{
return GetConnectInterface()->NipDisconnectDevice(connId);
}
ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode mode)
{
return GetConnectInterface()->LnnGetProtocolListenerModule(protocol, mode);
}
NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type)
{
return GetConnectInterface()->LnnGetNodeInfoById(id, type);
}
bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type)
{
return GetConnectInterface()->LnnHasDiscoveryType(info, type);
}
}
}

View File

@ -49,6 +49,7 @@ ohos_unittest("TransChannelManagerTest") {
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/sync_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
"$dsoftbus_root_path/core/common/message_handler/include",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",