GNUnet  0.17.6
testing_api_cmd_netjail_stop_testsystem.c
Go to the documentation of this file.
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 
26 #include "platform.h"
27 #include "gnunet_testing_ng_lib.h"
29 #include "testing_cmds.h"
30 
31 
37 {
38 
43 
44  const char *helper_start_label;
45 
50 
51  unsigned int local_m;
52 
53  unsigned int global_n;
54 
59  unsigned int known;
60 };
61 
62 
69 static void
71 {
72  struct StopHelperState *shs = cls;
73 
74  GNUNET_free (shs);
75 }
76 
77 
84 static void
87 {
88  struct StopHelperState *shs = cls;
89  const struct GNUNET_HELPER_Handle **helper;
90  const struct GNUNET_TESTING_Command *start_helper_cmd;
91 
93  shs->
94  helper_start_label);
96  &helper);
97 
98  for (int i = 1; i <= shs->known; i++)
99  {
101  "i: %u\n",
102  i);
104  (struct GNUNET_HELPER_Handle *) helper[i - 1],
105  GNUNET_YES);
106  }
107 
108  for (int i = 1; i <= shs->global_n; i++)
109  {
110  for (int j = 1; j <= shs->local_m; j++)
111  {
113  "i: %u j: %u\n",
114  i,
115  j);
116  GNUNET_HELPER_stop ((struct GNUNET_HELPER_Handle *) helper[(i - 1)
117  * shs->local_m
118  + j
119  + shs->known
120  - 1],
121  GNUNET_NO);
122  }
123  }
124 }
125 
126 
137  const char *label,
138  const char *helper_start_label,
140 {
141  struct StopHelperState *shs;
142 
143  shs = GNUNET_new (struct StopHelperState);
145  shs->local_m = topology->nodes_m;
146  shs->global_n = topology->namespaces_n;
147  shs->known = topology->nodes_x;
148  shs->topology = topology;
149 
150  struct GNUNET_TESTING_Command cmd = {
151  .cls = shs,
152  .label = label,
153  .run = &stop_testing_system_run,
154  .cleanup = &stop_testing_system_cleanup,
155  };
156 
157  return cmd;
158 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_helper_handles(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_HELPER_Handle ***ret)
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process.
Definition: helper.c:571
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
The handle to a helper process.
Definition: helper.c:79
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Struct to store information handed over to callbacks.
unsigned int known
Number of global known nodes.
struct GNUNET_TESTING_NetjailTopology * topology
The complete topology information.
struct GNUNET_HELPER_Handle ** helper
The process handle.
static void stop_testing_system_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function stops the helper process for each node.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_stop_testing_system(const char *label, const char *helper_start_label, struct GNUNET_TESTING_NetjailTopology *topology)
Create command.
static void stop_testing_system_cleanup(void *cls)
Code to clean up resource this cmd used.
Message formats for communication between testing cmds helper and testcase plugins.