- changed mesh 'monitor' API
authorBart Polot <bart@net.in.tum.de>
Fri, 30 Nov 2012 14:29:44 +0000 (14:29 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 30 Nov 2012 14:29:44 +0000 (14:29 +0000)
src/include/gnunet_mesh_service.h
src/mesh/gnunet-mesh.c
src/mesh/mesh_api.c

index beabbc5df897c1a5bc318f22a9532058bffa3a4a..4aa5947c4e91651b6dda49c87c1a391ca45538d8 100644 (file)
@@ -436,7 +436,7 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle
  * @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 @@ typedef void (*GNUNET_MESH_MonitorCB) (void *cls,
 
 
 /**
- * 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 @@ typedef void (*GNUNET_MESH_MonitorTunnelCB) (
  * @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 @@ GNUNET_MESH_monitor (struct GNUNET_MESH_Handle *h,
  * @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 @@ GNUNET_MESH_monitor_tunnel (struct GNUNET_MESH_Handle *h,
  * @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);
 
 
 /**
index c339c60b34fad5c9c6106bf48e6fe393db728a46..21a3f7d601847ef41c5394ca22565b487cf3c261 100644 (file)
  */
 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 @@ shutdown_task (void *cls,
  * @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,23 +97,60 @@ monitor_callback (void *cls,
 
 
 /**
- * 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)
+  {
+    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))
   {
-    /* keep open */
+    GNUNET_SCHEDULER_shutdown();
+    return;
   }
+  GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL);
 }
 
 
@@ -140,9 +185,13 @@ run (void *cls, char *const *args, const char *cfgfile,
   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 @@ main (int argc, char *const *argv)
   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."),
index 9e55f25494ff314c54092cb557d344939a85ea50..9ebc485363d26e11983e7bd617094b985d12f19a 100644 (file)
@@ -210,17 +210,17 @@ struct GNUNET_MESH_Handle
   /**
    * 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 @@ process_monitor (struct GNUNET_MESH_Handle *h,
 
   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 @@ process_monitor (struct GNUNET_MESH_Handle *h,
                 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 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
 /**
  * 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 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
  * @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 @@ GNUNET_MESH_monitor (struct GNUNET_MESH_Handle *h,
  * @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 @@ GNUNET_MESH_monitor_cancel (struct GNUNET_MESH_Handle *h)
  * @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;