Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit b3c74e8

Browse files
authored
Merge pull request #635 from openweave/feature/CheckEventWithNotifySize
Add a check to drop a large event.
2 parents 953da4c + 3dcfbee commit b3c74e8

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

src/lib/core/WeaveError.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ bool FormatWeaveError(char * buf, uint16_t bufSize, int32_t err)
232232
case WEAVE_ERROR_SESSION_KEY_SUSPENDED : desc = "Session key suspended"; break;
233233
case WEAVE_ERROR_UNSUPPORTED_WIRELESS_REGULATORY_DOMAIN : desc = "Unsupported wireless regulatory domain"; break;
234234
case WEAVE_ERROR_UNSUPPORTED_WIRELESS_OPERATING_LOCATION : desc = "Unsupported wireless operating location"; break;
235+
case WEAVE_ERROR_WDM_EVENT_TOO_BIG : desc = "The WDM Event is too big to be successfully transmitted to a peer node"; break;
235236
}
236237
#endif // !WEAVE_CONFIG_SHORT_ERROR_STR
237238

src/lib/core/WeaveError.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,17 @@ typedef WEAVE_CONFIG_ERROR_TYPE WEAVE_ERROR;
17571757
*/
17581758
#define WEAVE_ERROR_UNSUPPORTED_WIRELESS_OPERATING_LOCATION _WEAVE_ERROR(185)
17591759

1760+
/**
1761+
* @def WEAVE_ERROR_WDM_EVENT_TOO_BIG
1762+
*
1763+
* @brief
1764+
* The specified event is too big to be successfully transmitted to a peer node,
1765+
* e.g., it exceeds the maximum WDM Notification message size
1766+
* limit.
1767+
*
1768+
*/
1769+
#define WEAVE_ERROR_WDM_EVENT_TOO_BIG _WEAVE_ERROR(186)
1770+
17601771

17611772
/**
17621773
* @}

src/lib/profiles/data-management/Current/LoggingManagement.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,8 @@ inline event_id_t LoggingManagement::LogEventPrivate(const EventSchema & inSchem
13141314
CircularEventBuffer * buffer = mEventBuffer;
13151315
do
13161316
{
1317+
VerifyOrExit((WDM_MAX_NOTIFICATION_SIZE - WDM_NOTIFY_REQUEST_META_INFO_BYTES_MAX) >= writer.GetLengthWritten(),
1318+
err = WEAVE_ERROR_WDM_EVENT_TOO_BIG);
13171319
VerifyOrExit(buffer->mBuffer.GetQueueSize() >= writer.GetLengthWritten(), err = WEAVE_ERROR_BUFFER_TOO_SMALL);
13181320
if (buffer->IsFinalDestinationForImportance(inSchema.mImportance))
13191321
break;
@@ -1329,6 +1331,7 @@ inline event_id_t LoggingManagement::LogEventPrivate(const EventSchema & inSchem
13291331
if (err != WEAVE_NO_ERROR)
13301332
{
13311333
mEventBuffer->mBuffer = checkpoint;
1334+
WeaveLogError(EventLogging, "Failed to log event for profile id: 0x%x (err: %d)", inSchema.mProfileId, err);
13321335
}
13331336
else if (inSchema.mImportance <= GetCurrentImportance(inSchema.mProfileId))
13341337
{

src/lib/profiles/data-management/Current/NotificationEngine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
#include <Weave/Profiles/data-management/TraitData.h>
3434
#include <Weave/Profiles/data-management/TraitCatalog.h>
3535

36+
// Reserve bytes that would account for additional formulation overhead
37+
// of a Notify Request(beyond the event and the data lists) containing
38+
// meta information, e.g., SubscriptionId, etc. This is a conservative
39+
// estimate that should serve as a loose upper bound, and help in bounding
40+
// the maximum size of a WDM event.
41+
#define WDM_NOTIFY_REQUEST_META_INFO_BYTES_MAX (64)
42+
3643
namespace nl {
3744
namespace Weave {
3845
namespace Profiles {

src/test-apps/TestErrorStr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ static int32_t sContext[] =
294294
WEAVE_ERROR_SESSION_KEY_SUSPENDED,
295295
WEAVE_ERROR_UNSUPPORTED_WIRELESS_REGULATORY_DOMAIN,
296296
WEAVE_ERROR_UNSUPPORTED_WIRELESS_OPERATING_LOCATION,
297+
WEAVE_ERROR_WDM_EVENT_TOO_BIG,
297298

298299
WEAVE_ERROR_TUNNEL_ROUTING_RESTRICTED,
299300

0 commit comments

Comments
 (0)