- initialize set type in test case
authorFlorian Dold <florian.dold@gmail.com>
Fri, 6 Sep 2013 11:37:39 +0000 (11:37 +0000)
committerFlorian Dold <florian.dold@gmail.com>
Fri, 6 Sep 2013 11:37:39 +0000 (11:37 +0000)
- handle 1-peer consensus correcly
- don't store peers in consensus api
- updated consensus test case

src/consensus/consensus_api.c
src/consensus/gnunet-service-consensus.c
src/consensus/test_consensus_api.c
src/include/gnunet_consensus_service.h
src/set/test_set_api.c

index 873e72ca11c2bddacb956283cdf1760e505acd69..b2b3694d65914b1036c05acd7db68e0bd1cf8911 100644 (file)
@@ -64,16 +64,6 @@ struct GNUNET_CONSENSUS_Handle
    */
   struct GNUNET_HashCode session_id;
 
-  /**
-   * Number of peers in the consensus. Optionally includes the local peer.
-   */
-  int num_peers;
-
-  /**
-   * Peer identities of peers participating in the consensus, includes the local peer.
-   */
-  struct GNUNET_PeerIdentity **peers;
-
   /**
    * GNUNES_YES iff the join message has been sent to the service.
    */
@@ -194,15 +184,7 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
   consensus->cfg = cfg;
   consensus->new_element_cb = new_element_cb;
   consensus->new_element_cls = new_element_cls;
-  consensus->num_peers = num_peers;
   consensus->session_id = *session_id;
-
-  if (0 == num_peers)
-    consensus->peers = NULL;
-  else if (num_peers > 0)
-    consensus->peers =
-        GNUNET_memdup (peers, num_peers * sizeof (struct GNUNET_PeerIdentity));
-
   consensus->client = GNUNET_CLIENT_connect ("consensus", cfg);
   consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client,
                                                          mq_handlers, NULL, consensus);
@@ -214,10 +196,10 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
                             GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
 
   join_msg->session_id = consensus->session_id;
-  join_msg->num_peers = htonl (consensus->num_peers);
+  join_msg->num_peers = htonl (num_peers);
   memcpy(&join_msg[1],
-        consensus->peers,
-        consensus->num_peers * sizeof (struct GNUNET_PeerIdentity));
+        peers,
+        num_peers * sizeof (struct GNUNET_PeerIdentity));
 
   GNUNET_MQ_send (consensus->mq, ev);
   return consensus;
@@ -318,8 +300,6 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
     GNUNET_CLIENT_disconnect (consensus->client);
     consensus->client = NULL;
   }
-  if (NULL != consensus->peers)
-    GNUNET_free (consensus->peers);
   GNUNET_free (consensus);
 }
 
index 9e72a7f740f14a152790c0871a8e28581ded0506..a490ad7f42faa8f66129978b883b5eac337e2cdb 100644 (file)
@@ -1187,8 +1187,8 @@ client_conclude (void *cls,
   }
   if (session->num_peers <= 1)
   {
-    /* FIXME: what to do here? */
-    //send_client_conclude_done (session);
+    session->current_round = CONSENSUS_ROUND_FINISH;
+    GNUNET_SET_iterate (session->element_set, send_to_client_iter, session);
   }
   else
   {
index c79a6221c27cfc39ad8863c557784bd132ea1d66..37a5eb692ec2a4093de565344b3cadbb3bef7d47 100644 (file)
@@ -32,26 +32,23 @@ static struct GNUNET_CONSENSUS_Handle *consensus;
 
 static struct GNUNET_HashCode session_id;
 
+static unsigned int elements_received;
 
-static int
-conclude_done (void *cls, const struct GNUNET_CONSENSUS_Group *group)
+
+static void
+conclude_done (void *cls)
 {
-  if (NULL == group)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return GNUNET_NO;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "concluded\n");
-  return GNUNET_YES;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
+  if (2 != elements_received)
+    GNUNET_abort ();
+  GNUNET_SCHEDULER_shutdown ();
 }
 
-static int
+static void
 on_new_element (void *cls,
-                struct GNUNET_CONSENSUS_Element *element)
+                const struct GNUNET_SET_Element *element)
 {
-  GNUNET_assert (0);
-  return GNUNET_YES;
+  elements_received++;
 }
 
 static void
@@ -62,7 +59,7 @@ insert_done (void *cls, int success)
   GNUNET_assert (GNUNET_NO == called);
   called = GNUNET_YES;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
-  GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_SECONDS, 0, &conclude_done, NULL);
+  GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_SECONDS, &conclude_done, NULL);
 }
 
 
@@ -91,8 +88,8 @@ run (void *cls,
 {
   char *str = "foo";
 
-  struct GNUNET_CONSENSUS_Element el1 = {"foo", 4, 0};
-  struct GNUNET_CONSENSUS_Element el2 = {"bar", 4, 0};
+  struct GNUNET_SET_Element el1 = {4, 0, "foo"};
+  struct GNUNET_SET_Element el2 = {5, 0, "quux"};
 
   GNUNET_log_setup ("test_consensus_api",
                     "INFO",
index db7509976e68f8041def5c2389c2e3c8b3e17b5b..fc1255506b6a305ea6ab664993481ea4428fe815 100644 (file)
@@ -52,7 +52,7 @@ extern "C"
  * @param element new element, NULL on error
  */
 typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls,
-                                                 const struct GNUNET_SET_Element *element);
+                                                  const struct GNUNET_SET_Element *element);
 
 
 
index 3dd49f03695e0e4542fed27dfe0df8cd22b924bc..b7e1961f2cba8fb81436424209a8a5f7cff2a832 100644 (file)
@@ -136,9 +136,10 @@ init_set2 (void *cls)
 {
   struct GNUNET_SET_Element element;
 
-
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
 
+  element.type = 0;
+
   element.data = "hello";
   element.size = strlen(element.data);
   GNUNET_SET_add_element (set2, &element, NULL, NULL);
@@ -159,6 +160,8 @@ init_set1 (void)
 {
   struct GNUNET_SET_Element element;
 
+  element.type = 0;
+
   element.data = "hello";
   element.size = strlen(element.data);
   GNUNET_SET_add_element (set1, &element, NULL, NULL);