gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32278 - gnunet/src/consensus


From: gnunet
Subject: [GNUnet-SVN] r32278 - gnunet/src/consensus
Date: Mon, 10 Feb 2014 18:50:14 +0100

Author: dold
Date: 2014-02-10 18:50:14 +0100 (Mon, 10 Feb 2014)
New Revision: 32278

Modified:
   gnunet/src/consensus/consensus_api.c
   gnunet/src/consensus/gnunet-service-consensus.c
Log:
- fixed wrong round comparison code


Modified: gnunet/src/consensus/consensus_api.c
===================================================================
--- gnunet/src/consensus/consensus_api.c        2014-02-10 16:49:14 UTC (rev 
32277)
+++ gnunet/src/consensus/consensus_api.c        2014-02-10 17:50:14 UTC (rev 
32278)
@@ -141,6 +141,13 @@
 
   GNUNET_CONSENSUS_ConcludeCallback cc;
 
+  GNUNET_MQ_destroy (consensus->mq);
+  consensus->mq = NULL;
+
+  GNUNET_CLIENT_disconnect (consensus->client);
+  consensus->client = NULL;
+
+
   GNUNET_assert (NULL != (cc = consensus->conclude_cb));
   consensus->conclude_cb = NULL;
   cc (consensus->conclude_cls);
@@ -148,6 +155,22 @@
 
 
 /**
+ * Generic error handler, called with the appropriate
+ * error code and the same closure specified at the creation of
+ * the message queue.
+ * Not every message queue implementation supports an error handler.
+ *
+ * @param cls closure, same closure as for the message handlers
+ * @param error error code
+ */
+static void
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
+{
+  LOG (GNUNET_ERROR_TYPE_WARNING, "consensus service disconnected us\n");
+}
+
+
+/**
  * Create a consensus session.
  *
  * @param cfg configuration to use for connecting to the consensus service
@@ -192,7 +215,7 @@
   consensus->session_id = *session_id;
   consensus->client = GNUNET_CLIENT_connect ("consensus", cfg);
   consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client,
-                                                         mq_handlers, NULL, 
consensus);
+                                                         mq_handlers, 
mq_error_handler, consensus);
 
   GNUNET_assert (consensus->client != NULL);
 
@@ -298,8 +321,13 @@
 void
 GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
 {
-  if (consensus->client != NULL)
+  if (NULL != consensus->mq)
   {
+    GNUNET_MQ_destroy (consensus->mq);
+    consensus->mq = NULL;
+  }
+  if (NULL != consensus->client)
+  {
     GNUNET_CLIENT_disconnect (consensus->client);
     consensus->client = NULL;
   }

Modified: gnunet/src/consensus/gnunet-service-consensus.c
===================================================================
--- gnunet/src/consensus/gnunet-service-consensus.c     2014-02-10 16:49:14 UTC 
(rev 32277)
+++ gnunet/src/consensus/gnunet-service-consensus.c     2014-02-10 17:50:14 UTC 
(rev 32278)
@@ -551,9 +551,9 @@
   while (largest_arc < session->num_peers)
     largest_arc <<= 1;
   num_ghosts = largest_arc - session->num_peers;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "largest arc: %u\n", largest_arc);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arc: %u\n", arc);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "num ghosts: %u\n", num_ghosts);
+  // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "largest arc: %u\n", largest_arc);
+  // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arc: %u\n", arc);
+  // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "num ghosts: %u\n", num_ghosts);
 
   if (0 == (my_idx & arc))
   {
@@ -568,7 +568,7 @@
     if (my_idx < num_ghosts)
     {
       int ghost_partner_idx;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "my index %d, arc %d, peers %u\n", 
my_idx, arc, session->num_peers);
+      // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "my index %d, arc %d, peers 
%u\n", my_idx, arc, session->num_peers);
       ghost_partner_idx = (my_idx - (int) arc) % (int) session->num_peers;
       /* platform dependent; modulo sometimes returns negative values */
       if (ghost_partner_idx < 0)
@@ -576,7 +576,7 @@
       /* we only need to have a ghost partner if the partner is outgoing */
       if (0 == (ghost_partner_idx & arc))
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", 
ghost_partner_idx);
+        // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", 
ghost_partner_idx);
         session->partner_incoming = 
&session->info[session->shuffle_inv[ghost_partner_idx]];
         GNUNET_assert (GNUNET_NO == 
session->partner_incoming->set_op_finished);
         return;
@@ -612,6 +612,9 @@
   unsigned int remote_idx = cpi - cpi->session->info;
   unsigned int local_idx = cpi->session->local_peer_idx;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: set result from P%u with status 
%u\n",
+              local_idx, remote_idx, (unsigned int) status);
+
   GNUNET_assert ((cpi == cpi->session->partner_outgoing) ||
                  (cpi == cpi->session->partner_incoming));
 
@@ -686,7 +689,7 @@
       return 1;
     if (session->exp_subround < ri->exp_subround)
       return -1;
-    if (session->exp_subround < ri->exp_subround)
+    if (session->exp_subround > ri->exp_subround)
       return 1;
     return 0;
   }
@@ -813,7 +816,12 @@
                             GNUNET_SET_RESULT_ADDED,
                             set_result_cb, session->partner_outgoing);
     GNUNET_free (msg);
-    GNUNET_SET_commit (session->partner_outgoing->set_op, 
session->element_set);
+    if (GNUNET_OK != GNUNET_SET_commit (session->partner_outgoing->set_op, 
session->element_set))
+    {
+      GNUNET_break (0);
+      session->partner_outgoing->set_op = NULL;
+      session->partner_outgoing->set_op_finished = GNUNET_YES;
+    }
   }
 
   /* commit to the delayed set operation */
@@ -829,7 +837,10 @@
     }
     if (cmp == 0)
     {
-      GNUNET_SET_commit (session->partner_incoming->delayed_set_op, 
session->element_set);
+      if (GNUNET_OK != GNUNET_SET_commit 
(session->partner_incoming->delayed_set_op, session->element_set))
+      {
+        GNUNET_break (0);
+      }
       session->partner_incoming->set_op = 
session->partner_incoming->delayed_set_op;
       session->partner_incoming->delayed_set_op = NULL;
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d resumed delayed round with 
P%d\n",
@@ -1044,7 +1055,7 @@
       if (cmp > 0)
       {
         /* the other peer is too late */
-        GNUNET_break_op (0);
+        LOG_PP (GNUNET_ERROR_TYPE_DEBUG, cpi, "too late for the current 
round\n");
         return;
       }
       /* kill old request, if any. this is legal,
@@ -1060,8 +1071,20 @@
                                   set_result_cb, &session->info[index]);
       if (cmp == 0)
       {
+        /* we're in exactly the right round for the incoming request */
+        if (cpi != cpi->session->partner_incoming)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "P%u: got request from %u (with 
matching round), "
+                      "but incoming partner is %d\n", 
cpi->session->local_peer_idx, cpi - cpi->session->info,
+                      ((NULL == cpi->session->partner_incoming) ? -1 : 
(cpi->session->partner_incoming - cpi->session->info)));
+          GNUNET_SET_operation_cancel (set_op);
+          return;
+        }
         cpi->set_op = set_op;
-        GNUNET_SET_commit (set_op, session->element_set);
+        if (GNUNET_OK != GNUNET_SET_commit (set_op, session->element_set))
+        {
+          GNUNET_break (0);
+        }
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%d commited to set request from 
P%d\n", session->local_peer_idx, index);
       }
       else
@@ -1238,7 +1261,7 @@
   GNUNET_free (element);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: element added\n", 
session->local_peer_idx);
+  // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: element added\n", 
session->local_peer_idx);
 }
 
 




reply via email to

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