- more tunnels info for CLI
authorBart Polot <bart@net.in.tum.de>
Mon, 6 Jan 2014 05:18:30 +0000 (05:18 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 6 Jan 2014 05:18:30 +0000 (05:18 +0000)
src/mesh/gnunet-mesh.c
src/mesh/gnunet-service-mesh_local.c
src/mesh/gnunet-service-mesh_tunnel.c
src/mesh/gnunet-service-mesh_tunnel.h
src/mesh/mesh_api.c

index eaa9c09fdc7c6995d8a9287a15bbc6f00f31e46e..afdd94a9cfc948ac226ee0c68e23e7f7aed6decc 100644 (file)
@@ -122,6 +122,7 @@ static void
 shutdown_task (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
   if (NULL != ch)
   {
     GNUNET_MESH_channel_destroy (ch);
@@ -439,10 +440,18 @@ tunnels_callback (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
                   unsigned int channels,
                   unsigned int connections,
-                  unsigned int estate,
-                  unsigned int cstate)
+                  uint16_t estate,
+                  uint16_t cstate)
 {
-  FPRINTF (stdout, "%s [%u, %u] CH: %u, C: %u\n",
+  if (NULL == peer)
+  {
+    if (GNUNET_YES != monitor_connections)
+    {
+      GNUNET_SCHEDULER_shutdown();
+    }
+    return;
+  }
+  FPRINTF (stdout, "%s [ENC: %u, CON: %u] CHs: %u, CONNs: %u\n",
            GNUNET_i2s_full (peer), estate, cstate, channels, connections);
 }
 
@@ -483,15 +492,12 @@ tunnel_callback (void *cls,
 static void
 get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
   {
     return;
   }
   GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
-  if (GNUNET_YES != monitor_connections)
-  {
-    GNUNET_SCHEDULER_shutdown();
-  }
 }
 
 
index 8fc01f929607266edd32eb104eea7a77d74d53ef..0470d982df706f4139a609d4efacf5626e57bc39 100644 (file)
@@ -298,7 +298,8 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
   uint32_t *p;
   unsigned int i;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\nnew client connected %p\n", client);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client);
 
   /* Check data sanity */
   size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
@@ -581,7 +582,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
 /**
  * Iterator over all tunnels to send a monitoring client info about each tunnel.
  *
- * @param cls Closure (client handle).
+ * @param cls Closure ().
  * @param peer Peer ID (tunnel remote peer).
  * @param value Tunnel info.
  *
@@ -599,10 +600,10 @@ monitor_all_tunnels_iterator (void *cls,
   msg.header.size = htons (sizeof (msg));
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
   msg.destination = *peer;
-  msg.channels = htons (42);
-  msg.connections = htons (42);
-  msg.cstate = htons (GMT_get_cstate (t));
-  msg.estate = htons (42);
+  msg.channels = htonl (GMT_count_channels (t));
+  msg.connections = htonl (GMT_count_connections (t));
+  msg.cstate = htons ((uint16_t) GMT_get_cstate (t));
+  msg.estate = htons ((uint16_t) GMT_get_estate (t));
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "sending info about tunnel ->%s\n",
        GNUNET_i2s (peer));
@@ -625,8 +626,7 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
                     const struct GNUNET_MessageHeader *message)
 {
   struct MeshClient *c;
-  size_t size;
-  struct GNUNET_MessageHeader *reply;
+  struct GNUNET_MessageHeader reply;
 
   /* Sanity check for client registration */
   if (NULL == (c = GML_client_get (client)))
@@ -636,21 +636,17 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Received get tunnels request from client %u\n",
-       c->id);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Received get tunnels request from client %u (%p)\n",
+       c->id, client);
 
-  size = GMT_count_all () + 1; /* Last one is all \0 to mark 'end' */
-  size *= sizeof (struct GNUNET_PeerIdentity);
-  size += sizeof (*reply);
-  reply = GNUNET_malloc (size);
-  GMT_iterate_all (reply, monitor_all_tunnels_iterator);
-  reply->size = htons (size);
-  reply->type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
-  GNUNET_SERVER_notification_context_unicast (nc, client, reply, GNUNET_NO);
+  GMT_iterate_all (client, monitor_all_tunnels_iterator);
+  reply.size = htons (sizeof (reply));
+  reply.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+  GNUNET_SERVER_notification_context_unicast (nc, client, &reply, GNUNET_NO);
 
-  LOG (GNUNET_ERROR_TYPE_INFO,
-              "Get tunnels request from client %u completed\n",
-              c->id);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Get tunnels request from client %u completed\n", c->id);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
index 3224c9939cf35f59b725e8e92ef5d2b8d6e238d9..07375a43c4e959a9c1240ee97d5ac4f0d3808756 100644 (file)
@@ -2182,6 +2182,24 @@ GMT_get_cstate (struct MeshTunnel3 *t)
 }
 
 
+/**
+ * Get the encryption state of a tunnel.
+ *
+ * @param t Tunnel.
+ *
+ * @return Tunnel's encryption state.
+ */
+enum MeshTunnel3EState
+GMT_get_estate (struct MeshTunnel3 *t)
+{
+  if (NULL == t)
+  {
+    GNUNET_assert (0);
+    return (enum MeshTunnel3EState) -1;
+  }
+  return t->estate;
+}
+
 /**
  * Get the maximum buffer space for a tunnel towards a local client.
  *
@@ -2387,7 +2405,9 @@ GMT_send_connection_acks (struct MeshTunnel3 *t)
   /* Authorize connections to send more data */
   to_allow = buffer; /* - allowed; */
 
-  for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next)
+  for (iter = t->connection_head;
+       NULL != iter && to_allow > 0;
+       iter = iter->next)
   {
     allow_per_connection = to_allow/cs;
     to_allow -= allow_per_connection;
index 19431e346865ead4d30bd33b70766fc886e585d1..e38d313cb7662036d421f5e73a52faf4e32c33b3 100644 (file)
@@ -325,6 +325,16 @@ GMT_count_channels (struct MeshTunnel3 *t);
 enum MeshTunnel3CState
 GMT_get_cstate (struct MeshTunnel3 *t);
 
+/**
+ * Get the encryption state of a tunnel.
+ *
+ * @param t Tunnel.
+ *
+ * @return Tunnel's encryption state.
+ */
+enum MeshTunnel3EState
+GMT_get_estate (struct MeshTunnel3 *t);
+
 /**
  * Get the maximum buffer space for a tunnel towards a local client.
  *
index 5f3f2da5131c782371c91b94821044f0e8112295..6d16be08e87d78780b0c669368935a2a7f86ebf2 100644 (file)
@@ -1059,8 +1059,8 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
                  &msg->destination,
                  ntohl (msg->channels),
                  ntohl (msg->connections),
-                 ntohl (msg->estate),
-                 ntohl (msg->cstate));
+                 ntohs (msg->estate),
+                 ntohs (msg->cstate));
 
 }