From: Matthias Wachs Date: Wed, 22 Feb 2012 17:23:14 +0000 (+0000) Subject: - plugin (un)loading X-Git-Tag: initial-import-from-subversion-38251~14722 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1a9ce3aa8f18ddde390b45d7161b4d58a928379e;p=oweals%2Fgnunet.git - plugin (un)loading --- diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 5bfda0161..af8234638 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -27,8 +27,17 @@ #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. @@ -39,13 +48,15 @@ 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); + } diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 8b78c0842..781b48e49 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c @@ -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; }