From d1ee58bf994791f6b0020029db0959ec831b927d Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 16 Jan 2014 09:53:34 +0000 Subject: [PATCH] fixes for reconnecting and message handling --- .../gnunet-service-transport_clients.c | 3 +- src/transport/gnunet-transport.c | 25 ++++++++++--- src/transport/transport_api_monitoring.c | 36 ++++++++++++++----- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index fb848d0af..aefe581c7 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -1219,13 +1219,12 @@ clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client *clien if (GNUNET_YES != ntohl (msg->one_shot)) { - GNUNET_break (0); setup_val_monitoring_client (client, &msg->peer); } else { GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); } GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); } diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 8311c1d72..56df0fbf6 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -113,6 +113,11 @@ static int monitor_connects; */ static int monitor_connections; +/** + * Option -f. + */ +static int monitor_validation; + /** * Option -C. */ @@ -498,8 +503,9 @@ process_validation_string (void *cls, const char *address) s_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); FPRINTF (stdout, - _("Peer `%s' %s `%s'\n\t%s%s\n\t%s%s\n\t%s%s\n"), - GNUNET_i2s (&vc->id), address, GNUNET_TRANSPORT_vs2s (vc->state), + _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), + GNUNET_i2s (&vc->id), address, + (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", "Valid until : ", s_valid, "Last validation: ",s_last, "Next validation: ", s_next); @@ -1135,7 +1141,8 @@ testservice_task (void *cls, int result) } counter = benchmark_send + benchmark_receive + iterate_connections - + monitor_connections + monitor_connects + try_connect + iterate_validation; + + monitor_connections + monitor_connects + try_connect + + iterate_validation + monitor_validation; if (1 < counter) { @@ -1246,9 +1253,16 @@ testservice_task (void *cls, int result) } else if (iterate_validation) /* -d: Print information about validations */ { - vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, (NULL == cpid) ? NULL : &pid, + vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, + (NULL == cpid) ? NULL : &pid, GNUNET_YES, TIMEOUT, &process_validation_cb, (void *) cfg); } + else if (monitor_validation) /* -f: Print information about validations continuously */ + { + vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg, + (NULL == cpid) ? NULL : &pid, + GNUNET_NO, TIMEOUT, &process_validation_cb, (void *) cfg); + } else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ { monitor_connect_counter = 0; @@ -1312,6 +1326,9 @@ main (int argc, char * const *argv) { 'd', "validation", NULL, gettext_noop ("print information for all pending validations "), 0, &GNUNET_GETOPT_set_one, &iterate_validation }, + { 'f', "monitorvalidation", NULL, + gettext_noop ("print information for all pending validations continously"), + 0, &GNUNET_GETOPT_set_one, &monitor_validation }, { 'i', "information", NULL, gettext_noop ("provide information about all current connections (once)"), 0, &GNUNET_GETOPT_set_one, &iterate_connections }, diff --git a/src/transport/transport_api_monitoring.c b/src/transport/transport_api_monitoring.c index 9d74eb114..af5988151 100644 --- a/src/transport/transport_api_monitoring.c +++ b/src/transport/transport_api_monitoring.c @@ -240,6 +240,8 @@ GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state) { switch (state) { + case GNUNET_TRANSPORT_VS_NONE: + return "NEW"; case GNUNET_TRANSPORT_VS_NEW: return "NEW"; case GNUNET_TRANSPORT_VS_REMOVE: @@ -309,7 +311,7 @@ send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_c { struct ValidationMonitorMessage msg; - msg.header.size = htons (sizeof (struct PeerMonitorMessage)); + msg.header.size = htons (sizeof (struct ValidationMonitorMessage)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST); msg.one_shot = htonl (val_ctx->one_shot); msg.peer = val_ctx->peer; @@ -322,7 +324,6 @@ send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_c val_ctx)); } - /** * Task run to re-establish the connection. * @@ -330,8 +331,8 @@ send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_c * @param tc scheduler context, unused */ static void -do_connect (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +do_peer_connect (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; @@ -355,10 +356,29 @@ reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) pal_ctx->client = NULL; pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff); pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff, - &do_connect, + &do_peer_connect, pal_ctx); } + +/** + * Task run to re-establish the connection. + * + * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*' + * @param tc scheduler context, unused + */ +static void +do_val_connect (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls; + + val_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK; + val_ctx->client = GNUNET_CLIENT_connect ("transport", val_ctx->cfg); + GNUNET_assert (NULL != val_ctx->client); + send_val_mon_request (val_ctx); +} + /** * Cut the existing connection and reconnect. * @@ -372,7 +392,7 @@ reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx) val_ctx->client = NULL; val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff); val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff, - &do_connect, + &do_val_connect, val_ctx); } @@ -397,7 +417,6 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) if (msg == NULL) { - GNUNET_break (0); if (val_ctx->one_shot) { /* Disconnect */ @@ -415,6 +434,7 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) size = ntohs (msg->size); GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); + if (size == sizeof (struct GNUNET_MessageHeader)) { /* Done! */ @@ -548,7 +568,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) uint16_t size; size_t alen; size_t tlen; - GNUNET_break (0); + if (msg == NULL) { if (pal_ctx->one_shot) -- 2.25.1