mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-03 00:15:49 +03:00
coap_cache: initial caching code
This commit is contained in:
1 parent
e0a6593728
commit
0b142f9eda
6 files changed
+205
No files matched your search
@@ -40,6 +40,7 @@ extern "C" {
|
||||
#include "async.h"
|
||||
#include "bits.h"
|
||||
#include "block.h"
|
||||
#include "coap_cache.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_event.h"
|
||||
#include "coap_io.h"
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* coap_cache.h -- Caching of CoAP requests
|
||||
*
|
||||
* Copyright (C) 2020 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_cache.h
|
||||
* @brief Provides a simple request storage for CoAP requests
|
||||
*/
|
||||
|
||||
#ifndef COAP_CACHE_H_
|
||||
#define COAP_CACHE_H_
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
|
||||
typedef enum {
|
||||
COAP_CACHE_INVALID=-1,
|
||||
COAP_CACHE_MAXKEY=INT_MAX
|
||||
} coap_cache_key_t;
|
||||
|
||||
/**
|
||||
* Calculates a cache key for the given CoAP PDU. See
|
||||
* https://tools.ietf.org/html/rfc7252#section-5.6
|
||||
* for an explanation of CoAP cache keys.
|
||||
*
|
||||
* @param pdu The CoAP PDU for which a cache key is to be
|
||||
* calculated.
|
||||
*
|
||||
* @return The calculcated cache key.
|
||||
*/
|
||||
coap_cache_key_t coap_cache_key(const coap_pdu_t *pdu);
|
||||
|
||||
/**
|
||||
* Marks a request for permanent storage. The request may be retrieved
|
||||
* through its cache-key.
|
||||
*
|
||||
* @param ctx The context to use.
|
||||
* @param request The request to be stored.
|
||||
*
|
||||
* @return The cache key that corresponds to the newly stored
|
||||
* request or @c COAP_CACHE_INVALID if the request could
|
||||
* not be stored.
|
||||
*/
|
||||
coap_cache_key_t coap_cache_mark_request(coap_context_t *ctx,
|
||||
const coap_pdu_t *request);
|
||||
|
||||
/**
|
||||
* Clears a mark from a request.
|
||||
*
|
||||
* @param ctx The context to use.
|
||||
* @param cache_key The cache key for the request which can be
|
||||
* unmarked.
|
||||
*/
|
||||
void coap_cache_unmark_request(coap_context_t *ctx,
|
||||
coap_cache_key_t cache_key);
|
||||
|
||||
/**
|
||||
* Searches for a cache entry identified by @p cache_key. This
|
||||
* function returns the corresponding cache entry or @c NULL
|
||||
* if not found.
|
||||
*
|
||||
* @param ctx The context to use.
|
||||
* @param cache_key The cache key to look up.
|
||||
*
|
||||
* @return The cache entry for @p cache_key or @c NULL if not found.
|
||||
*/
|
||||
struct coap_cache_entry_t *coap_cache_lookup_key(coap_context_t *ctx,
|
||||
coap_cache_key_t cache_key);
|
||||
|
||||
/**
|
||||
* Searches for a cache entry corresponding to @p request. This
|
||||
* function returns the corresponding cache entry or @c NULL if not
|
||||
* found.
|
||||
*
|
||||
* @param ctx The context to use.
|
||||
* @param request The CoAP request to search for.
|
||||
*
|
||||
* @return The cache entry for @p request or @c NULL if not found.
|
||||
*/
|
||||
struct coap_cache_entry_t *coap_cache_lookup_request(coap_context_t *ctx,
|
||||
const coap_pdu_t *request);
|
||||
|
||||
|
||||
#endif /* COAP_CACHE_H */
|
||||
@@ -28,6 +28,7 @@ struct coap_queue_t;
|
||||
struct coap_session_t;
|
||||
struct coap_string_t;
|
||||
struct coap_subscription_t;
|
||||
struct coap_cache_entry_t;
|
||||
|
||||
/*
|
||||
* typedef all the structures that are defined in coap_*_internal.h
|
||||
|
||||
@@ -209,6 +209,7 @@ typedef struct coap_context_t {
|
||||
unsigned int csm_timeout; /**< Timeout for waiting for a CSM from the remote side. 0 means disabled. */
|
||||
int observe_pending; /**< Observe response pending */
|
||||
|
||||
struct coap_cache_entry_t *cache; /**< CoAP message cache */
|
||||
void *app; /**< application-specific data */
|
||||
#ifdef COAP_EPOLL_SUPPORT
|
||||
int epfd; /**< External FD for epoll */
|
||||
|
||||
Reference in new issue
Block a user