gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r28302 - gnunet/src/mesh
Date: Wed, 24 Jul 2013 15:41:28 +0200

Author: bartpolot
Date: 2013-07-24 15:41:28 +0200 (Wed, 24 Jul 2013)
New Revision: 28302

Modified:
   gnunet/src/mesh/gnunet-service-mesh-enc.c
Log:
- connection creation function


Modified: gnunet/src/mesh/gnunet-service-mesh-enc.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-07-24 13:40:40 UTC (rev 
28301)
+++ gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-07-24 13:41:28 UTC (rev 
28302)
@@ -419,26 +419,11 @@
   unsigned int queue_max;
 
     /**
-     * Last time the tunnel was used
+     * Last time the channel was used
      */
   struct GNUNET_TIME_Absolute timestamp;
 
     /**
-     * Destination of the tunnel.
-     */
-  GNUNET_PEER_Id dest;
-
-    /**
-     * Next hop in the tunnel. If 0, @c client must be set.
-     */
-  GNUNET_PEER_Id next_hop;
-
-    /**
-     * Previous hop in the tunnel. If 0, @c owner must be set.
-     */
-  GNUNET_PEER_Id prev_hop;
-
-    /**
      * Client owner of the tunnel, if any
      */
   struct MeshClient *owner;
@@ -474,13 +459,13 @@
 };
 
 
-struct MeshPath
+struct MeshConnection
 {
   /**
    * DLL
    */
-  struct MeshPath next;
-  struct MeshPath prev;
+  struct MeshConnection next;
+  struct MeshConnection prev;
 
   /**
    * Path being used for the tunnel.
@@ -488,6 +473,11 @@
   struct MeshPeerPath *path;
 
   /**
+   * Position of the local peer in the path.
+   */
+  unsigned int own_pos;
+
+  /**
    * Task to keep the used paths alive at the owner,
    * time tunnel out on all the other peers.
    */
@@ -562,8 +552,8 @@
   /**
    * Paths that are actively used to reach the destination peer.
    */
-  struct MeshPath *connection_head;
-  struct MeshPath *connection_tail;
+  struct MeshConnection *connection_head;
+  struct MeshConnection *connection_tail;
 
   /**
    * Channels inside this tunnel.
@@ -1255,17 +1245,14 @@
 static void
 send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                        GNUNET_PEER_Id peer,
-                       struct MeshTunnel *t)
+                       struct MeshTunnel2 *t)
 {
-  struct GNUNET_PeerIdentity id;
   struct MeshPeer *neighbor;
   struct MeshPeerPath *p;
   void *data;
   size_t size;
   uint16_t type;
 
-//   GNUNET_TRANSPORT_try_connect(); FIXME use?
-
   if (0 == peer)
     return;
 
@@ -1281,8 +1268,7 @@
     u = (struct GNUNET_MESH_Data *) data;
     u->ttl = htonl (ntohl (u->ttl) - 1);
   }
-  GNUNET_PEER_resolve (peer, &id);
-  neighbor = peer_get (&id);
+  neighbor = peer_get_short (peer);
   for (p = neighbor->path_head; NULL != p; p = p->next)
   {
     if (2 >= p->length)
@@ -1292,30 +1278,6 @@
   }
   if (NULL == p)
   {
-#if MESH_DEBUG
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "  %s IS NOT DIRECTLY CONNECTED\n",
-                GNUNET_i2s(&id));
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "  PATHS TO %s:\n",
-                GNUNET_i2s(&id));
-    for (p = neighbor->path_head; NULL != p; p = p->next)
-    {
-      struct GNUNET_PeerIdentity debug_id;
-      unsigned int i;
-
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "    path with %u hops through:\n",
-                  p->length);
-      for (i = 0; i < p->length; i++)
-      {
-        GNUNET_PEER_resolve(p->peers[i], &debug_id);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "      hop %u: %s\n",
-                    i, GNUNET_i2s(&debug_id));
-      }
-    }
-#endif
     GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                     " no direct connection to %s\n",
@@ -1323,7 +1285,7 @@
     GNUNET_free (data);
     return;
   }
-  if (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK == type)
+  if (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK == type) // FIXME
     type = 0;
   queue_add (data,
              type,
@@ -1333,6 +1295,24 @@
 }
 
 
+GNUNET_PEER_Id
+connection_get_prev_hop (struct MeshConnection *c)
+{
+  if (0 == c->own_pos || c->path->length < 2)
+    return c->path->peers[0];
+  return c->path->peers[c->own_pos - 1];
+}
+
+
+GNUNET_PEER_Id
+connection_get_next_hop (struct MeshConnection *c)
+{
+  if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
+    return c->path->peers[c->path->length - 1];
+  return c->path->peers[c->own_pos + 1];
+}
+
+
 /**
  * Sends a CREATE PATH message for a path to a peer, properly registrating
  * all used resources.
@@ -1340,19 +1320,22 @@
  * @param t Tunnel for which the path is created.
  */
 static void
-send_path_create (struct MeshTunnel *t)
+send_connection_create (struct MeshTunnel2 *t,
+                        struct MeshConnection *connection)
 {
   struct MeshPeer *neighbor;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send create path\n");
-  neighbor = peer_get_short (t->next_hop);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
+  neighbor = peer_get_short (connection_get_next_hop (connection));
   queue_add (t,
              GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE,
              sizeof (struct GNUNET_MESH_CreateTunnel) +
-                (t->path->length * sizeof (struct GNUNET_PeerIdentity)),
+                (connection->path->length *
+                 sizeof (struct GNUNET_PeerIdentity)),
              neighbor,
              t);
-  tunnel_change_state (t, MESH_TUNNEL_WAITING);
+  if (MESH_TUNNEL_SEARCHING == t->state)
+    tunnel_change_state (t, MESH_TUNNEL_WAITING);
 }
 
 




reply via email to

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