guix-env: some update.
[oweals/gnunet.git] / src / set / gnunet-service-set_union_strata_estimator.c
index e94d526501a0d5fc146d47bfd9d225586e37b714..e3d6bfaec702369ea089f3b6391d4ef83f51506d 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      Copyright (C) 2012 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2012 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -33,7 +33,7 @@
  * Should we try compressing the strata estimator? This will
  * break compatibility with the 0.10.1-network.
  */
-#define FAIL_10_1_COMPATIBILTIY 0
+#define FAIL_10_1_COMPATIBILTIY 1
 
 
 /**
@@ -47,7 +47,9 @@ size_t
 strata_estimator_write (const struct StrataEstimator *se,
                         void *buf)
 {
+  char *sbuf = buf;
   unsigned int i;
+  size_t osize;
 
   GNUNET_assert (NULL != se);
   for (i = 0; i < se->strata_count; i++)
@@ -55,13 +57,11 @@ strata_estimator_write (const struct StrataEstimator *se,
     ibf_write_slice (se->strata[i],
                      0,
                      se->ibf_size,
-                     buf);
-    buf += se->ibf_size * IBF_BUCKET_SIZE;
+                     &sbuf[se->ibf_size * IBF_BUCKET_SIZE * i]);
   }
   osize = se->ibf_size * IBF_BUCKET_SIZE * se->strata_count;
 #if FAIL_10_1_COMPATIBILTIY
   {
-    size_t osize;
     char *cbuf;
     size_t nsize;
 
@@ -71,7 +71,7 @@ strata_estimator_write (const struct StrataEstimator *se,
                                 &cbuf,
                                 &nsize))
     {
-      memcpy (buf, cbuf, nsize);
+      GNUNET_memcpy (buf, cbuf, nsize);
       osize = nsize;
       GNUNET_free (cbuf);
     }
@@ -123,6 +123,7 @@ strata_estimator_read (const void *buf,
     GNUNET_free_non_null (dbuf);
     return GNUNET_SYSERR;
   }
+
   for (i = 0; i < se->strata_count; i++)
   {
     ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]);
@@ -202,6 +203,8 @@ strata_estimator_create (unsigned int strata_count,
     se->strata[i] = ibf_create (ibf_size, ibf_hashnum);
     if (NULL == se->strata[i])
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to allocate memory for strata estimator\n");
       for (j = 0; j < i; j++)
         ibf_destroy (se->strata[i]);
       GNUNET_free (se);
@@ -277,7 +280,8 @@ strata_estimator_dup (struct StrataEstimator *se)
   c = GNUNET_new (struct StrataEstimator);
   c->strata_count = se->strata_count;
   c->ibf_size = se->ibf_size;
-  c->strata = GNUNET_malloc (sizeof (struct InvertibleBloomFilter *) * se->strata_count);
+  c->strata = GNUNET_new_array (se->strata_count,
+                                struct InvertibleBloomFilter *);
   for (i = 0; i < se->strata_count; i++)
     c->strata[i] = ibf_dup (se->strata[i]);
   return c;