gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25172 - in gnunet/src: include mesh


From: gnunet
Subject: [GNUnet-SVN] r25172 - in gnunet/src: include mesh
Date: Fri, 30 Nov 2012 15:29:44 +0100

Author: bartpolot
Date: 2012-11-30 15:29:44 +0100 (Fri, 30 Nov 2012)
New Revision: 25172

Modified:
   gnunet/src/include/gnunet_mesh_service.h
   gnunet/src/mesh/gnunet-mesh.c
   gnunet/src/mesh/mesh_api.c
Log:
- changed mesh 'monitor' API

Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h    2012-11-30 13:50:22 UTC (rev 
25171)
+++ gnunet/src/include/gnunet_mesh_service.h    2012-11-30 14:29:44 UTC (rev 
25172)
@@ -436,7 +436,7 @@
  * @param peers Array of peer identities that participate in the tunnel.
  * @param npeers Number of peers in peers.
  */
-typedef void (*GNUNET_MESH_MonitorCB) (void *cls,
+typedef void (*GNUNET_MESH_TunnelsCB) (void *cls,
                                        const struct GNUNET_PeerIdentity *owner,
                                        unsigned int tunnel_number,
                                        const struct GNUNET_PeerIdentity *peers,
@@ -444,30 +444,22 @@
 
 
 /**
- * Method called to retrieve information about each tunnel the mesh peer
- * is aware of.
+ * Method called to retrieve information about a specific tunnel the mesh peer
+ * is aware of, including all transit nodes.
  *
  * @param cls Closure.
- * @param initiator Peer that started the tunnel (owner).
- * @param tunnel_number Tunnel number.
- * @param peers Array of peers that form the tunnel, including transit nodes.
- *              The identities come in pairs, representing a peer
- *              and his predecessor in the tree. The root does not
- *              appear in the array.
- * @param npeers Number of peers in peers (size is 2 x npeers!).
+ * @param peer Peer in the tunnel's tree.
+ * @param parent Parent of the current peer. All 0 when peer is root.
  */
-typedef void (*GNUNET_MESH_MonitorTunnelCB) (
-                      void *cls,
-                      const struct GNUNET_PeerIdentity *owner,
-                      unsigned int tunnel_number,
-                      const struct GNUNET_PeerIdentity *peers,
-                      unsigned int npeers);
+typedef void (*GNUNET_MESH_TunnelCB) (void *cls,
+                                      const struct GNUNET_PeerIdentity *peer,
+                                      const struct GNUNET_PeerIdentity 
*parent);
 
 
 /**
  * Request information about the running mesh peer.
  * The callback will be called for every tunnel known to the service,
- * listing all peers that blong to the tunnel (active only).
+ * listing all active peers that blong to the tunnel.
  *
  * If called again on the same handle, it will overwrite the previous
  * callback and cls. To retrieve the cls, monitor_cancel must be
@@ -480,9 +472,9 @@
  * @param callback_cls Closure for @c callback.
  */
 void
-GNUNET_MESH_monitor (struct GNUNET_MESH_Handle *h,
-                     GNUNET_MESH_MonitorCB callback,
-                     void *callback_cls);
+GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
+                         GNUNET_MESH_TunnelsCB callback,
+                         void *callback_cls);
 
 
 /**
@@ -497,11 +489,11 @@
  * @param callback_cls Closure for @c callback.
  */
 void
-GNUNET_MESH_monitor_tunnel (struct GNUNET_MESH_Handle *h,
-                            struct GNUNET_PeerIdentity *initiator,
-                            unsigned int tunnel_number,
-                            GNUNET_MESH_MonitorTunnelCB callback,
-                            void *callback_cls);
+GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h,
+                         struct GNUNET_PeerIdentity *initiator,
+                         unsigned int tunnel_number,
+                         GNUNET_MESH_TunnelCB callback,
+                         void *callback_cls);
 
 
 /**
@@ -514,7 +506,7 @@
  * @return Closure given to GNUNET_MESH_monitor, if any.
  */
 void *
-GNUNET_MESH_monitor_cancel (struct GNUNET_MESH_Handle *h);
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h);
 
 
 /**

Modified: gnunet/src/mesh/gnunet-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-mesh.c       2012-11-30 13:50:22 UTC (rev 25171)
+++ gnunet/src/mesh/gnunet-mesh.c       2012-11-30 14:29:44 UTC (rev 25172)
@@ -35,12 +35,20 @@
  */
 static int monitor_connections;
 
+/**
+ * Option -t
+ */
+static char *tunnel_id;
 
 /**
  * Mesh handle.
  */
 static struct GNUNET_MESH_Handle *mh;
 
+/**
+ * Shutdown task handle.
+ */
+GNUNET_SCHEDULER_TaskIdentifier sd;
 
 /**
  * Task run in monitor mode when the user presses CTRL-C to abort.
@@ -72,7 +80,7 @@
  * @param npeers Number of peers in peers.
  */
 static void
-monitor_callback (void *cls,
+tunnels_callback (void *cls,
                  const struct GNUNET_PeerIdentity *initiator,
                  unsigned int tunnel_number,
                  const struct GNUNET_PeerIdentity *peers,
@@ -89,26 +97,63 @@
 
 
 /**
- * Call MESH's monitor API, start monitoring process
+ * Method called to retrieve information about each tunnel the mesh peer
+ * is aware of.
  *
+ * @param cls Closure.
+ * @param peer Peer in the tunnel's tree.
+ * @param parent Parent of the current peer. All 0 when peer is root.
+ * 
+ */
+static void
+tunnel_callback (void *cls,
+                 const struct GNUNET_PeerIdentity *peer,
+                 const struct GNUNET_PeerIdentity *parent)
+{
+}
+
+
+/**
+ * Call MESH's monitor API, get all tunnels known to peer.
+ *
  * @param cls Closure (unused).
  * @param tc TaskContext
  */
 static void
-monitor (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
   {
     return;
   }
-  GNUNET_MESH_monitor (mh, &monitor_callback, NULL);
-  if (GNUNET_YES == monitor_connections)
+  GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
+  if (GNUNET_YES != monitor_connections)
   {
-    /* keep open */
+    GNUNET_SCHEDULER_shutdown();
   }
 }
 
+/**
+ * Call MESH's monitor API, get info of one tunnel.
+ *
+ * @param cls Closure (unused).
+ * @param tc TaskContext
+ */
+static void
+show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_PeerIdentity pid;
 
+  if (GNUNET_OK !=
+      GNUNET_CRYPTO_hash_from_string (tunnel_id, &pid.hashPubKey))
+  {
+    GNUNET_SCHEDULER_shutdown();
+    return;
+  }
+  GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL);
+}
+
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -140,9 +185,13 @@
   if (NULL == mh)
     GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
   else
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                  shutdown_task, NULL);
-  GNUNET_SCHEDULER_add_now (&monitor, NULL);
+    sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                       shutdown_task, NULL);
+
+  if (NULL != tunnel_id)
+    GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+  else
+    GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
 }
 
 
@@ -159,15 +208,17 @@
   int res;
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'m', "monitor", NULL,
-    gettext_noop ("provide inthe 'struct 
GNUNET_TRANSPORT_PeerIterateContextformation about all tunnels (continuously)"),
-     0, &GNUNET_GETOPT_set_one, &monitor_connections},
+     gettext_noop ("provide information about all tunnels (continuously) NOT 
IMPLEMENTED"), /* FIXME */
+     GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections},
+    {'t', "tunnel", "OWNER_ID:TUNNEL_ID",
+     gettext_noop ("provide information about a particular tunnel"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &tunnel_id},
     GNUNET_GETOPT_OPTION_END
   };
 
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
 
-
   res = GNUNET_PROGRAM_run (argc, argv, "gnunet-mesh",
                       gettext_noop
                       ("Print information about mesh tunnels and peers."),

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2012-11-30 13:50:22 UTC (rev 25171)
+++ gnunet/src/mesh/mesh_api.c  2012-11-30 14:29:44 UTC (rev 25172)
@@ -210,17 +210,17 @@
   /**
    * Monitor callback
    */
-  GNUNET_MESH_MonitorCB monitor_cb;
+  GNUNET_MESH_TunnelsCB tunnels_cb;
 
   /**
    * Monitor callback closure.
    */
-  void *monitor_cls;
+  void *tunnels_cls;
 
   /**
    * Tunnel callback.
    */
-  GNUNET_MESH_MonitorTunnelCB tunnel_cb;
+  GNUNET_MESH_TunnelCB tunnel_cb;
 
   /**
    * Tunnel callback closure.
@@ -1276,7 +1276,7 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Monitor messasge received\n");
 
-  if (NULL == h->monitor_cb)
+  if (NULL == h->tunnels_cb)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "  ignored\n");
     return;
@@ -1297,7 +1297,7 @@
                 npeers);
     return;
   }
-  h->monitor_cb (h->monitor_cls,
+  h->tunnels_cb (h->tunnels_cls,
                  &msg->owner,
                  ntohl (msg->tunnel_id),
                  (struct GNUNET_PeerIdentity *) &msg[1],
@@ -2230,7 +2230,7 @@
 /**
  * Request information about the running mesh peer.
  * The callback will be called for every tunnel known to the service,
- * listing all peers that blong to the tunnel (active only).
+ * listing all active peers that blong to the tunnel.
  *
  * If called again on the same handle, it will overwrite the previous
  * callback and cls. To retrieve the cls, monitor_cancel must be
@@ -2243,17 +2243,17 @@
  * @param callback_cls Closure for @c callback.
  */
 void
-GNUNET_MESH_monitor (struct GNUNET_MESH_Handle *h,
-                     GNUNET_MESH_MonitorCB callback,
-                     void *callback_cls)
+GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
+                         GNUNET_MESH_TunnelsCB callback,
+                         void *callback_cls)
 {
   struct GNUNET_MessageHeader msg;
 
   msg.size = htons (sizeof (msg));
   msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR);
   send_packet (h, &msg, NULL);
-  h->monitor_cb = callback;
-  h->monitor_cls = callback_cls;
+  h->tunnels_cb = callback;
+  h->tunnels_cls = callback_cls;
 
   return;
 }
@@ -2267,13 +2267,13 @@
  * @return Closure given to GNUNET_MESH_monitor, if any.
  */
 void *
-GNUNET_MESH_monitor_cancel (struct GNUNET_MESH_Handle *h)
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
 {
   void *cls;
 
-  cls = h->monitor_cls;
-  h->monitor_cb = NULL;
-  h->monitor_cls = NULL;
+  cls = h->tunnels_cls;
+  h->tunnels_cb = NULL;
+  h->tunnels_cls = NULL;
   return cls;
 }
 
@@ -2290,11 +2290,11 @@
  * @param callback_cls Closure for @c callback.
  */
 void
-GNUNET_MESH_monitor_tunnel (struct GNUNET_MESH_Handle *h,
-                            struct GNUNET_PeerIdentity *initiator,
-                            unsigned int tunnel_number,
-                            GNUNET_MESH_MonitorTunnelCB callback,
-                            void *callback_cls)
+GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h,
+                         struct GNUNET_PeerIdentity *initiator,
+                         unsigned int tunnel_number,
+                         GNUNET_MESH_TunnelCB callback,
+                         void *callback_cls)
 {
   struct GNUNET_MESH_LocalMonitor msg;
 




reply via email to

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