gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r30095 - gnunet/src/mesh
Date: Thu, 10 Oct 2013 16:15:33 +0200

Author: bartpolot
Date: 2013-10-10 16:15:33 +0200 (Thu, 10 Oct 2013)
New Revision: 30095

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_peer.c
   gnunet/src/mesh/gnunet-service-mesh_peer.h
Log:
- move path manipulation to API


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 14:03:59 UTC 
(rev 30094)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 14:15:33 UTC 
(rev 30095)
@@ -32,7 +32,6 @@
 #include "mesh_path.h"
 #include "mesh_protocol_enc.h"
 #include "mesh_enc.h"
-
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_peer.h"
 #include "gnunet-service-mesh_tunnel.h"
@@ -1078,7 +1077,7 @@
   if (c->own_pos == size - 1)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  It's for us!\n");
-    peer_add_path_to_origin (orig_peer, path, GNUNET_YES);
+    GMP_add_path_to_origin (orig_peer, path, GNUNET_YES);
 
     if (NULL == orig_peer->tunnel)
     {
@@ -1100,8 +1099,8 @@
   {
     /* It's for somebody else! Retransmit. */
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  Retransmitting.\n");
-    peer_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
-    peer_add_path_to_origin (orig_peer, path, GNUNET_NO);
+    GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
+    GMP_add_path_to_origin (orig_peer, path, GNUNET_NO);
     GMC_send_prebuilt_message (message, c, NULL, GNUNET_YES);
   }
   return GNUNET_OK;

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-10 14:03:59 UTC (rev 
30094)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-10 14:15:33 UTC (rev 
30095)
@@ -202,6 +202,11 @@
  */
 const static struct GNUNET_PeerIdentity *my_full_id;
 
+/**
+ * Local peer own ID (short)
+ */
+static GNUNET_PEER_Id my_short_id;
+
 
/******************************************************************************/
 /***************************** CORE CALLBACKS 
*********************************/
 
/******************************************************************************/
@@ -764,140 +769,6 @@
 
 
 /**
- * Add the path to the peer and update the path used to reach it in case this
- * is the shortest.
- *
- * @param peer_info Destination peer to add the path to.
- * @param path New path to add. Last peer must be the peer in arg 1.
- *             Path will be either used of freed if already known.
- * @param trusted Do we trust that this path is real?
- */
-void
-peer_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
-               int trusted)
-{
-  struct MeshPeerPath *aux;
-  unsigned int l;
-  unsigned int l2;
-
-  if ((NULL == peer_info) || (NULL == path))
-  {
-    GNUNET_break (0);
-    path_destroy (path);
-    return;
-  }
-    if (path->peers[path->length - 1] != peer_info->id)
-    {
-      GNUNET_break (0);
-      path_destroy (path);
-      return;
-    }
-      if (2 >= path->length && GNUNET_NO == trusted)
-      {
-        /* Only allow CORE to tell us about direct paths */
-        path_destroy (path);
-        return;
-      }
-        for (l = 1; l < path->length; l++)
-        {
-          if (path->peers[l] == myid)
-          {
-            LOG (GNUNET_ERROR_TYPE_DEBUG, "shortening path by %u\n", l);
-            for (l2 = 0; l2 < path->length - l; l2++)
-            {
-              path->peers[l2] = path->peers[l + l2];
-            }
-                  path->length -= l;
-                  l = 1;
-                  path->peers =
-                            GNUNET_realloc (path->peers, path->length * sizeof 
(GNUNET_PEER_Id));
-          }
-        }
-
-          LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
-                      path->length, peer2s (peer_info));
-
-          l = path_get_length (path);
-          if (0 == l)
-          {
-            path_destroy (path);
-            return;
-          }
-
-            GNUNET_assert (peer_info->id == path->peers[path->length - 1]);
-            for (aux = peer_info->path_head; aux != NULL; aux = aux->next)
-            {
-              l2 = path_get_length (aux);
-              if (l2 > l)
-              {
-                GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
-                                                    peer_info->path_tail, aux, 
path);
-                return;
-              }
-                  else
-                  {
-                    if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
-                    {
-                      path_destroy (path);
-                      return;
-                    }
-                  }
-            }
-              GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, 
peer_info->path_tail,
-                                                path);
-              return;
-}
-
-
-/**
- * Add the path to the origin peer and update the path used to reach it in case
- * this is the shortest.
- * The path is given in peer_info -> destination, therefore we turn the path
- * upside down first.
- *
- * @param peer_info Peer to add the path to, being the origin of the path.
- * @param path New path to add after being inversed.
- *             Path will be either used or freed.
- * @param trusted Do we trust that this path is real?
- */
-static void
-peer_add_path_to_origin (struct MeshPeer *peer_info,
-                         struct MeshPeerPath *path, int trusted)
-{
-  if (NULL == path)
-    return;
-  path_invert (path);
-  peer_add_path (peer_info, path, trusted);
-}
-
-
-/**
- * Adds a path to the peer_infos of all the peers in the path
- *
- * @param p Path to process.
- * @param confirmed Whether we know if the path works or not.
- */
-static void
-path_add_to_peers (struct MeshPeerPath *p, int confirmed)
-{
-  unsigned int i;
-
-  /* TODO: invert and add */
-  for (i = 0; i < p->length && p->peers[i] != myid; i++) /* skip'em */ ;
-  for (i++; i < p->length; i++)
-  {
-    struct MeshPeer *aux;
-    struct MeshPeerPath *copy;
-
-    aux = peer_get_short (p->peers[i]);
-    copy = path_duplicate (p);
-    copy->length = i + 1;
-    peer_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed);
-  }
-}
-
-
-/**
  * Function to process paths received for a new peer addition. The recorded
  * paths form the initial tunnel, which can be optimized later.
  * Called on each result obtained for the DHT search.
@@ -1452,6 +1323,8 @@
           const struct GNUNET_PeerIdentity *id)
 {
   my_full_id = id;
+  my_short_id = GNUNET_PEER_intern (id);
+
   peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
@@ -1509,6 +1382,7 @@
     GNUNET_CORE_disconnect (core_handle);
     core_handle = NULL;
   }
+  GNUNET_PEER_change_rc (my_short_id, -1);
 }
 
 
@@ -1658,6 +1532,141 @@
 
 
 /**
+ * Add the path to the peer and update the path used to reach it in case this
+ * is the shortest.
+ *
+ * @param peer_info Destination peer to add the path to.
+ * @param path New path to add. Last peer must be the peer in arg 1.
+ *             Path will be either used of freed if already known.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
+              int trusted)
+{
+  struct MeshPeerPath *aux;
+  unsigned int l;
+  unsigned int l2;
+
+  if ((NULL == peer_info) || (NULL == path))
+  {
+    GNUNET_break (0);
+    path_destroy (path);
+    return;
+  }
+  if (path->peers[path->length - 1] != peer_info->id)
+  {
+    GNUNET_break (0);
+    path_destroy (path);
+    return;
+  }
+  if (2 >= path->length && GNUNET_NO == trusted)
+  {
+    /* Only allow CORE to tell us about direct paths */
+    path_destroy (path);
+    return;
+  }
+  for (l = 1; l < path->length; l++)
+  {
+    if (path->peers[l] == myid)
+    {
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "shortening path by %u\n", l);
+      for (l2 = 0; l2 < path->length - l; l2++)
+      {
+        path->peers[l2] = path->peers[l + l2];
+      }
+            path->length -= l;
+            l = 1;
+            path->peers =
+                      GNUNET_realloc (path->peers, path->length * sizeof 
(GNUNET_PEER_Id));
+    }
+  }
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
+              path->length, peer2s (peer_info));
+
+  l = path_get_length (path);
+  if (0 == l)
+  {
+    path_destroy (path);
+    return;
+  }
+
+  GNUNET_assert (peer_info->id == path->peers[path->length - 1]);
+  for (aux = peer_info->path_head; aux != NULL; aux = aux->next)
+  {
+    l2 = path_get_length (aux);
+    if (l2 > l)
+    {
+      GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
+                                          peer_info->path_tail, aux, path);
+      return;
+    }
+        else
+        {
+          if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
+          {
+            path_destroy (path);
+            return;
+          }
+        }
+  }
+  GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail,
+                                    path);
+  return;
+}
+
+
+/**
+ * Add the path to the origin peer and update the path used to reach it in case
+ * this is the shortest.
+ * The path is given in peer_info -> destination, therefore we turn the path
+ * upside down first.
+ *
+ * @param peer_info Peer to add the path to, being the origin of the path.
+ * @param path New path to add after being inversed.
+ *             Path will be either used or freed.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path_to_origin (struct MeshPeer *peer,
+                        struct MeshPeerPath *path,
+                        int trusted)
+{
+  if (NULL == path)
+    return;
+  path_invert (path);
+  GMP_add_path (peer, path, trusted);
+}
+
+
+/**
+ * Adds a path to the info of all the peers in the path
+ *
+ * @param p Path to process.
+ * @param confirmed Whether we know if the path works or not.
+ */
+void
+GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed)
+{
+  unsigned int i;
+
+  /* TODO: invert and add */
+  for (i = 0; i < p->length && p->peers[i] != my_short_id; i++) /* skip'em */ ;
+  for (i++; i < p->length; i++)
+  {
+    struct MeshPeer *aux;
+    struct MeshPeerPath *copy;
+
+    aux = peer_get_short (p->peers[i]);
+    copy = path_duplicate (p);
+    copy->length = i + 1;
+    GMP_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed);
+  }
+}
+
+
+/**
  * Remove a connection from a neighboring peer.
  *
  * @param peer Peer to remove connection from.

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-10 14:03:59 UTC (rev 
30094)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-10 14:15:33 UTC (rev 
30095)
@@ -142,6 +142,43 @@
 GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
 
 /**
+ * Add the path to the peer and update the path used to reach it in case this
+ * is the shortest.
+ *
+ * @param peer_info Destination peer to add the path to.
+ * @param path New path to add. Last peer must be the peer in arg 1.
+ *             Path will be either used of freed if already known.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
+
+/**
+ * Add the path to the origin peer and update the path used to reach it in case
+ * this is the shortest.
+ * The path is given in peer_info -> destination, therefore we turn the path
+ * upside down first.
+ *
+ * @param peer_info Peer to add the path to, being the origin of the path.
+ * @param path New path to add after being inversed.
+ *             Path will be either used or freed.
+ * @param trusted Do we trust that this path is real?
+ */
+void
+GMP_add_path_to_origin (struct MeshPeer *peer_info,
+                        struct MeshPeerPath *path,
+                        int trusted);
+
+/**
+ * Adds a path to the info of all the peers in the path
+ *
+ * @param p Path to process.
+ * @param confirmed Whether we know if the path works or not.
+ */
+void
+GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed);
+
+/**
  * Remove a connection from a neighboring peer.
  *
  * @param peer Peer to remove connection from.




reply via email to

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