mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-15 12:44:55 +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
116 lines
3.6 KiB
C
116 lines
3.6 KiB
C
/*
|
|
* This file is part of the CoAP library libcoap. Please see README for terms
|
|
* of use.
|
|
*/
|
|
|
|
/* Memory pool definitions for the libcoap when used with lwIP (which has its
|
|
* own mechanism for quickly allocating chunks of data with known sizes). Has
|
|
* to be findable by lwIP (ie. an #include <lwippools.h> must either directly
|
|
* include this or include something more generic which includes this), and
|
|
* MEMP_USE_CUSTOM_POOLS has to be set in lwipopts.h. */
|
|
|
|
#include "coap_internal.h"
|
|
#include <net.h>
|
|
#include <resource.h>
|
|
#include <subscribe.h>
|
|
|
|
#ifndef MEMP_NUM_COAPCONTEXT
|
|
#define MEMP_NUM_COAPCONTEXT 1
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPENDPOINT
|
|
#define MEMP_NUM_COAPENDPOINT 1
|
|
#endif
|
|
|
|
/* 1 is sufficient as this is very short-lived */
|
|
#ifndef MEMP_NUM_COAPPACKET
|
|
#define MEMP_NUM_COAPPACKET 1
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPNODE
|
|
#define MEMP_NUM_COAPNODE 4
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPPDU
|
|
#define MEMP_NUM_COAPPDU MEMP_NUM_COAPNODE
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPSESSION
|
|
#define MEMP_NUM_COAPSESSION 2
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAP_SUBSCRIPTION
|
|
#define MEMP_NUM_COAP_SUBSCRIPTION 4
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPRESOURCE
|
|
#define MEMP_NUM_COAPRESOURCE 10
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPRESOURCEATTR
|
|
#define MEMP_NUM_COAPRESOURCEATTR 20
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPOPTLIST
|
|
#define MEMP_NUM_COAPOPTLIST 1
|
|
#endif
|
|
|
|
#ifndef MEMP_LEN_COAPOPTLIST
|
|
#define MEMP_LEN_COAPOPTLIST 12
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPSTRING
|
|
#define MEMP_NUM_COAPSTRING 10
|
|
#endif
|
|
|
|
#ifndef MEMP_LEN_COAPSTRING
|
|
#define MEMP_LEN_COAPSTRING 32
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPCACHE_KEYS
|
|
#define MEMP_NUM_COAPCACHE_KEYS (2U)
|
|
#endif /* MEMP_NUM_COAPCACHE_KEYS */
|
|
|
|
#ifndef MEMP_NUM_COAPCACHE_ENTRIES
|
|
#define MEMP_NUM_COAPCACHE_ENTRIES (2U)
|
|
#endif /* MEMP_NUM_COAPCACHE_ENTRIES */
|
|
|
|
#ifndef MEMP_NUM_COAPPDUBUF
|
|
#define MEMP_NUM_COAPPDUBUF 2
|
|
#endif
|
|
|
|
#ifndef MEMP_LEN_COAPPDUBUF
|
|
#define MEMP_LEN_COAPPDUBUF 32
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPLGXMIT
|
|
#define MEMP_NUM_COAPLGXMIT 2
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPLGCRCV
|
|
#define MEMP_NUM_COAPLGCRCV 2
|
|
#endif
|
|
|
|
#ifndef MEMP_NUM_COAPLGSRCV
|
|
#define MEMP_NUM_COAPLGSRCV 2
|
|
#endif
|
|
|
|
LWIP_MEMPOOL(COAP_CONTEXT, MEMP_NUM_COAPCONTEXT, sizeof(coap_context_t), "COAP_CONTEXT")
|
|
LWIP_MEMPOOL(COAP_ENDPOINT, MEMP_NUM_COAPENDPOINT, sizeof(coap_endpoint_t), "COAP_ENDPOINT")
|
|
LWIP_MEMPOOL(COAP_PACKET, MEMP_NUM_COAPPACKET, sizeof(coap_packet_t), "COAP_PACKET")
|
|
LWIP_MEMPOOL(COAP_NODE, MEMP_NUM_COAPNODE, sizeof(coap_queue_t), "COAP_NODE")
|
|
LWIP_MEMPOOL(COAP_PDU, MEMP_NUM_COAPPDU, sizeof(coap_pdu_t), "COAP_PDU")
|
|
LWIP_MEMPOOL(COAP_SESSION, MEMP_NUM_COAPSESSION, sizeof(coap_session_t), "COAP_SESSION")
|
|
LWIP_MEMPOOL(COAP_subscription, MEMP_NUM_COAP_SUBSCRIPTION, sizeof(coap_subscription_t), "COAP_subscription")
|
|
LWIP_MEMPOOL(COAP_RESOURCE, MEMP_NUM_COAPRESOURCE, sizeof(coap_resource_t), "COAP_RESOURCE")
|
|
LWIP_MEMPOOL(COAP_RESOURCEATTR, MEMP_NUM_COAPRESOURCEATTR, sizeof(coap_attr_t), "COAP_RESOURCEATTR")
|
|
LWIP_MEMPOOL(COAP_OPTLIST, MEMP_NUM_COAPOPTLIST, sizeof(coap_optlist_t)+MEMP_LEN_COAPOPTLIST, "COAP_OPTLIST")
|
|
LWIP_MEMPOOL(COAP_STRING, MEMP_NUM_COAPSTRING, sizeof(coap_string_t)+MEMP_LEN_COAPSTRING, "COAP_STRING")
|
|
LWIP_MEMPOOL(COAP_CACHE_KEY, MEMP_NUM_COAPCACHE_KEYS, sizeof(coap_cache_key_t), "COAP_CACHE_KEY")
|
|
LWIP_MEMPOOL(COAP_CACHE_ENTRY, MEMP_NUM_COAPCACHE_ENTRIES, sizeof(coap_cache_entry_t), "COAP_CACHE_ENTRY")
|
|
LWIP_MEMPOOL(COAP_PDU_BUF, MEMP_NUM_COAPPDUBUF, MEMP_LEN_COAPPDUBUF, "COAP_PDU_BUF")
|
|
LWIP_MEMPOOL(COAP_LG_XMIT, MEMP_NUM_COAPLGXMIT, sizeof(coap_lg_xmit_t), "COAP_LG_XMIT")
|
|
LWIP_MEMPOOL(COAP_LG_CRCV, MEMP_NUM_COAPLGCRCV, sizeof(coap_lg_crcv_t), "COAP_LG_CRCV")
|
|
LWIP_MEMPOOL(COAP_LG_SRCV, MEMP_NUM_COAPLGSRCV, sizeof(coap_lg_srcv_t), "COAP_LG_SRCV")
|
|
|