Merged changes to destroy_tunnel, removed data pointer in th struct, cancel pending...
authorBart Polot <bart@net.in.tum.de>
Tue, 6 Sep 2011 03:13:55 +0000 (03:13 +0000)
committerBart Polot <bart@net.in.tum.de>
Tue, 6 Sep 2011 03:13:55 +0000 (03:13 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/mesh_api.c
src/mesh/mesh_api_new.c

index f5e8aa8e8ff158696b09e2bea5b18b04c94434cd..87f259c2250672bae90cb1ac8fbcc907ec307e18 100644 (file)
@@ -450,7 +450,7 @@ static unsigned int *applications_rc;
 /**
  * Number of applications provided by this peer
  */
-static unsigned int n_applications;
+static unsigned int n_apps;
 
 /**
  * Task to periodically announce provided applications
@@ -768,6 +768,8 @@ static int
 destroy_tunnel (struct MeshTunnel *t)
 {
   struct MeshClient *c;
+  struct MeshQueue *q;
+  struct MeshQueue *qn;
   GNUNET_HashCode hash;
   int r;
 
@@ -787,6 +789,17 @@ destroy_tunnel (struct MeshTunnel *t)
   {
     r = GNUNET_SYSERR;
   }
+  GNUNET_CONTAINER_multihashmap_destroy(t->peers);
+  q = t->queue_head;
+  while (NULL != q)
+  {
+    if (NULL != q->data)
+      GNUNET_free(q->data);
+    qn = q->next;
+    GNUNET_free(q);
+    q = qn;
+    /* TODO cancel core transmit ready in case it was active */
+  }
   GNUNET_free (t);
   return r;
 }
@@ -817,7 +830,7 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   p = (unsigned int *) &buffer[8];
   GNUNET_PEER_resolve (myid, &id);
-  for (i = 0; i < n_applications; i++)
+  for (i = 0; i < n_apps; i++)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %d\n",
                 applications[i]);
@@ -1999,56 +2012,46 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
   c = clients;
   while (NULL != c)
   {
-    if (c->handle == client)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  " matching client found, cleaning\n");
-      GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry,
-                                             c);
-      GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
-      if (0 != c->app_counter)
-      {                         /* deregister clients applications */
-        for (i = 0; i < c->app_counter; i++)
-        {
-          for (j = 0; j < n_applications; j++)
-          {
-            if (c->apps[i] == applications[j])
-            {
-              if (0 == --applications_rc[j])
-              {
-                applications[j] = applications[n_applications - 1];
-                applications_rc[j] = applications_rc[n_applications - 1];
-                n_applications--;
-                applications =
-                    GNUNET_realloc (applications,
-                                    n_applications *
-                                    sizeof (GNUNET_MESH_ApplicationType));
-                applications_rc =
-                    GNUNET_realloc (applications_rc,
-                                    n_applications * sizeof (unsigned int));
-              }
-              break;
-            }
-          }
-        }
-        GNUNET_free (c->apps);
-        if (0 == n_applications)
-        {
-          GNUNET_SCHEDULER_cancel (announce_applications_task);
-        }
-      }
-      if (0 != c->type_counter)
-        GNUNET_free (c->types);
-      GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c);
-      next = c->next;
-      GNUNET_free (c);
-      c = next;
-    }
-    else
+    if (c->handle != client)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:    ... searching\n");
       c = c->next;
+      continue;
     }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " matching client found, cleaning\n");
+    GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c);
+    GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
+    if (0 != c->app_counter)
+    {
+      /* deregister clients applications */
+      for (i = 0; i < c->app_counter; i++)
+      {
+       for (j = 0; j < n_apps; j++)
+       {
+         if (c->apps[i] == applications[j] && 0 == --applications_rc[j])
+         {
+           applications[j] = applications[n_apps - 1];
+           GNUNET_array_grow(applications, n_apps, n_apps - 1);
+           n_apps++;
+           applications_rc[j] = applications_rc[n_apps - 1];
+           GNUNET_array_grow(applications_rc, n_apps, n_apps - 1);
+
+         }
+         break;
+       }
+      }
+      GNUNET_free (c->apps);
+      if (0 == n_apps)
+      {
+       GNUNET_SCHEDULER_cancel (announce_applications_task);
+      }
+    }
+    if (0 != c->type_counter)
+      GNUNET_free (c->types);
+    GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c);
+    next = c->next;
+    GNUNET_free (c);
+    c = next;
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:    done!\n");
@@ -2109,7 +2112,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
   for (i = 0; i < apps; i++)
   {
     known = GNUNET_NO;
-    for (j = 0; i < n_applications; j++)
+    for (j = 0; i < n_apps; j++)
     {
       if (c->apps[i] == applications[j])
       {
@@ -2119,18 +2122,12 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
       }
     }
     if (!known)
-    {                           /* Register previously unknown application */
-      n_applications++;
-      applications =
-          GNUNET_realloc (applications,
-                          n_applications *
-                          sizeof (GNUNET_MESH_ApplicationType));
-      applications_rc =
-          GNUNET_realloc (applications_rc,
-                          n_applications * sizeof (unsigned int));
-      applications[n_applications - 1] = c->apps[i];
-      applications_rc[n_applications - 1] = 1;
-      if (0 == announce_applications_task)
+    {
+      /* Register previously unknown application */
+      GNUNET_array_append(applications, n_apps, c->apps[i]);
+      n_apps--;
+      GNUNET_array_append(applications_rc, n_apps, 1);
+      if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
       {
         announce_applications_task =
             GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME,
@@ -2480,7 +2477,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
 
   /* Do WE have the service? */
   type = ntohl (connect_msg->type);
-  for (i = 0; i < n_applications; i++)
+  for (i = 0; i < n_apps; i++)
   {
     if (applications[i] == type)
     {
@@ -2872,7 +2869,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
 
   applications = NULL;
   applications_rc = NULL;
-  n_applications = 0;
+  n_apps = 0;
   announce_applications_task = 0;
 
   /* Scheduled the task to clean up when shutdown is called */
index 61559362187cb43993f12f9dd410e0a301bc0109..e40221e08db57cd7c0f6a7a8824ecbfc831aa93a 100644 (file)
@@ -921,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
   GNUNET_free (handle);
 }
 
-/* end of mesh_api.c */
\ No newline at end of file
+/* end of mesh_api.c *
\ No newline at end of file
index 817c5fb3eead8e6974cedf066bd59f2bf20de36c..03c511adf69f05f52564e99022d45e3f954a43c1 100644 (file)
@@ -24,6 +24,7 @@
  * - callbacks to client missing on certain events
  * - processing messages from service is incomplete
  * - Check priorities to cancel traffic data
+ * - Use separate message types for tunnel creation s -> c (+pi) and c -> s
  *
  * STRUCTURE:
  * - CONSTANTS
@@ -379,6 +380,13 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t)
   unsigned int i;
 
   if (NULL == t)
+  {
+    GNUNET_break(0);
+    return;
+  }
+  h = t->mesh;
+  th = h->th_head;
+  while (NULL != th)
   {
     if (th->tunnel == t)
     {
@@ -401,8 +409,6 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t)
       th = th->next;
     }
   }
-  h = t->mesh;
-  /* TODO remove data packets from queue */
   GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
   for (i = 0; i < t->npeers; i++)
   {