gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r29843 - gnunet/src/mesh
Date: Fri, 4 Oct 2013 17:08:12 +0200

Author: bartpolot
Date: 2013-10-04 17:08:12 +0200 (Fri, 04 Oct 2013)
New Revision: 29843

Modified:
   gnunet/src/mesh/gnunet-service-mesh-enc.c
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_dht.c
   gnunet/src/mesh/gnunet-service-mesh_local.c
   gnunet/src/mesh/gnunet-service-mesh_peer.c
Log:
- sync


Modified: gnunet/src/mesh/gnunet-service-mesh-enc.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-10-04 14:41:54 UTC (rev 
29842)
+++ gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-10-04 15:08:12 UTC (rev 
29843)
@@ -496,33 +496,8 @@
 }
 
 
-/**
- * Get string description for tunnel state.
- *
- * @param s Tunnel state.
- *
- * @return String representation. 
- */
-static const char *
-GNUNET_MESH_DEBUG_CS2S (enum MeshTunnelState s)
-{
-  switch (s) 
-  {
-    case MESH_CONNECTION_NEW:
-      return "MESH_CONNECTION_NEW";
-    case MESH_CONNECTION_SENT:
-      return "MESH_CONNECTION_SENT";
-    case MESH_CONNECTION_ACK:
-      return "MESH_CONNECTION_ACK";
-    case MESH_CONNECTION_READY:
-      return "MESH_CONNECTION_READY";
-    default:
-      return "MESH_CONNECTION_STATE_ERROR";
-  }
-}
 
 
-
 
/******************************************************************************/
 /******************      GENERAL HELPER FUNCTIONS      
************************/
 
/******************************************************************************/
@@ -913,93 +888,8 @@
   return sizeof (struct GNUNET_MESH_ConnectionACK);
 }
 
-/**
- * Build a PeerPath from the paths returned from the DHT, reversing the paths
- * to obtain a local peer -> destination path and interning the peer ids.
- *
- * @return Newly allocated and created path
- */
-static struct MeshPeerPath *
-path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
-                     unsigned int get_path_length,
-                     const struct GNUNET_PeerIdentity *put_path,
-                     unsigned int put_path_length)
-{
-  struct MeshPeerPath *p;
-  GNUNET_PEER_Id id;
-  int i;
 
-  p = path_new (1);
-  p->peers[0] = myid;
-  GNUNET_PEER_change_rc (myid, 1);
-  i = get_path_length;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   GET has %d hops.\n", i);
-  for (i--; i >= 0; i--)
-  {
-    id = GNUNET_PEER_intern (&get_path[i]);
-    if (p->length > 0 && id == p->peers[p->length - 1])
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Optimizing 1 hop out.\n");
-      GNUNET_PEER_change_rc (id, -1);
-    }
-    else
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Adding from GET: %s.\n",
-                  GNUNET_i2s (&get_path[i]));
-      p->length++;
-      p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * 
p->length);
-      p->peers[p->length - 1] = id;
-    }
-  }
-  i = put_path_length;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   PUT has %d hops.\n", i);
-  for (i--; i >= 0; i--)
-  {
-    id = GNUNET_PEER_intern (&put_path[i]);
-    if (id == myid)
-    {
-      /* PUT path went through us, so discard the path up until now and start
-       * from here to get a much shorter (and loop-free) path.
-       */
-      path_destroy (p);
-      p = path_new (0);
-    }
-    if (p->length > 0 && id == p->peers[p->length - 1])
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Optimizing 1 hop out.\n");
-      GNUNET_PEER_change_rc (id, -1);
-    }
-    else
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Adding from PUT: %s.\n",
-                  GNUNET_i2s (&put_path[i]));
-      p->length++;
-      p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * 
p->length);
-      p->peers[p->length - 1] = id;
-    }
-  }
-#if MESH_DEBUG
-  if (get_path_length > 0)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   (first of GET: %s)\n",
-                GNUNET_i2s (&get_path[0]));
-  if (put_path_length > 0)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   (first of PUT: %s)\n",
-                GNUNET_i2s (&put_path[0]));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   In total: %d hops\n",
-              p->length);
-  for (i = 0; i < p->length; i++)
-  {
-    struct GNUNET_PeerIdentity peer_id;
 
-    GNUNET_PEER_resolve (p->peers[i], &peer_id);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "       %u: %s\n", p->peers[i],
-                GNUNET_i2s (&peer_id));
-  }
-#endif
-  return p;
-}
-
-
 /**
  * Adds a path to the peer_infos of all the peers in the path
  *
@@ -1907,40 +1797,16 @@
  * Called on each result obtained for the DHT search.
  *
  * @param cls closure
- * @param exp when will this value expire
- * @param key key of the result
- * @param get_path path of the get request
- * @param get_path_length lenght of get_path
- * @param put_path path of the put request
- * @param put_path_length length of the put_path
- * @param type type of the result
- * @param size number of bytes in data
- * @param data pointer to the result data
+ * @param path
  */
 static void
-dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
-                    const struct GNUNET_HashCode * key,
-                    const struct GNUNET_PeerIdentity *get_path,
-                    unsigned int get_path_length,
-                    const struct GNUNET_PeerIdentity *put_path,
-                    unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
-                    size_t size, const void *data)
+search_handler (void *cls, struct MeshPeerPath *path)
 {
-  struct MeshPeer *peer = cls;
-  struct MeshPeerPath *p;
   struct MeshConnection *c;
-  struct GNUNET_PeerIdentity pi;
   unsigned int connection_count;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got results from DHT!\n");
-  GNUNET_PEER_resolve (peer->id, &pi);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  for %s\n", GNUNET_i2s (&pi));
+  path_add_to_peers (path, GNUNET_NO);
 
-  p = path_build_from_dht (get_path, get_path_length,
-                           put_path, put_path_length);
-  path_add_to_peers (p, GNUNET_NO);
-  path_destroy (p);
-
   /* Count connections */
   connection_count = GMC_count (peer->tunnel->connection_head);
 
@@ -1957,126 +1823,6 @@
 }
 
 
-
-/**
- * Method called whenever a given peer connects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- */
-static void
-core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
-{
-  struct MeshPeer *pi;
-  struct MeshPeerPath *path;
-
-  DEBUG_CONN ("Peer connected\n");
-  DEBUG_CONN ("     %s\n", GNUNET_i2s (&my_full_id));
-  pi = peer_get (peer);
-  if (myid == pi->id)
-  {
-    DEBUG_CONN ("     (self)\n");
-    path = path_new (1);
-  }
-  else
-  {
-    DEBUG_CONN ("     %s\n", GNUNET_i2s (peer));
-    path = path_new (2);
-    path->peers[1] = pi->id;
-    GNUNET_PEER_change_rc (pi->id, 1);
-    GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
-  }
-  path->peers[0] = myid;
-  GNUNET_PEER_change_rc (myid, 1);
-  peer_add_path (pi, path, GNUNET_YES);
-
-  pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
-  return;
-}
-
-
-/**
- * Method called whenever a peer disconnects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- */
-static void
-core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
-{
-  struct MeshPeer *pi;
-
-  DEBUG_CONN ("Peer disconnected\n");
-  pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
-  if (NULL == pi)
-  {
-    GNUNET_break (0);
-    return;
-  }
-
-  GNUNET_CONTAINER_multihashmap_iterate (pi->connections,
-                                         GMC_notify_broken,
-                                         pi);
-  GNUNET_CONTAINER_multihashmap_destroy (pi->connections);
-  pi->connections = NULL;
-  if (NULL != pi->core_transmit)
-    {
-      GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit);
-      pi->core_transmit = NULL;
-    }
-  if (myid == pi->id)
-  {
-    DEBUG_CONN ("     (self)\n");
-  }
-  GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
-
-  return;
-}
-
-
-
-/**
- * To be called on core init/fail.
- *
- * @param cls Closure (config)
- * @param identity the public identity of this peer
- */
-static void
-core_init (void *cls, 
-           const struct GNUNET_PeerIdentity *identity)
-{
-  const struct GNUNET_CONFIGURATION_Handle *c = cls;
-  static int i = 0;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
-  if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                " core id %s\n",
-                GNUNET_i2s (identity));
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                " my id %s\n",
-                GNUNET_i2s (&my_full_id));
-    GNUNET_CORE_disconnect (core_handle);
-    core_handle = GNUNET_CORE_connect (c, /* Main configuration */
-                                       NULL,      /* Closure passed to MESH 
functions */
-                                       &core_init,        /* Call core_init 
once connected */
-                                       &core_connect,     /* Handle connects */
-                                       &core_disconnect,  /* remove peers on 
disconnects */
-                                       NULL,      /* Don't notify about all 
incoming messages */
-                                       GNUNET_NO, /* For header only in 
notification */
-                                       NULL,      /* Don't notify about all 
outbound messages */
-                                       GNUNET_NO, /* For header-only out 
notification */
-                                       core_handlers);    /* Register these 
handlers */
-    if (10 < i++)
-      GNUNET_abort();
-  }
-  server_init ();
-  return;
-}
-
-
 
/******************************************************************************/
 /************************      MAIN FUNCTIONS      
****************************/
 
/******************************************************************************/

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-04 14:41:54 UTC 
(rev 29842)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-04 15:08:12 UTC 
(rev 29843)
@@ -31,6 +31,7 @@
 
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_peer.h"
+#include "gnunet-service-mesh_local.h"
 #include "mesh_protocol_enc.h"
 #include "mesh_path.h"
 
@@ -286,7 +287,35 @@
 static struct GNUNET_CORE_Handle *core_handle;
 
 
+
 /**
+ * Get string description for tunnel state.
+ *
+ * @param s Tunnel state.
+ *
+ * @return String representation. 
+ */
+static const char *
+GMC_DEBUG_state2s (enum MeshTunnelState s)
+{
+  switch (s)
+  {
+    case MESH_CONNECTION_NEW:
+      return "MESH_CONNECTION_NEW";
+    case MESH_CONNECTION_SENT:
+      return "MESH_CONNECTION_SENT";
+    case MESH_CONNECTION_ACK:
+      return "MESH_CONNECTION_ACK";
+    case MESH_CONNECTION_READY:
+      return "MESH_CONNECTION_READY";
+    default:
+      return "MESH_CONNECTION_STATE_ERROR";
+  }
+}
+
+
+
+/**
  * Initialize a Flow Control structure to the initial state.
  * 
  * @param fc Flow Control structure to initialize.
@@ -1483,7 +1512,131 @@
 
 
 
+
+
 /**
+ * Method called whenever a given peer connects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct MeshPeer *pi;
+  struct MeshPeerPath *path;
+
+  DEBUG_CONN ("Peer connected\n");
+  DEBUG_CONN ("     %s\n", GNUNET_i2s (&my_full_id));
+  pi = peer_get (peer);
+  if (myid == pi->id)
+  {
+    DEBUG_CONN ("     (self)\n");
+    path = path_new (1);
+  }
+  else
+  {
+    DEBUG_CONN ("     %s\n", GNUNET_i2s (peer));
+    path = path_new (2);
+    path->peers[1] = pi->id;
+    GNUNET_PEER_change_rc (pi->id, 1);
+    GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
+  }
+  path->peers[0] = myid;
+  GNUNET_PEER_change_rc (myid, 1);
+  peer_add_path (pi, path, GNUNET_YES);
+
+  pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
+  return;
+}
+
+
+/**
+ * Method called whenever a peer disconnects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct MeshPeer *pi;
+
+  DEBUG_CONN ("Peer disconnected\n");
+  pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
+  if (NULL == pi)
+  {
+    GNUNET_break (0);
+    return;
+  }
+
+  GNUNET_CONTAINER_multihashmap_iterate (pi->connections,
+                                         GMC_notify_broken,
+                                         pi);
+  GNUNET_CONTAINER_multihashmap_destroy (pi->connections);
+  pi->connections = NULL;
+  if (NULL != pi->core_transmit)
+    {
+      GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit);
+      pi->core_transmit = NULL;
+    }
+  if (myid == pi->id)
+  {
+    DEBUG_CONN ("     (self)\n");
+  }
+  GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
+
+  return;
+}
+
+
+
+/**
+ * To be called on core init/fail.
+ *
+ * @param cls Closure (config)
+ * @param identity the public identity of this peer
+ */
+static void
+core_init (void *cls, 
+           const struct GNUNET_PeerIdentity *identity)
+{
+  const struct GNUNET_CONFIGURATION_Handle *c = cls;
+  static int i = 0;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
+  if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                " core id %s\n",
+                GNUNET_i2s (identity));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                " my id %s\n",
+                GNUNET_i2s (&my_full_id));
+    GNUNET_CORE_disconnect (core_handle);
+    core_handle = GNUNET_CORE_connect (c, /* Main configuration */
+                                       NULL,      /* Closure passed to MESH 
functions */
+                                       &core_init,        /* Call core_init 
once connected */
+                                       &core_connect,     /* Handle connects */
+                                       &core_disconnect,  /* remove peers on 
disconnects */
+                                       NULL,      /* Don't notify about all 
incoming messages */
+                                       GNUNET_NO, /* For header only in 
notification */
+                                       NULL,      /* Don't notify about all 
outbound messages */
+                                       GNUNET_NO, /* For header-only out 
notification */
+                                       core_handlers);    /* Register these 
handlers */
+    if (10 < i++)
+      GNUNET_abort();
+  }
+  GML_start ();
+  return;
+}
+
+
+
+
+
+/**
  * Core handler for connection creation.
  *
  * @param cls Closure (unused).

Modified: gnunet/src/mesh/gnunet-service-mesh_dht.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_dht.c   2013-10-04 14:41:54 UTC (rev 
29842)
+++ gnunet/src/mesh/gnunet-service-mesh_dht.c   2013-10-04 15:08:12 UTC (rev 
29843)
@@ -24,6 +24,7 @@
 
 #include "gnunet_dht_service.h"
 
+#include "mesh_path.h"
 #include "gnunet-service-mesh_dht.h"
 #include "gnunet-service-mesh_peer.h"
 
@@ -35,13 +36,40 @@
 #define DEBUG_DHT(...)
 #endif
 
+#define LOG (level, ...) GNUNET_log_from ("mesh-dht", level, __VA_ARGS__)
+
+
+
+/**
+ * Callback called on each path found over the DHT.
+ *
+ * @param cls Closure.
+ * @param path An unchecked, unoptimized path to the target node.
+ *             After callback will no longer be valid!
+ */
+typedef void (*GMD_search_callback) (void *cls,
+                                     const struct MeshPeerPath *path);
+
 
/******************************************************************************/
 /********************************   STRUCTS  
**********************************/
 
/******************************************************************************/
 
+/**
+ * Handle for DHT searches.
+ */
+struct GMD_search_handle
+{
+  /** DHT_GET handle. */
+  struct GNUNET_DHT_GetHandle *dhtget;
 
+  /** Provided callback to call when a path is found. */
+  GMD_search_callback callback;
 
+  /** Provided closure. */
+  void *cls;
+};
 
+
 
/******************************************************************************/
 /*******************************   GLOBALS  
***********************************/
 
/******************************************************************************/
@@ -67,9 +95,14 @@
 static GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
 
 /**
+ * Own ID (short value).
+ */
+static GNUNET_PEER_Id short_id;
+
+/**
  * Own ID (full value).
  */
-static struct GNUNET_PeerIdentity *id;
+static struct GNUNET_PeerIdentity *full_id;
 
 /**
  * Own private key.
@@ -83,6 +116,130 @@
 
 
 /**
+ * Build a PeerPath from the paths returned from the DHT, reversing the paths
+ * to obtain a local peer -> destination path and interning the peer ids.
+ *
+ * @return Newly allocated and created path
+ */
+static struct MeshPeerPath *
+path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
+                     unsigned int get_path_length,
+                     const struct GNUNET_PeerIdentity *put_path,
+                     unsigned int put_path_length)
+{
+  struct MeshPeerPath *p;
+  GNUNET_PEER_Id id;
+  int i;
+
+  p = path_new (1);
+  p->peers[0] = myid;
+  GNUNET_PEER_change_rc (myid, 1);
+  i = get_path_length;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   GET has %d hops.\n", i);
+  for (i--; i >= 0; i--)
+  {
+    id = GNUNET_PEER_intern (&get_path[i]);
+    if (p->length > 0 && id == p->peers[p->length - 1])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Optimizing 1 hop out.\n");
+      GNUNET_PEER_change_rc (id, -1);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Adding from GET: %s.\n",
+                  GNUNET_i2s (&get_path[i]));
+      p->length++;
+      p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * 
p->length);
+      p->peers[p->length - 1] = id;
+    }
+  }
+  i = put_path_length;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   PUT has %d hops.\n", i);
+  for (i--; i >= 0; i--)
+  {
+    id = GNUNET_PEER_intern (&put_path[i]);
+    if (id == myid)
+    {
+      /* PUT path went through us, so discard the path up until now and start
+       * from here to get a much shorter (and loop-free) path.
+       */
+      path_destroy (p);
+      p = path_new (0);
+    }
+    if (p->length > 0 && id == p->peers[p->length - 1])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Optimizing 1 hop out.\n");
+      GNUNET_PEER_change_rc (id, -1);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   Adding from PUT: %s.\n",
+                  GNUNET_i2s (&put_path[i]));
+      p->length++;
+      p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * 
p->length);
+      p->peers[p->length - 1] = id;
+    }
+  }
+#if MESH_DEBUG
+  if (get_path_length > 0)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   (first of GET: %s)\n",
+                GNUNET_i2s (&get_path[0]));
+  if (put_path_length > 0)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   (first of PUT: %s)\n",
+                GNUNET_i2s (&put_path[0]));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   In total: %d hops\n",
+              p->length);
+  for (i = 0; i < p->length; i++)
+  {
+    struct GNUNET_PeerIdentity peer_id;
+
+    GNUNET_PEER_resolve (p->peers[i], &peer_id);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "       %u: %s\n", p->peers[i],
+                GNUNET_i2s (&peer_id));
+  }
+#endif
+  return p;
+}
+
+
+/**
+ * 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.
+ *
+ * @param cls closure
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param get_path path of the get request
+ * @param get_path_length lenght of get_path
+ * @param put_path path of the put request
+ * @param put_path_length length of the put_path
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @param data pointer to the result data
+ */
+static void
+dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
+                    const struct GNUNET_HashCode * key,
+                    const struct GNUNET_PeerIdentity *get_path,
+                    unsigned int get_path_length,
+                    const struct GNUNET_PeerIdentity *put_path,
+                    unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
+                    size_t size, const void *data)
+{
+  struct GMD_search_handle *h = cls;
+  struct MeshPeerPath *p;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got results!\n");
+  p = path_build_from_dht (get_path, get_path_length,
+                           put_path, put_path_length);
+  h->callback (h->cls, p);
+  path_destroy (p);
+  return;
+}
+
+
+/**
  * Periodically announce self id in the DHT
  *
  * @param cls closure
@@ -105,8 +262,8 @@
    */
   DEBUG_DHT ("DHT_put for ID %s started.\n", GNUNET_i2s (id));
 
-  block.id = *id;
-  GNUNET_CRYPTO_hash (id, sizeof (struct GNUNET_PeerIdentity), &phash);
+  block.id = *full_id;
+  GNUNET_CRYPTO_hash (full_id, sizeof (struct GNUNET_PeerIdentity), &phash);
   GNUNET_DHT_put (dht_handle,   /* DHT handle */
                   &phash,       /* Key to use */
                   dht_replication_level,     /* Replication level */
@@ -137,7 +294,7 @@
 GMD_init (const struct GNUNET_CONFIGURATION_Handle *c,
           struct GNUNET_PeerIdentity *peer_id)
 {
-  id = peer_id;
+  full_id = peer_id;
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (c, "MESH", 
"DHT_REPLICATION_LEVEL",
                                              &dht_replication_level))
@@ -184,3 +341,34 @@
     announce_id_task = GNUNET_SCHEDULER_NO_TASK;
   }
 }
+
+struct GMD_search_handle *
+GMD_search (const struct GNUNET_PeerIdentity *peer_id,
+            GMD_search_callback callback, void *cls)
+{
+  struct GNUNET_HashCode phash;
+  struct GMD_search_handle *h;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "  Starting DHT GET for peer %s\n", GNUNET_i2s (peer_id));
+  GNUNET_CRYPTO_hash (peer_id, sizeof (struct GNUNET_PeerIdentity), &phash);
+  h = GNUNET_new (struct GMD_search_handle);
+  h->cls = cls;
+  h->dhtget = GNUNET_DHT_get_start (dht_handle,    /* handle */
+                                    GNUNET_BLOCK_TYPE_MESH_PEER, /* type */
+                                    &phash,     /* key to search */
+                                    dht_replication_level, /* replication 
level */
+                                    GNUNET_DHT_RO_RECORD_ROUTE |
+                                    GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+                                    NULL,       /* xquery */
+                                    0,     /* xquery bits */
+                                    &dht_get_id_handler, h);
+  return h;
+}
+
+void
+GMD_search_stop (struct GMD_search_handle *h)
+{
+  GNUNET_DHT_get_stop (h->dhtget);
+  GNUNET_free (h);
+}
\ No newline at end of file

Modified: gnunet/src/mesh/gnunet-service-mesh_local.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-04 14:41:54 UTC (rev 
29842)
+++ gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-04 15:08:12 UTC (rev 
29843)
@@ -157,8 +157,8 @@
  * @param cls Closure (unused).
  * @param client Client handler.
  */
-void
-GMLH_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+static void
+handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
 {
   struct MeshClient *c;
 
@@ -180,8 +180,8 @@
  * @param client identification of the client; NULL
  *        for the last call when the server is destroyed
  */
-void
-GMLH_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+static void
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
 {
   struct MeshClient *c;
 
@@ -240,9 +240,9 @@
  * @param client identification of the client
  * @param message the actual message, which includes messages the client wants
  */
-void
-GMLH_new_client (void *cls, struct GNUNET_SERVER_Client *client,
-                         const struct GNUNET_MessageHeader *message)
+static void
+handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ClientConnect *cc_msg;
   struct MeshClient *c;
@@ -306,9 +306,9 @@
  * @param client Identification of the client.
  * @param message The actual message.
  */
-void
-GMLH_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
-                            const struct GNUNET_MessageHeader *message)
+static void
+handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
+                       const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ChannelMessage *msg;
   struct MeshPeer *peer;
@@ -409,9 +409,9 @@
  * @param client identification of the client
  * @param message the actual message
  */
-void
-GMLH_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
-                             const struct GNUNET_MessageHeader *message)
+static void
+handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
+                        const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_ChannelMessage *msg;
   struct MeshClient *c;
@@ -486,9 +486,9 @@
  * @param client identification of the client
  * @param message the actual message
  */
-void
-GMLH_data (void *cls, struct GNUNET_SERVER_Client *client,
-                   const struct GNUNET_MessageHeader *message)
+static void
+handle_data (void *cls, struct GNUNET_SERVER_Client *client,
+             const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_LocalData *msg;
   struct MeshClient *c;
@@ -584,9 +584,9 @@
  * @param client Identification of the client.
  * @param message The actual message.
  */
-void
-GMLH_ack (void *cls, struct GNUNET_SERVER_Client *client,
-                  const struct GNUNET_MessageHeader *message)
+static void
+handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
+            const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_MESH_LocalAck *msg;
   struct MeshChannelReliability *rel;
@@ -677,9 +677,9 @@
  * @param client Identification of the client.
  * @param message The actual message.
  */
-void
-GMLH_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
-                          const struct GNUNET_MessageHeader *message)
+static void
+handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
+                    const struct GNUNET_MessageHeader *message)
 {
   struct MeshClient *c;
 
@@ -712,8 +712,8 @@
  * @param message The actual message.
  */
 void
-GMLH_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
-                          const struct GNUNET_MessageHeader *message)
+handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
+                    const struct GNUNET_MessageHeader *message)
 {
   const struct GNUNET_MESH_LocalMonitor *msg;
   struct GNUNET_MESH_LocalMonitor *resp;
@@ -768,17 +768,17 @@
  * Functions to handle messages from clients
  */
 static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
-  {&GMLH_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
-  {&GMLH_channel_create, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE,
+  {&handle_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
+  {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE,
    sizeof (struct GNUNET_MESH_ChannelMessage)},
-  {&GMLH_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY,
+  {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY,
    sizeof (struct GNUNET_MESH_ChannelMessage)},
-  {&GMLH_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
-  {&GMLH_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
+  {&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
+  {&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
    sizeof (struct GNUNET_MESH_LocalAck)},
-  {&GMLH_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
+  {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
    sizeof (struct GNUNET_MessageHeader)},
-  {&GMLH_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
+  {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
    sizeof (struct GNUNET_MESH_LocalMonitor)},
   {NULL, NULL, 0, 0}
 };
@@ -802,6 +802,7 @@
   ports = GNUNET_CONTAINER_multihashmap32_create (32);
 }
 
+
 /**
  * Install server (service) handlers and start listening to clients.
  */
@@ -809,8 +810,8 @@
 GML_start (void)
 {
   GNUNET_SERVER_add_handlers (server_handle, client_handlers);
-  GNUNET_SERVER_connect_notify (server_handle,  &GMLH_client_connect, NULL);
-  GNUNET_SERVER_disconnect_notify (server_handle, &GMLH_client_disconnect,
+  GNUNET_SERVER_connect_notify (server_handle,  &handle_client_connect, NULL);
+  GNUNET_SERVER_disconnect_notify (server_handle, &handle_client_disconnect,
                                    NULL);
   nc = GNUNET_SERVER_notification_context_create (server_handle, 1);
 

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-04 14:41:54 UTC (rev 
29842)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-04 15:08:12 UTC (rev 
29843)
@@ -23,6 +23,7 @@
 #include "gnunet_util_lib.h"
 
 #include "gnunet-service-mesh_peer.h"
+#include "gnunet-service-mesh_dht.h"
 #include "mesh_path.h"
 
 
/******************************************************************************/
@@ -393,96 +394,7 @@
 }
 
 
-
 /**
- * Try to establish a new connection to this peer in the given tunnel.
- * If the peer doesn't have any path to it yet, try to get one.
- * If the peer already has some path, send a CREATE CONNECTION towards it.
- *
- * @param peer PeerInfo of the peer.
- */
-static void
-peer_connect (struct MeshPeer *peer)
-{
-  struct MeshTunnel2 *t;
-  struct MeshPeerPath *p;
-  struct MeshConnection *c;
-  int rerun_dhtget;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "peer_connect towards %s\n",
-              peer2s (peer));
-  t = peer->tunnel;
-  c = NULL;
-  rerun_dhtget = GNUNET_NO;
-
-  if (NULL != peer->path_head)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "path exists\n");
-    p = peer_get_best_path (peer);
-    if (NULL != p)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  %u hops\n", p->length);
-      c = tunnel_use_path (t, p);
-      if (NULL == c)
-      {
-        /* This case can happen when the path includes a first hop that is
-         * not yet known to be connected.
-         * 
-         * This happens quite often during testing when running mesh
-         * under valgrind: core connect notifications come very late and the
-         * DHT result has already come and created a valid path.
-         * In this case, the peer->connections hashmap will be NULL and
-         * tunnel_use_path will not be able to create a connection from that
-         * path.
-         *
-         * Re-running the DHT GET should give core time to callback.
-         */
-        GNUNET_break(0);
-        rerun_dhtget = GNUNET_YES;
-      }
-            else
-            {
-              send_connection_create (c);
-              return;
-            }
-    }
-  }
-  
-    if (NULL != peer->dhtget && GNUNET_YES == rerun_dhtget)
-    {
-      GNUNET_DHT_get_stop (peer->dhtget);
-      peer->dhtget = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "  Stopping DHT GET for peer %s\n", peer2s (peer));
-    }
-    
-      if (NULL == peer->dhtget)
-      {
-        const struct GNUNET_PeerIdentity *id;
-        struct GNUNET_HashCode phash;
-        
-        id = GNUNET_PEER_resolve2 (peer->id);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "  Starting DHT GET for peer %s\n", peer2s (peer));
-        GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &phash);
-        peer->dhtget = GNUNET_DHT_get_start (dht_handle,    /* handle */
-                                             GNUNET_BLOCK_TYPE_MESH_PEER, /* 
type */
-                                             &phash,     /* key to search */
-                                             dht_replication_level, /* 
replication level */
-                                             GNUNET_DHT_RO_RECORD_ROUTE |
-                                                                               
       GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
-                                             NULL,       /* xquery */
-                                             0,     /* xquery bits */
-                                             &dht_get_id_handler, peer);
-        if (MESH_TUNNEL_NEW == t->state)
-          tunnel_change_state (t, MESH_TUNNEL_SEARCHING);
-      }
-}
-
-
-
-/**
  * Add the path to the peer and update the path used to reach it in case this
  * is the shortest.
  *
@@ -622,3 +534,89 @@
   GNUNET_CONTAINER_multipeermap_iterate (peers, &shutdown_tunnel, NULL);
 }
 
+
+/**
+ * Try to establish a new connection to this peer in the given tunnel.
+ * If the peer doesn't have any path to it yet, try to get one.
+ * If the peer already has some path, send a CREATE CONNECTION towards it.
+ *
+ * @param peer PeerInfo of the peer.
+ */
+void
+GMP_connect (struct MeshPeer *peer)
+{
+  struct MeshTunnel2 *t;
+  struct MeshPeerPath *p;
+  struct MeshConnection *c;
+  int rerun_dhtget;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "peer_connect towards %s\n",
+              peer2s (peer));
+  t = peer->tunnel;
+  c = NULL;
+  rerun_dhtget = GNUNET_NO;
+
+  if (NULL != peer->path_head)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "path exists\n");
+    p = peer_get_best_path (peer);
+    if (NULL != p)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  %u hops\n", p->length);
+      c = tunnel_use_path (t, p);
+      if (NULL == c)
+      {
+        /* This case can happen when the path includes a first hop that is
+         * not yet known to be connected.
+         * 
+         * This happens quite often during testing when running mesh
+         * under valgrind: core connect notifications come very late and the
+         * DHT result has already come and created a valid path.
+         * In this case, the peer->connections hashmap will be NULL and
+         * tunnel_use_path will not be able to create a connection from that
+         * path.
+         *
+         * Re-running the DHT GET should give core time to callback.
+         */
+        GNUNET_break(0);
+        rerun_dhtget = GNUNET_YES;
+      }
+      else
+      {
+        send_connection_create (c);
+        return;
+      }
+    }
+  }
+
+  if (NULL != peer->dhtget && GNUNET_YES == rerun_dhtget)
+  {
+    GNUNET_DHT_get_stop (peer->dhtget);
+    peer->dhtget = NULL;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "  Stopping DHT GET for peer %s\n", peer2s (peer));
+  }
+
+  if (NULL == peer->dhtget)
+  {
+    const struct GNUNET_PeerIdentity *id;
+    struct GNUNET_HashCode phash;
+
+    id = GNUNET_PEER_resolve2 (peer->id);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "  Starting DHT GET for peer %s\n", peer2s (peer));
+    GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &phash);
+    peer->dhtget = GNUNET_DHT_get_start (dht_handle,    /* handle */
+                                          GNUNET_BLOCK_TYPE_MESH_PEER, /* type 
*/
+                                          &phash,     /* key to search */
+                                          dht_replication_level, /* 
replication level */
+                                          GNUNET_DHT_RO_RECORD_ROUTE |
+                                          GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+                                          NULL,       /* xquery */
+                                          0,     /* xquery bits */
+                                          &dht_get_id_handler, peer);
+    if (MESH_TUNNEL_NEW == t->state)
+      tunnel_change_state (t, MESH_TUNNEL_SEARCHING);
+  }
+}
\ No newline at end of file




reply via email to

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