gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3051 - in GNUnet/src: include util util/containers util/cr


From: grothoff
Subject: [GNUnet-SVN] r3051 - in GNUnet/src: include util util/containers util/cron
Date: Sat, 24 Jun 2006 20:29:59 -0700 (PDT)

Author: grothoff
Date: 2006-06-24 20:29:57 -0700 (Sat, 24 Jun 2006)
New Revision: 3051

Modified:
   GNUnet/src/include/gnunet_util_containers.h
   GNUnet/src/util/README
   GNUnet/src/util/containers/Makefile.am
   GNUnet/src/util/containers/bloomfilter.c
   GNUnet/src/util/containers/hashtable.c
   GNUnet/src/util/containers/vector.c
   GNUnet/src/util/cron/cron.c
Log:
sync

Modified: GNUnet/src/include/gnunet_util_containers.h
===================================================================
--- GNUnet/src/include/gnunet_util_containers.h 2006-06-25 03:28:16 UTC (rev 
3050)
+++ GNUnet/src/include/gnunet_util_containers.h 2006-06-25 03:29:57 UTC (rev 
3051)
@@ -27,6 +27,9 @@
  * @author Gerd Knorr <address@hidden>
  * @author Ioana Patrascu
  * @author Tzvetan Horozov
+ * @author Nils Durner
+ *
+ * TODO: refactor APIs (more consistent naming conventions, etc.)
  */
 
 #ifndef GNUNET_UTIL_CONTAINERS_H
@@ -34,6 +37,7 @@
 
 /* add error and config prototypes */
 #include "gnunet_util.h"
+#include "gnunet_util_crypto.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -71,7 +75,8 @@
  *        element (number of bits set per element in the set)
  * @return the bloomfilter
  */
-struct Bloomfilter * loadBloomfilter(const char * filename,
+struct Bloomfilter * loadBloomfilter(struct GE_Context * ectx,
+                                    const char * filename,
                                     unsigned int size,
                                     unsigned int k);
 
@@ -310,8 +315,11 @@
  * @param value the value associated with the key
  * @return 0 if successful, -1 if an error was encountered
  */
-int ht_put(struct HashTable *hashTable, const void *key, const unsigned int 
keylen,
-  void *value, const unsigned int valuelen);
+int ht_put(struct HashTable *hashTable, 
+          const void *key, 
+          const unsigned int keylen,
+          void *value, 
+          const unsigned int valuelen);
   
 /**
  * @brief retrieves the value of a key in a HashTable
@@ -321,15 +329,20 @@
  * @param valuelen the length of the value
  * @return YES if found, NO otherwise
  */
-int ht_get(const struct HashTable *hashTable, const void *key, const unsigned 
int
-  keylen, void **value, unsigned int *valuelen);
+int ht_get(const struct HashTable *hashTable, 
+          const void *key, 
+          const unsigned int keylen, 
+          void **value, 
+          unsigned int *valuelen);
 
 /**
  * @brief removes a key/value pair from a HashTable
  * @param hashTable the HashTable to remove the key/value pair from
  * @param key the key specifying the key/value pair to be removed
  */
-void ht_remove(struct HashTable *hashTable, const void *key, const unsigned 
int keylen);
+void ht_remove(struct HashTable *hashTable, 
+              const void *key,
+              const unsigned int keylen);
 
 /**
  * @brief removes all key/value pairs from a HashTable
@@ -365,7 +378,8 @@
  *                     specified, an appropriate number of buckets is
  *                     automatically calculated.
  */
-void ht_rehash(struct HashTable *hashTable, long numOfBuckets);
+void ht_rehash(struct HashTable *hashTable, 
+              long numOfBuckets);
 
 /**
  * @brief sets the ideal element-to-bucket ratio of a HashTable
@@ -393,8 +407,10 @@
  *                     is considered unacceptably high, a value of 0.0 can
  *                     be specified.
  */
-void ht_setIdealRatio(struct HashTable *hashTable, float idealRatio,
-        float lowerRehashThreshold, float upperRehashThreshold);
+void ht_setIdealRatio(struct HashTable *hashTable, 
+                     float idealRatio,
+                     float lowerRehashThreshold, 
+                     float upperRehashThreshold);
 
 #define HT_PUT(ht, key, val) ht_put(ht, key, sizeof(key), val, sizeof(val))
 #define HT_GET(ht, key, val, vallen) ht_get(ht, key, sizeof(key), val, vallen)

Modified: GNUnet/src/util/README
===================================================================
--- GNUnet/src/util/README      2006-06-25 03:28:16 UTC (rev 3050)
+++ GNUnet/src/util/README      2006-06-25 03:29:57 UTC (rev 3051)
@@ -13,16 +13,16 @@
 util: main utility library (depends on all of the above)
       => these are all statically linked into gnunetutil.so
 
--------- TODO ----------
-
 util/config_impl: implementation of config API (depends on gnunetutil.so)
       => linked to gnunetutil_config.so
-util/containers: implementation of bloomfilter/vector/hashset (depends on 
gnunetutil.so)
-      => linked to gnunetutil_containers.so (also requires 
libgnunetutil_crypto)
+
+-------- TODO ----------
 util/cron: periodic job execution (depends on gnunetutil.so)
       => linked to gnunetutil_cron.so
 util/crypto: implementation of crypto API (depends on gnunetutil.so)
       => linked to gnunetutil_crypto.so
+util/containers: implementation of bloomfilter/vector/hashset (depends on 
gnunetutil.so)
+      => linked to gnunetutil_containers.so (also requires 
libgnunetutil_crypto)
 util/loggers: specific logging implementations (depends on gnunetutil.so)
       => linked to gnunetutil_logging.so
 

Modified: GNUnet/src/util/containers/Makefile.am
===================================================================
--- GNUnet/src/util/containers/Makefile.am      2006-06-25 03:28:16 UTC (rev 
3050)
+++ GNUnet/src/util/containers/Makefile.am      2006-06-25 03:29:57 UTC (rev 
3051)
@@ -6,7 +6,7 @@
 
 libgnunetutil_containers_la_LIBADD = \
  $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/util/libgnunetutil_crypto.la 
+ $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la 
 
 libgnunetutil_containers_la_LDFLAGS = \
  -version-info 0:0:0

Modified: GNUnet/src/util/containers/bloomfilter.c
===================================================================
--- GNUnet/src/util/containers/bloomfilter.c    2006-06-25 03:28:16 UTC (rev 
3050)
+++ GNUnet/src/util/containers/bloomfilter.c    2006-06-25 03:29:57 UTC (rev 
3051)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing 
authors)
+     (C) 2001, 2002, 2003, 2004, 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
@@ -18,7 +18,7 @@
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file util/bloomfilter.c
+ * @file util/containers/bloomfilter.c
  * @brief data structure used to reduce disk accesses.
  *
  * The idea basically: Create a signature for each element in the
@@ -40,19 +40,42 @@
  */
 
 #include "gnunet_util.h"
+#include "gnunet_util_containers.h"
 #include "platform.h"
 
 typedef struct Bloomfilter {
-  /** The bit counter file on disk */
+
+  /**
+   * Concurrency control 
+   */
+  struct MUTEX * lock;
+
+
+  /**
+   * The actual bloomfilter bit array 
+   */
+  char * bitArray;
+
+  /**
+   * For error handling.
+   */
+  struct GE_Context * ectx;
+
+  /**
+   * The bit counter file on disk 
+   */
   int fd;
-  /** How many bits we set for each stored element */
+
+  /**
+   * How many bits we set for each stored element 
+   */
   unsigned int addressesPerElement;
-  /** The actual bloomfilter bit array */
-  char * bitArray;
-  /** Size of bitArray in bytes */
+
+  /**
+   * Size of bitArray in bytes 
+   */
   unsigned int bitArraySize;
-  /** Concurrency control */
-  Mutex lock;
+
 } Bloomfilter;
 
 
@@ -130,12 +153,15 @@
 
   setBit(bitArray, bitIdx);
   /* Update the counter file on disk */
-  GNUNET_ASSERT(fd != -1);
+  GE_ASSERT(NULL,
+           fd != -1);
   fileSlot = bitIdx / 2;
   targetLoc = bitIdx % 2;
 
   if (fileSlot != (unsigned int) lseek(fd, fileSlot, SEEK_SET))
-    DIE_STRERROR("lseek");
+    GE_DIE_STRERROR(NULL,
+                   GE_ADMIN | GE_USER | GE_FATAL | GE_IMMEDIATE,
+                   "lseek");
   value = 0;
   READ(fd,
        &value,
@@ -153,9 +179,14 @@
   }
   value = ((high<<4) | low);
   if (fileSlot != (unsigned int) lseek(fd, fileSlot, SEEK_SET))
-    DIE_STRERROR("lseek");
+    GE_DIE_STRERROR(NULL,
+                   GE_ADMIN | GE_USER | GE_FATAL | GE_IMMEDIATE,
+                   "lseek");
   if (1 != WRITE(fd, &value, 1))
-    DIE_STRERROR("write");
+    GE_DIE_STRERROR(NULL,
+                   GE_ADMIN | GE_USER | GE_FATAL | GE_IMMEDIATE,
+                   "write");
+
 }
 
 /**
@@ -175,7 +206,7 @@
   unsigned int low;
   unsigned int targetLoc;
 
-  GNUNET_ASSERT(fd != -1);
+  GE_ASSERT(NULL, fd != -1);
   /* Each char slot in the counter file holds two 4 bit counters */
   fileSlot = bitIdx / 2;
   targetLoc = bitIdx % 2;
@@ -204,7 +235,9 @@
   value = ((high<<4) | low);
   lseek(fd, fileSlot, SEEK_SET);
   if (1 != WRITE(fd, &value, 1))
-    DIE_STRERROR("write");
+    GE_DIE_STRERROR(NULL,
+                   GE_ADMIN | GE_USER | GE_FATAL | GE_IMMEDIATE,
+                   "write");
 }
 
 #define BUFFSIZE 65536
@@ -224,7 +257,7 @@
 
   if (fd == -1)
     return SYSERR;
-  buffer = (char*)MALLOC(BUFFSIZE);
+  buffer = MALLOC(BUFFSIZE);
   memset(buffer, 0, BUFFSIZE);
   lseek(fd, 0, SEEK_SET);
 
@@ -237,7 +270,9 @@
       bytesleft = 0;
     }
     if(res == -1) {
-      LOG_STRERROR(LOG_WARNING, "write");
+      GE_DIE_STRERROR(NULL,
+                     GE_ADMIN | GE_USER | GE_FATAL | GE_IMMEDIATE,
+                     "write");
       FREE(buffer);
       return SYSERR;
     }
@@ -341,9 +376,10 @@
  * @param bit the bit to test
  * @param arg pointer set to NO if bit is not set
  */
-static void testBitCallback(const Bloomfilter * bf,
+static void testBitCallback(Bloomfilter * bf,
                            unsigned int bit,
-                           int * arg) {
+                           void * cls) {
+  int * arg = cls;
   if (NO == testBit(bf->bitArray,
                    bit))
     *arg = NO;
@@ -361,7 +397,8 @@
  *        element (number of bits set per element in the set)
  * @return the bloomfilter
  */
-Bloomfilter * loadBloomfilter(const char * filename,
+Bloomfilter * loadBloomfilter(struct GE_Context * ectx,
+                             const char * filename,
                              unsigned int size,
                              unsigned int k) {
   Bloomfilter * bf;
@@ -382,23 +419,27 @@
   size = ui; /* make sure it's a power of 2 */
 
   bf = (Bloomfilter *) MALLOC(sizeof(Bloomfilter));
-
+  bf->ectx = ectx;
   /* Try to open a bloomfilter file */
 #ifndef _MSC_VER
-  bf->fd = fileopen(filename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+  bf->fd = disk_file_open(ectx, 
+                         filename, 
+                         O_RDWR|O_CREAT, 
+                         S_IRUSR|S_IWUSR);
 #else
-  bf->fd = fileopen(filename, O_WRONLY|O_CREAT, S_IREAD|S_IWRITE);
+  bf->fd = disk_file_open(ectx,
+                         filename,
+                         O_WRONLY|O_CREAT, 
+                         S_IREAD|S_IWRITE);
 #endif
   if (-1 == bf->fd) {
-    LOG_FILE_STRERROR(LOG_FAILURE, "open", filename);
     FREE(bf);
     return NULL;
   }
 
   /* Alloc block */
-  MUTEX_CREATE_RECURSIVE(&bf->lock);
-  bf->bitArray
-    = (char *) xmalloc_unchecked_(size, __FILE__, __LINE__);
+  bf->lock = MUTEX_CREATE(YES);
+  bf->bitArray = MALLOC_LARGE(size);
   bf->bitArraySize = size;
   bf->addressesPerElement = k;
   memset(bf->bitArray,
@@ -406,7 +447,7 @@
         bf->bitArraySize);
 
   /* Read from the file what bits we can */
-  rbuff = (char*)MALLOC(BUFFSIZE);
+  rbuff = MALLOC(BUFFSIZE);
   pos = 0;
   while (pos < size*8) {
     int res;
@@ -442,8 +483,10 @@
 void freeBloomfilter(Bloomfilter * bf) {
   if (NULL == bf)
     return;
-  MUTEX_DESTROY(&bf->lock);
-  closefile(bf->fd);
+  MUTEX_DESTROY(bf->lock);
+  disk_file_close(bf->ectx,
+                 NULL, /* FIXME: keep filename around! */
+                 bf->fd);
   FREE(bf->bitArray);
   FREE(bf);
 }
@@ -457,13 +500,13 @@
   if (NULL == bf)
     return;
 
-  MUTEX_LOCK(&bf->lock);
+  MUTEX_LOCK(bf->lock);
   memset(bf->bitArray,
         0,
         bf->bitArraySize);
   makeEmptyFile(bf->fd,
                bf->bitArraySize * 4);
-  MUTEX_UNLOCK(&bf->lock);
+  MUTEX_UNLOCK(bf->lock);
 }
 
 
@@ -480,13 +523,13 @@
 
   if (NULL == bf)
     return YES;
-  MUTEX_LOCK(&bf->lock);
+  MUTEX_LOCK(bf->lock);
   res = YES;
   iterateBits(bf,
-             (BitIterator)&testBitCallback,
+             &testBitCallback,
              &res,
              e);
-  MUTEX_UNLOCK(&bf->lock);
+  MUTEX_UNLOCK(bf->lock);
   return res;
 }
 
@@ -501,12 +544,12 @@
 
   if (NULL == bf)
     return;
-  MUTEX_LOCK(&bf->lock);
+  MUTEX_LOCK(bf->lock);
   iterateBits(bf,
              &incrementBitCallback,
              NULL,
              e);
-  MUTEX_UNLOCK(&bf->lock);
+  MUTEX_UNLOCK(bf->lock);
 }
 
 /**
@@ -519,12 +562,12 @@
                        const HashCode512 * e) {
   if(NULL == bf)
     return;
-  MUTEX_LOCK(&bf->lock);
+  MUTEX_LOCK(bf->lock);
   iterateBits(bf,
              &decrementBitCallback,
              NULL,
              e);
-  MUTEX_UNLOCK(&bf->lock);
+  MUTEX_UNLOCK(bf->lock);
 }
 
 /**
@@ -546,7 +589,7 @@
   HashCode512 * e;
   unsigned int i;
 
-  MUTEX_LOCK(&bf->lock);
+  MUTEX_LOCK(bf->lock);
   FREE(bf->bitArray);
   i = 1;
   while (i < size)
@@ -567,7 +610,7 @@
     FREE(e);
     e = iterator(iterator_arg);
   }
-  MUTEX_UNLOCK(&bf->lock);
+  MUTEX_UNLOCK(bf->lock);
 }
 
 /* ******************** end of bloomfilter.c *********** */

Modified: GNUnet/src/util/containers/hashtable.c
===================================================================
--- GNUnet/src/util/containers/hashtable.c      2006-06-25 03:28:16 UTC (rev 
3050)
+++ GNUnet/src/util/containers/hashtable.c      2006-06-25 03:29:57 UTC (rev 
3051)
@@ -29,6 +29,7 @@
  */
 
 #include "gnunet_util.h"
+#include "gnunet_util_containers.h"
 #include "platform.h"
 
 typedef struct KeyValuePair {

Modified: GNUnet/src/util/containers/vector.c
===================================================================
--- GNUnet/src/util/containers/vector.c 2006-06-25 03:28:16 UTC (rev 3050)
+++ GNUnet/src/util/containers/vector.c 2006-06-25 03:29:57 UTC (rev 3051)
@@ -18,7 +18,7 @@
 */
 
 /**
- * @file util/vector.c
+ * @file util/containers/vector.c
  * @brief Implementation of a dynamic array
  * @author Antti Salonen, Christian Grothoff
  * @version vector.c,v 1.3 2004/05/02 20:22:52 aksalone Exp
@@ -41,6 +41,7 @@
 
 #include "platform.h"
 #include "gnunet_util.h"
+#include "gnunet_util_containers.h"
 
 typedef struct Vector {
   unsigned int VECTOR_SEGMENT_SIZE;
@@ -624,9 +625,7 @@
   VectorSegment *vs;
   size_t i = 0;
 
-  rvalue = xmalloc_unchecked_(v->size * sizeof (void *),
-                             __FILE__,
-                             __LINE__);
+  rvalue = MALLOC_LARGE(v->size * sizeof (void *));
   for (vs = v->segmentsHead; vs; vs = vs->next) {
     memcpy (rvalue + i,
            vs->data,

Modified: GNUnet/src/util/cron/cron.c
===================================================================
--- GNUnet/src/util/cron/cron.c 2006-06-25 03:28:16 UTC (rev 3050)
+++ GNUnet/src/util/cron/cron.c 2006-06-25 03:29:57 UTC (rev 3051)
@@ -34,6 +34,7 @@
  * then run the actual job.
  */
 
+#include "gnunet_util.h"
 #include "gnunet_util_cron.h"
 #include "platform.h"
 





reply via email to

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