gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r17286 - gnunet/src/mesh
Date: Fri, 7 Oct 2011 15:15:42 +0200

Author: bartpolot
Date: 2011-10-07 15:15:42 +0200 (Fri, 07 Oct 2011)
New Revision: 17286

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
Log:
Refactored sending a CREATE PATH message

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-10-07 13:09:36 UTC (rev 
17285)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-10-07 13:15:42 UTC (rev 
17286)
@@ -716,6 +716,20 @@
 
 
 /**
+ * Function called to notify a client about the socket
+ * being ready to queue more data.  "buf" will be
+ * NULL and "size" zero if the socket was closed for
+ * writing in the meantime.
+ *
+ * @param cls closure
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+static size_t
+send_core_create_path (void *cls, size_t size, void *buf);
+
+/**
  * Cancel a core transmission that was already requested and free all resources
  * associated to the request.
  * 
@@ -826,20 +840,46 @@
 
 
 /**
- * Function called to notify a client about the socket
- * being ready to queue more data.  "buf" will be
- * NULL and "size" zero if the socket was closed for
- * writing in the meantime.
- *
- * @param cls closure
- * @param size number of bytes available in buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * Sends a CREATE PATH message for a path to a peer, properly registrating
+ * all used resources.
+ * 
+ * @param peer PeerInfo of the final peer for whom this path is being created.
+ * @param p Path itself.
+ * @param t Tunnel for which the path is created.
  */
-static size_t
-send_core_create_path (void *cls, size_t size, void *buf);
+static void
+send_create_path (struct MeshPeerInfo *peer,
+                  struct MeshPeerPath *p,
+                  struct MeshTunnel *t)
+{
+  struct GNUNET_PeerIdentity *id;
+  struct MeshPathInfo *path_info;
+  struct MeshPeerInfo *neighbor;
 
+  path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
+  path_info->path = p;
+  path_info->peer = peer;
+  path_info->t = t;
+  id = path_get_first_hop(t->tree, peer->id);
+  neighbor = peer_info_get(id);
+  path_info->pos = peer_info_transmit_position(neighbor);
+  neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
+  neighbor->infos[path_info->pos] = path_info;
+  neighbor->core_transmit[path_info->pos] = 
+      GNUNET_CORE_notify_transmit_ready (
+          core_handle, /* handle */
+          0, /* cork */
+          0, /* priority */
+          GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
+          id, /* target */
+          sizeof (struct GNUNET_MESH_ManipulatePath)
+          + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
+          &send_core_create_path, /* callback */
+          path_info);        /* cls */
+  
+}
 
+
 /**
  * Try to establish a new connection to this peer.
  * Use the best path for the given tunnel.
@@ -854,35 +894,13 @@
 {
   struct MeshPeerPath *p;
   struct MeshPathInfo *path_info;
-  struct MeshPeerInfo *neighbor;
 
   if (NULL != peer->path_head)
   {
     p = tree_get_path_to_peer(t->tree, peer->id);
     if (p->length > 1)
     {
-      struct GNUNET_PeerIdentity *id;
-
-      path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
-      path_info->path = p;
-      path_info->peer = peer;
-      path_info->t = t;
-      id = path_get_first_hop(t->tree, peer->id);
-      neighbor = peer_info_get(id);
-      path_info->pos = peer_info_transmit_position(neighbor);
-      neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
-      neighbor->infos[path_info->pos] = path_info;
-      neighbor->core_transmit[path_info->pos] = 
-          GNUNET_CORE_notify_transmit_ready (
-              core_handle, /* handle */
-              0, /* cork */
-              0, /* priority */
-              GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
-              id, /* target */
-              sizeof (struct GNUNET_MESH_ManipulatePath)
-              + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */
-              &send_core_create_path, /* callback */
-              path_info);        /* cls */
+      send_create_path(peer, p, t);
     }
     else
     {




reply via email to

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