• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "client_trans_session_manager.h"
17 
18 #include <securec.h>
19 
20 #include "client_bus_center_manager.h"
21 #include "client_trans_channel_manager.h"
22 #include "softbus_adapter_mem.h"
23 #include "softbus_app_info.h"
24 #include "softbus_def.h"
25 #include "softbus_errcode.h"
26 #include "softbus_log.h"
27 #include "softbus_utils.h"
28 #include "trans_server_proxy.h"
29 
30 static int32_t g_sessionIdNum = 0;
31 static int32_t g_sessionId = 1;
32 static SoftBusList *g_clientSessionServerList = NULL;
33 
34 void TransSessionTimer(void);
35 
TransClientInit(void)36 int TransClientInit(void)
37 {
38     g_clientSessionServerList = CreateSoftBusList();
39     if (g_clientSessionServerList == NULL) {
40         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "init list failed");
41         return SOFTBUS_ERR;
42     }
43 
44     if (TransServerProxyInit() != SOFTBUS_OK) {
45         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "init trans ipc proxy failed");
46         return SOFTBUS_ERR;
47     }
48 
49     if (ClientTransChannelInit() != SOFTBUS_OK) {
50         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "init trans channel failed");
51         return SOFTBUS_ERR;
52     }
53 
54     ClientTransRegLnnOffline();
55     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "init trans client success");
56     return SOFTBUS_OK;
57 }
58 
GenerateSessionId(void)59 static int32_t GenerateSessionId(void)
60 {
61     if (g_sessionIdNum >= MAX_SESSION_ID) {
62         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "sessionid num cross the line error");
63         return INVALID_SESSION_ID;
64     }
65     int32_t id = g_sessionId++;
66     if (g_sessionId < 0) {
67         g_sessionId = 1;
68     }
69     g_sessionIdNum++;
70     return id;
71 }
72 
DestroySessionId(void)73 static void DestroySessionId(void)
74 {
75     if (g_sessionIdNum > 0) {
76         g_sessionIdNum--;
77     }
78     return;
79 }
80 
DestroyClientSessionServer(ClientSessionServer * server)81 static void DestroyClientSessionServer(ClientSessionServer *server)
82 {
83     if (server == NULL) {
84         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "invalid param");
85         return;
86     }
87 
88     if (!IsListEmpty(&(server->sessionList))) {
89         SessionInfo *sessionNode = NULL;
90         SessionInfo *sessionNodeNext = NULL;
91         LIST_FOR_EACH_ENTRY_SAFE(sessionNode, sessionNodeNext, &(server->sessionList), SessionInfo, node) {
92             int id = sessionNode->sessionId;
93             (void) ClientTransCloseChannel(sessionNode->channelId, sessionNode->channelType);
94             DestroySessionId();
95             ListDelete(&sessionNode->node);
96             SoftBusFree(sessionNode);
97             server->listener.session.OnSessionClosed(id);
98         }
99     }
100 
101     ListDelete(&(server->node));
102     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "destroy session server [%s]", server->sessionName);
103     SoftBusFree(server);
104 }
105 
TransClientDeinit(void)106 void TransClientDeinit(void)
107 {
108     if (g_clientSessionServerList == NULL) {
109         return;
110     }
111     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
112         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
113         return;
114     }
115     ClientSessionServer *serverNode = NULL;
116     ClientSessionServer *serverNodeNext = NULL;
117     LIST_FOR_EACH_ENTRY_SAFE(serverNode, serverNodeNext, &(g_clientSessionServerList->list),
118         ClientSessionServer, node) {
119         DestroyClientSessionServer(serverNode);
120     }
121     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
122 
123     DestroySoftBusList(g_clientSessionServerList);
124     g_clientSessionServerList = NULL;
125     ClientTransChannelDeinit();
126     TransServerProxyDeInit();
127 }
128 
TransSessionTimer(void)129 void TransSessionTimer(void)
130 {
131 #define TRANS_SESSION_TIMEOUT (7 * 24) // hour
132 #define TRANS_SESSION_COUNT_TIMEOUT (60 * 60) // count per hour
133     static int32_t count = 0;
134     count++;
135     if (count < TRANS_SESSION_COUNT_TIMEOUT) {
136         return;
137     }
138     count = 0;
139 
140     if (g_clientSessionServerList == NULL) {
141         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
142         return;
143     }
144 
145     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
146         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
147         return;
148     }
149 
150     ClientSessionServer *serverNode = NULL;
151     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
152         if (IsListEmpty(&(serverNode->sessionList))) {
153             continue;
154         }
155         SessionInfo *sessionNode = NULL;
156         SessionInfo *sessionNodeNext = NULL;
157         LIST_FOR_EACH_ENTRY_SAFE(sessionNode, sessionNodeNext, &(serverNode->sessionList), SessionInfo, node) {
158             sessionNode->timeout++;
159             if (sessionNode->timeout >= TRANS_SESSION_TIMEOUT) {
160                 serverNode->listener.session.OnSessionClosed(sessionNode->sessionId);
161                 (void)ClientTransCloseChannel(sessionNode->channelId, sessionNode->channelType);
162                 DestroySessionId();
163                 ListDelete(&(sessionNode->node));
164                 SoftBusFree(sessionNode);
165             }
166         }
167     }
168     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
169     return;
170 }
171 
SessionServerIsExist(const char * sessionName)172 static bool SessionServerIsExist(const char *sessionName)
173 {
174     /* need get lock before */
175     ListNode *pos = NULL;
176     ListNode *tmp = NULL;
177     ClientSessionServer *node = NULL;
178     LIST_FOR_EACH_SAFE(pos, tmp, &g_clientSessionServerList->list) {
179         node = (ClientSessionServer *)pos;
180         if (strcmp(node->sessionName, sessionName) == 0) {
181             return true;
182         }
183     }
184     return false;
185 }
186 
GetNewSessionServer(SoftBusSecType type,const char * sessionName,const char * pkgName,const ISessionListener * listener)187 static ClientSessionServer *GetNewSessionServer(SoftBusSecType type, const char *sessionName,
188     const char *pkgName, const ISessionListener *listener)
189 {
190     ClientSessionServer *server = SoftBusCalloc(sizeof(ClientSessionServer));
191     if (server == NULL) {
192         return NULL;
193     }
194     server->type = type;
195     if (strcpy_s(server->pkgName, sizeof(server->pkgName), pkgName) != EOK) {
196         goto EXIT_ERR;
197     }
198     if (strcpy_s(server->sessionName, sizeof(server->sessionName), sessionName) != EOK) {
199         goto EXIT_ERR;
200     }
201     if (memcpy_s(&server->listener.session, sizeof(ISessionListener), listener, sizeof(ISessionListener)) != EOK) {
202         goto EXIT_ERR;
203     }
204 
205     ListInit(&server->node);
206     ListInit(&server->sessionList);
207     return server;
208 EXIT_ERR:
209     if (server != NULL) {
210         SoftBusFree(server);
211     }
212     return NULL;
213 }
214 
ClientAddSessionServer(SoftBusSecType type,const char * pkgName,const char * sessionName,const ISessionListener * listener)215 int32_t ClientAddSessionServer(SoftBusSecType type, const char *pkgName, const char *sessionName,
216     const ISessionListener *listener)
217 {
218     if (pkgName == NULL || sessionName == NULL || listener == NULL) {
219         return SOFTBUS_INVALID_PARAM;
220     }
221 
222     if (g_clientSessionServerList == NULL) {
223         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
224         return SOFTBUS_ERR;
225     }
226     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
227         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
228         return SOFTBUS_LOCK_ERR;
229     }
230     if (SessionServerIsExist(sessionName)) {
231         (void)SoftBusMutexUnlock(&g_clientSessionServerList->lock);
232         return SOFTBUS_SERVER_NAME_REPEATED;
233     }
234 
235     if (g_clientSessionServerList->cnt >= MAX_SESSION_SERVER_NUMBER) {
236         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
237         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "server num reach max");
238         return SOFTBUS_INVALID_NUM;
239     }
240 
241     ClientSessionServer *server = GetNewSessionServer(type, sessionName, pkgName, listener);
242     if (server == NULL) {
243         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
244         return SOFTBUS_MEM_ERR;
245     }
246     ListAdd(&g_clientSessionServerList->list, &server->node);
247     g_clientSessionServerList->cnt++;
248 
249     (void)SoftBusMutexUnlock(&g_clientSessionServerList->lock);
250     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "session name [%s], pkg name [%s]",
251         server->sessionName, server->pkgName);
252     return SOFTBUS_OK;
253 }
254 
IsValidSessionParam(const SessionParam * param)255 static bool IsValidSessionParam(const SessionParam *param)
256 {
257     if ((param == NULL) ||
258         (param->sessionName == NULL) ||
259         (param->peerSessionName == NULL) ||
260         (param->peerDeviceId == NULL) ||
261         (param->groupId == NULL) ||
262         (param->attr == NULL)) {
263         return false;
264     }
265     return true;
266 }
267 
CreateNewSession(const SessionParam * param)268 static SessionInfo *CreateNewSession(const SessionParam *param)
269 {
270     SessionInfo *session = (SessionInfo*)SoftBusCalloc(sizeof(SessionInfo));
271     if (session == NULL) {
272         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "calloc failed");
273         return NULL;
274     }
275 
276     if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, param->peerSessionName) != EOK ||
277         strcpy_s(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX, param->peerDeviceId) != EOK ||
278         strcpy_s(session->info.groupId, GROUP_ID_SIZE_MAX, param->groupId) != EOK) {
279         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "strcpy failed");
280         SoftBusFree(session);
281         return NULL;
282     }
283 
284     session->sessionId = INVALID_SESSION_ID;
285     session->channelId = INVALID_CHANNEL_ID;
286     session->channelType = CHANNEL_TYPE_BUTT;
287     session->isServer = false;
288     session->isEnable = false;
289     session->info.flag = param->attr->dataType;
290     session->isEncrypt = true;
291 
292     return session;
293 }
294 
GetExistSession(const SessionParam * param)295 static SessionInfo *GetExistSession(const SessionParam *param)
296 {
297     /* need get lock before */
298     ClientSessionServer *serverNode = NULL;
299     SessionInfo *sessionNode = NULL;
300     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
301         if ((strcmp(serverNode->sessionName, param->sessionName) != 0) || IsListEmpty(&serverNode->sessionList)) {
302             continue;
303         }
304         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
305             if (sessionNode->isServer ||
306                 (strcmp(sessionNode->info.peerSessionName, param->peerSessionName) != 0) ||
307                 (strcmp(sessionNode->info.peerDeviceId, param->peerDeviceId) != 0) ||
308                 (strcmp(sessionNode->info.groupId, param->groupId) != 0) ||
309                 (sessionNode->info.flag != param->attr->dataType)) {
310                 continue;
311             }
312             return sessionNode;
313         }
314     }
315     return NULL;
316 }
317 
GetSessionById(int32_t sessionId,ClientSessionServer ** server,SessionInfo ** session)318 static int32_t GetSessionById(int32_t sessionId, ClientSessionServer **server, SessionInfo **session)
319 {
320     /* need get lock before */
321     ClientSessionServer *serverNode = NULL;
322     SessionInfo *sessionNode = NULL;
323 
324     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
325         if (IsListEmpty(&serverNode->sessionList)) {
326             continue;
327         }
328         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
329             if (sessionNode->sessionId == sessionId) {
330                 *server = serverNode;
331                 *session = sessionNode;
332                 return SOFTBUS_OK;
333             }
334         }
335     }
336     return SOFTBUS_ERR;
337 }
338 
AddSession(const char * sessionName,SessionInfo * session)339 static int32_t AddSession(const char *sessionName, SessionInfo *session)
340 {
341     /* need get lock before */
342     session->sessionId = GenerateSessionId();
343     if (session->sessionId < 0) {
344         return SOFTBUS_TRANS_SESSION_CNT_EXCEEDS_LIMIT;
345     }
346     ClientSessionServer *serverNode = NULL;
347     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
348         if (strcmp(serverNode->sessionName, sessionName) != 0) {
349             continue;
350         }
351         ListAdd(&serverNode->sessionList, &session->node);
352         return SOFTBUS_OK;
353     }
354     DestroySessionId();
355     return SOFTBUS_TRANS_SESSIONSERVER_NOT_CREATED;
356 }
357 
ClientAddNewSession(const char * sessionName,SessionInfo * session)358 int32_t ClientAddNewSession(const char *sessionName, SessionInfo *session)
359 {
360     if (session == NULL) {
361         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
362         return SOFTBUS_INVALID_PARAM;
363     }
364 
365     if (g_clientSessionServerList == NULL) {
366         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
367         return SOFTBUS_ERR;
368     }
369 
370     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
371         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
372         return SOFTBUS_ERR;
373     }
374 
375     int32_t ret = AddSession(sessionName, session);
376     if (ret != SOFTBUS_OK) {
377         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
378         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "add session failed, ret [%d]", ret);
379         return ret;
380     }
381     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
382     return SOFTBUS_OK;
383 }
384 
ClientAddSession(const SessionParam * param,int32_t * sessionId,bool * isEnabled)385 int32_t ClientAddSession(const SessionParam *param, int32_t *sessionId, bool *isEnabled)
386 {
387     if (!IsValidSessionParam(param) || (sessionId == NULL) || (isEnabled == NULL)) {
388         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
389         return SOFTBUS_INVALID_PARAM;
390     }
391 
392     if (g_clientSessionServerList == NULL) {
393         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
394         return SOFTBUS_ERR;
395     }
396 
397     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
398         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
399         return SOFTBUS_ERR;
400     }
401 
402     SessionInfo *session = GetExistSession(param);
403     if (session != NULL) {
404         *sessionId = session->sessionId;
405         *isEnabled = session->isEnable;
406         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
407         return SOFTBUS_TRANS_SESSION_REPEATED;
408     }
409 
410     session = CreateNewSession(param);
411     if (session == NULL) {
412         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
413         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "create session failed");
414         return SOFTBUS_ERR;
415     }
416 
417     int32_t ret = AddSession(param->sessionName, session);
418     if (ret != SOFTBUS_OK) {
419         SoftBusFree(session);
420         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
421         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Add Session failed, ret [%d]", ret);
422         return ret;
423     }
424 
425     *sessionId = session->sessionId;
426     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
427     return SOFTBUS_OK;
428 }
429 
CreateNonEncryptSessionInfo(const char * sessionName)430 static SessionInfo *CreateNonEncryptSessionInfo(const char *sessionName)
431 {
432     if (!IsValidString(sessionName, SESSION_NAME_SIZE_MAX)) {
433         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
434         return NULL;
435     }
436     SessionInfo *session = SoftBusCalloc(sizeof(SessionInfo));
437     if (session == NULL) {
438         return NULL;
439     }
440     session->channelType = CHANNEL_TYPE_AUTH;
441     session->isEncrypt = false;
442     if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, sessionName) != EOK) {
443         SoftBusFree(session);
444         return NULL;
445     }
446     return session;
447 }
448 
ClientAddAuthSession(const char * sessionName,int32_t * sessionId)449 int32_t ClientAddAuthSession(const char *sessionName, int32_t *sessionId)
450 {
451     if (!IsValidString(sessionName, SESSION_NAME_SIZE_MAX) || (sessionId == NULL)) {
452         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
453         return SOFTBUS_INVALID_PARAM;
454     }
455     if (g_clientSessionServerList == NULL) {
456         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
457         return SOFTBUS_ERR;
458     }
459     SessionInfo *session = CreateNonEncryptSessionInfo(sessionName);
460     if (session == NULL) {
461         return SOFTBUS_MALLOC_ERR;
462     }
463     if (ClientAddNewSession(sessionName, session) != SOFTBUS_OK) {
464         SoftBusFree(session);
465         return SOFTBUS_ERR;
466     }
467     *sessionId = session->sessionId;
468     return SOFTBUS_OK;
469 }
470 
ClientDeleteSessionServer(SoftBusSecType type,const char * sessionName)471 int32_t ClientDeleteSessionServer(SoftBusSecType type, const char *sessionName)
472 {
473     if ((type == SEC_TYPE_UNKNOWN) || (sessionName == NULL)) {
474         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
475         return SOFTBUS_INVALID_PARAM;
476     }
477 
478     if (g_clientSessionServerList == NULL) {
479         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
480         return SOFTBUS_NO_INIT;
481     }
482 
483     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
484         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
485         return SOFTBUS_LOCK_ERR;
486     }
487 
488     ClientSessionServer *serverNode = NULL;
489     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
490         if ((strcmp(serverNode->sessionName, sessionName) == 0) && (serverNode->type == type)) {
491             DestroyClientSessionServer(serverNode);
492             g_clientSessionServerList->cnt--;
493             (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
494             return SOFTBUS_OK;
495         }
496     }
497     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
498     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found [%s]", sessionName);
499     return SOFTBUS_ERR;
500 }
501 
ClientDeleteSession(int32_t sessionId)502 int32_t ClientDeleteSession(int32_t sessionId)
503 {
504     if (sessionId < 0) {
505         return SOFTBUS_ERR;
506     }
507 
508     if (g_clientSessionServerList == NULL) {
509         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
510         return SOFTBUS_ERR;
511     }
512 
513     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
514         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
515         return SOFTBUS_ERR;
516     }
517 
518     ClientSessionServer *serverNode = NULL;
519     SessionInfo *sessionNode = NULL;
520 
521     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
522         if (IsListEmpty(&serverNode->sessionList)) {
523             continue;
524         }
525         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
526             if (sessionNode->sessionId != sessionId) {
527                 continue;
528             }
529             ListDelete(&(sessionNode->node));
530             DestroySessionId();
531             (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
532             SoftBusFree(sessionNode);
533             return SOFTBUS_OK;
534         }
535     }
536 
537     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
538     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
539     return SOFTBUS_ERR;
540 }
541 
ClientGetSessionDataById(int32_t sessionId,char * data,uint16_t len,SessionKey key)542 int32_t ClientGetSessionDataById(int32_t sessionId, char *data, uint16_t len, SessionKey key)
543 {
544     if ((sessionId < 0) || (data == NULL) || (len == 0)) {
545         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
546         return SOFTBUS_INVALID_PARAM;
547     }
548 
549     if (g_clientSessionServerList == NULL) {
550         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
551         return SOFTBUS_ERR;
552     }
553 
554     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
555         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
556         return SOFTBUS_ERR;
557     }
558 
559     ClientSessionServer *serverNode = NULL;
560     SessionInfo *sessionNode = NULL;
561     int32_t ret = GetSessionById(sessionId, &serverNode, &sessionNode);
562     if (ret != SOFTBUS_OK) {
563         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
564         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
565         return SOFTBUS_ERR;
566     }
567 
568     switch (key) {
569         case KEY_SESSION_NAME:
570             ret = strcpy_s(data, len, serverNode->sessionName);
571             break;
572         case KEY_PEER_SESSION_NAME:
573             ret = strcpy_s(data, len, sessionNode->info.peerSessionName);
574             break;
575         case KEY_PEER_DEVICE_ID:
576             ret = strcpy_s(data, len, sessionNode->info.peerDeviceId);
577             break;
578         case KEY_PKG_NAME:
579             ret = strcpy_s(data, len, serverNode->pkgName);
580             break;
581         default:
582             (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
583             return SOFTBUS_ERR;
584     }
585 
586     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
587     if (ret != EOK) {
588         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "copy data failed");
589         return SOFTBUS_ERR;
590     }
591     return SOFTBUS_OK;
592 }
593 
ClientGetSessionIntegerDataById(int32_t sessionId,int * data,SessionKey key)594 int32_t ClientGetSessionIntegerDataById(int32_t sessionId, int *data, SessionKey key)
595 {
596     if ((sessionId < 0) || (data == NULL)) {
597         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
598         return SOFTBUS_INVALID_PARAM;
599     }
600 
601     if (g_clientSessionServerList == NULL) {
602         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
603         return SOFTBUS_ERR;
604     }
605 
606     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
607         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
608         return SOFTBUS_ERR;
609     }
610 
611     ClientSessionServer *serverNode = NULL;
612     SessionInfo *sessionNode = NULL;
613     int32_t ret = GetSessionById(sessionId, &serverNode, &sessionNode);
614     if (ret != SOFTBUS_OK) {
615         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
616         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
617         return SOFTBUS_ERR;
618     }
619     switch (key) {
620         case KEY_IS_SERVER:
621             *data = sessionNode->isServer;
622             break;
623         case KEY_PEER_PID:
624             *data = sessionNode->peerPid;
625             break;
626         case KEY_PEER_UID:
627             *data = sessionNode->peerUid;
628             break;
629         default:
630             (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
631             return SOFTBUS_ERR;
632     }
633 
634     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
635     if (ret != EOK) {
636         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "copy data failed");
637         return SOFTBUS_ERR;
638     }
639     return SOFTBUS_OK;
640 }
641 
ClientGetChannelBySessionId(int32_t sessionId,int32_t * channelId,int32_t * type,bool * isEnable)642 int32_t ClientGetChannelBySessionId(int32_t sessionId, int32_t *channelId, int32_t *type, bool *isEnable)
643 {
644     if (sessionId < 0) {
645         return SOFTBUS_INVALID_PARAM;
646     }
647     if (g_clientSessionServerList == NULL) {
648         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
649         return SOFTBUS_ERR;
650     }
651     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
652         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
653         return SOFTBUS_ERR;
654     }
655 
656     ClientSessionServer *serverNode = NULL;
657     SessionInfo *sessionNode = NULL;
658     if (GetSessionById(sessionId, &serverNode, &sessionNode) != SOFTBUS_OK) {
659         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
660         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
661         return SOFTBUS_ERR;
662     }
663 
664     if (channelId != NULL) {
665         *channelId = sessionNode->channelId;
666     }
667     if (type != NULL) {
668         *type = sessionNode->channelType;
669     }
670     if (isEnable != NULL) {
671         *isEnable = sessionNode->isEnable;
672     }
673     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
674     return SOFTBUS_OK;
675 }
676 
ClientSetChannelBySessionId(int32_t sessionId,TransInfo * transInfo)677 int32_t ClientSetChannelBySessionId(int32_t sessionId, TransInfo *transInfo)
678 {
679     if ((sessionId < 0) || (transInfo->channelId < 0)) {
680         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
681         return SOFTBUS_INVALID_PARAM;
682     }
683 
684     if (g_clientSessionServerList == NULL) {
685         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
686         return SOFTBUS_ERR;
687     }
688 
689     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
690         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
691         return SOFTBUS_ERR;
692     }
693 
694     ClientSessionServer *serverNode = NULL;
695     SessionInfo *sessionNode = NULL;
696 
697     int32_t ret = GetSessionById(sessionId, &serverNode, &sessionNode);
698     if (ret != SOFTBUS_OK) {
699         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
700         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
701         return SOFTBUS_ERR;
702     }
703     sessionNode->channelId = transInfo->channelId;
704     sessionNode->channelType = transInfo->channelType;
705 
706     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
707     return SOFTBUS_OK;
708 }
709 
GetEncryptByChannelId(int32_t channelId,int32_t channelType,int32_t * data)710 int32_t GetEncryptByChannelId(int32_t channelId, int32_t channelType, int32_t *data)
711 {
712     if ((channelId < 0) || (data == NULL)) {
713         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
714         return SOFTBUS_INVALID_PARAM;
715     }
716 
717     if (g_clientSessionServerList == NULL) {
718         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
719         return SOFTBUS_ERR;
720     }
721 
722     ClientSessionServer *serverNode = NULL;
723     SessionInfo *sessionNode = NULL;
724 
725     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
726         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
727         return SOFTBUS_ERR;
728     }
729 
730     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
731         if (IsListEmpty(&serverNode->sessionList)) {
732             continue;
733         }
734 
735         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
736             if (sessionNode->channelId == channelId && (int32_t)sessionNode->channelType == channelType) {
737                 *data = (int32_t)sessionNode->isEncrypt;
738                 (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
739                 return SOFTBUS_OK;
740             }
741         }
742     }
743 
744     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
745     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found session with channelId [%d]", channelId);
746     return SOFTBUS_ERR;
747 }
748 
ClientGetSessionIdByChannelId(int32_t channelId,int32_t channelType,int32_t * sessionId)749 int32_t ClientGetSessionIdByChannelId(int32_t channelId, int32_t channelType, int32_t *sessionId)
750 {
751     if ((channelId < 0) || (sessionId == NULL)) {
752         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
753         return SOFTBUS_INVALID_PARAM;
754     }
755 
756     if (g_clientSessionServerList == NULL) {
757         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
758         return SOFTBUS_ERR;
759     }
760 
761     ClientSessionServer *serverNode = NULL;
762     SessionInfo *sessionNode = NULL;
763 
764     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
765         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
766         return SOFTBUS_ERR;
767     }
768 
769     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
770         if (IsListEmpty(&serverNode->sessionList)) {
771             continue;
772         }
773 
774         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
775             if (sessionNode->channelId == channelId && sessionNode->channelType == (ChannelType)channelType) {
776                 *sessionId = sessionNode->sessionId;
777                 (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
778                 return SOFTBUS_OK;
779             }
780         }
781     }
782 
783     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
784     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found session with channelId [%d]", channelId);
785     return SOFTBUS_ERR;
786 }
787 
ClientEnableSessionByChannelId(const ChannelInfo * channel,int32_t * sessionId)788 int32_t ClientEnableSessionByChannelId(const ChannelInfo *channel, int32_t *sessionId)
789 {
790     if ((channel == NULL) || (sessionId == NULL)) {
791         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
792         return SOFTBUS_INVALID_PARAM;
793     }
794 
795     if (g_clientSessionServerList == NULL) {
796         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
797         return SOFTBUS_ERR;
798     }
799 
800     ClientSessionServer *serverNode = NULL;
801     SessionInfo *sessionNode = NULL;
802 
803     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
804         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
805         return SOFTBUS_ERR;
806     }
807 
808     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
809         if (IsListEmpty(&serverNode->sessionList)) {
810             continue;
811         }
812 
813         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
814             if ((sessionNode->channelId == channel->channelId) &&
815                 (sessionNode->channelType == (ChannelType)(channel->channelType))) {
816                 sessionNode->peerPid = channel->peerPid;
817                 sessionNode->peerUid = channel->peerUid;
818                 sessionNode->isServer = channel->isServer;
819                 sessionNode->isEnable = true;
820                 sessionNode->routeType = channel->routeType;
821                 *sessionId = sessionNode->sessionId;
822                 if (channel->channelType == CHANNEL_TYPE_AUTH || !sessionNode->isEncrypt) {
823                     if (memcpy_s(sessionNode->info.peerDeviceId, DEVICE_ID_SIZE_MAX,
824                             channel->peerDeviceId, DEVICE_ID_SIZE_MAX) != EOK) {
825                         (void)SoftBusMutexUnlock(&g_clientSessionServerList->lock);
826                         return SOFTBUS_MEM_ERR;
827                     }
828                 }
829                 (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
830                 return SOFTBUS_OK;
831             }
832         }
833     }
834 
835     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
836     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found session with channelId [%d], channelType [%d]",
837         channel->channelId, channel->channelType);
838     return SOFTBUS_ERR;
839 }
840 
ClientGetSessionCallbackById(int32_t sessionId,ISessionListener * callback)841 int32_t ClientGetSessionCallbackById(int32_t sessionId, ISessionListener *callback)
842 {
843     if (sessionId < 0 || callback == NULL) {
844         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
845         return SOFTBUS_INVALID_PARAM;
846     }
847 
848     if (g_clientSessionServerList == NULL) {
849         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
850         return SOFTBUS_ERR;
851     }
852 
853     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
854         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
855         return SOFTBUS_ERR;
856     }
857 
858     ClientSessionServer *serverNode = NULL;
859     SessionInfo *sessionNode = NULL;
860     int32_t ret = GetSessionById(sessionId, &serverNode, &sessionNode);
861     if (ret != SOFTBUS_OK) {
862         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
863         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
864         return SOFTBUS_ERR;
865     }
866 
867     ret = memcpy_s(callback, sizeof(ISessionListener), &serverNode->listener.session, sizeof(ISessionListener));
868 
869     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
870     if (ret != EOK) {
871         return SOFTBUS_ERR;
872     }
873     return SOFTBUS_OK;
874 }
875 
ClientGetSessionCallbackByName(const char * sessionName,ISessionListener * callback)876 int32_t ClientGetSessionCallbackByName(const char *sessionName, ISessionListener *callback)
877 {
878     if (sessionName == NULL || callback == NULL) {
879         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "Invalid param");
880         return SOFTBUS_INVALID_PARAM;
881     }
882 
883     if (g_clientSessionServerList == NULL) {
884         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
885         return SOFTBUS_ERR;
886     }
887 
888     ClientSessionServer *serverNode = NULL;
889 
890     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
891         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
892         return SOFTBUS_ERR;
893     }
894 
895     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
896         if (strcmp(serverNode->sessionName, sessionName) != 0) {
897             continue;
898         }
899 
900         int32_t ret = memcpy_s(callback, sizeof(ISessionListener),
901                                &serverNode->listener.session, sizeof(ISessionListener));
902         (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
903         if (ret != EOK) {
904             return SOFTBUS_ERR;
905         }
906         return SOFTBUS_OK;
907     }
908 
909     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
910     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not found");
911     return SOFTBUS_ERR;
912 }
913 
ClientGetSessionSide(int32_t sessionId)914 int32_t ClientGetSessionSide(int32_t sessionId)
915 {
916     if (g_clientSessionServerList == NULL) {
917         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
918         return SOFTBUS_ERR;
919     }
920 
921     int32_t side = -1;
922     ClientSessionServer *serverNode = NULL;
923     SessionInfo *sessionNode = NULL;
924 
925     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
926         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
927         return SOFTBUS_ERR;
928     }
929 
930     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
931         if (IsListEmpty(&serverNode->sessionList)) {
932             continue;
933         }
934         LIST_FOR_EACH_ENTRY(sessionNode, &(serverNode->sessionList), SessionInfo, node) {
935             if (sessionNode->sessionId != sessionId) {
936                 continue;
937             }
938             side = sessionNode->isServer ? IS_SERVER : IS_CLIENT;
939             (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
940             return side;
941         }
942     }
943     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
944     return side;
945 }
946 
DestroyClientSessionByDevId(const ClientSessionServer * server,const char * devId,int32_t routeType)947 static void DestroyClientSessionByDevId(const ClientSessionServer *server,
948     const char *devId, int32_t routeType)
949 {
950     SessionInfo *sessionNode = NULL;
951     SessionInfo *sessionNodeNext = NULL;
952     LIST_FOR_EACH_ENTRY_SAFE(sessionNode, sessionNodeNext, &(server->sessionList), SessionInfo, node) {
953         if (strcmp(sessionNode->info.peerDeviceId, devId) != 0) {
954             continue;
955         }
956         if (routeType != ROUTE_TYPE_ALL && sessionNode->routeType != routeType) {
957             continue;
958         }
959         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "DestroyClientSessionByDevId info={%d, %d, %d}",
960             sessionNode->channelId, sessionNode->channelType, sessionNode->routeType);
961 
962         int id = sessionNode->sessionId;
963         (void)ClientTransCloseChannel(sessionNode->channelId, sessionNode->channelType);
964         DestroySessionId();
965         ListDelete(&sessionNode->node);
966         SoftBusFree(sessionNode);
967         server->listener.session.OnSessionClosed(id);
968     }
969 }
970 
ClientTransLnnOfflineProc(NodeBasicInfo * info)971 static void ClientTransLnnOfflineProc(NodeBasicInfo *info)
972 {
973     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "device offline callback enter.");
974     if (info == NULL) {
975         return;
976     }
977     if (g_clientSessionServerList == NULL) {
978         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
979         return;
980     }
981 
982     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
983         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
984         return;
985     }
986 
987     ClientSessionServer *serverNode = NULL;
988     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
989         DestroyClientSessionByDevId(serverNode, info->networkId, ROUTE_TYPE_ALL);
990     }
991     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
992     return;
993 }
994 
995 static INodeStateCb g_transLnnCb = {
996     .events = EVENT_NODE_STATE_OFFLINE,
997     .onNodeOffline = ClientTransLnnOfflineProc,
998 };
999 
ReCreateSessionServerToServer(void)1000 int32_t ReCreateSessionServerToServer(void)
1001 {
1002     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "ReCreateSessionServerToServer");
1003     if (g_clientSessionServerList == NULL) {
1004         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "not init");
1005         return SOFTBUS_ERR;
1006     }
1007     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
1008         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
1009         return SOFTBUS_LOCK_ERR;
1010     }
1011 
1012     ClientSessionServer *serverNode = NULL;
1013     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
1014         int32_t ret = ServerIpcCreateSessionServer(serverNode->pkgName, serverNode->sessionName);
1015         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "session name [%s], pkg name [%s], ret [%d]",
1016             serverNode->sessionName, serverNode->pkgName, ret);
1017     }
1018 
1019     (void)SoftBusMutexUnlock(&g_clientSessionServerList->lock);
1020     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "ReCreateSessionServerToServer ok");
1021     return SOFTBUS_OK;
1022 }
1023 
1024 
ClientTransRegLnnOffline(void)1025 void ClientTransRegLnnOffline(void)
1026 {
1027     int32_t ret;
1028     ret = RegNodeDeviceStateCbInner("trans", &g_transLnnCb);
1029     if (ret != SOFTBUS_OK) {
1030         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "reg lnn offline fail");
1031     }
1032 }
1033 
ClientTransOnLinkDown(const char * networkId,int32_t routeType)1034 void ClientTransOnLinkDown(const char *networkId, int32_t routeType)
1035 {
1036     if (networkId == NULL || g_clientSessionServerList == NULL) {
1037         return;
1038     }
1039     SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "ClientTransOnLinkDown: routeType=%d", routeType);
1040 
1041     if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
1042         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "lock failed");
1043         return;
1044     }
1045     ClientSessionServer *serverNode = NULL;
1046     LIST_FOR_EACH_ENTRY(serverNode, &(g_clientSessionServerList->list), ClientSessionServer, node) {
1047         DestroyClientSessionByDevId(serverNode, networkId, routeType);
1048     }
1049     (void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
1050     return;
1051 }
1052 
1053