gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3852 - in GNUnet/src: applications/dht/module include


From: grothoff
Subject: [GNUnet-SVN] r3852 - in GNUnet/src: applications/dht/module include
Date: Sat, 2 Dec 2006 15:03:42 -0800 (PST)

Author: grothoff
Date: 2006-12-02 15:03:38 -0800 (Sat, 02 Dec 2006)
New Revision: 3852

Removed:
   GNUnet/src/applications/dht/module/datastore_dht_master.c
   GNUnet/src/applications/dht/module/datastore_dht_master.h
   GNUnet/src/applications/dht/module/datastore_memory.c
   GNUnet/src/include/gnunet_dht_datastore_memory.h
Modified:
   GNUnet/src/applications/dht/module/Makefile.am
   GNUnet/src/applications/dht/module/table.c
   GNUnet/src/include/Makefile.am
Log:
dht

Modified: GNUnet/src/applications/dht/module/Makefile.am
===================================================================
--- GNUnet/src/applications/dht/module/Makefile.am      2006-12-02 22:30:48 UTC 
(rev 3851)
+++ GNUnet/src/applications/dht/module/Makefile.am      2006-12-02 23:03:38 UTC 
(rev 3852)
@@ -5,14 +5,8 @@
 plugin_LTLIBRARIES = \
   libgnunetmodule_dht.la 
 
-lib_LTLIBRARIES = \
-  libgnunetdht_datastore_memory.la 
-
 libgnunetmodule_dht_la_SOURCES = \
-  dht.c \
-  datastore_dht_master.c \
-  datastore_dht_master.h \
-  cs.c 
+  table.c dstore.c 
 libgnunetmodule_dht_la_LIBADD = \
  $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
  $(top_builddir)/src/util/containers/libgnunetutil_containers.la \
@@ -22,26 +16,6 @@
 libgnunetmodule_dht_la_LDFLAGS = \
   -export-dynamic -avoid-version -module
 
-libgnunetdht_datastore_memory_la_SOURCES = \
-  datastore_memory.c 
-libgnunetdht_datastore_memory_la_LIBADD = \
- $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
- $(top_builddir)/src/util/libgnunetutil.la 
-libgnunetdht_datastore_memory_la_LDFLAGS = \
-  -export-dynamic -lm
 
 
-check_PROGRAMS = \
-  datastore_memory_test
 
-
-TESTS = $(check_PROGRAMS)
-
-datastore_memory_test_SOURCES = \
-  datastore_memory_test.c
-datastore_memory_test_LDADD = \
-  $(top_builddir)/src/applications/dht/module/libgnunetdht_datastore_memory.la 
\
-  $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
-  $(top_builddir)/src/util/libgnunetutil.la 
-
-

Deleted: GNUnet/src/applications/dht/module/datastore_dht_master.c
===================================================================
--- GNUnet/src/applications/dht/module/datastore_dht_master.c   2006-12-02 
22:30:48 UTC (rev 3851)
+++ GNUnet/src/applications/dht/module/datastore_dht_master.c   2006-12-02 
23:03:38 UTC (rev 3852)
@@ -1,427 +0,0 @@
- /*
-      This file is part of GNUnet
-      Copyright (C) 2004, 2005, 2006 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
-      by the Free Software Foundation; either version 2, or (at your
-      option) any later version.
-
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
-
-      You should have received a copy of the GNU General Public License
-      along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file applications/dht/module/datastore_dht_master.c
- * @brief provides the implementation of the
- * Blockstore API for the DHT master table; based on
- * datastore_memory.c.
- * @author Simo Viitanen, Christian Grothoff
- *
- *
- * The main difference between this datastore and the default
- * memory-datastore is that entries have a timestamp and are
- * timed-out after a certain time of inactivity.  Also,
- * duplicate entries are removed.<p>
- *
- * The priorities are ignored, except in get where
- * the priority is the maximum number of results to return.
- * The number of keys specified in a GET must always be one.
- */
-
-#include "platform.h"
-
-#include "gnunet_core.h"
-#include "gnunet_util_cron.h"
-#include "datastore_dht_master.h"
-
-typedef struct {
-  HashCode512 hash;
-  cron_t lastRefreshTime;
-} MasterEntry;
-
-/**
- * @brief datastructure for one entry in the table.
- */
-typedef struct HT_Entry_t {
-  struct HT_Entry_t * next;
-  HashCode512 key;
-  unsigned int count;
-  MasterEntry * values;
-} HT_Entry;
-
-/**
- * @brief the per-table data
- */
-typedef struct {
-  struct GE_Context * ectx;
-  struct MUTEX * lock;
-  struct CronManager * cron;
-  size_t max_memory;
-  HT_Entry * first;
-} MemoryDatastore;
-
-
-/**
- * Lookup an item in the datastore.
- *
- * @param key the value to lookup
- * @param prio is interpreted as the maximum number
- *  of results to return
- * @return number of results available, SYSERR on error
- */
-static int lookup(void * closure,
-                 unsigned int type,
-                 unsigned int prio,
-                 unsigned int keyCount,
-                 const HashCode512 * keys,
-                 DataProcessor resultCallback,
-                 void * resCallbackClosure) {
-  MemoryDatastore * ds = closure;
-  HT_Entry * pos;
-  int count;
-  int i;
-  DataContainer * data;
-
-  GE_ASSERT(ds->ectx, keyCount == 1);
-  if (ds == NULL)
-    return SYSERR;
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  while (pos != NULL) {
-    if (equalsHashCode512(&keys[0], &pos->key)) {
-      int * perm;
-
-      if (pos->count > prio)
-       count = prio;
-      else
-       count = pos->count;
-      if (count < pos->count)
-       perm = permute(WEAK, pos->count); /* randomize returned set! */
-      else
-       perm = NULL;
-
-      for (i=0;i<count;i++) {
-       int j;
-       if (perm == NULL)
-         j = i;
-       else
-         j = perm[i];
-       data = MALLOC(sizeof(DataContainer) +
-                     sizeof(HashCode512));
-       data->size = htonl(sizeof(DataContainer) +
-                          sizeof(HashCode512));
-       memcpy(&data[1],
-              &pos->values[j].hash,
-              sizeof(HashCode512));    
-       resultCallback(NULL,
-                      data,
-                      resCallbackClosure);
-       FREE(data);
-      }
-      FREENONNULL(perm);
-      MUTEX_UNLOCK(ds->lock);
-      return count;
-    }
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  return 0;
-}
-
-/**
- * Store an item in the datastore.
- *
- * @param key the key of the item
- * @param value the value to store, must be of size HashCode512 for
- *        the master table!
- * @return OK if the value could be stored, SYSERR if not,
- *         NO for out of space)
- */
-static int store(void * closure,
-                const HashCode512 * key,
-                const DataContainer * value,
-                unsigned int prio) {
-  MemoryDatastore * ds = (MemoryDatastore*) closure;
-  HT_Entry * pos;
-  int i;
-
-  if ( (ds == NULL) || (value == NULL) )
-    return SYSERR;
-  if (ntohl(value->size) - sizeof(DataContainer)
-      != sizeof(HashCode512))
-    return SYSERR;
-
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  while (pos != NULL) {
-    if (equalsHashCode512(key, &pos->key)) {
-      for (i=0;i<pos->count;i++)
-       if (equalsHashCode512(&pos->values[i].hash,
-                             (HashCode512*)&value[1])) {
-         pos->values[i].lastRefreshTime = get_time();
-         MUTEX_UNLOCK(ds->lock);
-         return OK; /* already present */
-       }
-      if (ds->max_memory < sizeof(MasterEntry)) {
-       MUTEX_UNLOCK(ds->lock);
-       return NO;
-      }
-      ds->max_memory -= sizeof(MasterEntry);
-      GROW(pos->values,
-          pos->count,
-          pos->count+1);
-      pos->values[pos->count-1].lastRefreshTime = get_time();
-      memcpy(&pos->values[pos->count-1].hash,
-            &value[1],
-            sizeof(HashCode512));
-      MUTEX_UNLOCK(ds->lock);
-      return OK;
-    } /* end key match */
-    pos = pos->next;
-  }
-  /* no key matched, create fresh entry */
-  if (ds->max_memory < sizeof(HT_Entry) + sizeof(MasterEntry)) {
-    MUTEX_UNLOCK(ds->lock);
-    return NO;
-  }
-  ds->max_memory -= sizeof(HT_Entry) + sizeof(MasterEntry);
-  pos = MALLOC(sizeof(HT_Entry));
-  pos->key = *key;
-  pos->count = 1;
-  pos->values = MALLOC(sizeof(MasterEntry));
-  memcpy(&pos->values[0].hash,
-        &value[1],
-        sizeof(HashCode512));
-  pos->values[0].lastRefreshTime = get_time();
-  pos->next = ds->first;
-  ds->first = pos;
-  MUTEX_UNLOCK(ds->lock);
-  return OK;
-}
-
-/**
- * Remove an item from the datastore.
- * @param key the key of the item
- * @param value the value to remove, NULL for all values of the key
- * @return OK if the value could be removed, SYSERR if not (i.e. not present)
- */
-static int ds_remove(void * closure,
-                    const HashCode512 * key,
-                    const DataContainer * value) {
-  MemoryDatastore * ds = (MemoryDatastore*) closure;
-  HT_Entry * pos;
-  HT_Entry * prev;
-  int i;
-
-  if (ds == NULL)
-    return SYSERR;
-  if ( (value != NULL) &&
-       (ntohl(value->size) - sizeof(DataContainer)
-       != sizeof(HashCode512)) )
-    return SYSERR;
-
-  MUTEX_LOCK(ds->lock);
-  prev = NULL;
-  pos = ds->first;
-  while (pos != NULL) {
-    if (equalsHashCode512(key, &pos->key)) {
-      if (value != NULL) {
-       for (i=0;i<pos->count;i++) {
-         if (0 == memcmp(&pos->values[i].hash,
-                         &value[1],
-                         sizeof(HashCode512))) {
-           pos->values[i] = pos->values[pos->count-1];
-           GROW(pos->values,
-                pos->count,
-                pos->count-1);
-           ds->max_memory += sizeof(MasterEntry);
-           if (pos->count == 0) {
-             if (prev == NULL)
-               ds->first = pos->next;
-             else
-               prev->next = pos->next;
-             FREE(pos);
-             ds->max_memory += sizeof(HT_Entry);       
-           }
-           MUTEX_UNLOCK(ds->lock);
-           return OK;
-         }
-       }
-      } else {
-       /* remove entire link */
-       if (prev == NULL)
-         ds->first = pos->next;
-       else
-         prev->next = pos->next;
-       
-       ds->max_memory += pos->count * sizeof(MasterEntry);
-       GROW(pos->values,
-            pos->count,
-            0);
-       FREE(pos);
-       ds->max_memory += sizeof(HT_Entry);
-      }
-      MUTEX_UNLOCK(ds->lock);
-      return OK;
-    }
-    prev = pos;
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  return SYSERR; /* not found */
-}
-
-/**
- * Iterate over all keys in the local datastore
- *
- * @param processor function to call on each item
- * @param cls argument to processor
- * @return number of results, SYSERR on error
- */
-static int iterate(void * closure,             
-                  DataProcessor processor,
-                  void * cls) {
-  MemoryDatastore * ds = (MemoryDatastore*) closure;
-  int ret;
-  HT_Entry * pos;
-  int i;
-  DataContainer * cont;
-
-  if (ds == NULL)
-    return SYSERR;
-
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  ret = 0;
-  cont = MALLOC(sizeof(HashCode512) + sizeof(DataContainer));
-  cont->size = htonl(sizeof(HashCode512) + sizeof(DataContainer));
-  while (pos != NULL) {
-    for (i=0;i<pos->count;i++) {
-      ret++;
-      if (processor != NULL) {
-       memcpy(&cont[1],
-              &pos->values[i].hash,
-              sizeof(HashCode512));
-       if (OK != processor(&pos->key,
-                           cont,
-                           cls)) {
-         MUTEX_UNLOCK(ds->lock);
-         FREE(cont);
-         return ret;
-       }
-      }
-    }
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  FREE(cont);
-  return SYSERR;
-}
-
-static void expirationJob(MemoryDatastore * store) {
-  HT_Entry * pos;
-  HT_Entry * prev;
-  int i;
-  cron_t now;
-
-  prev = NULL;
-  MUTEX_LOCK(store->lock);
-  now = get_time();
-  pos = store->first;
-  while (pos != NULL) {
-    for (i=pos->count-1;i>=0;i--) {
-      if (pos->values[i].lastRefreshTime + 15 * cronMINUTES < now) {
-       pos->values[i] = pos->values[pos->count-1];
-       GROW(pos->values,
-            pos->count,
-            pos->count-1);
-       store->max_memory += sizeof(MasterEntry);
-      }
-    }
-    if (pos->count == 0) {
-      if (prev == NULL)
-       store->first = pos->next;
-      else
-       prev->next = pos->next;
-      pos = pos->next;
-      FREE(pos);
-      store->max_memory += sizeof(HT_Entry);
-      continue;
-    }
-    prev = pos;
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(store->lock);
-}
-
-/**
- * Create a DHT Datastore (in memory)
- * @param max_memory do not use more than max_memory memory.
- */
-Blockstore * create_datastore_dht_master(struct GE_Context * ectx,
-                                        size_t max_memory) {
-  Blockstore * res;
-  MemoryDatastore * md;
-
-  md = MALLOC(sizeof(MemoryDatastore));
-  md->max_memory = max_memory;
-  md->first = NULL;
-  md->lock = MUTEX_CREATE(YES);
-  md->cron = cron_create(ectx);
-  md->ectx = ectx;
-  res = MALLOC(sizeof(Blockstore));
-  res->get  = &lookup;
-  res->put   = &store;
-  res->del  = &ds_remove;
-  res->iterate = &iterate;
-  res->closure = md;
-  cron_add_job(md->cron,
-              (CronJob) &expirationJob,
-              5 * cronMINUTES,
-              5 * cronMINUTES,
-              md);
-  cron_start(md->cron);
-  return res;
-}
-
-/**
- * Destroy a DHT Datastore (in memory)
- * @param ds the Datastore to destroy; must have been
- *  created by create_datastore_memory.
- */
-void destroy_datastore_dht_master(Blockstore * ds) {
-  MemoryDatastore * md;
-  HT_Entry * pos;
-  HT_Entry * next;
-
-  md  = ds->closure;
-  cron_stop(md->cron);
-  cron_del_job(md->cron,
-              (CronJob) &expirationJob,
-              5 * cronMINUTES,
-              md);
-  cron_destroy(md->cron);
-
-  pos = md->first;
-  while (pos != NULL) {
-    next = pos->next;
-    GROW(pos->values,
-        pos->count,
-        0);
-    FREE(pos);
-    pos = next;
-  }
-  MUTEX_DESTROY(md->lock);
-  FREE(md);
-  FREE(ds);
-}
-
-/* end of datastore_dht_master.c */

Deleted: GNUnet/src/applications/dht/module/datastore_dht_master.h
===================================================================
--- GNUnet/src/applications/dht/module/datastore_dht_master.h   2006-12-02 
22:30:48 UTC (rev 3851)
+++ GNUnet/src/applications/dht/module/datastore_dht_master.h   2006-12-02 
23:03:38 UTC (rev 3852)
@@ -1,48 +0,0 @@
- /*
-      This file is part of GNUnet
-      Copyright (C) 2004, 2005, 2006 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
-      by the Free Software Foundation; either version 2, or (at your
-      option) any later version.
-
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
-
-      You should have received a copy of the GNU General Public License
-      along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file applications/dht/module/datastore_dht_master.h
- * @brief provides the implementation of the
- * Blockstore API for keeping the table data in memory.
- * @author Simo Viitanen, Christian Grothoff
- */
-
-#ifndef DHT_DATASTORE_MASTER_H
-#define DHT_DATASTORE_MASTER_H
-
-#include "gnunet_blockstore.h"
-#include "gnunet_util.h"
-
-/**
- * Create a DHT Master Datastore
- * @param max_memory do not use more than max_memory memory.
- */
-Blockstore * create_datastore_dht_master(struct GE_Context * ectx,
-                                        size_t max_memory);
-
-/**
- * Destroy a DHT Master Datastore (in memory)
- * @param ds the Datastore to destroy; must have been
- *  created by create_datastore_memory.
- */
-void destroy_datastore_dht_master(Blockstore * ds);
-
-#endif

Deleted: GNUnet/src/applications/dht/module/datastore_memory.c
===================================================================
--- GNUnet/src/applications/dht/module/datastore_memory.c       2006-12-02 
22:30:48 UTC (rev 3851)
+++ GNUnet/src/applications/dht/module/datastore_memory.c       2006-12-02 
23:03:38 UTC (rev 3852)
@@ -1,334 +0,0 @@
- /*
-      This file is part of GNUnet
-      Copyright (C) 2004, 2005, 2006 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
-      by the Free Software Foundation; either version 2, or (at your
-      option) any later version.
-
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
-
-      You should have received a copy of the GNU General Public License
-      along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file applications/dht/module/datastore_memory.c
- * @brief provides the implementation of the
- *
- * Blockstore implementation for keeping the table
- * data in memory.  This implementation knows
- * nothing about entry types or multiple keys.
- * get calls must only use one key and types
- * are always ignored.
- *
- * @author Simo Viitanen, Christian Grothoff
- */
-
-#include "gnunet_dht_datastore_memory.h"
-#include "gnunet_core.h"
-#include "platform.h"
-
-/**
- * @brief datastructure for one entry in the table.
- */
-typedef struct HT_Entry_t {
-  struct HT_Entry_t * next;
-  HashCode512 key;
-  unsigned int count;
-  DataContainer ** values;
-} HT_Entry;
-
-/**
- * @brief the per-table data
- */
-typedef struct {
-  struct MUTEX * lock;
-  size_t max_memory;
-  HT_Entry * first;
-} MemoryDatastore;
-
-
-/**
- * Lookup an item in the datastore.
- *
- * @param key the value to lookup
- * @param maxResults maximum number of results
- * @param results where to store the result; must point to
- *        an array of maxResuls containers; if the containers
- *        point to allocated memory, it will be used by lookup;
- *        otherwise lookup will allocate the data pointer;
- *        in either case dataLength is adjusted to the actual
- *        size of the data.  If not enough space is present to
- *        accomodate the data the data will be truncated.
- * @return number of results, SYSERR on error
- */
-static int lookup(void * closure,
-                 unsigned int type,
-                 unsigned int prio,
-                 unsigned int keyCount,
-                 const HashCode512 * keys,
-                 DataProcessor resultCallback,
-                 void * resCallbackClosure) {
-  MemoryDatastore * ds = (MemoryDatastore*) closure;
-  HT_Entry * pos;
-  int i;
-
-  if ( (ds == NULL) || (keyCount != 1) )
-    return SYSERR;
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  while (pos != NULL) {
-    if (0 == memcmp(&keys[0],
-                   &pos->key,
-                   sizeof(HashCode512))) {
-      for (i=0;i<pos->count;i++)
-       if (OK != resultCallback(&pos->key,
-                                pos->values[i],
-                                resCallbackClosure)) {
-         MUTEX_UNLOCK(ds->lock);
-         return SYSERR;
-       }
-      MUTEX_UNLOCK(ds->lock);
-      return pos->count;
-    }
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  return 0;
-}
-
-/**
- * Store an item in the datastore.
- *
- * @param key the key of the item
- * @param value the value to store
- *  for other entries under the same key (if key already exists)
- * @return OK if the value could be stored, DHT_ERRORCODE or SYSERR if not 
(i.e. out of space)
- */
-static int store(void * closure,
-                const HashCode512 * key,
-                const DataContainer * value,
-                unsigned int prio) {
-  MemoryDatastore * ds = closure;
-  HT_Entry * pos;
-  unsigned int size;
-
-  if (ds == NULL)
-    return SYSERR;
-
-  size = ntohl(value->size);
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  while (pos != NULL) {
-    if (0 == memcmp(key,
-                   &pos->key,
-                   sizeof(HashCode512))) {
-      if (ds->max_memory < size) {
-       MUTEX_UNLOCK(ds->lock);
-       return NO;
-      }
-      ds->max_memory -= size;
-      GROW(pos->values,
-          pos->count,
-          pos->count+1);
-      pos->values[pos->count-1]
-       = MALLOC(size);
-      memcpy(pos->values[pos->count-1],
-            value,
-            size);
-      MUTEX_UNLOCK(ds->lock);
-      return OK;
-    } /* end key match */
-    pos = pos->next;
-  }
-  /* no key matched, create fresh entry */
-  if (ds->max_memory < sizeof(HT_Entry) + size) {
-    MUTEX_UNLOCK(ds->lock);
-    return NO;
-  }
-  ds->max_memory -= sizeof(HT_Entry) + size;
-  pos = MALLOC(sizeof(HT_Entry));
-  pos->key = *key;
-  pos->count = 1;
-  pos->values = MALLOC(sizeof(DataContainer*));
-  pos->values[0] = MALLOC(size);
-  memcpy(pos->values[0],
-        value,
-        size);
-  pos->next = ds->first;
-  ds->first = pos;
-  MUTEX_UNLOCK(ds->lock);
-  return OK;
-}
-
-/**
- * Remove an item from the datastore.
- *
- * @param key the key of the item
- * @param value the value to remove, NULL for all values of the key
- * @return OK if the value could be removed, SYSERR if not (i.e. not present)
- */
-static int ds_remove(void * closure,
-                    const HashCode512 * key,
-                    const DataContainer * value) {
-  MemoryDatastore * ds = closure;
-  HT_Entry * pos;
-  HT_Entry * prev;
-  int i;
-  unsigned int size;
-
-  if (ds == NULL)
-    return SYSERR;
-  size = ntohl(value->size);
-  MUTEX_LOCK(ds->lock);
-  prev = NULL;
-  pos = ds->first;
-  while (pos != NULL) {
-    if (0 == memcmp(key,
-                   &pos->key,
-                   sizeof(HashCode512))) {
-      if (value != NULL) {
-       for (i=0;i<pos->count;i++) {
-         if ( (pos->values[i]->size == value->size) &&
-              (0 == memcmp(pos->values[i],
-                           value,
-                           size)) ) {
-           FREE(pos->values[i]);
-           ds->max_memory += size;
-           pos->values[i] = pos->values[pos->count-1];
-           GROW(pos->values,
-                pos->count,
-                pos->count-1);
-           if (pos->count == 0) {
-             if (prev == NULL)
-               ds->first = pos->next;
-             else
-               prev->next = pos->next;
-             FREE(pos);
-             ds->max_memory += sizeof(HT_Entry);       
-           }
-           MUTEX_UNLOCK(ds->lock);
-           return OK;
-         }
-       }
-      } else {
-       /* remove entire link */
-       if (prev == NULL)
-         ds->first = pos->next;
-       else
-         prev->next = pos->next;
-       
-       for (i=0;i<pos->count;i++) {
-         ds->max_memory += ntohl(pos->values[i]->size);
-         FREE(pos->values[i]);
-       }
-       GROW(pos->values,
-            pos->count,
-            0);
-       FREE(pos);
-       ds->max_memory += sizeof(HT_Entry);
-      }
-      MUTEX_UNLOCK(ds->lock);
-      return OK;
-    }
-    prev = pos;
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  return SYSERR; /* not found */
-}
-
-/**
- * Iterate over all keys in the local datastore
- *
- * @param processor function to call on each item
- * @param cls argument to processor
- * @return number of results, SYSERR on error
- */
-static int iterate(void * closure,             
-                  DataProcessor processor,
-                  void * cls) {
-  MemoryDatastore * ds = closure;
-  int ret;
-  HT_Entry * pos;
-  int i;
-
-  if (ds == NULL)
-    return SYSERR;
-
-  MUTEX_LOCK(ds->lock);
-  pos = ds->first;
-  ret = 0;
-  while (pos != NULL) {
-    for (i=0;i<pos->count;i++) {
-      ret++;
-      if (processor != NULL)
-       if (OK != processor(&pos->key,
-                           pos->values[i],
-                           cls)) {
-         MUTEX_UNLOCK(ds->lock);
-         return ret;
-       }
-    }
-    pos = pos->next;
-  }
-  MUTEX_UNLOCK(ds->lock);
-  return SYSERR;
-}
-
-/**
- * Create a DHT Datastore (in memory)
- * @param max_memory do not use more than max_memory memory.
- */
-Blockstore * create_blockstore_memory(size_t max_memory) {
-  Blockstore * res;
-  MemoryDatastore * md;
-
-  md = MALLOC(sizeof(MemoryDatastore));
-  md->max_memory = max_memory;
-  md->first = NULL;
-  md->lock = MUTEX_CREATE(YES);
-
-  res = MALLOC(sizeof(Blockstore));
-  res->get = &lookup;
-  res->put = &store;
-  res->del = &ds_remove;
-  res->iterate = &iterate;
-  res->closure = md;
-  return res;
-}
-
-/**
- * Destroy a DHT Datastore (in memory)
- * @param ds the Datastore to destroy; must have been
- *  created by create_datastore_memory.
- */
-void destroy_blockstore_memory(Blockstore * ds) {
-  MemoryDatastore * md;
-  HT_Entry * pos;
-  HT_Entry * next;
-  unsigned int i;
-
-  md  = ds->closure;
-  pos = md->first;
-  while (pos != NULL) {
-    next = pos->next;
-    for (i=0;i<pos->count;i++)
-      FREENONNULL(pos->values[i]);
-    FREE(pos->values);
-    FREE(pos);
-    pos = next;
-  }
-  MUTEX_DESTROY(md->lock);
-  FREE(md);
-  FREE(ds);
-}
-
-/* end of datastore_memory.c */

Modified: GNUnet/src/applications/dht/module/table.c
===================================================================
--- GNUnet/src/applications/dht/module/table.c  2006-12-02 22:30:48 UTC (rev 
3851)
+++ GNUnet/src/applications/dht/module/table.c  2006-12-02 23:03:38 UTC (rev 
3852)
@@ -29,20 +29,25 @@
  * - no per-table storage; instead global,
  *   SQL database-based storage for entire peer
  * - no delete operation, just get/put + expiration
+ * - no "put" confirmation, try a get to confirm important put!
  * - modules:
  *   + table.c: DHT-peer table, peer discovery cron jobs;
- *     code tries to fill table "as much as possible" over time;
- *     reliabily metrics (to be added later)
- *   + routing.c: tracking of get/put operations, retry, reply handling
- *     code tries best-match routing among entries in table
- *   + cs.c: services to out-of-process DHT clients (via dht-lib)
+ *     code tries to fill table "as much as possible" over time; 
+ *     TODO: expose and improve reliabily metrics (to be added later)
  *   + dstore.c + plugin: SQL-based datastore: key, value, expiration
  *     (bounded FIFO-datastore, when full, kill oldest entry first)
  *     [?: better replacement policy to guard against attacks?]
+ *   + routing.c: tracking of get/put operations, retry, reply handling
+ *     code tries best-match routing among entries in table
+ *   + service.c: provide DHT services to rest of GNUnet process
+ *     (i.e. register datastore with shared data, get/put operations)
+ *   + cs.c: services to out-of-process DHT clients (via dht-lib) [mostly done]
  */
 
 #include "platform.h"
 #include "table.h"
+#include "gnunet_protocols.h"
+#include "gnunet_util.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_stats_service.h"
 #include "gnunet_identity_service.h"
@@ -141,7 +146,7 @@
 
 } PeerBucket;
 
-
+/**
  * Global core API.
  */
 static CoreAPIForApplication * coreAPI;
@@ -179,7 +184,7 @@
 /**
  * Pingpong service.
  */
-static PingPong_ServiceAPI * pingpong;
+static Pingpong_ServiceAPI * pingpong;
 
 static int stat_dht_total_peers;
 
@@ -277,8 +282,8 @@
  */
 static PeerInfo * 
 findPeerEntry(const PeerIdentity * peer) {
-  return findPeerEntryInBucke(findBucketFor(peer),
-                             peer);
+  return findPeerEntryInBucket(findBucketFor(peer),
+                              peer);
 }
 
 /**
@@ -333,7 +338,7 @@
 
   MUTEX_LOCK(lock);
   if (stats != NULL)
-    stats->update(stat_dht_route_looks, 1);
+    stats->change(stat_dht_route_looks, 1);
   for (bc=0;bc<bucketCount;bc++) {
     bucket = &buckets[bc];
     for (ec=0;ec<bucket->peers_size;ec++) {
@@ -341,7 +346,8 @@
       match = NO;
       for (i=0;i<blocked_size;i++) {
        if (0 == memcmp(&pi->id,
-                       &blocked[i])) {
+                       &blocked[i],
+                       sizeof(PeerIdentity))) {
          match = YES;
          break;
        }
@@ -364,7 +370,8 @@
       match = NO;
       for (i=0;i<blocked_size;i++) {
        if (0 == memcmp(&pi->id,
-                       &blocked[i])) {
+                       &blocked[i],
+                       sizeof(PeerIdentity))) {
          match = YES;
          break;
        }
@@ -374,7 +381,7 @@
       distance = inverse_distance(target,
                                  &pi->id.hashPubKey);
       if (distance > selected) {
-       set = pi->id;
+       *set = pi->id;
        MUTEX_UNLOCK(lock);
        return OK;
       } 
@@ -529,12 +536,12 @@
     if (checkExpired(peer) == YES) {
       total_peers--;
       if (stats != NULL)
-       stats->update(stat_dht_total_peers, -1);
+       stats->change(stat_dht_total_peers, -1);
       FREE(peer);
       bucket->peers[i] = bucket->peers[bucket->peers_size-1];
       GROW(bucket->peers,
-          bucket->peeers_size,
-          bucket->peeers_size - 1);
+          bucket->peers_size,
+          bucket->peers_size - 1);
     }
   }
 }
@@ -542,24 +549,23 @@
 /**
  * Consider adding the given peer to the DHT.
  */
-static void considerPeer(const PeerIdentity * peer) {
-  unsigned int pc;
+static void considerPeer(const PeerIdentity * sender,
+                        const PeerIdentity * peer) {
   PeerInfo * pi;
   PeerBucket * bucket;
-  const P2P_DHT_Discovery * disco;
   P2P_DHT_ASK_HELLO ask;
   P2P_hello_MESSAGE * hello;
 
   bucket = findBucketFor(peer);
   if (bucket == NULL)
-    continue; /* peers[i] == self */
+    return; /* peers[i] == self */
   if (bucket->peers_size >= MAINTAIN_BUCKET_SIZE) 
     checkExpiration(bucket);
   if (bucket->peers_size >= MAINTAIN_BUCKET_SIZE) 
-    continue; /* do not care */
+    return; /* do not care */
   if (NULL != findPeerEntryInBucket(bucket,
                                    peer))
-    continue; /* already have this peer in buckets */
+    return; /* already have this peer in buckets */
   /* do we know how to contact this peer? */
   hello = identity->identity2Helo(peer,
                                  ANY_PROTOCOL_NUMBER,
@@ -569,12 +575,12 @@
     ask.header.size = htons(sizeof(P2P_DHT_ASK_HELLO));
     ask.header.type = htons(sizeof(P2P_PROTO_DHT_ASK_HELLO));
     ask.reserved = 0;
-    ask.peer = *peers[i];
+    ask.peer = *peer;
     coreAPI->unicast(sender,
                     &ask.header,
                     0, /* FIXME: priority */
-                    5 * CRON_SECONDS);
-    continue;
+                    5 * cronSECONDS);
+    return;
   }
   FREE(hello);
   /* check if connected, if not, send discovery */
@@ -582,7 +588,7 @@
     /* not yet connected; connect sending DISCOVERY */
     broadcast_dht_discovery(peer,
                            NULL);
-    continue;
+    return;
   }
   /* we are connected (in core), add to bucket */
   pi = MALLOC(sizeof(PeerInfo));
@@ -597,7 +603,7 @@
   bucket->peers[bucket->peers_size-1] = pi;
   total_peers++;
   if (stats != NULL)
-    stats->update(stat_dht_total_peers, 1);
+    stats->change(stat_dht_total_peers, 1);
 }
 
 /**
@@ -608,6 +614,7 @@
   unsigned int pc;
   unsigned int i;
   const P2P_DHT_Discovery * disco;
+  const PeerIdentity * peers;
 
   pc = (ntohs(msg->size) - sizeof(P2P_DHT_Discovery)) / sizeof(PeerIdentity);
   if (pc > MAINTAIN_ADV_CAP * 8) {
@@ -618,9 +625,9 @@
     GE_BREAK(coreAPI->ectx, 0);
     return SYSERR; /* malformed */
   }
-  disco = (const P2P_DHT_Discovery) msg;
+  disco = (const P2P_DHT_Discovery*) msg;
   if (stats != NULL)
-    stats->update(stat_dht_discoveries, 1);
+    stats->change(stat_dht_discoveries, 1);
   if (pc == 0) {
     /* if peer has 0 connections, be sure to send discovery back */
     broadcast_dht_discovery(sender,
@@ -628,10 +635,10 @@
     return OK;
   }
   MUTEX_LOCK(lock);
-  considerPeer(sender);
+  considerPeer(sender, sender);
   peers = (const PeerIdentity*) &disco[1];
   for (i=0;i<pc;i++) 
-    considerPeer(&peers[i]);
+    considerPeer(sender, &peers[i]);
   MUTEX_UNLOCK(lock);
   return OK;
 }
@@ -657,7 +664,7 @@
   coreAPI->unicast(sender,
                   &hello->header,
                   0,
-                  5 * CRON_SECONDS);
+                  5 * cronSECONDS);
   FREE(hello);
   return OK;
 }
@@ -670,10 +677,8 @@
  */
 int init_dht_table(CoreAPIForApplication * capi) {
   unsigned long long i;
-  unsigned long long j;
 
   coreAPI = capi;
-  ectx = capi->ectx;
   /* use less than 50% of peer's ideal number of
      connections for DHT table size */
   i = coreAPI->getSlotCount() / MAINTAIN_BUCKET_SIZE / 2;
@@ -694,17 +699,18 @@
     stat_dht_route_looks = stats->create(gettext_noop("# dht route host 
lookups performed"));
   }
   identity = coreAPI->requestService("identity");
-  GE_ASSERT(ectx, identity != NULL);
+  GE_ASSERT(coreAPI->ectx, identity != NULL);
   pingpong = coreAPI->requestService("pingpong");
-  GE_ASSERT(ectx, pingpong != NULL);
+  GE_ASSERT(coreAPI->ectx, pingpong != NULL);
   capi->registerHandler(P2P_PROTO_DHT_DISCOVERY,
                        &handleDiscovery);
-  capi->registerHandler(P2P_PROTO_ASK_HELLO,
+  capi->registerHandler(P2P_PROTO_DHT_ASK_HELLO,
                        &handleAskHello);
-  cron_add_job(coreAPI->cron_manager,
+  cron_add_job(coreAPI->cron,
               &maintain_dht_job,
               MAINTAIN_FREQUENCY,
-              MAINTAIN_FREQUENCY);
+              MAINTAIN_FREQUENCY,
+              NULL);
   return OK;
 }
 
@@ -715,14 +721,16 @@
  */
 int done_dht_table() {
   unsigned int i;
-
-  capi->unregisterHandler(P2P_PROTO_DHT_DISCOVERY,
-                         &handleDiscovery);
-  capi->unregisterHandler(P2P_PROTO_ASK_HELLO,
-                         &handleAskHello);
-  cron_del_job(coreAPI->cron_manager,
+  unsigned int j;
+  
+  coreAPI->unregisterHandler(P2P_PROTO_DHT_DISCOVERY,
+                            &handleDiscovery);
+  coreAPI->unregisterHandler(P2P_PROTO_DHT_ASK_HELLO,
+                            &handleAskHello);
+  cron_del_job(coreAPI->cron,
               &maintain_dht_job,
-              MAINTAIN_FREQUENCY);
+              MAINTAIN_FREQUENCY,
+              NULL);
   if (stats != NULL) {
     coreAPI->releaseService(stats);
     stats = NULL;
@@ -731,9 +739,11 @@
   identity = NULL;
   coreAPI->releaseService(pingpong);
   pingpong = NULL;
-  for (i=0;i<bucketCount;i++) {
-    GROW(buckets[i]->peers,
-        buckets[i]->peers_size,
+  for (i=0;i<bucketCount;i++) { 
+    for (j=0;j<buckets[i].peers_size;j++)
+      FREE(buckets[i].peers[j]);
+    GROW(buckets[i].peers,
+        buckets[i].peers_size,
         0);
   }
   GROW(buckets,

Modified: GNUnet/src/include/Makefile.am
===================================================================
--- GNUnet/src/include/Makefile.am      2006-12-02 22:30:48 UTC (rev 3851)
+++ GNUnet/src/include/Makefile.am      2006-12-02 23:03:38 UTC (rev 3852)
@@ -18,7 +18,6 @@
   gnunet_core.h \
   gnunet_datastore_service.h \
   gnunet_dht.h \
-  gnunet_dht_datastore_memory.h \
   gnunet_dht_lib.h \
   gnunet_dht_service.h \
   gnunet_directories.h \

Deleted: GNUnet/src/include/gnunet_dht_datastore_memory.h
===================================================================
--- GNUnet/src/include/gnunet_dht_datastore_memory.h    2006-12-02 22:30:48 UTC 
(rev 3851)
+++ GNUnet/src/include/gnunet_dht_datastore_memory.h    2006-12-02 23:03:38 UTC 
(rev 3852)
@@ -1,62 +0,0 @@
- /*
-      This file is part of GNUnet
-      (C) 2004, 2005, 2006 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
-      by the Free Software Foundation; either version 2, or (at your
-      option) any later version.
-
-      GNUnet is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
-
-      You should have received a copy of the GNU General Public License
-      along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file include/gnunet_dht_datastore_memory.h
- * @brief provides the implementation of the
- * Blockstore for keeping the table data in memory.
- * @author Simo Viitanen, Christian Grothoff
- */
-
-#ifndef GNUNET_DHT_DATASTORE_MEMORY_H
-#define GNUNET_DHT_DATASTORE_MEMORY_H
-
-#include "gnunet_blockstore.h"
-
-#ifdef __cplusplus
-extern "C" {
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
-
-/**
- * Create a DHT Datastore (in memory)
- * @param max_memory do not use more than max_memory memory.
- */
-Blockstore * create_blockstore_memory(size_t max_memory);
-
-/**
- * Destroy a DHT Datastore (in memory)
- * @param ds the Datastore to destroy; must have been
- *  created by create_datastore_memory.
- */
-void destroy_blockstore_memory(Blockstore * ds);
-
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]