diff options
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 236 |
1 files changed, 118 insertions, 118 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 557b91d1c..d6853c184 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/test_gnunet_daemon_hostlist.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist.c |
22 | * @brief test for gnunet_daemon_hostslist.c | 22 | * @brief test for gnunet_daemon_hostslist.c |
@@ -32,14 +32,13 @@ | |||
32 | /** | 32 | /** |
33 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150) |
36 | 36 | ||
37 | static int ok; | 37 | static int ok; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 39 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
40 | 40 | ||
41 | struct PeerContext | 41 | struct PeerContext { |
42 | { | ||
43 | struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | struct GNUNET_CONFIGURATION_Handle *cfg; |
44 | struct GNUNET_TRANSPORT_CoreHandle *th; | 43 | struct GNUNET_TRANSPORT_CoreHandle *th; |
45 | struct GNUNET_MessageHeader *hello; | 44 | struct GNUNET_MessageHeader *hello; |
@@ -53,29 +52,29 @@ static struct PeerContext p2; | |||
53 | 52 | ||
54 | 53 | ||
55 | static void | 54 | static void |
56 | clean_up (void *cls) | 55 | clean_up(void *cls) |
57 | { | 56 | { |
58 | if (NULL != p1.th) | 57 | if (NULL != p1.th) |
59 | { | ||
60 | if (NULL != p1.ghh) | ||
61 | { | 58 | { |
62 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); | 59 | if (NULL != p1.ghh) |
63 | p1.ghh = NULL; | 60 | { |
61 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); | ||
62 | p1.ghh = NULL; | ||
63 | } | ||
64 | GNUNET_TRANSPORT_core_disconnect(p1.th); | ||
65 | p1.th = NULL; | ||
64 | } | 66 | } |
65 | GNUNET_TRANSPORT_core_disconnect (p1.th); | ||
66 | p1.th = NULL; | ||
67 | } | ||
68 | if (NULL != p2.th) | 67 | if (NULL != p2.th) |
69 | { | ||
70 | if (NULL != p2.ghh) | ||
71 | { | 68 | { |
72 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); | 69 | if (NULL != p2.ghh) |
73 | p2.ghh = NULL; | 70 | { |
71 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); | ||
72 | p2.ghh = NULL; | ||
73 | } | ||
74 | GNUNET_TRANSPORT_core_disconnect(p2.th); | ||
75 | p2.th = NULL; | ||
74 | } | 76 | } |
75 | GNUNET_TRANSPORT_core_disconnect (p2.th); | 77 | GNUNET_SCHEDULER_shutdown(); |
76 | p2.th = NULL; | ||
77 | } | ||
78 | GNUNET_SCHEDULER_shutdown (); | ||
79 | } | 78 | } |
80 | 79 | ||
81 | 80 | ||
@@ -83,12 +82,12 @@ clean_up (void *cls) | |||
83 | * Timeout, give up. | 82 | * Timeout, give up. |
84 | */ | 83 | */ |
85 | static void | 84 | static void |
86 | timeout_error (void *cls) | 85 | timeout_error(void *cls) |
87 | { | 86 | { |
88 | timeout_task = NULL; | 87 | timeout_task = NULL; |
89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
90 | "Timeout trying to connect peers, test failed.\n"); | 89 | "Timeout trying to connect peers, test failed.\n"); |
91 | clean_up (NULL); | 90 | clean_up(NULL); |
92 | } | 91 | } |
93 | 92 | ||
94 | 93 | ||
@@ -101,92 +100,92 @@ timeout_error (void *cls) | |||
101 | * @param mq message queue to send messages to the peer | 100 | * @param mq message queue to send messages to the peer |
102 | */ | 101 | */ |
103 | static void * | 102 | static void * |
104 | notify_connect (void *cls, | 103 | notify_connect(void *cls, |
105 | const struct GNUNET_PeerIdentity *peer, | 104 | const struct GNUNET_PeerIdentity *peer, |
106 | struct GNUNET_MQ_Handle *mq) | 105 | struct GNUNET_MQ_Handle *mq) |
107 | { | 106 | { |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
109 | ok = 0; | 108 | ok = 0; |
110 | if (NULL != timeout_task) | 109 | if (NULL != timeout_task) |
111 | { | 110 | { |
112 | GNUNET_SCHEDULER_cancel (timeout_task); | 111 | GNUNET_SCHEDULER_cancel(timeout_task); |
113 | timeout_task = NULL; | 112 | timeout_task = NULL; |
114 | } | 113 | } |
115 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 114 | GNUNET_SCHEDULER_add_now(&clean_up, NULL); |
116 | return NULL; | 115 | return NULL; |
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
120 | static void | 119 | static void |
121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) | 120 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) |
122 | { | 121 | { |
123 | struct PeerContext *p = cls; | 122 | struct PeerContext *p = cls; |
124 | 123 | ||
125 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); | 124 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); |
126 | p->ghh = NULL; | 125 | p->ghh = NULL; |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
128 | "Received HELLO, starting hostlist service.\n"); | 127 | "Received HELLO, starting hostlist service.\n"); |
129 | } | 128 | } |
130 | 129 | ||
131 | 130 | ||
132 | static void | 131 | static void |
133 | setup_peer (struct PeerContext *p, const char *cfgname) | 132 | setup_peer(struct PeerContext *p, const char *cfgname) |
134 | { | 133 | { |
135 | char *binary; | 134 | char *binary; |
136 | 135 | ||
137 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 136 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
138 | p->cfg = GNUNET_CONFIGURATION_create (); | 137 | p->cfg = GNUNET_CONFIGURATION_create(); |
139 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, | 138 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, |
140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
141 | NULL, | 140 | NULL, |
142 | NULL, | 141 | NULL, |
143 | NULL, | 142 | NULL, |
144 | binary, | 143 | binary, |
145 | "gnunet-service-arm", | 144 | "gnunet-service-arm", |
146 | "-c", | 145 | "-c", |
147 | cfgname, | 146 | cfgname, |
148 | NULL); | 147 | NULL); |
149 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 148 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); |
150 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | 149 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, |
151 | NULL, | 150 | NULL, |
152 | NULL, | 151 | NULL, |
153 | p, | 152 | p, |
154 | ¬ify_connect, | 153 | ¬ify_connect, |
155 | NULL, | 154 | NULL, |
156 | NULL); | 155 | NULL); |
157 | GNUNET_assert (NULL != p->th); | 156 | GNUNET_assert(NULL != p->th); |
158 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 157 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, |
159 | GNUNET_TRANSPORT_AC_ANY, | 158 | GNUNET_TRANSPORT_AC_ANY, |
160 | &process_hello, | 159 | &process_hello, |
161 | p); | 160 | p); |
162 | GNUNET_free (binary); | 161 | GNUNET_free(binary); |
163 | } | 162 | } |
164 | 163 | ||
165 | 164 | ||
166 | static void | 165 | static void |
167 | waitpid_task (void *cls) | 166 | waitpid_task(void *cls) |
168 | { | 167 | { |
169 | struct PeerContext *p = cls; | 168 | struct PeerContext *p = cls; |
170 | 169 | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
172 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 171 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) |
173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 172 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
174 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) | 173 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) |
175 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 174 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
177 | "ARM process %u stopped\n", | 176 | "ARM process %u stopped\n", |
178 | GNUNET_OS_process_get_pid (p->arm_proc)); | 177 | GNUNET_OS_process_get_pid(p->arm_proc)); |
179 | GNUNET_OS_process_destroy (p->arm_proc); | 178 | GNUNET_OS_process_destroy(p->arm_proc); |
180 | p->arm_proc = NULL; | 179 | p->arm_proc = NULL; |
181 | GNUNET_CONFIGURATION_destroy (p->cfg); | 180 | GNUNET_CONFIGURATION_destroy(p->cfg); |
182 | } | 181 | } |
183 | 182 | ||
184 | 183 | ||
185 | static void | 184 | static void |
186 | stop_arm (struct PeerContext *p) | 185 | stop_arm(struct PeerContext *p) |
187 | { | 186 | { |
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 188 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
@@ -194,67 +193,68 @@ stop_arm (struct PeerContext *p) | |||
194 | * Try again to connect to transport service. | 193 | * Try again to connect to transport service. |
195 | */ | 194 | */ |
196 | static void | 195 | static void |
197 | shutdown_task (void *cls) | 196 | shutdown_task(void *cls) |
198 | { | 197 | { |
199 | stop_arm (&p1); | 198 | stop_arm(&p1); |
200 | stop_arm (&p2); | 199 | stop_arm(&p2); |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | static void | 203 | static void |
205 | run (void *cls, | 204 | run(void *cls, |
206 | char *const *args, | 205 | char *const *args, |
207 | const char *cfgfile, | 206 | const char *cfgfile, |
208 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 207 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
209 | { | 208 | { |
210 | GNUNET_assert (ok == 1); | 209 | GNUNET_assert(ok == 1); |
211 | ok++; | 210 | ok++; |
212 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); | 211 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); |
213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 212 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
214 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 213 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
215 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 214 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
216 | } | 215 | } |
217 | 216 | ||
218 | 217 | ||
219 | static int | 218 | static int |
220 | check () | 219 | check() |
221 | { | 220 | { |
222 | char *const argv[] = {"test-gnunet-daemon-hostlist", | 221 | char *const argv[] = { "test-gnunet-daemon-hostlist", |
223 | "-c", | 222 | "-c", |
224 | "test_gnunet_daemon_hostlist_data.conf", | 223 | "test_gnunet_daemon_hostlist_data.conf", |
225 | NULL}; | 224 | NULL }; |
226 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; | 225 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; |
226 | |||
227 | ok = 1; | 227 | ok = 1; |
228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 228 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
229 | argv, | 229 | argv, |
230 | "test-gnunet-daemon-hostlist", | 230 | "test-gnunet-daemon-hostlist", |
231 | "nohelp", | 231 | "nohelp", |
232 | options, | 232 | options, |
233 | &run, | 233 | &run, |
234 | &ok); | 234 | &ok); |
235 | return ok; | 235 | return ok; |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | int | 239 | int |
240 | main (int argc, char *argv[]) | 240 | main(int argc, char *argv[]) |
241 | { | 241 | { |
242 | int ret; | 242 | int ret; |
243 | 243 | ||
244 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 244 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
245 | "GNUNET_TEST_HOME"); | 245 | "GNUNET_TEST_HOME"); |
246 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 246 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
247 | "GNUNET_TEST_HOME"); | 247 | "GNUNET_TEST_HOME"); |
248 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 248 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
249 | "GNUNET_TEST_HOME"); | 249 | "GNUNET_TEST_HOME"); |
250 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); | 250 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); |
251 | ret = check (); | 251 | ret = check(); |
252 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 253 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", | 254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 255 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 257 | "GNUNET_TEST_HOME"); |
258 | return ret; | 258 | return ret; |
259 | } | 259 | } |
260 | 260 | ||