Add a debug "dump to stderr" feature to cadet
authorBart Polot <bart@net.in.tum.de>
Wed, 18 Jun 2014 00:22:35 +0000 (00:22 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 18 Jun 2014 00:22:35 +0000 (00:22 +0000)
src/cadet/cadet_api.c
src/cadet/cadet_common.c
src/cadet/gnunet-cadet.c
src/cadet/gnunet-service-cadet_local.c
src/include/gnunet_cadet_service.h
src/include/gnunet_protocols.h

index bcbc33ce39c25f29c381f9b78789ba16703cd35b..12d1ba2dad17aae88ea301a0d81f486b0e628c91 100644 (file)
@@ -1809,6 +1809,21 @@ send_info_request (struct GNUNET_CADET_Handle *h, uint16_t type)
 }
 
 
+/**
+ * Request a debug dump on the service's STDERR.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h cadet handle
+ */
+void
+GNUNET_CADET_request_dump (struct GNUNET_CADET_Handle *h)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "requesting dump\n");
+  send_info_request (h, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP);
+}
+
+
 /**
  * Request information about peers known to the running cadet service.
  * The callback will be called for every peer known to the service.
index 94ba1bdfa9b89a482fbe841390973997642863be..b1d0501b2bc8d7d96e8346916e83d86d5a63c066 100644 (file)
@@ -328,10 +328,10 @@ GC_m2s (uint16_t m)
       break;
 
       /**
-       * 640kb should be enough for everybody
+       * Debug request.
        */
-    case 299:
-      t = "RESERVE_END";
+    case GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP:
+      t = "INFO_DUMP";
       break;
 
     default:
index 2a43f570d9a2cc643a75ae8dd1de55fc203e1156..d6ae663316bfdacb195b39cad29af9fc59b69ba8 100644 (file)
@@ -32,7 +32,7 @@
 /**
  * Option -m.
  */
-static int monitor_connections;
+static int monitor_mode;
 
 /**
  * Option -P.
@@ -74,6 +74,11 @@ static uint32_t listen_port;
  */
 int echo;
 
+/**
+ * Request a debug dump
+ */
+int dump;
+
 /**
  * Time of last echo request.
  */
@@ -333,6 +338,20 @@ 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)
+{
+  GNUNET_CADET_request_dump (mh);
+  GNUNET_SCHEDULER_cancel (sd);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+}
+
 
 /**
  * Call CADET's monitor API, get info of one connection.
@@ -458,7 +477,7 @@ peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
 {
   if (NULL == peer)
   {
-    if (GNUNET_YES != monitor_connections)
+    if (GNUNET_YES != monitor_mode)
     {
       GNUNET_SCHEDULER_shutdown();
     }
@@ -512,7 +531,7 @@ tunnels_callback (void *cls,
 {
   if (NULL == peer)
   {
-    if (GNUNET_YES != monitor_connections)
+    if (GNUNET_YES != monitor_mode)
     {
       GNUNET_SCHEDULER_shutdown();
     }
@@ -560,7 +579,7 @@ tunnel_callback (void *cls,
     FPRINTF (stdout, "- enc state: %u\n", estate);
     FPRINTF (stdout, "- con state: %u\n", cstate);
   }
-  if (GNUNET_YES != monitor_connections)
+  if (GNUNET_YES != monitor_mode)
   {
     GNUNET_SCHEDULER_shutdown();
   }
@@ -706,7 +725,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   target_id = args[0];
   target_port = args[0] && args[1] ? atoi(args[1]) : 0;
   if ( (0 != (request_peers | request_tunnels)
-        || 0 != monitor_connections
+        || 0 != monitor_mode
         || NULL != tunnel_id
         || NULL != conn_id
         || NULL != channel_id)
@@ -718,7 +737,13 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
-  if (NULL != target_id)
+  if (GNUNET_YES == dump)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "requesting debug dump\n");
+    GNUNET_SCHEDULER_add_now (&request_dump, NULL);
+  }
+  else if (NULL != target_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Creating channel to %s\n",
@@ -809,6 +834,9 @@ main (int argc, char *const *argv)
     {'e', "echo", NULL,
      gettext_noop ("activate echo mode"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &echo},
+    {'d', "dump", NULL,
+     gettext_noop ("dump debug information to STDERR"),
+     GNUNET_NO, &GNUNET_GETOPT_set_one, &dump},
 //     {'m', "monitor", NULL,
 //      gettext_noop ("provide information about all events (continuously)"),
 //      GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_mode},
@@ -831,7 +859,7 @@ main (int argc, char *const *argv)
     GNUNET_GETOPT_OPTION_END
   };
 
-  monitor_connections = GNUNET_NO;
+  monitor_mode = GNUNET_NO;
 
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
index 3f1c05bc30ef54fc09937ac0bddc23d9a2aa0361..b7ac11c5e12b4e9912d733c484e2532ea3ce5ba1 100644 (file)
@@ -580,7 +580,6 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
-
 /**
  * Iterator over all peers to send a monitoring client info about each peer.
  *
@@ -614,6 +613,36 @@ get_all_peers_iterator (void *cls,
 }
 
 
+/**
+ * Iterator over all peers to dump info for each peer.
+ *
+ * @param cls Closure (unused).
+ * @param peer Peer ID (tunnel remote peer).
+ * @param value Peer info.
+ *
+ * @return #GNUNET_YES, to keep iterating.
+ */
+static int
+show_peer_iterator (void *cls,
+                        const struct GNUNET_PeerIdentity * peer,
+                        void *value)
+{
+  struct CadetPeer *p = value;
+  struct CadetTunnel *t;
+
+  LOG (GNUNET_ERROR_TYPE_ERROR, "Peer %s\n", GCP_2s (p));
+  LOG (GNUNET_ERROR_TYPE_ERROR, " %u paths\n", GCP_count_paths (p));
+
+  t = GCP_get_tunnel (p);
+  if (NULL != t)
+    GCT_debug (t, GNUNET_ERROR_TYPE_ERROR);
+
+  LOG (GNUNET_ERROR_TYPE_ERROR, "\n");
+
+  return GNUNET_YES;
+}
+
+
 /**
  * Handler for client's INFO PEERS request.
  *
@@ -830,6 +859,42 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
+/**
+ * Handler for client's INFO_DUMP request.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+void
+handle_info_dump (void *cls, struct GNUNET_SERVER_Client *client,
+                  const struct GNUNET_MessageHeader *message)
+{
+  struct CadetClient *c;
+
+  /* Sanity check for client registration */
+  if (NULL == (c = GML_client_get (client)))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
+  LOG (GNUNET_ERROR_TYPE_INFO, "Received dump info request from client %u\n",
+       c->id);
+
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "*************************** DUMP START ***************************\n");
+
+  GCP_iterate_all (&show_peer_iterator, NULL);
+
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "**************************** DUMP END ****************************\n");
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
 /**
  * Functions to handle messages from clients
  */
@@ -848,6 +913,8 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
    sizeof (struct GNUNET_MessageHeader)},
   {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
    sizeof (struct GNUNET_CADET_LocalInfo)},
+  {&handle_info_dump, NULL, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP,
+   sizeof (struct GNUNET_MessageHeader)},
   {NULL, NULL, 0, 0}
 };
 
index e69c9eaa71c642ce4642d32b8d0baba4e67adde7..14826c40bdbb5b009f73b6dcac77208fd3540503 100644 (file)
@@ -493,6 +493,15 @@ GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h,
                          GNUNET_CADET_ChannelCB callback,
                          void *callback_cls);
 
+/**
+ * Request a debug dump on the service's STDERR.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h cadet handle
+ */
+void
+GNUNET_CADET_request_dump (struct GNUNET_CADET_Handle *h);
 
 /**
  * Request information about peers known to the running cadet service.
index 0368fac342395dc34122dfa08a9a97d84b9b507a..77c6a6337556d3af78a8dcf606d4431c29e05c34 100644 (file)
@@ -946,9 +946,9 @@ extern "C"
 #define GNUNET_MESSAGE_TYPE_CADET_CLI                    298
 
 /**
- * 640kb should be enough for everybody
+ * Debug request.
  */
-#define GNUNET_MESSAGE_TYPE_CADET_RESERVE_END            299
+#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP        299
 
 
 
@@ -2493,7 +2493,7 @@ extern "C"
 #define GNUNET_MESSAGE_TYPE_SOCIAL_JOIN_DECISION 848
 
 /*******************************************************************************
- * X-VINE DHT messages 
+ * X-VINE DHT messages
  ******************************************************************************/
 
 /**
@@ -2532,17 +2532,17 @@ extern "C"
 #define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_REJECTION 886
 
 /**
- * Trail Tear down Message. 
+ * Trail Tear down Message.
  */
 #define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN 887
 
 /**
- * Routing table add message. 
+ * Routing table add message.
  */
 #define GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL 888
 
 /**
- * Trail compression message. 
+ * Trail compression message.
  */
 #define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_COMPRESSION 889