aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_barriers.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-13 18:19:48 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-13 18:19:48 +0200
commit21c4b14e7e9a5f113b2c190b0223ca95074125b1 (patch)
treecb3105228f1ba52bea81c74caa642b26bc6c297e /src/testbed/testbed_api_barriers.c
parentf5c99c11e752667d6c07d16568ae16a782b48e4c (diff)
downloadgnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.tar.gz
gnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.zip
Delete more subsystems not required after tng
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r--src/testbed/testbed_api_barriers.c253
1 files changed, 0 insertions, 253 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c
deleted file mode 100644
index 6074beb12..000000000
--- a/src/testbed/testbed_api_barriers.c
+++ /dev/null
@@ -1,253 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2008--2013, 2016 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/testbed_api_barriers.c
23 * @brief API implementation for testbed barriers
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26#include "platform.h"
27#include "gnunet_testbed_service.h"
28#include "testbed_api.h"
29
30/**
31 * Logging shorthand
32 */
33#define LOG(type, ...) \
34 GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__);
35
36/**
37 * Debug logging shorthand
38 */
39#define LOG_DEBUG(...) \
40 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
41
42
43/**
44 * Barrier wait handle
45 */
46struct GNUNET_TESTBED_BarrierWaitHandle
47{
48 /**
49 * The name of the barrier
50 */
51 char *name;
52
53 /**
54 * Then configuration used for the client connection
55 */
56 struct GNUNET_CONFIGURATION_Handle *cfg;
57
58 /**
59 * The testbed-barrier service message queue.
60 */
61 struct GNUNET_MQ_Handle *mq;
62
63 /**
64 * The barrier wait callback
65 */
66 GNUNET_TESTBED_barrier_wait_cb cb;
67
68 /**
69 * The closure for @e cb.
70 */
71 void *cb_cls;
72};
73
74
75/**
76 * Check if barrier status message is well-formed.
77 *
78 * @param cls closure
79 * @param msg received message
80 * @return #GNUNET_OK if the message is well-formed.
81 */
82static int
83check_status (void *cls,
84 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
85{
86 /* FIXME: this fails to actually check that the message
87 follows the protocol spec (0-terminations!). However,
88 not critical as #handle_status() doesn't interpret the
89 variable-size part anyway right now. */
90 return GNUNET_OK;
91}
92
93
94/**
95 * Type of a function to call when we receive a message
96 * from the service.
97 *
98 * @param cls closure
99 * @param msg received message
100 */
101static void
102handle_status (void *cls,
103 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
104{
105 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls;
106
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Got barrier status %d\n",
109 (int) ntohs (msg->status));
110 switch (ntohs (msg->status))
111 {
112 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
113 h->cb (h->cb_cls,
114 h->name,
115 GNUNET_SYSERR);
116 break;
117
118 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
119 h->cb (h->cb_cls,
120 h->name,
121 GNUNET_SYSERR);
122 GNUNET_break (0);
123 break;
124
125 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
126 h->cb (h->cb_cls,
127 h->name,
128 GNUNET_OK);
129 break;
130
131 default:
132 GNUNET_break_op (0);
133 h->cb (h->cb_cls,
134 h->name,
135 GNUNET_SYSERR);
136 break;
137 }
138 GNUNET_TESTBED_barrier_wait_cancel (h);
139}
140
141
142/**
143 * Generic error handler, called with the appropriate error code and
144 * the same closure specified at the creation of the message queue.
145 * Not every message queue implementation supports an error handler.
146 *
147 * @param cls closure with the `struct GNUNET_TESTBED_BarrierWaitHandle *`
148 * @param error error code
149 */
150static void
151mq_error_handler (void *cls,
152 enum GNUNET_MQ_Error error)
153{
154 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls;
155
156 h->cb (h->cb_cls,
157 h->name,
158 GNUNET_SYSERR);
159 GNUNET_TESTBED_barrier_wait_cancel (h);
160}
161
162
163struct GNUNET_TESTBED_BarrierWaitHandle *
164GNUNET_TESTBED_barrier_wait (const char *name,
165 GNUNET_TESTBED_barrier_wait_cb cb,
166 void *cb_cls)
167{
168 struct GNUNET_TESTBED_BarrierWaitHandle *h
169 = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle);
170 struct GNUNET_MQ_MessageHandler handlers[] = {
171 GNUNET_MQ_hd_var_size (status,
172 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
173 struct GNUNET_TESTBED_BarrierStatusMsg,
174 h),
175 GNUNET_MQ_handler_end ()
176 };
177 struct GNUNET_MQ_Envelope *env;
178 struct GNUNET_TESTBED_BarrierWait *msg;
179 const char *cfg_filename;
180 size_t name_len;
181
182 GNUNET_assert (NULL != cb);
183 cfg_filename = getenv (ENV_TESTBED_CONFIG);
184 if (NULL == cfg_filename)
185 {
186 LOG (GNUNET_ERROR_TYPE_ERROR,
187 "Are you running under testbed?\n");
188 GNUNET_free (h);
189 return NULL;
190 }
191 h->cfg = GNUNET_CONFIGURATION_create ();
192 if (GNUNET_OK !=
193 GNUNET_CONFIGURATION_load (h->cfg,
194 cfg_filename))
195 {
196 LOG (GNUNET_ERROR_TYPE_ERROR,
197 "Unable to load configuration from file `%s'\n",
198 cfg_filename);
199 GNUNET_CONFIGURATION_destroy (h->cfg);
200 GNUNET_free (h);
201 return NULL;
202 }
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
204 "Waiting on barrier `%s'\n",
205 name);
206 h->name = GNUNET_strdup (name);
207 h->cb = cb;
208 h->cb_cls = cb_cls;
209 h->mq = GNUNET_CLIENT_connect (h->cfg,
210 "testbed-barrier",
211 handlers,
212 &mq_error_handler,
213 h);
214 if (NULL == h->mq)
215 {
216 LOG (GNUNET_ERROR_TYPE_ERROR,
217 "Unable to connect to local testbed-barrier service\n");
218 GNUNET_TESTBED_barrier_wait_cancel (h);
219 return NULL;
220 }
221 name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */
222 env = GNUNET_MQ_msg_extra (msg,
223 name_len,
224 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT);
225 GNUNET_memcpy (msg->name,
226 name,
227 name_len);
228 GNUNET_MQ_send (h->mq,
229 env);
230 return h;
231}
232
233
234/**
235 * Cancel a barrier wait handle
236 *
237 * @param h the barrier wait handle
238 */
239void
240GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h)
241{
242 if (NULL != h->mq)
243 {
244 GNUNET_MQ_destroy (h->mq);
245 h->mq = NULL;
246 }
247 GNUNET_free (h->name);
248 GNUNET_CONFIGURATION_destroy (h->cfg);
249 GNUNET_free (h);
250}
251
252
253/* end of testbed_api_barriers.c */