plugin datastore mysql
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index b9465b2fe652ddb4953a068027dcb8de22e23325..8a286742c60688c369dbc56394dafd4e1468ead9 100644 (file)
@@ -1,6 +1,6 @@
 /*
   This file is part of GNUnet.
-  (C) 2008--2013 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2008--2013 GNUnet e.V.
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
   You should have received a copy of the GNU General Public License
   along with GNUnet; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-  Boston, MA 02111-1307, USA.
+  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -129,12 +129,6 @@ static struct MessageQueue *mq_head;
 static struct MessageQueue *mq_tail;
 
 
-/**
- * The shutdown task handle
- */
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
-
-
 /**
  * Function called to notify a client about the connection begin ready to queue
  * more data.  "buf" will be NULL and "size" zero if the connection was closed
@@ -191,7 +185,7 @@ GST_queue_message (struct GNUNET_SERVER_Client *client,
   size = ntohs (msg->size);
   GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
                  (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
-  mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
+  mq_entry = GNUNET_new (struct MessageQueue);
   mq_entry->msg = msg;
   mq_entry->client = client;
   GNUNET_SERVER_client_keep (client);
@@ -364,7 +358,7 @@ GST_queue_host_registration (struct Slave *slave,
        "Queueing host registration for host %u at %u\n",
        GNUNET_TESTBED_host_get_id_ (host),
        GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id]));
-  hr = GNUNET_malloc (sizeof (struct HostRegistration));
+  hr = GNUNET_new (struct HostRegistration);
   hr->cb = cb;
   hr->cb_cls = cb_cls;
   hr->host = host;
@@ -405,11 +399,9 @@ GST_forwarded_operation_reply_relay (void *cls,
  * Task to free resources when forwarded operation has been timedout
  *
  * @param cls the ForwardedOperationContext
- * @param tc the task context from scheduler
  */
 void
-GST_forwarded_operation_timeout (void *cls,
-                                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+GST_forwarded_operation_timeout (void *cls)
 {
   struct ForwardedOperationContext *fopc = cls;
 
@@ -446,7 +438,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;
@@ -482,7 +474,8 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
  * @param message the actual message
  */
 static void
-handle_init (void *cls, struct GNUNET_SERVER_Client *client,
+handle_init (void *cls,
+            struct GNUNET_SERVER_Client *client,
              const struct GNUNET_MessageHeader *message)
 {
   const struct GNUNET_TESTBED_InitMessage *msg;
@@ -525,7 +518,7 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_free (ss_str);
     ss_str = NULL;
   }
-  GST_context = GNUNET_malloc (sizeof (struct Context));
+  GST_context = GNUNET_new (struct Context);
   GNUNET_SERVER_client_keep (client);
   GST_context->client = client;
   GST_context->host_id = ntohl (msg->host_id);
@@ -555,14 +548,15 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
 
 
 /**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
+ * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
  *
  * @param cls NULL
  * @param client identification of the client
  * @param message the actual message
  */
 static void
-handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
+handle_add_host (void *cls,
+                struct GNUNET_SERVER_Client *client,
                  const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTBED_Host *host;
@@ -590,7 +584,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))
   {
@@ -671,14 +665,15 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
 
 
 /**
- * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
  *
  * @param cls NULL
  * @param client identification of the client
  * @param message the actual message
  */
 static void
-handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
+handle_slave_get_config (void *cls,
+                        struct GNUNET_SERVER_Client *client,
                          const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
@@ -731,12 +726,12 @@ void
 GST_clear_fopcq ()
 {
   struct ForwardedOperationContext *fopc;
-  
+
   while (NULL != (fopc = fopcq_head))
   {
     GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
     GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
-    if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
+    if (NULL != fopc->timeout_task)
       GNUNET_SCHEDULER_cancel (fopc->timeout_task);
     GNUNET_SERVER_client_drop (fopc->client);
     switch (fopc->type)
@@ -747,7 +742,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)
@@ -776,15 +771,13 @@ GST_clear_fopcq ()
  * Task to clean up and shutdown nicely
  *
  * @param cls NULL
- * @param tc the TaskContext from scheduler
  */
 static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   struct MessageQueue *mq_entry;
   uint32_t id;
 
-  shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
   LOG_DEBUG ("Shutting down testbed service\n");
   /* cleanup any remaining forwarded operations */
   GST_clear_fopcq ();
@@ -901,9 +894,9 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
      sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
     {&GST_handle_peer_reconfigure, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
-    {&GST_handle_barrier_init, NULL, 
+    {&GST_handle_barrier_init, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0},
-    {&GST_handle_barrier_cancel, NULL, 
+    {&GST_handle_barrier_cancel, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0},
     {&GST_handle_barrier_status, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 0},
@@ -942,10 +935,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
   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 =
-      GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                  GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                                  &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   LOG_DEBUG ("Testbed startup complete\n");
   GST_stats_init (GST_config);
   GST_barriers_init (GST_config);
@@ -958,9 +948,10 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
 int
 main (int argc, char *const *argv)
 {
-  //sleep (15);                 /* Debugging */
   return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
+          GNUNET_SERVICE_run (argc, argv,
+                             "testbed",
+                             GNUNET_SERVICE_OPTION_NONE,
                               &testbed_run, NULL)) ? 0 : 1;
 }