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.c154
1 files changed, 0 insertions, 154 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 a80742b5f..000000000
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ /dev/null
@@ -1,154 +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_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Disconnecting from TRANSPORT service\n");
77 GNUNET_TRANSPORT_core_disconnect (sps->th);
78 }
79 if (NULL != sps->ah)
80 {
81 GNUNET_TRANSPORT_application_done (sps->ah);
82 }
83 if (NULL != sps->ph)
84 {
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Disconnecting from PEERSTORE service\n");
87 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
88 }
89 if (NULL != sps->peer)
90 {
91 if (GNUNET_OK !=
92 GNUNET_TESTING_peer_stop (sps->peer))
93 {
94 LOG (GNUNET_ERROR_TYPE_ERROR,
95 "Testing lib failed to stop peer %u (`%s')\n",
96 sps->no,
97 GNUNET_i2s (&sps->id));
98 }
99 GNUNET_TESTING_peer_destroy (sps->peer);
100 }
101 if (NULL != sps->rh_task)
102 GNUNET_SCHEDULER_cancel (sps->rh_task);
103}
104
105
106/**
107 * The cleanup function of this cmd frees resources the cmd allocated.
108 *
109 */
110static void
111stop_peer_cleanup (void *cls)
112{
113 struct StopPeerState *sps = cls;
114
115 GNUNET_free (sps);
116}
117
118
119/**
120 * Trait function of this cmd does nothing.
121 *
122 */
123static int
124stop_peer_traits (void *cls,
125 const void **ret,
126 const char *trait,
127 unsigned int index)
128{
129 return GNUNET_OK;
130}
131
132
133/**
134 * Create command.
135 *
136 * @param label name for command.
137 * @param start_label Label of the cmd to start the peer.
138 * @return command.
139 */
140struct GNUNET_TESTING_Command
141GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
142 const char *start_label)
143{
144 struct StopPeerState *sps;
145
146 sps = GNUNET_new (struct StopPeerState);
147 sps->start_label = start_label;
148 return GNUNET_TESTING_command_new (sps,
149 label,
150 &stop_peer_run,
151 &stop_peer_cleanup,
152 &stop_peer_traits,
153 NULL);
154}