#include "gnunet_statistics_service.h"
#include "gnunet_datacache_plugin.h"
+#define DEBUG_DATACACHE GNUNET_EXTRA_LOGGING
+
+#define LOG(kind,...) GNUNET_log_from (kind, "datacache", __VA_ARGS__)
+
+#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache", op, fn)
+
/**
* Internal state of the datacache library.
*/
{
struct GNUNET_DATACACHE_Handle *h = cls;
+#if DEBUG_DATACACHE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Content under key `%s' discarded\n",
+ GNUNET_h2s (key));
+#endif
GNUNET_assert (h->utilization >= size);
h->utilization -= size;
GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
char *name;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", "a))
+ GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", "a))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"), "QUOTA",
- section);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"), "QUOTA", section);
return NULL;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
- section);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
+ section);
return NULL;
}
bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name, quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
5);
}
- else
+ if (NULL == ret->filter)
{
ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
}
+ if (NULL == ret->filter)
+ {
+ GNUNET_free (name);
+ GNUNET_free (ret->bloom_name);
+ GNUNET_free (ret);
+ return NULL;
+ }
ret->stats = GNUNET_STATISTICS_create ("datacache", cfg);
ret->section = GNUNET_strdup (section);
ret->env.cfg = cfg;
ret->env.cls = ret;
ret->env.delete_notify = &env_delete_notify;
ret->env.quota = quota;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datacache plugin\n"),
- name);
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datacache plugin\n"), name);
GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
ret->short_name = name;
ret->lib_name = libname;
ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (ret->api == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datacache plugin for `%s'\n"), name);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load datacache plugin for `%s'\n"), name);
GNUNET_DATACACHE_destroy (ret);
return NULL;
}
if (h->bloom_name != NULL)
{
if (0 != UNLINK (h->bloom_name))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
- h->bloom_name);
+ GNUNET_log_from_strerror_file (GNUNET_ERROR_TYPE_WARNING, "datacache",
+ "unlink", h->bloom_name);
GNUNET_free (h->bloom_name);
}
GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
GNUNET_break (0);
return GNUNET_SYSERR;
}
+#if DEBUG_DATACACHE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Stored data under key `%s' in cache\n",
+ GNUNET_h2s (key));
+#endif
GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size,
GNUNET_NO);
GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
while (h->utilization + used > h->env.quota)
- GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
+ GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
h->utilization += used;
return GNUNET_OK;
}
{
GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1,
GNUNET_NO);
+#if DEBUG_DATACACHE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for key `%s'\n",
+ GNUNET_h2s (key));
+#endif
if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
{
GNUNET_STATISTICS_update (h->stats,
gettext_noop
("# requests filtered by bloom filter"), 1,
GNUNET_NO);
+#if DEBUG_DATACACHE
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Bloomfilter filters request for key `%s'\n",
+ GNUNET_h2s (key));
+#endif
return 0; /* can not be present */
}
return h->api->get (h->api->cls, key, type, iter, iter_cls);