- plugin (un)loading
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 22 Feb 2012 17:23:14 +0000 (17:23 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 22 Feb 2012 17:23:14 +0000 (17:23 +0000)
src/namestore/gnunet-service-namestore.c
src/namestore/test_namestore_api.c

index 5bfda01610cf749bbe6fd0469d28e4cb0ca1d9a5..af8234638789fbb1bce6926f7039ad6081e42b1a 100644 (file)
 #include "gnunet_getopt_lib.h"
 #include "gnunet_service_lib.h"
 #include "gnunet_namestore_service.h"
+#include "gnunet_namestore_plugin.h"
 #include "namestore.h"
 
+/**
+ * Configuration handle.
+ */
+const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
+
+static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
+
+static char *db_lib_name;
 
 /**
  * Task run during shutdown.
 static void
 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  /* FIXME: do clean up here */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
+
+  GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
+  GNUNET_free (db_lib_name);
 }
 
 static void handle_start ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "START");
-
 }
 
 
@@ -60,15 +71,37 @@ static void
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  char * database;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
+
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_start, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
     {NULL, NULL, 0, 0}
   };
 
+  GSN_cfg = cfg;
+
+  /* Loading database plugin */
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database",
+                                             &database))
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
+
+  GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
+  GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
+  if (GSN_database == NULL)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n",
+        db_lib_name);
+  GNUNET_free (database);
+
+  /* Configuring server handles */
   GNUNET_SERVER_add_handlers (server, handlers);
+
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
                                 NULL);
+
 }
 
 
index 8b78c084269a0450f388dd8b29683002b41be027..781b48e493dbabda6dad0bc955bc56e7486c248b 100644 (file)
@@ -27,7 +27,7 @@
 
 #define VERBOSE GNUNET_EXTRA_LOGGING
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
 static struct GNUNET_NAMESTORE_Handle * nsh;
 
@@ -107,8 +107,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_break (NULL != nsh);
   GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
 
-  stop_arm ();
-  end ();
+  //stop_arm ();
+  //end ();
   res = 0;
 }