diff options
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 236 |
1 files changed, 119 insertions, 117 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index f811b6381..7e38b4297 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file testbed/testbed_api_barriers.c | 22 | * @file testbed/testbed_api_barriers.c |
@@ -31,20 +31,19 @@ | |||
31 | * Logging shorthand | 31 | * Logging shorthand |
32 | */ | 32 | */ |
33 | #define LOG(type, ...) \ | 33 | #define LOG(type, ...) \ |
34 | GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__); | 34 | GNUNET_log_from(type, "testbed-api-barriers", __VA_ARGS__); |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Debug logging shorthand | 37 | * Debug logging shorthand |
38 | */ | 38 | */ |
39 | #define LOG_DEBUG(...) \ | 39 | #define LOG_DEBUG(...) \ |
40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 40 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Barrier wait handle | 44 | * Barrier wait handle |
45 | */ | 45 | */ |
46 | struct GNUNET_TESTBED_BarrierWaitHandle | 46 | struct GNUNET_TESTBED_BarrierWaitHandle { |
47 | { | ||
48 | /** | 47 | /** |
49 | * The name of the barrier | 48 | * The name of the barrier |
50 | */ | 49 | */ |
@@ -81,8 +80,8 @@ struct GNUNET_TESTBED_BarrierWaitHandle | |||
81 | * @return #GNUNET_OK if the message is well-formed. | 80 | * @return #GNUNET_OK if the message is well-formed. |
82 | */ | 81 | */ |
83 | static int | 82 | static int |
84 | check_status (void *cls, | 83 | check_status(void *cls, |
85 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 84 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
86 | { | 85 | { |
87 | /* FIXME: this fails to actually check that the message | 86 | /* FIXME: this fails to actually check that the message |
88 | follows the protocol spec (0-terminations!). However, | 87 | follows the protocol spec (0-terminations!). However, |
@@ -100,40 +99,43 @@ check_status (void *cls, | |||
100 | * @param msg received message | 99 | * @param msg received message |
101 | */ | 100 | */ |
102 | static void | 101 | static void |
103 | handle_status (void *cls, | 102 | handle_status(void *cls, |
104 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 103 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
105 | { | 104 | { |
106 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 105 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
107 | 106 | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
109 | "Got barrier status %d\n", | 108 | "Got barrier status %d\n", |
110 | (int) ntohs (msg->status)); | 109 | (int)ntohs(msg->status)); |
111 | switch (ntohs (msg->status)) | 110 | switch (ntohs(msg->status)) |
112 | { | 111 | { |
113 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 112 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
114 | h->cb (h->cb_cls, | 113 | h->cb(h->cb_cls, |
115 | h->name, | 114 | h->name, |
116 | GNUNET_SYSERR); | 115 | GNUNET_SYSERR); |
117 | break; | 116 | break; |
118 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 117 | |
119 | h->cb (h->cb_cls, | 118 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
120 | h->name, | 119 | h->cb(h->cb_cls, |
121 | GNUNET_SYSERR); | 120 | h->name, |
122 | GNUNET_break (0); | 121 | GNUNET_SYSERR); |
123 | break; | 122 | GNUNET_break(0); |
124 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 123 | break; |
125 | h->cb (h->cb_cls, | 124 | |
126 | h->name, | 125 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
127 | GNUNET_OK); | 126 | h->cb(h->cb_cls, |
128 | break; | 127 | h->name, |
129 | default: | 128 | GNUNET_OK); |
130 | GNUNET_break_op (0); | 129 | break; |
131 | h->cb (h->cb_cls, | 130 | |
132 | h->name, | 131 | default: |
133 | GNUNET_SYSERR); | 132 | GNUNET_break_op(0); |
134 | break; | 133 | h->cb(h->cb_cls, |
135 | } | 134 | h->name, |
136 | GNUNET_TESTBED_barrier_wait_cancel (h); | 135 | GNUNET_SYSERR); |
136 | break; | ||
137 | } | ||
138 | GNUNET_TESTBED_barrier_wait_cancel(h); | ||
137 | } | 139 | } |
138 | 140 | ||
139 | 141 | ||
@@ -146,15 +148,15 @@ handle_status (void *cls, | |||
146 | * @param error error code | 148 | * @param error error code |
147 | */ | 149 | */ |
148 | static void | 150 | static void |
149 | mq_error_handler (void *cls, | 151 | mq_error_handler(void *cls, |
150 | enum GNUNET_MQ_Error error) | 152 | enum GNUNET_MQ_Error error) |
151 | { | 153 | { |
152 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 154 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
153 | 155 | ||
154 | h->cb (h->cb_cls, | 156 | h->cb(h->cb_cls, |
155 | h->name, | 157 | h->name, |
156 | GNUNET_SYSERR); | 158 | GNUNET_SYSERR); |
157 | GNUNET_TESTBED_barrier_wait_cancel (h); | 159 | GNUNET_TESTBED_barrier_wait_cancel(h); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
@@ -170,72 +172,72 @@ mq_error_handler (void *cls, | |||
170 | * anytime before the callback is called. NULL upon error. | 172 | * anytime before the callback is called. NULL upon error. |
171 | */ | 173 | */ |
172 | struct GNUNET_TESTBED_BarrierWaitHandle * | 174 | struct GNUNET_TESTBED_BarrierWaitHandle * |
173 | GNUNET_TESTBED_barrier_wait (const char *name, | 175 | GNUNET_TESTBED_barrier_wait(const char *name, |
174 | GNUNET_TESTBED_barrier_wait_cb cb, | 176 | GNUNET_TESTBED_barrier_wait_cb cb, |
175 | void *cb_cls) | 177 | void *cb_cls) |
176 | { | 178 | { |
177 | struct GNUNET_TESTBED_BarrierWaitHandle *h | 179 | struct GNUNET_TESTBED_BarrierWaitHandle *h |
178 | = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); | 180 | = GNUNET_new(struct GNUNET_TESTBED_BarrierWaitHandle); |
179 | struct GNUNET_MQ_MessageHandler handlers[] = { | 181 | struct GNUNET_MQ_MessageHandler handlers[] = { |
180 | GNUNET_MQ_hd_var_size (status, | 182 | GNUNET_MQ_hd_var_size(status, |
181 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 183 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, |
182 | struct GNUNET_TESTBED_BarrierStatusMsg, | 184 | struct GNUNET_TESTBED_BarrierStatusMsg, |
183 | h), | 185 | h), |
184 | GNUNET_MQ_handler_end () | 186 | GNUNET_MQ_handler_end() |
185 | }; | 187 | }; |
186 | struct GNUNET_MQ_Envelope *env; | 188 | struct GNUNET_MQ_Envelope *env; |
187 | struct GNUNET_TESTBED_BarrierWait *msg; | 189 | struct GNUNET_TESTBED_BarrierWait *msg; |
188 | const char *cfg_filename; | 190 | const char *cfg_filename; |
189 | size_t name_len; | 191 | size_t name_len; |
190 | 192 | ||
191 | GNUNET_assert (NULL != cb); | 193 | GNUNET_assert(NULL != cb); |
192 | cfg_filename = getenv (ENV_TESTBED_CONFIG); | 194 | cfg_filename = getenv(ENV_TESTBED_CONFIG); |
193 | if (NULL == cfg_filename) | 195 | if (NULL == cfg_filename) |
194 | { | 196 | { |
195 | LOG (GNUNET_ERROR_TYPE_ERROR, | 197 | LOG(GNUNET_ERROR_TYPE_ERROR, |
196 | "Are you running under testbed?\n"); | 198 | "Are you running under testbed?\n"); |
197 | GNUNET_free (h); | 199 | GNUNET_free(h); |
198 | return NULL; | 200 | return NULL; |
199 | } | 201 | } |
200 | h->cfg = GNUNET_CONFIGURATION_create (); | 202 | h->cfg = GNUNET_CONFIGURATION_create(); |
201 | if (GNUNET_OK != | 203 | if (GNUNET_OK != |
202 | GNUNET_CONFIGURATION_load (h->cfg, | 204 | GNUNET_CONFIGURATION_load(h->cfg, |
203 | cfg_filename)) | 205 | cfg_filename)) |
204 | { | 206 | { |
205 | LOG (GNUNET_ERROR_TYPE_ERROR, | 207 | LOG(GNUNET_ERROR_TYPE_ERROR, |
206 | "Unable to load configuration from file `%s'\n", | 208 | "Unable to load configuration from file `%s'\n", |
207 | cfg_filename); | 209 | cfg_filename); |
208 | GNUNET_CONFIGURATION_destroy (h->cfg); | 210 | GNUNET_CONFIGURATION_destroy(h->cfg); |
209 | GNUNET_free (h); | 211 | GNUNET_free(h); |
210 | return NULL; | 212 | return NULL; |
211 | } | 213 | } |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
213 | "Waiting on barrier `%s'\n", | 215 | "Waiting on barrier `%s'\n", |
214 | name); | 216 | name); |
215 | h->name = GNUNET_strdup (name); | 217 | h->name = GNUNET_strdup(name); |
216 | h->cb = cb; | 218 | h->cb = cb; |
217 | h->cb_cls = cb_cls; | 219 | h->cb_cls = cb_cls; |
218 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 220 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
219 | "testbed-barrier", | 221 | "testbed-barrier", |
220 | handlers, | 222 | handlers, |
221 | &mq_error_handler, | 223 | &mq_error_handler, |
222 | h); | 224 | h); |
223 | if (NULL == h->mq) | 225 | if (NULL == h->mq) |
224 | { | 226 | { |
225 | LOG (GNUNET_ERROR_TYPE_ERROR, | 227 | LOG(GNUNET_ERROR_TYPE_ERROR, |
226 | "Unable to connect to local testbed-barrier service\n"); | 228 | "Unable to connect to local testbed-barrier service\n"); |
227 | GNUNET_TESTBED_barrier_wait_cancel (h); | 229 | GNUNET_TESTBED_barrier_wait_cancel(h); |
228 | return NULL; | 230 | return NULL; |
229 | } | 231 | } |
230 | name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */ | 232 | name_len = strlen(name); /* NOTE: unusual to not have 0-termination, change? */ |
231 | env = GNUNET_MQ_msg_extra (msg, | 233 | env = GNUNET_MQ_msg_extra(msg, |
232 | name_len, | 234 | name_len, |
233 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); | 235 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); |
234 | GNUNET_memcpy (msg->name, | 236 | GNUNET_memcpy(msg->name, |
235 | name, | 237 | name, |
236 | name_len); | 238 | name_len); |
237 | GNUNET_MQ_send (h->mq, | 239 | GNUNET_MQ_send(h->mq, |
238 | env); | 240 | env); |
239 | return h; | 241 | return h; |
240 | } | 242 | } |
241 | 243 | ||
@@ -246,16 +248,16 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
246 | * @param h the barrier wait handle | 248 | * @param h the barrier wait handle |
247 | */ | 249 | */ |
248 | void | 250 | void |
249 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) | 251 | GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h) |
250 | { | 252 | { |
251 | if (NULL != h->mq) | 253 | if (NULL != h->mq) |
252 | { | 254 | { |
253 | GNUNET_MQ_destroy (h->mq); | 255 | GNUNET_MQ_destroy(h->mq); |
254 | h->mq = NULL; | 256 | h->mq = NULL; |
255 | } | 257 | } |
256 | GNUNET_free (h->name); | 258 | GNUNET_free(h->name); |
257 | GNUNET_CONFIGURATION_destroy (h->cfg); | 259 | GNUNET_CONFIGURATION_destroy(h->cfg); |
258 | GNUNET_free (h); | 260 | GNUNET_free(h); |
259 | } | 261 | } |
260 | 262 | ||
261 | /* end of testbed_api_barriers.c */ | 263 | /* end of testbed_api_barriers.c */ |