]> git.meshlink.io Git - catta/blob - cache.h
add client part of probing
[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_key);
36     FLX_LLIST_FIELDS(flxCacheEntry, entry);
37 };
38
39 struct _flxCache {
40     flxServer *server;
41     
42     flxInterface *interface;
43     
44     GHashTable *hash_table;
45
46     FLX_LLIST_HEAD(flxCacheEntry, entries);
47 };
48
49 flxCache *flx_cache_new(flxServer *server, flxInterface *interface);
50 void flx_cache_free(flxCache *c);
51
52 flxCacheEntry *flx_cache_lookup_key(flxCache *c, flxKey *k);
53 flxCacheEntry *flx_cache_lookup_record(flxCache *c, flxRecord *r);
54
55 void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a);
56
57 void flx_cache_drop_record(flxCache *c,  flxRecord *r);
58
59 void flx_cache_dump(flxCache *c, FILE *f);
60
61 typedef gpointer flxCacheWalkCallback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata);
62 gpointer flx_cache_walk(flxCache *c, flxKey *pattern, flxCacheWalkCallback cb, gpointer userdata);
63
64 gboolean flx_cache_entry_half_ttl(flxCache *c, flxCacheEntry *e);
65
66 #endif