diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-11-25 13:03:37 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-11-25 13:03:37 +0000 |
commit | d4350788eea01f04b464d382d74ee0f391a78398 (patch) | |
tree | 908e24ce99ea465b9cd05ea15d61b702c1b883cb /src/include | |
parent | 922841847862b39662b1039304de1361401f214b (diff) | |
download | s6-dns-d4350788eea01f04b464d382d74ee0f391a78398.tar.xz |
Initial libdcache implementation
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/s6-dns/dcache.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/include/s6-dns/dcache.h b/src/include/s6-dns/dcache.h new file mode 100644 index 0000000..59e78c0 --- /dev/null +++ b/src/include/s6-dns/dcache.h @@ -0,0 +1,53 @@ +/* ISC license. */ + +#ifndef S6DNS_DCACHE_H +#define S6DNS_DCACHE_H + +#include <stdint.h> + +#include <skalibs/uint64.h> +#include <skalibs/tai.h> +#include <skalibs/gensetdyn.h> +#include <skalibs/avltree.h> + +#define DCACHE_MAGIC "--DCACHE--\n" + +typedef struct dcache_key_s dcache_key_t, *dcache_key_t_ref ; +struct dcache_key_s +{ + char *s ; + uint16_t len ; +} ; + +typedef struct dcache_node_s dcache_node_t, *dcache_node_t_ref ; +struct dcache_node_s +{ + dcache_key_t key ; + uint16_t datalen ; + tain_t entry ; + tain_t expire ; +} ; + +typedef struct dcache_s dcache_t, *dcache_t_ref ; +struct dcache_s +{ + gensetdyn storage ; /* dcache_node_t */ + avltree by_key ; + avltree by_entry ; + avltree by_expire ; + uint64_t size ; + uint64_t motion ; +} ; +#define DCACHE_ZERO { .storage = GENSETDYN_ZERO, .by_key = AVLTREE_ZERO, .by_entry = AVLTREE_ZERO, .by_expire = AVLTREE_ZERO, .size = 0, .motion = 0 } + +extern void dcache_init (dcache_t *, uint64_t) ; +extern dcache_node_t *dcache_search (dcache_t *, char const *, uint16_t) ; +extern int dcache_add (dcache_t *, uint64_t, char const *, uint16_t, char const *, uint16_t, tain_t const *, tain_t const *) ; +#define dcache_add_g(d, max, key, keylen, data, datalen, expire) dcache_add(d, max, key, keylen, data, datalen, (expire), &STAMP) +extern void dcache_free (dcache_t *) ; + +extern int dcache_save (dcache_t const *, char const *) ; +extern int dcache_load (dcache_t *, uint64_t, char const *) ; + + +#endif |