diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 10:36:28 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 10:36:28 +0000 |
commit | a94a1861d123fe850d2ab5ae74cbb59b132a15ea (patch) | |
tree | a16d2518067d13f2463e83cd9dc66bdd6b733621 /src/testbed/testbed_api_testbed.c | |
parent | d0c55c3ee57913977b1497ea0e6f20573820b206 (diff) | |
download | gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.tar.gz gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.zip |
adhering to indentation standard
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 146 |
1 files changed, 72 insertions, 74 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index 914523780..fb9ed31b6 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -61,13 +61,13 @@ struct DLLOperation | |||
61 | /** | 61 | /** |
62 | * Closure | 62 | * Closure |
63 | */ | 63 | */ |
64 | void *cls; | 64 | void *cls; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * The next pointer for DLL | 67 | * The next pointer for DLL |
68 | */ | 68 | */ |
69 | struct DLLOperation *next; | 69 | struct DLLOperation *next; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * The prev pointer for DLL | 72 | * The prev pointer for DLL |
73 | */ | 73 | */ |
@@ -78,13 +78,13 @@ struct DLLOperation | |||
78 | /** | 78 | /** |
79 | * States of RunContext | 79 | * States of RunContext |
80 | */ | 80 | */ |
81 | enum State | 81 | enum State |
82 | { | 82 | { |
83 | /** | 83 | /** |
84 | * Initial state | 84 | * Initial state |
85 | */ | 85 | */ |
86 | RC_INIT = 0, | 86 | RC_INIT = 0, |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Peers have been started | 89 | * Peers have been started |
90 | */ | 90 | */ |
@@ -94,12 +94,11 @@ enum State | |||
94 | * Peers are stopped | 94 | * Peers are stopped |
95 | */ | 95 | */ |
96 | RC_PEERS_STOPPED, | 96 | RC_PEERS_STOPPED, |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Peers are destroyed | 99 | * Peers are destroyed |
100 | */ | 100 | */ |
101 | RC_PEERS_DESTROYED | 101 | RC_PEERS_DESTROYED |
102 | |||
103 | }; | 102 | }; |
104 | 103 | ||
105 | 104 | ||
@@ -127,17 +126,17 @@ struct RunContext | |||
127 | * The callback to use as controller callback | 126 | * The callback to use as controller callback |
128 | */ | 127 | */ |
129 | GNUNET_TESTBED_ControllerCallback cc; | 128 | GNUNET_TESTBED_ControllerCallback cc; |
130 | 129 | ||
131 | /** | 130 | /** |
132 | * The pointer to the controller callback | 131 | * The pointer to the controller callback |
133 | */ | 132 | */ |
134 | void *cc_cls; | 133 | void *cc_cls; |
135 | 134 | ||
136 | /** | 135 | /** |
137 | * Master task to call when testbed initialization is done | 136 | * Master task to call when testbed initialization is done |
138 | */ | 137 | */ |
139 | GNUNET_SCHEDULER_Task master; | 138 | GNUNET_SCHEDULER_Task master; |
140 | 139 | ||
141 | /** | 140 | /** |
142 | * The closure for the master task | 141 | * The closure for the master task |
143 | */ | 142 | */ |
@@ -147,7 +146,7 @@ struct RunContext | |||
147 | * The head element of DLL operations | 146 | * The head element of DLL operations |
148 | */ | 147 | */ |
149 | struct DLLOperation *dll_op_head; | 148 | struct DLLOperation *dll_op_head; |
150 | 149 | ||
151 | /** | 150 | /** |
152 | * The tail element of DLL operations | 151 | * The tail element of DLL operations |
153 | */ | 152 | */ |
@@ -157,7 +156,7 @@ struct RunContext | |||
157 | * Array of peers which we create | 156 | * Array of peers which we create |
158 | */ | 157 | */ |
159 | struct GNUNET_TESTBED_Peer **peers; | 158 | struct GNUNET_TESTBED_Peer **peers; |
160 | 159 | ||
161 | /** | 160 | /** |
162 | * The event mask for the controller | 161 | * The event mask for the controller |
163 | */ | 162 | */ |
@@ -173,7 +172,7 @@ struct RunContext | |||
173 | * successful operation on a peer | 172 | * successful operation on a peer |
174 | */ | 173 | */ |
175 | unsigned int peer_count; | 174 | unsigned int peer_count; |
176 | 175 | ||
177 | /** | 176 | /** |
178 | * number of peers to start | 177 | * number of peers to start |
179 | */ | 178 | */ |
@@ -203,12 +202,12 @@ struct RunContext | |||
203 | */ | 202 | */ |
204 | struct GNUNET_TESTBED_Testbed * | 203 | struct GNUNET_TESTBED_Testbed * |
205 | GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, | 204 | GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, |
206 | unsigned int num_hosts, | 205 | unsigned int num_hosts, |
207 | struct GNUNET_TESTBED_Host **hosts, | 206 | struct GNUNET_TESTBED_Host **hosts, |
208 | unsigned int num_peers, | 207 | unsigned int num_peers, |
209 | const struct GNUNET_CONFIGURATION_Handle *peer_cfg, | 208 | const struct GNUNET_CONFIGURATION_Handle *peer_cfg, |
210 | enum GNUNET_TESTBED_TopologyOption underlay_topology, | 209 | enum GNUNET_TESTBED_TopologyOption underlay_topology, |
211 | va_list va) | 210 | va_list va) |
212 | { | 211 | { |
213 | GNUNET_break (0); | 212 | GNUNET_break (0); |
214 | return NULL; | 213 | return NULL; |
@@ -233,12 +232,12 @@ GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, | |||
233 | */ | 232 | */ |
234 | struct GNUNET_TESTBED_Testbed * | 233 | struct GNUNET_TESTBED_Testbed * |
235 | GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller, | 234 | GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller, |
236 | unsigned int num_hosts, | 235 | unsigned int num_hosts, |
237 | struct GNUNET_TESTBED_Host **hosts, | 236 | struct GNUNET_TESTBED_Host **hosts, |
238 | unsigned int num_peers, | 237 | unsigned int num_peers, |
239 | const struct GNUNET_CONFIGURATION_Handle *peer_cfg, | 238 | const struct GNUNET_CONFIGURATION_Handle *peer_cfg, |
240 | enum GNUNET_TESTBED_TopologyOption underlay_topology, | 239 | enum GNUNET_TESTBED_TopologyOption underlay_topology, |
241 | ...) | 240 | ...) |
242 | { | 241 | { |
243 | GNUNET_break (0); | 242 | GNUNET_break (0); |
244 | return NULL; | 243 | return NULL; |
@@ -268,18 +267,18 @@ static void | |||
268 | start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 267 | start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
269 | { | 268 | { |
270 | struct RunContext *rc = cls; | 269 | struct RunContext *rc = cls; |
271 | struct DLLOperation *dll_op; | 270 | struct DLLOperation *dll_op; |
272 | unsigned int peer; | 271 | unsigned int peer; |
273 | 272 | ||
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting Peers\n"); | 273 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting Peers\n"); |
275 | for (peer = 0; peer < rc->num_peers; peer++) | 274 | for (peer = 0; peer < rc->num_peers; peer++) |
276 | { | 275 | { |
277 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | 276 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); |
278 | dll_op->op = GNUNET_TESTBED_peer_start (rc->peers[peer]); | 277 | dll_op->op = GNUNET_TESTBED_peer_start (rc->peers[peer]); |
279 | dll_op->cls = rc->peers[peer]; | 278 | dll_op->cls = rc->peers[peer]; |
280 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); | 279 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); |
281 | } | 280 | } |
282 | rc->peer_count = 0; | 281 | rc->peer_count = 0; |
283 | } | 282 | } |
284 | 283 | ||
285 | 284 | ||
@@ -292,17 +291,17 @@ start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
292 | * creation | 291 | * creation |
293 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 292 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
294 | */ | 293 | */ |
295 | static void | 294 | static void |
296 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 295 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
297 | { | 296 | { |
298 | struct DLLOperation *dll_op = cls; | 297 | struct DLLOperation *dll_op = cls; |
299 | struct RunContext *rc; | 298 | struct RunContext *rc; |
300 | 299 | ||
301 | GNUNET_assert (NULL != dll_op); | 300 | GNUNET_assert (NULL != dll_op); |
302 | rc = dll_op->rc; | 301 | rc = dll_op->rc; |
303 | GNUNET_assert (NULL != rc); | 302 | GNUNET_assert (NULL != rc); |
304 | GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); | 303 | GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); |
305 | GNUNET_TESTBED_operation_done (dll_op->op); | 304 | GNUNET_TESTBED_operation_done (dll_op->op); |
306 | GNUNET_free (dll_op); | 305 | GNUNET_free (dll_op); |
307 | if (NULL == peer) | 306 | if (NULL == peer) |
308 | { | 307 | { |
@@ -316,7 +315,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
316 | rc->peer_count++; | 315 | rc->peer_count++; |
317 | if (rc->peer_count < rc->num_peers) | 316 | if (rc->peer_count < rc->num_peers) |
318 | return; | 317 | return; |
319 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Required peers created successfully\n"); | 318 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Required peers created successfully\n"); |
320 | GNUNET_SCHEDULER_add_now (&start_peers_task, rc); | 319 | GNUNET_SCHEDULER_add_now (&start_peers_task, rc); |
321 | } | 320 | } |
322 | 321 | ||
@@ -331,8 +330,8 @@ static void | |||
331 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 330 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
332 | { | 331 | { |
333 | struct RunContext *rc = cls; | 332 | struct RunContext *rc = cls; |
334 | struct DLLOperation *dll_op; | 333 | struct DLLOperation *dll_op; |
335 | 334 | ||
336 | GNUNET_assert (NULL == rc->peers); | 335 | GNUNET_assert (NULL == rc->peers); |
337 | GNUNET_assert (RC_PEERS_DESTROYED == rc->state); | 336 | GNUNET_assert (RC_PEERS_DESTROYED == rc->state); |
338 | if (NULL != rc->c) | 337 | if (NULL != rc->c) |
@@ -363,21 +362,21 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
363 | * @param cls closure | 362 | * @param cls closure |
364 | * @param event information about the event | 363 | * @param event information about the event |
365 | */ | 364 | */ |
366 | static void | 365 | static void |
367 | event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 366 | event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
368 | { | 367 | { |
369 | struct RunContext *rc = cls; | 368 | struct RunContext *rc = cls; |
370 | struct DLLOperation *dll_op; | 369 | struct DLLOperation *dll_op; |
371 | unsigned int peer_id; | 370 | unsigned int peer_id; |
372 | |||
373 | 371 | ||
374 | if ((RC_INIT != rc->state) && | 372 | |
375 | ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type)|| | 373 | if ((RC_INIT != rc->state) && |
374 | ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) || | ||
376 | (GNUNET_TESTBED_ET_PEER_STOP == event->type))) | 375 | (GNUNET_TESTBED_ET_PEER_STOP == event->type))) |
377 | { | 376 | { |
378 | for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) | 377 | for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) |
379 | { | 378 | { |
380 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && | 379 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && |
381 | (event->details.operation_finished.operation == dll_op->op)) | 380 | (event->details.operation_finished.operation == dll_op->op)) |
382 | break; | 381 | break; |
383 | if ((GNUNET_TESTBED_ET_PEER_STOP == event->type) && | 382 | if ((GNUNET_TESTBED_ET_PEER_STOP == event->type) && |
@@ -418,12 +417,12 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
418 | return; | 417 | return; |
419 | } | 418 | } |
420 | 419 | ||
421 | call_cc: | 420 | call_cc: |
422 | rc->cc (rc->cc_cls, event); | 421 | rc->cc (rc->cc_cls, event); |
423 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | 422 | if (GNUNET_TESTBED_ET_PEER_START != event->type) |
424 | return; | 423 | return; |
425 | for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) | 424 | for (dll_op = rc->dll_op_head; NULL != dll_op; dll_op = dll_op->next) |
426 | if ((NULL != dll_op->cls) && | 425 | if ((NULL != dll_op->cls) && |
427 | (event->details.peer_start.peer == dll_op->cls)) | 426 | (event->details.peer_start.peer == dll_op->cls)) |
428 | break; | 427 | break; |
429 | GNUNET_assert (NULL != dll_op); | 428 | GNUNET_assert (NULL != dll_op); |
@@ -436,7 +435,7 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
436 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers started successfully\n"); | 435 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers started successfully\n"); |
437 | rc->state = RC_PEERS_STARTED; | 436 | rc->state = RC_PEERS_STARTED; |
438 | GNUNET_SCHEDULER_add_continuation (rc->master, rc->master_cls, | 437 | GNUNET_SCHEDULER_add_continuation (rc->master, rc->master_cls, |
439 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 438 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
440 | } | 439 | } |
441 | 440 | ||
442 | 441 | ||
@@ -450,32 +449,33 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
450 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | 449 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, |
451 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 450 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
452 | */ | 451 | */ |
453 | static void | 452 | static void |
454 | controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 453 | controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
455 | int status) | 454 | int status) |
456 | { | 455 | { |
457 | struct RunContext *rc = cls; | 456 | struct RunContext *rc = cls; |
458 | struct DLLOperation *dll_op; | 457 | struct DLLOperation *dll_op; |
459 | unsigned int peer; | 458 | unsigned int peer; |
460 | 459 | ||
461 | if (status != GNUNET_OK) | 460 | if (status != GNUNET_OK) |
462 | { | 461 | { |
463 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); | 462 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); |
464 | return; | 463 | return; |
465 | } | 464 | } |
466 | rc->c = GNUNET_TESTBED_controller_connect (cfg, rc->h, rc->event_mask, | 465 | rc->c = |
467 | &event_cb, rc); | 466 | GNUNET_TESTBED_controller_connect (cfg, rc->h, rc->event_mask, &event_cb, |
468 | rc->peers = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) | 467 | rc); |
469 | * rc->num_peers); | 468 | rc->peers = |
469 | GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * rc->num_peers); | ||
470 | GNUNET_assert (NULL != rc->c); | 470 | GNUNET_assert (NULL != rc->c); |
471 | rc->peer_count = 0; | 471 | rc->peer_count = 0; |
472 | for (peer = 0; peer < rc->num_peers; peer++) | 472 | for (peer = 0; peer < rc->num_peers; peer++) |
473 | { | 473 | { |
474 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | 474 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); |
475 | dll_op->rc = rc; | 475 | dll_op->rc = rc; |
476 | dll_op->op = GNUNET_TESTBED_peer_create (rc->c, rc->h, cfg, peer_create_cb, | 476 | dll_op->op = |
477 | dll_op); | 477 | GNUNET_TESTBED_peer_create (rc->c, rc->h, cfg, peer_create_cb, dll_op); |
478 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); | 478 | GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
@@ -488,11 +488,11 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
488 | */ | 488 | */ |
489 | void | 489 | void |
490 | shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 490 | shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
491 | { | 491 | { |
492 | struct RunContext *rc = cls; | 492 | struct RunContext *rc = cls; |
493 | struct DLLOperation *dll_op; | 493 | struct DLLOperation *dll_op; |
494 | unsigned int peer; | 494 | unsigned int peer; |
495 | 495 | ||
496 | if (NULL != rc->c) | 496 | if (NULL != rc->c) |
497 | { | 497 | { |
498 | if (NULL != rc->peers) | 498 | if (NULL != rc->peers) |
@@ -509,8 +509,8 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
509 | return; | 509 | return; |
510 | } | 510 | } |
511 | } | 511 | } |
512 | rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the | 512 | rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the |
513 | state where all peers are destroyed */ | 513 | * state where all peers are destroyed */ |
514 | GNUNET_SCHEDULER_add_now (&cleanup_task, rc); | 514 | GNUNET_SCHEDULER_add_now (&cleanup_task, rc); |
515 | } | 515 | } |
516 | 516 | ||
@@ -540,25 +540,23 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
540 | */ | 540 | */ |
541 | void | 541 | void |
542 | GNUNET_TESTBED_run (const char *host_filename, | 542 | GNUNET_TESTBED_run (const char *host_filename, |
543 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 543 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
544 | unsigned int num_peers, | 544 | unsigned int num_peers, uint64_t event_mask, |
545 | uint64_t event_mask, | 545 | GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, |
546 | GNUNET_TESTBED_ControllerCallback cc, | 546 | GNUNET_SCHEDULER_Task master, void *master_cls) |
547 | void *cc_cls, | ||
548 | GNUNET_SCHEDULER_Task master, | ||
549 | void *master_cls) | ||
550 | { | 547 | { |
551 | struct RunContext *rc; | 548 | struct RunContext *rc; |
552 | 549 | ||
553 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 550 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
554 | rc = GNUNET_malloc (sizeof (struct RunContext)); | 551 | rc = GNUNET_malloc (sizeof (struct RunContext)); |
555 | GNUNET_break (NULL == host_filename); /* Currently we do not support host | 552 | GNUNET_break (NULL == host_filename); /* Currently we do not support host |
556 | files */ | 553 | * files */ |
557 | host_filename = NULL; | 554 | host_filename = NULL; |
558 | rc->h = GNUNET_TESTBED_host_create (NULL, NULL, 0); | 555 | rc->h = GNUNET_TESTBED_host_create (NULL, NULL, 0); |
559 | GNUNET_assert (NULL != rc->h); | 556 | GNUNET_assert (NULL != rc->h); |
560 | rc->cproc = GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, cfg, | 557 | rc->cproc = |
561 | &controller_status_cb, rc); | 558 | GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, cfg, |
559 | &controller_status_cb, rc); | ||
562 | GNUNET_assert (NULL != rc->cproc); | 560 | GNUNET_assert (NULL != rc->cproc); |
563 | rc->num_peers = num_peers; | 561 | rc->num_peers = num_peers; |
564 | rc->event_mask = event_mask; | 562 | rc->event_mask = event_mask; |