gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19733 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r19733 - gnunet/src/mesh
Date: Wed, 8 Feb 2012 16:23:34 +0100

Author: bartpolot
Date: 2012-02-08 16:23:34 +0100 (Wed, 08 Feb 2012)
New Revision: 19733

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api.c
   gnunet/src/mesh/test_mesh_small.c
Log:
Attemp to fix ctrl-c crashes - disconnect from services before calling 
daemons_stop, since the cfg is free'd in the latter.

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2012-02-08 14:07:32 UTC (rev 
19732)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2012-02-08 15:23:34 UTC (rev 
19733)
@@ -1614,7 +1614,7 @@
                                          GNUNET_TIME_UNIT_FOREVER_REL,  /* 
timeout */
                                          GNUNET_BLOCK_TYPE_TEST,        /* 
type */
                                          &id.hashPubKey,        /* key to 
search */
-                                         4,     /* replication level */
+                                         10U,     /* replication level */
                                          GNUNET_DHT_RO_RECORD_ROUTE | 
GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL,       /* xquery */
                                          0,     /* xquery bits */
                                          &dht_get_id_handler, path_info);

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2012-02-08 14:07:32 UTC (rev 19732)
+++ gnunet/src/mesh/mesh_api.c  2012-02-08 15:23:34 UTC (rev 19733)
@@ -207,6 +207,11 @@
    * Time to the next reconnect in case one reconnect fails
    */
   struct GNUNET_TIME_Relative reconnect_time;
+  
+  /**
+   * Task for trying to reconnect.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
 };
 
 
@@ -629,7 +634,7 @@
     for (napps = 0; napps < h->n_applications; napps++)
     {
       apps[napps] = htonl (h->applications[napps]);
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:  app %u\n", h->applications[napps]);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " app %u\n", h->applications[napps]);
     }
     types = (uint16_t *) & apps[napps];
     for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
@@ -637,7 +642,7 @@
     msg->applications = htons (napps);
     msg->types = htons (ntypes);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "mesh: Sending %lu bytes long message %d types and %d apps\n",
+         "Sending %lu bytes long message %d types and %d apps\n",
          ntohs (msg->header.size), ntypes, napps);
     send_packet (h, &msg->header, NULL);
   }
@@ -653,14 +658,14 @@
  * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
  */
 static int
-reconnect (struct GNUNET_MESH_Handle *h)
+do_reconnect (struct GNUNET_MESH_Handle *h)
 {
   struct GNUNET_MESH_Tunnel *t;
   unsigned int i;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *******   RECONNECT   *******\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "*******   RECONNECT   *******\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
 
   h->in_receive = GNUNET_NO;
   /* disconnect */
@@ -678,12 +683,13 @@
   h->client = GNUNET_CLIENT_connect ("mesh", h->cfg);
   if (h->client == NULL)
   {
-    GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
+    h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
+                                                      &reconnect_cbk, h);
     h->reconnect_time =
         GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
                                   GNUNET_TIME_relative_multiply
                                   (h->reconnect_time, 2));
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   Next retry in %sms\n",
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  Next retry in %sms\n",
          GNUNET_TIME_relative_to_string (h->reconnect_time));
     GNUNET_break (0);
     return GNUNET_NO;
@@ -752,12 +758,29 @@
 {
   struct GNUNET_MESH_Handle *h = cls;
 
-  if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
-  reconnect (h);
+  do_reconnect (h);
 }
 
 
+/**
+ * Reconnect to the service, retransmit all infomation to try to restore the
+ * original state.
+ *
+ * @param h handle to the mesh
+ *
+ * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ */
+static void
+reconnect (struct GNUNET_MESH_Handle *h)
+{
+  if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
+    GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
+}
+
+
 
/******************************************************************************/
 /***********************      RECEIVE HANDLERS     
****************************/
 
/******************************************************************************/
@@ -800,7 +823,7 @@
     atsi.value = 0;
     t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: new incoming tunnel %X\n", t->tid);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "new incoming tunnel %X\n", t->tid);
   return;
 }
 
@@ -829,7 +852,7 @@
   {
     GNUNET_break (0);
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %u destroyed\n", t->tid);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %u destroyed\n", t->tid);
   destroy_tunnel (t, GNUNET_YES);
   return;
 }
@@ -851,7 +874,7 @@
   GNUNET_PEER_Id id;
   uint16_t size;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processig peer event\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "processig peer event\n");
   size = ntohs (msg->header.size);
   if (size != sizeof (struct GNUNET_MESH_PeerControl))
   {
@@ -869,7 +892,7 @@
     p = add_peer_to_tunnel (t, &msg->peer);
   if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type))
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: adding peer\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "adding peer\n");
     if (NULL != t->connect_handler)
     {
       atsi.type = 0;
@@ -880,7 +903,7 @@
   }
   else
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: removing peer\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "removing peer\n");
     if (NULL != t->disconnect_handler && p->connected)
     {
       t->disconnect_handler (t->cls, &msg->peer);
@@ -888,7 +911,7 @@
     remove_peer_from_tunnel (p);
     GNUNET_free (p);
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processing peer event END\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "processing peer event END\n");
 }
 
 
@@ -915,7 +938,7 @@
   unsigned int i;
   uint16_t type;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Got a data message!\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
   type = ntohs (message->type);
   switch (type)
   {
@@ -925,7 +948,7 @@
     t = retrieve_tunnel (h, ntohl (ucast->tid));
     payload = (struct GNUNET_MessageHeader *) &ucast[1];
     peer = &ucast->oid;
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   ucast on tunnel %s [%x]\n",
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  ucast on tunnel %s [%x]\n",
          GNUNET_i2s (peer), ntohl (ucast->tid));
     break;
   case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
@@ -933,7 +956,7 @@
     t = retrieve_tunnel (h, ntohl (mcast->tid));
     payload = (struct GNUNET_MessageHeader *) &mcast[1];
     peer = &mcast->oid;
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   mcast on tunnel %s [%x]\n",
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  mcast on tunnel %s [%x]\n",
          GNUNET_i2s (peer), ntohl (mcast->tid));
     break;
   case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
@@ -941,7 +964,7 @@
     t = retrieve_tunnel (h, ntohl (to_orig->tid));
     payload = (struct GNUNET_MessageHeader *) &to_orig[1];
     peer = &to_orig->sender;
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   torig on tunnel %s [%x]\n",
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  torig on tunnel %s [%x]\n",
          GNUNET_i2s (peer), ntohl (to_orig->tid));
     break;
   default:
@@ -995,10 +1018,11 @@
 
   if (msg == NULL)
   {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL msg\n");
     reconnect (h);
     return;
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: received a message type %hu from 
MESH\n",
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "received a message type %hu from MESH\n",
        ntohs (msg->type));
   switch (ntohs (msg->type))
   {
@@ -1028,7 +1052,7 @@
          "MESH: unsolicited message form service (type %d)\n",
          ntohs (msg->type));
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
   GNUNET_CLIENT_receive (h->client, &msg_received, h,
                          GNUNET_TIME_UNIT_FOREVER_REL);
 }
@@ -1057,11 +1081,12 @@
   size_t tsize;
   size_t psize;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() Buffer %u\n", size);
   h->th = NULL;
   if ((0 == size) || (NULL == buf))
   {
-    reconnect (h);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL callback\n");
+//     reconnect (h); FIXME
     return 0;
   }
   tsize = 0;
@@ -1078,7 +1103,7 @@
         GNUNET_assert (size >= th->size);
         mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
         psize = th->notify (th->notify_cls, size - sizeof (to), mh);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   to origin, type %u\n",
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "  to origin, type %u\n",
              ntohs (mh->type));
         if (psize > 0)
         {
@@ -1101,7 +1126,7 @@
         GNUNET_assert (size >= th->size);
         mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
         psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   multicast, type %u\n",
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "  multicast, type %u\n",
              ntohs (mh->type));
         if (psize > 0)
         {
@@ -1125,7 +1150,7 @@
         GNUNET_assert (size >= th->size);
         mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
         psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   unicast, type %u\n",
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "  unicast, type %u\n",
              ntohs (mh->type));
         if (psize > 0)
         {
@@ -1158,17 +1183,17 @@
     size -= psize;
     tsize += psize;
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   total size: %u\n", tsize);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  total size: %u\n", tsize);
   if (NULL != (th = h->th_head))
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:   next size: %u\n", th->size);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  next size: %u\n", th->size);
     if (NULL == h->th)
       h->th =
           GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
                                                GNUNET_TIME_UNIT_FOREVER_REL,
                                                GNUNET_YES, &send_callback, h);
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() END\n");
   if (GNUNET_NO == h->in_receive)
   {
     h->in_receive = GNUNET_YES;
@@ -1248,7 +1273,7 @@
 {
   struct GNUNET_MESH_Handle *h;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n");
   h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
   h->cfg = cfg;
   h->max_queue_size = queue_size;
@@ -1272,7 +1297,7 @@
   for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
   for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
   send_connect (h);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n");
   return h;
 }
 
@@ -1299,7 +1324,7 @@
     if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
     {
       GNUNET_break (0);
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %X not destroyed\n", t->tid);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X not destroyed\n", t->tid);
     }
     destroy_tunnel (t, GNUNET_YES);
     t = aux;
@@ -1321,7 +1346,7 @@
         break;
       default:
         GNUNET_break (0);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: unexpected msg %u\n",
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "unexpected msg %u\n",
              ntohs(msg->type));
     }
 
@@ -1339,6 +1364,11 @@
     GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
     handle->client = NULL;
   }
+  if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel(handle->reconnect_task);
+    handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   GNUNET_free (handle);
 }
 
@@ -1362,7 +1392,7 @@
   struct GNUNET_MESH_Tunnel *t;
   struct GNUNET_MESH_TunnelMessage msg;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new tunnel\n");
   t = create_tunnel (h, 0);
   t->connect_handler = connect_handler;
   t->disconnect_handler = disconnect_handler;
@@ -1389,7 +1419,7 @@
   struct GNUNET_MESH_TunnelMessage msg;
   struct GNUNET_MESH_TransmitHandle *th;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel\n");
   h = tunnel->mesh;
 
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
@@ -1564,11 +1594,11 @@
   size_t overhead;
 
   GNUNET_assert (NULL != tunnel);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: mesh notify transmit ready called\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh notify transmit ready called\n");
   if (NULL != target)
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:     target %s\n", GNUNET_i2s 
(target));
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "    target %s\n", GNUNET_i2s (target));
   else
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh:     target multicast\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "    target multicast\n");
   GNUNET_assert (NULL != notify);
   if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
       tunnel->npackets > 0)

Modified: gnunet/src/mesh/test_mesh_small.c
===================================================================
--- gnunet/src/mesh/test_mesh_small.c   2012-02-08 14:07:32 UTC (rev 19732)
+++ gnunet/src/mesh/test_mesh_small.c   2012-02-08 15:23:34 UTC (rev 19733)
@@ -26,7 +26,9 @@
 #include "platform.h"
 #include "gnunet_testing_lib.h"
 #include "gnunet_mesh_service.h"
+#include <gauger.h>
 
+
 #define VERBOSE GNUNET_YES
 #define REMOVE_DIR GNUNET_YES
 
@@ -217,6 +219,22 @@
     disconnect_task = GNUNET_SCHEDULER_NO_TASK;
   }
 
+  if (NULL != h1)
+  {
+    GNUNET_MESH_disconnect (h1);
+    h1 = NULL;
+  }
+  if (NULL != h2)
+  {
+    GNUNET_MESH_disconnect (h2);
+    h2 = NULL;
+  }
+  if (test == MULTICAST && NULL != h3)
+  {
+    GNUNET_MESH_disconnect (h3);
+    h3 = NULL;
+  }
+  
   if (data_file != NULL)
     GNUNET_DISK_file_close (data_file);
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -250,8 +268,12 @@
   }
   GNUNET_MESH_disconnect (h1);
   GNUNET_MESH_disconnect (h2);
+  h1 = h2 = NULL;
   if (test == MULTICAST)
+  {
     GNUNET_MESH_disconnect (h3);
+    h3 = NULL;
+  }
   if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
   {
     GNUNET_SCHEDULER_cancel (shutdown_handle);
@@ -376,11 +398,14 @@
         return GNUNET_OK;
       end_time = GNUNET_TIME_absolute_get();
       total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
-      FPRINTF (stderr, "\nTest time %llu ms\n", total_time.rel_value);
+      FPRINTF (stderr, "\nTest time %llu ms\n",
+               (unsigned long long) total_time.rel_value);
       FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
                4000.0 / total_time.rel_value);
       FPRINTF (stderr, "Test throughput: %f packets/s\n",
                1000000.0 / total_time.rel_value);
+      GAUGER ("MESH", "Tunnel 5 peers", 1000000.0 / total_time.rel_value,
+              "packets/s");
     }
     GNUNET_MESH_tunnel_destroy (tunnel);
     if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)




reply via email to

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