diff options
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem.c')
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start_testsystem.c | 187 |
1 files changed, 64 insertions, 123 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index c3598d174..89c193de5 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c | |||
@@ -25,9 +25,10 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_testing_ng_lib.h" | 27 | #include "gnunet_testing_ng_lib.h" |
28 | #include "gnunet_testing_netjail_lib.h" | ||
28 | #include "testing_cmds.h" | 29 | #include "testing_cmds.h" |
29 | 30 | ||
30 | #define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" | 31 | #define NETJAIL_EXEC_SCRIPT "netjail_exec.sh" |
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Generic logging shortcut | 34 | * Generic logging shortcut |
@@ -83,18 +84,6 @@ struct NetJailState | |||
83 | struct GNUNET_TESTING_NetjailTopology *topology; | 84 | struct GNUNET_TESTING_NetjailTopology *topology; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * Head of the DLL which stores messages received by the helper. | ||
87 | * | ||
88 | */ | ||
89 | struct HelperMessage *hp_messages_head; | ||
90 | |||
91 | /** | ||
92 | * Tail of the DLL which stores messages received by the helper. | ||
93 | * | ||
94 | */ | ||
95 | struct HelperMessage *hp_messages_tail; | ||
96 | |||
97 | /** | ||
98 | * Array with handles of helper processes. | 87 | * Array with handles of helper processes. |
99 | */ | 88 | */ |
100 | struct GNUNET_HELPER_Handle **helper; | 89 | struct GNUNET_HELPER_Handle **helper; |
@@ -123,27 +112,6 @@ struct NetJailState | |||
123 | */ | 112 | */ |
124 | unsigned int known; | 113 | unsigned int known; |
125 | 114 | ||
126 | /** | ||
127 | * The send handle for the helper | ||
128 | */ | ||
129 | // struct GNUNET_HELPER_SendHandle **shandle; | ||
130 | |||
131 | /** | ||
132 | * Size of the array NetJailState#shandle. | ||
133 | * | ||
134 | */ | ||
135 | // unsigned int n_shandle; | ||
136 | |||
137 | /** | ||
138 | * The messages send to the helper. | ||
139 | */ | ||
140 | struct GNUNET_MessageHeader **msg; | ||
141 | |||
142 | /** | ||
143 | * Size of the array NetJailState#msg. | ||
144 | * | ||
145 | */ | ||
146 | unsigned int n_msg; | ||
147 | 115 | ||
148 | /** | 116 | /** |
149 | * Number of test environments started. | 117 | * Number of test environments started. |
@@ -176,16 +144,14 @@ struct NetJailState | |||
176 | char *plugin_name; | 144 | char *plugin_name; |
177 | 145 | ||
178 | /** | 146 | /** |
179 | * HEAD of the DLL containing TestingSystemCount. | 147 | * Shall we read the topology from file, or from a string. |
180 | * | ||
181 | */ | 148 | */ |
182 | struct TestingSystemCount *tbcs_head; | 149 | unsigned int *read_file; |
183 | 150 | ||
184 | /** | 151 | /** |
185 | * TAIL of the DLL containing TestingSystemCount. | 152 | * String with topology data or name of topology file. |
186 | * | ||
187 | */ | 153 | */ |
188 | struct TestingSystemCount *tbcs_tail; | 154 | char *topology_data; |
189 | }; | 155 | }; |
190 | 156 | ||
191 | /** | 157 | /** |
@@ -207,13 +173,7 @@ struct TestingSystemCount | |||
207 | /** | 173 | /** |
208 | * The send handle for the helper | 174 | * The send handle for the helper |
209 | */ | 175 | */ |
210 | struct GNUNET_HELPER_SendHandle *shandle;// **shandle; | 176 | struct GNUNET_HELPER_SendHandle *shandle; |
211 | |||
212 | /** | ||
213 | * Size of the array NetJailState#shandle. | ||
214 | * | ||
215 | */ | ||
216 | // unsigned int n_shandle; | ||
217 | 177 | ||
218 | /** | 178 | /** |
219 | * The number of the test environment. | 179 | * The number of the test environment. |
@@ -226,6 +186,11 @@ struct TestingSystemCount | |||
226 | * | 186 | * |
227 | */ | 187 | */ |
228 | struct NetJailState *ns; | 188 | struct NetJailState *ns; |
189 | |||
190 | /** | ||
191 | * The messages send to the helper. | ||
192 | */ | ||
193 | struct GNUNET_MessageHeader *msg; | ||
229 | }; | 194 | }; |
230 | 195 | ||
231 | /** | 196 | /** |
@@ -237,24 +202,7 @@ static void | |||
237 | netjail_exec_cleanup (void *cls) | 202 | netjail_exec_cleanup (void *cls) |
238 | { | 203 | { |
239 | struct NetJailState *ns = cls; | 204 | struct NetJailState *ns = cls; |
240 | struct HelperMessage *message_pos; | ||
241 | struct TestingSystemCount *tbc_pos; | ||
242 | 205 | ||
243 | while (NULL != (message_pos = ns->hp_messages_head)) | ||
244 | { | ||
245 | GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head, | ||
246 | ns->hp_messages_tail, | ||
247 | message_pos); | ||
248 | GNUNET_free (message_pos); | ||
249 | } | ||
250 | while (NULL != (tbc_pos = ns->tbcs_head)) | ||
251 | { | ||
252 | GNUNET_CONTAINER_DLL_remove (ns->tbcs_head, | ||
253 | ns->tbcs_tail, | ||
254 | tbc_pos); | ||
255 | GNUNET_free (tbc_pos); | ||
256 | } | ||
257 | GNUNET_TESTING_free_topology (ns->topology); | ||
258 | GNUNET_free (ns); | 206 | GNUNET_free (ns); |
259 | } | 207 | } |
260 | 208 | ||
@@ -271,7 +219,6 @@ netjail_exec_traits (void *cls, | |||
271 | { | 219 | { |
272 | struct NetJailState *ns = cls; | 220 | struct NetJailState *ns = cls; |
273 | struct GNUNET_HELPER_Handle **helper = ns->helper; | 221 | struct GNUNET_HELPER_Handle **helper = ns->helper; |
274 | struct HelperMessage *hp_messages_head = ns->hp_messages_head; | ||
275 | 222 | ||
276 | 223 | ||
277 | struct GNUNET_TESTING_Trait traits[] = { | 224 | struct GNUNET_TESTING_Trait traits[] = { |
@@ -280,11 +227,6 @@ netjail_exec_traits (void *cls, | |||
280 | .trait_name = "helper_handles", | 227 | .trait_name = "helper_handles", |
281 | .ptr = (const void *) helper, | 228 | .ptr = (const void *) helper, |
282 | }, | 229 | }, |
283 | { | ||
284 | .index = 1, | ||
285 | .trait_name = "hp_msgs_head", | ||
286 | .ptr = (const void *) hp_messages_head, | ||
287 | }, | ||
288 | GNUNET_TESTING_trait_end () | 230 | GNUNET_TESTING_trait_end () |
289 | }; | 231 | }; |
290 | 232 | ||
@@ -327,12 +269,12 @@ static void | |||
327 | clear_msg (void *cls, int result) | 269 | clear_msg (void *cls, int result) |
328 | { | 270 | { |
329 | struct TestingSystemCount *tbc = cls; | 271 | struct TestingSystemCount *tbc = cls; |
330 | struct NetJailState *ns = tbc->ns; | ||
331 | 272 | ||
332 | GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]); | 273 | GNUNET_assert (NULL != tbc->shandle); |
333 | tbc->shandle = NULL;// [tbc->count - 1] = NULL; | 274 | GNUNET_free (tbc->shandle); |
334 | GNUNET_free (ns->msg[tbc->count - 1]); | 275 | tbc->shandle = NULL; |
335 | ns->msg[tbc->count - 1] = NULL; | 276 | GNUNET_free (tbc->msg); |
277 | tbc->msg = NULL; | ||
336 | } | 278 | } |
337 | 279 | ||
338 | 280 | ||
@@ -361,7 +303,7 @@ send_message_to_locals ( | |||
361 | 303 | ||
362 | helper = ns->helper[tbc->count - 1];// - total_number]; | 304 | helper = ns->helper[tbc->count - 1];// - total_number]; |
363 | 305 | ||
364 | GNUNET_array_append (ns->msg, ns->n_msg, header); | 306 | |
365 | 307 | ||
366 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( | 308 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( |
367 | helper, | 309 | helper, |
@@ -427,7 +369,7 @@ static int | |||
427 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | 369 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) |
428 | { | 370 | { |
429 | // struct TestingSystemCount *tbc = cls; | 371 | // struct TestingSystemCount *tbc = cls; |
430 | struct NetJailState *ns = cls;// tbc->ns; | 372 | struct NetJailState *ns = cls; |
431 | struct HelperMessage *hp_msg; | 373 | struct HelperMessage *hp_msg; |
432 | unsigned int total_number = ns->local_m * ns->global_n + ns->known; | 374 | unsigned int total_number = ns->local_m * ns->global_n + ns->known; |
433 | // uint16_t message_type = ntohs (message->type); | 375 | // uint16_t message_type = ntohs (message->type); |
@@ -543,11 +485,8 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | |||
543 | } | 485 | } |
544 | else | 486 | else |
545 | { | 487 | { |
546 | hp_msg = GNUNET_new (struct HelperMessage); | 488 | // We received a message we can not handle. |
547 | hp_msg->bytes_msg = message->size; | 489 | GNUNET_assert (0); |
548 | memcpy (&hp_msg[1], message, message->size); | ||
549 | GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, | ||
550 | hp_msg); | ||
551 | } | 490 | } |
552 | 491 | ||
553 | 492 | ||
@@ -629,6 +568,7 @@ start_helper (struct NetJailState *ns, | |||
629 | char *known_char; | 568 | char *known_char; |
630 | char *node_id; | 569 | char *node_id; |
631 | char *plugin; | 570 | char *plugin; |
571 | char *read_file; | ||
632 | pid_t pid; | 572 | pid_t pid; |
633 | unsigned int script_num; | 573 | unsigned int script_num; |
634 | struct GNUNET_ShortHashCode *hkey; | 574 | struct GNUNET_ShortHashCode *hkey; |
@@ -636,6 +576,9 @@ start_helper (struct NetJailState *ns, | |||
636 | struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; | 576 | struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; |
637 | struct GNUNET_TESTING_NetjailNode *node; | 577 | struct GNUNET_TESTING_NetjailNode *node; |
638 | struct GNUNET_TESTING_NetjailNamespace *namespace; | 578 | struct GNUNET_TESTING_NetjailNamespace *namespace; |
579 | char *data_dir; | ||
580 | char *script_name; | ||
581 | char *topology_data; | ||
639 | 582 | ||
640 | 583 | ||
641 | if (0 == n) | 584 | if (0 == n) |
@@ -652,47 +595,31 @@ start_helper (struct NetJailState *ns, | |||
652 | GNUNET_asprintf (&node_id, "%06x-%08x\n", | 595 | GNUNET_asprintf (&node_id, "%06x-%08x\n", |
653 | pid, | 596 | pid, |
654 | script_num); | 597 | script_num); |
598 | // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data); | ||
599 | GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); | ||
655 | 600 | ||
656 | 601 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | |
657 | char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, | 602 | GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT); |
658 | m_char, | ||
659 | n_char, | ||
660 | GNUNET_OS_get_libexec_binary_path ( | ||
661 | HELPER_CMDS_BINARY), | ||
662 | global_n_char, | ||
663 | local_m_char, | ||
664 | node_id, | ||
665 | NULL}; | ||
666 | |||
667 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( | 603 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( |
668 | NETJAIL_EXEC_SCRIPT, | 604 | script_name, |
669 | GNUNET_YES, | 605 | GNUNET_YES, |
670 | NULL); | 606 | NULL); |
671 | 607 | ||
672 | tbc = GNUNET_new (struct TestingSystemCount); | 608 | tbc = GNUNET_new (struct TestingSystemCount); |
673 | tbc->ns = ns; | 609 | tbc->ns = ns; |
674 | if (0 == n) | ||
675 | tbc->count = m; | ||
676 | else | ||
677 | tbc->count = (n - 1) * ns->local_m + m + ns->known; | ||
678 | |||
679 | GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, | ||
680 | ns->tbcs_tail, | ||
681 | tbc); | ||
682 | |||
683 | 610 | ||
684 | if (GNUNET_NO == helper_check) | 611 | if (GNUNET_NO == helper_check) |
685 | { | 612 | { |
686 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
687 | "No SUID for %s!\n", | 614 | "No SUID for %s!\n", |
688 | NETJAIL_EXEC_SCRIPT); | 615 | script_name); |
689 | GNUNET_TESTING_interpreter_fail (ns->is); | 616 | GNUNET_TESTING_interpreter_fail (ns->is); |
690 | } | 617 | } |
691 | else if (GNUNET_NO == helper_check) | 618 | else if (GNUNET_NO == helper_check) |
692 | { | 619 | { |
693 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 620 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
694 | "%s not found!\n", | 621 | "%s not found!\n", |
695 | NETJAIL_EXEC_SCRIPT); | 622 | script_name); |
696 | GNUNET_TESTING_interpreter_fail (ns->is); | 623 | GNUNET_TESTING_interpreter_fail (ns->is); |
697 | } | 624 | } |
698 | 625 | ||
@@ -705,17 +632,29 @@ start_helper (struct NetJailState *ns, | |||
705 | ns->local_m, | 632 | ns->local_m, |
706 | ns->global_n, | 633 | ns->global_n, |
707 | ns->known); | 634 | ns->known); |
635 | { | ||
636 | char *const script_argv[] = {script_name, | ||
637 | m_char, | ||
638 | n_char, | ||
639 | GNUNET_OS_get_libexec_binary_path ( | ||
640 | HELPER_CMDS_BINARY), | ||
641 | global_n_char, | ||
642 | local_m_char, | ||
643 | node_id, | ||
644 | read_file, | ||
645 | ns->topology_data, | ||
646 | NULL}; | ||
647 | helper = GNUNET_HELPER_start ( | ||
648 | GNUNET_YES, | ||
649 | script_name, | ||
650 | script_argv, | ||
651 | &helper_mst, | ||
652 | &exp_cb, | ||
653 | ns); | ||
654 | GNUNET_array_append (ns->helper, ns->n_helper, helper); | ||
655 | } | ||
708 | 656 | ||
709 | GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( | 657 | tbc->count = ns->n_helper; |
710 | GNUNET_YES, | ||
711 | NETJAIL_EXEC_SCRIPT, | ||
712 | script_argv, | ||
713 | &helper_mst, | ||
714 | &exp_cb, | ||
715 | ns)); | ||
716 | |||
717 | helper = ns->helper[tbc->count - 1]; | ||
718 | |||
719 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | 658 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); |
720 | 659 | ||
721 | plugin = topology->plugin; | 660 | plugin = topology->plugin; |
@@ -767,8 +706,6 @@ start_helper (struct NetJailState *ns, | |||
767 | 706 | ||
768 | msg = create_helper_init_msg_ (plugin); | 707 | msg = create_helper_init_msg_ (plugin); |
769 | 708 | ||
770 | GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); | ||
771 | |||
772 | // GNUNET_array_append (tbc->shandle, tbc->n_shandle, | 709 | // GNUNET_array_append (tbc->shandle, tbc->n_shandle, |
773 | tbc->shandle = GNUNET_HELPER_send ( | 710 | tbc->shandle = GNUNET_HELPER_send ( |
774 | helper, | 711 | helper, |
@@ -825,24 +762,28 @@ netjail_exec_run (void *cls, | |||
825 | * Create command. | 762 | * Create command. |
826 | * | 763 | * |
827 | * @param label Name for the command. | 764 | * @param label Name for the command. |
828 | * @param topology_config Configuration file for the test topology. | 765 | * @param topology The complete topology information. |
766 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
767 | * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. | ||
829 | * @return command. | 768 | * @return command. |
830 | */ | 769 | */ |
831 | struct GNUNET_TESTING_Command | 770 | struct GNUNET_TESTING_Command |
832 | GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, | 771 | GNUNET_TESTING_cmd_netjail_start_testing_system ( |
833 | const char *topology_config) | 772 | const char *label, |
773 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
774 | unsigned int *read_file, | ||
775 | char *topology_data) | ||
834 | { | 776 | { |
835 | struct NetJailState *ns; | 777 | struct NetJailState *ns; |
836 | 778 | ||
837 | struct GNUNET_TESTING_NetjailTopology *topology = | ||
838 | GNUNET_TESTING_get_topo_from_file (topology_config); | ||
839 | |||
840 | ns = GNUNET_new (struct NetJailState); | 779 | ns = GNUNET_new (struct NetJailState); |
841 | ns->local_m = topology->nodes_m; | 780 | ns->local_m = topology->nodes_m; |
842 | ns->global_n = topology->namespaces_n; | 781 | ns->global_n = topology->namespaces_n; |
843 | ns->known = topology->nodes_x; | 782 | ns->known = topology->nodes_x; |
844 | ns->plugin_name = topology->plugin; | 783 | ns->plugin_name = topology->plugin; |
845 | ns->topology = topology; | 784 | ns->topology = topology; |
785 | ns->read_file = read_file; | ||
786 | ns->topology_data = topology_data; | ||
846 | 787 | ||
847 | struct GNUNET_TESTING_Command cmd = { | 788 | struct GNUNET_TESTING_Command cmd = { |
848 | .cls = ns, | 789 | .cls = ns, |