gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36417 - gnunet/src/cadet


From: gnunet
Subject: [GNUnet-SVN] r36417 - gnunet/src/cadet
Date: Fri, 2 Oct 2015 05:37:41 +0200

Author: bartpolot
Date: 2015-10-02 05:37:41 +0200 (Fri, 02 Oct 2015)
New Revision: 36417

Modified:
   gnunet/src/cadet/cadet_api.c
   gnunet/src/cadet/test_cadet.c
Log:
- cancel transmit requests before destroying channels, warn API users if not

Modified: gnunet/src/cadet/cadet_api.c
===================================================================
--- gnunet/src/cadet/cadet_api.c        2015-10-02 03:37:40 UTC (rev 36416)
+++ gnunet/src/cadet/cadet_api.c        2015-10-02 03:37:41 UTC (rev 36417)
@@ -1683,6 +1683,8 @@
       {
         /* applications should cancel before destroying channel */
         GNUNET_break (0);
+        LOG (GNUNET_ERROR_TYPE_WARNING,
+             "Channel destroyed without cancelling transmission requests\n");
         th->notify (th->notify_cls, 0, NULL);
       }
       GNUNET_CADET_notify_transmit_ready_cancel (th);

Modified: gnunet/src/cadet/test_cadet.c
===================================================================
--- gnunet/src/cadet/test_cadet.c       2015-10-02 03:37:40 UTC (rev 36416)
+++ gnunet/src/cadet/test_cadet.c       2015-10-02 03:37:41 UTC (rev 36417)
@@ -177,6 +177,17 @@
 static struct GNUNET_CADET_Channel *incoming_ch;
 
 /**
+ * Transmit handle for root data calls
+ */
+static struct GNUNET_CADET_TransmitHandle *th;
+
+/**
+ * Transmit handle for root data calls
+ */
+static struct GNUNET_CADET_TransmitHandle *incoming_th;
+
+
+/**
  * Time we started the data transmission (after channel has been established
  * and initilized).
  */
@@ -286,11 +297,21 @@
   }
   if (NULL != ch)
   {
+    if (NULL != th)
+    {
+      GNUNET_CADET_notify_transmit_ready_cancel (th);
+      th = NULL;
+    }
     GNUNET_CADET_channel_destroy (ch);
     ch = NULL;
   }
   if (NULL != incoming_ch)
   {
+    if (NULL != incoming_th)
+    {
+      GNUNET_CADET_notify_transmit_ready_cancel (incoming_th);
+      incoming_th = NULL;
+    }
     GNUNET_CADET_channel_destroy (incoming_ch);
     incoming_ch = NULL;
   }
@@ -372,8 +393,9 @@
 gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext 
*tc)
 {
   disconnect_task = NULL;
+  long l = (long) cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", 
l);
 
   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
   {
@@ -385,6 +407,11 @@
 
   if (NULL != ch)
   {
+    if (NULL != th)
+    {
+      GNUNET_CADET_notify_transmit_ready_cancel (th);
+      th = NULL;
+    }
     GNUNET_CADET_channel_destroy (ch);
     ch = NULL;
   }
@@ -426,7 +453,7 @@
 
 
 /**
- * Task to schedule a new data transmission.
+ * Task to request a new data transmission.
  *
  * @param cls Closure (peer #).
  * @param tc Task Context.
@@ -434,8 +461,9 @@
 static void
 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct GNUNET_CADET_TransmitHandle *th;
   struct GNUNET_CADET_Channel *channel;
+  static struct GNUNET_CADET_TransmitHandle **pth;
+
   long src;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
@@ -446,25 +474,25 @@
   if (GNUNET_YES == test_backwards)
   {
     channel = incoming_ch;
+    pth = &incoming_th;
     src = peers_requested - 1;
   }
   else
   {
     channel = ch;
+    pth = &th;
     src = 0;
   }
 
-  if (NULL == channel)
+  GNUNET_assert (NULL != channel);
+  GNUNET_assert (NULL == *pth);
+
+  *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
+                                             GNUNET_TIME_UNIT_FOREVER_REL,
+                                             size_payload + data_sent,
+                                             &tmt_rdy, (void *) src);
+  if (NULL == *pth)
   {
-    GNUNET_break (0);
-    return;
-  }
-  th = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
-                                           GNUNET_TIME_UNIT_FOREVER_REL,
-                                           size_payload + data_sent,
-                                           &tmt_rdy, (void *) src);
-  if (NULL == th)
-  {
     unsigned long i = (unsigned long) cls;
 
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retransmission\n");
@@ -478,9 +506,9 @@
     {
       i++;
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
-                                      GNUNET_TIME_UNIT_MILLISECONDS,
-                                      i),
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
+                                        GNUNET_TIME_UNIT_MILLISECONDS,
+                                        i),
                                     &data_task, (void *) i);
     }
   }
@@ -504,6 +532,12 @@
   unsigned int counter;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy on %ld, filling buffer\n", id);
+  if (0 == id)
+    th = NULL;
+  else if ((peers_requested - 1) == id)
+    incoming_th = NULL;
+  else
+    GNUNET_assert (0);
   counter = get_expected_target () == id ? ack_sent : data_sent;
   msg_size = size_payload + counter;
   if (size < msg_size || NULL == buf)
@@ -551,7 +585,7 @@
 /**
  * Function is called whenever a message is received.
  *
- * @param cls closure (set from GNUNET_CADET_connect)
+ * @param cls closure (set from GNUNET_CADET_connect, peer number)
  * @param channel connection to the other end
  * @param channel_ctx place to store local state associated with the channel
  * @param message the actual message
@@ -563,6 +597,7 @@
                void **channel_ctx,
                const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_CADET_TransmitHandle **pth;
   long client = (long) cls;
   long expected_target_client;
   uint32_t *data;
@@ -590,15 +625,19 @@
   {
   case 0L:
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
+    GNUNET_assert (channel == ch);
+    pth = &th;
     break;
   case 1L:
   case 4L:
     GNUNET_assert (client == peers_requested - 1);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client %li got a message.\n",
+    GNUNET_assert (channel == incoming_ch);
+    pth = &incoming_th;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client %ld got a message.\n",
                 client);
     break;
   default:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %li not valid.\n", client);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %ld not valid.\n", client);
     GNUNET_assert (0);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
@@ -635,10 +674,11 @@
     if (SPEED != test || (ok_goal - 2) == ok)
     {
       /* Send ACK */
-      GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
-                                          GNUNET_TIME_UNIT_FOREVER_REL,
-                                          size_payload + ack_sent, &tmt_rdy,
-                                          (void *) client);
+      GNUNET_assert (NULL == *pth);
+      *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL,
+                                                 size_payload + ack_sent,
+                                                 &tmt_rdy, (void *) client);
       return GNUNET_OK;
     }
     else
@@ -653,10 +693,12 @@
     {
       ack_received++;
       GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
-      GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
-                                          GNUNET_TIME_UNIT_FOREVER_REL,
-                                          size_payload + data_sent, &tmt_rdy,
-                                          (void *) client);
+      /* send more data */
+      GNUNET_assert (NULL == *pth);
+      *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL,
+                                                 size_payload + data_sent,
+                                                 &tmt_rdy, (void *) client);
       if (ack_received < TOTAL_PACKETS && SPEED != test)
         return GNUNET_OK;
       if (ok == 2 && SPEED == test)
@@ -665,11 +707,21 @@
     }
     if (test == P2P_SIGNAL)
     {
+      if (NULL != incoming_th)
+      {
+        GNUNET_CADET_notify_transmit_ready_cancel (incoming_th);
+        incoming_th = NULL;
+      }
       GNUNET_CADET_channel_destroy (incoming_ch);
       incoming_ch = NULL;
     }
     else
     {
+      if (NULL != th)
+      {
+        GNUNET_CADET_notify_transmit_ready_cancel (th);
+        th = NULL;
+      }
       GNUNET_CADET_channel_destroy (ch);
       ch = NULL;
     }
@@ -680,7 +732,8 @@
 
 
 /**
- * Handlers, for diverse services
+ * Data handlers for every message type of CADET's payload.
+ * {callback_function, message_type, size_expected}
  */
 static struct GNUNET_CADET_MessageHandler handlers[] = {
   {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
@@ -733,7 +786,7 @@
  * Function called whenever an inbound channel is destroyed.  Should clean up
  * any associated state.
  *
- * @param cls closure (set from GNUNET_CADET_connect)
+ * @param cls closure (set from GNUNET_CADET_connect, peer number)
  * @param channel connection to the other end (henceforth invalid)
  * @param channel_ctx place where local state associated
  *                   with the channel is stored
@@ -781,7 +834,7 @@
  * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
  *
  * Testcase continues when the root receives confirmation of connected peers,
- * on callback funtion ch.
+ * on callback function ch.
  *
  * @param cls Closure (unused).
  * @param tc Task Context.
@@ -794,7 +847,7 @@
   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
     return;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
 
   if (NULL != disconnect_task)
   {
@@ -820,10 +873,10 @@
   data_sent = 0;
   ack_received = 0;
   ack_sent = 0;
-  GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
-                                      GNUNET_TIME_UNIT_FOREVER_REL,
-                                      size_payload + 1000,
-                                      &tmt_rdy, (void *) 0L);
+  th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
+                                           GNUNET_TIME_UNIT_FOREVER_REL,
+                                           size_payload + 1000,
+                                           &tmt_rdy, (void *) 0L);
 }
 
 /**




reply via email to

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