!8410 make timeout config works for unicast. for internal auto-reply unicast, make its type to NON-confirmable

Merge pull request !8410 from wanghan985406/master
This commit is contained in:
openharmony_ci 2024-11-20 06:55:33 +00:00 committed by Gitee
commit 9292eca2b3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 13 additions and 9 deletions

View File

@ -288,6 +288,7 @@ static coap_session_t *CoapGetSessionEx(coap_context_t *ctx, const char *localAd
/* reuse the existed session */
session = coap_session_get_by_peer(ctx, dst, 0);
if (session != NULL) {
CoapSetAckTimeOut(session);
(void)coap_session_reference(session);
return session;
}

View File

@ -224,7 +224,11 @@ static int32_t CoapResponseService(CoapCtxType *ctx, const char *remoteUrl, uint
return NSTACKX_EFAILED;
}
int ret = CoapSendRequest(ctx, COAP_MESSAGE_CON, remoteUrl, data, strlen(data) + 1);
// for internal auto-reply unicast, make its type to NON-confirmable
// reliablity depends on the number of broadcast
uint8_t coapMsgType = (ShouldAutoReplyUnicast(businessType) == NSTACKX_TRUE) ? COAP_MESSAGE_NON : COAP_MESSAGE_CON;
int32_t ret = CoapSendRequest(ctx, coapMsgType, remoteUrl, data, strlen(data) + 1);
cJSON_free(data);
return ret;
}
@ -274,7 +278,7 @@ static void CoapResponseServiceDiscovery(const char *remoteUrl, const coap_conte
coap_pdu_t *response, uint8_t businessType)
{
if (remoteUrl != NULL) {
if (CheckBusinessTypeReplyUnicast(businessType) == NSTACKX_EOK) {
if (ShouldAutoReplyUnicast(businessType) == NSTACKX_TRUE) {
CoapCtxType *ctx = CoapGetCoapCtxType(currCtx);
if (ctx != NULL) {
(void)CoapResponseService(ctx, remoteUrl, businessType);

View File

@ -133,7 +133,7 @@ static void CoapResponseServiceDiscovery(const char *remoteUrl, const CoapPacket
(void)inet_ntop(AF_INET, ip, wifiIpAddr, sizeof(wifiIpAddr));
GetBuildCoapParam(pkt, remoteUrl, wifiIpAddr, &param);
if (remoteUrl != NULL) {
if (CheckBusinessTypeReplyUnicast(businessType) == NSTACKX_EOK) {
if (ShouldAutoReplyUnicast(businessType) == NSTACKX_TRUE) {
(void)CoapSendMessage(&param, NSTACKX_FALSE, businessType, false);
}
} else {

View File

@ -120,18 +120,18 @@ void NotifyDFinderMsgRecver(DFinderMsgType msgType)
}
}
int32_t CheckBusinessTypeReplyUnicast(uint8_t businessType)
int32_t ShouldAutoReplyUnicast(uint8_t businessType)
{
switch (businessType) {
case NSTACKX_BUSINESS_TYPE_SOFTBUS:
case NSTACKX_BUSINESS_TYPE_AUTONET:
case NSTACKX_BUSINESS_TYPE_STRATEGY:
return NSTACKX_EFAILED;
return NSTACKX_FALSE;
case NSTACKX_BUSINESS_TYPE_NULL:
case NSTACKX_BUSINESS_TYPE_HICOM:
case NSTACKX_BUSINESS_TYPE_NEARBY:
default:
return NSTACKX_EOK;
return NSTACKX_TRUE;
}
}

View File

@ -123,8 +123,7 @@ static int32_t UpdateDeviceDbInDeviceList(const CoapCtxType *coapCtx, const Devi
DFINDER_LOGE(TAG, "update remote node by deviceinfo failed");
return NSTACKX_EFAILED;
}
// for non-automatic reply businessType, report each unicast received, even if the content is same
if (!receiveBcast && (CheckBusinessTypeReplyUnicast(deviceInfo->businessType) != NSTACKX_EOK)) {
if (!receiveBcast && (ShouldAutoReplyUnicast(deviceInfo->businessType) != NSTACKX_TRUE)) {
return updated ? DeviceInfoNotify(deviceInfo) : NSTACKX_EOK;
}
if (updated || forceUpdate) {

View File

@ -52,7 +52,7 @@ void NotifyDFinderMsgRecver(DFinderMsgType msgType);
EpollDesc GetMainLoopEpollFd(void);
List *GetMainLoopEvendChain(void);
uint32_t GetDefaultDiscoverInterval(uint32_t discoverCount);
int32_t CheckBusinessTypeReplyUnicast(uint8_t businessType);
int32_t ShouldAutoReplyUnicast(uint8_t businessType);
int32_t GetServiceDiscoverInfo(const uint8_t *buf, size_t size, struct DeviceInfo *deviceInfo, char **remoteUrlPtr);
int32_t GetServiceNotificationInfo(const uint8_t *buf, size_t size, NSTACKX_NotificationConfig *notification);
List *GetEventNodeChain(void);