summaryrefslogtreecommitdiffstats
path: root/cache.h
blob: ec0e974ae3122c9908d94f801e12d941b45eae5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef foocachehfoo
#define foocachehfoo

#include <glib.h>

struct _flxCache;
typedef struct _flxCache flxCache;

#include "prioq.h"
#include "server.h"
#include "llist.h"

typedef enum {
    FLX_CACHE_VALID,
    FLX_CACHE_EXPIRY1,
    FLX_CACHE_EXPIRY2,
    FLX_CACHE_EXPIRY3
        
} flxCacheEntryState;

typedef struct flxCacheEntry flxCacheEntry;

struct flxCacheEntry {
    flxRecord *record;
    GTimeVal timestamp;
    GTimeVal expiry;
    
    flxAddress origin;

    flxCacheEntryState state;

    FLX_LLIST_FIELDS(flxCacheEntry, by_name);

    flxPrioQueueNode *node;
    
};

struct _flxCache {
    flxServer *server;
    flxInterface *interface;
    
    GHashTable *hash_table;
};

flxCache *flx_cache_new(flxServer *server, flxInterface *interface);
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_drop_key(flxCache *c, flxKey *k);
void flx_cache_drop_record(flxCache *c,  flxRecord *r);

#endif