gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r17137 - gnunet/src/mesh
Date: Fri, 30 Sep 2011 14:51:57 +0200

Author: bartpolot
Date: 2011-09-30 14:51:57 +0200 (Fri, 30 Sep 2011)
New Revision: 17137

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
Log:
Added send path create on new peer with direct connection, added resource 
liberation on neighbor disconnection which queued messages

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-09-30 11:20:44 UTC (rev 
17136)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-09-30 12:51:57 UTC (rev 
17137)
@@ -146,9 +146,14 @@
     /**
      * Pointer to info stuctures used as cls for queued transmissions
      */
-  struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE];
+  void *infos[CORE_QUEUE_SIZE];
 
     /**
+     * Type of message being in each transmission
+     */
+  uint16_t types[CORE_QUEUE_SIZE];
+
+    /**
      * Array of tunnels this peer participates in
      * (most probably a small amount, therefore not a hashmap)
      * When the path to the peer changes, notify these tunnels to let them
@@ -1318,6 +1323,7 @@
 
     GNUNET_PEER_resolve(info->peer->id, &id);
     info->peer->infos[info->handler_n] = info;
+    info->peer->types[info->handler_n] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
     info->peer->core_transmit[info->handler_n] =
       GNUNET_CORE_notify_transmit_ready (core_handle,
                                          0,
@@ -1802,6 +1808,7 @@
     }
     info->handler_n = i;
     info->peer->infos[i] = info;
+    info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
     info->peer->core_transmit[i] =
         GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
                                            GNUNET_TIME_UNIT_FOREVER_REL, id,
@@ -2612,10 +2619,11 @@
                           const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_PeerControl *peer_msg;
+  struct MeshPathInfo *path_info;
+  struct MeshPeerInfo *peer_info;
   struct MeshClient *c;
   struct MeshTunnel *t;
   MESH_TunnelNumber tid;
-  struct MeshPeerInfo *peer_info;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
   /* Sanity check for client registration */
@@ -2659,8 +2667,6 @@
   /* Start DHT search if needed, otherwise just add peer to tunnel. */
   if (NULL == peer_info->dhtget && NULL == peer_info->path_head)
   {
-    struct MeshPathInfo *path_info;
-
     path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
     path_info->peer = peer_info;
     path_info->t = t;
@@ -2675,10 +2681,37 @@
                                             &dht_get_id_handler,
                                             (void *) path_info);
   }
-  if (NULL != peer_info->path_head)
+  else if (NULL != peer_info->path_head)
   {
+    unsigned int i;
+    for (i = 0; i < CORE_QUEUE_SIZE; i++)
+    {
+      if (NULL == peer_info->core_transmit[i])
+        break;
+    }
+    if (CORE_QUEUE_SIZE == i)
+    {
+      GNUNET_break (0);
+      GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      return;
+    }
+    path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
+    path_info->peer = peer_info;
+    path_info->t = t;
     tunnel_add_peer(t, peer_info);
+    path_info->path = tree_get_path_to_peer(t->tree, peer_info->id);
+    peer_info = peer_info_get(path_get_first_hop(t->tree, 
path_info->peer->id));
+    peer_info->infos[i] = path_info;
+    peer_info->types[i] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
+    peer_info->core_transmit[i] =
+      GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
+                                         GNUNET_TIME_UNIT_FOREVER_REL,
+                                         path_get_first_hop(t->tree,
+                                                            
path_info->peer->id),
+                                         sizeof (struct GNUNET_MessageHeader),
+                                         &send_core_create_path, path_info);
   }
+  /* Otherwise: there is no path yet, but there is a DHT_get active already. */
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
   return;
 }
@@ -3095,8 +3128,27 @@
   {
     if (pi->core_transmit[i])
     {
+      struct MeshDataDescriptor *dd;
+      struct MeshPathInfo *path_info;
       GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit[i]);
       /* TODO: notify that tranmission has failed */
+      switch (pi->types[i])
+      {
+        case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+        case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+        case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+          dd = pi->infos[i];
+          if (0 == --(*dd->copies))
+          {
+            GNUNET_free (dd->copies);
+            GNUNET_free (dd->data);
+          }
+          break;
+        case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
+          path_info = pi->infos[i];
+          path_destroy(path_info->path);
+          break;
+      }
       GNUNET_free (pi->infos[i]);
     }
   }




reply via email to

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