diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-10 12:18:07 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-09-10 12:18:07 +0000 |
commit | 9363d5db9dd612c1ec8be0f202da23aeaf09be49 (patch) | |
tree | c10ade1161826fdadd24f1e1a2e350596f4a0a19 /src/testbed/testbed_api_barriers.c | |
parent | abe521f93a227ef120cd75c7d649782951e8eca5 (diff) | |
download | gnunet-9363d5db9dd612c1ec8be0f202da23aeaf09be49.tar.gz gnunet-9363d5db9dd612c1ec8be0f202da23aeaf09be49.zip |
- experiment driver propagates barrier crossed notification
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index 96fd3be66..3e4640309 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_testbed_service.h" | 28 | #include "gnunet_testbed_service.h" |
29 | #include "testbed_api.h" | 29 | #include "testbed_api.h" |
30 | #include "testbed_api_barriers.h" | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Logging shorthand | 33 | * Logging shorthand |
@@ -70,6 +71,10 @@ struct GNUNET_TESTBED_Barrier | |||
70 | */ | 71 | */ |
71 | void *cls; | 72 | void *cls; |
72 | 73 | ||
74 | /** | ||
75 | * Should the barrier crossed status message be echoed back to the controller? | ||
76 | */ | ||
77 | int echo; | ||
73 | }; | 78 | }; |
74 | 79 | ||
75 | 80 | ||
@@ -172,6 +177,8 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
172 | goto cleanup; | 177 | goto cleanup; |
173 | } | 178 | } |
174 | GNUNET_assert (NULL != barrier->cb); | 179 | GNUNET_assert (NULL != barrier->cb); |
180 | if ((GNUNET_YES == barrier->echo) && (BARRIER_STATUS_CROSSED == status)) | ||
181 | GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header)); | ||
175 | barrier->cb (barrier->cls, name, barrier, status, emsg); | 182 | barrier->cb (barrier->cls, name, barrier, status, emsg); |
176 | if (BARRIER_STATUS_INITIALISED == status) | 183 | if (BARRIER_STATUS_INITIALISED == status) |
177 | return GNUNET_OK; /* just initialised; skip cleanup */ | 184 | return GNUNET_OK; /* just initialised; skip cleanup */ |
@@ -196,13 +203,16 @@ GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
196 | * @param cb the callback to call when the barrier is reached or upon error. | 203 | * @param cb the callback to call when the barrier is reached or upon error. |
197 | * Cannot be NULL. | 204 | * Cannot be NULL. |
198 | * @param cls closure for the above callback | 205 | * @param cls closure for the above callback |
206 | * @param echo GNUNET_YES to echo the barrier crossed status message back to the | ||
207 | * controller | ||
199 | * @return barrier handle; NULL upon error | 208 | * @return barrier handle; NULL upon error |
200 | */ | 209 | */ |
201 | struct GNUNET_TESTBED_Barrier * | 210 | struct GNUNET_TESTBED_Barrier * |
202 | GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | 211 | GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, |
203 | const char *name, | 212 | const char *name, |
204 | unsigned int quorum, | 213 | unsigned int quorum, |
205 | GNUNET_TESTBED_barrier_status_cb cb, void *cls) | 214 | GNUNET_TESTBED_barrier_status_cb cb, void *cls, |
215 | int echo) | ||
206 | { | 216 | { |
207 | struct GNUNET_TESTBED_BarrierInit *msg; | 217 | struct GNUNET_TESTBED_BarrierInit *msg; |
208 | struct GNUNET_TESTBED_Barrier *barrier; | 218 | struct GNUNET_TESTBED_Barrier *barrier; |
@@ -229,6 +239,7 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | |||
229 | barrier->name = GNUNET_strdup (name); | 239 | barrier->name = GNUNET_strdup (name); |
230 | barrier->cb = cb; | 240 | barrier->cb = cb; |
231 | barrier->cls = cls; | 241 | barrier->cls = cls; |
242 | barrier->echo = echo; | ||
232 | (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode)); | 243 | (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode)); |
233 | GNUNET_assert (GNUNET_OK == | 244 | GNUNET_assert (GNUNET_OK == |
234 | GNUNET_CONTAINER_multihashmap_put (barrier_map, &barrier->key, | 245 | GNUNET_CONTAINER_multihashmap_put (barrier_map, &barrier->key, |
@@ -246,6 +257,30 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | |||
246 | 257 | ||
247 | 258 | ||
248 | /** | 259 | /** |
260 | * Initialise a barrier and call the given callback when the required percentage | ||
261 | * of peers (quorum) reach the barrier OR upon error. | ||
262 | * | ||
263 | * @param controller the handle to the controller | ||
264 | * @param name identification name of the barrier | ||
265 | * @param quorum the percentage of peers that is required to reach the barrier. | ||
266 | * Peers signal reaching a barrier by calling | ||
267 | * GNUNET_TESTBED_barrier_reached(). | ||
268 | * @param cb the callback to call when the barrier is reached or upon error. | ||
269 | * Cannot be NULL. | ||
270 | * @param cls closure for the above callback | ||
271 | * @return barrier handle; NULL upon error | ||
272 | */ | ||
273 | struct GNUNET_TESTBED_Barrier * | ||
274 | GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | ||
275 | const char *name, | ||
276 | unsigned int quorum, | ||
277 | GNUNET_TESTBED_barrier_status_cb cb, void *cls) | ||
278 | { | ||
279 | return GNUNET_TESTBED_barrier_init_ (controller, name, quorum, cb, cls, GNUNET_YES); | ||
280 | } | ||
281 | |||
282 | |||
283 | /** | ||
249 | * Cancel a barrier. | 284 | * Cancel a barrier. |
250 | * | 285 | * |
251 | * @param barrier the barrier handle | 286 | * @param barrier the barrier handle |