-fixing misc issues and bugs, including better termination logic for intersection...
[oweals/gnunet.git] / src / set / gnunet-set-profiler.c
index b0c81feb134b1a9e23100163dbab5220d3b95842..3bff452544ff923806ace4723f1083fed9030593 100644 (file)
@@ -4,7 +4,7 @@
 
       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
+      by the Free Software Foundation; either version 3, or (at your
       option) any later version.
 
       GNUnet is distributed in the hope that it will be useful, but
@@ -24,7 +24,6 @@
  * @author Florian Dold
  */
 #include "platform.h"
-#include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_set_service.h"
 #include "gnunet_testbed_service.h"
@@ -36,8 +35,6 @@ static unsigned int num_a = 5;
 static unsigned int num_b = 5;
 static unsigned int num_c = 20;
 
-static unsigned int salt = 42;
-
 static char *op_str = "union";
 
 const static struct GNUNET_CONFIGURATION_Handle *config;
@@ -52,13 +49,13 @@ struct SetInfo
   int done;
 } info1, info2;
 
-struct GNUNET_CONTAINER_MultiHashMap *common_sent;
+static struct GNUNET_CONTAINER_MultiHashMap *common_sent;
 
-struct GNUNET_HashCode app_id;
+static struct GNUNET_HashCode app_id;
 
-struct GNUNET_PeerIdentity local_peer;
+static struct GNUNET_PeerIdentity local_peer;
 
-struct GNUNET_SET_ListenHandle *set_listener;
+static struct GNUNET_SET_ListenHandle *set_listener;
 
 
 static int
@@ -78,6 +75,7 @@ map_remove_iterator (void *cls,
 
 }
 
+
 static void
 check_all_done (void)
 {
@@ -145,18 +143,19 @@ set_listen_cb (void *cls,
 {
   if (NULL == request)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "listener failed\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "listener failed\n");
     return;
   }
   GNUNET_assert (NULL == info2.oh);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set listen cb called\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "set listen cb called\n");
   info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED,
                                set_result_cb, &info2);
   GNUNET_SET_commit (info2.oh, info2.set);
 }
 
 
-
 static int
 set_insert_iterator (void *cls,
                      const struct GNUNET_HashCode *key,
@@ -165,8 +164,9 @@ set_insert_iterator (void *cls,
   struct GNUNET_SET_Handle *set = cls;
   struct GNUNET_SET_Element *el;
 
-  el = GNUNET_malloc (sizeof *el + sizeof *key);
-  el->type = 0;
+  el = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) +
+                      sizeof (struct GNUNET_HashCode));
+  el->element_type = 0;
   memcpy (&el[1], key, sizeof *key);
   el->data = &el[1];
   el->size = sizeof *key;
@@ -207,6 +207,7 @@ handle_shutdown (void *cls,
   }
 }
 
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -216,7 +217,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   config = cfg;
 
-  if (GNUNET_OK != GNUNET_CRYPTO_get_host_identity (cfg, &local_peer))
+  if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n");
     ret = 0;
@@ -227,13 +228,13 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   info1.id = "a";
   info2.id = "b";
-  
-  info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO);
-  info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO);
-  common_sent = GNUNET_CONTAINER_multihashmap_create (num_c, GNUNET_NO);
 
-  info1.received = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO);
-  info2.received = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO);
+  info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO);
+  info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO);
+  common_sent = GNUNET_CONTAINER_multihashmap_create (num_c+1, GNUNET_NO);
+
+  info1.received = GNUNET_CONTAINER_multihashmap_create (num_a+1, GNUNET_NO);
+  info2.received = GNUNET_CONTAINER_multihashmap_create (num_b+1, GNUNET_NO);
 
   for (i = 0; i < num_a; i++)
   {
@@ -271,8 +272,9 @@ run (void *cls, char *const *args, const char *cfgfile,
   set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
                                     &app_id, set_listen_cb, NULL);
 
-  info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, salt, GNUNET_SET_RESULT_ADDED,
-                       set_result_cb, &info1);
+  info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL,
+                                 GNUNET_SET_RESULT_ADDED,
+                                 set_result_cb, &info1);
   GNUNET_SET_commit (info1.oh, info1.set);
   GNUNET_SET_destroy (info1.set);
   info1.set = NULL;