aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-test-barriers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-test-barriers.c')
-rw-r--r--src/testbed/gnunet-service-test-barriers.c152
1 files changed, 0 insertions, 152 deletions
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c
deleted file mode 100644
index e10a28902..000000000
--- a/src/testbed/gnunet-service-test-barriers.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
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>
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testbed_service.h"
31#include "test_testbed_api_barriers.h"
32
33/**
34 * logging short hand
35 */
36#define LOG(type, ...) \
37 GNUNET_log (type, __VA_ARGS__);
38
39/**
40 * Our barrier wait handle
41 */
42static struct GNUNET_TESTBED_BarrierWaitHandle *wh;
43
44static struct GNUNET_SCHEDULER_Task *tt;
45
46
47/**
48 * Dummy task callback to keep us running forever
49 *
50 * @param cls NULL
51 */
52static void
53do_shutdown (void *cls)
54{
55 if (NULL != wh)
56 {
57 GNUNET_TESTBED_barrier_wait_cancel (wh);
58 wh = NULL;
59 }
60 if (NULL != tt)
61 {
62 GNUNET_SCHEDULER_cancel (tt);
63 tt = NULL;
64 }
65}
66
67
68/**
69 * Functions of this type are to be given as acallback argument to
70 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
71 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
72 *
73 * @param cls NULL
74 * @param name the barrier name
75 * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
76 * #GNUNET_OK if the barrier is crossed
77 */
78static void
79barrier_wait_cb (void *cls,
80 const char *name,
81 int status)
82{
83 GNUNET_break (NULL == cls);
84 wh = NULL;
85 GNUNET_break (GNUNET_OK == status);
86}
87
88
89/**
90 * Task to wait for the barrier
91 *
92 * @param cls NULL
93 * @return
94 */
95static void
96do_wait (void *cls)
97{
98 tt = NULL;
99 wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
100 &barrier_wait_cb,
101 NULL);
102 GNUNET_break (NULL != wh);
103}
104
105
106/**
107 * Main run function.
108 *
109 * @param cls NULL
110 * @param args arguments passed to GNUNET_PROGRAM_run
111 * @param cfgfile the path to configuration file
112 * @param config the configuration file handle
113 */
114static void
115run (void *cls,
116 char *const *args,
117 const char *cfgfile,
118 const struct GNUNET_CONFIGURATION_Handle *config)
119{
120 unsigned int rsec;
121
122 rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
123 10);
124 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
125 GNUNET_TIME_UNIT_SECONDS,
126 rsec),
127 &do_wait,
128 NULL);
129 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
130}
131
132
133/**
134 * Main
135 */
136int
137main (int argc, char **argv)
138{
139 struct GNUNET_GETOPT_CommandLineOption options[] = {
140 GNUNET_GETOPT_OPTION_END
141 };
142 int ret;
143
144 ret =
145 GNUNET_PROGRAM_run (argc, argv,
146 "test-barriers",
147 "nohelp",
148 options,
149 &run,
150 NULL);
151 return ret;
152}