X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftestbed%2Fgnunet-service-test-barriers.c;h=efc9d56777e825e6adc7ebb2a89d607f2bfb0fe5;hb=db9c68c76d7a9eb3f200df9d0fcaf971387cb061;hp=84c6bde68286c43f2a066a25d3d70c7f84de787f;hpb=2ca4b8a208f6f910c819bbaa6785a25ae2955501;p=oweals%2Fgnunet.git diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c index 84c6bde68..efc9d5677 100644 --- a/src/testbed/gnunet-service-test-barriers.c +++ b/src/testbed/gnunet-service-test-barriers.c @@ -22,11 +22,113 @@ * @file testbed/gnunet-service-test-barriers.c * @brief Daemon acting as a service for testing testbed barriers. It is * started as a peer service and waits for a barrier to be crossed. - * @author Sree Harsha Totakura + * @author Sree Harsha Totakura */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testbed_service.h" +#include "test_testbed_api_barriers.h" -int main () +/** + * logging short hand + */ +#define LOG(type,...) \ + GNUNET_log (type, __VA_ARGS__); + +/** + * Our barrier wait handle + */ +struct GNUNET_TESTBED_BarrierWaitHandle *wh; + + +/** + * Dummy task callback to keep us running forever + * + * @param cls NULL + * @param tc scheduler task context + */ +static void +do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (NULL != wh) + GNUNET_TESTBED_barrier_wait_cancel (wh); + wh = NULL; +} + + +/** + * Functions of this type are to be given as acallback argumetn to + * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier + * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled. + * + * @param cls NULL + * @param name the barrier name + * @param status GNUNET_SYSERR in case of error while waiting for the barrier; + * GNUNET_OK if the barrier is crossed + */ +static void +barrier_wait_cb (void *cls, const char *name, int status) +{ + GNUNET_break (NULL == cls); + wh = NULL; + GNUNET_break (GNUNET_OK == status); +} + + +/** + * Task to wait for the barrier + * + * @param cls NULL + * @param tc scheduler task context + * @return + */ +static void +do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) + return; + wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL); + GNUNET_break (NULL != wh); +} + + +/** + * Main run function. + * + * @param cls NULL + * @param args arguments passed to GNUNET_PROGRAM_run + * @param cfgfile the path to configuration file + * @param config the configuration file handle + */ +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { - return 0; + unsigned int rsec; + + rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, rsec), + &do_wait, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, + &do_shutdown, NULL); +} + + + +/** + * Main + */ +int main (int argc, char **argv) +{ + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + int ret; + + ret = + GNUNET_PROGRAM_run (argc, argv, + "test-barriers", "nohelp", options, &run, NULL); + return ret; }