From e4d12b9b2c3584dba64e7b3ae2d2b466d09b6122 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 18 Jun 2014 00:22:35 +0000 Subject: [PATCH] Add a debug "dump to stderr" feature to cadet --- src/cadet/cadet_api.c | 15 ++++++ src/cadet/cadet_common.c | 6 +-- src/cadet/gnunet-cadet.c | 42 +++++++++++++--- src/cadet/gnunet-service-cadet_local.c | 69 +++++++++++++++++++++++++- src/include/gnunet_cadet_service.h | 9 ++++ src/include/gnunet_protocols.h | 12 ++--- 6 files changed, 136 insertions(+), 17 deletions(-) diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index bcbc33ce3..12d1ba2da 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c @@ -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. diff --git a/src/cadet/cadet_common.c b/src/cadet/cadet_common.c index 94ba1bdfa..b1d0501b2 100644 --- a/src/cadet/cadet_common.c +++ b/src/cadet/cadet_common.c @@ -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: diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 2a43f570d..d6ae66331 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c @@ -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; diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c index 3f1c05bc3..b7ac11c5e 100644 --- a/src/cadet/gnunet-service-cadet_local.c +++ b/src/cadet/gnunet-service-cadet_local.c @@ -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} }; diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h index e69c9eaa7..14826c40b 100644 --- a/src/include/gnunet_cadet_service.h +++ b/src/include/gnunet_cadet_service.h @@ -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. diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 0368fac34..77c6a6337 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -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 -- 2.25.1