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