fixes for reconnecting and message handling
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Jan 2014 09:53:34 +0000 (09:53 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 16 Jan 2014 09:53:34 +0000 (09:53 +0000)
src/transport/gnunet-service-transport_clients.c
src/transport/gnunet-transport.c
src/transport/transport_api_monitoring.c

index fb848d0afdc37087f18bca9978f31b740749d8c5..aefe581c7d488776c7f829131db27391afaf0fed 100644 (file)
@@ -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);
 }
index 8311c1d72d66a00338f5c42ee19aad415ea7b861..56df0fbf622840003e91879fa14725b76ec04642 100644 (file)
@@ -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 },
index 9d74eb114d434a7dd05a81ff31a8845e7e4191d8..af59881516dfb40fe38cd1a31d563403859a0542 100644 (file)
@@ -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)