• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef SOFTBUS_TCP_DIRECT_SESSIONCONN_H
17 #define SOFTBUS_TCP_DIRECT_SESSIONCONN_H
18 
19 #include <stdint.h>
20 #include "softbus_def.h"
21 #include "common_list.h"
22 #include "softbus_app_info.h"
23 #include "softbus_base_listener.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 #endif /* __cplusplus */
30 
31 #define REQUEST_INVALID 0
32 
33 typedef enum {
34     TCP_DIRECT_CHANNEL_STATUS_INIT,
35     TCP_DIRECT_CHANNEL_STATUS_AUTH_CHANNEL,
36     TCP_DIRECT_CHANNEL_STATUS_VERIFY_P2P,
37     TCP_DIRECT_CHANNEL_STATUS_HANDSHAKING,
38     TCP_DIRECT_CHANNEL_STATUS_CONNECTING,
39     TCP_DIRECT_CHANNEL_STATUS_CONNECTED,
40     TCP_DIRECT_CHANNEL_STATUS_TIMEOUT,
41 } TcpDirectChannelStatus;
42 
43 typedef struct {
44     ListNode node;
45     bool serverSide;
46     int32_t channelId;
47     AppInfo appInfo;
48     uint32_t status;
49     uint32_t timeout;
50     int64_t req;
51     uint32_t requestId;
52     int64_t authId;
53     bool isMeta;
54     ListenerModule listenMod;
55 } SessionConn;
56 
57 uint64_t TransTdcGetNewSeqId(void);
58 
59 int32_t CreatSessionConnList(void);
60 
61 SoftBusList *GetSessionConnList(void);
62 
63 int32_t GetSessionConnLock(void);
64 
65 void ReleaseSessonConnLock(void);
66 
67 SessionConn *GetSessionConnByRequestId(uint32_t requestId);
68 
69 SessionConn *GetSessionConnByReq(int64_t req);
70 
71 SessionConn *CreateNewSessinConn(ListenerModule module, bool isServerSid);
72 
73 SessionConn *GetSessionConnByFd(int32_t fd, SessionConn *conn);
74 
75 SessionConn *GetSessionConnById(int32_t channelId, SessionConn *conn);
76 
77 int32_t SetAppInfoById(int32_t channelId, const AppInfo *appInfo);
78 int32_t GetAppInfoById(int32_t channelId, AppInfo *appInfo);
79 
80 int32_t SetAuthIdByChanId(int32_t channelId, int64_t authId);
81 int64_t GetAuthIdByChanId(int32_t channelId);
82 
83 void TransDelSessionConnById(int32_t channelId);
84 
85 int32_t TransTdcAddSessionConn(SessionConn *conn);
86 
87 void SetSessionKeyByChanId(int32_t chanId, const char *sessionKey, int32_t keyLen);
88 
89 int32_t SetSessionConnStatusById(int32_t channelId, uint32_t status);
90 
91 int32_t TcpTranGetAppInfobyChannelId(int32_t channelId, AppInfo* appInfo);
92 
93 #ifdef __cplusplus
94 #if __cplusplus
95 }
96 #endif /* __cplusplus */
97 #endif /* __cplusplus */
98 #endif
99