/*
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 "gnunet_statistics_service.h"
#include "plugin_datacache.h"
/**
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);
}
const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section)
{
- int fd;
unsigned int bf_size;
unsigned long long quota;
struct GNUNET_DATACACHE_Handle *ret;
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_strdup ("/tmp/datacachebloomXXXXXX");
- fd = mkstemp (ret->bloom_name);
- if (fd != -1)
+ 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 */
5);
- CLOSE (fd);
}
else
{
ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
}
+ ret->stats = GNUNET_STATISTICS_create (sched,
+ "datacache",
+ cfg);
ret->section = GNUNET_strdup (section);
ret->env.sched = sched;
ret->env.cfg = cfg;
GNUNET_free (h->section);
if (h->bloom_name != NULL)
{
- UNLINK (h->bloom_name);
+ if (0 != UNLINK (h->bloom_name))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink",
+ 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,