REST/NAMESTORE: rework API
[oweals/gnunet.git] / src / cadet / gnunet-cadet.c
index 3386f7464944653ada039922cd540ea7dbc641ae..932d069a12ef759d9298f98b7f5053ff07a878a7 100644 (file)
@@ -11,7 +11,7 @@
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-    
+
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -46,11 +46,6 @@ static char *peer_id;
  */
 static int request_tunnels;
 
-/**
- * Option --tunnel
- */
-static char *tunnel_id;
-
 /**
  * Option --connection
  */
@@ -108,8 +103,13 @@ static struct GNUNET_CADET_GetPath *gpo;
 
 /**
  * Active peer listing operation.
- */ 
-struct GNUNET_CADET_PeersLister *plo;
+ */
+static struct GNUNET_CADET_PeersLister *plo;
+
+/**
+ * Active tunnel listing operation.
+ */
+static struct GNUNET_CADET_ListTunnels *tio;
 
 /**
  * Channel handle.
@@ -220,7 +220,7 @@ shutdown_task (void *cls)
   {
     GNUNET_CADET_channel_destroy (ch);
     ch = NULL;
-  } 
+  }
   if (NULL != gpo)
   {
     GNUNET_CADET_get_path_cancel (gpo);
@@ -231,6 +231,11 @@ shutdown_task (void *cls)
     GNUNET_CADET_list_peers_cancel (plo);
     plo = NULL;
   }
+  if (NULL != tio)
+  {
+    GNUNET_CADET_list_tunnels_cancel (tio);
+    tio = NULL;
+  }
   if (NULL != mh)
   {
     GNUNET_CADET_disconnect (mh);
@@ -301,12 +306,12 @@ read_stdio (void *cls)
   if (GNUNET_NO == echo)
   {
     // Use MQ's notification if too much data of stdin is pooring in too fast.
-    if (STREAM_BUFFER_SIZE < sent_pkt) 
+    if (STREAM_BUFFER_SIZE < sent_pkt)
     {
       GNUNET_MQ_notify_sent (env, mq_cb, cls);
       sent_pkt = 0;
     }
-    else 
+    else
     {
       listen_stdio ();
     }
@@ -558,7 +563,7 @@ path_callback (void *cls,
           ppd->path_length);
   for (unsigned int i = 0; i < ppd->path_length; i++)
     FPRINTF (stdout,
-            "%s ",
+            (i == ppd->target_offset) ? "*%s* " : "%s ",
             GNUNET_i2s (&ppd->path[i]));
   FPRINTF (stdout,
           "\n");
@@ -569,73 +574,25 @@ path_callback (void *cls,
  * Method called to retrieve information about all tunnels in CADET.
  *
  * @param cls Closure.
- * @param peer Destination peer.
- * @param channels Number of channels.
- * @param connections Number of connections.
- * @param estate Encryption state.
- * @param cstate Connectivity state.
+ * @param td tunnel details
  */
 static void
 tunnels_callback (void *cls,
-                  const struct GNUNET_PeerIdentity *peer,
-                  unsigned int channels,
-                  unsigned int connections,
-                  uint16_t estate,
-                  uint16_t cstate)
+                 const struct GNUNET_CADET_TunnelDetails *td)
 {
-  if (NULL == peer)
+  if (NULL == td)
   {
+    tio = NULL;
     GNUNET_SCHEDULER_shutdown();
     return;
   }
   FPRINTF (stdout,
            "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
-           GNUNET_i2s_full (peer),
-           enc_2s (estate),
-           conn_2s (cstate),
-           channels,
-           connections);
-}
-
-
-/**
- * Method called to retrieve information about a specific tunnel the cadet peer
- * has established, o`r is trying to establish.
- *
- * @param cls Closure.
- * @param peer Peer towards whom the tunnel is directed.
- * @param n_channels Number of channels.
- * @param n_connections Number of connections.
- * @param channels Channels.
- * @param connections Connections.
- * @param estate Encryption status.
- * @param cstate Connectivity status.
- */
-static void
-tunnel_callback (void *cls,
-                 const struct GNUNET_PeerIdentity *peer,
-                 unsigned int n_channels,
-                 unsigned int n_connections,
-                 const struct GNUNET_CADET_ChannelTunnelNumber *channels,
-                 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
-                 unsigned int estate,
-                 unsigned int cstate)
-{
-  unsigned int i;
-
-  if (NULL != peer)
-  {
-    FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
-    FPRINTF (stdout, "\t%u channels\n", n_channels);
-    for (i = 0; i < n_channels; i++)
-      FPRINTF (stdout, "\t\t%X\n", ntohl (channels[i].cn));
-    FPRINTF (stdout, "\t%u connections\n", n_connections);
-    for (i = 0; i < n_connections; i++)
-      FPRINTF (stdout, "\t\t%s\n", GNUNET_sh2s (&connections[i].connection_of_tunnel));
-    FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate));
-    FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate));
-  }
-  GNUNET_SCHEDULER_shutdown ();
+           GNUNET_i2s_full (&td->peer),
+           enc_2s (td->estate),
+           conn_2s (td->cstate),
+           td->channels,
+           td->connections);
 }
 
 
@@ -669,7 +626,7 @@ show_peer (void *cls)
       GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
                                                   strlen (peer_id),
                                                   &pid.public_key))
-    {
+  {
     fprintf (stderr,
              _("Invalid peer ID `%s'\n"),
              peer_id);
@@ -692,42 +649,9 @@ static void
 get_tunnels (void *cls)
 {
   job = NULL;
-#if FIXME5385
-  GNUNET_CADET_list_tunnels (my_cfg,
-                            &tunnels_callback,
-                            NULL);
-#endif
-}
-
-
-/**
- * Call CADET's monitor API, get info of one tunnel.
- *
- * @param cls Closure (unused).
- */
-static void
-show_tunnel (void *cls)
-{
-  struct GNUNET_PeerIdentity pid;
-
-  job = NULL;
-  if (GNUNET_OK !=
-      GNUNET_CRYPTO_eddsa_public_key_from_string (tunnel_id,
-                                                  strlen (tunnel_id),
-                                                  &pid.public_key))
-  {
-    fprintf (stderr,
-             _("Invalid tunnel owner `%s'\n"),
-             tunnel_id);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-#if FIXME5385
-  GNUNET_CADET_get_tunnel (my_cfg,
-                           &pid,
-                           &tunnel_callback,
-                           NULL);
-#endif
+  tio = GNUNET_CADET_list_tunnels (my_cfg,
+                                  &tunnels_callback,
+                                  NULL);
 }
 
 
@@ -786,7 +710,6 @@ run (void *cls,
     target_port = args[1];
 
   if ( (0 != (request_peers | request_tunnels)
-        || NULL != tunnel_id
         || NULL != conn_id
         || NULL != channel_id)
        && target_id != NULL)
@@ -804,13 +727,6 @@ run (void *cls,
     job = GNUNET_SCHEDULER_add_now (&show_peer,
                                     NULL);
   }
-  else if (NULL != tunnel_id)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Show tunnel\n");
-    job = GNUNET_SCHEDULER_add_now (&show_tunnel,
-                                    NULL);
-  }
   else if (NULL != channel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -943,7 +859,7 @@ main (int argc,
     GNUNET_GETOPT_option_flag ('e',
                               "echo",
                               gettext_noop ("Activate echo mode"),
-                              &echo), 
+                              &echo),
     GNUNET_GETOPT_option_string ('o',
                                  "open-port",
                                  "SHARED_SECRET",
@@ -958,11 +874,6 @@ main (int argc,
                               "peers",
                               gettext_noop ("Provide information about all peers"),
                               &request_peers),
-    GNUNET_GETOPT_option_string ('t',
-                                 "tunnel",
-                                 "TUNNEL_ID",
-                                 gettext_noop ("Provide information about a particular tunnel"),
-                                 &tunnel_id),
     GNUNET_GETOPT_option_flag ('T',
                               "tunnels",
                               gettext_noop ("Provide information about all tunnels"),