diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
commit | 93085e8a2991fde229400b588a5930e9fcca0d75 (patch) | |
tree | 0384246adbd96fa0138a46ad5fecb777aa40e789 /src/testbed/gnunet-service-testbed_links.c | |
parent | 2bf962c76bb82c1f38acea42c7bdfb241e2582e7 (diff) | |
download | gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.tar.gz gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.zip |
migrating testbed to new service API
Diffstat (limited to 'src/testbed/gnunet-service-testbed_links.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_links.c | 380 |
1 files changed, 237 insertions, 143 deletions
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index b922a8da8..3447a3f34 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c | |||
@@ -75,6 +75,16 @@ enum LCFContextState | |||
75 | struct LCFContext | 75 | struct LCFContext |
76 | { | 76 | { |
77 | /** | 77 | /** |
78 | * The LCFContext | ||
79 | */ | ||
80 | struct LCFContext *next; | ||
81 | |||
82 | /** | ||
83 | * The LCFContext | ||
84 | */ | ||
85 | struct LCFContext *prev; | ||
86 | |||
87 | /** | ||
78 | * The gateway which will pass the link message to delegated host | 88 | * The gateway which will pass the link message to delegated host |
79 | */ | 89 | */ |
80 | struct Slave *gateway; | 90 | struct Slave *gateway; |
@@ -82,7 +92,7 @@ struct LCFContext | |||
82 | /** | 92 | /** |
83 | * The client which has asked to perform this operation | 93 | * The client which has asked to perform this operation |
84 | */ | 94 | */ |
85 | struct GNUNET_SERVER_Client *client; | 95 | struct GNUNET_SERVICE_Client *client; |
86 | 96 | ||
87 | /** | 97 | /** |
88 | * Handle for operations which are forwarded while linking controllers | 98 | * Handle for operations which are forwarded while linking controllers |
@@ -92,7 +102,7 @@ struct LCFContext | |||
92 | /** | 102 | /** |
93 | * The timeout task | 103 | * The timeout task |
94 | */ | 104 | */ |
95 | struct GNUNET_SCHEDULER_Task * timeout_task; | 105 | struct GNUNET_SCHEDULER_Task *timeout_task; |
96 | 106 | ||
97 | /** | 107 | /** |
98 | * The id of the operation which created this context | 108 | * The id of the operation which created this context |
@@ -123,28 +133,6 @@ struct LCFContext | |||
123 | 133 | ||
124 | 134 | ||
125 | /** | 135 | /** |
126 | * Structure of a queue entry in LCFContext request queue | ||
127 | */ | ||
128 | struct LCFContextQueue | ||
129 | { | ||
130 | /** | ||
131 | * The LCFContext | ||
132 | */ | ||
133 | struct LCFContext *lcf; | ||
134 | |||
135 | /** | ||
136 | * Head prt for DLL | ||
137 | */ | ||
138 | struct LCFContextQueue *next; | ||
139 | |||
140 | /** | ||
141 | * Tail ptr for DLL | ||
142 | */ | ||
143 | struct LCFContextQueue *prev; | ||
144 | }; | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Notification context to be used to notify when connection to the neighbour's | 136 | * Notification context to be used to notify when connection to the neighbour's |
149 | * controller is opened | 137 | * controller is opened |
150 | */ | 138 | */ |
@@ -260,12 +248,12 @@ struct NeighbourConnectCtxt | |||
260 | /** | 248 | /** |
261 | * The client requesting the connection | 249 | * The client requesting the connection |
262 | */ | 250 | */ |
263 | struct GNUNET_SERVER_Client *client; | 251 | struct GNUNET_SERVICE_Client *client; |
264 | 252 | ||
265 | /** | 253 | /** |
266 | * Task to be run upon timeout | 254 | * Task to be run upon timeout |
267 | */ | 255 | */ |
268 | struct GNUNET_SCHEDULER_Task * timeout_task; | 256 | struct GNUNET_SCHEDULER_Task *timeout_task; |
269 | 257 | ||
270 | /** | 258 | /** |
271 | * The notification handle associated with the neighbour's connection request | 259 | * The notification handle associated with the neighbour's connection request |
@@ -305,14 +293,14 @@ unsigned int GST_slave_list_size; | |||
305 | static struct Route **route_list; | 293 | static struct Route **route_list; |
306 | 294 | ||
307 | /** | 295 | /** |
308 | * The head for the LCF queue | 296 | * The LCF queue |
309 | */ | 297 | */ |
310 | static struct LCFContextQueue *lcfq_head; | 298 | static struct LCFContext *lcf_head; |
311 | 299 | ||
312 | /** | 300 | /** |
313 | * The tail for the LCF queue | 301 | * The tail for the LCF queue |
314 | */ | 302 | */ |
315 | static struct LCFContextQueue *lcfq_tail; | 303 | static struct LCFContext *lcf_tail; |
316 | 304 | ||
317 | /** | 305 | /** |
318 | * The lcf_task handle | 306 | * The lcf_task handle |
@@ -334,7 +322,8 @@ static void | |||
334 | slave_list_add (struct Slave *slave) | 322 | slave_list_add (struct Slave *slave) |
335 | { | 323 | { |
336 | if (slave->host_id >= GST_slave_list_size) | 324 | if (slave->host_id >= GST_slave_list_size) |
337 | GST_array_grow_large_enough (GST_slave_list, GST_slave_list_size, | 325 | GST_array_grow_large_enough (GST_slave_list, |
326 | GST_slave_list_size, | ||
338 | slave->host_id); | 327 | slave->host_id); |
339 | GNUNET_assert (NULL == GST_slave_list[slave->host_id]); | 328 | GNUNET_assert (NULL == GST_slave_list[slave->host_id]); |
340 | GST_slave_list[slave->host_id] = slave; | 329 | GST_slave_list[slave->host_id] = slave; |
@@ -342,6 +331,35 @@ slave_list_add (struct Slave *slave) | |||
342 | 331 | ||
343 | 332 | ||
344 | /** | 333 | /** |
334 | * Clean up all forwarded operation overlay context matching the | ||
335 | * client given in @a cls. | ||
336 | * | ||
337 | * @param cls a `struct GNUNET_SERVICE_Client *` to match | ||
338 | * @param key unused | ||
339 | * @param value the `struct RegisteredHostContext` to search for @a cls | ||
340 | * @return #GNUNET_OK (continue iterating) | ||
341 | */ | ||
342 | static int | ||
343 | drop_client_entries (void *cls, | ||
344 | const struct GNUNET_HashCode *key, | ||
345 | void *value) | ||
346 | { | ||
347 | struct GNUNET_SERVICE_Client *client = cls; | ||
348 | struct RegisteredHostContext *rhc = value; | ||
349 | struct ForwardedOverlayConnectContext *focc; | ||
350 | struct ForwardedOverlayConnectContext *foccn; | ||
351 | |||
352 | for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) | ||
353 | { | ||
354 | foccn = focc->next; | ||
355 | if (focc->client == client) | ||
356 | GST_cleanup_focc (focc); | ||
357 | } | ||
358 | return GNUNET_OK; | ||
359 | } | ||
360 | |||
361 | |||
362 | /** | ||
345 | * Adds a route to the route list | 363 | * Adds a route to the route list |
346 | * | 364 | * |
347 | * @param route the route to add | 365 | * @param route the route to add |
@@ -394,12 +412,12 @@ GST_route_list_clear () | |||
394 | * @param cls handle to the slave | 412 | * @param cls handle to the slave |
395 | * @param key current key code | 413 | * @param key current key code |
396 | * @param value value in the hash map | 414 | * @param value value in the hash map |
397 | * @return GNUNET_YES if we should continue to | 415 | * @return #GNUNET_YES if we should continue to iterate, |
398 | * iterate, | 416 | * #GNUNET_NO if not. |
399 | * GNUNET_NO if not. | ||
400 | */ | 417 | */ |
401 | static int | 418 | static int |
402 | reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key, | 419 | reghost_free_iterator (void *cls, |
420 | const struct GNUNET_HashCode *key, | ||
403 | void *value) | 421 | void *value) |
404 | { | 422 | { |
405 | struct Slave *slave = cls; | 423 | struct Slave *slave = cls; |
@@ -410,10 +428,7 @@ reghost_free_iterator (void *cls, const struct GNUNET_HashCode *key, | |||
410 | GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key, | 428 | GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key, |
411 | value)); | 429 | value)); |
412 | while (NULL != (focc = rhc->focc_dll_head)) | 430 | while (NULL != (focc = rhc->focc_dll_head)) |
413 | { | ||
414 | GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc); | ||
415 | GST_cleanup_focc (focc); | 431 | GST_cleanup_focc (focc); |
416 | } | ||
417 | GNUNET_free (value); | 432 | GNUNET_free (value); |
418 | return GNUNET_YES; | 433 | return GNUNET_YES; |
419 | } | 434 | } |
@@ -536,12 +551,12 @@ GST_find_dest_route (uint32_t host_id) | |||
536 | * NULL if cfg is set! | 551 | * NULL if cfg is set! |
537 | */ | 552 | */ |
538 | static void | 553 | static void |
539 | send_controller_link_response (struct GNUNET_SERVER_Client *client, | 554 | send_controller_link_response (struct GNUNET_SERVICE_Client *client, |
540 | uint64_t operation_id, | 555 | uint64_t operation_id, |
541 | const struct GNUNET_CONFIGURATION_Handle | 556 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
542 | *cfg, | ||
543 | const char *emsg) | 557 | const char *emsg) |
544 | { | 558 | { |
559 | struct GNUNET_MQ_Envelope *env; | ||
545 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; | 560 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; |
546 | char *xconfig; | 561 | char *xconfig; |
547 | size_t config_size; | 562 | size_t config_size; |
@@ -552,7 +567,7 @@ send_controller_link_response (struct GNUNET_SERVER_Client *client, | |||
552 | xconfig = NULL; | 567 | xconfig = NULL; |
553 | xconfig_size = 0; | 568 | xconfig_size = 0; |
554 | config_size = 0; | 569 | config_size = 0; |
555 | msize = sizeof (struct GNUNET_TESTBED_ControllerLinkResponse); | 570 | msize = 0; |
556 | if (NULL != cfg) | 571 | if (NULL != cfg) |
557 | { | 572 | { |
558 | xconfig = GNUNET_TESTBED_compress_cfg_ (cfg, | 573 | xconfig = GNUNET_TESTBED_compress_cfg_ (cfg, |
@@ -562,22 +577,26 @@ send_controller_link_response (struct GNUNET_SERVER_Client *client, | |||
562 | } | 577 | } |
563 | if (NULL != emsg) | 578 | if (NULL != emsg) |
564 | msize += strlen (emsg); | 579 | msize += strlen (emsg); |
565 | msg = GNUNET_malloc (msize); | 580 | env = GNUNET_MQ_msg_extra (msg, |
566 | msg->header.type = htons | 581 | msize, |
567 | (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); | 582 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); |
568 | msg->header.size = htons (msize); | ||
569 | if (NULL == emsg) | 583 | if (NULL == emsg) |
570 | msg->success = htons (GNUNET_YES); | 584 | msg->success = htons (GNUNET_YES); |
571 | msg->operation_id = GNUNET_htonll (operation_id); | 585 | msg->operation_id = GNUNET_htonll (operation_id); |
572 | msg->config_size = htons ((uint16_t) config_size); | 586 | msg->config_size = htons ((uint16_t) config_size); |
573 | if (NULL != xconfig) | 587 | if (NULL != xconfig) |
574 | { | 588 | { |
575 | GNUNET_memcpy (&msg[1], xconfig, xconfig_size); | 589 | GNUNET_memcpy (&msg[1], |
590 | xconfig, | ||
591 | xconfig_size); | ||
576 | GNUNET_free (xconfig); | 592 | GNUNET_free (xconfig); |
577 | } | 593 | } |
578 | if (NULL != emsg) | 594 | if (NULL != emsg) |
579 | GNUNET_memcpy (&msg[1], emsg, strlen (emsg)); | 595 | GNUNET_memcpy (&msg[1], |
580 | GST_queue_message (client, &msg->header); | 596 | emsg, |
597 | strlen (emsg)); | ||
598 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
599 | env); | ||
581 | } | 600 | } |
582 | 601 | ||
583 | 602 | ||
@@ -597,7 +616,8 @@ lcf_proc_task (void *cls); | |||
597 | * @param emsg the error message; NULL if host registration is successful | 616 | * @param emsg the error message; NULL if host registration is successful |
598 | */ | 617 | */ |
599 | static void | 618 | static void |
600 | lcf_proc_cc (void *cls, const char *emsg) | 619 | lcf_proc_cc (void *cls, |
620 | const char *emsg) | ||
601 | { | 621 | { |
602 | struct LCFContext *lcf = cls; | 622 | struct LCFContext *lcf = cls; |
603 | 623 | ||
@@ -622,10 +642,12 @@ lcf_proc_cc (void *cls, const char *emsg) | |||
622 | return; | 642 | return; |
623 | 643 | ||
624 | registration_error: | 644 | registration_error: |
625 | LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n", | 645 | LOG (GNUNET_ERROR_TYPE_WARNING, |
646 | "Host registration failed with message: %s\n", | ||
626 | emsg); | 647 | emsg); |
627 | lcf->state = FINISHED; | 648 | lcf->state = FINISHED; |
628 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 649 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, |
650 | lcf); | ||
629 | } | 651 | } |
630 | 652 | ||
631 | 653 | ||
@@ -652,11 +674,13 @@ lcf_forwarded_operation_timeout (void *cls) | |||
652 | // GST_forwarded_operation_timeout (lcf->fopc, tc); | 674 | // GST_forwarded_operation_timeout (lcf->fopc, tc); |
653 | LOG (GNUNET_ERROR_TYPE_WARNING, | 675 | LOG (GNUNET_ERROR_TYPE_WARNING, |
654 | "A forwarded controller link operation has timed out\n"); | 676 | "A forwarded controller link operation has timed out\n"); |
655 | send_controller_link_response (lcf->client, lcf->operation_id, NULL, | 677 | send_controller_link_response (lcf->client, |
656 | "A forwarded controller link operation has " | 678 | lcf->operation_id, |
657 | "timed out\n"); | 679 | NULL, |
680 | "A forwarded controller link operation has timed out\n"); | ||
658 | GNUNET_assert (NULL == lcf_proc_task_id); | 681 | GNUNET_assert (NULL == lcf_proc_task_id); |
659 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 682 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, |
683 | lcf); | ||
660 | } | 684 | } |
661 | 685 | ||
662 | 686 | ||
@@ -669,7 +693,6 @@ static void | |||
669 | lcf_proc_task (void *cls) | 693 | lcf_proc_task (void *cls) |
670 | { | 694 | { |
671 | struct LCFContext *lcf = cls; | 695 | struct LCFContext *lcf = cls; |
672 | struct LCFContextQueue *lcfq; | ||
673 | 696 | ||
674 | lcf_proc_task_id = NULL; | 697 | lcf_proc_task_id = NULL; |
675 | switch (lcf->state) | 698 | switch (lcf->state) |
@@ -710,22 +733,21 @@ lcf_proc_task (void *cls) | |||
710 | GST_host_list[lcf->slave_host_id], | 733 | GST_host_list[lcf->slave_host_id], |
711 | lcf->is_subordinate); | 734 | lcf->is_subordinate); |
712 | lcf->timeout_task = | 735 | lcf->timeout_task = |
713 | GNUNET_SCHEDULER_add_delayed (GST_timeout, &lcf_forwarded_operation_timeout, | 736 | GNUNET_SCHEDULER_add_delayed (GST_timeout, |
737 | &lcf_forwarded_operation_timeout, | ||
714 | lcf); | 738 | lcf); |
715 | lcf->state = FINISHED; | 739 | lcf->state = FINISHED; |
716 | break; | 740 | break; |
717 | case FINISHED: | 741 | case FINISHED: |
718 | lcfq = lcfq_head; | ||
719 | GNUNET_assert (lcfq->lcf == lcf); | ||
720 | GNUNET_SERVER_client_drop (lcf->client); | ||
721 | if (NULL != lcf->op) | 742 | if (NULL != lcf->op) |
722 | GNUNET_TESTBED_operation_done (lcf->op); | 743 | GNUNET_TESTBED_operation_done (lcf->op); |
744 | GNUNET_CONTAINER_DLL_remove (lcf_head, | ||
745 | lcf_tail, | ||
746 | lcf); | ||
723 | GNUNET_free (lcf); | 747 | GNUNET_free (lcf); |
724 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); | 748 | if (NULL != lcf_head) |
725 | GNUNET_free (lcfq); | 749 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, |
726 | if (NULL != lcfq_head) | 750 | lcf_head); |
727 | lcf_proc_task_id = | ||
728 | GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf); | ||
729 | } | 751 | } |
730 | } | 752 | } |
731 | 753 | ||
@@ -770,12 +792,13 @@ slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
770 | * | 792 | * |
771 | * @param cls the handle to the slave whose status is to be found here | 793 | * @param cls the handle to the slave whose status is to be found here |
772 | * @param cfg the configuration with which the controller has been started; | 794 | * @param cfg the configuration with which the controller has been started; |
773 | * NULL if status is not GNUNET_OK | 795 | * NULL if status is not #GNUNET_OK |
774 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | 796 | * @param status #GNUNET_OK if the startup is successfull; #GNUNET_SYSERR if not, |
775 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 797 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
776 | */ | 798 | */ |
777 | static void | 799 | static void |
778 | slave_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 800 | slave_status_cb (void *cls, |
801 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
779 | int status) | 802 | int status) |
780 | { | 803 | { |
781 | struct Slave *slave = cls; | 804 | struct Slave *slave = cls; |
@@ -789,7 +812,7 @@ slave_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
789 | and as these tasks they depend on the operation queues which are created | 812 | and as these tasks they depend on the operation queues which are created |
790 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call | 813 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call |
791 | the destructor function GNUNET_TESTBED_controller_disconnect() */ | 814 | the destructor function GNUNET_TESTBED_controller_disconnect() */ |
792 | GST_free_lcfq (); | 815 | GST_free_lcf (); |
793 | kill_slave (slave); | 816 | kill_slave (slave); |
794 | destroy_slave (slave); | 817 | destroy_slave (slave); |
795 | slave = NULL; | 818 | slave = NULL; |
@@ -819,8 +842,7 @@ slave_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
819 | { | 842 | { |
820 | if (NULL != lcc->client) | 843 | if (NULL != lcc->client) |
821 | { | 844 | { |
822 | GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK); | 845 | GNUNET_SERVICE_client_continue (lcc->client); |
823 | GNUNET_SERVER_client_drop (lcc->client); | ||
824 | lcc->client = NULL; | 846 | lcc->client = NULL; |
825 | } | 847 | } |
826 | GNUNET_free (lcc); | 848 | GNUNET_free (lcc); |
@@ -1051,8 +1073,9 @@ cleanup_ncc (struct NeighbourConnectCtxt *ncc) | |||
1051 | GST_neighbour_get_connection_cancel (ncc->nh); | 1073 | GST_neighbour_get_connection_cancel (ncc->nh); |
1052 | if (NULL != ncc->timeout_task) | 1074 | if (NULL != ncc->timeout_task) |
1053 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); | 1075 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); |
1054 | GNUNET_SERVER_client_drop (ncc->client); | 1076 | GNUNET_CONTAINER_DLL_remove (ncc_head, |
1055 | GNUNET_CONTAINER_DLL_remove (ncc_head, ncc_tail, ncc); | 1077 | ncc_tail, |
1078 | ncc); | ||
1056 | GNUNET_free (ncc); | 1079 | GNUNET_free (ncc); |
1057 | } | 1080 | } |
1058 | 1081 | ||
@@ -1061,7 +1084,7 @@ cleanup_ncc (struct NeighbourConnectCtxt *ncc) | |||
1061 | * Cleans up the neighbour list | 1084 | * Cleans up the neighbour list |
1062 | */ | 1085 | */ |
1063 | void | 1086 | void |
1064 | GST_neighbour_list_clean() | 1087 | GST_neighbour_list_clean () |
1065 | { | 1088 | { |
1066 | struct Neighbour *n; | 1089 | struct Neighbour *n; |
1067 | unsigned int id; | 1090 | unsigned int id; |
@@ -1091,8 +1114,7 @@ GST_get_neighbour (uint32_t id) | |||
1091 | { | 1114 | { |
1092 | if (neighbour_list_size <= id) | 1115 | if (neighbour_list_size <= id) |
1093 | return NULL; | 1116 | return NULL; |
1094 | else | 1117 | return neighbour_list[id]; |
1095 | return neighbour_list[id]; | ||
1096 | } | 1118 | } |
1097 | 1119 | ||
1098 | 1120 | ||
@@ -1118,7 +1140,9 @@ timeout_neighbour_connect (void *cls) | |||
1118 | struct NeighbourConnectCtxt *ncc = cls; | 1140 | struct NeighbourConnectCtxt *ncc = cls; |
1119 | 1141 | ||
1120 | ncc->timeout_task = NULL; | 1142 | ncc->timeout_task = NULL; |
1121 | send_controller_link_response (ncc->client, ncc->op_id, NULL, | 1143 | send_controller_link_response (ncc->client, |
1144 | ncc->op_id, | ||
1145 | NULL, | ||
1122 | "Could not connect to delegated controller"); | 1146 | "Could not connect to delegated controller"); |
1123 | cleanup_ncc (ncc); | 1147 | cleanup_ncc (ncc); |
1124 | } | 1148 | } |
@@ -1131,7 +1155,8 @@ timeout_neighbour_connect (void *cls) | |||
1131 | * @param c the handle the neighbour's controller | 1155 | * @param c the handle the neighbour's controller |
1132 | */ | 1156 | */ |
1133 | static void | 1157 | static void |
1134 | neighbour_connect_cb (void *cls, struct GNUNET_TESTBED_Controller *c) | 1158 | neighbour_connect_cb (void *cls, |
1159 | struct GNUNET_TESTBED_Controller *c) | ||
1135 | { | 1160 | { |
1136 | struct NeighbourConnectCtxt *ncc = cls; | 1161 | struct NeighbourConnectCtxt *ncc = cls; |
1137 | 1162 | ||
@@ -1139,7 +1164,10 @@ neighbour_connect_cb (void *cls, struct GNUNET_TESTBED_Controller *c) | |||
1139 | ncc->timeout_task = NULL; | 1164 | ncc->timeout_task = NULL; |
1140 | ncc->nh = NULL; | 1165 | ncc->nh = NULL; |
1141 | GST_neighbour_release_connection (ncc->n); | 1166 | GST_neighbour_release_connection (ncc->n); |
1142 | send_controller_link_response (ncc->client, ncc->op_id, NULL, NULL); | 1167 | send_controller_link_response (ncc->client, |
1168 | ncc->op_id, | ||
1169 | NULL, | ||
1170 | NULL); | ||
1143 | cleanup_ncc (ncc); | 1171 | cleanup_ncc (ncc); |
1144 | } | 1172 | } |
1145 | 1173 | ||
@@ -1162,18 +1190,17 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host) | |||
1162 | 1190 | ||
1163 | 1191 | ||
1164 | /** | 1192 | /** |
1165 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message | 1193 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message |
1166 | * | 1194 | * |
1167 | * @param cls NULL | 1195 | * @param cls identification of the client |
1168 | * @param client identification of the client | 1196 | * @param msg the actual message |
1169 | * @param message the actual message | ||
1170 | */ | 1197 | */ |
1171 | void | 1198 | void |
1172 | GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | 1199 | handle_link_controllers (void *cls, |
1173 | const struct GNUNET_MessageHeader *message) | 1200 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg) |
1174 | { | 1201 | { |
1175 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg; | 1202 | struct GNUNET_SERVICE_Client *client = cls; |
1176 | struct LCFContextQueue *lcfq; | 1203 | struct LCFContext *lcf; |
1177 | struct Route *route; | 1204 | struct Route *route; |
1178 | struct Route *new_route; | 1205 | struct Route *new_route; |
1179 | uint64_t op_id; | 1206 | uint64_t op_id; |
@@ -1183,39 +1210,42 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1183 | if (NULL == GST_context) | 1210 | if (NULL == GST_context) |
1184 | { | 1211 | { |
1185 | GNUNET_break (0); | 1212 | GNUNET_break (0); |
1186 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1213 | GNUNET_SERVICE_client_drop (client); |
1187 | return; | 1214 | return; |
1188 | } | 1215 | } |
1189 | msg = (const struct GNUNET_TESTBED_ControllerLinkRequest *) message; | ||
1190 | delegated_host_id = ntohl (msg->delegated_host_id); | 1216 | delegated_host_id = ntohl (msg->delegated_host_id); |
1191 | if (delegated_host_id == GST_context->host_id) | 1217 | if (delegated_host_id == GST_context->host_id) |
1192 | { | 1218 | { |
1193 | GNUNET_break (0); | 1219 | GNUNET_break (0); |
1194 | LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n"); | 1220 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1195 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1221 | "Trying to link ourselves\n"); |
1222 | GNUNET_SERVICE_client_drop (client); | ||
1196 | return; | 1223 | return; |
1197 | } | 1224 | } |
1198 | if ((delegated_host_id >= GST_host_list_size) || | 1225 | if ((delegated_host_id >= GST_host_list_size) || |
1199 | (NULL == GST_host_list[delegated_host_id])) | 1226 | (NULL == GST_host_list[delegated_host_id])) |
1200 | { | 1227 | { |
1201 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1228 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1202 | "Delegated host %u not registered with us\n", delegated_host_id); | 1229 | "Delegated host %u not registered with us\n", |
1203 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1230 | delegated_host_id); |
1231 | GNUNET_SERVICE_client_drop (client); | ||
1204 | return; | 1232 | return; |
1205 | } | 1233 | } |
1206 | slave_host_id = ntohl (msg->slave_host_id); | 1234 | slave_host_id = ntohl (msg->slave_host_id); |
1207 | if ((slave_host_id >= GST_host_list_size) || | 1235 | if ((slave_host_id >= GST_host_list_size) || |
1208 | (NULL == GST_host_list[slave_host_id])) | 1236 | (NULL == GST_host_list[slave_host_id])) |
1209 | { | 1237 | { |
1210 | LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n", | 1238 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1239 | "Slave host %u not registered with us\n", | ||
1211 | slave_host_id); | 1240 | slave_host_id); |
1212 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1241 | GNUNET_SERVICE_client_drop (client); |
1213 | return; | 1242 | return; |
1214 | } | 1243 | } |
1215 | if (slave_host_id == delegated_host_id) | 1244 | if (slave_host_id == delegated_host_id) |
1216 | { | 1245 | { |
1217 | LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n"); | 1246 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1218 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1247 | "Slave and delegated host are same\n"); |
1248 | GNUNET_SERVICE_client_drop (client); | ||
1219 | return; | 1249 | return; |
1220 | } | 1250 | } |
1221 | op_id = GNUNET_ntohll (msg->operation_id); | 1251 | op_id = GNUNET_ntohll (msg->operation_id); |
@@ -1224,7 +1254,6 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1224 | struct Slave *slave; | 1254 | struct Slave *slave; |
1225 | struct LinkControllersContext *lcc; | 1255 | struct LinkControllersContext *lcc; |
1226 | 1256 | ||
1227 | |||
1228 | if (1 != msg->is_subordinate) | 1257 | if (1 != msg->is_subordinate) |
1229 | { | 1258 | { |
1230 | struct Neighbour *n; | 1259 | struct Neighbour *n; |
@@ -1234,7 +1263,7 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1234 | (NULL != neighbour_list[delegated_host_id])) | 1263 | (NULL != neighbour_list[delegated_host_id])) |
1235 | { | 1264 | { |
1236 | GNUNET_break (0); | 1265 | GNUNET_break (0); |
1237 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1266 | GNUNET_SERVICE_client_drop (client); |
1238 | return; | 1267 | return; |
1239 | } | 1268 | } |
1240 | LOG_DEBUG ("Received request to establish a link to host %u\n", | 1269 | LOG_DEBUG ("Received request to establish a link to host %u\n", |
@@ -1244,37 +1273,42 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1244 | ncc->n = n; | 1273 | ncc->n = n; |
1245 | ncc->op_id = op_id; | 1274 | ncc->op_id = op_id; |
1246 | ncc->client = client; | 1275 | ncc->client = client; |
1247 | GNUNET_SERVER_client_keep (client); | 1276 | ncc->nh = GST_neighbour_get_connection (n, |
1248 | ncc->nh = GST_neighbour_get_connection (n, neighbour_connect_cb, ncc); | 1277 | &neighbour_connect_cb, |
1249 | ncc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1278 | ncc); |
1250 | &timeout_neighbour_connect, | 1279 | ncc->timeout_task |
1251 | ncc); | 1280 | = GNUNET_SCHEDULER_add_delayed (GST_timeout, |
1252 | GNUNET_CONTAINER_DLL_insert_tail (ncc_head, ncc_tail, ncc); | 1281 | &timeout_neighbour_connect, |
1253 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1282 | ncc); |
1283 | GNUNET_CONTAINER_DLL_insert_tail (ncc_head, | ||
1284 | ncc_tail, | ||
1285 | ncc); | ||
1286 | GNUNET_SERVICE_client_continue (client); | ||
1254 | return; | 1287 | return; |
1255 | } | 1288 | } |
1256 | if ((delegated_host_id < GST_slave_list_size) && | 1289 | if ( (delegated_host_id < GST_slave_list_size) && |
1257 | (NULL != GST_slave_list[delegated_host_id])) | 1290 | (NULL != GST_slave_list[delegated_host_id]) ) |
1258 | { | 1291 | { |
1259 | GNUNET_break (0); | 1292 | GNUNET_break (0); |
1260 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1293 | GNUNET_SERVICE_client_drop (client); |
1261 | return; | 1294 | return; |
1262 | } | 1295 | } |
1263 | LOG_DEBUG ("Received request to start and establish a link to host %u\n", | 1296 | LOG_DEBUG ("Received request to start and establish a link to host %u\n", |
1264 | delegated_host_id); | 1297 | delegated_host_id); |
1265 | slave = GNUNET_new (struct Slave); | 1298 | slave = GNUNET_new (struct Slave); |
1266 | slave->host_id = delegated_host_id; | 1299 | slave->host_id = delegated_host_id; |
1267 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO); | 1300 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, |
1301 | GNUNET_NO); | ||
1268 | slave_list_add (slave); | 1302 | slave_list_add (slave); |
1269 | lcc = GNUNET_new (struct LinkControllersContext); | 1303 | lcc = GNUNET_new (struct LinkControllersContext); |
1270 | lcc->operation_id = op_id; | 1304 | lcc->operation_id = op_id; |
1271 | GNUNET_SERVER_client_keep (client); | ||
1272 | lcc->client = client; | 1305 | lcc->client = client; |
1273 | slave->lcc = lcc; | 1306 | slave->lcc = lcc; |
1274 | slave->controller_proc = | 1307 | slave->controller_proc |
1275 | GNUNET_TESTBED_controller_start (GST_context->master_ip, | 1308 | = GNUNET_TESTBED_controller_start (GST_context->master_ip, |
1276 | GST_host_list[slave->host_id], | 1309 | GST_host_list[slave->host_id], |
1277 | &slave_status_cb, slave); | 1310 | &slave_status_cb, |
1311 | slave); | ||
1278 | new_route = GNUNET_new (struct Route); | 1312 | new_route = GNUNET_new (struct Route); |
1279 | new_route->dest = delegated_host_id; | 1313 | new_route->dest = delegated_host_id; |
1280 | new_route->thru = GST_context->host_id; | 1314 | new_route->thru = GST_context->host_id; |
@@ -1285,52 +1319,114 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1285 | /* Route the request */ | 1319 | /* Route the request */ |
1286 | if (slave_host_id >= route_list_size) | 1320 | if (slave_host_id >= route_list_size) |
1287 | { | 1321 | { |
1288 | LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host"); | 1322 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1289 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1323 | "No route towards slave host"); |
1324 | GNUNET_SERVICE_client_drop (client); | ||
1290 | return; | 1325 | return; |
1291 | } | 1326 | } |
1292 | lcfq = GNUNET_new (struct LCFContextQueue); | 1327 | lcf = GNUNET_new (struct LCFContext); |
1293 | lcfq->lcf = GNUNET_new (struct LCFContext); | 1328 | lcf->delegated_host_id = delegated_host_id; |
1294 | lcfq->lcf->delegated_host_id = delegated_host_id; | 1329 | lcf->slave_host_id = slave_host_id; |
1295 | lcfq->lcf->slave_host_id = slave_host_id; | ||
1296 | route = GST_find_dest_route (slave_host_id); | 1330 | route = GST_find_dest_route (slave_host_id); |
1297 | GNUNET_assert (NULL != route); /* because we add routes carefully */ | 1331 | GNUNET_assert (NULL != route); /* because we add routes carefully */ |
1298 | GNUNET_assert (route->dest < GST_slave_list_size); | 1332 | GNUNET_assert (route->dest < GST_slave_list_size); |
1299 | GNUNET_assert (NULL != GST_slave_list[route->dest]); | 1333 | GNUNET_assert (NULL != GST_slave_list[route->dest]); |
1300 | lcfq->lcf->is_subordinate = msg->is_subordinate; | 1334 | lcf->is_subordinate = msg->is_subordinate; |
1301 | lcfq->lcf->state = INIT; | 1335 | lcf->state = INIT; |
1302 | lcfq->lcf->operation_id = op_id; | 1336 | lcf->operation_id = op_id; |
1303 | lcfq->lcf->gateway = GST_slave_list[route->dest]; | 1337 | lcf->gateway = GST_slave_list[route->dest]; |
1304 | GNUNET_SERVER_client_keep (client); | 1338 | lcf->client = client; |
1305 | lcfq->lcf->client = client; | 1339 | if (NULL == lcf_head) |
1306 | if (NULL == lcfq_head) | ||
1307 | { | 1340 | { |
1308 | GNUNET_assert (NULL == lcf_proc_task_id); | 1341 | GNUNET_assert (NULL == lcf_proc_task_id); |
1309 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); | 1342 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, |
1310 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf); | 1343 | lcf_tail, |
1344 | lcf); | ||
1345 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | ||
1346 | lcf); | ||
1311 | } | 1347 | } |
1312 | else | 1348 | else |
1313 | GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq); | 1349 | { |
1350 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, | ||
1351 | lcf_tail, | ||
1352 | lcf); | ||
1353 | } | ||
1314 | /* FIXME: Adding a new route should happen after the controllers are linked | 1354 | /* FIXME: Adding a new route should happen after the controllers are linked |
1315 | * successfully */ | 1355 | * successfully */ |
1316 | if (1 != msg->is_subordinate) | 1356 | if (1 != msg->is_subordinate) |
1317 | { | 1357 | { |
1318 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1358 | GNUNET_SERVICE_client_continue (client); |
1319 | return; | 1359 | return; |
1320 | } | 1360 | } |
1321 | if ((delegated_host_id < route_list_size) && | 1361 | if ( (delegated_host_id < route_list_size) && |
1322 | (NULL != route_list[delegated_host_id])) | 1362 | (NULL != route_list[delegated_host_id]) ) |
1323 | { | 1363 | { |
1324 | GNUNET_break_op (0); /* Are you trying to link delegated host twice | 1364 | GNUNET_break_op (0); /* Are you trying to link delegated host twice |
1325 | * with is subordinate flag set to GNUNET_YES? */ | 1365 | * with is subordinate flag set to GNUNET_YES? */ |
1326 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1366 | GNUNET_SERVICE_client_drop (client); |
1327 | return; | 1367 | return; |
1328 | } | 1368 | } |
1329 | new_route = GNUNET_new (struct Route); | 1369 | new_route = GNUNET_new (struct Route); |
1330 | new_route->dest = delegated_host_id; | 1370 | new_route->dest = delegated_host_id; |
1331 | new_route->thru = route->dest; | 1371 | new_route->thru = route->dest; |
1332 | route_list_add (new_route); | 1372 | route_list_add (new_route); |
1333 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1373 | GNUNET_SERVICE_client_continue (client); |
1374 | } | ||
1375 | |||
1376 | |||
1377 | /** | ||
1378 | * Clean up @a client handle if we stored any via #handle_link_controllers(), | ||
1379 | * the given client disconnected. | ||
1380 | * | ||
1381 | * @param client the client that is history | ||
1382 | */ | ||
1383 | void | ||
1384 | GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | ||
1385 | { | ||
1386 | struct NeighbourConnectCtxt *ncc; | ||
1387 | struct NeighbourConnectCtxt *nccn; | ||
1388 | struct LCFContext *lcf; | ||
1389 | struct LCFContext *lcfn; | ||
1390 | |||
1391 | 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 | { | ||
1412 | slave->lcc = NULL; | ||
1413 | GNUNET_free (lcc); | ||
1414 | } | ||
1415 | } | ||
1416 | for (lcf = lcf_head; NULL != lcf; lcf = lcfn) | ||
1417 | { | ||
1418 | lcfn = lcf->next; | ||
1419 | if ( (NULL != lcf) && | ||
1420 | (client == lcf->client) ) | ||
1421 | { | ||
1422 | if (NULL != lcf->op) | ||
1423 | GNUNET_TESTBED_operation_done (lcf->op); | ||
1424 | GNUNET_CONTAINER_DLL_remove (lcf_head, | ||
1425 | lcf_tail, | ||
1426 | lcf); | ||
1427 | GNUNET_free (lcf); | ||
1428 | } | ||
1429 | } | ||
1334 | } | 1430 | } |
1335 | 1431 | ||
1336 | 1432 | ||
@@ -1338,12 +1434,11 @@ GST_handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1338 | * Cleans up the queue used for forwarding link controllers requests | 1434 | * Cleans up the queue used for forwarding link controllers requests |
1339 | */ | 1435 | */ |
1340 | void | 1436 | void |
1341 | GST_free_lcfq () | 1437 | GST_free_lcf () |
1342 | { | 1438 | { |
1343 | struct LCFContextQueue *lcfq; | ||
1344 | struct LCFContext *lcf; | 1439 | struct LCFContext *lcf; |
1345 | 1440 | ||
1346 | if (NULL != lcfq_head) | 1441 | if (NULL != lcf_head) |
1347 | { | 1442 | { |
1348 | if (NULL != lcf_proc_task_id) | 1443 | if (NULL != lcf_proc_task_id) |
1349 | { | 1444 | { |
@@ -1352,16 +1447,15 @@ GST_free_lcfq () | |||
1352 | } | 1447 | } |
1353 | } | 1448 | } |
1354 | GNUNET_assert (NULL == lcf_proc_task_id); | 1449 | GNUNET_assert (NULL == lcf_proc_task_id); |
1355 | for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) | 1450 | for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) |
1356 | { | 1451 | { |
1357 | lcf = lcfq->lcf; | ||
1358 | GNUNET_SERVER_client_drop (lcf->client); | ||
1359 | if (NULL != lcf->op) | 1452 | if (NULL != lcf->op) |
1360 | GNUNET_TESTBED_operation_done (lcf->op); | 1453 | GNUNET_TESTBED_operation_done (lcf->op); |
1361 | if (NULL != lcf->timeout_task) | 1454 | if (NULL != lcf->timeout_task) |
1362 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 1455 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); |
1456 | GNUNET_CONTAINER_DLL_remove (lcf_head, | ||
1457 | lcf_tail, | ||
1458 | lcf); | ||
1363 | GNUNET_free (lcf); | 1459 | GNUNET_free (lcf); |
1364 | GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq); | ||
1365 | GNUNET_free (lcfq); | ||
1366 | } | 1460 | } |
1367 | } | 1461 | } |