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