aboutsummaryrefslogtreecommitdiff
path: root/src/service/transport/testing_api_cmd_stop_peer.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-05-20 13:29:41 +0200
committerChristian Grothoff <christian@grothoff.org>2024-05-20 13:29:41 +0200
commit9185820ef1a1b2273fb4bbbf78ad60a3453d48bc (patch)
tree8833f541754879dd97a0eb6351e86c336a411000 /src/service/transport/testing_api_cmd_stop_peer.c
parent66f19cd73d9c0bd35354f2c86673d6ab82618c81 (diff)
downloadgnunet-9185820ef1a1b2273fb4bbbf78ad60a3453d48bc.tar.gz
gnunet-9185820ef1a1b2273fb4bbbf78ad60a3453d48bc.zip
-minor refactoring
Diffstat (limited to 'src/service/transport/testing_api_cmd_stop_peer.c')
-rw-r--r--src/service/transport/testing_api_cmd_stop_peer.c130
1 files changed, 0 insertions, 130 deletions
diff --git a/src/service/transport/testing_api_cmd_stop_peer.c b/src/service/transport/testing_api_cmd_stop_peer.c
deleted file mode 100644
index 38d53ffba..000000000
--- a/src/service/transport/testing_api_cmd_stop_peer.c
+++ /dev/null
@@ -1,130 +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_api_cmd_stop_peer.c
23 * @brief cmd to stop a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_lib.h"
29#include "gnunet_testbed_lib.h"
30#include "gnunet_transport_testing_ng_lib.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37
38/**
39 * Struct to hold information for callbacks.
40 *
41 */
42struct StopPeerState
43{
44 // Label of the cmd to start the peer.
45 const char *start_label;
46};
47
48
49/**
50 * The run method of this cmd will stop all services of a peer which were used to test the transport service.
51 *
52 */
53static void
54stop_peer_run (void *cls,
55 struct GNUNET_TESTING_Interpreter *is)
56{
57 struct StopPeerState *stop_ps = cls;
58 const struct GNUNET_TESTING_StartPeerState *sps;
59 const struct GNUNET_TESTING_Command *start_cmd;
60
61 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
62 stop_ps->start_label);
63 GNUNET_TRANSPORT_TESTING_get_trait_state (start_cmd,
64 &sps);
65
66 if (NULL != sps->peer)
67 {
68 if (GNUNET_OK !=
69 GNUNET_TESTBED_peer_stop (sps->peer))
70 {
71 LOG (GNUNET_ERROR_TYPE_ERROR,
72 "Testing lib failed to stop peer %u (`%s')\n",
73 sps->no,
74 GNUNET_i2s (&sps->id));
75 }
76 GNUNET_TESTBED_peer_destroy (sps->peer);
77 }
78 if (NULL != sps->rh_task)
79 GNUNET_SCHEDULER_cancel (sps->rh_task);
80}
81
82
83/**
84 * The cleanup function of this cmd frees resources the cmd allocated.
85 *
86 */
87static void
88stop_peer_cleanup (void *cls)
89{
90 struct StopPeerState *sps = cls;
91
92 GNUNET_free (sps);
93}
94
95
96/**
97 * Trait function of this cmd does nothing.
98 *
99 */
100static int
101stop_peer_traits (void *cls,
102 const void **ret,
103 const char *trait,
104 unsigned int index)
105{
106 return GNUNET_OK;
107}
108
109
110/**
111 * Create command.
112 *
113 * @param label name for command.
114 * @param start_label Label of the cmd to start the peer.
115 * @return command.
116 */
117struct GNUNET_TESTING_Command
118GNUNET_TESTING_cmd_stop_peer (const char *label,
119 const char *start_label)
120{
121 struct StopPeerState *sps;
122
123 sps = GNUNET_new (struct StopPeerState);
124 sps->start_label = start_label;
125 return GNUNET_TESTING_command_new (sps,
126 label,
127 &stop_peer_run,
128 &stop_peer_cleanup,
129 &stop_peer_traits);
130}