diff options
Diffstat (limited to 'src/service/testing/testing_api_cmd_netjail_stop_cmds_helper.c')
-rw-r--r-- | src/service/testing/testing_api_cmd_netjail_stop_cmds_helper.c | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/service/testing/testing_api_cmd_netjail_stop_cmds_helper.c b/src/service/testing/testing_api_cmd_netjail_stop_cmds_helper.c deleted file mode 100644 index c6bb0ab52..000000000 --- a/src/service/testing/testing_api_cmd_netjail_stop_cmds_helper.c +++ /dev/null | |||
@@ -1,157 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/testing_api_cmd_hello_world.c | ||
23 | * @brief Command to start the netjail peers. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_testing_plugin.h" | ||
29 | #include "gnunet_testing_barrier.h" | ||
30 | #include "gnunet_testing_netjail_lib.h" | ||
31 | #include "testing_cmds.h" | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Struct to store information handed over to callbacks. | ||
36 | * | ||
37 | */ | ||
38 | struct StopHelperState | ||
39 | { | ||
40 | |||
41 | /** | ||
42 | * The complete topology information. | ||
43 | */ | ||
44 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
45 | |||
46 | const char *helper_start_label; | ||
47 | |||
48 | /** | ||
49 | * The process handle | ||
50 | */ | ||
51 | struct GNUNET_HELPER_Handle **helper; | ||
52 | |||
53 | unsigned int local_m; | ||
54 | |||
55 | unsigned int global_n; | ||
56 | |||
57 | /** | ||
58 | * Number of global known nodes. | ||
59 | * | ||
60 | */ | ||
61 | unsigned int known; | ||
62 | }; | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Code to clean up resource this cmd used. | ||
67 | * | ||
68 | * @param cls closure | ||
69 | * @param cmd current CMD being cleaned up. | ||
70 | */ | ||
71 | static void | ||
72 | stop_testing_system_cleanup (void *cls) | ||
73 | { | ||
74 | struct StopHelperState *shs = cls; | ||
75 | |||
76 | GNUNET_free (shs); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * This function stops the helper process for each node. | ||
82 | * | ||
83 | * @param cls closure. | ||
84 | * @param is interpreter state. | ||
85 | */ | ||
86 | static void | ||
87 | stop_testing_system_run (void *cls, | ||
88 | struct GNUNET_TESTING_Interpreter *is) | ||
89 | { | ||
90 | struct StopHelperState *shs = cls; | ||
91 | const struct GNUNET_HELPER_Handle **helper; | ||
92 | const struct GNUNET_TESTING_Command *start_helper_cmd; | ||
93 | |||
94 | start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
95 | shs-> | ||
96 | helper_start_label); | ||
97 | GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, | ||
98 | &helper); | ||
99 | |||
100 | for (int i = 1; i <= shs->known; i++) | ||
101 | { | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
103 | "i: %u\n", | ||
104 | i); | ||
105 | GNUNET_HELPER_stop ( | ||
106 | (struct GNUNET_HELPER_Handle *) helper[i - 1], | ||
107 | GNUNET_YES); | ||
108 | } | ||
109 | |||
110 | for (int i = 1; i <= shs->global_n; i++) | ||
111 | { | ||
112 | for (int j = 1; j <= shs->local_m; j++) | ||
113 | { | ||
114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
115 | "i: %u j: %u\n", | ||
116 | i, | ||
117 | j); | ||
118 | GNUNET_HELPER_stop ((struct GNUNET_HELPER_Handle *) helper[(i - 1) | ||
119 | * shs->local_m | ||
120 | + j | ||
121 | + shs->known | ||
122 | - 1], | ||
123 | GNUNET_YES); | ||
124 | } | ||
125 | } | ||
126 | GNUNET_free (helper); | ||
127 | } | ||
128 | |||
129 | |||
130 | /** | ||
131 | * Create command. | ||
132 | * | ||
133 | * @param label name for command. | ||
134 | * @param helper_start_label label of the cmd to start the test system. | ||
135 | * @param topology The complete topology information. | ||
136 | * @return command. | ||
137 | */ | ||
138 | struct GNUNET_TESTING_Command | ||
139 | GNUNET_TESTING_cmd_stop_cmds_helper ( | ||
140 | const char *label, | ||
141 | const char *helper_start_label, | ||
142 | struct GNUNET_TESTING_NetjailTopology *topology) | ||
143 | { | ||
144 | struct StopHelperState *shs; | ||
145 | |||
146 | shs = GNUNET_new (struct StopHelperState); | ||
147 | shs->helper_start_label = helper_start_label; | ||
148 | shs->local_m = topology->nodes_m; | ||
149 | shs->global_n = topology->namespaces_n; | ||
150 | shs->known = topology->nodes_x; | ||
151 | shs->topology = topology; | ||
152 | |||
153 | return GNUNET_TESTING_command_new (shs, label, | ||
154 | &stop_testing_system_run, | ||
155 | &stop_testing_system_cleanup, | ||
156 | NULL, NULL); | ||
157 | } | ||