mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-26 18:30:47 +00:00
!8389 fix:transfer differential code handling
Merge pull request !8389 from wangyipeng/master
This commit is contained in:
commit
36e0ec3019
@ -193,8 +193,8 @@ void TransChannelDeinit(void)
|
||||
TransAsyncReqLanePendingDeinit();
|
||||
TransNetworkStatisticsDeinit();
|
||||
TransReqAuthPendingDeinit();
|
||||
TransFreeLanePendingDeinit();
|
||||
TransAuthWithParaReqLanePendingDeinit();
|
||||
TransFreeLanePendingDeinit();
|
||||
SoftBusMutexDestroy(&g_myIdLock);
|
||||
}
|
||||
|
||||
@ -216,6 +216,15 @@ static bool IsLaneModuleError(int32_t errcode)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void TransFreeLaneInner(uint32_t laneHandle, bool isQosLane, bool isAsync)
|
||||
{
|
||||
if (isQosLane) {
|
||||
TransFreeLaneByLaneHandle(laneHandle, isAsync);
|
||||
} else {
|
||||
LnnFreeLane(laneHandle);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
|
||||
{
|
||||
if (param == NULL || transInfo == NULL) {
|
||||
@ -265,7 +274,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
|
||||
AnonymizeWrapper(tmpName), param->sessionId);
|
||||
AnonymizeFree(tmpName);
|
||||
if (ret != SOFTBUS_TRANS_STOP_BIND_BY_CANCEL) {
|
||||
TransFreeLane(laneHandle, param->isQosLane, param->isAsync);
|
||||
TransFreeLaneInner(laneHandle, param->isQosLane, param->isAsync);
|
||||
}
|
||||
(void)TransDeleteSocketChannelInfoBySession(param->sessionName, param->sessionId);
|
||||
}
|
||||
@ -338,8 +347,8 @@ EXIT_ERR:
|
||||
TransBuildTransAlarmEvent(&extraAlarm, appInfo, ret);
|
||||
TRANS_ALARM(OPEN_SESSION_FAIL_ALARM, CONTROL_ALARM_TYPE, extraAlarm);
|
||||
TransFreeAppInfo(appInfo);
|
||||
if (ret != SOFTBUS_TRANS_STOP_BIND_BY_CANCEL) {
|
||||
TransFreeLane(laneHandle, param->isQosLane, param->isAsync);
|
||||
if (ret != SOFTBUS_TRANS_STOP_BIND_BY_CANCEL || laneHandle != INVALID_LANE_REQ_ID) {
|
||||
TransFreeLaneInner(laneHandle, param->isQosLane, param->isAsync);
|
||||
}
|
||||
(void)TransDeleteSocketChannelInfoBySession(param->sessionName, param->sessionId);
|
||||
TRANS_LOGE(TRANS_SVC, "server TransOpenChannel err, socket=%{public}d, ret=%{public}d", param->sessionId, ret);
|
||||
@ -348,7 +357,7 @@ EXIT_CANCEL:
|
||||
TransBuildTransOpenChannelCancelEvent(&extra, transInfo, appInfo->timeStart, SOFTBUS_TRANS_STOP_BIND_BY_CANCEL);
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_OPEN_CHANNEL_END, extra);
|
||||
TransFreeAppInfo(appInfo);
|
||||
TransFreeLane(laneHandle, param->isQosLane, param->isAsync);
|
||||
TransFreeLaneInner(laneHandle, param->isQosLane, param->isAsync);
|
||||
(void)TransDeleteSocketChannelInfoBySession(param->sessionName, param->sessionId);
|
||||
TRANS_LOGE(TRANS_SVC, "server open channel cancel, socket=%{public}d", param->sessionId);
|
||||
return SOFTBUS_TRANS_STOP_BIND_BY_CANCEL;
|
||||
|
@ -241,13 +241,28 @@ int32_t GetBrMacFromConnInfo(uint32_t connId, char *peerBrMac, uint32_t len)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t TransProxyParseMessageNoDecrypt(ProxyMessage *msg)
|
||||
{
|
||||
uint8_t *allocData = (uint8_t *)SoftBusCalloc((uint32_t)msg->dateLen);
|
||||
if (allocData == NULL) {
|
||||
TRANS_LOGE(TRANS_CTRL, "malloc data fail");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s(allocData, msg->dateLen, msg->data, msg->dateLen) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "memcpy data fail");
|
||||
SoftBusFree(allocData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
msg->data = (char *)allocData;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t TransProxyParseMessage(char *data, int32_t len, ProxyMessage *msg, AuthHandle *auth)
|
||||
{
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(len > PROXY_CHANNEL_HEAD_LEN,
|
||||
SOFTBUS_INVALID_PARAM, TRANS_CTRL, "parseMessage: invalid message len!");
|
||||
int32_t ret = TransProxyParseMessageHead(data, len, msg);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_CTRL, "TransProxyParseMessageHead fail!");
|
||||
|
||||
if ((msg->msgHead.cipher & ENCRYPTED) != 0) {
|
||||
if (msg->dateLen <= 0 || (uint32_t)msg->dateLen < sizeof(uint32_t)) {
|
||||
TRANS_LOGE(TRANS_CTRL, "The data length of the ProxyMessage is abnormal!");
|
||||
@ -281,15 +296,11 @@ int32_t TransProxyParseMessage(char *data, int32_t len, ProxyMessage *msg, AuthH
|
||||
msg->data = (char *)decData;
|
||||
msg->dateLen = (int32_t)decDataLen;
|
||||
} else {
|
||||
uint8_t *allocData = (uint8_t *)SoftBusCalloc((uint32_t)msg->dateLen);
|
||||
if (allocData == NULL) {
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
ret = TransProxyParseMessageNoDecrypt(msg);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "trans not need decrypt msg fail, ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (memcpy_s(allocData, msg->dateLen, msg->data, msg->dateLen) != EOK) {
|
||||
SoftBusFree(allocData);
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
msg->data = (char *)allocData;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ int32_t TransDecConnRefByConnId(uint32_t connId, bool isServer)
|
||||
{
|
||||
ProxyConnInfo *removeNode = NULL;
|
||||
ProxyConnInfo *tmpNode = NULL;
|
||||
|
||||
if ((g_proxyConnectionList == NULL) || (connId == 0)) {
|
||||
TRANS_LOGE(TRANS_MSG, "g_proxyConnectionList or connId is null");
|
||||
return SOFTBUS_NO_INIT;
|
||||
@ -843,10 +844,9 @@ static int32_t TransProxySendBadKeyMessage(ProxyMessage *msg, const AuthHandle *
|
||||
} else {
|
||||
msg->msgHead.cipher |= BAD_CIPHER;
|
||||
}
|
||||
|
||||
TRANS_LOGW(TRANS_MSG, "send msg is bad key myChannelId=%{public}d, peerChannelId=%{public}d",
|
||||
msg->msgHead.myId, msg->msgHead.peerId);
|
||||
|
||||
|
||||
int32_t ret = PackPlaintextMessage(&msg->msgHead, &dataInfo);
|
||||
TRANS_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, TRANS_MSG, "PackPlaintextMessage fail");
|
||||
|
||||
@ -858,10 +858,11 @@ static int32_t TransProxySendBadKeyMessage(ProxyMessage *msg, const AuthHandle *
|
||||
|
||||
static void TransProxyOnDataReceived(uint32_t connectionId, ConnModule moduleId, int64_t seq, char *data, int32_t len)
|
||||
{
|
||||
ProxyMessage msg;
|
||||
TRANS_LOGI(TRANS_CTRL, "recv data connId=%{public}u, moduleId=%{public}d, seq=%{public}" PRId64 ", len=%{public}d",
|
||||
connectionId, moduleId, seq, len);
|
||||
TRANS_CHECK_AND_RETURN_LOGE(data != NULL && moduleId == MODULE_PROXY_CHANNEL, TRANS_CTRL, "invalid param");
|
||||
|
||||
ProxyMessage msg;
|
||||
(void)memset_s(&msg, sizeof(ProxyMessage), 0, sizeof(ProxyMessage));
|
||||
msg.connId = connectionId;
|
||||
|
||||
|
@ -95,6 +95,7 @@ static int32_t StartVerifySession(SessionConn *conn)
|
||||
return SOFTBUS_TRANS_TCP_GENERATE_SESSIONKEY_FAILED;
|
||||
}
|
||||
SetSessionKeyByChanId(conn->channelId, conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey));
|
||||
|
||||
bool isAuthServer = false;
|
||||
uint32_t cipherFlag = FLAG_WIFI;
|
||||
bool isLegacyOs = IsPeerDeviceLegacyOs(conn->appInfo.osType);
|
||||
@ -108,6 +109,7 @@ static int32_t StartVerifySession(SessionConn *conn)
|
||||
if (isAuthServer) {
|
||||
seq |= AUTH_CONN_SERVER_SIDE;
|
||||
}
|
||||
|
||||
char *bytes = PackRequest(&conn->appInfo);
|
||||
if (bytes == NULL) {
|
||||
TRANS_LOGE(TRANS_CTRL,
|
||||
@ -210,8 +212,8 @@ static int32_t TdcOnConnectEvent(ListenerModule module, int cfd, const ConnectOp
|
||||
TRANS_LOGW(TRANS_CTRL, "invalid param, cfd=%{public}d", cfd);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t ret;
|
||||
int32_t channelId = GenerateChannelId(true);
|
||||
int32_t ret = TransSrvAddDataBufNode(channelId, cfd); // fd != channelId
|
||||
TransEventExtra extra = {
|
||||
.socketName = NULL,
|
||||
.peerNetworkId = NULL,
|
||||
@ -220,6 +222,16 @@ static int32_t TdcOnConnectEvent(ListenerModule module, int cfd, const ConnectOp
|
||||
.socketFd = cfd,
|
||||
.channelId = channelId
|
||||
};
|
||||
if (channelId <= INVALID_CHANNEL_ID) {
|
||||
ret = SOFTBUS_TRANS_INVALID_CHANNEL_ID;
|
||||
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, "channelId is invalid");
|
||||
ConnShutdownSocket(cfd);
|
||||
return ret;
|
||||
}
|
||||
ret = TransSrvAddDataBufNode(channelId, cfd); // fd != channelId
|
||||
if (ret != SOFTBUS_OK) {
|
||||
extra.result = EVENT_STAGE_RESULT_FAILED;
|
||||
extra.errcode = ret;
|
||||
@ -257,7 +269,6 @@ static void CloseTcpDirectFd(int fd)
|
||||
static void TransProcDataRes(ListenerModule module, int32_t ret, int32_t channelId, int32_t fd)
|
||||
{
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGI(TRANS_CTRL, "unequal SOFTBUS_OK");
|
||||
TransEventExtra extra = {
|
||||
.socketName = NULL,
|
||||
.peerNetworkId = NULL,
|
||||
@ -310,7 +321,8 @@ static int32_t ProcessSocketOutEvent(SessionConn *conn, int fd)
|
||||
return SOFTBUS_TRANS_ADD_TRIGGER_FAILED;
|
||||
}
|
||||
ret = StartVerifySession(conn);
|
||||
TransEventExtra extra = { .socketName = NULL,
|
||||
TransEventExtra extra = {
|
||||
.socketName = NULL,
|
||||
.peerNetworkId = NULL,
|
||||
.calleePkg = NULL,
|
||||
.callerPkg = NULL,
|
||||
@ -318,10 +330,11 @@ static int32_t ProcessSocketOutEvent(SessionConn *conn, int fd)
|
||||
.channelId = conn->channelId,
|
||||
.authId = conn->authHandle.authId,
|
||||
.errcode = ret,
|
||||
.result = (ret == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED };
|
||||
.result = (ret == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED
|
||||
};
|
||||
TRANS_EVENT(EVENT_SCENE_OPEN_CHANNEL, EVENT_STAGE_HANDSHAKE_START, extra);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "start verify session fail.");
|
||||
TRANS_LOGE(TRANS_CTRL, "start verify session failed, ret=%{public}d", ret);
|
||||
DelTrigger(conn->listenMod, fd, READ_TRIGGER);
|
||||
ConnShutdownSocket(fd);
|
||||
(void)NotifyChannelOpenFailed(conn->channelId, ret);
|
||||
@ -331,7 +344,7 @@ static int32_t ProcessSocketOutEvent(SessionConn *conn, int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ProcessSocketSocketExceptionEvent(SessionConn *conn, int fd)
|
||||
static void ProcessSocketExceptionEvent(SessionConn *conn, int fd)
|
||||
{
|
||||
TRANS_LOGE(TRANS_CTRL, "exception occurred.");
|
||||
DelTrigger(conn->listenMod, fd, EXCEPT_TRIGGER);
|
||||
@ -349,7 +362,7 @@ static int32_t TdcOnDataEvent(ListenerModule module, int events, int fd)
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (GetSessionConnByFd(fd, conn) != SOFTBUS_OK || conn->appInfo.fd != fd) {
|
||||
TRANS_LOGE(TRANS_CTRL, "fd=%{public}d is not exist tdc info. appfd=%{public}d", fd, conn->appInfo.fd);
|
||||
TRANS_LOGE(TRANS_CTRL, "fd is not exist tdc info. fd=%{public}d, appfd=%{public}d", fd, conn->appInfo.fd);
|
||||
for (uint32_t i = DIRECT_CHANNEL_SERVER_P2P; i <= DIRECT_CHANNEL_SERVER_HML_END; i++) {
|
||||
DelTrigger((ListenerModule)i, fd, READ_TRIGGER);
|
||||
DelTrigger((ListenerModule)i, fd, WRITE_TRIGGER);
|
||||
@ -366,7 +379,7 @@ static int32_t TdcOnDataEvent(ListenerModule module, int events, int fd)
|
||||
} else if (events == SOFTBUS_SOCKET_OUT) {
|
||||
ret = ProcessSocketOutEvent(conn, fd);
|
||||
} else if (events == SOFTBUS_SOCKET_EXCEPTION) {
|
||||
ProcessSocketSocketExceptionEvent(conn, fd);
|
||||
ProcessSocketExceptionEvent(conn, fd);
|
||||
}
|
||||
(void)memset_s(conn->appInfo.sessionKey, sizeof(conn->appInfo.sessionKey), 0, sizeof(conn->appInfo.sessionKey));
|
||||
SoftBusFree(conn);
|
||||
|
Loading…
Reference in New Issue
Block a user