mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-03 00:15:49 +03:00
coap_session.[hc]: make message id session-local
The message id in the CoAP header is used for reliability when transferring a CoAP PDU over a non-reliable transport protocol such as UDP. For message de-duplication, it is useful to have a monotonously increasing number space within a session. Therefore, the context-global value has been moved to coap_session_t. The function coap_new_message_id() now takes a coap_session_t object as its argument.
This commit is contained in:
1 parent
d7ebf14395
commit
5c079b72d9
6 files changed
+16
-9
No files matched your search
+4
-2
@@ -148,12 +148,13 @@ coap_new_request(coap_context_t *ctx,
|
||||
size_t length) {
|
||||
coap_pdu_t *pdu;
|
||||
coap_list_t *opt;
|
||||
(void)ctx;
|
||||
|
||||
if ( ! ( pdu = coap_new_pdu(session) ) )
|
||||
return NULL;
|
||||
|
||||
pdu->hdr->type = msgtype;
|
||||
pdu->hdr->id = coap_new_message_id(ctx);
|
||||
pdu->hdr->id = coap_new_message_id(session);
|
||||
pdu->hdr->code = m;
|
||||
|
||||
pdu->hdr->token_length = (uint16_t)the_token.length;
|
||||
@@ -190,11 +191,12 @@ clear_obs(coap_context_t *ctx, coap_session_t *session) {
|
||||
coap_list_t *option;
|
||||
coap_tid_t tid = COAP_INVALID_TID;
|
||||
unsigned char buf[2];
|
||||
(void)ctx;
|
||||
|
||||
/* create bare PDU w/o any option */
|
||||
pdu = coap_pdu_init(msgtype,
|
||||
COAP_REQUEST_GET,
|
||||
coap_new_message_id(ctx),
|
||||
coap_new_message_id(session),
|
||||
coap_session_max_pdu_size(session));
|
||||
|
||||
if (!pdu) {
|
||||
|
||||
@@ -266,7 +266,7 @@ check_async(coap_context_t *ctx,
|
||||
return;
|
||||
}
|
||||
|
||||
response->hdr->id = coap_new_message_id(ctx);
|
||||
response->hdr->id = coap_new_message_id(async->session);
|
||||
|
||||
if (async->tokenlen)
|
||||
coap_add_token(response, async->tokenlen, async->token);
|
||||
|
||||
@@ -60,6 +60,7 @@ typedef struct coap_session_t {
|
||||
struct coap_endpoint_t *endpoint; /**< session's endpoint */
|
||||
struct coap_context_t *context; /**< session's context */
|
||||
void *tls; /**< security parameters */
|
||||
uint16_t tx_mid; /**< the last message id that was used in this session */
|
||||
struct coap_queue_t *sendqueue; /**< list of messages waiting to be sent */
|
||||
coap_tick_t last_rx_tx;
|
||||
uint8_t *psk_identity;
|
||||
|
||||
+5
-5
@@ -215,13 +215,13 @@ void coap_context_set_psk( coap_context_t *ctx, const char *hint,
|
||||
*
|
||||
* @return Incremented message id in network byte order.
|
||||
*/
|
||||
COAP_STATIC_INLINE unsigned short
|
||||
coap_new_message_id(coap_context_t *context) {
|
||||
context->message_id++;
|
||||
COAP_STATIC_INLINE uint16_t
|
||||
coap_new_message_id(coap_session_t *session) {
|
||||
session->tx_mid++;
|
||||
#ifndef WITH_CONTIKI
|
||||
return htons(context->message_id);
|
||||
return htons(session->tx_mid);
|
||||
#else /* WITH_CONTIKI */
|
||||
return uip_htons(context->message_id);
|
||||
return uip_htons(session->tx_mid);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ coap_make_session(coap_proto_t proto, coap_session_type_t type, const coap_addre
|
||||
coap_log(LOG_ERR, "DTLS overhead exceeds MTU\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize message id */
|
||||
prng((unsigned char *)&session->tx_mid, sizeof(session->tx_mid));
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -679,7 +679,7 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
|
||||
token.length = obs->token_length;
|
||||
token.s = obs->token;
|
||||
|
||||
response->hdr->id = coap_new_message_id(context);
|
||||
response->hdr->id = coap_new_message_id(obs->session);
|
||||
if ((r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) == 0
|
||||
&& obs->non_cnt < COAP_OBS_MAX_NON) {
|
||||
response->hdr->type = COAP_MESSAGE_NON;
|
||||
|
||||
Reference in new issue
Block a user