]> git.meshlink.io Git - catta/blob - src/cache.h
rename everything avahi to catta
[catta] / src / cache.h
1 #ifndef foocachehfoo
2 #define foocachehfoo
3
4 /***
5   This file is part of catta.
6
7   catta is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as
9   published by the Free Software Foundation; either version 2.1 of the
10   License, or (at your option) any later version.
11
12   catta is distributed in the hope that it will be useful, but WITHOUT
13   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15   Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public
18   License along with catta; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20   USA.
21 ***/
22
23 typedef struct CattaCache CattaCache;
24
25 #include <catta/llist.h>
26 #include "prioq.h"
27 #include "internal.h"
28 #include "timeeventq.h"
29 #include "hashmap.h"
30
31 typedef enum {
32     CATTA_CACHE_VALID,
33     CATTA_CACHE_EXPIRY1,
34     CATTA_CACHE_EXPIRY2,
35     CATTA_CACHE_EXPIRY3,
36     CATTA_CACHE_EXPIRY_FINAL,
37     CATTA_CACHE_POOF,       /* Passive observation of failure */
38     CATTA_CACHE_POOF_FINAL,
39     CATTA_CACHE_GOODBYE_FINAL,
40     CATTA_CACHE_REPLACE_FINAL
41 } CattaCacheEntryState;
42
43 typedef struct CattaCacheEntry CattaCacheEntry;
44
45 struct CattaCacheEntry {
46     CattaCache *cache;
47     CattaRecord *record;
48     struct timeval timestamp;
49     struct timeval poof_timestamp;
50     struct timeval expiry;
51     int cache_flush;
52     int poof_num;
53
54     CattaAddress origin;
55
56     CattaCacheEntryState state;
57     CattaTimeEvent *time_event;
58
59     CattaAddress poof_address;
60
61     CATTA_LLIST_FIELDS(CattaCacheEntry, by_key);
62     CATTA_LLIST_FIELDS(CattaCacheEntry, entry);
63 };
64
65 struct CattaCache {
66     CattaServer *server;
67
68     CattaInterface *interface;
69
70     CattaHashmap *hashmap;
71
72     CATTA_LLIST_HEAD(CattaCacheEntry, entries);
73
74     unsigned n_entries;
75
76     int last_rand;
77     time_t last_rand_timestamp;
78 };
79
80 CattaCache *catta_cache_new(CattaServer *server, CattaInterface *interface);
81 void catta_cache_free(CattaCache *c);
82
83 void catta_cache_update(CattaCache *c, CattaRecord *r, int cache_flush, const CattaAddress *a);
84
85 int catta_cache_dump(CattaCache *c, CattaDumpCallback callback, void* userdata);
86
87 typedef void* CattaCacheWalkCallback(CattaCache *c, CattaKey *pattern, CattaCacheEntry *e, void* userdata);
88 void* catta_cache_walk(CattaCache *c, CattaKey *pattern, CattaCacheWalkCallback cb, void* userdata);
89
90 int catta_cache_entry_half_ttl(CattaCache *c, CattaCacheEntry *e);
91
92 /** Start the "Passive observation of Failure" algorithm for all
93  * records of the specified key. The specified address is  */
94 void catta_cache_start_poof(CattaCache *c, CattaKey *key, const CattaAddress *a);
95
96 /* Stop a previously started POOF algorithm for a record. (Used for response suppresions records */
97 void catta_cache_stop_poof(CattaCache *c, CattaRecord *record, const CattaAddress *a);
98
99 void catta_cache_flush(CattaCache *c);
100
101 #endif