From: Matthias Wachs Date: Wed, 22 Feb 2012 12:09:48 +0000 (+0000) Subject: - changess X-Git-Tag: initial-import-from-subversion-38251~14741 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8961a8c3b9d2ed5f72ebf62e7326e103688df37c;p=oweals%2Fgnunet.git - changess --- diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index fbe212c44..0aec6bb8e 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -99,6 +99,10 @@ struct GNUNET_NAMESTORE_Handle */ GNUNET_SCHEDULER_TaskIdentifier reconnect_task; + /** + * Pending messages to send to the service + */ + struct PendingMessage * pending_head; struct PendingMessage * pending_tail; diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 85fbcbfc5..8b78c0842 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c @@ -27,18 +27,88 @@ #define VERBOSE GNUNET_EXTRA_LOGGING +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + static struct GNUNET_NAMESTORE_Handle * nsh; +static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; +static struct GNUNET_OS_Process *arm; + static int res; +static void +start_arm (const char *cfgname) +{ + arm = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + "gnunet-service-arm", "-c", cfgname, +#if VERBOSE_PEERS + "-L", "DEBUG", +#else + "-L", "ERROR", +#endif + NULL); +} + +static void +stop_arm () +{ + if (NULL != arm) + { + if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + GNUNET_OS_process_wait (arm); + GNUNET_OS_process_close (arm); + arm = NULL; + } +} + +/** + * Re-establish the connection to the service. + * + * @param cls handle to use to re-connect. + * @param tc scheduler context + */ +static void +endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (NULL != arm) + stop_arm(); + res = 1; +} + + +static void +end (void) +{ + if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_NO_TASK; + } + + if (NULL != arm) + stop_arm(); + + res = 0; +} + + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); + + start_arm (cfgfile); + GNUNET_assert (arm != NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); + + stop_arm (); + end (); res = 0; }