gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32268 - gnunet/src/set


From: gnunet
Subject: [GNUnet-SVN] r32268 - gnunet/src/set
Date: Mon, 10 Feb 2014 01:13:13 +0100

Author: dold
Date: 2014-02-10 01:13:13 +0100 (Mon, 10 Feb 2014)
New Revision: 32268

Modified:
   gnunet/src/set/gnunet-service-set.c
   gnunet/src/set/set_api.c
   gnunet/src/set/test_set_api.c
Log:
- fix operation cancellation in SET


Modified: gnunet/src/set/gnunet-service-set.c
===================================================================
--- gnunet/src/set/gnunet-service-set.c 2014-02-09 21:54:56 UTC (rev 32267)
+++ gnunet/src/set/gnunet-service-set.c 2014-02-10 00:13:13 UTC (rev 32268)
@@ -224,6 +224,7 @@
   {
     struct GNUNET_SERVER_Client *client = listener->client;
     listener->client = NULL;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting listener client\n");
     GNUNET_SERVER_client_disconnect (client);
     return;
   }
@@ -1053,24 +1054,30 @@
     GNUNET_SERVER_client_disconnect (client);
     return;
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client requested cancel for op %u\n", 
ntohl (msg->request_id));
+
   found = GNUNET_NO;
   for (op = set->ops_head; NULL != op; op = op->next)
   {
-    if (op->spec->client_request_id == msg->request_id)
+    if (op->spec->client_request_id == ntohl (msg->request_id))
     {
       found = GNUNET_YES;
       break;
     }
   }
 
-  if (GNUNET_NO == found)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_client_disconnect (client);
-    return;
-  }
+  /* It may happen that the operation was destroyed due to
+   * the other peer disconnecting.  The client may not know about this
+   * yet and try to cancel the (non non-existent) operation.
+   */
+  if (GNUNET_NO != found)
+    _GSS_operation_destroy (op);
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client canceled non-existent op\n");
 
-  _GSS_operation_destroy (op);
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 

Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c    2014-02-09 21:54:56 UTC (rev 32267)
+++ gnunet/src/set/set_api.c    2014-02-10 00:13:13 UTC (rev 32268)
@@ -283,7 +283,13 @@
   result_status = ntohs (msg->result_status);
 
   oh = GNUNET_MQ_assoc_get (set->mq, ntohl (msg->request_id));
-  GNUNET_assert (NULL != oh);
+  // 'oh' can be NULL if we canceled the operation, but the service
+  // did not get the cancel message yet.
+  if (NULL == oh)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ignoring result from canceled 
operation\n");
+    return;
+  }
   /* status is not STATUS_OK => there's no attached element,
    * and this is the last result message we get */
   if (GNUNET_SET_STATUS_OK != result_status)
@@ -356,7 +362,7 @@
 {
   struct GNUNET_SET_ListenHandle *lh = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listener broke down, re-connecting\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "listener broke down, re-connecting\n");
   GNUNET_CLIENT_disconnect (lh->client);
   lh->client = NULL;
   GNUNET_MQ_destroy (lh->mq);
@@ -381,6 +387,7 @@
     set->destroy_requested = GNUNET_YES;
     return GNUNET_NO;
   }
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Really destroying set\n");
   GNUNET_CLIENT_disconnect (set->client);
   set->client = NULL;
   GNUNET_MQ_destroy (set->mq);
@@ -415,16 +422,21 @@
   if (NULL != oh->set)
   {
     struct GNUNET_SET_OperationHandle *h_assoc;
+    struct GNUNET_SET_CancelMessage *m;
     struct GNUNET_MQ_Envelope *mqm;
 
     GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, oh->set->ops_tail, oh);
     h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, oh->request_id);
     GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh));
-    mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_CANCEL);
+    mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL);
+    m->request_id = htonl (oh->request_id);
     GNUNET_MQ_send (oh->set->mq, mqm);
 
     if (GNUNET_YES == oh->set->destroy_requested)
+    {
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying set after operation cancel\n");
       ret = set_destroy (oh->set);
+    }
   }
 
   GNUNET_free (oh);
@@ -451,6 +463,8 @@
 {
   struct GNUNET_SET_Handle *set = cls;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "handling client set error\n");
+
   while (NULL != set->ops_head)
   {
     if (NULL != set->ops_head->result_cb)
@@ -836,6 +850,7 @@
 {
   struct GNUNET_MQ_Envelope *ev;
 
+
   GNUNET_assert (NULL != iter);
 
   if (GNUNET_YES == set->invalid)
@@ -843,6 +858,8 @@
   if (NULL != set->iterator)
     return GNUNET_NO;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "iterating set\n");
+
   set->iterator = iter;
   set->iterator_cls = cls;
   ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST);

Modified: gnunet/src/set/test_set_api.c
===================================================================
--- gnunet/src/set/test_set_api.c       2014-02-09 21:54:56 UTC (rev 32267)
+++ gnunet/src/set/test_set_api.c       2014-02-10 00:13:13 UTC (rev 32268)
@@ -241,7 +241,9 @@
   set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
 
-  /* test if canceling an uncommited request works! */
+
+
+  ///* test if canceling an uncommited request works! */
   my_oh = GNUNET_SET_prepare (&local_id, &app_id, NULL, 0,
                               GNUNET_SET_RESULT_ADDED, NULL, NULL);
 




reply via email to

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