Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master_log_3

# Conflicts:
#	core/transmission/trans_channel/proxy/src/softbus_proxychannel_listener.c
#	core/transmission/trans_channel/tcp_direct/src/trans_tcp_direct_listener.c
This commit is contained in:
cuile4 2024-01-11 20:26:16 +08:00
commit b9c581a399
29 changed files with 375 additions and 181 deletions

View File

@ -65,7 +65,7 @@
#define QUERY_RULES_MAX_NUM 10
#define MAX_LENGTH_OF_EVENT_DOMAIN 17
#define MAX_LENGTH_OF_EVENT_NAME 33
#define MAX_LENGTH_OF_SUCCESS_RATE 50
#define MAX_LENGTH_OF_SUCCESS_RATE 100
typedef void (*HandleMessageFunc)(SoftBusMessage* msg);
@ -103,8 +103,19 @@ typedef struct {
typedef struct {
int32_t total;
int32_t successTotal;
int32_t delayNum;
int64_t delay;
} TransStatsSuccessRateDetail;
typedef struct {
int32_t scene;
int32_t stage;
int32_t stageRes;
char *socketName;
int32_t linkType;
int32_t delay;
} TransStatsPara;
typedef struct {
int32_t openSessionFailTotal;
int32_t openSessionSuccessTotal;
@ -323,7 +334,17 @@ static void OnCompleteLnn(int32_t reason, int32_t total)
g_isLnnQueryEnd = true;
}
static void TransStatsSuccessDetail(bool success, const char *socketName, int32_t linkTypePara)
static void UpdateTransSuccessDetail(TransStatsSuccessRateDetail *res, int32_t delay)
{
res->successTotal++;
if (delay < SOFTBUS_ZERO || delay > MINUTE_TIME) {
return;
}
res->delayNum++;
res->delay += delay;
}
static void TransStatsSuccessDetail(bool success, const char *socketName, int32_t linkTypePara, int32_t delay)
{
int linkType = linkTypePara;
if (linkType < CONNECT_TCP || linkType >= CONNECT_TYPE_MAX) {
@ -346,8 +367,10 @@ static void TransStatsSuccessDetail(bool success, const char *socketName, int32_
TransStatsSuccessRateDetail newResult;
newResult.successTotal = 0;
newResult.total = 1;
newResult.delay = 0;
newResult.delayNum = 0;
if (success) {
newResult.successTotal = 1;
UpdateTransSuccessDetail(&newResult, delay);
}
if (LnnMapSet(&g_transStatsInfo.sessionNameLinkTypeMap, keyStr, (const void *)&newResult,
sizeof(TransStatsSuccessRateDetail)) != SOFTBUS_OK) {
@ -358,16 +381,22 @@ static void TransStatsSuccessDetail(bool success, const char *socketName, int32_
}
data->total++;
if (success) {
data->successTotal++;
UpdateTransSuccessDetail(data, delay);
}
TransMapUnlock();
}
static void TransStats(int32_t scene, int32_t stage, int32_t stageRes, const char *socketName, int32_t linkType)
static void TransStats(TransStatsPara *transStatsPara)
{
int32_t scene = transStatsPara->scene;
int32_t stage = transStatsPara->stage;
int32_t stageRes = transStatsPara->stageRes;
const char *socketName = transStatsPara->socketName;
int32_t linkType = transStatsPara->linkType;
int32_t delay = transStatsPara->delay;
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
&& stageRes == EVENT_STAGE_RESULT_OK) {
TransStatsSuccessDetail(true, socketName, linkType);
TransStatsSuccessDetail(true, socketName, linkType, delay);
g_transStatsInfo.openSessionSuccessTotal++;
g_transStatsInfo.currentParaSessionNum++;
return;
@ -375,7 +404,7 @@ static void TransStats(int32_t scene, int32_t stage, int32_t stageRes, const cha
if (scene == EVENT_SCENE_OPEN_CHANNEL && stage == EVENT_STAGE_OPEN_CHANNEL_END
&& stageRes == EVENT_STAGE_RESULT_FAILED) {
TransStatsSuccessDetail(false, socketName, linkType);
TransStatsSuccessDetail(false, socketName, linkType, delay);
g_transStatsInfo.openSessionFailTotal++;
return;
}
@ -417,9 +446,22 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
continue;
}
int32_t timeConsuming = GetInt32ValueByRecord(&srcRecord[i], TIME_CONSUMING_NAME);
if (timeConsuming != SOFTBUS_ERR && stageRes == EVENT_STAGE_RESULT_OK && scene == EVENT_SCENE_OPEN_CHANNEL) {
g_transStatsInfo.delayTimeTotal += timeConsuming;
g_transStatsInfo.delayNum++;
}
char* socketName = GetStringValueByRecord(&srcRecord[i], SOCKET_KEY_NAME);
int32_t linkType = GetInt32ValueByRecord(&srcRecord[i], LINK_TYPE_NAME);
TransStats(scene, stage, stageRes, socketName, linkType);
TransStatsPara transStatsPara = {
.scene = scene,
.stage = stage,
.stageRes = stageRes,
.socketName = socketName,
.linkType = linkType,
.delay = timeConsuming
};
TransStats(&transStatsPara);
cJSON_free(socketName);
if (scene == EVENT_SCENE_CLOSE_CHANNEL_ACTIVE && stage == EVENT_STAGE_CLOSE_CHANNEL &&
stageRes == EVENT_STAGE_RESULT_OK && g_transStatsInfo.currentParaSessionNum > 0) {
@ -429,11 +471,6 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
g_transStatsInfo.maxParaSessionNum = (maxParaSessionNum > g_transStatsInfo.currentParaSessionNum) ?
maxParaSessionNum : g_transStatsInfo.currentParaSessionNum;
int32_t timeConsuming = GetInt32ValueByRecord(&srcRecord[i], TIME_CONSUMING_NAME);
if (timeConsuming != SOFTBUS_ERR && stageRes == EVENT_STAGE_RESULT_OK) {
g_transStatsInfo.delayTimeTotal += timeConsuming;
g_transStatsInfo.delayNum++;
}
int32_t btFlow = GetInt32ValueByRecord(&srcRecord[i], BT_FLOW_NAME);
if (btFlow != SOFTBUS_ERR) {
g_transStatsInfo.btFlowTotal += btFlow;
@ -540,8 +577,8 @@ void GenerateTransSuccessRateString(MapIterator *it, char *res, uint64_t maxLen)
if (quantity->total > 0) {
rate = 1.0 * quantity->successTotal / quantity->total * RATE_HUNDRED;
}
int32_t ret = sprintf_s(res, maxLen, "%s,%d,%d,%d,%2.2f", sessionName, linkType, quantity->total,
quantity->successTotal, rate);
int32_t ret = sprintf_s(res, maxLen, "%s,%d,%d,%d,%2.2f,%d,%lld", sessionName, linkType, quantity->total,
quantity->successTotal, rate, quantity->delayNum, quantity->delay);
if (ret <= 0) {
COMM_LOGE(COMM_DFX, "sprintf_s fail");
return;

View File

@ -33,6 +33,7 @@ typedef enum {
EVENT_SCENE_LANE_SCORE = 6,
EVENT_SCENE_ACTIVATION = 7,
EVENT_SCENE_DETECTION = 8,
EVENT_SCENE_OPEN_CHANNEL_SERVER = 9,
} TransEventScene;
typedef enum {

View File

@ -162,6 +162,7 @@ typedef struct {
char *reqId;
int64_t timeStart;
int32_t linkType;
int32_t connectType;
bool isFastData;
uint32_t dataConfig;
} ChannelInfo;

View File

@ -81,6 +81,15 @@ static void DfxRecordTcpConnectFail(uint32_t pId, ConnectOption *option, TcpConn
CONN_LOGI(CONN_COMMON, "record tcp conn fail, connectTraceId=%{public}u, reason=%{public}d",
statistics->connectTraceId, reason);
uint64_t costTime = SoftBusGetSysTimeMs() - statistics->startTime;
ConnEventExtra extra = {
.linkType = CONNECT_TCP,
.errcode = reason,
.result = EVENT_STAGE_RESULT_FAILED
};
if (tcpInfo != NULL) {
extra.requestId = (int32_t)tcpInfo->requestId;
}
CONN_EVENT(EVENT_SCENE_CONNECT, EVENT_STAGE_CONNECT_END, extra);
SoftbusRecordConnResult(pId, SOFTBUS_HISYSEVT_CONN_TYPE_TCP, SOFTBUS_EVT_CONN_FAIL, costTime, reason);
}
@ -93,6 +102,15 @@ static void DfxRecordTcpConnectSuccess(uint32_t pId, TcpConnInfoNode *tcpInfo, C
CONN_LOGI(CONN_COMMON, "record tcp conn success, connectTraceId=%{public}u", statistics->connectTraceId);
uint64_t costTime = SoftBusGetSysTimeMs() - statistics->startTime;
ConnEventExtra extra = {
.linkType = CONNECT_TCP,
.costTime = (int32_t)costTime,
.result = EVENT_STAGE_RESULT_OK
};
if (tcpInfo != NULL) {
extra.requestId = (int32_t)tcpInfo->requestId;
}
CONN_EVENT(EVENT_SCENE_CONNECT, EVENT_STAGE_CONNECT_END, extra);
SoftbusRecordConnResult(pId, SOFTBUS_HISYSEVT_CONN_TYPE_TCP, SOFTBUS_EVT_CONN_SUCC, costTime,
SOFTBUS_HISYSEVT_CONN_OK);
}

View File

@ -110,6 +110,7 @@ typedef struct {
int32_t transFlag;
int64_t authSeq;
int32_t linkType;
int32_t connectType;
int32_t channelType;
int32_t errorCode;
int64_t timeStart;

View File

@ -26,9 +26,11 @@
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_hisysevt_transreporter.h"
#include "softbus_utils.h"
#include "trans_auth_message.h"
#include "trans_channel_limit.h"
#include "trans_event.h"
#include "trans_session_manager.h"
#include "trans_channel_manager.h"
#include "trans_log.h"
@ -153,6 +155,8 @@ static int32_t NotifyOpenAuthChannelSuccess(const AppInfo *appInfo, bool isServe
channelInfo.autoCloseTime = appInfo->autoCloseTime;
channelInfo.reqId = (char*)appInfo->reqId;
channelInfo.dataConfig = appInfo->myData.dataConfig;
channelInfo.timeStart = appInfo->timeStart;
channelInfo.connectType = appInfo->connectType;
return g_cb->OnChannelOpened(appInfo->myData.pkgName, appInfo->myData.pid,
appInfo->myData.sessionName, &channelInfo);
}
@ -314,6 +318,14 @@ static void OnRecvAuthChannelRequest(int32_t authId, const char *data, int32_t l
return;
}
TransEventExtra extra = {
.peerNetworkId = NULL,
.calleePkg = NULL,
.callerPkg = NULL,
.socketName = NULL,
.channelType = CHANNEL_TYPE_AUTH,
.authId = authId
};
AppInfo appInfo;
int32_t ret = TransAuthChannelMsgUnpack(data, &appInfo, len);
if (ret != SOFTBUS_OK) {
@ -321,6 +333,8 @@ static void OnRecvAuthChannelRequest(int32_t authId, const char *data, int32_t l
TransPostAuthChannelErrMsg(authId, ret, "unpackRequest");
goto EXIT_ERR;
}
extra.socketName = appInfo.myData.sessionName;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
if (!CheckSessionNameValidOnAuthChannel(appInfo.myData.sessionName)) {
TRANS_LOGE(TRANS_SVC, "check auth channel pkginfo invalid.");
TransPostAuthChannelErrMsg(authId, ret, "check msginfo failed");
@ -342,6 +356,9 @@ static void OnRecvAuthChannelRequest(int32_t authId, const char *data, int32_t l
TransPostAuthChannelErrMsg(authId, ret, "unpackRequest");
goto EXIT_ERR;
}
extra.result = EVENT_STAGE_RESULT_OK;
extra.channelId = appInfo.myData.channelId;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
ret = NotifyOpenAuthChannelSuccess(&appInfo, true);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "NotifyOpenAuthChannelSuccess failed");
@ -354,8 +371,14 @@ static void OnRecvAuthChannelRequest(int32_t authId, const char *data, int32_t l
TransPostAuthChannelErrMsg(authId, ret, "send reply failed");
goto EXIT_ERR;
}
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
return;
EXIT_ERR:
if (extra.socketName != NULL) {
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
DelAuthChannelInfoByAuthId(authId);
AuthCloseChannel(authId);
}
@ -396,6 +419,17 @@ static void OnRecvAuthChannelReply(int32_t authId, const char *data, int32_t len
TRANS_LOGE(TRANS_SVC, "can not find channel info by auth id");
return;
}
TransEventExtra extra = {
.peerNetworkId = NULL,
.calleePkg = NULL,
.callerPkg = NULL,
.socketName = info.appInfo.myData.sessionName,
.channelId = info.appInfo.myData.channelId,
.channelType = CHANNEL_TYPE_AUTH,
.authId = authId,
.linkType = info.connOpt.type
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
int32_t ret = TransAuthChannelMsgUnpack(data, &info.appInfo, len);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "unpackReply failed");
@ -406,6 +440,8 @@ static void OnRecvAuthChannelReply(int32_t authId, const char *data, int32_t len
TRANS_LOGE(TRANS_SVC, "ProcessDataConfig failed");
goto EXIT_ERR;
}
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
ret = NotifyOpenAuthChannelSuccess(&info.appInfo, false);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "NotifyOpenAuthChannelSuccess failed");
@ -413,6 +449,9 @@ static void OnRecvAuthChannelReply(int32_t authId, const char *data, int32_t len
}
return;
EXIT_ERR:
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
AuthCloseChannel(authId);
DelAuthChannelInfoByChanId((int32_t)(info.appInfo.myData.channelId));
(void)NotifyOpenAuthChannelFailed((const char *)(info.appInfo.myData.pkgName),
@ -727,12 +766,27 @@ int32_t TransOpenAuthMsgChannel(const char *sessionName, const ConnectOption *co
return SOFTBUS_MEM_ERR;
}
*channelId = (int32_t)channel->appInfo.myData.channelId;
channel->appInfo.timeStart = GetSoftbusRecordTimeMillis();
channel->appInfo.connectType = connOpt->type;
TransEventExtra extra = {
.peerNetworkId = NULL,
.calleePkg = NULL,
.callerPkg = NULL,
.socketName = sessionName,
.channelId = *channelId,
.channelType = CHANNEL_TYPE_AUTH,
.linkType = connOpt->type
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_START_CONNECT, extra);
int32_t authId = AuthOpenChannel(connOpt->socketOption.addr, connOpt->socketOption.port);
if (authId < 0) {
TRANS_LOGE(TRANS_SVC, "AuthOpenChannel failed");
SoftBusFree(channel);
return SOFTBUS_ERR;
}
extra.result = EVENT_STAGE_RESULT_OK;
extra.authId = authId;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_START_CONNECT, extra);
channel->authId = authId;
if (SoftBusMutexLock(&g_authChannelList->lock) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "SoftBusMutexLock failed");
@ -747,6 +801,8 @@ int32_t TransOpenAuthMsgChannel(const char *sessionName, const ConnectOption *co
(void)SoftBusMutexUnlock(&g_authChannelList->lock);
return SOFTBUS_ERR;
}
extra.result = 0;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_START, extra);
if (TransPostAuthChannelMsg(&channel->appInfo, authId, AUTH_CHANNEL_REQ) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SVC, "TransPostAuthRequest failed");
AuthCloseChannel(channel->authId);
@ -754,6 +810,8 @@ int32_t TransOpenAuthMsgChannel(const char *sessionName, const ConnectOption *co
(void)SoftBusMutexUnlock(&g_authChannelList->lock);
return SOFTBUS_ERR;
}
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_START, extra);
(void)SoftBusMutexUnlock(&g_authChannelList->lock);
return SOFTBUS_OK;
}

View File

@ -42,17 +42,19 @@ static int32_t TransServerOnChannelOpened(const char *pkgName, int32_t pid, cons
}
int64_t timeStart = channel->timeStart;
int64_t timediff = GetSoftbusRecordTimeMillis() - timeStart;
if (!channel->isServer) {
TransEventExtra extra = {
.calleePkg = NULL,
.peerNetworkId = channel->peerDeviceId,
.linkType = channel->linkType,
.channelId = channel->channelId,
.costTime = (int32_t)timediff,
.result = EVENT_STAGE_RESULT_OK,
.callerPkg = pkgName,
.socketName = sessionName
};
TransEventExtra extra = {
.calleePkg = NULL,
.peerNetworkId = channel->peerDeviceId,
.linkType = channel->connectType,
.channelId = channel->channelId,
.costTime = (int32_t)timediff,
.result = EVENT_STAGE_RESULT_OK,
.callerPkg = pkgName,
.socketName = sessionName
};
if (channel->isServer) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_OPEN_CHANNEL_END, extra);
} else {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
}
SoftbusRecordOpenSessionKpi(pkgName, channel->linkType, SOFTBUS_EVT_OPEN_SESSION_SUCC, timediff);

View File

@ -437,7 +437,8 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
.callerPkg = appInfo->myData.pkgName,
.socketName = appInfo->myData.sessionName,
.dataType = appInfo->businessType,
.peerNetworkId = appInfo->peerNetWorkId
.peerNetworkId = appInfo->peerNetWorkId,
.result = EVENT_STAGE_RESULT_OK
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra);
errCode = TransGetLaneInfo(param, &connInfo, &laneId);
@ -458,6 +459,8 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - timeStart);
goto EXIT_ERR;
}
appInfo->connectType = connOpt.type;
extra.linkType = connOpt.type;
FillAppInfo(appInfo, param, transInfo, &connInfo);
TransOpenChannelSetModule(transInfo->channelType, &connOpt);
TRANS_LOGI(TRANS_CTRL, "laneId=%{public}u, channelType=%{public}u", laneId, transInfo->channelType);
@ -566,34 +569,52 @@ EXIT_ERR:
int32_t TransOpenAuthChannel(const char *sessionName, const ConnectOption *connOpt,
const char *reqId)
{
TransEventExtra extra = {
.calleePkg = NULL,
.callerPkg = NULL,
.socketName = NULL,
.peerNetworkId = NULL,
.channelType = CHANNEL_TYPE_AUTH,
.result = EVENT_STAGE_RESULT_OK
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_START, extra);
int32_t channelId = INVALID_CHANNEL_ID;
if (!IsValidString(sessionName, SESSION_NAME_SIZE_MAX) || connOpt == NULL) {
return channelId;
goto EXIT_ERR;
}
extra.socketName = sessionName;
extra.linkType = connOpt->type;
if (connOpt->type == CONNECT_TCP) {
if (TransOpenAuthMsgChannel(sessionName, connOpt, &channelId, reqId) != SOFTBUS_OK) {
return INVALID_CHANNEL_ID;
goto EXIT_ERR;
}
} else if (connOpt->type == CONNECT_BR || connOpt->type == CONNECT_BLE) {
AppInfo *appInfo = GetAuthAppInfo(sessionName);
if (appInfo == NULL) {
TRANS_LOGE(TRANS_CTRL, "GetAuthAppInfo failed");
return INVALID_CHANNEL_ID;
goto EXIT_ERR;
}
appInfo->connectType = connOpt->type;
if (strcpy_s(appInfo->reqId, REQ_ID_SIZE_MAX, reqId) != EOK) {
TRANS_LOGE(TRANS_CTRL, "strcpy_s reqId failed");
SoftBusFree(appInfo);
return INVALID_CHANNEL_ID;
goto EXIT_ERR;
}
if (TransProxyOpenProxyChannel(appInfo, connOpt, &channelId) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "proxy channel err");
SoftBusFree(appInfo);
return INVALID_CHANNEL_ID;
goto EXIT_ERR;
}
SoftBusFree(appInfo);
} else {
goto EXIT_ERR;
}
return channelId;
EXIT_ERR:
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = SOFTBUS_ERR;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
return INVALID_CHANNEL_ID;
}
static uint32_t MergeStatsInterval(const uint32_t *data, uint32_t left, uint32_t right)

View File

@ -77,6 +77,7 @@ static int32_t NotifyNormalChannelOpened(int32_t channelId, const AppInfo *appIn
}
info.timeStart = appInfo->timeStart;
info.linkType = appInfo->linkType;
info.connectType = appInfo->connectType;
int32_t ret = SOFTBUS_ERR;
if (appInfo->appType != APP_TYPE_AUTH) {
@ -127,7 +128,11 @@ int32_t OnProxyChannelOpened(int32_t channelId, const AppInfo *appInfo, unsigned
.errcode = ret,
.result = (ret == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
if (!isServer) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
} else if (ret != SOFTBUS_OK) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_OPEN_CHANNEL_END, extra);
}
TRANS_LOGI(TRANS_CTRL, "on open ret=%{public}d", ret);
return ret;
}
@ -161,7 +166,7 @@ int32_t OnProxyChannelOpenFailed(int32_t channelId, const AppInfo *appInfo, int3
TransEventExtra extra = {
.calleePkg = NULL,
.peerNetworkId = appInfo->peerData.deviceId,
.linkType = appInfo->linkType,
.linkType = appInfo->connectType,
.channelId = channelId,
.costTime = timediff,
.errcode = errCode,

View File

@ -1081,23 +1081,36 @@ void TransProxyProcessHandshakeMsg(const ProxyMessage *msg)
(TransProxyAckHandshake(msg->connId, chan, ret) != SOFTBUS_OK)) {
TRANS_LOGE(TRANS_CTRL, "ErrHandshake fail, connId=%{public}u.", msg->connId);
}
TransEventExtra extra = {
.calleePkg = NULL,
.callerPkg = NULL,
.peerNetworkId = NULL,
.channelId = chan->myId,
.peerChannelId = chan->peerId,
.socketName = chan->appInfo.myData.sessionName,
.authId = chan->authId,
.connectionId = chan->connId,
.linkType = chan->type
};
if (ret != SOFTBUS_OK) {
SoftBusFree(chan);
return;
goto EXIT_ERR;
}
TransCreateConnByConnId(msg->connId);
if ((ret = TransProxyAddChanItem(chan)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "AddChanItem fail");
SoftBusFree(chan);
return;
goto EXIT_ERR;
}
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
if ((ret = OnProxyChannelOpened(chan->channelId, &(chan->appInfo), PROXY_CHANNEL_SERVER)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "OnProxyChannelOpened fail");
(void)TransProxyCloseConnChannelReset(msg->connId, false);
TransProxyDelChanByChanId(chan->channelId);
return;
goto EXIT_ERR;
}
if (chan->appInfo.fastTransData != NULL && chan->appInfo.fastTransDataSize > 0) {
TransProxyFastDataRecv(chan);
@ -1108,7 +1121,14 @@ void TransProxyProcessHandshakeMsg(const ProxyMessage *msg)
TRANS_LOGE(TRANS_CTRL, "AckHandshake fail");
OnProxyChannelClosed(chan->channelId, &(chan->appInfo));
TransProxyDelChanByChanId(chan->channelId);
goto EXIT_ERR;
}
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
return;
EXIT_ERR:
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
void TransProxyProcessResetMsg(const ProxyMessage *msg)

View File

@ -177,20 +177,36 @@ static int32_t TdcOnConnectEvent(ListenerModule module, int cfd, const ConnectOp
}
int32_t channelId = GenerateChannelId(true);
int32_t ret = TransSrvAddDataBufNode(channelId, cfd); // fd != channelId
TransEventExtra extra = {
.socketName = NULL,
.peerNetworkId = NULL,
.calleePkg = NULL,
.callerPkg = NULL,
.socketFd = cfd,
.channelId = channelId
};
if (ret != SOFTBUS_OK) {
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_START_CONNECT, extra);
TRANS_LOGE(TRANS_CTRL, "create srv data buf node failed.");
ConnShutdownSocket(cfd);
return ret;
}
ret = CreateSessionConnNode(module, cfd, channelId, clientAddr);
if (ret != SOFTBUS_OK) {
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_START_CONNECT, extra);
TRANS_LOGE(TRANS_CTRL, "create session conn node fail, delete data buf node.");
TransSrvDelDataBufNode(channelId);
ConnShutdownSocket(cfd);
return ret;
}
TRANS_LOGI(TRANS_CTRL, "tdc conn event cfd=%{public}d, channelId=%{public}d, module=%{public}d.", cfd, channelId,
module);
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_START_CONNECT, extra);
TRANS_LOGI(TRANS_CTRL,
"tdc conn event cfd=%{public}d, channelId=%{public}d, module=%{public}d", cfd, channelId, module);
return SOFTBUS_OK;
}
@ -217,7 +233,12 @@ static void TransProcDataRes(ListenerModule module, int32_t ret, int32_t channel
.errcode = ret,
.result = EVENT_STAGE_RESULT_FAILED
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
SessionConn conn;
if (GetSessionConnById(channelId, &conn) == NULL || !conn.serverSide) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_REPLY, extra);
} else {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
DelTrigger(module, fd, READ_TRIGGER);
ConnShutdownSocket(fd);
NotifyChannelOpenFailed(channelId, ret);

View File

@ -21,6 +21,7 @@
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_hisysevt_transreporter.h"
#include "softbus_socket.h"
#include "trans_event.h"
#include "trans_log.h"
@ -37,6 +38,25 @@ static void OnSessionOpenFailProc(const SessionConn *node, int32_t errCode)
{
TRANS_LOGW(TRANS_CTRL, "OnSesssionOpenFailProc: channelId=%{public}d, side=%{public}d, status=%{public}d",
node->channelId, node->serverSide, node->status);
int64_t timeStart = node->appInfo.timeStart;
int64_t timeDiff = GetSoftbusRecordTimeMillis() - timeStart;
TransEventExtra extra = {
.calleePkg = NULL,
.callerPkg = node->appInfo.myData.pkgName,
.channelId = node->appInfo.myData.channelId,
.peerChannelId = node->appInfo.peerData.channelId,
.peerNetworkId = node->appInfo.peerNetWorkId,
.socketName = node->appInfo.myData.sessionName,
.linkType = node->appInfo.connectType,
.costTime = (int32_t)timeDiff,
.errcode = errCode,
.result = EVENT_STAGE_RESULT_FAILED
};
if (!node->serverSide) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
} else {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_OPEN_CHANNEL_END, extra);
}
if (node->serverSide == false) {
if (TransTdcOnChannelOpenFailed(node->appInfo.myData.pkgName, node->appInfo.myData.pid,
node->channelId, errCode) != SOFTBUS_OK) {

View File

@ -414,6 +414,7 @@ static int32_t NotifyChannelOpened(int32_t channelId)
info.peerDeviceId = buf;
info.timeStart = conn.appInfo.timeStart;
info.linkType = conn.appInfo.linkType;
info.connectType = conn.appInfo.connectType;
char pkgName[PKG_NAME_SIZE_MAX] = {0};
if (TransTdcGetPkgName(conn.appInfo.myData.sessionName, pkgName, PKG_NAME_SIZE_MAX) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "get pkg name fail.");
@ -456,14 +457,18 @@ int32_t NotifyChannelOpenFailed(int32_t channelId, int32_t errCode)
.calleePkg = NULL,
.callerPkg = conn.appInfo.myData.pkgName,
.channelId = conn.appInfo.myData.channelId,
.peerNetworkId = conn.appInfo.myData.deviceId,
.peerNetworkId = conn.appInfo.peerNetWorkId,
.socketName = conn.appInfo.myData.sessionName,
.linkType = conn.appInfo.linkType,
.linkType = conn.appInfo.connectType,
.costTime = timediff,
.errcode = errCode,
.result = EVENT_STAGE_RESULT_FAILED
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
if (!conn.serverSide) {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
} else {
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_OPEN_CHANNEL_END, extra);
}
TransAlarmExtra extraAlarm = {
.conflictName = NULL,
.conflictedName = NULL,
@ -808,6 +813,17 @@ static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t se
return SOFTBUS_INVALID_PARAM;
}
TransEventExtra extra = {
.socketName = conn->appInfo.myData.sessionName,
.peerNetworkId = NULL,
.calleePkg = NULL,
.callerPkg = NULL,
.channelId = channelId,
.peerChannelId = conn->appInfo.peerData.channelId,
.socketFd = conn->appInfo.fd,
.result = EVENT_STAGE_RESULT_OK
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
if ((flags & FLAG_AUTH_META) != 0 && !IsMetaSession(conn->appInfo.myData.sessionName)) {
char *tmpName = NULL;
Anonymize(conn->appInfo.myData.sessionName, &tmpName);
@ -869,6 +885,9 @@ static int32_t OpenDataBusRequest(int32_t channelId, uint32_t flags, uint64_t se
(void)NotifyChannelClosed(&conn->appInfo, channelId);
SoftBusFree(conn);
return SOFTBUS_ERR;
} else {
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
if (conn->appInfo.routeType == WIFI_P2P) {

View File

@ -137,6 +137,7 @@ static int32_t NotifyUdpChannelOpened(const AppInfo *appInfo, bool isServerSide)
info.autoCloseTime = appInfo->autoCloseTime;
info.timeStart = appInfo->timeStart;
info.linkType = appInfo->linkType;
info.connectType = appInfo->connectType;
int32_t ret = g_channelCb->GetPkgNameBySessionName(appInfo->myData.sessionName,
(char*)appInfo->myData.pkgName, PKG_NAME_SIZE_MAX);
if (ret != SOFTBUS_OK) {
@ -180,7 +181,7 @@ int32_t NotifyUdpChannelOpenFailed(const AppInfo *info, int32_t errCode)
.channelId = info->myData.channelId,
.peerNetworkId = info->myData.deviceId,
.socketName = info->myData.sessionName,
.linkType = info->linkType,
.linkType = info->connectType,
.costTime = timediff,
.errcode = errCode,
.result = EVENT_STAGE_RESULT_FAILED
@ -556,12 +557,26 @@ static void TransOnExchangeUdpInfoRequest(int64_t authId, int64_t seq, const cJS
(void)memset_s(&info, sizeof(info), 0, sizeof(info));
char* errDesc = NULL;
TransEventExtra extra = {
.calleePkg = NULL,
.callerPkg = NULL,
.socketName = NULL,
.peerNetworkId = NULL,
.channelType = CHANNEL_TYPE_UDP,
.authId = authId
};
int32_t ret = ParseRequestAppInfo(authId, msg, &info);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "get appinfo failed. ret=%{public}d", ret);
errDesc = (char *)"peer device session name not create";
goto ERR_EXIT;
}
if (info.udpChannelOptType == TYPE_UDP_CHANNEL_OPEN) {
extra.socketName = info.myData.sessionName;
extra.peerChannelId = info.peerData.channelId;
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_START, extra);
}
ret = ProcessUdpChannelState(&info, true);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "process udp channel state failed. ret=%{public}d", ret);
@ -576,9 +591,18 @@ static void TransOnExchangeUdpInfoRequest(int64_t authId, int64_t seq, const cJS
ProcessAbnormalUdpChannelState(&info, ret, false);
goto ERR_EXIT;
}
if (info.udpChannelOptType == TYPE_UDP_CHANNEL_OPEN) {
extra.result = EVENT_STAGE_RESULT_OK;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
return;
ERR_EXIT:
if (extra.socketName != NULL && info.udpChannelOptType == TYPE_UDP_CHANNEL_OPEN) {
extra.result = EVENT_STAGE_RESULT_FAILED;
extra.errcode = ret;
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL_SERVER, EVENT_STAGE_HANDSHAKE_REPLY, extra);
}
if (SendReplyErrInfo(ret, errDesc, authId, seq) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "send reply error info failed.");
}
@ -806,8 +830,7 @@ static int32_t OpenAuthConnForUdpNegotiation(UdpChannelInfo *channel)
.channelType = CHANNEL_TYPE_UDP,
.channelId = channel->info.myData.channelId,
.requestId = requestId,
.peerNetworkId = channel->info.peerData.deviceId,
.result = EVENT_STAGE_RESULT_OK
.peerNetworkId = channel->info.peerNetWorkId
};
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_START_CONNECT, extra);
if (ret != SOFTBUS_OK) {

View File

@ -172,6 +172,8 @@ int32_t ClientGetSessionCallbackAdapterByName(const char *sessionName, SessionLi
int32_t ClientGetSessionCallbackAdapterById(int32_t sessionId, SessionListenerAdapter *callbackAdapter);
int32_t ClientGetPeerSocketInfoById(int32_t sessionId, PeerSocketInfo *peerSocketInfo);
bool IsSessionExceedLimit();
#ifdef __cplusplus
}
#endif

View File

@ -1913,4 +1913,19 @@ int32_t ClientGetPeerSocketInfoById(int32_t sessionId, PeerSocketInfo *peerSocke
peerSocketInfo->dataType = (TransDataType)sessionNode->info.flag;
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
return SOFTBUS_OK;
}
bool IsSessionExceedLimit()
{
if (SoftBusMutexLock(&(g_clientSessionServerList->lock)) != 0) {
TRANS_LOGE(TRANS_SDK, "lock failed");
return true;
}
if (g_sessionIdNum >= MAX_SESSION_ID) {
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
TRANS_LOGE(TRANS_SDK, "sessionId num exceed limit.");
return true;
}
(void)SoftBusMutexUnlock(&(g_clientSessionServerList->lock));
return false;
}

View File

@ -16,8 +16,9 @@
#include "string.h"
#include "anonymizer.h"
#include "client_trans_session_adapter.h"
#include "socket.h"
#include "client_trans_session_manager.h"
#include "inner_socket.h"
#include "socket.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_error_code.h"
@ -102,6 +103,9 @@ int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISock
int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener)
{
TRANS_LOGI(TRANS_SDK, "Bind: socket=%d", socket);
if (IsSessionExceedLimit()) {
return SOFTBUS_TRANS_SESSION_CNT_EXCEEDS_LIMIT;
}
return ClientBind(socket, qos, qosCount, listener);
}

View File

@ -31,6 +31,9 @@ int32_t TransOnChannelOpened(const char *sessionName, const ChannelInfo *channel
TRANS_LOGW(TRANS_SDK, "[client] invalid param.");
return SOFTBUS_INVALID_PARAM;
}
if (IsSessionExceedLimit()) {
return SOFTBUS_TRANS_SESSION_CNT_EXCEEDS_LIMIT;
}
int32_t ret = SOFTBUS_ERR;
int32_t udpPort = 0;

View File

@ -31,7 +31,7 @@ typedef struct {
const StreamFrameInfo *param);
int32_t (*OnFileGetSessionId)(int32_t channelId, int32_t *sessionId);
void (*OnMessageReceived)(void);
void (*OnUdpChannelOpened)(int32_t channelId);
int32_t (*OnUdpChannelOpened)(int32_t channelId);
void (*OnUdpChannelClosed)(int32_t channelId, ShutdownReason reason);
void (*OnQosEvent)(int channelId, int eventId, int tvCount, const QosTv *tvList);
} UdpChannelMgrCb;

View File

@ -148,20 +148,22 @@ static int32_t TransSetUdpChannelEnable(int32_t channelId, bool isEnable)
return SOFTBUS_ERR;
}
static void OnUdpChannelOpened(int32_t channelId)
static int32_t OnUdpChannelOpened(int32_t channelId)
{
UdpChannel channel;
if (memset_s(&channel, sizeof(UdpChannel), 0, sizeof(UdpChannel)) != EOK) {
TRANS_LOGE(TRANS_SDK, "on udp channel opened memset failed.");
return;
return SOFTBUS_ERR;
}
if (TransGetUdpChannel(channelId, &channel) != SOFTBUS_OK) {
int ret = TransGetUdpChannel(channelId, &channel);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "get udp channelId=%d failed.", channelId);
return;
return ret;
}
if (TransSetUdpChannelEnable(channelId, true) != SOFTBUS_OK) {
ret = TransSetUdpChannelEnable(channelId, true);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_SDK, "set udp channelId=%d enable failed.", channelId);
return;
return ret;
}
SessionType type = TYPE_BUTT;
switch (channel.businessType) {
@ -173,7 +175,7 @@ static void OnUdpChannelOpened(int32_t channelId)
break;
default:
TRANS_LOGE(TRANS_SDK, "unsupport businessType=%d.", channel.businessType);
return;
return SOFTBUS_ERR;
}
ChannelInfo info = {0};
info.channelId = channel.channelId;
@ -187,8 +189,9 @@ static void OnUdpChannelOpened(int32_t channelId)
info.routeType = channel.routeType;
info.businessType = channel.businessType;
if ((g_sessionCb != NULL) && (g_sessionCb->OnSessionOpened != NULL)) {
g_sessionCb->OnSessionOpened(channel.info.mySessionName, &info, type);
return g_sessionCb->OnSessionOpened(channel.info.mySessionName, &info, type);
}
return SOFTBUS_ERR;
}
static UdpChannel *ConvertChannelInfoToUdpChannel(const char *sessionName, const ChannelInfo *channel)

View File

@ -314,9 +314,16 @@ int32_t TransOnFileChannelOpened(const char *sessionName, const ChannelInfo *cha
TRANS_LOGE(TRANS_FILE, "start file channel as server failed");
return SOFTBUS_ERR;
}
g_udpChannelMgrCb->OnUdpChannelOpened(channel->channelId);
if (g_udpChannelMgrCb->OnUdpChannelOpened(channel->channelId) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "udp channel open failed.");
NSTACKX_DFileClose(fileSession);
*filePort = 0;
return SOFTBUS_ERR;
}
if (UpdateFileRecvPath(channel->channelId, &fileListener, fileSession)) {
TRANS_LOGE(TRANS_FILE, "update receive file path failed");
NSTACKX_DFileClose(fileSession);
*filePort = 0;
return SOFTBUS_ERR;
}
} else {

View File

@ -76,6 +76,11 @@ ohos_unittest("AuthTest") {
ohos_unittest("AuthEnhanceMockTest") {
module_out_path = module_output_path
sanitize = {
cfi = true
cfi_cross_dso = true
debug = true
}
sources = [
"$dsoftbus_root_path/core/adapter/authentication/src/lnn_extdata_config_virtual.c",
"$dsoftbus_root_path/core/authentication/src/auth_common.c",

View File

@ -395,25 +395,6 @@ HWTEST_F(AuthOtherTest, AUTH_MANAGER_SET_AUTH_PASSED_TEST_001, TestSize.Level1)
DelAuthManager(auth, true);
}
/*
* @tc.name: AUTH_MANAGER_SET_AUTH_TIMEOUT_TEST_001
* @tc.desc: auth manager set auth timeout test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthOtherTest, AUTH_MANAGER_SET_AUTH_TIMEOUT_TEST_001, TestSize.Level1)
{
int64_t authSeq = 0;
AuthSessionInfo info;
(void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
info.connInfo.type = AUTH_LINK_TYPE_WIFI;
int32_t reason = SOFTBUS_AUTH_TIMEOUT;
AuthManager *auth = NewAuthManager(authSeq, &info);
EXPECT_TRUE(auth != nullptr);
AuthManagerSetAuthFailed(authSeq, &info, reason);
DelAuthManager(auth, true);
}
/*
* @tc.name: HANDLE_CONNECTION_DATA_TEST_001
* @tc.desc: handle connection data test
@ -485,7 +466,7 @@ HWTEST_F(AuthOtherTest, AUTH_DEVICE_OPEN_CONN_TEST_001, TestSize.Level1)
EXPECT_TRUE(ret == SOFTBUS_AUTH_NOT_FOUND);
(void)strcpy_s(connInfo.info.ipInfo.ip, IP_LEN, ip);
ret = AuthDeviceOpenConn(&connInfo, requestId, &cb);
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_TRUE(ret == SOFTBUS_AUTH_NOT_FOUND);
connInfo.type = AUTH_LINK_TYPE_BR;
ret = AuthDeviceOpenConn(&connInfo, requestId, &cb);
EXPECT_TRUE(ret != SOFTBUS_OK);
@ -1151,10 +1132,10 @@ HWTEST_F(AuthOtherTest, GET_LATEST_ID_BY_CONNINFO_TEST_001, TestSize.Level1)
const char *ip = "192.168.12.1";
(void)strcpy_s(connInfo->info.ipInfo.ip, IP_LEN, ip);
ret = GetLatestIdByConnInfo(connInfo, type);
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_TRUE(ret == AUTH_INVALID_ID);
type = AUTH_LINK_TYPE_BLE;
ret = GetLatestIdByConnInfo(connInfo, type);
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_TRUE(ret == AUTH_INVALID_ID);
SoftBusFree(connInfo);
}
@ -1241,7 +1222,6 @@ HWTEST_F(AuthOtherTest, SYNC_DEVINFO_STATE_PROCESS_TEST_001, TestSize.Level1)
msgType = FSM_MSG_AUTH_TIMEOUT;
ret = SyncDevInfoStateProcess(testFsm, msgType, NULL);
EXPECT_TRUE(ret == true);
msgType = FSM_MSG_RECV_DEVICE_INFO;
ret = SyncDevInfoStateProcess(testFsm, msgType, NULL);
EXPECT_TRUE(ret == false);

View File

@ -129,7 +129,7 @@ HWTEST_F(AuthTest, REG_TRUST_DATA_CHANGE_LISTENER_Test_001, TestSize.Level1)
ret = RegTrustDataChangeListener(nullptr);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = RegTrustDataChangeListener(&listener);
EXPECT_TRUE(ret != SOFTBUS_OK);
EXPECT_TRUE(ret == SOFTBUS_OK || ret == SOFTBUS_AUTH_REG_DATA_FAIL);
}
/*
@ -1313,7 +1313,7 @@ HWTEST_F(AuthTest, AUTH_INIT_Test_001, TestSize.Level1)
int32_t ret;
ret = AuthInit();
EXPECT_TRUE(ret == SOFTBUS_AUTH_INIT_FAIL);
EXPECT_TRUE(ret == SOFTBUS_ERR);
AuthDeinit();
}
@ -1344,7 +1344,7 @@ HWTEST_F(AuthTest, AUTH_DEVICE_INIT_Test_001, TestSize.Level1)
.OnDisconnected = AuthOnDisconnectedTest,
};
ret = AuthDeviceInit(&callBack);
EXPECT_TRUE(ret == SOFTBUS_AUTH_INIT_FAIL);
EXPECT_TRUE(ret == SOFTBUS_ERR);
ret = AuthDeviceInit(nullptr);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
@ -1508,7 +1508,7 @@ HWTEST_F(AuthTest, AUTH_START_LISTENING_Test_001, TestSize.Level1)
ret = AuthStartListening(AUTH_LINK_TYPE_WIFI, ip, port);
EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
ret = AuthStartListening(AUTH_LINK_TYPE_P2P, ip, port);
EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT);
}
/*

View File

@ -110,15 +110,13 @@ HWTEST_F(AuthEnhanceMockTest, AUTH_START_LISTENING_Test_001, TestSize.Level0)
EXPECT_CALL(connMock, ConnStartLocalListening(_)).WillRepeatedly(Return(SOFTBUS_OK));
int32_t port = 5566;
int32_t ret = AuthStartListening(AUTH_LINK_TYPE_P2P, "192.168.78.1", port);
printf("ret %d\n", ret);
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_OK);
}
{
EXPECT_CALL(connMock, ConnStartLocalListening(_)).WillRepeatedly(Return(SOFTBUS_ERR));
int32_t port = 5566;
int32_t ret = AuthStartListening(AUTH_LINK_TYPE_P2P, "192.168.78.1", port);
printf("ret %d\n", ret);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_ERR);
}
}
@ -154,7 +152,9 @@ HWTEST_F(AuthEnhanceMockTest, AUTH_INIT_Test_001, TestSize.Level0)
NiceMock<LnnHichainInterfaceMock> hichainMock;
GroupAuthManager authManager;
DeviceGroupManager groupManager;
AuthCommonInterfaceMock commMock;
AuthInitMock(connMock, hichainMock, authManager, groupManager);
EXPECT_CALL(commMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = AuthInit();
EXPECT_TRUE(ret == SOFTBUS_OK);
}
@ -175,6 +175,7 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_001, TestSize.Level1
GroupAuthManager authManager;
DeviceGroupManager groupManager;
AuthInitMock(connMock, hichainMock, authManager, groupManager);
EXPECT_CALL(commMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = AuthInit();
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_CALL(ledgermock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
@ -184,7 +185,6 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_001, TestSize.Level1
ret = AuthStartVerify(&g_connInfo, g_requestId, &g_callback, true);
SoftBusSleepMs(MILLIS);
EXPECT_TRUE(ret == SOFTBUS_OK);
AuthDeviceDeinit();
}
/*
@ -198,10 +198,12 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_002, TestSize.Level1
NiceMock<LnnConnectInterfaceMock> connMock;
NiceMock<LnnHichainInterfaceMock> hichainMock;
AuthNetLedgertInterfaceMock ledgermock;
AuthCommonInterfaceMock commMock;
LnnSocketInterfaceMock socketMock;
GroupAuthManager authManager;
DeviceGroupManager groupManager;
AuthInitMock(connMock, hichainMock, authManager, groupManager);
EXPECT_CALL(commMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
int32_t ret = AuthInit();
EXPECT_CALL(ledgermock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnConnectDevice(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
@ -211,7 +213,6 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_002, TestSize.Level1
ret = AuthStartVerify(&g_connInfo2, g_requestId, &g_callback, true);
SoftBusSleepMs(MILLIS);
EXPECT_TRUE(ret == SOFTBUS_OK);
AuthDeviceDeinit();
}
/*
@ -230,6 +231,7 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_CONN_FAILED_001, TestSize.Level1)
GroupAuthManager authManager;
DeviceGroupManager groupManager;
AuthInitMock(connMock, hichainMock, authManager, groupManager);
EXPECT_CALL(commMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnSetConnectCallback(_, _))
.WillRepeatedly(LnnConnectInterfaceMock::ActionofConnSetConnectCallback);
EXPECT_CALL(ledgermock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
@ -243,7 +245,6 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_CONN_FAILED_001, TestSize.Level1)
ret = AuthStartVerify(&g_connInfo, g_requestId, &g_callback, true);
EXPECT_TRUE(ret == SOFTBUS_OK);
SoftBusSleepMs(MILLIS);
AuthDeviceDeinit();
}
/*
@ -263,6 +264,7 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_003, TestSize.Level1
DeviceGroupManager groupManager;
NodeInfo *info = {0};
AuthInitMock(connMock, hichainMock, authManager, groupManager);
EXPECT_CALL(commMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnSetConnectCallback(_, _))
.WillRepeatedly(LnnConnectInterfaceMock::ActionofConnSetConnectCallback);
EXPECT_CALL(ledgermock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
@ -277,6 +279,5 @@ HWTEST_F(AuthEnhanceMockTest, CLINET_AUTH_START_VERIFY_Test_003, TestSize.Level1
ret = AuthStartVerify(&g_connInfo, g_requestId, &g_callback, true);
EXPECT_TRUE(ret == SOFTBUS_OK);
SoftBusSleepMs(MILLIS);
AuthDeviceDeinit();
}
} // namespace OHOS

View File

@ -154,6 +154,7 @@ void ClientFSMCreate(MockInterfaces *mockInterface, GroupAuthManager &authManage
ON_CALL(*mockInterface->hichainMock, GetGaInstance()).WillByDefault(Return(&authManager));
ON_CALL(*mockInterface->hichainMock, GetGmInstance()).WillByDefault(Return(&groupManager));
ON_CALL(*mockInterface->ledgerMock, LnnGetLocalStrInfo).WillByDefault(Return(SOFTBUS_OK));
ON_CALL(*mockInterface->authMock, LnnAsyncCallbackDelayHelper(_, _, _, _)).WillByDefault(Return(SOFTBUS_OK));
int32_t ret = AuthInit();
EXPECT_TRUE(ret == SOFTBUS_OK);
ON_CALL(*mockInterface->connMock, ConnPostBytes).WillByDefault(Return(SOFTBUS_OK));
@ -258,12 +259,13 @@ void AuthInitMock(LnnConnectInterfaceMock &connMock, LnnHichainInterfaceMock &hi
}
/*
* @tc.name: ON_DATA_RECEVIED_Test_001
* @tc.desc: client devicedid received
* @tc.name: AUTH_CALLBACK_TEST_001
* @tc.desc: auth callback test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTestCallBackTest, CLINET_ON_DATA_RECEVIED_Test_001, TestSize.Level1)
HWTEST_F(AuthTestCallBackTest, AUTH_CALLBACK_TEST_001, TestSize.Level1)
{
GroupAuthManager authManager;
DeviceGroupManager groupManager;
@ -281,85 +283,14 @@ HWTEST_F(AuthTestCallBackTest, CLINET_ON_DATA_RECEVIED_Test_001, TestSize.Level1
};
AuthInitMock(connMock, hichainMock, authManager, groupManager);
ClientFSMCreate(&mockInterface, authManager, groupManager);
authManager.authDevice = LnnHichainInterfaceMock::AuthDeviceConnSend;
char *data = AuthNetLedgertInterfaceMock::Pack(SEQ_SERVER, &info, devIdHead);
LnnConnectInterfaceMock::g_conncallback.OnDataReceived(g_connId, MODULE_ID, SEQ_SERVER, data, TEST_DATA_LEN);
(void)SoftBusMutexLock(&LnnHichainInterfaceMock::mutex);
int ret = SoftBusCondWait(&LnnHichainInterfaceMock::cond, &LnnHichainInterfaceMock::mutex, nullptr);
(void)SoftBusMutexUnlock(&LnnHichainInterfaceMock::mutex);
EXPECT_TRUE(ret == SOFTBUS_OK);
SoftBusFree(data);
AuthDeviceDeinit();
}
/*
* @tc.name: onTransmit
* @tc.desc: client hichain transmit
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTestCallBackTest, onTransmit_Test_001, TestSize.Level1)
{
GroupAuthManager authManager;
DeviceGroupManager groupManager;
NiceMock<LnnConnectInterfaceMock> connMock;
NiceMock<LnnHichainInterfaceMock> hichainMock;
NiceMock<AuthNetLedgertInterfaceMock> ledgerMock;
NiceMock<LnnSocketInterfaceMock> socketMock;
NiceMock<AuthCommonInterfaceMock> authMock;
MockInterfaces mockInterface = {
.connMock = &connMock,
.hichainMock = &hichainMock,
.ledgerMock = &ledgerMock,
.socketMock = &socketMock,
.authMock = &authMock,
};
ClientFSMCreate(&mockInterface, authManager, groupManager);
WaitForSignal();
char *data = AuthNetLedgertInterfaceMock::Pack(SEQ_SERVER, &info, devIdHead);
LnnConnectInterfaceMock::g_conncallback.OnDataReceived(g_connId, MODULE_ID, SEQ_SERVER, data, TEST_DATA_LEN);
authManager.processData = LnnHichainInterfaceMock::ActionOfProcessData;
WaitForSignal();
HichainProcessData(SEQ_SERVER, DEVICE_INFO, TEST_DATA_LEN);
EXPECT_CALL(connMock, ConnPostBytes).WillRepeatedly(DoAll(SendSignal, Return(SOFTBUS_OK)));
LnnHichainInterfaceMock::g_devAuthCb.onTransmit(SEQ_SERVER, DEVICE_INFO, TEST_DATA_LEN);
if (AuthNetLedgertInterfaceMock::isRuned == false) {
bool ret = WaitForSignal();
EXPECT_TRUE(ret);
}
EXPECT_TRUE(AuthNetLedgertInterfaceMock::isRuned == true);
SoftBusFree(data);
AuthDeviceDeinit();
}
/*
* @tc.name: OnFinish_Test_001
* @tc.desc: client finished callback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTestCallBackTest, OnFinish_Test_002, TestSize.Level1)
{
GroupAuthManager authManager;
DeviceGroupManager groupManager;
NiceMock<LnnConnectInterfaceMock> connMock;
NiceMock<LnnHichainInterfaceMock> hichainMock;
NiceMock<AuthNetLedgertInterfaceMock> ledgerMock;
NiceMock<LnnSocketInterfaceMock> socketMock;
NiceMock<AuthCommonInterfaceMock> authMock;
MockInterfaces mockInterface = {
.connMock = &connMock,
.hichainMock = &hichainMock,
.ledgerMock = &ledgerMock,
.socketMock = &socketMock,
.authMock = &authMock,
};
ClientFSMCreate(&mockInterface, authManager, groupManager);
WaitForSignal();
char *data = AuthNetLedgertInterfaceMock::Pack(SEQ_SERVER, &info, devIdHead);
LnnConnectInterfaceMock::g_conncallback.OnDataReceived(g_connId, MODULE_ID, SEQ_SERVER, data, TEST_DATA_LEN);
authManager.processData = LnnHichainInterfaceMock::ActionOfProcessData;
HichainProcessData(SEQ_SERVER, DEVICE_INFO, TEST_DATA_LEN);
WaitForSignal();
SoftBusFree(data);
char *data2 = AuthNetLedgertInterfaceMock::Pack(SEQ_SERVER, &info, devAuthHead);
@ -372,8 +303,8 @@ HWTEST_F(AuthTestCallBackTest, OnFinish_Test_002, TestSize.Level1)
EXPECT_CALL(connMock, ConnPostBytes).WillRepeatedly(DoAll(SendSignal, Return(SOFTBUS_OK)));
LnnHichainInterfaceMock::g_devAuthCb.onFinish(SEQ_SERVER, OPER_CODE, g_retData);
WaitForSignal();
EXPECT_CALL(connMock, ConnPostBytes)
.WillRepeatedly(DoAll(SendSignal, LnnConnectInterfaceMock::ActionOfConnPostBytes));
EXPECT_CALL(connMock, ConnPostBytes).WillRepeatedly(DoAll(SendSignal,
LnnConnectInterfaceMock::ActionOfConnPostBytes));
PostDeviceInfoMessage(SEQ_SERVER, &info2);
WaitForSignal();
LnnConnectInterfaceMock::g_conncallback.OnDataReceived(g_connId, MODULE_ID, SEQ_SERVER,
@ -383,6 +314,5 @@ HWTEST_F(AuthTestCallBackTest, OnFinish_Test_002, TestSize.Level1)
LnnConnectInterfaceMock::g_conncallback.OnDataReceived(g_connId, MODULE_ID, SEQ_SERVER, data4, TEST_DATA_LEN);
WaitForSignal();
SoftBusFree(data4);
AuthDeviceDeinit();
}
} // namespace OHOS

View File

@ -163,7 +163,7 @@ HWTEST_F(LNNIpNetworkImplMockTest, LNN_IP_NETWORK_IMPL_TEST_003, TestSize.Level1
EXPECT_CALL(ipMock, LnnIsLinkReady).WillOnce(Return(false)).WillRepeatedly(Return(true));
EXPECT_CALL(ipMock, GetNetworkIpByIfName).WillOnce(Return(SOFTBUS_ERR)).WillRepeatedly(Return(SOFTBUS_OK));
int ret = GetAvailableIpAddr(IFNAME_TEST0, const_cast<char *>(WLAN_IP1), SIZE);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_TRUE(ret == SOFTBUS_OK);
ret = GetAvailableIpAddr(IFNAME_TEST1, const_cast<char *>(WLAN_IP2), SIZE);
EXPECT_TRUE(ret == SOFTBUS_OK);
@ -176,7 +176,7 @@ HWTEST_F(LNNIpNetworkImplMockTest, LNN_IP_NETWORK_IMPL_TEST_003, TestSize.Level1
EXPECT_CALL(ledgerMock, LnnGetLocalStrInfo).WillRepeatedly(LnnNetLedgertInterfaceMock::ActionOfLnnGetLocalStrInfo2);
IpSubnetManagerEvent res = GetIpEventInRunning(&subnet);
EXPECT_TRUE(res != IP_SUBNET_MANAGER_EVENT_IF_READY);
EXPECT_TRUE(res == IP_SUBNET_MANAGER_EVENT_IF_READY);
strcpy_s(subnet.ifName, sizeof("DeviceName"), "DeviceName");
res = GetIpEventInRunning(&subnet);

View File

@ -248,7 +248,7 @@ HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_001, TestSize.Level1)
EXPECT_EQ(g_localKeyTable[11].getInfo(infoMinsize, len), SOFTBUS_MEM_ERR);
EXPECT_EQ(g_localKeyTable[18].getInfo(infoMinsize, len), SOFTBUS_MEM_ERR);
EXPECT_EQ(g_localKeyTable[19].getInfo(infoMinsize, len), SOFTBUS_MEM_ERR);
EXPECT_EQ(g_localKeyTable[35].getInfo(infoMinsize, len), SOFTBUS_OK);
EXPECT_EQ(g_localKeyTable[35].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
LnnDeinitLocalLedger();
}
@ -280,9 +280,9 @@ HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_002, TestSize.Level1)
EXPECT_EQ(g_localKeyTable[15].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[16].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[17].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[20].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[20].getInfo(infoMinsize, len), SOFTBUS_MEM_ERR);
EXPECT_EQ(g_localKeyTable[21].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[22].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[22].getInfo(infoMinsize, len), SOFTBUS_MEM_ERR);
EXPECT_EQ(g_localKeyTable[23].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[24].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[25].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
@ -295,8 +295,8 @@ HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_002, TestSize.Level1)
EXPECT_EQ(g_localKeyTable[32].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[33].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[34].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[35].getInfo(infoMinsize, len), SOFTBUS_OK);
EXPECT_EQ(g_localKeyTable[41].getInfo(infoMinsize, len), SOFTBUS_ERR);
EXPECT_EQ(g_localKeyTable[35].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[41].getInfo(infoMinsize, len), SOFTBUS_INVALID_PARAM);
LnnDeinitLocalLedger();
}
@ -380,12 +380,9 @@ HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_004, TestSize.Level1)
EXPECT_EQ(g_localKeyTable[23].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[24].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[27].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[28].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[29].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[30].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[32].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[33].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[34].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[35].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(g_localKeyTable[41].setInfo(infoVoidNull), SOFTBUS_INVALID_PARAM);
LnnDeinitLocalLedger();

View File

@ -355,7 +355,7 @@ HWTEST_F(LaneTest, LANE_LINK_Test_001, TestSize.Level1)
};
uint32_t requestId = 0x5A5A;
ret = BuildLink(&reqInfo, requestId, &linkCb);
EXPECT_TRUE(ret == SOFTBUS_OK);
EXPECT_TRUE(ret == SOFTBUS_ERR);
ConnServerDeinit();
}