mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-28 03:10:48 +00:00
!6210 fix:udp and tcp closesession error
Merge pull request !6210 from xzh/240523
This commit is contained in:
commit
3201d3b5ef
@ -236,6 +236,7 @@ void TransTdcDeathCallback(const char *pkgName, int32_t pid)
|
||||
TRANS_LOGI(TRANS_CTRL, "delete pkgName = %{public}s, pid = %{public}d", pkgName, pid);
|
||||
sessionList->cnt--;
|
||||
DelTrigger(item->listenMod, item->appInfo.fd, RW_TRIGGER);
|
||||
ConnShutdownSocket(item->appInfo.fd);
|
||||
SoftBusFree(item);
|
||||
continue;
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ void TransUpdateUdpChannelInfo(int64_t seq, const AppInfo *appInfo);
|
||||
UdpChannelInfo *TransGetChannelObj(int32_t channelId);
|
||||
|
||||
int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo);
|
||||
int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -516,3 +516,33 @@ int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo)
|
||||
TRANS_LOGE(TRANS_CTRL, "udp channel not found. channelId=%{public}d", channelId);
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
|
||||
int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo)
|
||||
{
|
||||
if (appInfo == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "Invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (g_udpChannelMgr == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "udp channel manager hasn't init.");
|
||||
return SOFTBUS_NO_INIT;
|
||||
}
|
||||
|
||||
if (SoftBusMutexLock(&(g_udpChannelMgr->lock)) != SOFTBUS_OK) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
|
||||
UdpChannelInfo *udpChannelNode = NULL;
|
||||
LIST_FOR_EACH_ENTRY(udpChannelNode, &(g_udpChannelMgr->list), UdpChannelInfo, node) {
|
||||
if (udpChannelNode->info.peerData.channelId == appInfo->peerData.channelId) {
|
||||
if (strcmp(udpChannelNode->info.peerData.addr, appInfo->peerData.addr) == EOK) {
|
||||
appInfo->myData.channelId = udpChannelNode->info.myData.channelId;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
|
||||
TRANS_LOGE(TRANS_CTRL, "not found peerChannelId and addr");
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "trans_log.h"
|
||||
#include "trans_udp_channel_manager.h"
|
||||
|
||||
#define BASE64_SESSION_KEY_LEN 45
|
||||
typedef enum {
|
||||
@ -99,19 +100,16 @@ int32_t TransUnpackReplyUdpInfo(const cJSON *msg, AppInfo *appInfo)
|
||||
int32_t TransUnpackRequestUdpInfo(const cJSON *msg, AppInfo *appInfo)
|
||||
{
|
||||
TRANS_LOGI(TRANS_CTRL, "unpack request udp info in negotiation.");
|
||||
if (msg == NULL || appInfo == NULL) {
|
||||
TRANS_LOGW(TRANS_CTRL, "invalid param.");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGW(msg != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "Invalid param");
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGW(appInfo != NULL, SOFTBUS_INVALID_PARAM, TRANS_CTRL, "Invalid param");
|
||||
unsigned char encodeSessionKey[BASE64_SESSION_KEY_LEN] = {0};
|
||||
size_t len = 0;
|
||||
(void)GetJsonObjectStringItem(msg, "SESSION_KEY", (char*)encodeSessionKey, BASE64_SESSION_KEY_LEN);
|
||||
int32_t ret = SoftBusBase64Decode((unsigned char*)appInfo->sessionKey, sizeof(appInfo->sessionKey), &len,
|
||||
(unsigned char*)encodeSessionKey, strlen((char*)encodeSessionKey));
|
||||
if (len != sizeof(appInfo->sessionKey) || ret != 0) {
|
||||
TRANS_LOGE(TRANS_CTRL, "mbedtls decode failed.");
|
||||
return SOFTBUS_DECRYPT_ERR;
|
||||
}
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(len == sizeof(appInfo->sessionKey),
|
||||
SOFTBUS_DECRYPT_ERR, TRANS_CTRL, "mbedtls decode failed.");
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == 0, SOFTBUS_DECRYPT_ERR, TRANS_CTRL, "mbedtls decode failed.");
|
||||
|
||||
(void)GetJsonObjectStringItem(msg, "PKG_NAME", appInfo->peerData.pkgName, PKG_NAME_SIZE_MAX);
|
||||
(void)GetJsonObjectStringItem(msg, "BUS_NAME", appInfo->myData.sessionName, SESSION_NAME_SIZE_MAX);
|
||||
@ -142,6 +140,11 @@ int32_t TransUnpackRequestUdpInfo(const cJSON *msg, AppInfo *appInfo)
|
||||
break;
|
||||
case TYPE_UDP_CHANNEL_CLOSE:
|
||||
(void)GetJsonObjectNumber64Item(msg, "PEER_CHANNEL_ID", &(appInfo->myData.channelId));
|
||||
(void)GetJsonObjectNumber64Item(msg, "MY_CHANNEL_ID", &(appInfo->peerData.channelId));
|
||||
(void)GetJsonObjectStringItem(msg, "MY_IP", appInfo->peerData.addr, sizeof(appInfo->peerData.addr));
|
||||
if (appInfo->myData.channelId == 0) {
|
||||
(void)TransUdpGetChannelIdByAddr(appInfo);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TRANS_LOGE(TRANS_CTRL, "invalid udp channel type.");
|
||||
@ -166,6 +169,8 @@ int32_t TransPackRequestUdpInfo(cJSON *msg, const AppInfo *appInfo)
|
||||
break;
|
||||
case TYPE_UDP_CHANNEL_CLOSE:
|
||||
(void)AddNumber64ToJsonObject(msg, "PEER_CHANNEL_ID", appInfo->peerData.channelId);
|
||||
(void)AddNumber64ToJsonObject(msg, "MY_CHANNEL_ID", appInfo->myData.channelId);
|
||||
(void)AddStringToJsonObject(msg, "MY_IP", appInfo->myData.addr);
|
||||
break;
|
||||
default:
|
||||
TRANS_LOGE(TRANS_CTRL, "invalid udp channel type.");
|
||||
|
@ -861,13 +861,13 @@ HWTEST_F(TransUdpNegoTest, ParseRequestAppInfo001, TestSize.Level1)
|
||||
|
||||
memset_s(appInfo, sizeof(AppInfo), 0, sizeof(AppInfo));
|
||||
appInfo->udpChannelOptType = TYPE_INVALID_CHANNEL;
|
||||
(void)TransSessionMgrInit();
|
||||
ret = ParseRequestAppInfo(authHandle, msg, appInfo);
|
||||
EXPECT_EQ(ret, SOFTBUS_ERR);
|
||||
|
||||
cJSON_Delete(msg);
|
||||
SoftBusFree(appInfo);
|
||||
SoftBusFree(newNode);
|
||||
TransSessionMgrDeinit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -885,11 +885,10 @@ HWTEST_F(TransUdpNegoTest, TransPackRequestUdpInfo001, TestSize.Level1)
|
||||
memset_s(appInfo, sizeof(AppInfo), 0, sizeof(AppInfo));
|
||||
GenerateAppInfo(appInfo);
|
||||
appInfo->udpChannelOptType = TYPE_UDP_CHANNEL_OPEN;
|
||||
cJSON *msg = cJSON_CreateObject();
|
||||
ASSERT_TRUE(msg != nullptr);
|
||||
|
||||
string msgStr = "normal msgStr";
|
||||
cJSON *msg = cJSON_Parse(msgStr.c_str());
|
||||
int32_t ret = TransPackRequestUdpInfo(msg, appInfo);
|
||||
EXPECT_EQ(ret, SOFTBUS_OK);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
|
||||
TransOnExchangeUdpInfoRequest(authHandle, seq, msg);
|
||||
cJSON_Delete(msg);
|
||||
|
Loading…
Reference in New Issue
Block a user