X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=cache.h;h=3b4eef656a11129b82a25c88b8f39dab9444400e;hb=96c58e8ba51d67d1d90660ba8ff4f597c03688fe;hp=7f7d0bdc3bcd87d1f01c993919946957bb6e79ac;hpb=f0f4bb0c37eeed71934e3191cffa5afb1cfdca0d;p=catta diff --git a/cache.h b/cache.h index 7f7d0bd..3b4eef6 100644 --- a/cache.h +++ b/cache.h @@ -9,18 +9,20 @@ typedef struct _flxCache flxCache; #include "prioq.h" #include "server.h" #include "llist.h" +#include "timeeventq.h" typedef enum { FLX_CACHE_VALID, FLX_CACHE_EXPIRY1, FLX_CACHE_EXPIRY2, - FLX_CACHE_EXPIRY3 - + FLX_CACHE_EXPIRY3, + FLX_CACHE_FINAL } flxCacheEntryState; typedef struct flxCacheEntry flxCacheEntry; struct flxCacheEntry { + flxCache *cache; flxRecord *record; GTimeVal timestamp; GTimeVal expiry; @@ -28,11 +30,10 @@ struct flxCacheEntry { flxAddress origin; flxCacheEntryState state; + flxTimeEvent *time_event; - FLX_LLIST_FIELDS(flxCacheEntry, by_name); - - flxPrioQueueNode *node; - + FLX_LLIST_FIELDS(flxCacheEntry, by_key); + FLX_LLIST_FIELDS(flxCacheEntry, entry); }; struct _flxCache { @@ -41,6 +42,8 @@ struct _flxCache { flxInterface *interface; GHashTable *hash_table; + + FLX_LLIST_HEAD(flxCacheEntry, entries); }; flxCache *flx_cache_new(flxServer *server, flxInterface *interface); @@ -49,11 +52,15 @@ void flx_cache_free(flxCache *c); flxCacheEntry *flx_cache_lookup_key(flxCache *c, flxKey *k); flxCacheEntry *flx_cache_lookup_record(flxCache *c, flxRecord *r); -flxCacheEntry *flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a); +void flx_cache_update(flxCache *c, flxRecord *r, gboolean unique, const flxAddress *a); -void flx_cache_drop_key(flxCache *c, flxKey *k); void flx_cache_drop_record(flxCache *c, flxRecord *r); void flx_cache_dump(flxCache *c, FILE *f); +typedef gpointer flxCacheWalkCallback(flxCache *c, flxKey *pattern, flxCacheEntry *e, gpointer userdata); +gpointer flx_cache_walk(flxCache *c, flxKey *pattern, flxCacheWalkCallback cb, gpointer userdata); + +gboolean flx_cache_entry_half_ttl(flxCache *c, flxCacheEntry *e); + #endif