aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_stop_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_cmd_stop_peer.c')
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c156
1 files changed, 0 insertions, 156 deletions
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
deleted file mode 100644
index 4ca730add..000000000
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ /dev/null
@@ -1,156 +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_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
30#include "gnunet_peerstore_service.h"
31#include "gnunet_transport_core_service.h"
32#include "gnunet_transport_application_service.h"
33#include "transport-testing-cmds.h"
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39
40
41/**
42 * Struct to hold information for callbacks.
43 *
44 */
45struct StopPeerState
46{
47 // Label of the cmd to start the peer.
48 const char *start_label;
49};
50
51
52/**
53 * The run method of this cmd will stop all services of a peer which were used to test the transport service.
54 *
55 */
56static void
57stop_peer_run (void *cls,
58 struct GNUNET_TESTING_Interpreter *is)
59{
60 struct StopPeerState *stop_ps = cls;
61 const struct StartPeerState *sps;
62 const struct GNUNET_TESTING_Command *start_cmd;
63
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
65 stop_ps->start_label);
66 GNUNET_TRANSPORT_get_trait_state (start_cmd,
67 &sps);
68
69 if (NULL != sps->pic)
70 {
71 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
72 }
73 if (NULL != sps->th)
74 {
75 GNUNET_TRANSPORT_core_disconnect (sps->th);
76 }
77 if (NULL != sps->ah)
78 {
79 GNUNET_TRANSPORT_application_done (sps->ah);
80 }
81 if (NULL != sps->ph)
82 {
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Disconnecting from PEERSTORE service\n");
85 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
86 }
87 if (NULL != sps->peer)
88 {
89 if (GNUNET_OK !=
90 GNUNET_TESTING_peer_stop (sps->peer))
91 {
92 LOG (GNUNET_ERROR_TYPE_ERROR,
93 "Testing lib failed to stop peer %u (`%s')\n",
94 sps->no,
95 GNUNET_i2s (&sps->id));
96 }
97 GNUNET_TESTING_peer_destroy (sps->peer);
98 }
99 if (NULL != sps->rh_task)
100 GNUNET_SCHEDULER_cancel (sps->rh_task);
101}
102
103
104/**
105 * The cleanup function of this cmd frees resources the cmd allocated.
106 *
107 */
108static void
109stop_peer_cleanup (void *cls)
110{
111 struct StopPeerState *sps = cls;
112
113 GNUNET_free (sps);
114}
115
116
117/**
118 * Trait function of this cmd does nothing.
119 *
120 */
121static int
122stop_peer_traits (void *cls,
123 const void **ret,
124 const char *trait,
125 unsigned int index)
126{
127 return GNUNET_OK;
128}
129
130
131/**
132 * Create command.
133 *
134 * @param label name for command.
135 * @param start_label Label of the cmd to start the peer.
136 * @return command.
137 */
138struct GNUNET_TESTING_Command
139GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
140 const char *start_label)
141{
142 struct StopPeerState *sps;
143
144 sps = GNUNET_new (struct StopPeerState);
145 sps->start_label = start_label;
146 {
147 struct GNUNET_TESTING_Command cmd = {
148 .cls = sps,
149 .label = label,
150 .run = &stop_peer_run,
151 .cleanup = &stop_peer_cleanup,
152 .traits = &stop_peer_traits
153 };
154 return cmd;
155 }
156}