BugID:16952646 :[alcs]add coap request receive flowcontrol with fixed trigger threshould
@@ -686,6 +686,9 @@ static int CoAPRespMessage_handle(CoAPContext *context, NetworkAddr *remote, CoA
return COAP_ERROR_NOT_FOUND;
}
+#define PACKET_INTERVAL_THRE_MS 800
+#define PACKET_TRIGGER_NUM 100
+
static int CoAPRequestMessage_handle(CoAPContext *context, NetworkAddr *remote, CoAPMessage *message)
{
int index = 0;
@@ -709,10 +712,36 @@ static int CoAPRequestMessage_handle(CoAPContext *context, NetworkAddr *remote,
}
COAP_DEBUG("Request path is %s", path);
+ /* CoAP request receive flowControl */
+ uint64_t time_curr = 0;
+ int64_t time_delta = 0;
+ int isOverThre = 0;
+ static uint64_t time_prev = 0;
+ static int count = 0;
+
+ time_curr = HAL_UptimeMs();
+ if (time_curr < time_prev) {
+ time_curr = time_prev;
+ }
+ time_delta = time_curr - time_prev;
+
+ if (time_delta < (uint64_t)PACKET_INTERVAL_THRE_MS) {
+ if (++count > PACKET_TRIGGER_NUM) {
+ count = PACKET_TRIGGER_NUM;
+ isOverThre = 1;
+ }
+ }
+ else {
+ time_prev = time_curr;
+
+ count -= (time_delta - PACKET_INTERVAL_THRE_MS) / PACKET_INTERVAL_THRE_MS;
+ count = (count < 0) ? 0: count;
+ }
+
resource = CoAPResourceByPath_get(ctx, (char *)path);
if (NULL != resource) {
if (NULL != resource->callback) {
- if (((resource->permission) & (1 << ((message->header.code) - 1))) > 0) {
+ if ((((resource->permission) & (1 << ((message->header.code) - 1))) > 0) && !isOverThre) {
resource->callback(ctx, (char *)path, remote, message);
} else {
COAP_INFO("The resource %s isn't allowed", resource->path);
