2 This file is part of GNUnet
3 (C) 2008--2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/gnunet-service-test-barriers.c
23 * @brief Daemon acting as a service for testing testbed barriers. It is
24 * started as a peer service and waits for a barrier to be crossed.
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
31 #include "test_testbed_api_barriers.h"
36 #define LOG(type,...) \
37 GNUNET_log (type, __VA_ARGS__);
40 * Our barrier wait handle
42 struct GNUNET_TESTBED_BarrierWaitHandle *wh;
46 * Dummy task callback to keep us running forever
49 * @param tc scheduler task context
52 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
55 GNUNET_TESTBED_barrier_wait_cancel (wh);
61 * Functions of this type are to be given as acallback argumetn to
62 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
63 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
66 * @param name the barrier name
67 * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
68 * GNUNET_OK if the barrier is crossed
71 barrier_wait_cb (void *cls, const char *name, int status)
73 GNUNET_break (NULL == cls);
75 GNUNET_break (GNUNET_OK == status);
80 * Task to wait for the barrier
83 * @param tc scheduler task context
87 do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
91 wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
92 GNUNET_break (NULL != wh);
100 * @param args arguments passed to GNUNET_PROGRAM_run
101 * @param cfgfile the path to configuration file
102 * @param cfg the configuration file handle
105 run (void *cls, char *const *args, const char *cfgfile,
106 const struct GNUNET_CONFIGURATION_Handle *config)
110 rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
111 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
112 (GNUNET_TIME_UNIT_SECONDS, rsec),
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
123 int main (int argc, char **argv)
125 struct GNUNET_GETOPT_CommandLineOption options[] = {
126 GNUNET_GETOPT_OPTION_END
131 GNUNET_PROGRAM_run (argc, argv,
132 "test-barriers", "nohelp", options, &run, NULL);