More API function tests...
[oweals/gnunet.git] / src / dht / gnunet-service-wdht.c
index 8be25ad5e067babb9846f290a5358972485d7959..e1ca1c968872e784cb1b1c11a80f46920b742194 100644 (file)
@@ -24,7 +24,6 @@
  * @author Christian Grothoff
  * @author Nathan Evans
  */
-
 #include "platform.h"
 #include "gnunet_block_lib.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet-service-wdht.h"
-#include "gnunet-service-wdht_clients.h"
 #include "gnunet-service-dht_datacache.h"
-#include "gnunet-service-wdht_neighbours.h"
+#include "gnunet-service-dht_neighbours.h"
 #include "gnunet-service-dht_nse.h"
 
 
-
-/**
- * Handle for the statistics service.
- */
-struct GNUNET_STATISTICS_Handle *GDS_stats;
-
-/**
- * Our handle to the BLOCK library.
- */
-struct GNUNET_BLOCK_Context *GDS_block_context;
-
-/**
- * The configuration the DHT service is running with
- */
-const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
+/* Code shared between different DHT implementations */
+#include "gnunet-service-dht_clients.c"
 
 
 /**
@@ -67,16 +52,17 @@ shutdown_task (void *cls)
   GDS_NEIGHBOURS_done ();
   GDS_DATACACHE_done ();
   GDS_NSE_done ();
-  if (GDS_block_context != NULL)
+  if (NULL != GDS_block_context)
   {
     GNUNET_BLOCK_context_destroy (GDS_block_context);
     GDS_block_context = NULL;
   }
-  if (GDS_stats != NULL)
+  if (NULL != GDS_stats)
   {
     GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES);
     GDS_stats = NULL;
   }
+  GDS_CLIENTS_stop ();
 }
 
 
@@ -84,48 +70,34 @@ shutdown_task (void *cls)
  * Process dht requests.
  *
  * @param cls closure
- * @param server the initialized server
  * @param c configuration to use
+ * @param service the initialized service
  */
 static void
-run (void *cls, struct GNUNET_SERVER_Handle *server,
-     const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+     const struct GNUNET_CONFIGURATION_Handle *c,
+     struct GNUNET_SERVICE_Handle *service)
 {
   GDS_cfg = c;
+  GDS_service = service;
   GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
-  GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg);
+  GDS_stats = GNUNET_STATISTICS_create ("dht",
+                                        GDS_cfg);
   GDS_NSE_init ();
   GDS_DATACACHE_init ();
-  GDS_CLIENTS_init (server);
+  GDS_CLIENTS_init ();
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
   if (GNUNET_OK != GDS_NEIGHBOURS_init ())
   {
-    shutdown_task (NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
-                                NULL);
 }
 
 
-/**
- * The main function for the dht service.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
- */
-int
-main (int argc, char *const *argv)
-{
-  int ret;
+/* Finally, define the main method */
+GDS_DHT_SERVICE_INIT("wdht", &run);
 
-  ret =
-      (GNUNET_OK ==
-       GNUNET_SERVICE_run (argc, argv, "wdht",
-                           GNUNET_SERVICE_OPTION_NONE, &run,
-                           NULL)) ? 0 : 1;
-  GDS_CLIENTS_done ();
-  return ret;
-}
 
 /* end of gnunet-service-wdht.c */