-remove trailing whitespace
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index 6bca3d9cdebec7b0ec1fae2675509eb88e626c65..6f806e21b6d535e1726f67602a186b8617bf445d 100644 (file)
@@ -4,7 +4,7 @@
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2, or (at your
+  by the Free Software Foundation; either version 3, or (at your
   option) any later version.
 
   GNUnet is distributed in the hope that it will be useful, but
@@ -25,7 +25,8 @@
  */
 
 #include "gnunet-service-testbed.h"
-
+#include "gnunet-service-testbed_barriers.h"
+#include "gnunet-service-testbed_connectionpool.h"
 
 /***********/
 /* Globals */
@@ -34,7 +35,7 @@
 /**
  * Our configuration
  */
-struct GNUNET_CONFIGURATION_Handle *our_config;
+struct GNUNET_CONFIGURATION_Handle *GST_config;
 
 /**
  * The master context; generated with the first INIT message
@@ -445,7 +446,7 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
     (void) memcpy (&slist[n - 1], &ss,                                  \
                    sizeof (struct GNUNET_TESTING_SharedService));       \
   } while (0)
-  
+
   slist = NULL;
   n = 0;
   ss.cfg = cfg;
@@ -453,7 +454,7 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
   {
     ss.service = NULL;
     ss.share = 0;
-    if (2 != sscanf (arg, "%255s:%u", service, &ss.share))
+    if (2 != sscanf (arg, "%255[^:]:%u", service, &ss.share))
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, "Ignoring shared service spec: %s", arg);
       continue;
@@ -516,11 +517,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
   }
   ss_str = NULL;
   ss = NULL;
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (our_config, "TESTBED",
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (GST_config, "TESTBED",
                                                           "SHARED_SERVICES",
                                                           &ss_str))
   {
-    ss = parse_shared_services (ss_str, our_config);
+    ss = parse_shared_services (ss_str, GST_config);
     GNUNET_free (ss_str);
     ss_str = NULL;
   }
@@ -546,7 +547,7 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
   host =
       GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
                                           GST_context->master_ip, NULL,
-                                          our_config, 0);
+                                          GST_config, 0);
   host_list_add (host);
   LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -589,7 +590,7 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
   username_length = ntohs (msg->username_length);
   hostname_length = ntohs (msg->hostname_length);
   /* msg must contain hostname */
-  if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) + 
+  if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
                  username_length))
       || (0 == hostname_length))
   {
@@ -616,7 +617,6 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
   }
   hostname = GNUNET_malloc (hostname_length + 1);
   strncpy (hostname, ptr, hostname_length);
-  ptr += hostname_length;
   if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message)))
   {
     GNUNET_free_non_null (username);
@@ -731,7 +731,7 @@ void
 GST_clear_fopcq ()
 {
   struct ForwardedOperationContext *fopc;
-  
+
   while (NULL != (fopc = fopcq_head))
   {
     GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
@@ -747,7 +747,7 @@ GST_clear_fopcq ()
     case OP_SHUTDOWN_PEERS:
       {
         struct HandlerContext_ShutdownPeers *hc = fopc->cls;
-        
+
         GNUNET_assert (0 < hc->nslaves);
         hc->nslaves--;
         if (0 == hc->nslaves)
@@ -762,6 +762,7 @@ GST_clear_fopcq ()
     case OP_LINK_CONTROLLERS:
     case OP_GET_SLAVE_CONFIG:
     case OP_MANAGE_SERVICE:
+    case OP_PEER_RECONFIGURE:
       break;
     case OP_FORWARDED:
       GNUNET_assert (0);
@@ -784,7 +785,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   uint32_t id;
 
   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
+  LOG_DEBUG ("Shutting down testbed service\n");
   /* cleanup any remaining forwarded operations */
   GST_clear_fopcq ();
   GST_free_lcfq ();
@@ -793,6 +794,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GST_free_roccq ();
   GST_free_nccq ();
   GST_neighbour_list_clean();
+  GST_free_prcq ();
   /* Clear peer list */
   GST_destroy_peers ();
   /* Clear route list */
@@ -823,12 +825,14 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_free (mq_entry);
   }
   GNUNET_free_non_null (hostname);
-  GNUNET_CONFIGURATION_destroy (our_config);
   /* Free hello cache */
   GST_cache_clear ();
+  GST_connection_pool_destroy ();
   GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
   GST_opq_openfds = NULL;
   GST_stats_destroy ();
+  GST_barriers_destroy ();
+  GNUNET_CONFIGURATION_destroy (GST_config);
 }
 
 
@@ -881,7 +885,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
     {&GST_handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
      sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
     {&GST_handle_peer_get_config, NULL,
-     GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION,
+     GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION,
      sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
     {&GST_handle_overlay_connect, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
@@ -895,11 +899,20 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
      sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
     {&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
      sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
+    {&GST_handle_peer_reconfigure, NULL,
+     GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
+    {&GST_handle_barrier_init, NULL,
+     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0},
+    {&GST_handle_barrier_cancel, NULL,
+     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0},
+    {&GST_handle_barrier_status, NULL,
+     GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 0},
     {NULL, NULL, 0, 0}
   };
   char *logfile;
   unsigned long long num;
 
+  LOG_DEBUG ("Starting testbed\n");
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
                                                &logfile))
@@ -911,10 +924,12 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
                  GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
                                                         "CACHE_SIZE", &num));
   GST_cache_init ((unsigned int) num);
+  GST_connection_pool_init ((unsigned int) num);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
                                                         "MAX_OPEN_FDS", &num));
-  GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ((unsigned int) num);
+  GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_
+      (OPERATION_QUEUE_TYPE_FIXED, (unsigned int) num);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
                                                       "OPERATION_TIMEOUT",
@@ -924,7 +939,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
                                                         "HOSTNAME", &hostname));
-  our_config = GNUNET_CONFIGURATION_dup (cfg);
+  GST_config = GNUNET_CONFIGURATION_dup (cfg);
   GNUNET_SERVER_add_handlers (server, message_handlers);
   GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
   shutdown_task_id =
@@ -932,7 +947,8 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
                                                   GNUNET_SCHEDULER_PRIORITY_IDLE,
                                                   &shutdown_task, NULL);
   LOG_DEBUG ("Testbed startup complete\n");
-  GST_stats_init (our_config);
+  GST_stats_init (GST_config);
+  GST_barriers_init (GST_config);
 }