diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed_links.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.c | 1147 |
1 files changed, 573 insertions, 574 deletions
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index 62f65387e..d7715a16e 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.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 GNUnet e.V. | 3 | Copyright (C) 2008--2013 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/gnunet-service-testbed_links.c | 22 | * @file testbed/gnunet-service-testbed_links.c |
@@ -33,8 +33,8 @@ | |||
33 | #ifdef LOG | 33 | #ifdef LOG |
34 | #undef LOG | 34 | #undef LOG |
35 | #endif | 35 | #endif |
36 | #define LOG(kind,...) \ | 36 | #define LOG(kind, ...) \ |
37 | GNUNET_log_from (kind, "testbed-links", __VA_ARGS__) | 37 | GNUNET_log_from(kind, "testbed-links", __VA_ARGS__) |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * The event mask for the events we listen from sub-controllers | 40 | * The event mask for the events we listen from sub-controllers |
@@ -45,8 +45,7 @@ | |||
45 | /** | 45 | /** |
46 | * States of LCFContext | 46 | * States of LCFContext |
47 | */ | 47 | */ |
48 | enum LCFContextState | 48 | enum LCFContextState { |
49 | { | ||
50 | /** | 49 | /** |
51 | * The Context has been initialized; Nothing has been done on it | 50 | * The Context has been initialized; Nothing has been done on it |
52 | */ | 51 | */ |
@@ -72,8 +71,7 @@ enum LCFContextState | |||
72 | /** | 71 | /** |
73 | * Link controllers request forwarding context | 72 | * Link controllers request forwarding context |
74 | */ | 73 | */ |
75 | struct LCFContext | 74 | struct LCFContext { |
76 | { | ||
77 | /** | 75 | /** |
78 | * The LCFContext | 76 | * The LCFContext |
79 | */ | 77 | */ |
@@ -128,7 +126,6 @@ struct LCFContext | |||
128 | * The slave host | 126 | * The slave host |
129 | */ | 127 | */ |
130 | uint32_t slave_host_id; | 128 | uint32_t slave_host_id; |
131 | |||
132 | }; | 129 | }; |
133 | 130 | ||
134 | 131 | ||
@@ -136,8 +133,7 @@ struct LCFContext | |||
136 | * Notification context to be used to notify when connection to the neighbour's | 133 | * Notification context to be used to notify when connection to the neighbour's |
137 | * controller is opened | 134 | * controller is opened |
138 | */ | 135 | */ |
139 | struct NeighbourConnectNotification | 136 | struct NeighbourConnectNotification { |
140 | { | ||
141 | /** | 137 | /** |
142 | * DLL next for inclusion in neighbour's list of notification requests | 138 | * DLL next for inclusion in neighbour's list of notification requests |
143 | */ | 139 | */ |
@@ -168,8 +164,7 @@ struct NeighbourConnectNotification | |||
168 | /** | 164 | /** |
169 | * A connected controller which is not our child | 165 | * A connected controller which is not our child |
170 | */ | 166 | */ |
171 | struct Neighbour | 167 | struct Neighbour { |
172 | { | ||
173 | /** | 168 | /** |
174 | * The controller handle | 169 | * The controller handle |
175 | */ | 170 | */ |
@@ -228,8 +223,7 @@ static unsigned int neighbour_list_size; | |||
228 | * Context information for establishing a link to neighbour (Used is | 223 | * Context information for establishing a link to neighbour (Used is |
229 | * GST_handle_link_controllers() | 224 | * GST_handle_link_controllers() |
230 | */ | 225 | */ |
231 | struct NeighbourConnectCtxt | 226 | struct NeighbourConnectCtxt { |
232 | { | ||
233 | /** | 227 | /** |
234 | * DLL next for inclusion in the corresponding context list | 228 | * DLL next for inclusion in the corresponding context list |
235 | */ | 229 | */ |
@@ -319,13 +313,13 @@ static unsigned int route_list_size; | |||
319 | * @param slave the slave controller to add | 313 | * @param slave the slave controller to add |
320 | */ | 314 | */ |
321 | static void | 315 | static void |
322 | slave_list_add (struct Slave *slave) | 316 | slave_list_add(struct Slave *slave) |
323 | { | 317 | { |
324 | if (slave->host_id >= GST_slave_list_size) | 318 | if (slave->host_id >= GST_slave_list_size) |
325 | GST_array_grow_large_enough (GST_slave_list, | 319 | GST_array_grow_large_enough(GST_slave_list, |
326 | GST_slave_list_size, | 320 | GST_slave_list_size, |
327 | slave->host_id); | 321 | slave->host_id); |
328 | GNUNET_assert (NULL == GST_slave_list[slave->host_id]); | 322 | GNUNET_assert(NULL == GST_slave_list[slave->host_id]); |
329 | GST_slave_list[slave->host_id] = slave; | 323 | GST_slave_list[slave->host_id] = slave; |
330 | } | 324 | } |
331 | 325 | ||
@@ -340,9 +334,9 @@ slave_list_add (struct Slave *slave) | |||
340 | * @return #GNUNET_OK (continue iterating) | 334 | * @return #GNUNET_OK (continue iterating) |
341 | */ | 335 | */ |
342 | static int | 336 | static int |
343 | drop_client_entries (void *cls, | 337 | drop_client_entries(void *cls, |
344 | const struct GNUNET_HashCode *key, | 338 | const struct GNUNET_HashCode *key, |
345 | void *value) | 339 | void *value) |
346 | { | 340 | { |
347 | struct GNUNET_SERVICE_Client *client = cls; | 341 | struct GNUNET_SERVICE_Client *client = cls; |
348 | struct RegisteredHostContext *rhc = value; | 342 | struct RegisteredHostContext *rhc = value; |
@@ -350,11 +344,11 @@ drop_client_entries (void *cls, | |||
350 | struct ForwardedOverlayConnectContext *foccn; | 344 | struct ForwardedOverlayConnectContext *foccn; |
351 | 345 | ||
352 | for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) | 346 | for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) |
353 | { | 347 | { |
354 | foccn = focc->next; | 348 | foccn = focc->next; |
355 | if (focc->client == client) | 349 | if (focc->client == client) |
356 | GST_cleanup_focc (focc); | 350 | GST_cleanup_focc(focc); |
357 | } | 351 | } |
358 | return GNUNET_OK; | 352 | return GNUNET_OK; |
359 | } | 353 | } |
360 | 354 | ||
@@ -365,11 +359,11 @@ drop_client_entries (void *cls, | |||
365 | * @param route the route to add | 359 | * @param route the route to add |
366 | */ | 360 | */ |
367 | static void | 361 | static void |
368 | route_list_add (struct Route *route) | 362 | route_list_add(struct Route *route) |
369 | { | 363 | { |
370 | if (route->dest >= route_list_size) | 364 | if (route->dest >= route_list_size) |
371 | GST_array_grow_large_enough (route_list, route_list_size, route->dest); | 365 | GST_array_grow_large_enough(route_list, route_list_size, route->dest); |
372 | GNUNET_assert (NULL == route_list[route->dest]); | 366 | GNUNET_assert(NULL == route_list[route->dest]); |
373 | route_list[route->dest] = route; | 367 | route_list[route->dest] = route; |
374 | } | 368 | } |
375 | 369 | ||
@@ -381,11 +375,11 @@ route_list_add (struct Route *route) | |||
381 | * @param n the neighbour to add | 375 | * @param n the neighbour to add |
382 | */ | 376 | */ |
383 | static void | 377 | static void |
384 | neighbour_list_add (struct Neighbour *n) | 378 | neighbour_list_add(struct Neighbour *n) |
385 | { | 379 | { |
386 | if (n->host_id >= neighbour_list_size) | 380 | if (n->host_id >= neighbour_list_size) |
387 | GST_array_grow_large_enough (neighbour_list, neighbour_list_size, n->host_id); | 381 | GST_array_grow_large_enough(neighbour_list, neighbour_list_size, n->host_id); |
388 | GNUNET_assert (NULL == neighbour_list[n->host_id]); | 382 | GNUNET_assert(NULL == neighbour_list[n->host_id]); |
389 | neighbour_list[n->host_id] = n; | 383 | neighbour_list[n->host_id] = n; |
390 | } | 384 | } |
391 | 385 | ||
@@ -394,14 +388,14 @@ neighbour_list_add (struct Neighbour *n) | |||
394 | * Cleans up the route list | 388 | * Cleans up the route list |
395 | */ | 389 | */ |
396 | void | 390 | void |
397 | GST_route_list_clear () | 391 | GST_route_list_clear() |
398 | { | 392 | { |
399 | unsigned int id; | 393 | unsigned int id; |
400 | 394 | ||
401 | for (id = 0; id < route_list_size; id++) | 395 | for (id = 0; id < route_list_size; id++) |
402 | if (NULL != route_list[id]) | 396 | if (NULL != route_list[id]) |
403 | GNUNET_free (route_list[id]); | 397 | GNUNET_free(route_list[id]); |
404 | GNUNET_free_non_null (route_list); | 398 | GNUNET_free_non_null(route_list); |
405 | route_list = NULL; | 399 | route_list = NULL; |
406 | } | 400 | } |
407 | 401 | ||
@@ -416,20 +410,20 @@ GST_route_list_clear () | |||
416 | * #GNUNET_NO if not. | 410 | * #GNUNET_NO if not. |
417 | */ | 411 | */ |
418 | static int | 412 | static int |
419 | reghost_free_iterator (void *cls, | 413 | reghost_free_iterator(void *cls, |
420 | const struct GNUNET_HashCode *key, | 414 | const struct GNUNET_HashCode *key, |
421 | void *value) | 415 | void *value) |
422 | { | 416 | { |
423 | struct Slave *slave = cls; | 417 | struct Slave *slave = cls; |
424 | struct RegisteredHostContext *rhc = value; | 418 | struct RegisteredHostContext *rhc = value; |
425 | struct ForwardedOverlayConnectContext *focc; | 419 | struct ForwardedOverlayConnectContext *focc; |
426 | 420 | ||
427 | GNUNET_assert (GNUNET_YES == | 421 | GNUNET_assert(GNUNET_YES == |
428 | GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key, | 422 | GNUNET_CONTAINER_multihashmap_remove(slave->reghost_map, key, |
429 | value)); | 423 | value)); |
430 | while (NULL != (focc = rhc->focc_dll_head)) | 424 | while (NULL != (focc = rhc->focc_dll_head)) |
431 | GST_cleanup_focc (focc); | 425 | GST_cleanup_focc(focc); |
432 | GNUNET_free (value); | 426 | GNUNET_free(value); |
433 | return GNUNET_YES; | 427 | return GNUNET_YES; |
434 | } | 428 | } |
435 | 429 | ||
@@ -440,30 +434,30 @@ reghost_free_iterator (void *cls, | |||
440 | * @param slave the #Slave object | 434 | * @param slave the #Slave object |
441 | */ | 435 | */ |
442 | static void | 436 | static void |
443 | kill_slave (struct Slave *slave) | 437 | kill_slave(struct Slave *slave) |
444 | { | 438 | { |
445 | struct HostRegistration *hr_entry; | 439 | struct HostRegistration *hr_entry; |
446 | 440 | ||
447 | while (NULL != (hr_entry = slave->hr_dll_head)) | 441 | while (NULL != (hr_entry = slave->hr_dll_head)) |
448 | { | 442 | { |
449 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, | 443 | GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, slave->hr_dll_tail, |
450 | hr_entry); | 444 | hr_entry); |
451 | GNUNET_free (hr_entry); | 445 | GNUNET_free(hr_entry); |
452 | } | 446 | } |
453 | if (NULL != slave->rhandle) | 447 | if (NULL != slave->rhandle) |
454 | GNUNET_TESTBED_cancel_registration (slave->rhandle); | 448 | GNUNET_TESTBED_cancel_registration(slave->rhandle); |
455 | GNUNET_assert (GNUNET_SYSERR != | 449 | GNUNET_assert(GNUNET_SYSERR != |
456 | GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, | 450 | GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, |
457 | reghost_free_iterator, | 451 | reghost_free_iterator, |
458 | slave)); | 452 | slave)); |
459 | GNUNET_CONTAINER_multihashmap_destroy (slave->reghost_map); | 453 | GNUNET_CONTAINER_multihashmap_destroy(slave->reghost_map); |
460 | if (NULL != slave->controller) | 454 | if (NULL != slave->controller) |
461 | GNUNET_TESTBED_controller_disconnect (slave->controller); | 455 | GNUNET_TESTBED_controller_disconnect(slave->controller); |
462 | if (NULL != slave->controller_proc) | 456 | if (NULL != slave->controller_proc) |
463 | { | 457 | { |
464 | LOG_DEBUG ("Stopping a slave\n"); | 458 | LOG_DEBUG("Stopping a slave\n"); |
465 | GNUNET_TESTBED_controller_kill_ (slave->controller_proc); | 459 | GNUNET_TESTBED_controller_kill_(slave->controller_proc); |
466 | } | 460 | } |
467 | } | 461 | } |
468 | 462 | ||
469 | 463 | ||
@@ -473,15 +467,15 @@ kill_slave (struct Slave *slave) | |||
473 | * @param slave the #Slave object | 467 | * @param slave the #Slave object |
474 | */ | 468 | */ |
475 | static void | 469 | static void |
476 | destroy_slave (struct Slave *slave) | 470 | destroy_slave(struct Slave *slave) |
477 | { | 471 | { |
478 | if (NULL != slave->controller_proc) | 472 | if (NULL != slave->controller_proc) |
479 | { | 473 | { |
480 | GNUNET_TESTBED_controller_destroy_ (slave->controller_proc); | 474 | GNUNET_TESTBED_controller_destroy_(slave->controller_proc); |
481 | LOG_DEBUG ("Slave stopped\n"); | 475 | LOG_DEBUG("Slave stopped\n"); |
482 | } | 476 | } |
483 | GST_slave_list[slave->host_id] = NULL; | 477 | GST_slave_list[slave->host_id] = NULL; |
484 | GNUNET_free (slave); | 478 | GNUNET_free(slave); |
485 | } | 479 | } |
486 | 480 | ||
487 | 481 | ||
@@ -489,26 +483,26 @@ destroy_slave (struct Slave *slave) | |||
489 | * Cleans up the slave list | 483 | * Cleans up the slave list |
490 | */ | 484 | */ |
491 | void | 485 | void |
492 | GST_slave_list_clear () | 486 | GST_slave_list_clear() |
493 | { | 487 | { |
494 | struct Slave *slave; | 488 | struct Slave *slave; |
495 | unsigned int id; | 489 | unsigned int id; |
496 | 490 | ||
497 | for (id = 0; id < GST_slave_list_size; id++) | 491 | for (id = 0; id < GST_slave_list_size; id++) |
498 | { | 492 | { |
499 | slave = GST_slave_list[id]; | 493 | slave = GST_slave_list[id]; |
500 | if (NULL == slave) | 494 | if (NULL == slave) |
501 | continue; | 495 | continue; |
502 | kill_slave (slave); | 496 | kill_slave(slave); |
503 | } | 497 | } |
504 | for (id = 0; id < GST_slave_list_size; id++) | 498 | for (id = 0; id < GST_slave_list_size; id++) |
505 | { | 499 | { |
506 | slave = GST_slave_list[id]; | 500 | slave = GST_slave_list[id]; |
507 | if (NULL == slave) | 501 | if (NULL == slave) |
508 | continue; | 502 | continue; |
509 | destroy_slave (slave); | 503 | destroy_slave(slave); |
510 | } | 504 | } |
511 | GNUNET_free_non_null (GST_slave_list); | 505 | GNUNET_free_non_null(GST_slave_list); |
512 | GST_slave_list = NULL; | 506 | GST_slave_list = NULL; |
513 | } | 507 | } |
514 | 508 | ||
@@ -522,18 +516,18 @@ GST_slave_list_clear () | |||
522 | * is found | 516 | * is found |
523 | */ | 517 | */ |
524 | struct Route * | 518 | struct Route * |
525 | GST_find_dest_route (uint32_t host_id) | 519 | GST_find_dest_route(uint32_t host_id) |
526 | { | 520 | { |
527 | struct Route *route; | 521 | struct Route *route; |
528 | 522 | ||
529 | if (route_list_size <= host_id) | 523 | if (route_list_size <= host_id) |
530 | return NULL; | 524 | return NULL; |
531 | while (NULL != (route = route_list[host_id])) | 525 | while (NULL != (route = route_list[host_id])) |
532 | { | 526 | { |
533 | if (route->thru == GST_context->host_id) | 527 | if (route->thru == GST_context->host_id) |
534 | break; | 528 | break; |
535 | host_id = route->thru; | 529 | host_id = route->thru; |
536 | } | 530 | } |
537 | return route; | 531 | return route; |
538 | } | 532 | } |
539 | 533 | ||
@@ -551,10 +545,10 @@ GST_find_dest_route (uint32_t host_id) | |||
551 | * NULL if cfg is set! | 545 | * NULL if cfg is set! |
552 | */ | 546 | */ |
553 | static void | 547 | static void |
554 | send_controller_link_response (struct GNUNET_SERVICE_Client *client, | 548 | send_controller_link_response(struct GNUNET_SERVICE_Client *client, |
555 | uint64_t operation_id, | 549 | uint64_t operation_id, |
556 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 550 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
557 | const char *emsg) | 551 | const char *emsg) |
558 | { | 552 | { |
559 | struct GNUNET_MQ_Envelope *env; | 553 | struct GNUNET_MQ_Envelope *env; |
560 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; | 554 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; |
@@ -563,40 +557,40 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, | |||
563 | size_t xconfig_size; | 557 | size_t xconfig_size; |
564 | uint16_t msize; | 558 | uint16_t msize; |
565 | 559 | ||
566 | GNUNET_assert ((NULL == cfg) || (NULL == emsg)); | 560 | GNUNET_assert((NULL == cfg) || (NULL == emsg)); |
567 | xconfig = NULL; | 561 | xconfig = NULL; |
568 | xconfig_size = 0; | 562 | xconfig_size = 0; |
569 | config_size = 0; | 563 | config_size = 0; |
570 | msize = 0; | 564 | msize = 0; |
571 | if (NULL != cfg) | 565 | if (NULL != cfg) |
572 | { | 566 | { |
573 | xconfig = GNUNET_TESTBED_compress_cfg_ (cfg, | 567 | xconfig = GNUNET_TESTBED_compress_cfg_(cfg, |
574 | &config_size, | 568 | &config_size, |
575 | &xconfig_size); | 569 | &xconfig_size); |
576 | msize += xconfig_size; | 570 | msize += xconfig_size; |
577 | } | 571 | } |
578 | if (NULL != emsg) | 572 | if (NULL != emsg) |
579 | msize += strlen (emsg); | 573 | msize += strlen(emsg); |
580 | env = GNUNET_MQ_msg_extra (msg, | 574 | env = GNUNET_MQ_msg_extra(msg, |
581 | msize, | 575 | msize, |
582 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); | 576 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); |
583 | if (NULL == emsg) | 577 | if (NULL == emsg) |
584 | msg->success = htons (GNUNET_YES); | 578 | msg->success = htons(GNUNET_YES); |
585 | msg->operation_id = GNUNET_htonll (operation_id); | 579 | msg->operation_id = GNUNET_htonll(operation_id); |
586 | msg->config_size = htons ((uint16_t) config_size); | 580 | msg->config_size = htons((uint16_t)config_size); |
587 | if (NULL != xconfig) | 581 | if (NULL != xconfig) |
588 | { | 582 | { |
589 | GNUNET_memcpy (&msg[1], | 583 | GNUNET_memcpy(&msg[1], |
590 | xconfig, | 584 | xconfig, |
591 | xconfig_size); | 585 | xconfig_size); |
592 | GNUNET_free (xconfig); | 586 | GNUNET_free(xconfig); |
593 | } | 587 | } |
594 | if (NULL != emsg) | 588 | if (NULL != emsg) |
595 | GNUNET_memcpy (&msg[1], | 589 | GNUNET_memcpy(&msg[1], |
596 | emsg, | 590 | emsg, |
597 | strlen (emsg)); | 591 | strlen(emsg)); |
598 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 592 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
599 | env); | 593 | env); |
600 | } | 594 | } |
601 | 595 | ||
602 | 596 | ||
@@ -606,7 +600,7 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, | |||
606 | * @param cls the LCFContext | 600 | * @param cls the LCFContext |
607 | */ | 601 | */ |
608 | static void | 602 | static void |
609 | lcf_proc_task (void *cls); | 603 | lcf_proc_task(void *cls); |
610 | 604 | ||
611 | 605 | ||
612 | /** | 606 | /** |
@@ -616,38 +610,40 @@ lcf_proc_task (void *cls); | |||
616 | * @param emsg the error message; NULL if host registration is successful | 610 | * @param emsg the error message; NULL if host registration is successful |
617 | */ | 611 | */ |
618 | static void | 612 | static void |
619 | lcf_proc_cc (void *cls, | 613 | lcf_proc_cc(void *cls, |
620 | const char *emsg) | 614 | const char *emsg) |
621 | { | 615 | { |
622 | struct LCFContext *lcf = cls; | 616 | struct LCFContext *lcf = cls; |
623 | 617 | ||
624 | GNUNET_assert (NULL == lcf_proc_task_id); | 618 | GNUNET_assert(NULL == lcf_proc_task_id); |
625 | switch (lcf->state) | 619 | switch (lcf->state) |
626 | { | 620 | { |
627 | case INIT: | 621 | case INIT: |
628 | if (NULL != emsg) | 622 | if (NULL != emsg) |
629 | goto registration_error; | 623 | goto registration_error; |
630 | lcf->state = DELEGATED_HOST_REGISTERED; | 624 | lcf->state = DELEGATED_HOST_REGISTERED; |
631 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 625 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
632 | break; | 626 | break; |
633 | case DELEGATED_HOST_REGISTERED: | 627 | |
634 | if (NULL != emsg) | 628 | case DELEGATED_HOST_REGISTERED: |
635 | goto registration_error; | 629 | if (NULL != emsg) |
636 | lcf->state = SLAVE_HOST_REGISTERED; | 630 | goto registration_error; |
637 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 631 | lcf->state = SLAVE_HOST_REGISTERED; |
638 | break; | 632 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
639 | default: | 633 | break; |
640 | GNUNET_assert (0); /* Shouldn't reach here */ | 634 | |
641 | } | 635 | default: |
636 | GNUNET_assert(0); /* Shouldn't reach here */ | ||
637 | } | ||
642 | return; | 638 | return; |
643 | 639 | ||
644 | registration_error: | 640 | registration_error: |
645 | LOG (GNUNET_ERROR_TYPE_WARNING, | 641 | LOG(GNUNET_ERROR_TYPE_WARNING, |
646 | "Host registration failed with message: %s\n", | 642 | "Host registration failed with message: %s\n", |
647 | emsg); | 643 | emsg); |
648 | lcf->state = FINISHED; | 644 | lcf->state = FINISHED; |
649 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 645 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
650 | lcf); | 646 | lcf); |
651 | } | 647 | } |
652 | 648 | ||
653 | 649 | ||
@@ -657,7 +653,7 @@ registration_error: | |||
657 | * @param cls the LCFContext | 653 | * @param cls the LCFContext |
658 | */ | 654 | */ |
659 | static void | 655 | static void |
660 | lcf_proc_task (void *cls); | 656 | lcf_proc_task(void *cls); |
661 | 657 | ||
662 | 658 | ||
663 | /** | 659 | /** |
@@ -666,21 +662,21 @@ lcf_proc_task (void *cls); | |||
666 | * @param cls the LCFContext | 662 | * @param cls the LCFContext |
667 | */ | 663 | */ |
668 | static void | 664 | static void |
669 | lcf_forwarded_operation_timeout (void *cls) | 665 | lcf_forwarded_operation_timeout(void *cls) |
670 | { | 666 | { |
671 | struct LCFContext *lcf = cls; | 667 | struct LCFContext *lcf = cls; |
672 | 668 | ||
673 | lcf->timeout_task = NULL; | 669 | lcf->timeout_task = NULL; |
674 | // GST_forwarded_operation_timeout (lcf->fopc, tc); | 670 | // GST_forwarded_operation_timeout (lcf->fopc, tc); |
675 | LOG (GNUNET_ERROR_TYPE_WARNING, | 671 | LOG(GNUNET_ERROR_TYPE_WARNING, |
676 | "A forwarded controller link operation has timed out\n"); | 672 | "A forwarded controller link operation has timed out\n"); |
677 | send_controller_link_response (lcf->client, | 673 | send_controller_link_response(lcf->client, |
678 | lcf->operation_id, | 674 | lcf->operation_id, |
679 | NULL, | 675 | NULL, |
680 | "A forwarded controller link operation has timed out\n"); | 676 | "A forwarded controller link operation has timed out\n"); |
681 | GNUNET_assert (NULL == lcf_proc_task_id); | 677 | GNUNET_assert(NULL == lcf_proc_task_id); |
682 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 678 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
683 | lcf); | 679 | lcf); |
684 | } | 680 | } |
685 | 681 | ||
686 | 682 | ||
@@ -690,65 +686,68 @@ lcf_forwarded_operation_timeout (void *cls) | |||
690 | * @param cls the LCFContext | 686 | * @param cls the LCFContext |
691 | */ | 687 | */ |
692 | static void | 688 | static void |
693 | lcf_proc_task (void *cls) | 689 | lcf_proc_task(void *cls) |
694 | { | 690 | { |
695 | struct LCFContext *lcf = cls; | 691 | struct LCFContext *lcf = cls; |
696 | 692 | ||
697 | lcf_proc_task_id = NULL; | 693 | lcf_proc_task_id = NULL; |
698 | switch (lcf->state) | 694 | switch (lcf->state) |
699 | { | ||
700 | case INIT: | ||
701 | if (GNUNET_NO == | ||
702 | GNUNET_TESTBED_is_host_registered_ (GST_host_list | ||
703 | [lcf->delegated_host_id], | ||
704 | lcf->gateway->controller)) | ||
705 | { | ||
706 | GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, | ||
707 | GST_host_list[lcf->delegated_host_id]); | ||
708 | } | ||
709 | else | ||
710 | { | ||
711 | lcf->state = DELEGATED_HOST_REGISTERED; | ||
712 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | ||
713 | } | ||
714 | break; | ||
715 | case DELEGATED_HOST_REGISTERED: | ||
716 | if (GNUNET_NO == | ||
717 | GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id], | ||
718 | lcf->gateway->controller)) | ||
719 | { | ||
720 | GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, | ||
721 | GST_host_list[lcf->slave_host_id]); | ||
722 | } | ||
723 | else | ||
724 | { | 695 | { |
725 | lcf->state = SLAVE_HOST_REGISTERED; | 696 | case INIT: |
726 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 697 | if (GNUNET_NO == |
698 | GNUNET_TESTBED_is_host_registered_(GST_host_list | ||
699 | [lcf->delegated_host_id], | ||
700 | lcf->gateway->controller)) | ||
701 | { | ||
702 | GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, | ||
703 | GST_host_list[lcf->delegated_host_id]); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | lcf->state = DELEGATED_HOST_REGISTERED; | ||
708 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); | ||
709 | } | ||
710 | break; | ||
711 | |||
712 | case DELEGATED_HOST_REGISTERED: | ||
713 | if (GNUNET_NO == | ||
714 | GNUNET_TESTBED_is_host_registered_(GST_host_list[lcf->slave_host_id], | ||
715 | lcf->gateway->controller)) | ||
716 | { | ||
717 | GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, | ||
718 | GST_host_list[lcf->slave_host_id]); | ||
719 | } | ||
720 | else | ||
721 | { | ||
722 | lcf->state = SLAVE_HOST_REGISTERED; | ||
723 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); | ||
724 | } | ||
725 | break; | ||
726 | |||
727 | case SLAVE_HOST_REGISTERED: | ||
728 | lcf->op = GNUNET_TESTBED_controller_link(lcf, | ||
729 | lcf->gateway->controller, | ||
730 | GST_host_list[lcf->delegated_host_id], | ||
731 | GST_host_list[lcf->slave_host_id], | ||
732 | lcf->is_subordinate); | ||
733 | lcf->timeout_task = | ||
734 | GNUNET_SCHEDULER_add_delayed(GST_timeout, | ||
735 | &lcf_forwarded_operation_timeout, | ||
736 | lcf); | ||
737 | lcf->state = FINISHED; | ||
738 | break; | ||
739 | |||
740 | case FINISHED: | ||
741 | if (NULL != lcf->op) | ||
742 | GNUNET_TESTBED_operation_done(lcf->op); | ||
743 | GNUNET_CONTAINER_DLL_remove(lcf_head, | ||
744 | lcf_tail, | ||
745 | lcf); | ||
746 | GNUNET_free(lcf); | ||
747 | if (NULL != lcf_head) | ||
748 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, | ||
749 | lcf_head); | ||
727 | } | 750 | } |
728 | break; | ||
729 | case SLAVE_HOST_REGISTERED: | ||
730 | lcf->op = GNUNET_TESTBED_controller_link (lcf, | ||
731 | lcf->gateway->controller, | ||
732 | GST_host_list[lcf->delegated_host_id], | ||
733 | GST_host_list[lcf->slave_host_id], | ||
734 | lcf->is_subordinate); | ||
735 | lcf->timeout_task = | ||
736 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | ||
737 | &lcf_forwarded_operation_timeout, | ||
738 | lcf); | ||
739 | lcf->state = FINISHED; | ||
740 | break; | ||
741 | case FINISHED: | ||
742 | if (NULL != lcf->op) | ||
743 | GNUNET_TESTBED_operation_done (lcf->op); | ||
744 | GNUNET_CONTAINER_DLL_remove (lcf_head, | ||
745 | lcf_tail, | ||
746 | lcf); | ||
747 | GNUNET_free (lcf); | ||
748 | if (NULL != lcf_head) | ||
749 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | ||
750 | lcf_head); | ||
751 | } | ||
752 | } | 751 | } |
753 | 752 | ||
754 | 753 | ||
@@ -759,30 +758,30 @@ lcf_proc_task (void *cls) | |||
759 | * @param event information about the event | 758 | * @param event information about the event |
760 | */ | 759 | */ |
761 | static void | 760 | static void |
762 | slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 761 | slave_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
763 | { | 762 | { |
764 | struct LCFContext *lcf; | 763 | struct LCFContext *lcf; |
765 | 764 | ||
766 | /* We currently only get here when working on LCFContexts */ | 765 | /* We currently only get here when working on LCFContexts */ |
767 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | 766 | GNUNET_assert(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
768 | lcf = event->op_cls; | 767 | lcf = event->op_cls; |
769 | GNUNET_assert (lcf->op == event->op); | 768 | GNUNET_assert(lcf->op == event->op); |
770 | GNUNET_TESTBED_operation_done (lcf->op); | 769 | GNUNET_TESTBED_operation_done(lcf->op); |
771 | lcf->op = NULL; | 770 | lcf->op = NULL; |
772 | GNUNET_assert (FINISHED == lcf->state); | 771 | GNUNET_assert(FINISHED == lcf->state); |
773 | GNUNET_assert (NULL != lcf->timeout_task); | 772 | GNUNET_assert(NULL != lcf->timeout_task); |
774 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 773 | GNUNET_SCHEDULER_cancel(lcf->timeout_task); |
775 | if (NULL == event->details.operation_finished.emsg) | 774 | if (NULL == event->details.operation_finished.emsg) |
776 | send_controller_link_response (lcf->client, lcf->operation_id, | 775 | send_controller_link_response(lcf->client, lcf->operation_id, |
777 | GNUNET_TESTBED_host_get_cfg_ | 776 | GNUNET_TESTBED_host_get_cfg_ |
778 | (GST_host_list[lcf->delegated_host_id]), | 777 | (GST_host_list[lcf->delegated_host_id]), |
779 | NULL); | 778 | NULL); |
780 | else | 779 | else |
781 | send_controller_link_response (lcf->client, lcf->operation_id, | 780 | send_controller_link_response(lcf->client, lcf->operation_id, |
782 | NULL, | 781 | NULL, |
783 | event->details.operation_finished.emsg); | 782 | event->details.operation_finished.emsg); |
784 | GNUNET_assert (NULL == lcf_proc_task_id); | 783 | GNUNET_assert(NULL == lcf_proc_task_id); |
785 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 784 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
786 | return; | 785 | return; |
787 | } | 786 | } |
788 | 787 | ||
@@ -797,56 +796,56 @@ slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
797 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 796 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
798 | */ | 797 | */ |
799 | static void | 798 | static void |
800 | slave_status_cb (void *cls, | 799 | slave_status_cb(void *cls, |
801 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 800 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
802 | int status) | 801 | int status) |
803 | { | 802 | { |
804 | struct Slave *slave = cls; | 803 | struct Slave *slave = cls; |
805 | struct LinkControllersContext *lcc; | 804 | struct LinkControllersContext *lcc; |
806 | 805 | ||
807 | lcc = slave->lcc; | 806 | lcc = slave->lcc; |
808 | if (GNUNET_SYSERR == status) | 807 | if (GNUNET_SYSERR == status) |
809 | { | 808 | { |
810 | slave->controller_proc = NULL; | 809 | slave->controller_proc = NULL; |
811 | /* Stop all link controller forwarding tasks since we shutdown here anyway | 810 | /* Stop all link controller forwarding tasks since we shutdown here anyway |
812 | and as these tasks they depend on the operation queues which are created | 811 | and as these tasks they depend on the operation queues which are created |
813 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call | 812 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call |
814 | the destructor function GNUNET_TESTBED_controller_disconnect() */ | 813 | the destructor function GNUNET_TESTBED_controller_disconnect() */ |
815 | GST_free_lcf (); | 814 | GST_free_lcf(); |
816 | kill_slave (slave); | 815 | kill_slave(slave); |
817 | destroy_slave (slave); | 816 | destroy_slave(slave); |
818 | slave = NULL; | 817 | slave = NULL; |
819 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); | 818 | LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); |
820 | GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ | 819 | GNUNET_SCHEDULER_shutdown(); /* We too shutdown */ |
821 | goto clean_lcc; | 820 | goto clean_lcc; |
822 | } | 821 | } |
823 | slave->controller = | 822 | slave->controller = |
824 | GNUNET_TESTBED_controller_connect (GST_host_list[slave->host_id], | 823 | GNUNET_TESTBED_controller_connect(GST_host_list[slave->host_id], |
825 | EVENT_MASK, &slave_event_cb, | 824 | EVENT_MASK, &slave_event_cb, |
826 | slave); | 825 | slave); |
827 | if (NULL != slave->controller) | 826 | if (NULL != slave->controller) |
828 | { | 827 | { |
829 | send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL); | 828 | send_controller_link_response(lcc->client, lcc->operation_id, cfg, NULL); |
830 | } | 829 | } |
831 | else | 830 | else |
832 | { | 831 | { |
833 | send_controller_link_response (lcc->client, lcc->operation_id, NULL, | 832 | send_controller_link_response(lcc->client, lcc->operation_id, NULL, |
834 | "Could not connect to delegated controller"); | 833 | "Could not connect to delegated controller"); |
835 | kill_slave (slave); | 834 | kill_slave(slave); |
836 | destroy_slave (slave); | 835 | destroy_slave(slave); |
837 | slave = NULL; | 836 | slave = NULL; |
838 | } | 837 | } |
839 | 838 | ||
840 | clean_lcc: | 839 | clean_lcc: |
841 | if (NULL != lcc) | 840 | if (NULL != lcc) |
842 | { | ||
843 | if (NULL != lcc->client) | ||
844 | { | 841 | { |
845 | GNUNET_SERVICE_client_continue (lcc->client); | 842 | if (NULL != lcc->client) |
846 | lcc->client = NULL; | 843 | { |
844 | GNUNET_SERVICE_client_continue(lcc->client); | ||
845 | lcc->client = NULL; | ||
846 | } | ||
847 | GNUNET_free(lcc); | ||
847 | } | 848 | } |
848 | GNUNET_free (lcc); | ||
849 | } | ||
850 | if (NULL != slave) | 849 | if (NULL != slave) |
851 | slave->lcc = NULL; | 850 | slave->lcc = NULL; |
852 | } | 851 | } |
@@ -861,7 +860,7 @@ slave_status_cb (void *cls, | |||
861 | * @param n the neighbour | 860 | * @param n the neighbour |
862 | */ | 861 | */ |
863 | static void | 862 | static void |
864 | trigger_notifications (struct Neighbour *n); | 863 | trigger_notifications(struct Neighbour *n); |
865 | 864 | ||
866 | 865 | ||
867 | /** | 866 | /** |
@@ -871,19 +870,19 @@ trigger_notifications (struct Neighbour *n); | |||
871 | * @param cls the neighbour | 870 | * @param cls the neighbour |
872 | */ | 871 | */ |
873 | static void | 872 | static void |
874 | neighbour_connect_notify_task (void *cls) | 873 | neighbour_connect_notify_task(void *cls) |
875 | { | 874 | { |
876 | struct Neighbour *n = cls; | 875 | struct Neighbour *n = cls; |
877 | struct NeighbourConnectNotification *h; | 876 | struct NeighbourConnectNotification *h; |
878 | 877 | ||
879 | GNUNET_assert (NULL != (h = n->nl_head)); | 878 | GNUNET_assert(NULL != (h = n->nl_head)); |
880 | GNUNET_assert (NULL != n->notify_task); | 879 | GNUNET_assert(NULL != n->notify_task); |
881 | n->notify_task = NULL; | 880 | n->notify_task = NULL; |
882 | GNUNET_assert (NULL != n->controller); | 881 | GNUNET_assert(NULL != n->controller); |
883 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 882 | GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); |
884 | trigger_notifications (n); | 883 | trigger_notifications(n); |
885 | h->cb (h->cb_cls, n->controller); | 884 | h->cb(h->cb_cls, n->controller); |
886 | GNUNET_free (h); | 885 | GNUNET_free(h); |
887 | } | 886 | } |
888 | 887 | ||
889 | 888 | ||
@@ -896,9 +895,9 @@ neighbour_connect_notify_task (void *cls) | |||
896 | * @param n the neighbour | 895 | * @param n the neighbour |
897 | */ | 896 | */ |
898 | static void | 897 | static void |
899 | trigger_notifications (struct Neighbour *n) | 898 | trigger_notifications(struct Neighbour *n) |
900 | { | 899 | { |
901 | GNUNET_assert (NULL != n->conn_op); | 900 | GNUNET_assert(NULL != n->conn_op); |
902 | if (NULL == n->nl_head) | 901 | if (NULL == n->nl_head) |
903 | return; | 902 | return; |
904 | if (NULL == n->controller) | 903 | if (NULL == n->controller) |
@@ -906,14 +905,14 @@ trigger_notifications (struct Neighbour *n) | |||
906 | if (NULL != n->notify_task) | 905 | if (NULL != n->notify_task) |
907 | return; | 906 | return; |
908 | if (1 == n->inactive) | 907 | if (1 == n->inactive) |
909 | { | 908 | { |
910 | GNUNET_assert (0 == n->reference_cnt); | 909 | GNUNET_assert(0 == n->reference_cnt); |
911 | GNUNET_TESTBED_operation_activate_ (n->conn_op); | 910 | GNUNET_TESTBED_operation_activate_(n->conn_op); |
912 | n->inactive = 0; | 911 | n->inactive = 0; |
913 | } | 912 | } |
914 | n->reference_cnt++; | 913 | n->reference_cnt++; |
915 | n->notify_task = | 914 | n->notify_task = |
916 | GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n); | 915 | GNUNET_SCHEDULER_add_now(&neighbour_connect_notify_task, n); |
917 | } | 916 | } |
918 | 917 | ||
919 | 918 | ||
@@ -925,18 +924,18 @@ trigger_notifications (struct Neighbour *n) | |||
925 | * @param cls the neighbour | 924 | * @param cls the neighbour |
926 | */ | 925 | */ |
927 | static void | 926 | static void |
928 | opstart_neighbour_conn (void *cls) | 927 | opstart_neighbour_conn(void *cls) |
929 | { | 928 | { |
930 | struct Neighbour *n = cls; | 929 | struct Neighbour *n = cls; |
931 | 930 | ||
932 | GNUNET_assert (NULL != n->conn_op); | 931 | GNUNET_assert(NULL != n->conn_op); |
933 | GNUNET_assert (NULL == n->controller); | 932 | GNUNET_assert(NULL == n->controller); |
934 | LOG_DEBUG ("Opening connection to controller on host %u\n", n->host_id); | 933 | LOG_DEBUG("Opening connection to controller on host %u\n", n->host_id); |
935 | n->controller = GNUNET_TESTBED_controller_connect (GST_host_list[n->host_id], | 934 | n->controller = GNUNET_TESTBED_controller_connect(GST_host_list[n->host_id], |
936 | EVENT_MASK, | 935 | EVENT_MASK, |
937 | &slave_event_cb, | 936 | &slave_event_cb, |
938 | NULL); | 937 | NULL); |
939 | trigger_notifications (n); | 938 | trigger_notifications(n); |
940 | } | 939 | } |
941 | 940 | ||
942 | 941 | ||
@@ -946,21 +945,21 @@ opstart_neighbour_conn (void *cls) | |||
946 | * @param cls the neighbour | 945 | * @param cls the neighbour |
947 | */ | 946 | */ |
948 | static void | 947 | static void |
949 | oprelease_neighbour_conn (void *cls) | 948 | oprelease_neighbour_conn(void *cls) |
950 | { | 949 | { |
951 | struct Neighbour *n = cls; | 950 | struct Neighbour *n = cls; |
952 | 951 | ||
953 | GNUNET_assert (0 == n->reference_cnt); | 952 | GNUNET_assert(0 == n->reference_cnt); |
954 | GNUNET_assert (NULL == n->notify_task); | 953 | GNUNET_assert(NULL == n->notify_task); |
955 | GNUNET_assert (NULL == n->nl_head); | 954 | GNUNET_assert(NULL == n->nl_head); |
956 | if (NULL != n->controller) | 955 | if (NULL != n->controller) |
957 | { | 956 | { |
958 | LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id); | 957 | LOG_DEBUG("Closing connection to controller on host %u\n", n->host_id); |
959 | GNUNET_TESTBED_controller_disconnect (n->controller); | 958 | GNUNET_TESTBED_controller_disconnect(n->controller); |
960 | n->controller = NULL; | 959 | n->controller = NULL; |
961 | } | 960 | } |
962 | n->conn_op = NULL; | 961 | n->conn_op = NULL; |
963 | n->inactive = 0; | 962 | n->inactive = 0; |
964 | } | 963 | } |
965 | 964 | ||
966 | 965 | ||
@@ -976,30 +975,30 @@ oprelease_neighbour_conn (void *cls) | |||
976 | * @param cb_cls the closure for the above callback | 975 | * @param cb_cls the closure for the above callback |
977 | */ | 976 | */ |
978 | struct NeighbourConnectNotification * | 977 | struct NeighbourConnectNotification * |
979 | GST_neighbour_get_connection (struct Neighbour *n, | 978 | GST_neighbour_get_connection(struct Neighbour *n, |
980 | GST_NeigbourConnectNotifyCallback cb, | 979 | GST_NeigbourConnectNotifyCallback cb, |
981 | void *cb_cls) | 980 | void *cb_cls) |
982 | { | 981 | { |
983 | struct NeighbourConnectNotification *h; | 982 | struct NeighbourConnectNotification *h; |
984 | 983 | ||
985 | GNUNET_assert (NULL != cb); | 984 | GNUNET_assert(NULL != cb); |
986 | LOG_DEBUG ("Attempting to get connection to controller on host %u\n", | 985 | LOG_DEBUG("Attempting to get connection to controller on host %u\n", |
987 | n->host_id); | 986 | n->host_id); |
988 | h = GNUNET_new (struct NeighbourConnectNotification); | 987 | h = GNUNET_new(struct NeighbourConnectNotification); |
989 | h->n = n; | 988 | h->n = n; |
990 | h->cb = cb; | 989 | h->cb = cb; |
991 | h->cb_cls = cb_cls; | 990 | h->cb_cls = cb_cls; |
992 | GNUNET_CONTAINER_DLL_insert_tail (n->nl_head, n->nl_tail, h); | 991 | GNUNET_CONTAINER_DLL_insert_tail(n->nl_head, n->nl_tail, h); |
993 | if (NULL == n->conn_op) | 992 | if (NULL == n->conn_op) |
994 | { | 993 | { |
995 | GNUNET_assert (NULL == n->controller); | 994 | GNUNET_assert(NULL == n->controller); |
996 | n->conn_op = GNUNET_TESTBED_operation_create_ (n, &opstart_neighbour_conn, | 995 | n->conn_op = GNUNET_TESTBED_operation_create_(n, &opstart_neighbour_conn, |
997 | &oprelease_neighbour_conn); | 996 | &oprelease_neighbour_conn); |
998 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, n->conn_op); | 997 | GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, n->conn_op); |
999 | GNUNET_TESTBED_operation_begin_wait_ (n->conn_op); | 998 | GNUNET_TESTBED_operation_begin_wait_(n->conn_op); |
1000 | return h; | 999 | return h; |
1001 | } | 1000 | } |
1002 | trigger_notifications (n); | 1001 | trigger_notifications(n); |
1003 | return h; | 1002 | return h; |
1004 | } | 1003 | } |
1005 | 1004 | ||
@@ -1010,33 +1009,33 @@ GST_neighbour_get_connection (struct Neighbour *n, | |||
1010 | * @param h the notification handle | 1009 | * @param h the notification handle |
1011 | */ | 1010 | */ |
1012 | void | 1011 | void |
1013 | GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) | 1012 | GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h) |
1014 | { | 1013 | { |
1015 | struct Neighbour *n; | 1014 | struct Neighbour *n; |
1016 | int cleanup_task; | 1015 | int cleanup_task; |
1017 | 1016 | ||
1018 | n = h->n; | 1017 | n = h->n; |
1019 | cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; | 1018 | cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; |
1020 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 1019 | GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); |
1021 | GNUNET_free (h); | 1020 | GNUNET_free(h); |
1022 | if (GNUNET_NO == cleanup_task) | 1021 | if (GNUNET_NO == cleanup_task) |
1023 | return; | 1022 | return; |
1024 | if (NULL == n->notify_task) | 1023 | if (NULL == n->notify_task) |
1025 | return; | 1024 | return; |
1026 | GNUNET_assert (0 < n->reference_cnt); | 1025 | GNUNET_assert(0 < n->reference_cnt); |
1027 | n->reference_cnt--; | 1026 | n->reference_cnt--; |
1028 | GNUNET_SCHEDULER_cancel (n->notify_task); | 1027 | GNUNET_SCHEDULER_cancel(n->notify_task); |
1029 | n->notify_task = NULL; | 1028 | n->notify_task = NULL; |
1030 | if (NULL == n->nl_head) | 1029 | if (NULL == n->nl_head) |
1031 | { | ||
1032 | if ( (0 == n->reference_cnt) && (0 == n->inactive) ) | ||
1033 | { | 1030 | { |
1034 | n->inactive = 1; | 1031 | if ((0 == n->reference_cnt) && (0 == n->inactive)) |
1035 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | 1032 | { |
1033 | n->inactive = 1; | ||
1034 | GNUNET_TESTBED_operation_inactivate_(n->conn_op); | ||
1035 | } | ||
1036 | return; | ||
1036 | } | 1037 | } |
1037 | return; | 1038 | trigger_notifications(n); |
1038 | } | ||
1039 | trigger_notifications (n); | ||
1040 | } | 1039 | } |
1041 | 1040 | ||
1042 | 1041 | ||
@@ -1048,16 +1047,16 @@ GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) | |||
1048 | * @param n the neighbour whose connection can be closed | 1047 | * @param n the neighbour whose connection can be closed |
1049 | */ | 1048 | */ |
1050 | void | 1049 | void |
1051 | GST_neighbour_release_connection (struct Neighbour *n) | 1050 | GST_neighbour_release_connection(struct Neighbour *n) |
1052 | { | 1051 | { |
1053 | GNUNET_assert (0 == n->inactive); | 1052 | GNUNET_assert(0 == n->inactive); |
1054 | GNUNET_assert (0 < n->reference_cnt); | 1053 | GNUNET_assert(0 < n->reference_cnt); |
1055 | n->reference_cnt--; | 1054 | n->reference_cnt--; |
1056 | if (0 == n->reference_cnt) | 1055 | if (0 == n->reference_cnt) |
1057 | { | 1056 | { |
1058 | n->inactive = 1; | 1057 | n->inactive = 1; |
1059 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | 1058 | GNUNET_TESTBED_operation_inactivate_(n->conn_op); |
1060 | } | 1059 | } |
1061 | } | 1060 | } |
1062 | 1061 | ||
1063 | 1062 | ||
@@ -1067,16 +1066,16 @@ GST_neighbour_release_connection (struct Neighbour *n) | |||
1067 | * @param ncc the neighbour connect context to cleanup | 1066 | * @param ncc the neighbour connect context to cleanup |
1068 | */ | 1067 | */ |
1069 | static void | 1068 | static void |
1070 | cleanup_ncc (struct NeighbourConnectCtxt *ncc) | 1069 | cleanup_ncc(struct NeighbourConnectCtxt *ncc) |
1071 | { | 1070 | { |
1072 | if (NULL != ncc->nh) | 1071 | if (NULL != ncc->nh) |
1073 | GST_neighbour_get_connection_cancel (ncc->nh); | 1072 | GST_neighbour_get_connection_cancel(ncc->nh); |
1074 | if (NULL != ncc->timeout_task) | 1073 | if (NULL != ncc->timeout_task) |
1075 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); | 1074 | GNUNET_SCHEDULER_cancel(ncc->timeout_task); |
1076 | GNUNET_CONTAINER_DLL_remove (ncc_head, | 1075 | GNUNET_CONTAINER_DLL_remove(ncc_head, |
1077 | ncc_tail, | 1076 | ncc_tail, |
1078 | ncc); | 1077 | ncc); |
1079 | GNUNET_free (ncc); | 1078 | GNUNET_free(ncc); |
1080 | } | 1079 | } |
1081 | 1080 | ||
1082 | 1081 | ||
@@ -1084,21 +1083,21 @@ cleanup_ncc (struct NeighbourConnectCtxt *ncc) | |||
1084 | * Cleans up the neighbour list | 1083 | * Cleans up the neighbour list |
1085 | */ | 1084 | */ |
1086 | void | 1085 | void |
1087 | GST_neighbour_list_clean () | 1086 | GST_neighbour_list_clean() |
1088 | { | 1087 | { |
1089 | struct Neighbour *n; | 1088 | struct Neighbour *n; |
1090 | unsigned int id; | 1089 | unsigned int id; |
1091 | 1090 | ||
1092 | for (id = 0; id < neighbour_list_size; id++) | 1091 | for (id = 0; id < neighbour_list_size; id++) |
1093 | { | 1092 | { |
1094 | if (NULL == (n = neighbour_list[id])) | 1093 | if (NULL == (n = neighbour_list[id])) |
1095 | continue; | 1094 | continue; |
1096 | if (NULL != n->conn_op) | 1095 | if (NULL != n->conn_op) |
1097 | GNUNET_TESTBED_operation_release_ (n->conn_op); | 1096 | GNUNET_TESTBED_operation_release_(n->conn_op); |
1098 | GNUNET_free (n); | 1097 | GNUNET_free(n); |
1099 | neighbour_list[id] = NULL; | 1098 | neighbour_list[id] = NULL; |
1100 | } | 1099 | } |
1101 | GNUNET_free_non_null (neighbour_list); | 1100 | GNUNET_free_non_null(neighbour_list); |
1102 | } | 1101 | } |
1103 | 1102 | ||
1104 | 1103 | ||
@@ -1110,7 +1109,7 @@ GST_neighbour_list_clean () | |||
1110 | * the list size or neighbour at that index is NULL) | 1109 | * the list size or neighbour at that index is NULL) |
1111 | */ | 1110 | */ |
1112 | struct Neighbour * | 1111 | struct Neighbour * |
1113 | GST_get_neighbour (uint32_t id) | 1112 | GST_get_neighbour(uint32_t id) |
1114 | { | 1113 | { |
1115 | if (neighbour_list_size <= id) | 1114 | if (neighbour_list_size <= id) |
1116 | return NULL; | 1115 | return NULL; |
@@ -1122,10 +1121,10 @@ GST_get_neighbour (uint32_t id) | |||
1122 | * Function to cleanup the neighbour connect contexts | 1121 | * Function to cleanup the neighbour connect contexts |
1123 | */ | 1122 | */ |
1124 | void | 1123 | void |
1125 | GST_free_nccq () | 1124 | GST_free_nccq() |
1126 | { | 1125 | { |
1127 | while (NULL != ncc_head) | 1126 | while (NULL != ncc_head) |
1128 | cleanup_ncc (ncc_head); | 1127 | cleanup_ncc(ncc_head); |
1129 | } | 1128 | } |
1130 | 1129 | ||
1131 | 1130 | ||
@@ -1135,16 +1134,16 @@ GST_free_nccq () | |||
1135 | * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() | 1134 | * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() |
1136 | */ | 1135 | */ |
1137 | static void | 1136 | static void |
1138 | timeout_neighbour_connect (void *cls) | 1137 | timeout_neighbour_connect(void *cls) |
1139 | { | 1138 | { |
1140 | struct NeighbourConnectCtxt *ncc = cls; | 1139 | struct NeighbourConnectCtxt *ncc = cls; |
1141 | 1140 | ||
1142 | ncc->timeout_task = NULL; | 1141 | ncc->timeout_task = NULL; |
1143 | send_controller_link_response (ncc->client, | 1142 | send_controller_link_response(ncc->client, |
1144 | ncc->op_id, | 1143 | ncc->op_id, |
1145 | NULL, | 1144 | NULL, |
1146 | "Could not connect to delegated controller"); | 1145 | "Could not connect to delegated controller"); |
1147 | cleanup_ncc (ncc); | 1146 | cleanup_ncc(ncc); |
1148 | } | 1147 | } |
1149 | 1148 | ||
1150 | 1149 | ||
@@ -1155,20 +1154,20 @@ timeout_neighbour_connect (void *cls) | |||
1155 | * @param c the handle the neighbour's controller | 1154 | * @param c the handle the neighbour's controller |
1156 | */ | 1155 | */ |
1157 | static void | 1156 | static void |
1158 | neighbour_connect_cb (void *cls, | 1157 | neighbour_connect_cb(void *cls, |
1159 | struct GNUNET_TESTBED_Controller *c) | 1158 | struct GNUNET_TESTBED_Controller *c) |
1160 | { | 1159 | { |
1161 | struct NeighbourConnectCtxt *ncc = cls; | 1160 | struct NeighbourConnectCtxt *ncc = cls; |
1162 | 1161 | ||
1163 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); | 1162 | GNUNET_SCHEDULER_cancel(ncc->timeout_task); |
1164 | ncc->timeout_task = NULL; | 1163 | ncc->timeout_task = NULL; |
1165 | ncc->nh = NULL; | 1164 | ncc->nh = NULL; |
1166 | GST_neighbour_release_connection (ncc->n); | 1165 | GST_neighbour_release_connection(ncc->n); |
1167 | send_controller_link_response (ncc->client, | 1166 | send_controller_link_response(ncc->client, |
1168 | ncc->op_id, | 1167 | ncc->op_id, |
1169 | NULL, | 1168 | NULL, |
1170 | NULL); | 1169 | NULL); |
1171 | cleanup_ncc (ncc); | 1170 | cleanup_ncc(ncc); |
1172 | } | 1171 | } |
1173 | 1172 | ||
1174 | 1173 | ||
@@ -1178,13 +1177,13 @@ neighbour_connect_cb (void *cls, | |||
1178 | * @param host the host of the neighbour | 1177 | * @param host the host of the neighbour |
1179 | */ | 1178 | */ |
1180 | struct Neighbour * | 1179 | struct Neighbour * |
1181 | GST_create_neighbour (struct GNUNET_TESTBED_Host *host) | 1180 | GST_create_neighbour(struct GNUNET_TESTBED_Host *host) |
1182 | { | 1181 | { |
1183 | struct Neighbour *n; | 1182 | struct Neighbour *n; |
1184 | 1183 | ||
1185 | n = GNUNET_new (struct Neighbour); | 1184 | n = GNUNET_new(struct Neighbour); |
1186 | n->host_id = GNUNET_TESTBED_host_get_id_ (host); | 1185 | n->host_id = GNUNET_TESTBED_host_get_id_(host); |
1187 | neighbour_list_add (n); /* just add; connect on-demand */ | 1186 | neighbour_list_add(n); /* just add; connect on-demand */ |
1188 | return n; | 1187 | return n; |
1189 | } | 1188 | } |
1190 | 1189 | ||
@@ -1196,8 +1195,8 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host) | |||
1196 | * @param msg the actual message | 1195 | * @param msg the actual message |
1197 | */ | 1196 | */ |
1198 | void | 1197 | void |
1199 | handle_link_controllers (void *cls, | 1198 | handle_link_controllers(void *cls, |
1200 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg) | 1199 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg) |
1201 | { | 1200 | { |
1202 | struct GNUNET_SERVICE_Client *client = cls; | 1201 | struct GNUNET_SERVICE_Client *client = cls; |
1203 | struct LCFContext *lcf; | 1202 | struct LCFContext *lcf; |
@@ -1208,169 +1207,169 @@ handle_link_controllers (void *cls, | |||
1208 | uint32_t slave_host_id; | 1207 | uint32_t slave_host_id; |
1209 | 1208 | ||
1210 | if (NULL == GST_context) | 1209 | if (NULL == GST_context) |
1211 | { | 1210 | { |
1212 | GNUNET_break (0); | 1211 | GNUNET_break(0); |
1213 | GNUNET_SERVICE_client_drop (client); | 1212 | GNUNET_SERVICE_client_drop(client); |
1214 | return; | 1213 | return; |
1215 | } | 1214 | } |
1216 | delegated_host_id = ntohl (msg->delegated_host_id); | 1215 | delegated_host_id = ntohl(msg->delegated_host_id); |
1217 | if (delegated_host_id == GST_context->host_id) | 1216 | if (delegated_host_id == GST_context->host_id) |
1218 | { | 1217 | { |
1219 | GNUNET_break (0); | 1218 | GNUNET_break(0); |
1220 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1219 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1221 | "Trying to link ourselves\n"); | 1220 | "Trying to link ourselves\n"); |
1222 | GNUNET_SERVICE_client_drop (client); | 1221 | GNUNET_SERVICE_client_drop(client); |
1223 | return; | 1222 | return; |
1224 | } | 1223 | } |
1225 | if ((delegated_host_id >= GST_host_list_size) || | 1224 | if ((delegated_host_id >= GST_host_list_size) || |
1226 | (NULL == GST_host_list[delegated_host_id])) | 1225 | (NULL == GST_host_list[delegated_host_id])) |
1227 | { | 1226 | { |
1228 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1227 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1229 | "Delegated host %u not registered with us\n", | 1228 | "Delegated host %u not registered with us\n", |
1230 | delegated_host_id); | 1229 | delegated_host_id); |
1231 | GNUNET_SERVICE_client_drop (client); | 1230 | GNUNET_SERVICE_client_drop(client); |
1232 | return; | 1231 | return; |
1233 | } | 1232 | } |
1234 | slave_host_id = ntohl (msg->slave_host_id); | 1233 | slave_host_id = ntohl(msg->slave_host_id); |
1235 | if ((slave_host_id >= GST_host_list_size) || | 1234 | if ((slave_host_id >= GST_host_list_size) || |
1236 | (NULL == GST_host_list[slave_host_id])) | 1235 | (NULL == GST_host_list[slave_host_id])) |
1237 | { | 1236 | { |
1238 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1237 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1239 | "Slave host %u not registered with us\n", | 1238 | "Slave host %u not registered with us\n", |
1240 | slave_host_id); | 1239 | slave_host_id); |
1241 | GNUNET_SERVICE_client_drop (client); | 1240 | GNUNET_SERVICE_client_drop(client); |
1242 | return; | 1241 | return; |
1243 | } | 1242 | } |
1244 | if (slave_host_id == delegated_host_id) | 1243 | if (slave_host_id == delegated_host_id) |
1245 | { | ||
1246 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1247 | "Slave and delegated host are same\n"); | ||
1248 | GNUNET_SERVICE_client_drop (client); | ||
1249 | return; | ||
1250 | } | ||
1251 | op_id = GNUNET_ntohll (msg->operation_id); | ||
1252 | if (slave_host_id == GST_context->host_id) /* Link from us */ | ||
1253 | { | ||
1254 | struct Slave *slave; | ||
1255 | struct LinkControllersContext *lcc; | ||
1256 | |||
1257 | if (1 != msg->is_subordinate) | ||
1258 | { | 1244 | { |
1259 | struct Neighbour *n; | 1245 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1260 | struct NeighbourConnectCtxt *ncc; | 1246 | "Slave and delegated host are same\n"); |
1261 | 1247 | GNUNET_SERVICE_client_drop(client); | |
1262 | if ((delegated_host_id < neighbour_list_size) && | ||
1263 | (NULL != neighbour_list[delegated_host_id])) | ||
1264 | { | ||
1265 | GNUNET_break (0); | ||
1266 | GNUNET_SERVICE_client_drop (client); | ||
1267 | return; | ||
1268 | } | ||
1269 | LOG_DEBUG ("Received request to establish a link to host %u\n", | ||
1270 | delegated_host_id); | ||
1271 | n = GST_create_neighbour (GST_host_list[delegated_host_id]); | ||
1272 | ncc = GNUNET_new (struct NeighbourConnectCtxt); | ||
1273 | ncc->n = n; | ||
1274 | ncc->op_id = op_id; | ||
1275 | ncc->client = client; | ||
1276 | ncc->nh = GST_neighbour_get_connection (n, | ||
1277 | &neighbour_connect_cb, | ||
1278 | ncc); | ||
1279 | ncc->timeout_task | ||
1280 | = GNUNET_SCHEDULER_add_delayed (GST_timeout, | ||
1281 | &timeout_neighbour_connect, | ||
1282 | ncc); | ||
1283 | GNUNET_CONTAINER_DLL_insert_tail (ncc_head, | ||
1284 | ncc_tail, | ||
1285 | ncc); | ||
1286 | GNUNET_SERVICE_client_continue (client); | ||
1287 | return; | 1248 | return; |
1288 | } | 1249 | } |
1289 | if ( (delegated_host_id < GST_slave_list_size) && | 1250 | op_id = GNUNET_ntohll(msg->operation_id); |
1290 | (NULL != GST_slave_list[delegated_host_id]) ) | 1251 | if (slave_host_id == GST_context->host_id) /* Link from us */ |
1291 | { | 1252 | { |
1292 | GNUNET_break (0); | 1253 | struct Slave *slave; |
1293 | GNUNET_SERVICE_client_drop (client); | 1254 | struct LinkControllersContext *lcc; |
1255 | |||
1256 | if (1 != msg->is_subordinate) | ||
1257 | { | ||
1258 | struct Neighbour *n; | ||
1259 | struct NeighbourConnectCtxt *ncc; | ||
1260 | |||
1261 | if ((delegated_host_id < neighbour_list_size) && | ||
1262 | (NULL != neighbour_list[delegated_host_id])) | ||
1263 | { | ||
1264 | GNUNET_break(0); | ||
1265 | GNUNET_SERVICE_client_drop(client); | ||
1266 | return; | ||
1267 | } | ||
1268 | LOG_DEBUG("Received request to establish a link to host %u\n", | ||
1269 | delegated_host_id); | ||
1270 | n = GST_create_neighbour(GST_host_list[delegated_host_id]); | ||
1271 | ncc = GNUNET_new(struct NeighbourConnectCtxt); | ||
1272 | ncc->n = n; | ||
1273 | ncc->op_id = op_id; | ||
1274 | ncc->client = client; | ||
1275 | ncc->nh = GST_neighbour_get_connection(n, | ||
1276 | &neighbour_connect_cb, | ||
1277 | ncc); | ||
1278 | ncc->timeout_task | ||
1279 | = GNUNET_SCHEDULER_add_delayed(GST_timeout, | ||
1280 | &timeout_neighbour_connect, | ||
1281 | ncc); | ||
1282 | GNUNET_CONTAINER_DLL_insert_tail(ncc_head, | ||
1283 | ncc_tail, | ||
1284 | ncc); | ||
1285 | GNUNET_SERVICE_client_continue(client); | ||
1286 | return; | ||
1287 | } | ||
1288 | if ((delegated_host_id < GST_slave_list_size) && | ||
1289 | (NULL != GST_slave_list[delegated_host_id])) | ||
1290 | { | ||
1291 | GNUNET_break(0); | ||
1292 | GNUNET_SERVICE_client_drop(client); | ||
1293 | return; | ||
1294 | } | ||
1295 | LOG_DEBUG("Received request to start and establish a link to host %u\n", | ||
1296 | delegated_host_id); | ||
1297 | slave = GNUNET_new(struct Slave); | ||
1298 | slave->host_id = delegated_host_id; | ||
1299 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create(100, | ||
1300 | GNUNET_NO); | ||
1301 | slave_list_add(slave); | ||
1302 | lcc = GNUNET_new(struct LinkControllersContext); | ||
1303 | lcc->operation_id = op_id; | ||
1304 | lcc->client = client; | ||
1305 | slave->lcc = lcc; | ||
1306 | slave->controller_proc | ||
1307 | = GNUNET_TESTBED_controller_start(GST_context->master_ip, | ||
1308 | GST_host_list[slave->host_id], | ||
1309 | &slave_status_cb, | ||
1310 | slave); | ||
1311 | new_route = GNUNET_new(struct Route); | ||
1312 | new_route->dest = delegated_host_id; | ||
1313 | new_route->thru = GST_context->host_id; | ||
1314 | route_list_add(new_route); | ||
1294 | return; | 1315 | return; |
1295 | } | 1316 | } |
1296 | LOG_DEBUG ("Received request to start and establish a link to host %u\n", | ||
1297 | delegated_host_id); | ||
1298 | slave = GNUNET_new (struct Slave); | ||
1299 | slave->host_id = delegated_host_id; | ||
1300 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, | ||
1301 | GNUNET_NO); | ||
1302 | slave_list_add (slave); | ||
1303 | lcc = GNUNET_new (struct LinkControllersContext); | ||
1304 | lcc->operation_id = op_id; | ||
1305 | lcc->client = client; | ||
1306 | slave->lcc = lcc; | ||
1307 | slave->controller_proc | ||
1308 | = GNUNET_TESTBED_controller_start (GST_context->master_ip, | ||
1309 | GST_host_list[slave->host_id], | ||
1310 | &slave_status_cb, | ||
1311 | slave); | ||
1312 | new_route = GNUNET_new (struct Route); | ||
1313 | new_route->dest = delegated_host_id; | ||
1314 | new_route->thru = GST_context->host_id; | ||
1315 | route_list_add (new_route); | ||
1316 | return; | ||
1317 | } | ||
1318 | 1317 | ||
1319 | /* Route the request */ | 1318 | /* Route the request */ |
1320 | if (slave_host_id >= route_list_size) | 1319 | if (slave_host_id >= route_list_size) |
1321 | { | 1320 | { |
1322 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1321 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1323 | "No route towards slave host"); | 1322 | "No route towards slave host"); |
1324 | GNUNET_SERVICE_client_drop (client); | 1323 | GNUNET_SERVICE_client_drop(client); |
1325 | return; | 1324 | return; |
1326 | } | 1325 | } |
1327 | lcf = GNUNET_new (struct LCFContext); | 1326 | lcf = GNUNET_new(struct LCFContext); |
1328 | lcf->delegated_host_id = delegated_host_id; | 1327 | lcf->delegated_host_id = delegated_host_id; |
1329 | lcf->slave_host_id = slave_host_id; | 1328 | lcf->slave_host_id = slave_host_id; |
1330 | route = GST_find_dest_route (slave_host_id); | 1329 | route = GST_find_dest_route(slave_host_id); |
1331 | GNUNET_assert (NULL != route); /* because we add routes carefully */ | 1330 | GNUNET_assert(NULL != route); /* because we add routes carefully */ |
1332 | GNUNET_assert (route->dest < GST_slave_list_size); | 1331 | GNUNET_assert(route->dest < GST_slave_list_size); |
1333 | GNUNET_assert (NULL != GST_slave_list[route->dest]); | 1332 | GNUNET_assert(NULL != GST_slave_list[route->dest]); |
1334 | lcf->is_subordinate = msg->is_subordinate; | 1333 | lcf->is_subordinate = msg->is_subordinate; |
1335 | lcf->state = INIT; | 1334 | lcf->state = INIT; |
1336 | lcf->operation_id = op_id; | 1335 | lcf->operation_id = op_id; |
1337 | lcf->gateway = GST_slave_list[route->dest]; | 1336 | lcf->gateway = GST_slave_list[route->dest]; |
1338 | lcf->client = client; | 1337 | lcf->client = client; |
1339 | if (NULL == lcf_head) | 1338 | if (NULL == lcf_head) |
1340 | { | 1339 | { |
1341 | GNUNET_assert (NULL == lcf_proc_task_id); | 1340 | GNUNET_assert(NULL == lcf_proc_task_id); |
1342 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, | 1341 | GNUNET_CONTAINER_DLL_insert_tail(lcf_head, |
1343 | lcf_tail, | 1342 | lcf_tail, |
1344 | lcf); | 1343 | lcf); |
1345 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 1344 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
1346 | lcf); | 1345 | lcf); |
1347 | } | 1346 | } |
1348 | else | 1347 | else |
1349 | { | 1348 | { |
1350 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, | 1349 | GNUNET_CONTAINER_DLL_insert_tail(lcf_head, |
1351 | lcf_tail, | 1350 | lcf_tail, |
1352 | lcf); | 1351 | lcf); |
1353 | } | 1352 | } |
1354 | /* FIXME: Adding a new route should happen after the controllers are linked | 1353 | /* FIXME: Adding a new route should happen after the controllers are linked |
1355 | * successfully */ | 1354 | * successfully */ |
1356 | if (1 != msg->is_subordinate) | 1355 | if (1 != msg->is_subordinate) |
1357 | { | 1356 | { |
1358 | GNUNET_SERVICE_client_continue (client); | 1357 | GNUNET_SERVICE_client_continue(client); |
1359 | return; | 1358 | return; |
1360 | } | 1359 | } |
1361 | if ( (delegated_host_id < route_list_size) && | 1360 | if ((delegated_host_id < route_list_size) && |
1362 | (NULL != route_list[delegated_host_id]) ) | 1361 | (NULL != route_list[delegated_host_id])) |
1363 | { | 1362 | { |
1364 | GNUNET_break_op (0); /* Are you trying to link delegated host twice | 1363 | GNUNET_break_op(0); /* Are you trying to link delegated host twice |
1365 | * with is subordinate flag set to GNUNET_YES? */ | 1364 | * with is subordinate flag set to GNUNET_YES? */ |
1366 | GNUNET_SERVICE_client_drop (client); | 1365 | GNUNET_SERVICE_client_drop(client); |
1367 | return; | 1366 | return; |
1368 | } | 1367 | } |
1369 | new_route = GNUNET_new (struct Route); | 1368 | new_route = GNUNET_new(struct Route); |
1370 | new_route->dest = delegated_host_id; | 1369 | new_route->dest = delegated_host_id; |
1371 | new_route->thru = route->dest; | 1370 | new_route->thru = route->dest; |
1372 | route_list_add (new_route); | 1371 | route_list_add(new_route); |
1373 | GNUNET_SERVICE_client_continue (client); | 1372 | GNUNET_SERVICE_client_continue(client); |
1374 | } | 1373 | } |
1375 | 1374 | ||
1376 | 1375 | ||
@@ -1381,7 +1380,7 @@ handle_link_controllers (void *cls, | |||
1381 | * @param client the client that is history | 1380 | * @param client the client that is history |
1382 | */ | 1381 | */ |
1383 | void | 1382 | void |
1384 | GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | 1383 | GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client) |
1385 | { | 1384 | { |
1386 | struct NeighbourConnectCtxt *ncc; | 1385 | struct NeighbourConnectCtxt *ncc; |
1387 | struct NeighbourConnectCtxt *nccn; | 1386 | struct NeighbourConnectCtxt *nccn; |
@@ -1389,44 +1388,44 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | |||
1389 | struct LCFContext *lcfn; | 1388 | struct LCFContext *lcfn; |
1390 | 1389 | ||
1391 | for (ncc = ncc_head; NULL != ncc; ncc = nccn) | 1390 | for (ncc = ncc_head; NULL != ncc; ncc = nccn) |
1392 | { | ||
1393 | nccn = ncc->next; | ||
1394 | if (ncc->client == client) | ||
1395 | cleanup_ncc (ncc); | ||
1396 | } | ||
1397 | for (unsigned int i=0;i<GST_slave_list_size;i++) | ||
1398 | { | ||
1399 | struct Slave *slave = GST_slave_list[i]; | ||
1400 | struct LinkControllersContext *lcc; | ||
1401 | |||
1402 | if (NULL == slave) | ||
1403 | continue; | ||
1404 | GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, | ||
1405 | &drop_client_entries, | ||
1406 | client); | ||
1407 | lcc = slave->lcc; | ||
1408 | if (NULL == lcc) | ||
1409 | continue; | ||
1410 | if (lcc->client == client) | ||
1411 | { | 1391 | { |
1412 | slave->lcc = NULL; | 1392 | nccn = ncc->next; |
1413 | GNUNET_free (lcc); | 1393 | if (ncc->client == client) |
1394 | cleanup_ncc(ncc); | ||
1395 | } | ||
1396 | for (unsigned int i = 0; i < GST_slave_list_size; i++) | ||
1397 | { | ||
1398 | struct Slave *slave = GST_slave_list[i]; | ||
1399 | struct LinkControllersContext *lcc; | ||
1400 | |||
1401 | if (NULL == slave) | ||
1402 | continue; | ||
1403 | GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, | ||
1404 | &drop_client_entries, | ||
1405 | client); | ||
1406 | lcc = slave->lcc; | ||
1407 | if (NULL == lcc) | ||
1408 | continue; | ||
1409 | if (lcc->client == client) | ||
1410 | { | ||
1411 | slave->lcc = NULL; | ||
1412 | GNUNET_free(lcc); | ||
1413 | } | ||
1414 | } | 1414 | } |
1415 | } | ||
1416 | for (lcf = lcf_head; NULL != lcf; lcf = lcfn) | 1415 | for (lcf = lcf_head; NULL != lcf; lcf = lcfn) |
1417 | { | ||
1418 | lcfn = lcf->next; | ||
1419 | if ( (NULL != lcf) && | ||
1420 | (client == lcf->client) ) | ||
1421 | { | 1416 | { |
1422 | if (NULL != lcf->op) | 1417 | lcfn = lcf->next; |
1423 | GNUNET_TESTBED_operation_done (lcf->op); | 1418 | if ((NULL != lcf) && |
1424 | GNUNET_CONTAINER_DLL_remove (lcf_head, | 1419 | (client == lcf->client)) |
1425 | lcf_tail, | 1420 | { |
1426 | lcf); | 1421 | if (NULL != lcf->op) |
1427 | GNUNET_free (lcf); | 1422 | GNUNET_TESTBED_operation_done(lcf->op); |
1423 | GNUNET_CONTAINER_DLL_remove(lcf_head, | ||
1424 | lcf_tail, | ||
1425 | lcf); | ||
1426 | GNUNET_free(lcf); | ||
1427 | } | ||
1428 | } | 1428 | } |
1429 | } | ||
1430 | } | 1429 | } |
1431 | 1430 | ||
1432 | 1431 | ||
@@ -1434,28 +1433,28 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | |||
1434 | * Cleans up the queue used for forwarding link controllers requests | 1433 | * Cleans up the queue used for forwarding link controllers requests |
1435 | */ | 1434 | */ |
1436 | void | 1435 | void |
1437 | GST_free_lcf () | 1436 | GST_free_lcf() |
1438 | { | 1437 | { |
1439 | struct LCFContext *lcf; | 1438 | struct LCFContext *lcf; |
1440 | 1439 | ||
1441 | if (NULL != lcf_head) | 1440 | if (NULL != lcf_head) |
1442 | { | ||
1443 | if (NULL != lcf_proc_task_id) | ||
1444 | { | 1441 | { |
1445 | GNUNET_SCHEDULER_cancel (lcf_proc_task_id); | 1442 | if (NULL != lcf_proc_task_id) |
1446 | lcf_proc_task_id = NULL; | 1443 | { |
1444 | GNUNET_SCHEDULER_cancel(lcf_proc_task_id); | ||
1445 | lcf_proc_task_id = NULL; | ||
1446 | } | ||
1447 | } | 1447 | } |
1448 | } | 1448 | GNUNET_assert(NULL == lcf_proc_task_id); |
1449 | GNUNET_assert (NULL == lcf_proc_task_id); | ||
1450 | for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) | 1449 | for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) |
1451 | { | 1450 | { |
1452 | if (NULL != lcf->op) | 1451 | if (NULL != lcf->op) |
1453 | GNUNET_TESTBED_operation_done (lcf->op); | 1452 | GNUNET_TESTBED_operation_done(lcf->op); |
1454 | if (NULL != lcf->timeout_task) | 1453 | if (NULL != lcf->timeout_task) |
1455 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 1454 | GNUNET_SCHEDULER_cancel(lcf->timeout_task); |
1456 | GNUNET_CONTAINER_DLL_remove (lcf_head, | 1455 | GNUNET_CONTAINER_DLL_remove(lcf_head, |
1457 | lcf_tail, | 1456 | lcf_tail, |
1458 | lcf); | 1457 | lcf); |
1459 | GNUNET_free (lcf); | 1458 | GNUNET_free(lcf); |
1460 | } | 1459 | } |
1461 | } | 1460 | } |