mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 10:50:41 +00:00
fix: auth session add timeout
Signed-off-by: liangjunhao <liangjunhao10@huawei.com>
This commit is contained in:
parent
e03355ae0e
commit
a0b2dd6eb6
@ -28,6 +28,8 @@ extern "C" {
|
||||
|
||||
#define IS_SERVER 0
|
||||
#define IS_CLIENT 1
|
||||
#define ISHARE_AUTH_SESSION "IShareAuthSession"
|
||||
#define ISHARE_AUTH_SESSION_MAX_IDLE_TIME 5000 // 5s
|
||||
|
||||
typedef struct {
|
||||
char peerSessionName[SESSION_NAME_SIZE_MAX];
|
||||
@ -278,6 +280,8 @@ int32_t ClientSignalSyncBind(int32_t socket, int32_t errCode);
|
||||
int32_t ClientDfsIpcOpenSession(int32_t sessionId, TransInfo *transInfo);
|
||||
|
||||
void SocketServerStateUpdate(const char *sessionName);
|
||||
|
||||
int32_t ClientCancelAuthSessionTimer(int32_t sessionId);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -69,7 +69,8 @@ void ClientConvertRetVal(int32_t socket, int32_t *retOut);
|
||||
|
||||
void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList);
|
||||
|
||||
void ClientCheckWaitTimeOut(SessionInfo *sessionNode, int32_t waitOutSocket[], uint32_t capacity, uint32_t *num);
|
||||
void ClientCheckWaitTimeOut(const ClientSessionServer *serverNode, SessionInfo *sessionNode,
|
||||
int32_t waitOutSocket[], uint32_t capacity, uint32_t *num);
|
||||
|
||||
void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum);
|
||||
|
||||
|
@ -1010,6 +1010,17 @@ int32_t ClientGetDataConfigByChannelId(int32_t channelId, int32_t channelType, u
|
||||
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Only need to operate on the action guidance ishare auth channel
|
||||
static void ClientSetAuthSessionTimer(const ClientSessionServer *serverNode, SessionInfo *sessionNode)
|
||||
{
|
||||
if (strcmp(serverNode->sessionName, ISHARE_AUTH_SESSION) == 0 && sessionNode->channelType == CHANNEL_TYPE_AUTH &&
|
||||
sessionNode->actionId != 0) {
|
||||
sessionNode->lifecycle.maxWaitTime = ISHARE_AUTH_SESSION_MAX_IDLE_TIME;
|
||||
sessionNode->lifecycle.waitTime = 0;
|
||||
TRANS_LOGI(TRANS_SDK, "set auth sessionId=%{public}d waitTime success.", sessionNode->sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sessionId)
|
||||
{
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(
|
||||
@ -1045,6 +1056,7 @@ int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sess
|
||||
sessionNode->isEncrypt = channel->isEncrypt;
|
||||
*sessionId = sessionNode->sessionId;
|
||||
if (channel->channelType == CHANNEL_TYPE_AUTH || !sessionNode->isEncrypt) {
|
||||
ClientSetAuthSessionTimer(serverNode, sessionNode);
|
||||
if (memcpy_s(sessionNode->info.peerDeviceId, DEVICE_ID_SIZE_MAX,
|
||||
channel->peerDeviceId, DEVICE_ID_SIZE_MAX) != EOK) {
|
||||
UnlockClientSessionServerList();
|
||||
@ -1783,7 +1795,7 @@ static void ClientTransSessionTimerProc(void)
|
||||
}
|
||||
LIST_FOR_EACH_ENTRY_SAFE(sessionNode, nextSessionNode, &(serverNode->sessionList), SessionInfo, node) {
|
||||
ClientUpdateIdleTimeout(serverNode, sessionNode, &destroyList);
|
||||
ClientCheckWaitTimeOut(sessionNode, waitOutSocket, MAX_SESSION_ID, &waitOutNum);
|
||||
ClientCheckWaitTimeOut(serverNode, sessionNode, waitOutSocket, MAX_SESSION_ID, &waitOutNum);
|
||||
}
|
||||
}
|
||||
UnlockClientSessionServerList();
|
||||
@ -2263,3 +2275,50 @@ int32_t ClientDfsIpcOpenSession(int32_t sessionId, TransInfo *transInfo)
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ClientUpdateAuthSessionTimer(SessionInfo *sessionNode, int32_t sessionId)
|
||||
{
|
||||
// Only need to operate on the action guidance channel
|
||||
if (sessionNode->actionId == 0) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (sessionNode->lifecycle.maxWaitTime == 0) {
|
||||
TRANS_LOGE(TRANS_SDK, "sessionId=%{public}d is not need update.", sessionId);
|
||||
return SOFTBUS_NOT_NEED_UPDATE;
|
||||
}
|
||||
sessionNode->lifecycle.maxWaitTime = 0;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ClientCancelAuthSessionTimer(int32_t sessionId)
|
||||
{
|
||||
if (sessionId <= 0) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid sessionId");
|
||||
return SOFTBUS_TRANS_INVALID_SESSION_ID;
|
||||
}
|
||||
|
||||
int32_t ret = LockClientSessionServerList();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "lock failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ClientSessionServer *serverNode = NULL;
|
||||
SessionInfo *sessionNode = NULL;
|
||||
LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
|
||||
if (IsListEmpty(&serverNode->sessionList) || strcmp(serverNode->sessionName, ISHARE_AUTH_SESSION) != 0) {
|
||||
continue;
|
||||
}
|
||||
LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
|
||||
if (sessionNode->sessionId != sessionId || sessionNode->channelType != CHANNEL_TYPE_AUTH) {
|
||||
continue;
|
||||
}
|
||||
ret = ClientUpdateAuthSessionTimer(sessionNode, sessionId);
|
||||
UnlockClientSessionServerList();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
UnlockClientSessionServerList();
|
||||
TRANS_LOGE(TRANS_SDK, "not found ishare auth session by sessionId=%{public}d", sessionId);
|
||||
return SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND;
|
||||
}
|
||||
|
@ -630,13 +630,15 @@ void ClientCleanUpIdleTimeoutSocket(const ListNode *destroyList)
|
||||
TRANS_LOGD(TRANS_SDK, "ok");
|
||||
}
|
||||
|
||||
void ClientCheckWaitTimeOut(SessionInfo *sessionNode, int32_t waitOutSocket[], uint32_t capacity, uint32_t *num)
|
||||
void ClientCheckWaitTimeOut(const ClientSessionServer *serverNode, SessionInfo *sessionNode,
|
||||
int32_t waitOutSocket[], uint32_t capacity, uint32_t *num)
|
||||
{
|
||||
if (sessionNode == NULL || waitOutSocket == NULL || num == NULL) {
|
||||
TRANS_LOGE(TRANS_SDK, "invalid param.");
|
||||
return;
|
||||
}
|
||||
if (sessionNode->enableStatus == ENABLE_STATUS_SUCCESS) {
|
||||
if (sessionNode->enableStatus == ENABLE_STATUS_SUCCESS &&
|
||||
strcmp(serverNode->sessionName, ISHARE_AUTH_SESSION) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -660,6 +662,26 @@ void ClientCheckWaitTimeOut(SessionInfo *sessionNode, int32_t waitOutSocket[], u
|
||||
*num = tmpNum + 1;
|
||||
}
|
||||
|
||||
static bool CleanUpTimeoutAuthSession(int32_t sessionId)
|
||||
{
|
||||
SocketLifecycleData lifecycle;
|
||||
(void)memset_s(&lifecycle, sizeof(SocketLifecycleData), 0, sizeof(SocketLifecycleData));
|
||||
char sessionName[SESSION_NAME_SIZE_MAX] = { 0 };
|
||||
int32_t ret = GetSocketLifecycleAndSessionNameBySessionId(sessionId, sessionName, &lifecycle);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SDK, "Get sessionId=%{public}d name failed, ret=%{public}d", sessionId, ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(sessionName, ISHARE_AUTH_SESSION) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TRANS_LOGI(TRANS_SDK, "sessionId=%{public}d is idle timeout.", sessionId);
|
||||
CloseSession(sessionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum)
|
||||
{
|
||||
if (waitOutSocket == NULL) {
|
||||
@ -672,7 +694,14 @@ void ClientCleanUpWaitTimeoutSocket(int32_t waitOutSocket[], uint32_t waitOutNum
|
||||
TRANS_LOGI(TRANS_SDK, "time out shutdown socket=%{public}d", waitOutSocket[i]);
|
||||
SessionEnableStatus enableStatus = ENABLE_STATUS_INIT;
|
||||
int32_t ret = ClientGetChannelBySessionId(waitOutSocket[i], NULL, NULL, &enableStatus);
|
||||
if (ret != SOFTBUS_OK || enableStatus == ENABLE_STATUS_SUCCESS) {
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGI(TRANS_SDK, "socket get channel failed, socket=%{public}d", waitOutSocket[i]);
|
||||
continue;
|
||||
}
|
||||
if (enableStatus == ENABLE_STATUS_SUCCESS) {
|
||||
if (CleanUpTimeoutAuthSession(waitOutSocket[i])) {
|
||||
continue;
|
||||
}
|
||||
TRANS_LOGI(TRANS_SDK, "socket has enabled, need not shutdown, socket=%{public}d", waitOutSocket[i]);
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user