mid_duplicates: Drop general responses duplicates

This commit is contained in:
Jon Shallow authored and mrdeep1 committed 2022-07-08 15:59:13 +01:00
1 parent dc92fe5e1e
commit 8c973a454e
3 files changed
+23

No files matched your search

+4
View File
@@ -149,6 +149,10 @@ struct coap_session_t {
uint64_t tx_token; /**< Next token number to use */
coap_bin_const_t *last_token; /** last token used to make a request */
coap_bin_const_t *echo; /**< Echo value to send with next request */
coap_mid_t last_ack_mid; /**< The last ACK mid that has been
been processed */
coap_mid_t last_con_mid; /**< The last CON mid that has been
been processed */
};
#if COAP_SERVER_SUPPORT
+2
View File
@@ -209,6 +209,8 @@ coap_make_session(coap_proto_t proto, coap_session_type_t type,
session->probing_rate = COAP_DEFAULT_PROBING_RATE;
session->dtls_event = -1;
session->last_ping_mid = COAP_INVALID_MID;
session->last_ack_mid = COAP_INVALID_MID;
session->last_con_mid = COAP_INVALID_MID;
/* Randomly initialize */
coap_prng((unsigned char *)&session->tx_mid, sizeof(session->tx_mid));
+17
View File
@@ -3033,6 +3033,23 @@ handle_response(coap_context_t *context, coap_session_t *session,
if (rcvd->type != COAP_MESSAGE_ACK)
coap_cancel_all_messages(context, session, rcvd->token, rcvd->token_length);
/* Check for message duplication */
if (COAP_PROTO_NOT_RELIABLE(session->proto)) {
if (rcvd->type == COAP_MESSAGE_CON) {
if (rcvd->mid == session->last_con_mid) {
/* Duplicate response */
return;
}
session->last_con_mid = rcvd->mid;
} else if (rcvd->type == COAP_MESSAGE_ACK) {
if (rcvd->mid == session->last_ack_mid) {
/* Duplicate response */
return;
}
session->last_ack_mid = rcvd->mid;
}
}
if (session->block_mode & COAP_BLOCK_USE_LIBCOAP) {
/* See if need to send next block to server */
if (coap_handle_response_send_block(session, sent, rcvd)) {