refactor DHT for new service API
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet.c
index de9aaf7a51c3735fe3537cebd00d7ac5ef98555c..3a07f0ee58e3de12258fbe4d85be84dc02e648b5 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001-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.
 */
 
 /**
@@ -98,21 +98,20 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
  * Task run during shutdown.
  *
  * @param cls unused
- * @param tc unused
  */
 static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
 
   shutting_down = GNUNET_YES;
 
   GML_shutdown ();
-  GMH_shutdown ();
-  GMC_shutdown ();
-  GMT_shutdown ();
-  GMD_shutdown ();
-  GMP_shutdown ();
+  GCH_shutdown ();
+  GCC_shutdown ();
+  GCT_shutdown ();
+  GCD_shutdown ();
+  GCP_shutdown ();
 
   GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
   stats = NULL;
@@ -136,23 +135,23 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   stats = GNUNET_STATISTICS_create ("cadet", c);
 
   /* Scheduled the task to clean up when shutdown is called */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
   my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
   GNUNET_assert (NULL != my_private_key);
   GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key);
   myid = GNUNET_PEER_intern (&my_full_id);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "STARTING SERVICE (CADET) for peer [%s]\n",
+              "STARTING SERVICE (cadet) for peer [%s]\n",
               GNUNET_i2s (&my_full_id));
 
   GML_init (server);    /* Local clients */
-  GMH_init (c);         /* Hellos */
-  GMC_init (c);         /* Connections */
-  GMP_init (c);         /* Peers */
-  GMD_init (c);         /* DHT */
-  GMT_init (c, my_private_key); /* Tunnels */
+  GCH_init (c);         /* Hellos */
+  GCC_init (c);         /* Connections */
+  GCP_init (c);         /* Peers */
+  GCD_init (c);         /* DHT */
+  GCT_init (c, my_private_key); /* Tunnels */
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cadet service running\n");
 }
@@ -168,14 +167,18 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
 int
 main (int argc, char *const *argv)
 {
-  int ret;
   int r;
 
   shutting_down = GNUNET_NO;
   r = GNUNET_SERVICE_run (argc, argv, "cadet", GNUNET_SERVICE_OPTION_NONE, &run,
                           NULL);
   GNUNET_free (my_private_key);
-  ret = (GNUNET_OK == r) ? 0 : 1;
 
-  return ret;
+  if (GNUNET_OK != r)
+  {
+    FPRINTF (stderr, "GNUNET_SERVICE_run for CADET has failed!\n");
+    return 1;
+  }
+
+  return 0;
 }