feat: adjust file transfer priority during business concurrency

Signed-off-by: xuxiaoqing <xuxiaoqing16@huawei.com>
This commit is contained in:
xuxiaoqing 2024-06-04 15:37:08 +08:00
parent 79d885ddbf
commit 9bf6664934
29 changed files with 370 additions and 9 deletions

View File

@ -1645,6 +1645,11 @@ void NSTACKX_DFileRegisterDefaultLog(void)
}
int32_t NSTACKX_DFileSessionGetFileList(int32_t sessionId)
{
return NSTACKX_EOK;
}
int32_t NSTACKX_DFileSetSessionOpt(int32_t sessionId, const DFileOpt *opt)
{
return NSTACKX_EOK;
}

View File

@ -415,6 +415,26 @@ NSTACKX_EXPORT void NSTACKX_DFileRegisterDefaultLog(void);
*/
NSTACKX_EXPORT int32_t NSTACKX_DFileSessionGetFileList(int32_t sessionId);
typedef enum {
/* the priority of socket, value is same as IP_TOS, vallen is siezeof(uint8_t) */
OPT_TYPE_SOCK_PRIO,
OPT_TYPE_BUTT
} DFileOptType;
typedef struct {
DFileOptType optType;
uint32_t valLen; /* length of value */
uint64_t value; /* the option value, could be a pointer */
} DFileOpt;
/*
* set dfile session opt
* @brief Sets DFile session options. for client session, Recommend to configure after DFILE_ON_CONNECT_SUCCESS.
* @param[in] sessionId the session id of the session
* @param[in] opt option tlv
* @return 0 on success, negative value on failure
*/
NSTACKX_EXPORT int32_t NSTACKX_DFileSetSessionOpt(int32_t sessionId, const DFileOpt *opt);
#ifdef __cplusplus
}
#endif

View File

@ -80,6 +80,9 @@ extern "C" {
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
#define FILE_PRIORITY_BE 0x00
#define FILE_PRIORITY_BK 0x08
typedef struct {
SoftBusMutex lock;
unsigned int cnt;

View File

@ -112,6 +112,7 @@ enum SoftBusFuncId {
CLIENT_ON_PERMISSION_CHANGE,
CLIENT_SET_CHANNEL_INFO,
CLIENT_ON_DATA_LEVEL_CHANGED,
CLIENT_ON_TRANS_LIMIT_CHANGE,
};
#ifdef __cplusplus

View File

@ -43,6 +43,7 @@ int32_t ClientIpcOnChannelQosEvent(const char *pkgName, const QosParam *param);
int32_t InformPermissionChange(int32_t state, const char *pkgName, int32_t pid);
int32_t ClientIpcSetChannelInfo(
const char *pkgName, const char *sessionName, int32_t sessionId, const TransInfo *transInfo, int32_t pid);
int32_t ClientIpcOnTransLimitChange(const char *pkgName, int32_t pid, int32_t channelId, uint8_t tos);
#ifdef __cplusplus
}

View File

@ -65,3 +65,12 @@ int32_t ClientIpcSetChannelInfo(
(void)pid;
return TransSetChannelInfo(sessionName, sessionId, transInfo->channelId, transInfo->channelType);
}
int32_t ClientIpcOnTransLimitChange(const char *pkgName, int32_t pid, int32_t channelId, uint8_t tos)
{
(void)pkgName;
(void)pid;
(void)channelId;
(void)tos;
return SOFTBUS_FUNC_NOT_SUPPORT;
}

View File

@ -274,4 +274,13 @@ int32_t ClientIpcSetChannelInfo(
TRANS_LOGE(TRANS_CTRL, "SendRequest failed, ret=%{public}d", ret);
}
return ret;
}
int32_t ClientIpcOnTransLimitChange(const char *pkgName, int32_t pid, int32_t channelId, uint8_t tos)
{
(void)pkgName;
(void)pid;
(void)channelId;
(void)tos;
return SOFTBUS_FUNC_NOT_SUPPORT;
}

View File

@ -52,6 +52,7 @@ public:
void OnRefreshDeviceFound(const void *device, uint32_t deviceLen) override;
int32_t OnClientPermissonChange(const char *pkgName, int32_t state);
void OnDataLevelChanged(const char *networkId, const DataLevelInfo *dataLevelInfo) override;
int32_t OnClientTransLimitChange(int32_t channelId, uint8_t tos) override;
private:
static inline BrokerDelegator<TransClientProxy> delegator_;

View File

@ -157,3 +157,18 @@ int32_t ClientIpcOnChannelQosEvent(const char *pkgName, const QosParam *param)
param->tvCount, param->tvList);
return SOFTBUS_OK;
}
int32_t ClientIpcOnTransLimitChange(const char *pkgName, int32_t pid, int32_t channelId, uint8_t tos)
{
if (pkgName == nullptr) {
TRANS_LOGE(TRANS_SDK, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
sptr<TransClientProxy> clientProxy = GetClientProxy(pkgName, pid);
if (clientProxy == nullptr) {
TRANS_LOGE(TRANS_SDK, "softbus client proxy is nullptr!");
return SOFTBUS_TRANS_GET_CLIENT_PROXY_NULL;
}
return clientProxy->OnClientTransLimitChange(channelId, tos);
}

View File

@ -111,6 +111,42 @@ int32_t TransClientProxy::MessageParcelWrite(MessageParcel &data, const char *se
return SOFTBUS_OK;
}
int32_t TransClientProxy::OnClientTransLimitChange(int32_t channelId, uint8_t tos)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TRANS_LOGE(TRANS_CTRL, "remote is nullptr");
return SOFTBUS_TRANS_PROXY_REMOTE_NULL;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
TRANS_LOGE(TRANS_CTRL, "write InterfaceToken failed!");
return SOFTBUS_TRANS_PROXY_WRITETOKEN_FAILED;
}
if (!data.WriteInt32(channelId)) {
TRANS_LOGE(TRANS_CTRL, "write channel id failed");
return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
}
if (!data.WriteUint8(tos)) {
TRANS_LOGE(TRANS_CTRL, "write tos failed");
return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
}
MessageParcel reply;
MessageOption option;
int32_t ret = remote->SendRequest(CLIENT_ON_TRANS_LIMIT_CHANGE, data, reply, option);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "OnClientTransLimitChange send request failed, ret=%{public}d", ret);
return ret;
}
int32_t serverRet;
if (!reply.ReadInt32(serverRet)) {
TRANS_LOGE(TRANS_CTRL, "OnChannelOpened read serverRet failed");
return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
}
return serverRet;
}
int32_t TransClientProxy::OnChannelOpened(const char *sessionName, const ChannelInfo *channel)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -29,6 +29,8 @@
#include "trans_lane_manager.h"
#include "trans_log.h"
#include "trans_session_manager.h"
#include "trans_tcp_direct_sessionconn.h"
#include "trans_udp_channel_manager.h"
static IServerChannelCallBack g_channelCallBack;
@ -81,7 +83,9 @@ static int32_t TransServerOnChannelOpened(const char *pkgName, int32_t pid, cons
SoftbusRecordOpenSessionKpi(pkgName, channel->linkType, SOFTBUS_EVT_OPEN_SESSION_SUCC, timediff);
SoftbusHitraceStop();
TransSetSocketChannelStateByChannel(channel->channelId, channel->channelType, CORE_SESSION_STATE_CHANNEL_OPENED);
return ClientIpcOnChannelOpened(pkgName, sessionName, channel, pid);
int32_t ret = ClientIpcOnChannelOpened(pkgName, sessionName, channel, pid);
(void)UdpChannelFileTransLimit(channel, FILE_PRIORITY_BK);
return ret;
}
static int32_t TransServerOnChannelClosed(
@ -109,6 +113,9 @@ static int32_t TransServerOnChannelClosed(
TRANS_LOGE(TRANS_CTRL, "client ipc on channel close fail");
return SOFTBUS_IPC_ERR;
}
if (IsTdcRecoveryTransLimit() && IsUdpRecoveryTransLimit()) {
UdpChannelFileTransRecoveryLimit(FILE_PRIORITY_BE);
}
return SOFTBUS_OK;
}

View File

@ -558,7 +558,11 @@ int32_t TransReleaseUdpResources(int32_t channelId)
int32_t TransCloseChannel(const char *sessionName, int32_t channelId, int32_t channelType)
{
return TransCommonCloseChannel(sessionName, channelId, channelType);
int32_t ret = TransCommonCloseChannel(sessionName, channelId, channelType);
if (IsTdcRecoveryTransLimit() && IsUdpRecoveryTransLimit()) {
UdpChannelFileTransRecoveryLimit(FILE_PRIORITY_BE);
}
return ret;
}
int32_t TransCloseChannelWithStatistics(int32_t channelId, uint64_t laneId, const void *dataInfo, uint32_t len)

View File

@ -93,6 +93,8 @@ int32_t TcpTranGetAppInfobyChannelId(int32_t channelId, AppInfo* appInfo);
int32_t *GetChannelIdsByAuthIdAndStatus(int32_t *num, int64_t authId, uint32_t status);
bool IsTdcRecoveryTransLimit(void);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -363,6 +363,24 @@ int32_t SetSessionConnStatusById(int32_t channelId, uint32_t status)
return SOFTBUS_NOT_FIND;
}
bool IsTdcRecoveryTransLimit(void)
{
if (GetSessionConnLock() != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "lock failed.");
return false;
}
SessionConn *connInfo = NULL;
LIST_FOR_EACH_ENTRY(connInfo, &g_sessionConnList->list, SessionConn, node) {
if (connInfo->appInfo.businessType == BUSINESS_TYPE_BYTE) {
TRANS_LOGD(TRANS_CTRL, "tcp direct channel exists bytes business, no need to recovery limit.");
ReleaseSessonConnLock();
return false;
}
}
ReleaseSessonConnLock();
return true;
}
int32_t TcpTranGetAppInfobyChannelId(int32_t channelId, AppInfo* appInfo)
{
if (GetSessionConnLock() != SOFTBUS_OK) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -39,6 +39,7 @@ typedef struct {
uint32_t requestId;
bool isMeta;
int32_t errCode;
uint8_t tos;
} UdpChannelInfo;
SoftBusList *GetUdpChannelMgrHead(void);
@ -70,6 +71,12 @@ UdpChannelInfo *TransGetChannelObj(int32_t channelId);
int32_t TransGetUdpAppInfoByChannelId(int32_t channelId, AppInfo *appInfo);
int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo);
int32_t UdpChannelFileTransLimit(const ChannelInfo *channel, uint8_t tos);
int32_t UdpChannelFileTransRecoveryLimit(uint8_t tos);
bool IsUdpRecoveryTransLimit(void);
#ifdef __cplusplus
}
#endif

View File

@ -23,6 +23,7 @@
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
#include "trans_client_proxy.h"
#include "trans_log.h"
#include "trans_udp_negotiation.h"
@ -547,3 +548,85 @@ int32_t TransUdpGetChannelIdByAddr(AppInfo *appInfo)
TRANS_LOGE(TRANS_CTRL, "not found peerChannelId and addr");
return SOFTBUS_NOT_FIND;
}
static int32_t ModifyUdpChannelTos(uint8_t tos)
{
if (g_udpChannelMgr == NULL) {
TRANS_LOGE(TRANS_CTRL, "udp channel manager not initialized.");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&(g_udpChannelMgr->lock)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "lock failed");
return SOFTBUS_LOCK_ERR;
}
UdpChannelInfo *udpChannelNode = NULL;
int32_t ret = SOFTBUS_ERR;
LIST_FOR_EACH_ENTRY(udpChannelNode, &(g_udpChannelMgr->list), UdpChannelInfo, node) {
if (udpChannelNode->info.businessType == BUSINESS_TYPE_FILE && udpChannelNode->info.isClient &&
udpChannelNode->tos != tos) {
ret = ClientIpcOnTransLimitChange(udpChannelNode->info.myData.pkgName, udpChannelNode->info.myData.pid,
udpChannelNode->info.myData.channelId, tos);
TRANS_LOGI(TRANS_CTRL, "ClientIpcOnTransLimitChange end, channelId=%{public}" PRId64 ", ret=%{public}d",
udpChannelNode->info.myData.channelId, ret);
if (ret == SOFTBUS_OK) {
udpChannelNode->tos = tos;
}
}
}
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
return ret;
}
int32_t UdpChannelFileTransLimit(const ChannelInfo *channel, uint8_t tos)
{
if (channel == NULL) {
TRANS_LOGE(TRANS_CTRL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
TRANS_LOGD(TRANS_CTRL, "new session opened, channelId=%{public}d, channelType=%{public}d, businessType=%{public}d",
channel->channelId, channel->channelType, channel->businessType);
if (channel->channelType == CHANNEL_TYPE_PROXY) {
TRANS_LOGI(TRANS_CTRL, "channel type is proxy, no need to limit file trans.");
return SOFTBUS_OK;
}
if (channel->businessType == BUSINESS_TYPE_MESSAGE) {
TRANS_LOGI(TRANS_CTRL, "business type is message, no need to limit file trans.");
return SOFTBUS_OK;
}
int32_t ret = ModifyUdpChannelTos(tos);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "ModifyUdpChannelTos failed, ret=%{public}d", ret);
}
return SOFTBUS_OK;
}
int32_t UdpChannelFileTransRecoveryLimit(uint8_t tos)
{
int32_t ret = ModifyUdpChannelTos(tos);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "ModifyUdpChannelTos failed, ret=%{public}d", ret);
}
return SOFTBUS_OK;
}
bool IsUdpRecoveryTransLimit(void)
{
if (g_udpChannelMgr == NULL) {
TRANS_LOGE(TRANS_CTRL, "invalid param.");
return false;
}
if (SoftBusMutexLock(&(g_udpChannelMgr->lock)) != SOFTBUS_OK) {
TRANS_LOGE(TRANS_CTRL, "lock failed");
return false;
}
UdpChannelInfo *udpChannelNode = NULL;
LIST_FOR_EACH_ENTRY(udpChannelNode, &(g_udpChannelMgr->list), UdpChannelInfo, node) {
if (udpChannelNode->info.businessType == BUSINESS_TYPE_STREAM) {
TRANS_LOGD(TRANS_CTRL, "udp channel exists stream business, no need to recovery limit.");
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
return false;
}
}
(void)SoftBusMutexUnlock(&(g_udpChannelMgr->lock));
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -143,6 +143,17 @@ typedef struct {
int32_t value; /**< Value of Qos types */
} QosTV;
/**
* @brief Enumerates the file priority.
*
* @since 2.0
* @version 2.0
*/
typedef enum {
FILE_PRIORITY_TYPE_DEFAUT = 0, /**< Default priority */
FILE_PRIORITY_TYPE_LOW, /**< Low priority */
} FilePriority;
/**
* @brief Enumerates the file types.
*
@ -159,6 +170,7 @@ typedef enum {
FILE_EVENT_RECV_FINISH, /**< Receive file end */
FILE_EVENT_RECV_ERROR, /**< Receive file failed */
FILE_EVENT_TRANS_STATUS, /**< Transmission status of the files */
FILE_EVENT_TRANS_LIMIT_CHANGED, /**< Transmission limit changed */
FILE_EVENT_BUTT,
} FileEventType;
@ -183,6 +195,7 @@ typedef struct {
FileStatusList statusList; /**< File status list */
int32_t errorCode; /**< Error code */
uint32_t rate; /**< Rate of the file transmission */
FilePriority filePriority; /**< Priority of the file */
} FileEvent;
/**

View File

@ -77,6 +77,8 @@ public:
virtual void OnDataLevelChanged(const char *networkId, const DataLevelInfo *dataLevelInfo);
virtual int32_t OnClientTransLimitChange(int32_t channelId, uint8_t tos);
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISoftBusClient");
};

View File

@ -58,6 +58,7 @@ public:
void OnRefreshLNNResult(int32_t refreshId, int32_t reason) override;
void OnRefreshDeviceFound(const void *device, uint32_t deviceLen) override;
void OnDataLevelChanged(const char *networkId, const DataLevelInfo *dataLevelInfo) override;
int32_t OnClientTransLimitChange(int32_t channelId, uint8_t tos) override;
private:
int32_t OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply);
@ -82,6 +83,7 @@ private:
int32_t OnRefreshDeviceFoundInner(MessageParcel &data, MessageParcel &reply);
int32_t OnClientPermissonChangeInner(MessageParcel &data, MessageParcel &reply);
int32_t OnDataLevelChangedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnClientTransLimitChangeInner(MessageParcel &data, MessageParcel &reply);
using SoftBusClientStubFunc =
int32_t (SoftBusClientStub::*)(MessageParcel &data, MessageParcel &reply);

View File

@ -149,4 +149,10 @@ void ISoftBusClient::OnDataLevelChanged(const char *networkId, const DataLevelIn
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
int32_t ISoftBusClient::OnClientTransLimitChange(int32_t channelId, uint8_t tos)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
return SOFTBUS_OK;
}
} // namespace OHOS

View File

@ -30,6 +30,7 @@
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_server_ipc_interface_code.h"
#include "client_trans_udp_manager.h"
namespace OHOS {
SoftBusClientStub::SoftBusClientStub()
@ -78,6 +79,8 @@ SoftBusClientStub::SoftBusClientStub()
&SoftBusClientStub::SetChannelInfoInner;
memberFuncMap_[CLIENT_ON_DATA_LEVEL_CHANGED] =
&SoftBusClientStub::OnDataLevelChangedInner;
memberFuncMap_[CLIENT_ON_TRANS_LIMIT_CHANGE] =
&SoftBusClientStub::OnClientTransLimitChangeInner;
}
int32_t SoftBusClientStub::OnRemoteRequest(uint32_t code,
@ -159,6 +162,32 @@ int32_t SoftBusClientStub::OnPublishFailInner(MessageParcel &data, MessageParcel
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnClientTransLimitChangeInner(MessageParcel &data, MessageParcel &reply)
{
int32_t channelId;
if (!data.ReadInt32(channelId)) {
COMM_LOGE(COMM_SDK, "OnClientTransLimitChangeInner read channel id failed!");
return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
}
uint8_t tos;
if (!data.ReadUint8(tos)) {
COMM_LOGE(COMM_SDK, "OnClientTransLimitChangeInner read tos failed!");
return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
}
int32_t ret = OnClientTransLimitChange(channelId, tos);
bool res = reply.WriteInt32(ret);
if (!res) {
COMM_LOGE(COMM_SDK, "OnClientTransLimitChangeInner write reply failed!");
return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
}
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnClientTransLimitChange(int32_t channelId, uint8_t tos)
{
return TransLimitChange(channelId, tos);
}
void SoftBusClientStub::OnDeviceFound(const DeviceInfo *device)
{
DiscClientOnDeviceFound(device);

View File

@ -508,6 +508,8 @@
"UnregistDirSchema";
"TransRegistDirSchema";
"TransUnRegistDirSchema";
"TransLimitChange";
"NotifyTransLimitChanged";
extern "C++" {
OHOS::StreamAdaptor*;
Communication::SoftBus*;
@ -573,6 +575,7 @@
"non-virtual thunk to OHOS::SoftBusClientStub::OnRefreshDeviceFound(void const*, unsigned int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnRefreshLNNResult(int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnTimeSyncResult(void const*, unsigned int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnClientTransLimitChange(int, unsigned char)";
"vtable for Communication::SoftBus::IStreamSocket";
"vtable for Communication::SoftBus::RawStreamData";
"vtable for Communication::SoftBus::SessionImpl";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -84,6 +84,8 @@ void TransUdpDeleteFileListener(const char *sessionName);
int32_t TransUdpOnCloseAckReceived(int32_t channelId);
int32_t ClientEmitFileEvent(int32_t channelId);
int32_t TransLimitChange(int32_t channelId, uint8_t tos);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -614,6 +614,42 @@ void TransUdpDeleteFileListener(const char *sessionName)
return TransDeleteFileListener(sessionName);
}
int32_t TransLimitChange(int32_t channelId, uint8_t tos)
{
if (tos != FILE_PRIORITY_BK && tos != FILE_PRIORITY_BE) {
TRANS_LOGE(TRANS_FILE, "invalid ip tos");
return SOFTBUS_INVALID_PARAM;
}
UdpChannel channel;
(void)memset_s(&channel, sizeof(UdpChannel), 0, sizeof(UdpChannel));
int32_t ret = TransGetUdpChannel(channelId, &channel);
if (ret != SOFTBUS_OK) {
return ret;
}
if (channel.info.isServer) {
TRANS_LOGE(TRANS_FILE, "server side no need to set ip tos");
return SOFTBUS_NOT_NEED_UPDATE;
}
if (channel.businessType != BUSINESS_TYPE_FILE) {
TRANS_LOGE(TRANS_FILE, "bussiness type not match");
return SOFTBUS_NOT_NEED_UPDATE;
}
uint8_t dfileTos = tos;
DFileOpt dfileOpt = {
.optType = OPT_TYPE_SOCK_PRIO,
.valLen = sizeof(uint8_t),
.value = (uint64_t)&dfileTos,
};
ret = NSTACKX_DFileSetSessionOpt(channel.dfileId, &dfileOpt);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "NSTACKX_DFileSetOpt, channelId=%{public}d, ret=%{public}d, tos=%{public}hhu", channelId,
ret, tos);
return ret;
}
NotifyTransLimitChanged(channelId, tos);
return ret;
}
int32_t TransUdpOnCloseAckReceived(int32_t channelId)
{
return SetPendingPacket(channelId, 0, PENDING_TYPE_UDP);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -54,6 +54,8 @@ void TransFileSchemaDeinit(void);
int32_t CheckFileSchema(int32_t sessionId, FileSchemaListener *fileSchemaListener);
int32_t SetSchemaCallback(FileSchema fileSchema, const char *sFileList[], uint32_t fileCnt);
int32_t NotifyTransLimitChanged(int32_t channelId, uint8_t tos);
#ifdef __cplusplus
}
#endif

View File

@ -25,6 +25,7 @@
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "trans_log.h"
#include "client_trans_session_manager.h"
#define DEFAULT_KEY_LENGTH 32
#define MAX_FILE_NUM 500
@ -523,4 +524,40 @@ int32_t TransSendFile(int32_t dfileId, const char *sFileList[], const char *dFil
return NSTACKX_DFileSendFiles(dfileId, sFileList, fileCnt, NULL);
}
return NSTACKX_DFileSendFilesWithRemotePath(dfileId, sFileList, dFileList, fileCnt, NULL);
}
}
int32_t NotifyTransLimitChanged(int32_t channelId, uint8_t tos)
{
char sessionName[SESSION_NAME_SIZE_MAX + 1] = { 0 };
int32_t ret = ClientGetSessionNameByChannelId(channelId, CHANNEL_TYPE_UDP, sessionName, SESSION_NAME_SIZE_MAX);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "failed to get sessionName, channelId=%{public}d", channelId);
return ret;
}
FileListener fileListener;
(void)memset_s(&fileListener, sizeof(FileListener), 0, sizeof(FileListener));
ret = TransGetFileListener(sessionName, &fileListener);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "get file listener failed");
return ret;
}
int32_t sessionId = INVALID_SESSION_ID;
ret = ClientGetSessionIdByChannelId(channelId, CHANNEL_TYPE_UDP, &sessionId);
if (ret != SOFTBUS_OK) {
TRANS_LOGE(TRANS_FILE, "get file listener failed");
return ret;
}
if (fileListener.socketSendCallback != NULL) {
FileEvent event;
(void)memset_s(&event, sizeof(FileEvent), 0, sizeof(FileEvent));
event.type = FILE_EVENT_TRANS_LIMIT_CHANGED;
if (tos == FILE_PRIORITY_BE) {
event.filePriority = FILE_PRIORITY_TYPE_DEFAUT;
} else {
event.filePriority = FILE_PRIORITY_TYPE_LOW;
}
fileListener.socketSendCallback(sessionId, &event);
TRANS_LOGI(TRANS_FILE, "notify trans limit changed, file priority=%{public}d", event.filePriority);
}
return ret;
}

View File

@ -77,6 +77,7 @@ ohos_unittest("TransServerTcpDirectTest") {
"$dsoftbus_root_path/core/discovery/event_manager/include",
"$dsoftbus_root_path/core/connection/wifi_direct",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/transmission/trans_channel/udp_negotiation/include",
]
deps = [

View File

@ -73,6 +73,9 @@ ohos_unittest("TransUdpNegoTest") {
"$dsoftbus_root_path/tests/sdk/common/include",
"$dsoftbus_root_path/core/frame/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/manager/src",
"$dsoftbus_root_path/core/transmission/trans_channel/udp_negotiation/include",
"$dsoftbus_root_path/sdk/transmission/trans_channel/udp/common/include",
"$dsoftbus_root_path/core/transmission/ipc/include",
]
deps = [
@ -232,6 +235,9 @@ ohos_unittest("TransUdpManagerTest") {
"$dsoftbus_root_path/core/connection/p2p/interface",
"$dsoftbus_root_path/core/connection/p2p/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/udp_negotiation/include",
"$dsoftbus_root_path/sdk/transmission/trans_channel/udp/common/include",
"$dsoftbus_root_path/core/transmission/ipc/include",
]
deps = [

View File

@ -36,6 +36,7 @@ ohos_unittest("SoftBusFrameStandardTest") {
"${dsoftbus_root_path}/sdk/transmission/session/include",
"${dsoftbus_root_path}/sdk/transmission/ipc/include",
"${dsoftbus_root_path}/sdk/transmission/trans_channel/manager/include",
"${dsoftbus_root_path}/sdk/transmission/trans_channel/udp/common/include",
]
deps = [