mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-06 17:52:54 +03:00
mid_duplicates: Drop general responses duplicates
This commit is contained in:
1 parent
dc92fe5e1e
commit
8c973a454e
3 files changed
+23
No files matched your search
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in new issue
Block a user