!2420 新增wifi/蓝牙掉线时的UDP通道处理流程

Merge pull request !2420 from zhangshen/master
This commit is contained in:
openharmony_ci 2022-09-26 06:23:44 +00:00 committed by Gitee
commit cbc8f79d5d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 105 additions and 24 deletions

View File

@ -90,11 +90,6 @@ void InitSoftBusServer(void)
goto ERR_EXIT;
}
if (TransServerInit() == SOFTBUS_ERR) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus trans server init failed.");
goto ERR_EXIT;
}
if (AuthInit() == SOFTBUS_ERR) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus auth init failed.");
goto ERR_EXIT;
@ -110,6 +105,11 @@ void InitSoftBusServer(void)
goto ERR_EXIT;
}
if (TransServerInit() == SOFTBUS_ERR) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus trans server init failed.");
goto ERR_EXIT;
}
if (InitP2pLink() != SOFTBUS_OK) {
goto ERR_EXIT;
}

View File

@ -78,6 +78,7 @@ typedef struct {
char groupId[GROUP_ID_SIZE_MAX];
char sessionKey[SESSION_KEY_LENGTH];
char reqId[REQ_ID_SIZE_MAX];
char peerNetWorkId[DEVICE_ID_SIZE_MAX];
RouteType routeType;
BusinessType businessType;
StreamType streamType;

View File

@ -88,6 +88,34 @@ void TransChannelDeinit(void)
TransReqLanePendingDeinit();
}
static int32_t CopyAppInfoFromSessionParam(AppInfo* appInfo, const SessionParam* param)
{
if (TransGetUidAndPid(param->sessionName, &appInfo->myData.uid, &appInfo->myData.pid) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (strcpy_s(appInfo->groupId, sizeof(appInfo->groupId), param->groupId) != EOK) {
return SOFTBUS_ERR;
}
if (strcpy_s(appInfo->myData.sessionName, sizeof(appInfo->myData.sessionName), param->sessionName) != EOK) {
return SOFTBUS_ERR;
}
if (strcpy_s(appInfo->peerNetWorkId, sizeof(appInfo->peerNetWorkId), param->peerDeviceId) != EOK) {
return SOFTBUS_ERR;
}
if (TransGetPkgNameBySessionName(param->sessionName, appInfo->myData.pkgName, PKG_NAME_SIZE_MAX) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (strcpy_s(appInfo->peerData.sessionName, sizeof(appInfo->peerData.sessionName), param->peerSessionName) != 0) {
return SOFTBUS_ERR;
}
if (LnnGetRemoteStrInfo(param->peerDeviceId, STRING_KEY_UUID,
appInfo->peerData.deviceId, sizeof(appInfo->peerData.deviceId)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "get remote node uuid err");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static AppInfo *GetAppInfo(const SessionParam *param)
{
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "GetAppInfo");
@ -103,20 +131,11 @@ static AppInfo *GetAppInfo(const SessionParam *param)
} else if (param->attr->dataType == TYPE_FILE) {
appInfo->businessType = BUSINESS_TYPE_FILE;
}
if (TransGetUidAndPid(param->sessionName, &appInfo->myData.uid, &appInfo->myData.pid) != SOFTBUS_OK) {
goto EXIT_ERR;
}
if (LnnGetLocalStrInfo(STRING_KEY_UUID, appInfo->myData.deviceId,
sizeof(appInfo->myData.deviceId)) != SOFTBUS_OK) {
goto EXIT_ERR;
}
if (strcpy_s(appInfo->groupId, sizeof(appInfo->groupId), param->groupId) != EOK) {
goto EXIT_ERR;
}
if (strcpy_s(appInfo->myData.sessionName, sizeof(appInfo->myData.sessionName), param->sessionName) != EOK) {
goto EXIT_ERR;
}
if (TransGetPkgNameBySessionName(param->sessionName, appInfo->myData.pkgName, PKG_NAME_SIZE_MAX) != SOFTBUS_OK) {
if (CopyAppInfoFromSessionParam(appInfo, param) != SOFTBUS_OK) {
goto EXIT_ERR;
}
@ -124,14 +143,7 @@ static AppInfo *GetAppInfo(const SessionParam *param)
appInfo->encrypt = APP_INFO_FILE_FEATURES_SUPPORT;
appInfo->algorithm = APP_INFO_ALGORITHM_AES_GCM_256;
appInfo->crc = APP_INFO_FILE_FEATURES_SUPPORT;
if (strcpy_s(appInfo->peerData.sessionName, sizeof(appInfo->peerData.sessionName), param->peerSessionName) != 0) {
goto EXIT_ERR;
}
if (LnnGetRemoteStrInfo(param->peerDeviceId, STRING_KEY_UUID,
appInfo->peerData.deviceId, sizeof(appInfo->peerData.deviceId)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "get remote node uuid err");
goto EXIT_ERR;
}
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "GetAppInfo ok");
return appInfo;
EXIT_ERR:

View File

@ -45,6 +45,7 @@ void ReleaseUdpChannelLock(void);
int32_t TransAddUdpChannel(UdpChannelInfo *channel);
int32_t TransDelUdpChannel(int32_t channelId);
void TransCloseUdpChannelByNetWorkId(const char* netWorkId);
int32_t TransGetUdpChannelBySeq(int64_t seq, UdpChannelInfo *channel);
int32_t TransGetUdpChannelById(int32_t channelId, UdpChannelInfo *channel);

View File

@ -205,6 +205,47 @@ int32_t TransDelUdpChannel(int32_t channelId)
return SOFTBUS_ERR;
}
static void NotifyUdpChannelCloseInList(ListNode *udpChannelList)
{
UdpChannelInfo *udpChannel = NULL;
UdpChannelInfo *udpChannelNext = NULL;
LIST_FOR_EACH_ENTRY_SAFE(udpChannel, udpChannelNext, udpChannelList, UdpChannelInfo, node) {
(void)NotifyUdpChannelClosed(&udpChannel->info);
ListDelete(&(udpChannel->node));
SoftBusFree(udpChannel);
}
}
void TransCloseUdpChannelByNetWorkId(const char* netWorkId)
{
if ((g_udpChannelMgr == NULL) || (netWorkId == NULL)) {
return;
}
if (SoftBusMutexLock(&g_udpChannelMgr->lock) != 0) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "TransCloseUdpChannelByAuId lock failed");
return;
}
ListNode udpDeleteChannelList;
ListInit(&udpDeleteChannelList);
UdpChannelInfo *udpChannel = NULL;
UdpChannelInfo *udpChannelNext = NULL;
LIST_FOR_EACH_ENTRY_SAFE(udpChannel, udpChannelNext, &g_udpChannelMgr->list, UdpChannelInfo, node) {
if (strcmp(udpChannel->info.peerNetWorkId, netWorkId) == 0) {
ReleaseUdpChannelId((int32_t)(udpChannel->info.myData.channelId));
ListDelete(&(udpChannel->node));
g_udpChannelMgr->cnt--;
ListAdd(&udpDeleteChannelList, &(udpChannel->node));
}
}
(void)SoftBusMutexUnlock(&g_udpChannelMgr->lock);
NotifyUdpChannelCloseInList(&udpDeleteChannelList);
}
int32_t TransGetUdpChannelBySeq(int64_t seq, UdpChannelInfo *channel)
{
if (g_udpChannelMgr == NULL) {

View File

@ -16,6 +16,7 @@
#include "trans_udp_negotiation.h"
#include "auth_interface.h"
#include "bus_center_event.h"
#include "bus_center_info_key.h"
#include "bus_center_manager.h"
#include "p2plink_interface.h"
@ -750,6 +751,20 @@ static void UdpModuleCb(int64_t authId, const AuthTransData *data)
}
}
void TransUdpNodeOffLineProc(const LnnEventBasicInfo *info)
{
if ((info == NULL) || (info->event != LNN_EVENT_NODE_ONLINE_STATE_CHANGED)) {
return;
}
LnnOnlineStateEventInfo *onlineStateInfo = (LnnOnlineStateEventInfo*)info;
if (onlineStateInfo->isOnline == true) {
return;
}
TransCloseUdpChannelByNetWorkId(onlineStateInfo->networkId);
}
int32_t TransUdpChannelInit(IServerChannelCallBack *callback)
{
g_channelCb = callback;
@ -770,6 +785,12 @@ int32_t TransUdpChannelInit(IServerChannelCallBack *callback)
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "register udp callback to auth failed.");
return SOFTBUS_ERR;
}
if (LnnRegisterEventHandler(LNN_EVENT_NODE_ONLINE_STATE_CHANGED, TransUdpNodeOffLineProc) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "register udp Node offLine Proc failed.");
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "server trans udp channel init success.");
return SOFTBUS_OK;
}
@ -778,6 +799,8 @@ void TransUdpChannelDeinit(void)
{
TransUdpChannelMgrDeinit();
UnregAuthTransListener(MODULE_UDP_INFO);
LnnUnregisterEventHandler(LNN_EVENT_NODE_ONLINE_STATE_CHANGED, TransUdpNodeOffLineProc);
g_channelCb = NULL;
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "server trans udp channel deinit success.");
}

View File

@ -27,4 +27,7 @@ if (dsoftbus_feature_trans_udp == true) {
"$udp_channel_path/src/trans_udp_channel_manager_virtual.c",
]
}
trans_udp_channel_inc = [ "$udp_channel_path/include" ]
trans_udp_channel_inc = [
"$udp_channel_path/include",
"$dsoftbus_root_path/core/bus_center/service/include",
]