- doc
[oweals/gnunet.git] / src / mesh / mesh_api.c
index 46dfe546fac5f1cff48770b9ea9f0fbf8af27d16..5fdfe612c2d43cfedbdd2ffbb8c6c99130ee492f 100644 (file)
@@ -86,6 +86,34 @@ struct GNUNET_MESH_TransmitHandle
   size_t size;
 };
 
+union MeshInfoCB {
+
+  /**
+   * Channel callback.
+   */
+  GNUNET_MESH_ChannelCB channel_cb;
+
+  /**
+   * Monitor callback
+   */
+  GNUNET_MESH_PeersCB peers_cb;
+
+  /**
+   * Monitor callback
+   */
+  GNUNET_MESH_PeerCB peer_cb;
+
+  /**
+   * Monitor callback
+   */
+  GNUNET_MESH_TunnelsCB tunnels_cb;
+
+  /**
+   * Tunnel callback.
+   */
+  GNUNET_MESH_TunnelCB tunnel_cb;
+};
+
 
 /**
  * Opaque handle to the service.
@@ -185,24 +213,14 @@ struct GNUNET_MESH_Handle
   GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
 
   /**
-   * Monitor callback
+   * Callback for an info task (only one active at a time).
    */
-  GNUNET_MESH_ChannelsCB channels_cb;
+  union MeshInfoCB info_cb;
 
   /**
-   * Monitor callback closure.
+   * Info callback closure for @c info_cb.
    */
-  void *channels_cls;
-
-  /**
-   * Channel callback.
-   */
-  GNUNET_MESH_ChannelCB channel_cb;
-
-  /**
-   * Channel callback closure.
-   */
-  void *channel_cls;
+  void *info_cls;
 };
 
 
@@ -220,13 +238,6 @@ struct GNUNET_MESH_Peer
    * Channel this peer belongs to
    */
   struct GNUNET_MESH_Channel *t;
-
-  /**
-   * Flag indicating whether service has informed about its connection
-   * FIXME-BART: is this flag used? Seems dead right now...
-   */
-  int connected;
-
 };
 
 
@@ -279,7 +290,7 @@ struct GNUNET_MESH_Channel
     /**
      * Channel options: reliability, etc.
      */
-  enum MeshOption options;
+  enum GNUNET_MESH_ChannelOption options;
 
     /**
      * Are we allowed to send to the service?
@@ -411,7 +422,7 @@ create_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid)
 {
   struct GNUNET_MESH_Channel *ch;
 
-  ch = GNUNET_malloc (sizeof (struct GNUNET_MESH_Channel));
+  ch = GNUNET_new (struct GNUNET_MESH_Channel);
   GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch);
   ch->mesh = h;
   if (0 == chid)
@@ -839,18 +850,21 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
   const struct GNUNET_MESH_MessageHandler *handler;
   struct GNUNET_MESH_LocalData *dmsg;
   struct GNUNET_MESH_Channel *ch;
+  size_t size;
   unsigned int i;
   uint16_t type;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Got a data message!\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
   dmsg = (struct GNUNET_MESH_LocalData *) message;
   ch = retrieve_channel (h, ntohl (dmsg->id));
   payload = (struct GNUNET_MessageHeader *) &dmsg[1];
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "  %s data on channel %s [%X]\n",
-       ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "fwd" : "bck",
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  %s data on channel %s [%X]\n",
+       GM_f2s (ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV),
        GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (dmsg->id));
+
+  size = ntohs (message->size);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  %u bytes\n", size);
+
   if (NULL == ch)
   {
     /* Channel was ignored/destroyed, probably service didn't get it yet */
@@ -858,12 +872,12 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
     return;
   }
   type = ntohs (payload->type);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  payload type %u\n", type);
+  size = ntohs (payload->size);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  payload type %s\n", GM_m2s (type));
   for (i = 0; i < h->n_handlers; i++)
   {
     handler = &h->message_handlers[i];
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "    checking handler for type %u\n",
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "    checking handler for type %u\n",
          handler->type);
     if (handler->type == type)
     {
@@ -903,10 +917,10 @@ process_ack (struct GNUNET_MESH_Handle *h,
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
   msg = (struct GNUNET_MESH_LocalAck *) message;
   chid = ntohl (msg->channel_id);
-    ch = retrieve_channel (h, chid);
+  ch = retrieve_channel (h, chid);
   if (NULL == ch)
   {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown channel %X\n", chid);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK on unknown channel %X\n", chid);
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  on channel %X!\n", ch->chid);
@@ -914,10 +928,9 @@ process_ack (struct GNUNET_MESH_Handle *h,
   if (NULL == h->th && 0 < ch->packet_size)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  tmt rdy was NULL, requesting!\n");
-    h->th =
-        GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size,
-                                             GNUNET_TIME_UNIT_FOREVER_REL,
-                                             GNUNET_YES, &send_callback, h);
+    h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL,
+                                                 GNUNET_YES, &send_callback, h);
   }
 }
 
@@ -932,7 +945,7 @@ process_ack (struct GNUNET_MESH_Handle *h,
 // process_get_channels (struct GNUNET_MESH_Handle *h,
 //                      const struct GNUNET_MessageHeader *message)
 // {
-//   struct GNUNET_MESH_LocalMonitor *msg;
+//   struct GNUNET_MESH_LocalInfo *msg;
 //
 //   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
 //
@@ -942,16 +955,16 @@ process_ack (struct GNUNET_MESH_Handle *h,
 //     return;
 //   }
 //
-//   msg = (struct GNUNET_MESH_LocalMonitor *) message;
+//   msg = (struct GNUNET_MESH_LocalInfo *) message;
 //   if (ntohs (message->size) !=
-//       (sizeof (struct GNUNET_MESH_LocalMonitor) +
+//       (sizeof (struct GNUNET_MESH_LocalInfo) +
 //        sizeof (struct GNUNET_PeerIdentity)))
 //   {
 //     GNUNET_break_op (0);
 //     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
 //                 "Get channels message: size %hu - expected %u\n",
 //                 ntohs (message->size),
-//                 sizeof (struct GNUNET_MESH_LocalMonitor));
+//                 sizeof (struct GNUNET_MESH_LocalInfo));
 //     return;
 //   }
 //   h->channels_cb (h->channels_cls,
@@ -972,7 +985,7 @@ process_ack (struct GNUNET_MESH_Handle *h,
 // process_show_channel (struct GNUNET_MESH_Handle *h,
 //                      const struct GNUNET_MessageHeader *message)
 // {
-//   struct GNUNET_MESH_LocalMonitor *msg;
+//   struct GNUNET_MESH_LocalInfo *msg;
 //   size_t esize;
 //
 //   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
@@ -984,8 +997,8 @@ process_ack (struct GNUNET_MESH_Handle *h,
 //   }
 //
 //   /* Verify message sanity */
-//   msg = (struct GNUNET_MESH_LocalMonitor *) message;
-//   esize = sizeof (struct GNUNET_MESH_LocalMonitor);
+//   msg = (struct GNUNET_MESH_LocalInfo *) message;
+//   esize = sizeof (struct GNUNET_MESH_LocalInfo);
 //   if (ntohs (message->size) != esize)
 //   {
 //     GNUNET_break_op (0);
@@ -1007,6 +1020,211 @@ process_ack (struct GNUNET_MESH_Handle *h,
 // }
 
 
+
+/**
+ * Process a local reply about info on all tunnels, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_peers (struct GNUNET_MESH_Handle *h,
+                     const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_MESH_LocalInfoPeer *msg;
+  uint16_t size;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Peer messasge received\n");
+
+  if (NULL == h->info_cb.peers_cb)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  ignored\n");
+    return;
+  }
+
+  size = ntohs (message->size);
+  if (sizeof (struct GNUNET_MESH_LocalInfoPeer) > size)
+  {
+    h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0);
+    h->info_cb.peers_cb = NULL;
+    h->info_cls = NULL;
+    return;
+  }
+
+  msg = (struct GNUNET_MESH_LocalInfoPeer *) message;
+  h->info_cb.peers_cb (h->info_cls, &msg->destination,
+                       (int) ntohs (msg->tunnel),
+                       (unsigned int ) ntohs (msg->paths),
+                       0);
+}
+
+
+/**
+ * Process a local peer info reply, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_peer (struct GNUNET_MESH_Handle *h,
+                  const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_MESH_LocalInfoTunnel *msg;
+  size_t esize;
+  size_t msize;
+  unsigned int ch_n;
+  unsigned int c_n;
+  struct GNUNET_MeshHash *conns;
+  MESH_ChannelNumber *chns;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n");
+  if (NULL == h->info_cb.tunnel_cb)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  ignored\n");
+    return;
+  }
+
+  /* Verify message sanity */
+  msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+  msize = ntohs (message->size);
+  esize = sizeof (struct GNUNET_MESH_LocalInfoTunnel);
+  if (esize > msize)
+  {
+    GNUNET_break_op (0);
+    h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+    goto clean_cls;
+  }
+  ch_n = ntohl (msg->channels);
+  c_n = ntohl (msg->connections);
+  esize += ch_n * sizeof (MESH_ChannelNumber);
+  esize += c_n * sizeof (struct GNUNET_MeshHash);
+  if (msize != esize)
+  {
+    GNUNET_break_op (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "m:%u, e: %u (%u ch, %u conn)\n",
+                msize, esize, ch_n, c_n);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n",
+                sizeof (struct GNUNET_MESH_LocalInfoTunnel),
+                sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode));
+    h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+    goto clean_cls;
+  }
+
+  /* Call Callback with tunnel info. */
+  conns = (struct GNUNET_MeshHash *) &msg[1];
+  chns = (MESH_ChannelNumber *) &conns[c_n];
+  h->info_cb.tunnel_cb (h->info_cls, &msg->destination,
+                        ch_n, c_n, chns, conns,
+                        ntohs (msg->estate), ntohs (msg->cstate));
+
+  clean_cls:
+  h->info_cb.tunnel_cb = NULL;
+  h->info_cls = NULL;
+}
+
+
+/**
+ * Process a local reply about info on all tunnels, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_tunnels (struct GNUNET_MESH_Handle *h,
+                     const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_MESH_LocalInfoTunnel *msg;
+  uint16_t size;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n");
+
+  if (NULL == h->info_cb.tunnels_cb)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  ignored\n");
+    return;
+  }
+
+  size = ntohs (message->size);
+  if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size)
+  {
+    h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0);
+    h->info_cb.tunnels_cb = NULL;
+    h->info_cls = NULL;
+    return;
+  }
+
+  msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+  h->info_cb.tunnels_cb (h->info_cls, &msg->destination,
+                         ntohl (msg->channels), ntohl (msg->connections),
+                         ntohs (msg->estate), ntohs (msg->cstate));
+
+}
+
+
+/**
+ * Process a local tunnel info reply, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_tunnel (struct GNUNET_MESH_Handle *h,
+                    const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_MESH_LocalInfoTunnel *msg;
+  size_t esize;
+  size_t msize;
+  unsigned int ch_n;
+  unsigned int c_n;
+  struct GNUNET_MeshHash *conns;
+  MESH_ChannelNumber *chns;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n");
+  if (NULL == h->info_cb.tunnel_cb)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  ignored\n");
+    return;
+  }
+
+  /* Verify message sanity */
+  msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+  msize = ntohs (message->size);
+  esize = sizeof (struct GNUNET_MESH_LocalInfoTunnel);
+  if (esize > msize)
+  {
+    GNUNET_break_op (0);
+    h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+    goto clean_cls;
+  }
+  ch_n = ntohl (msg->channels);
+  c_n = ntohl (msg->connections);
+  esize += ch_n * sizeof (MESH_ChannelNumber);
+  esize += c_n * sizeof (struct GNUNET_MeshHash);
+  if (msize != esize)
+  {
+    GNUNET_break_op (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "m:%u, e: %u (%u ch, %u conn)\n",
+                msize, esize, ch_n, c_n);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n",
+                sizeof (struct GNUNET_MESH_LocalInfoTunnel),
+                sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode));
+    h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+    goto clean_cls;
+  }
+
+  /* Call Callback with tunnel info. */
+  conns = (struct GNUNET_MeshHash *) &msg[1];
+  chns = (MESH_ChannelNumber *) &conns[c_n];
+  h->info_cb.tunnel_cb (h->info_cls, &msg->destination,
+                ch_n, c_n, chns, conns,
+                ntohs (msg->estate), ntohs (msg->cstate));
+
+clean_cls:
+  h->info_cb.tunnel_cb = NULL;
+  h->info_cls = NULL;
+}
+
+
 /**
  * Function to process all messages received from the service
  *
@@ -1038,7 +1256,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
     break;
     /* Notify of a channel disconnection */
   case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: /* TODO separate(gid problem)*/
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK:
+  case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK:
     process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg);
     break;
   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA:
@@ -1047,10 +1265,25 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
     process_ack (h, msg);
     break;
-//   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED
+//   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
 //     process_get_channels (h, msg);
 //     break;
-//   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED
+//   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+//     process_show_channel (h, msg);
+//     break;
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS:
+    process_get_peers (h, msg);
+    break;
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER:
+    process_get_peer (h, msg);
+    break;
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
+    process_get_tunnels (h, msg);
+    break;
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+    process_get_tunnel (h, msg);
+    break;
+//   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
 //     process_show_channel (h, msg);
 //     break;
   default:
@@ -1251,7 +1484,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
   struct GNUNET_MESH_Handle *h;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n");
-  h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
+  h = GNUNET_new (struct GNUNET_MESH_Handle);
   LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h);
   h->cfg = cfg;
   h->new_channel = new_channel;
@@ -1332,6 +1565,10 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
       case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
       case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
       case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER:
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS:
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
         break;
       default:
         GNUNET_break (0);
@@ -1382,7 +1619,7 @@ GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
                             void *channel_ctx,
                             const struct GNUNET_PeerIdentity *peer,
                             uint32_t port,
-                            enum MeshOption options)
+                            enum GNUNET_MESH_ChannelOption options)
 {
   struct GNUNET_MESH_Channel *ch;
   struct GNUNET_MESH_ChannelMessage msg;
@@ -1457,7 +1694,7 @@ GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel)
  */
 const union GNUNET_MESH_ChannelInfo *
 GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel,
-                              enum MeshOption option, ...)
+                              enum GNUNET_MESH_ChannelOption option, ...)
 {
   static int bool_flag;
   const union GNUNET_MESH_ChannelInfo *ret;
@@ -1504,7 +1741,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, int cork
   LOG (GNUNET_ERROR_TYPE_DEBUG, "    payload size %u\n", notify_size);
   GNUNET_assert (NULL != notify);
   GNUNET_assert (0 == channel->packet_size); // Only one data packet allowed
-  th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
+  th = GNUNET_new (struct GNUNET_MESH_TransmitHandle);
   th->channel = channel;
   th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
   th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData);
@@ -1555,33 +1792,135 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel)
 }
 
 
+static void
+send_info_request (struct GNUNET_MESH_Handle *h, uint16_t type)
+{
+  struct GNUNET_MessageHeader msg;
+
+  msg.size = htons (sizeof (msg));
+  msg.type = htons (type);
+  send_packet (h, &msg, NULL);
+}
+
+
 /**
- * Request information about the running mesh peer.
- * The callback will be called for every channel known to the service,
- * listing all active peers that blong to the channel.
+ * Request information about peers known to the running mesh service.
+ * The callback will be called for every peer known to the service.
+ * Only one info request (of any kind) can be active at once.
  *
- * If called again on the same handle, it will overwrite the previous
- * callback and cls. To retrieve the cls, monitor_cancel must be
- * called first.
  *
  * WARNING: unstable API, likely to change in the future!
  *
  * @param h Handle to the mesh peer.
  * @param callback Function to call with the requested data.
  * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
  */
-void
-GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
-                         GNUNET_MESH_ChannelsCB callback,
-                         void *callback_cls)
+int
+GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
+                       GNUNET_MESH_PeersCB callback,
+                       void *callback_cls)
 {
-  struct GNUNET_MessageHeader msg;
+  if (NULL != h->info_cb.peers_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
+  h->info_cb.peers_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
+}
 
-  msg.size = htons (sizeof (msg));
-  msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS);
-  send_packet (h, &msg, NULL);
-  h->channels_cb = callback;
-  h->channels_cls = callback_cls;
+
+/**
+ * Cancel a peer info request. The callback will not be called (anymore).
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Mesh handle.
+ *
+ * @return Closure given to GNUNET_MESH_get_peers.
+ */
+void *
+GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h)
+{
+  void *cls;
+
+  cls = h->info_cls;
+  h->info_cb.peers_cb = NULL;
+  h->info_cls = NULL;
+  return cls;
+}
+
+
+/**
+ * Request information about a peer known to the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
+                      const struct GNUNET_PeerIdentity *id,
+                      GNUNET_MESH_PeerCB callback,
+                      void *callback_cls)
+{
+  struct GNUNET_MESH_LocalInfo msg;
+
+  if (NULL != h->info_cb.peer_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  memset (&msg, 0, sizeof (msg));
+  msg.header.size = htons (sizeof (msg));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER);
+  msg.peer = *id;
+  send_packet (h, &msg.header, NULL);
+  h->info_cb.peer_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
+}
+
+
+/**
+ * Request information about tunnels of the running mesh peer.
+ * The callback will be called for every tunnel of the service.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
+                         GNUNET_MESH_TunnelsCB callback,
+                         void *callback_cls)
+{
+  if (NULL != h->info_cb.tunnels_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+  h->info_cb.tunnels_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
 }
 
 
@@ -1590,20 +1929,61 @@ GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
  *
  * @param h Mesh handle.
  *
- * @return Closure given to GNUNET_MESH_monitor, if any.
+ * @return Closure given to GNUNET_MESH_get_tunnels.
  */
 void *
-GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h)
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
 {
   void *cls;
 
-  cls = h->channels_cls;
-  h->channels_cb = NULL;
-  h->channels_cls = NULL;
+  h->info_cb.tunnels_cb = NULL;
+  cls = h->info_cls;
+  h->info_cls = NULL;
+
   return cls;
 }
 
 
+
+/**
+ * Request information about a tunnel of the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
+                        const struct GNUNET_PeerIdentity *id,
+                        GNUNET_MESH_TunnelCB callback,
+                        void *callback_cls)
+{
+  struct GNUNET_MESH_LocalInfo msg;
+
+  if (NULL != h->info_cb.tunnel_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  memset (&msg, 0, sizeof (msg));
+  msg.header.size = htons (sizeof (msg));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
+  msg.peer = *id;
+  send_packet (h, &msg.header, NULL);
+  h->info_cb.tunnel_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
+}
+
+
 /**
  * Request information about a specific channel of the running mesh peer.
  *
@@ -1615,24 +1995,33 @@ GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h)
  * @param channel_number Channel number.
  * @param callback Function to call with the requested data.
  * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
  */
-void
+int
 GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
                          struct GNUNET_PeerIdentity *initiator,
                          unsigned int channel_number,
                          GNUNET_MESH_ChannelCB callback,
                          void *callback_cls)
 {
-  struct GNUNET_MESH_LocalMonitor msg;
+  struct GNUNET_MESH_LocalInfo msg;
+
+  if (NULL != h->info_cb.channel_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
 
   msg.header.size = htons (sizeof (msg));
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
-  msg.owner = *initiator;
+  msg.peer = *initiator;
   msg.channel_id = htonl (channel_number);
-  msg.reserved = 0;
+//   msg.reserved = 0;
   send_packet (h, &msg.header, NULL);
-  h->channel_cb = callback;
-  h->channel_cls = callback_cls;
+  h->info_cb.channel_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
 }