40{
45
50
55
59 char *section;
60
66
70 char *short_name;
71
75 char *lib_name;
76
80 char *bloom_name;
81
86
90 unsigned long long utilization;
91};
92
93
102static void
106{
108
110 "Content under key `%s' discarded\n",
113 h->utilization -=
size;
116 "# bytes stored",
120 "# items stored",
121 -1,
123}
124
125
129{
130 unsigned int bf_size;
131 unsigned long long quota;
133 char *libname;
135
139 "QUOTA",
141 {
144 "QUOTA");
145 return NULL;
146 }
150 "DATABASE",
152 {
155 "DATABASE");
156 return NULL;
157 }
158 bf_size =
quota / 32;
159
161
165 "DISABLE_BF"))
166 {
170 "DISABLE_BF_RC"))
171 {
173 }
174 if (NULL !=
ret->bloom_name)
175 {
179 5);
180 }
181 if (NULL ==
ret->filter)
182 {
185 bf_size,
186 5);
187 }
188 }
194 ret->env.section =
ret->section;
199 "Loading `%s' datacache plugin\n",
202 "libgnunet_plugin_datacache_%s",
205 ret->lib_name = libname;
206
208 libname,
210 if (NULL ==
ret->api)
211 {
213 "Failed to load datacache plugin for `%s'\n",
216 return NULL;
217 }
219}
220
221
222void
224{
225 if (NULL !=
h->filter)
234 if (NULL !=
h->bloom_name)
235 {
236 if (0 != unlink (
h->bloom_name))
238 "datacache",
239 "unlink",
242 }
245}
246
247
250 uint32_t xor_distance,
252{
253 ssize_t used;
254
255 used =
h->api->put (
h->api->cls,
256 xor_distance,
257 block);
258 if (-1 == used)
259 {
262 }
263 if (0 == used)
264 {
265
267 }
269 "Stored data under key `%s' in cache\n",
271 if (NULL !=
h->filter)
275 "# bytes stored",
276 used,
279 "# items stored",
280 1,
282 while (
h->utilization + used >
h->env.quota)
284 h->api->del (
h->api->cls));
285 h->utilization += used;
287}
288
289
290unsigned int
295 void *iter_cls)
296{
298 "# requests received",
299 1,
302 "Processing request for key `%s'\n",
304 if ( (NULL !=
h->filter) &&
308 {
310 "# requests filtered by bloom filter",
311 1,
314 "Bloomfilter filters request for key `%s'\n",
316 return 0;
317 }
318 return h->api->get (
h->api->cls,
321 iter, iter_cls);
322}
323
324
325unsigned int
329 unsigned int num_results,
331 void *iter_cls)
332{
334 "# proximity search requests received",
335 1,
338 "Processing proximity search at `%s'\n",
340 return h->api->get_closest (
h->api->cls,
343 num_results,
344 iter,
345 iter_cls);
346}
347
348
349
struct GNUNET_MQ_Envelope * env
static void env_delete_notify(void *cls, const struct GNUNET_HashCode *key, size_t size)
Function called by plugins to notify the datacache about content deletions.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_HashCode key
The key used in the DHT.
static char * name
Name (label) of the records to list.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
static unsigned long long quota
How much space are we allowed to use?
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load(const char *filename, size_t size, unsigned int k)
Load a Bloom filter from a file.
void GNUNET_CONTAINER_bloomfilter_remove(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Remove an element from the filter.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data(const struct GNUNET_CONFIGURATION_Handle *cfg)
Return the project data associated with this configuration.
unsigned int GNUNET_DATACACHE_get(struct GNUNET_DATACACHE_Handle *h, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datacache.
enum GNUNET_GenericReturnValue GNUNET_DATACACHE_put(struct GNUNET_DATACACHE_Handle *h, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block)
Store an item in the datacache.
struct GNUNET_DATACACHE_Handle * GNUNET_DATACACHE_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a data cache.
enum GNUNET_GenericReturnValue(* GNUNET_DATACACHE_Iterator)(void *cls, const struct GNUNET_DATACACHE_Block *block)
An iterator over a set of items stored in the datacache.
void GNUNET_DATACACHE_destroy(struct GNUNET_DATACACHE_Handle *h)
Destroy a data cache (and free associated resources).
unsigned int GNUNET_DATACACHE_get_closest(struct GNUNET_DATACACHE_Handle *h, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_load(const struct GNUNET_OS_ProjectData *pd, const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static unsigned int size
Size of the "table".
Information about a block stored in the datacache.
struct GNUNET_HashCode key
Key of the block.
Internal state of the datacache library.
char * section
Configuration section to use.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
void * cls
Closure to use for callbacks.
struct returned by the initialization function of the plugin