aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_stop_testsystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_stop_testsystem.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c153
1 files changed, 0 insertions, 153 deletions
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
deleted file mode 100644
index 4b52878c4..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ /dev/null
@@ -1,153 +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_netjail_lib.h"
29#include "testing_cmds.h"
30
31
32/**
33 * Struct to store information handed over to callbacks.
34 *
35 */
36struct StopHelperState
37{
38
39 /**
40 * The complete topology information.
41 */
42 struct GNUNET_TESTING_NetjailTopology *topology;
43
44 const char *helper_start_label;
45
46 /**
47 * The process handle
48 */
49 struct GNUNET_HELPER_Handle **helper;
50
51 unsigned int local_m;
52
53 unsigned int global_n;
54
55 /**
56 * Number of global known nodes.
57 *
58 */
59 unsigned int known;
60};
61
62
63/**
64* Code to clean up resource this cmd used.
65*
66* @param cls closure
67* @param cmd current CMD being cleaned up.
68*/
69static void
70stop_testing_system_cleanup (void *cls)
71{
72 struct StopHelperState *shs = cls;
73
74 GNUNET_free (shs);
75}
76
77
78/**
79* This function stops the helper process for each node.
80*
81* @param cls closure.
82* @param is interpreter state.
83*/
84static void
85stop_testing_system_run (void *cls,
86 struct GNUNET_TESTING_Interpreter *is)
87{
88 struct StopHelperState *shs = cls;
89 struct GNUNET_HELPER_Handle **helper;
90 const struct GNUNET_TESTING_Command *start_helper_cmd;
91
92 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
93 shs->
94 helper_start_label);
95 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
96 &helper);
97
98 for (int i = 1; i <= shs->known; i++)
99 {
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
101 "i: %u\n",
102 i);
103 GNUNET_HELPER_stop (helper[i - 1],
104 GNUNET_YES);
105 }
106
107 for (int i = 1; i <= shs->global_n; i++)
108 {
109 for (int j = 1; j <= shs->local_m; j++)
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 "i: %u j: %u\n",
113 i,
114 j);
115 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
116 GNUNET_YES);
117 }
118 }
119}
120
121
122/**
123 * Create command.
124 *
125 * @param label name for command.
126 * @param helper_start_label label of the cmd to start the test system.
127 * @param topology The complete topology information.
128 * @return command.
129 */
130struct GNUNET_TESTING_Command
131GNUNET_TESTING_cmd_stop_testing_system (
132 const char *label,
133 const char *helper_start_label,
134 struct GNUNET_TESTING_NetjailTopology *topology)
135{
136 struct StopHelperState *shs;
137
138 shs = GNUNET_new (struct StopHelperState);
139 shs->helper_start_label = helper_start_label;
140 shs->local_m = topology->nodes_m;
141 shs->global_n = topology->namespaces_n;
142 shs->known = topology->nodes_x;
143 shs->topology = topology;
144
145 struct GNUNET_TESTING_Command cmd = {
146 .cls = shs,
147 .label = label,
148 .run = &stop_testing_system_run,
149 .cleanup = &stop_testing_system_cleanup,
150 };
151
152 return cmd;
153}