mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-02 02:47:09 +03:00
This change removes the need for applications having to know about handling requests for the next block etc. It also gives the application the ability to pass a large body of data to be transmitted and be told when this body is no longer required. This logic is enabled in libcoap by setting COAP_BLOCK_USE_LIBCOAP using coap_context_set_block_mode() This change breaks down into 4 specific areas 1) Client doing a PUT/POST etc. of a large amount of data (BLOCK1). coap_add_data_large_request() is used which provides a 'finished with data' callback function as well as adding required options to the PDUs. This function calls coap_add_data_large_internal(). Internal coap_handle_response_send_block() sends off the subsequent blocks (using session->lg_xmit). 2) Server receiving PUT/POST etc. of a large amount of data (BLOCK1). Internal coap_handle_request_get_block() acknowledges the appropriate blocks (using session->lg_srcv) and either passes in the individual blocks or the body depending on whether COAP_BLOCK_SINGLE_BODY is set or not using coap_context_set_block_mode(). 3) Server sending a large data response to GET / observe (BLOCK2) coap_add_data_large_response() is used which provides a 'finished with data' callback function. This function calls coap_add_data_large_internal() as well as filling in the necessary options for each PDU. Interal coap_handle_request_send_block() will then send the next requested block (using session->lg_xmit). 4) Client receiving a large data response (BLOCK2) coap_send_large() for the initial request sets this up. Internal coap_handle_response_get_block() will then request the next block when previous block received (using session->lg_crcv) and either passes the individual blocks or the body depending on COAP_BLOCK_SINGLE_BODY being set in coap_context_set_block_mode(). ---- The following new internal functions have been added coap_handle_request_get_block() coap_handle_request_send_block() coap_handle_response_get_block() coap_handle_response_send_block() coap_add_data_large_internal() The following new functions have been added. coap_add_data_large_request() coap_add_data_large_response() coap_context_set_block_mode() coap_get_data_large() coap_pdu_duplicate() coap_send_large() coap_session_init_token() coap_session_new_token() The coap_session_init_token() and coap_session_new_token() were added to make the handling of unique tokens for each request/response easier. https://datatracker.ietf.org/doc/html/draft-ietf-core-echo-request-tag-10#section-4 New files include/coap2/coap_block_internal.h: man/coap_block.txt.in: New memory types COAP_LG_XMIT COAP_LG_SRCV COAP_LG_CRCV
68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
/*
|
|
* coap_subscribe_internal.h -- Structures, Enums & Functions that are not
|
|
* exposed to application programming
|
|
*
|
|
* Copyright (C) 2010-2019 Olaf Bergmann <bergmann@tzi.org>
|
|
*
|
|
* This file is part of the CoAP library libcoap. Please see README for terms
|
|
* of use.
|
|
*/
|
|
|
|
/**
|
|
* @file coap_subscribe_internal.h
|
|
* @brief COAP subscribe internal information
|
|
*/
|
|
|
|
#ifndef COAP_SUBSCRIBE_INTERNAL_H_
|
|
#define COAP_SUBSCRIBE_INTERNAL_H_
|
|
|
|
/**
|
|
* @defgroup subscribe_internal Observe Subscription (Internal)
|
|
* CoAP Observe Subscription Structures, Enums and Functions that are not
|
|
* exposed to applications
|
|
* @{
|
|
*/
|
|
|
|
#ifndef COAP_OBS_MAX_NON
|
|
/**
|
|
* Number of notifications that may be sent non-confirmable before a confirmable
|
|
* message is sent to detect if observers are alive. The maximum allowed value
|
|
* here is @c 15.
|
|
*/
|
|
#define COAP_OBS_MAX_NON 5
|
|
#endif /* COAP_OBS_MAX_NON */
|
|
|
|
#ifndef COAP_OBS_MAX_FAIL
|
|
/**
|
|
* Number of confirmable notifications that may fail (i.e. time out without
|
|
* being ACKed) before an observer is removed. The maximum value for
|
|
* COAP_OBS_MAX_FAIL is @c 3.
|
|
*/
|
|
#define COAP_OBS_MAX_FAIL 3
|
|
#endif /* COAP_OBS_MAX_FAIL */
|
|
|
|
/** Subscriber information */
|
|
struct coap_subscription_t {
|
|
struct coap_subscription_t *next; /**< next element in linked list */
|
|
struct coap_session_t *session; /**< subscriber session */
|
|
|
|
unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */
|
|
unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */
|
|
unsigned int dirty:1; /**< set if the notification temporarily could not be
|
|
* sent (in that case, the resource's partially
|
|
* dirty flag is set too) */
|
|
unsigned int has_block2:1; /**< request had Block2 definition */
|
|
uint8_t code; /** request type code (GET/FETCH)*/
|
|
coap_block_t block; /**< GET/FETCH request Block definition */
|
|
uint16_t tid; /**< transaction id, if any, in regular host byte order */
|
|
size_t token_length; /**< actual length of token */
|
|
unsigned char token[8]; /**< token used for subscription */
|
|
struct coap_string_t *query; /**< query string used for subscription, if any */
|
|
};
|
|
|
|
void coap_subscription_init(coap_subscription_t *);
|
|
|
|
/** @} */
|
|
|
|
#endif /* COAP_SUBSCRIBE_INTERNAL_H_ */
|