refactor DHT for new service API
[oweals/gnunet.git] / src / cadet / gnunet-cadet.c
index 9c8615e1c441ca5d1907166482a0e6719ef4251c..5afb64e24e5b99a9e0694ea28f2b7b54fbdb43d8 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -65,29 +65,29 @@ static char *conn_id;
 static char *channel_id;
 
 /**
- * Port to listen on (-p).
+ * Port to listen on (-o).
  */
-static uint32_t listen_port;
+static char *listen_port;
 
 /**
  * Request echo service
  */
-int echo;
+static int echo;
 
 /**
  * Request a debug dump
  */
-int dump;
+static int dump;
 
 /**
  * Time of last echo request.
  */
-struct GNUNET_TIME_Absolute echo_time;
+static struct GNUNET_TIME_Absolute echo_time;
 
 /**
  * Task for next echo request.
  */
-struct GNUNET_SCHEDULER_Task * echo_task;
+static struct GNUNET_SCHEDULER_Task *echo_task;
 
 /**
  * Peer to connect to.
@@ -97,13 +97,12 @@ static char *target_id;
 /**
  * Port to connect to
  */
-static uint32_t target_port;
+static char *target_port = "default";
 
 /**
  * Data pending in netcat mode.
  */
-size_t data_size;
-
+static size_t data_size;
 
 /**
  * Cadet handle.
@@ -120,11 +119,30 @@ static struct GNUNET_CADET_Channel *ch;
  */
 static struct GNUNET_CADET_TransmitHandle *th;
 
+/**
+ * HashCode of the given port string
+ */
+static struct GNUNET_HashCode porthash;
+
+/**
+ * Data structure for ongoing reception of incoming virtual circuits.
+ */
+struct GNUNET_CADET_Port *lp;
+
 /**
  * Shutdown task handle.
  */
-struct GNUNET_SCHEDULER_Task * sd;
+static struct GNUNET_SCHEDULER_Task *sd;
 
+/**
+ * Task for reading from stdin.
+ */
+static struct GNUNET_SCHEDULER_Task *rd_task;
+
+/**
+ * Task for main job.
+ */
+static struct GNUNET_SCHEDULER_Task *job;
 
 
 static void
@@ -170,13 +188,15 @@ conn_2s (uint16_t status)
   switch (status)
   {
     case 0:
-      return "OFF  ";
+      return "NEW  ";
     case 1:
-      return "SENT ";
+      return "SRCH ";
     case 2:
-      return "ACK'D";
+      return "WAIT ";
     case 3:
       return "READY";
+    case 4:
+      return "SHUTD";
     default:
       return "";
   }
@@ -185,17 +205,15 @@ conn_2s (uint16_t status)
 
 
 /**
- * Task run in monitor mode when the user presses CTRL-C to abort.
- * Stops monitoring activity.
+ * Task to shut down this application.
  *
  * @param cls Closure (unused).
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Shutdown\n");
   if (NULL != th)
   {
     GNUNET_CADET_notify_transmit_ready_cancel (th);
@@ -206,10 +224,31 @@ shutdown_task (void *cls,
     GNUNET_CADET_channel_destroy (ch);
     ch = NULL;
   }
+  else if (NULL != target_id) {
+    // FIXME: would be nicer to have proper NACK support from cadet_api
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               "Connection refused to %s\n",
+               target_id);
+  }
   if (NULL != mh)
   {
     GNUNET_CADET_disconnect (mh);
-        mh = NULL;
+    mh = NULL;
+  }
+  if (NULL != rd_task)
+  {
+    GNUNET_SCHEDULER_cancel (rd_task);
+    rd_task = NULL;
+  }
+  if (NULL != echo_task)
+  {
+    GNUNET_SCHEDULER_cancel (echo_task);
+    echo_task = NULL;
+  }
+  if (NULL != job)
+  {
+    GNUNET_SCHEDULER_cancel (job);
+    job = NULL;
   }
 }
 
@@ -227,7 +266,7 @@ shutdown_task (void *cls,
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
-size_t
+static size_t
 data_ready (void *cls, size_t size, void *buf)
 {
   struct GNUNET_MessageHeader *msg;
@@ -242,13 +281,15 @@ data_ready (void *cls, size_t size, void *buf)
   }
 
   total_size = data_size + sizeof (struct GNUNET_MessageHeader);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending %u bytes\n", data_size);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "sending %u bytes\n",
+              (unsigned int) data_size);
   GNUNET_assert (size >= total_size);
 
   msg = buf;
   msg->size = htons (total_size);
   msg->type = htons (GNUNET_MESSAGE_TYPE_CADET_CLI);
-  memcpy (&msg[1], cls, data_size);
+  GNUNET_memcpy (&msg[1], cls, data_size);
   if (GNUNET_NO == echo)
   {
     listen_stdio ();
@@ -266,21 +307,16 @@ data_ready (void *cls, size_t size, void *buf)
  * Task run in stdio mode, after some data is available at stdin.
  *
  * @param cls Closure (unused).
- * @param tc scheduler context
  */
 static void
-read_stdio (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+read_stdio (void *cls)
 {
   static char buf[60000];
 
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    return;
-  }
-
   data_size = read (0, buf, 60000);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "stdio read %u bytes\n",
+              (unsigned int) data_size);
   if (data_size < 1)
   {
     GNUNET_SCHEDULER_shutdown();
@@ -305,10 +341,10 @@ listen_stdio (void)
 
   rs = GNUNET_NETWORK_fdset_create ();
   GNUNET_NETWORK_fdset_set_native (rs, 0);
-  GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                               GNUNET_TIME_UNIT_FOREVER_REL,
-                               rs, NULL,
-                               &read_stdio, NULL);
+  rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+                                        GNUNET_TIME_UNIT_FOREVER_REL,
+                                        rs, NULL,
+                                        &read_stdio, NULL);
   GNUNET_NETWORK_fdset_destroy (rs);
 }
 
@@ -355,8 +391,8 @@ channel_ended (void *cls,
  * Only called (once) upon reception of data with a message type which was
  * subscribed to in #GNUNET_CADET_connect.
  *
- * A call to #GNUNET_CADET_channel_destroy causes te channel to be ignored. In
- * this case the handler MUST return NULL.
+ * A call to #GNUNET_CADET_channel_destroy causes the channel to be ignored.
+ * In this case the handler MUST return NULL.
  *
  * @param cls closure
  * @param channel new handle to the channel
@@ -369,27 +405,47 @@ channel_ended (void *cls,
  */
 static void *
 channel_incoming (void *cls,
-                  struct GNUNET_CADET_Channel * channel,
-                  const struct GNUNET_PeerIdentity * initiator,
-                  uint32_t port, enum GNUNET_CADET_ChannelOption options)
+                  struct GNUNET_CADET_Channel *channel,
+                  const struct GNUNET_PeerIdentity *initiator,
+                  const struct GNUNET_HashCode *port,
+                  enum GNUNET_CADET_ChannelOption options)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Incoming channel %p on port %u\n",
-              channel, port);
+  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+              "Connected from %s\n",
+              GNUNET_i2s_full (initiator));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Incoming channel %p on port %s\n",
+              channel, GNUNET_h2s (port));
   if (NULL != ch)
   {
     GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "A channel already exists (%p)\n", ch);
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Incoming channel %p on port %u\n", channel, port);
+    /*
+     * From now on multiple channels will be sending data to us
+     * making the service of this command unpredictable in its
+     * current implementation. So for now let's just bail out.
+     */
+    GNUNET_SCHEDULER_shutdown();
     return NULL;
   }
-  if (0 == listen_port)
+  if (NULL == listen_port)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not listening to channels\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not listening to channels\n");
     return NULL;
   }
+#if 0
+  // Closing the listen port currently breaks open connections.
+  // Is this an intentional departure from POSIX socket behavior?
+  //
+  if (NULL != lp) {
+    /* Now that we have our circuit up and running, let's not
+     * get confused by further incoming connect requests.
+     */
+    GNUNET_CADET_close_port (lp);
+    lp = NULL;
+  }
+#endif
   ch = channel;
   if (GNUNET_NO == echo)
   {
@@ -404,14 +460,12 @@ channel_incoming (void *cls,
  * @brief Send an echo request to the remote peer.
  *
  * @param cls Closure (NULL).
- * @param tc Task context.
  */
 static void
-send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_echo (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
+  if (NULL == ch)
     return;
-
   GNUNET_assert (NULL == th);
   th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
                                            GNUNET_TIME_UNIT_FOREVER_REL,
@@ -424,14 +478,14 @@ send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, request debug dump on the service.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-request_dump (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+request_dump (void *cls)
 {
   GNUNET_CADET_request_dump (mh);
   GNUNET_SCHEDULER_cancel (sd);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                               &shutdown_task, NULL);
 }
 
 
@@ -439,10 +493,9 @@ request_dump (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one connection.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+create_channel (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
   enum GNUNET_CADET_ChannelOption opt;
@@ -462,11 +515,12 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to `%s'\n", target_id);
   opt = GNUNET_CADET_OPTION_DEFAULT | GNUNET_CADET_OPTION_RELIABLE;
-  ch = GNUNET_CADET_channel_create (mh, NULL, &pid, target_port, opt);
+  GNUNET_CRYPTO_hash (target_port, strlen(target_port), &porthash);
+  ch = GNUNET_CADET_channel_create (mh, NULL, &pid, &porthash, opt);
   if (GNUNET_NO == echo)
     listen_stdio ();
   else
-    GNUNET_SCHEDULER_add_now (send_echo, NULL);
+    echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
 }
 
 
@@ -486,9 +540,9 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 static int
 data_callback (void *cls,
-               struct GNUNET_CADET_Channel *channel,
-               void **channel_ctx,
-               const struct GNUNET_MessageHeader *message)
+       struct GNUNET_CADET_Channel *channel,
+       void **channel_ctx,
+       const struct GNUNET_MessageHeader *message)
 {
   uint16_t len;
   ssize_t done;
@@ -499,7 +553,7 @@ data_callback (void *cls,
 
   if (GNUNET_YES == echo)
   {
-    if (0 != listen_port)
+    if (NULL != listen_port)
     {
       /* Just listening to echo incoming messages*/
       if (NULL != th)
@@ -561,8 +615,11 @@ data_callback (void *cls,
  *                  (0 = unknown, 1 = ourselves, 2 = neighbor)
  */
 static void
-peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
-                int tunnel, unsigned int n_paths, unsigned int best_path)
+peers_callback (void *cls,
+               const struct GNUNET_PeerIdentity *peer,
+                int tunnel,
+               unsigned int n_paths,
+               unsigned int best_path)
 {
   if (NULL == peer)
   {
@@ -589,7 +646,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
  *              Each path starts with the local peer.
  *              Each path ends with the destination peer (given in @c peer).
  */
-void
+static void
 peer_callback (void *cls,
                const struct GNUNET_PeerIdentity *peer,
                int tunnel,
@@ -629,7 +686,7 @@ peer_callback (void *cls,
  * @param estate Encryption state.
  * @param cstate Connectivity state.
  */
-void
+static void
 tunnels_callback (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
                   unsigned int channels,
@@ -665,7 +722,7 @@ tunnels_callback (void *cls,
  * @param estate Encryption status.
  * @param cstate Connectivity status.
  */
-void
+static void
 tunnel_callback (void *cls,
                  const struct GNUNET_PeerIdentity *peer,
                  unsigned int n_channels,
@@ -691,7 +748,7 @@ tunnel_callback (void *cls,
   }
   if (GNUNET_YES != monitor_mode)
   {
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
   }
   return;
 }
@@ -701,16 +758,11 @@ tunnel_callback (void *cls,
  * Call CADET's meta API, get all peers known to a peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_peers (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
 }
 
@@ -719,18 +771,18 @@ get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_peer (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
+  job = NULL;
   if (GNUNET_OK !=
-    GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
-                                                strlen (peer_id),
-                                                &pid.public_key))
-  {
+      GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+                                                  strlen (peer_id),
+                                                  &pid.public_key))
+    {
     fprintf (stderr,
              _("Invalid peer ID `%s'\n"),
              peer_id);
@@ -740,20 +792,16 @@ show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
 }
 
+
 /**
  * Call CADET's meta API, get all tunnels known to a peer.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_tunnels (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
-    return;
-  }
+  job = NULL;
   GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
 }
 
@@ -762,10 +810,9 @@ get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET'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)
+show_tunnel (void *cls)
 {
   struct GNUNET_PeerIdentity pid;
 
@@ -777,7 +824,7 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     fprintf (stderr,
              _("Invalid tunnel owner `%s'\n"),
              tunnel_id);
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
@@ -788,12 +835,12 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one channel.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_channel (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -801,12 +848,12 @@ show_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Call CADET's monitor API, get info of one connection.
  *
  * @param cls Closure (unused).
- * @param tc TaskContext
  */
 static void
-show_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+show_connection (void *cls)
 {
-
+  job = NULL;
+  GNUNET_break (0);
 }
 
 
@@ -819,20 +866,21 @@ show_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cfg configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
-  GNUNET_CADET_ChannelEndHandler *endch = NULL;
   static const struct GNUNET_CADET_MessageHandler handlers[] = {
     {&data_callback, GNUNET_MESSAGE_TYPE_CADET_CLI, 0},
     {NULL, 0, 0} /* FIXME add option to monitor msg types */
   };
-  static uint32_t *ports = NULL;
+
   /* FIXME add option to monitor apps */
 
   target_id = args[0];
-  target_port = args[0] && args[1] ? atoi(args[1]) : 0;
+  if (target_id && args[1]) target_port = args[1];
+
   if ( (0 != (request_peers | request_tunnels)
         || 0 != monitor_mode
         || NULL != tunnel_id
@@ -858,66 +906,59 @@ run (void *cls, char *const *args, const char *cfgfile,
                 "Creating channel to %s\n",
                 target_id);
     GNUNET_SCHEDULER_add_now (&create_channel, NULL);
-    endch = &channel_ended;
-  }
-  else if (0 != listen_port)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Listen\n");
-    newch = &channel_incoming;
-    endch = &channel_ended;
-    ports = GNUNET_malloc (sizeof (uint32_t) * 2);
-    ports[0] = listen_port;
   }
   else if (NULL != peer_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
-    GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
   }
   else if (NULL != tunnel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
-    GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
   }
   else if (NULL != channel_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
-    GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
   }
   else if (NULL != conn_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
-    GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+    job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
   }
   else if (GNUNET_YES == request_peers)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
-    GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
   }
   else if (GNUNET_YES == request_tunnels)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
-    GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+    job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
   }
-  else
+  else if (NULL == listen_port)
   {
     FPRINTF (stderr, "No action requested\n");
     return;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to cadet\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
   mh = GNUNET_CADET_connect (cfg,
                             NULL, /* cls */
-                            newch, /* new channel */
-                            endch, /* cleaner */
-                            handlers,
-                            ports);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
+                            &channel_ended, /* cleaner */
+                            handlers);
   if (NULL == mh)
-    GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
+    GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
   else
-    sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                       shutdown_task, NULL);
+    sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 
+  if (NULL != listen_port)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
+    GNUNET_CRYPTO_hash (listen_port, strlen(listen_port), &porthash);
+    lp = GNUNET_CADET_open_port (mh, &porthash, &channel_incoming, NULL);
+  }
 }
 
 
@@ -950,8 +991,8 @@ main (int argc, char *const *argv)
 //      gettext_noop ("provide information about all events (continuously)"),
 //      GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_mode},
     {'o', "open-port", NULL,
-     gettext_noop ("port to listen to (default; 0)"),
-     GNUNET_YES, &GNUNET_GETOPT_set_uint, &listen_port},
+     gettext_noop ("port to listen to"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &listen_port},
     {'p', "peer", "PEER_ID",
      gettext_noop ("provide information about a patricular peer"),
      GNUNET_YES, &GNUNET_GETOPT_set_string, &peer_id},