]> git.meshlink.io Git - catta/blob - cache.h
* add announcing/goodbye
[catta] / cache.h
1 #ifndef foocachehfoo
2 #define foocachehfoo
3
4 #include <glib.h>
5
6 struct _flxCache;
7 typedef struct _flxCache flxCache;
8
9 #include "prioq.h"
10 #include "server.h"
11 #include "llist.h"
12 #include "timeeventq.h"
13
14 typedef enum {
15     FLX_CACHE_VALID,
16     FLX_CACHE_EXPIRY1,
17     FLX_CACHE_EXPIRY2,
18     FLX_CACHE_EXPIRY3,
19     FLX_CACHE_FINAL
20 } flxCacheEntryState;
21
22 typedef struct flxCacheEntry flxCacheEntry;
23
24 struct flxCacheEntry {
25     flxCache *cache;
26     flxRecord *record;
27     GTimeVal timestamp;
28     GTimeVal expiry;
29     
30     flxAddress origin;
31
32     flxCacheEntryState state;
33     flxTimeEvent *time_event;
34
35     FLX_LLIST_FIELDS(flxCacheEntry, by_name);
36     
37 };
38
39 struct _flxCache {
40     flxServer *server;
41     
42     flxInterface *interface;
43     
44     GHashTable *hash_table;
45 };
46
47 flxCache *flx_cache_new(flxServer *server, flxInterface *interface);
48 void flx_cache_free(flxCache *c);
49
50 flxCacheEntry *flx_cache_lookup_key(flxCache *c, flxKey *k);
51 flxCacheEntry *flx_cache_lookup_record(flxCache *c, flxRecord *r);
52
53 flxCacheEntry *flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a);
54
55 void flx_cache_drop_key(flxCache *c, flxKey *k);
56 void flx_cache_drop_record(flxCache *c,  flxRecord *r);
57
58 void flx_cache_dump(flxCache *c, FILE *f);
59
60 #endif