GNUnet  0.10.x
gnunet-service-test-barriers.c
Go to the documentation of this file.
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 
28 #include "platform.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
31 #include "test_testbed_api_barriers.h"
32 
36 #define LOG(type, ...) \
37  GNUNET_log(type, __VA_ARGS__);
38 
43 
44 static struct GNUNET_SCHEDULER_Task *tt;
45 
46 
52 static void
53 do_shutdown(void *cls)
54 {
55  if (NULL != wh)
56  {
58  wh = NULL;
59  }
60  if (NULL != tt)
61  {
63  tt = NULL;
64  }
65 }
66 
67 
78 static void
79 barrier_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 
95 static void
96 do_wait(void *cls)
97 {
98  tt = NULL;
99  wh = GNUNET_TESTBED_barrier_wait(TEST_BARRIER_NAME,
101  NULL);
102  GNUNET_break(NULL != wh);
103 }
104 
105 
114 static void
115 run(void *cls,
116  char *const *args,
117  const char *cfgfile,
118  const struct GNUNET_CONFIGURATION_Handle *config)
119 {
120  unsigned int rsec;
121 
123  10);
125  rsec),
126  &do_wait,
127  NULL);
129 }
130 
131 
132 
136 int
137 main(int argc, char **argv)
138 {
139  struct GNUNET_GETOPT_CommandLineOption options[] = {
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 }
void GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h)
Cancel a barrier wait handle.
static void barrier_wait_cb(void *cls, const char *name, int status)
Functions of this type are to be given as acallback argumetn to GNUNET_TESTBED_barrier_wait().
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
Randomness for IVs etc.
uint16_t status
See PRISM_STATUS_*-constants.
static const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
int main(int argc, char **argv)
Main.
static struct GNUNET_SCHEDULER_Task * tt
struct GNUNET_TESTBED_BarrierWaitHandle * GNUNET_TESTBED_barrier_wait(const char *name, GNUNET_TESTBED_barrier_wait_cb cb, void *cls)
Wait for a barrier to be crossed.
const char * name
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
configuration data
Definition: configuration.c:83
Entry in list of pending tasks.
Definition: scheduler.c:131
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:367
static void do_shutdown(void *cls)
Dummy task callback to keep us running forever.
static void do_wait(void *cls)
Task to wait for the barrier.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main run function.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956