/*
This file is part of GNUnet
- (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
/**
- * @file datacache/datacache_api.c
+ * @file datacache/datacache.c
* @brief datacache API implementation
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_datacache_lib.h"
-#include "plugin_datacache.h"
+#include "gnunet_statistics_service.h"
+#include "gnunet_datacache_plugin.h"
/**
* Internal state of the datacache library.
struct GNUNET_DATACACHE_Handle
{
- /**
- * Our datastore plugin (NULL if not available).
- */
- struct DatastorePlugin *plugin;
-
/**
* Bloomfilter to quickly tell if we don't have the content.
*/
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
+ /**
+ * Opaque handle for the statistics service.
+ */
+ struct GNUNET_STATISTICS_Handle *stats;
+
/**
* Configuration section to use.
*/
static void
env_delete_notify (void *cls,
const GNUNET_HashCode *key,
- uint32_t size)
+ size_t size)
{
struct GNUNET_DATACACHE_Handle * h = cls;
GNUNET_assert (h->utilization >= size);
h->utilization -= size;
GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# bytes stored"),
+ -size,
+ GNUNET_NO);
}
/**
* Create a data cache.
*
- * @param sched scheduler to use
* @param cfg configuration to use
* @param section section in the configuration that contains our options
* @return handle to use to access the service
*/
struct GNUNET_DATACACHE_Handle *
-GNUNET_DATACACHE_create (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section)
{
unsigned int bf_size;
bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
ret = GNUNET_malloc (sizeof(struct GNUNET_DATACACHE_Handle));
- ret->bloom_name = GNUNET_DISK_mktemp ("datacachebloom");
-
- if (ret->bloom_name)
+ ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
+ if (NULL != ret->bloom_name)
{
ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name,
quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
{
ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
}
+ ret->stats = GNUNET_STATISTICS_create ("datacache",
+ cfg);
ret->section = GNUNET_strdup (section);
- ret->env.sched = sched;
ret->env.cfg = cfg;
ret->env.delete_notify = &env_delete_notify;
ret->env.section = ret->section;
h->bloom_name);
GNUNET_free (h->bloom_name);
}
+ GNUNET_STATISTICS_destroy (h->stats,
+ GNUNET_NO);
GNUNET_free (h);
}
int
GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
const GNUNET_HashCode * key,
- uint32_t size,
+ size_t size,
const char *data,
- unsigned int type,
+ enum GNUNET_BLOCK_Type type,
struct GNUNET_TIME_Absolute discard_time)
{
uint32_t used;
type,
discard_time);
if (used == 0)
- return GNUNET_SYSERR;
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ 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));
unsigned int
GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
const GNUNET_HashCode * key,
- unsigned int type,
+ enum GNUNET_BLOCK_Type type,
GNUNET_DATACACHE_Iterator iter,
void *iter_cls)
{
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# requests received"),
+ 1,
+ GNUNET_NO);
if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter,
key))
- return 0; /* can not be present */
+ {
+ GNUNET_STATISTICS_update (h->stats,
+ gettext_noop ("# requests filtered by bloom filter"),
+ 1,
+ GNUNET_NO);
+ return 0; /* can not be present */
+ }
return h->api->get (h->api->cls,
key,
type,