diff options
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_learning.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 659 |
1 files changed, 330 insertions, 329 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index a18255e6d..fa72ac828 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 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_learning.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist_learning.c |
22 | * @brief test for gnunet_daemon_hostslist.c | 22 | * @brief test for gnunet_daemon_hostslist.c |
@@ -35,13 +35,12 @@ | |||
35 | /** | 35 | /** |
36 | * How long until wait until testcases fails | 36 | * How long until wait until testcases fails |
37 | */ | 37 | */ |
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 180) |
39 | 39 | ||
40 | #define CHECK_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 40 | #define CHECK_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
41 | 41 | ||
42 | 42 | ||
43 | struct PeerContext | 43 | struct PeerContext { |
44 | { | ||
45 | struct GNUNET_CONFIGURATION_Handle *cfg; | 44 | struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
47 | struct GNUNET_CORE_Handle *core; | 46 | struct GNUNET_CORE_Handle *core; |
@@ -79,86 +78,86 @@ static struct GNUNET_STATISTICS_GetHandle *advsent_stat; | |||
79 | 78 | ||
80 | 79 | ||
81 | static void | 80 | static void |
82 | shutdown_testcase () | 81 | shutdown_testcase() |
83 | { | 82 | { |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 83 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | "Shutdown testcase....\n"); | 84 | "Shutdown testcase....\n"); |
86 | if (NULL != timeout_task) | 85 | if (NULL != timeout_task) |
87 | { | 86 | { |
88 | GNUNET_SCHEDULER_cancel (timeout_task); | 87 | GNUNET_SCHEDULER_cancel(timeout_task); |
89 | timeout_task = NULL; | 88 | timeout_task = NULL; |
90 | } | 89 | } |
91 | if (NULL != download_stats) | 90 | if (NULL != download_stats) |
92 | { | 91 | { |
93 | GNUNET_STATISTICS_get_cancel (download_stats); | 92 | GNUNET_STATISTICS_get_cancel(download_stats); |
94 | download_stats = NULL; | 93 | download_stats = NULL; |
95 | } | 94 | } |
96 | if (NULL != urisrecv_stat) | 95 | if (NULL != urisrecv_stat) |
97 | { | 96 | { |
98 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 97 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); |
99 | urisrecv_stat = NULL; | 98 | urisrecv_stat = NULL; |
100 | } | 99 | } |
101 | if (NULL != advsent_stat) | 100 | if (NULL != advsent_stat) |
102 | { | 101 | { |
103 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 102 | GNUNET_STATISTICS_get_cancel(advsent_stat); |
104 | advsent_stat = NULL; | 103 | advsent_stat = NULL; |
105 | } | 104 | } |
106 | if (NULL != adv_peer.stats) | 105 | if (NULL != adv_peer.stats) |
107 | { | 106 | { |
108 | GNUNET_STATISTICS_destroy (adv_peer.stats, GNUNET_NO); | 107 | GNUNET_STATISTICS_destroy(adv_peer.stats, GNUNET_NO); |
109 | adv_peer.stats = NULL; | 108 | adv_peer.stats = NULL; |
110 | } | 109 | } |
111 | if (NULL != learn_peer.stats) | 110 | if (NULL != learn_peer.stats) |
112 | { | 111 | { |
113 | GNUNET_STATISTICS_destroy (learn_peer.stats, GNUNET_NO); | 112 | GNUNET_STATISTICS_destroy(learn_peer.stats, GNUNET_NO); |
114 | learn_peer.stats = NULL; | 113 | learn_peer.stats = NULL; |
115 | } | 114 | } |
116 | if (NULL != check_task) | 115 | if (NULL != check_task) |
117 | { | 116 | { |
118 | GNUNET_SCHEDULER_cancel (check_task); | 117 | GNUNET_SCHEDULER_cancel(check_task); |
119 | check_task = NULL; | 118 | check_task = NULL; |
120 | } | 119 | } |
121 | if (NULL != current_adv_uri) | 120 | if (NULL != current_adv_uri) |
122 | { | 121 | { |
123 | GNUNET_free (current_adv_uri); | 122 | GNUNET_free(current_adv_uri); |
124 | current_adv_uri = NULL; | 123 | current_adv_uri = NULL; |
125 | } | 124 | } |
126 | if (NULL != adv_peer.core) | 125 | if (NULL != adv_peer.core) |
127 | { | 126 | { |
128 | GNUNET_CORE_disconnect (adv_peer.core); | 127 | GNUNET_CORE_disconnect(adv_peer.core); |
129 | adv_peer.core = NULL; | 128 | adv_peer.core = NULL; |
130 | } | 129 | } |
131 | if (NULL != learn_peer.core) | 130 | if (NULL != learn_peer.core) |
132 | { | 131 | { |
133 | GNUNET_CORE_disconnect (learn_peer.core); | 132 | GNUNET_CORE_disconnect(learn_peer.core); |
134 | learn_peer.core = NULL; | 133 | learn_peer.core = NULL; |
135 | } | 134 | } |
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
137 | "Killing hostlist server ARM process.\n"); | 136 | "Killing hostlist server ARM process.\n"); |
138 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, | 137 | if (0 != GNUNET_OS_process_kill(adv_peer.arm_proc, |
139 | GNUNET_TERM_SIG)) | 138 | GNUNET_TERM_SIG)) |
140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 139 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
141 | "kill"); | 140 | "kill"); |
142 | if (GNUNET_OK != | 141 | if (GNUNET_OK != |
143 | GNUNET_OS_process_wait (adv_peer.arm_proc)) | 142 | GNUNET_OS_process_wait(adv_peer.arm_proc)) |
144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 143 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
145 | "waitpid"); | 144 | "waitpid"); |
146 | GNUNET_OS_process_destroy (adv_peer.arm_proc); | 145 | GNUNET_OS_process_destroy(adv_peer.arm_proc); |
147 | adv_peer.arm_proc = NULL; | 146 | adv_peer.arm_proc = NULL; |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Killing hostlist client ARM process.\n"); | 148 | "Killing hostlist client ARM process.\n"); |
150 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, | 149 | if (0 != GNUNET_OS_process_kill(learn_peer.arm_proc, |
151 | GNUNET_TERM_SIG)) | 150 | GNUNET_TERM_SIG)) |
152 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 151 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
153 | "kill"); | 152 | "kill"); |
154 | if (GNUNET_OK != | 153 | if (GNUNET_OK != |
155 | GNUNET_OS_process_wait (learn_peer.arm_proc)) | 154 | GNUNET_OS_process_wait(learn_peer.arm_proc)) |
156 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 155 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
157 | "waitpid"); | 156 | "waitpid"); |
158 | GNUNET_OS_process_destroy (learn_peer.arm_proc); | 157 | GNUNET_OS_process_destroy(learn_peer.arm_proc); |
159 | learn_peer.arm_proc = NULL; | 158 | learn_peer.arm_proc = NULL; |
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
161 | "Shutdown complete....\n"); | 160 | "Shutdown complete....\n"); |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
@@ -166,111 +165,112 @@ shutdown_testcase () | |||
166 | * Timeout, give up. | 165 | * Timeout, give up. |
167 | */ | 166 | */ |
168 | static void | 167 | static void |
169 | timeout_error (void *cls) | 168 | timeout_error(void *cls) |
170 | { | 169 | { |
171 | timeout_task = NULL; | 170 | timeout_task = NULL; |
172 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
173 | "Timeout while executing testcase, test failed.\n"); | 172 | "Timeout while executing testcase, test failed.\n"); |
174 | timeout = GNUNET_YES; | 173 | timeout = GNUNET_YES; |
175 | shutdown_testcase (); | 174 | shutdown_testcase(); |
176 | } | 175 | } |
177 | 176 | ||
178 | 177 | ||
179 | static void | 178 | static void |
180 | process_downloads_done (void *cls, int success) | 179 | process_downloads_done(void *cls, int success) |
181 | { | 180 | { |
182 | download_stats = NULL; | 181 | download_stats = NULL; |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
186 | static void | 185 | static void |
187 | do_shutdown (void *cls) | 186 | do_shutdown(void *cls) |
188 | { | 187 | { |
189 | shutdown_testcase (); | 188 | shutdown_testcase(); |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
193 | static int | 192 | static int |
194 | process_downloads (void *cls, | 193 | process_downloads(void *cls, |
195 | const char *subsystem, | 194 | const char *subsystem, |
196 | const char *name, | 195 | const char *name, |
197 | uint64_t value, | 196 | uint64_t value, |
198 | int is_persistent) | 197 | int is_persistent) |
199 | { | 198 | { |
200 | if ( (value >= 2) && | 199 | if ((value >= 2) && |
201 | (GNUNET_NO == learned_hostlist_downloaded) ) | 200 | (GNUNET_NO == learned_hostlist_downloaded)) |
202 | { | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
204 | "Peer has successfully downloaded advertised URI\n"); | ||
205 | learned_hostlist_downloaded = GNUNET_YES; | ||
206 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) | ||
207 | { | 201 | { |
208 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 202 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
203 | "Peer has successfully downloaded advertised URI\n"); | ||
204 | learned_hostlist_downloaded = GNUNET_YES; | ||
205 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) | ||
206 | { | ||
207 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
208 | } | ||
209 | } | 209 | } |
210 | } | ||
211 | return GNUNET_OK; | 210 | return GNUNET_OK; |
212 | } | 211 | } |
213 | 212 | ||
214 | 213 | ||
215 | static void | 214 | static void |
216 | process_uris_recv_done (void *cls, int success) | 215 | process_uris_recv_done(void *cls, int success) |
217 | { | 216 | { |
218 | urisrecv_stat = NULL; | 217 | urisrecv_stat = NULL; |
219 | } | 218 | } |
220 | 219 | ||
221 | 220 | ||
222 | static int | 221 | static int |
223 | process_uris_recv (void *cls, | 222 | process_uris_recv(void *cls, |
224 | const char *subsystem, | 223 | const char *subsystem, |
225 | const char *name, | 224 | const char *name, |
226 | uint64_t value, | 225 | uint64_t value, |
227 | int is_persistent) | 226 | int is_persistent) |
228 | { | 227 | { |
229 | struct PeerContext *pc = cls; | 228 | struct PeerContext *pc = cls; |
230 | if ( (pc == &learn_peer) && | 229 | |
231 | (value == 1) && | 230 | if ((pc == &learn_peer) && |
232 | (learned_hostlist_saved == GNUNET_NO) ) | 231 | (value == 1) && |
233 | { | 232 | (learned_hostlist_saved == GNUNET_NO)) |
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
235 | "Peer has successfully saved advertised URI\n"); | ||
236 | learned_hostlist_saved = GNUNET_YES; | ||
237 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | ||
238 | (adv_sent == GNUNET_YES) ) | ||
239 | { | 233 | { |
240 | GNUNET_SCHEDULER_add_now (&do_shutdown, | 234 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
241 | NULL); | 235 | "Peer has successfully saved advertised URI\n"); |
236 | learned_hostlist_saved = GNUNET_YES; | ||
237 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
238 | (adv_sent == GNUNET_YES)) | ||
239 | { | ||
240 | GNUNET_SCHEDULER_add_now(&do_shutdown, | ||
241 | NULL); | ||
242 | } | ||
242 | } | 243 | } |
243 | } | ||
244 | return GNUNET_OK; | 244 | return GNUNET_OK; |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | static void | 248 | static void |
249 | process_adv_sent_done (void *cls, int success) | 249 | process_adv_sent_done(void *cls, int success) |
250 | { | 250 | { |
251 | advsent_stat = NULL; | 251 | advsent_stat = NULL; |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | static int | 255 | static int |
256 | process_adv_sent (void *cls, | 256 | process_adv_sent(void *cls, |
257 | const char *subsystem, | 257 | const char *subsystem, |
258 | const char *name, | 258 | const char *name, |
259 | uint64_t value, | 259 | uint64_t value, |
260 | int is_persistent) | 260 | int is_persistent) |
261 | { | 261 | { |
262 | if ((value >= 1) && (adv_sent == GNUNET_NO)) | 262 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
265 | "Server has successfully sent advertisement\n"); | ||
266 | adv_sent = GNUNET_YES; | ||
267 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
268 | (learned_hostlist_saved == GNUNET_YES)) | ||
269 | { | 263 | { |
270 | GNUNET_SCHEDULER_add_now (&do_shutdown, | 264 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
271 | NULL); | 265 | "Server has successfully sent advertisement\n"); |
266 | adv_sent = GNUNET_YES; | ||
267 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
268 | (learned_hostlist_saved == GNUNET_YES)) | ||
269 | { | ||
270 | GNUNET_SCHEDULER_add_now(&do_shutdown, | ||
271 | NULL); | ||
272 | } | ||
272 | } | 273 | } |
273 | } | ||
274 | return GNUNET_OK; | 274 | return GNUNET_OK; |
275 | } | 275 | } |
276 | 276 | ||
@@ -279,69 +279,70 @@ process_adv_sent (void *cls, | |||
279 | * Check the server statistics regularly | 279 | * Check the server statistics regularly |
280 | */ | 280 | */ |
281 | static void | 281 | static void |
282 | check_statistics (void *cls) | 282 | check_statistics(void *cls) |
283 | { | 283 | { |
284 | char *stat; | 284 | char *stat; |
285 | 285 | ||
286 | check_task = NULL; | 286 | check_task = NULL; |
287 | GNUNET_asprintf (&stat, | 287 | GNUNET_asprintf(&stat, |
288 | gettext_noop ("# advertised URI `%s' downloaded"), | 288 | gettext_noop("# advertised URI `%s' downloaded"), |
289 | current_adv_uri); | 289 | current_adv_uri); |
290 | if (NULL != learn_peer.stats) | 290 | if (NULL != learn_peer.stats) |
291 | { | 291 | { |
292 | if (NULL != download_stats) | 292 | if (NULL != download_stats) |
293 | GNUNET_STATISTICS_get_cancel (download_stats); | 293 | GNUNET_STATISTICS_get_cancel(download_stats); |
294 | download_stats = | 294 | download_stats = |
295 | GNUNET_STATISTICS_get (learn_peer.stats, | 295 | GNUNET_STATISTICS_get(learn_peer.stats, |
296 | "hostlist", | 296 | "hostlist", |
297 | stat, | 297 | stat, |
298 | &process_downloads_done, | 298 | &process_downloads_done, |
299 | &process_downloads, | 299 | &process_downloads, |
300 | &learn_peer); | 300 | &learn_peer); |
301 | if (NULL != urisrecv_stat) | 301 | if (NULL != urisrecv_stat) |
302 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 302 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); |
303 | urisrecv_stat = | 303 | urisrecv_stat = |
304 | GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", | 304 | GNUNET_STATISTICS_get(learn_peer.stats, "hostlist", |
305 | gettext_noop ("# advertised hostlist URIs"), | 305 | gettext_noop("# advertised hostlist URIs"), |
306 | &process_uris_recv_done, &process_uris_recv, | 306 | &process_uris_recv_done, &process_uris_recv, |
307 | &learn_peer); | 307 | &learn_peer); |
308 | } | 308 | } |
309 | GNUNET_free (stat); | 309 | GNUNET_free(stat); |
310 | if (NULL != adv_peer.stats) | 310 | if (NULL != adv_peer.stats) |
311 | { | 311 | { |
312 | if (NULL != advsent_stat) | 312 | if (NULL != advsent_stat) |
313 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 313 | GNUNET_STATISTICS_get_cancel(advsent_stat); |
314 | advsent_stat = | 314 | advsent_stat = |
315 | GNUNET_STATISTICS_get (adv_peer.stats, "hostlist", | 315 | GNUNET_STATISTICS_get(adv_peer.stats, "hostlist", |
316 | gettext_noop ("# hostlist advertisements send"), | 316 | gettext_noop("# hostlist advertisements send"), |
317 | &process_adv_sent_done, | 317 | &process_adv_sent_done, |
318 | &process_adv_sent, | 318 | &process_adv_sent, |
319 | NULL); | 319 | NULL); |
320 | } | 320 | } |
321 | check_task = | 321 | check_task = |
322 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, | 322 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, |
323 | &check_statistics, | 323 | &check_statistics, |
324 | NULL); | 324 | NULL); |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | static int | 328 | static int |
329 | check_ad_arrive (void *cls, | 329 | check_ad_arrive(void *cls, |
330 | const struct GNUNET_MessageHeader *message) | 330 | const struct GNUNET_MessageHeader *message) |
331 | { | 331 | { |
332 | const char *end = (const char *) &message[1]; | 332 | const char *end = (const char *)&message[1]; |
333 | if ('\0' != end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) | 333 | |
334 | { | 334 | if ('\0' != end[ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - 1]) |
335 | GNUNET_break (0); | 335 | { |
336 | return GNUNET_SYSERR; | 336 | GNUNET_break(0); |
337 | } | 337 | return GNUNET_SYSERR; |
338 | } | ||
338 | return GNUNET_OK; | 339 | return GNUNET_OK; |
339 | } | 340 | } |
340 | 341 | ||
341 | 342 | ||
342 | static void | 343 | static void |
343 | handle_ad_arrive (void *cls, | 344 | handle_ad_arrive(void *cls, |
344 | const struct GNUNET_MessageHeader *message) | 345 | const struct GNUNET_MessageHeader *message) |
345 | { | 346 | { |
346 | char *hostname; | 347 | char *hostname; |
347 | char *expected_uri; | 348 | char *expected_uri; |
@@ -349,132 +350,132 @@ handle_ad_arrive (void *cls, | |||
349 | const char *end; | 350 | const char *end; |
350 | 351 | ||
351 | if (GNUNET_SYSERR == | 352 | if (GNUNET_SYSERR == |
352 | GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, | 353 | GNUNET_CONFIGURATION_get_value_number(adv_peer.cfg, |
353 | "HOSTLIST", | 354 | "HOSTLIST", |
354 | "HTTPPORT", | 355 | "HTTPPORT", |
355 | &port)) | 356 | &port)) |
356 | { | 357 | { |
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 358 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
358 | "Could not read advertising server's configuration\n"); | 359 | "Could not read advertising server's configuration\n"); |
359 | return; | 360 | return; |
360 | } | 361 | } |
361 | 362 | ||
362 | if (GNUNET_SYSERR == | 363 | if (GNUNET_SYSERR == |
363 | GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | 364 | GNUNET_CONFIGURATION_get_value_string(adv_peer.cfg, |
364 | "HOSTLIST", | 365 | "HOSTLIST", |
365 | "EXTERNAL_DNS_NAME", | 366 | "EXTERNAL_DNS_NAME", |
366 | &hostname)) | 367 | &hostname)) |
367 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 368 | hostname = GNUNET_RESOLVER_local_fqdn_get(); |
368 | GNUNET_asprintf (&expected_uri, | 369 | GNUNET_asprintf(&expected_uri, |
369 | "http://%s:%u/", | 370 | "http://%s:%u/", |
370 | hostname != NULL ? hostname : "localhost", | 371 | hostname != NULL ? hostname : "localhost", |
371 | (unsigned int) port); | 372 | (unsigned int)port); |
372 | end = (const char *) &message[1]; | 373 | end = (const char *)&message[1]; |
373 | current_adv_uri = GNUNET_strdup (end); | 374 | current_adv_uri = GNUNET_strdup(end); |
374 | if (0 == strcmp (expected_uri, | 375 | if (0 == strcmp(expected_uri, |
375 | current_adv_uri)) | 376 | current_adv_uri)) |
376 | { | 377 | { |
377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 378 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
378 | "Received hostlist advertisement with URI `%s' as expected\n", | 379 | "Received hostlist advertisement with URI `%s' as expected\n", |
379 | current_adv_uri); | 380 | current_adv_uri); |
380 | adv_arrived = GNUNET_YES; | 381 | adv_arrived = GNUNET_YES; |
381 | adv_sent = GNUNET_YES; | 382 | adv_sent = GNUNET_YES; |
382 | } | 383 | } |
383 | else | 384 | else |
384 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 385 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
385 | "Expected URI `%s' and received URI `%s' differ\n", | 386 | "Expected URI `%s' and received URI `%s' differ\n", |
386 | expected_uri, | 387 | expected_uri, |
387 | current_adv_uri); | 388 | current_adv_uri); |
388 | GNUNET_free (expected_uri); | 389 | GNUNET_free(expected_uri); |
389 | GNUNET_free_non_null (hostname); | 390 | GNUNET_free_non_null(hostname); |
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||
393 | static void | 394 | static void |
394 | setup_learn_peer (struct PeerContext *p, | 395 | setup_learn_peer(struct PeerContext *p, |
395 | const char *cfgname) | 396 | const char *cfgname) |
396 | { | 397 | { |
397 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 398 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
398 | GNUNET_MQ_hd_var_size (ad_arrive, | 399 | GNUNET_MQ_hd_var_size(ad_arrive, |
399 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 400 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
400 | struct GNUNET_MessageHeader, | 401 | struct GNUNET_MessageHeader, |
401 | NULL), | 402 | NULL), |
402 | GNUNET_MQ_handler_end () | 403 | GNUNET_MQ_handler_end() |
403 | }; | 404 | }; |
404 | char *filename; | 405 | char *filename; |
405 | unsigned int result; | 406 | unsigned int result; |
406 | char *binary; | 407 | char *binary; |
407 | 408 | ||
408 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 409 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
409 | p->cfg = GNUNET_CONFIGURATION_create (); | 410 | p->cfg = GNUNET_CONFIGURATION_create(); |
410 | p->arm_proc = | 411 | p->arm_proc = |
411 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 412 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
412 | NULL, NULL, NULL, | 413 | NULL, NULL, NULL, |
413 | binary, | 414 | binary, |
414 | "gnunet-service-arm", | 415 | "gnunet-service-arm", |
415 | "-c", cfgname, NULL); | 416 | "-c", cfgname, NULL); |
416 | GNUNET_assert (GNUNET_OK == | 417 | GNUNET_assert(GNUNET_OK == |
417 | GNUNET_CONFIGURATION_load (p->cfg, | 418 | GNUNET_CONFIGURATION_load(p->cfg, |
418 | cfgname)); | 419 | cfgname)); |
419 | if (GNUNET_OK == | 420 | if (GNUNET_OK == |
420 | GNUNET_CONFIGURATION_get_value_string (p->cfg, | 421 | GNUNET_CONFIGURATION_get_value_string(p->cfg, |
421 | "HOSTLIST", | 422 | "HOSTLIST", |
422 | "HOSTLISTFILE", | 423 | "HOSTLISTFILE", |
423 | &filename)) | 424 | &filename)) |
424 | { | ||
425 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
426 | { | 425 | { |
427 | result = unlink (filename); | 426 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) |
428 | if (result == 0) | 427 | { |
429 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 428 | result = unlink(filename); |
430 | _("Hostlist file `%s' was removed\n"), | 429 | if (result == 0) |
431 | filename); | 430 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
431 | _("Hostlist file `%s' was removed\n"), | ||
432 | filename); | ||
433 | } | ||
434 | GNUNET_free(filename); | ||
432 | } | 435 | } |
433 | GNUNET_free (filename); | 436 | p->core = GNUNET_CORE_connect(p->cfg, |
434 | } | 437 | NULL, |
435 | p->core = GNUNET_CORE_connect (p->cfg, | 438 | NULL, |
436 | NULL, | 439 | NULL, |
437 | NULL, | 440 | NULL, |
438 | NULL, | 441 | learn_handlers); |
439 | NULL, | 442 | GNUNET_assert(NULL != p->core); |
440 | learn_handlers); | 443 | p->stats = GNUNET_STATISTICS_create("hostlist", |
441 | GNUNET_assert (NULL != p->core); | 444 | p->cfg); |
442 | p->stats = GNUNET_STATISTICS_create ("hostlist", | 445 | GNUNET_assert(NULL != p->stats); |
443 | p->cfg); | 446 | GNUNET_free(binary); |
444 | GNUNET_assert (NULL != p->stats); | ||
445 | GNUNET_free (binary); | ||
446 | } | 447 | } |
447 | 448 | ||
448 | 449 | ||
449 | static void | 450 | static void |
450 | setup_adv_peer (struct PeerContext *p, | 451 | setup_adv_peer(struct PeerContext *p, |
451 | const char *cfgname) | 452 | const char *cfgname) |
452 | { | 453 | { |
453 | char *binary; | 454 | char *binary; |
454 | 455 | ||
455 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 456 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
456 | p->cfg = GNUNET_CONFIGURATION_create (); | 457 | p->cfg = GNUNET_CONFIGURATION_create(); |
457 | p->arm_proc = | 458 | p->arm_proc = |
458 | GNUNET_OS_start_process (GNUNET_YES, | 459 | GNUNET_OS_start_process(GNUNET_YES, |
459 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 460 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
460 | NULL, NULL, NULL, | 461 | NULL, NULL, NULL, |
461 | binary, | 462 | binary, |
462 | "gnunet-service-arm", | 463 | "gnunet-service-arm", |
463 | "-c", cfgname, NULL); | 464 | "-c", cfgname, NULL); |
464 | GNUNET_assert (GNUNET_OK == | 465 | GNUNET_assert(GNUNET_OK == |
465 | GNUNET_CONFIGURATION_load (p->cfg, | 466 | GNUNET_CONFIGURATION_load(p->cfg, |
466 | cfgname)); | 467 | cfgname)); |
467 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 468 | p->stats = GNUNET_STATISTICS_create("hostlist", p->cfg); |
468 | GNUNET_assert (NULL != p->stats); | 469 | GNUNET_assert(NULL != p->stats); |
469 | GNUNET_free (binary); | 470 | GNUNET_free(binary); |
470 | } | 471 | } |
471 | 472 | ||
472 | 473 | ||
473 | static void | 474 | static void |
474 | run (void *cls, | 475 | run(void *cls, |
475 | char *const *args, | 476 | char *const *args, |
476 | const char *cfgfile, | 477 | const char *cfgfile, |
477 | const struct GNUNET_CONFIGURATION_Handle *c) | 478 | const struct GNUNET_CONFIGURATION_Handle *c) |
478 | { | 479 | { |
479 | timeout = GNUNET_NO; | 480 | timeout = GNUNET_NO; |
480 | adv_sent = GNUNET_NO; | 481 | adv_sent = GNUNET_NO; |
@@ -485,22 +486,22 @@ run (void *cls, | |||
485 | 486 | ||
486 | cfg = c; | 487 | cfg = c; |
487 | 488 | ||
488 | setup_adv_peer (&adv_peer, | 489 | setup_adv_peer(&adv_peer, |
489 | "test_learning_adv_peer.conf"); | 490 | "test_learning_adv_peer.conf"); |
490 | setup_learn_peer (&learn_peer, | 491 | setup_learn_peer(&learn_peer, |
491 | "test_learning_learn_peer.conf"); | 492 | "test_learning_learn_peer.conf"); |
492 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 493 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
493 | &timeout_error, | 494 | &timeout_error, |
494 | NULL); | 495 | NULL); |
495 | check_task = | 496 | check_task = |
496 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, | 497 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, |
497 | &check_statistics, | 498 | &check_statistics, |
498 | NULL); | 499 | NULL); |
499 | } | 500 | } |
500 | 501 | ||
501 | 502 | ||
502 | static int | 503 | static int |
503 | check () | 504 | check() |
504 | { | 505 | { |
505 | unsigned int failed; | 506 | unsigned int failed; |
506 | 507 | ||
@@ -513,44 +514,44 @@ check () | |||
513 | GNUNET_GETOPT_OPTION_END | 514 | GNUNET_GETOPT_OPTION_END |
514 | }; | 515 | }; |
515 | 516 | ||
516 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 517 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
517 | argv, | 518 | argv, |
518 | "test-gnunet-daemon-hostlist-learning", | 519 | "test-gnunet-daemon-hostlist-learning", |
519 | "nohelp", | 520 | "nohelp", |
520 | options, | 521 | options, |
521 | &run, | 522 | &run, |
522 | NULL); | 523 | NULL); |
523 | failed = GNUNET_NO; | 524 | failed = GNUNET_NO; |
524 | if (timeout == GNUNET_YES) | 525 | if (timeout == GNUNET_YES) |
525 | { | 526 | { |
526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 527 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
527 | "Testcase timeout\n"); | 528 | "Testcase timeout\n"); |
528 | failed = GNUNET_YES; | 529 | failed = GNUNET_YES; |
529 | } | 530 | } |
530 | if (adv_arrived != GNUNET_YES) | 531 | if (adv_arrived != GNUNET_YES) |
531 | { | 532 | { |
532 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
533 | "Learning peer did not receive advertisement from server\n"); | 534 | "Learning peer did not receive advertisement from server\n"); |
534 | failed = GNUNET_YES; | 535 | failed = GNUNET_YES; |
535 | } | 536 | } |
536 | if (learned_hostlist_saved == GNUNET_NO) | 537 | if (learned_hostlist_saved == GNUNET_NO) |
537 | { | 538 | { |
538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 539 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
539 | "Advertised hostlist was not saved in datastore\n"); | 540 | "Advertised hostlist was not saved in datastore\n"); |
540 | failed = GNUNET_YES; | 541 | failed = GNUNET_YES; |
541 | } | 542 | } |
542 | if (learned_hostlist_downloaded == GNUNET_NO) | 543 | if (learned_hostlist_downloaded == GNUNET_NO) |
543 | { | 544 | { |
544 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 545 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
545 | "Advertised hostlist could not be downloaded from server\n"); | 546 | "Advertised hostlist could not be downloaded from server\n"); |
546 | failed = GNUNET_YES; | 547 | failed = GNUNET_YES; |
547 | } | 548 | } |
548 | if (adv_sent == GNUNET_NO) | 549 | if (adv_sent == GNUNET_NO) |
549 | { | 550 | { |
550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 551 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
551 | "Advertised was not sent from server to client\n"); | 552 | "Advertised was not sent from server to client\n"); |
552 | failed = GNUNET_YES; | 553 | failed = GNUNET_YES; |
553 | } | 554 | } |
554 | if (GNUNET_YES == failed) | 555 | if (GNUNET_YES == failed) |
555 | return GNUNET_YES; | 556 | return GNUNET_YES; |
556 | return GNUNET_NO; | 557 | return GNUNET_NO; |
@@ -558,29 +559,29 @@ check () | |||
558 | 559 | ||
559 | 560 | ||
560 | int | 561 | int |
561 | main (int argc, char *argv[]) | 562 | main(int argc, char *argv[]) |
562 | { | 563 | { |
563 | int ret; | 564 | int ret; |
564 | 565 | ||
565 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", | 566 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", |
566 | "GNUNET_TEST_HOME"); | 567 | "GNUNET_TEST_HOME"); |
567 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", | 568 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", |
568 | "GNUNET_TEST_HOME"); | 569 | "GNUNET_TEST_HOME"); |
569 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | 570 | GNUNET_log_setup("test-gnunet-daemon-hostlist", |
570 | "WARNING", | 571 | "WARNING", |
571 | NULL); | 572 | NULL); |
572 | ret = check (); | 573 | ret = check(); |
573 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", | 574 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", |
574 | "GNUNET_TEST_HOME"); | 575 | "GNUNET_TEST_HOME"); |
575 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", | 576 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", |
576 | "GNUNET_TEST_HOME"); | 577 | "GNUNET_TEST_HOME"); |
577 | if (GNUNET_YES == | 578 | if (GNUNET_YES == |
578 | GNUNET_DISK_file_test ("hostlists_learn_peer.file")) | 579 | GNUNET_DISK_file_test("hostlists_learn_peer.file")) |
579 | { | 580 | { |
580 | if (0 == unlink ("hostlists_learn_peer.file")) | 581 | if (0 == unlink("hostlists_learn_peer.file")) |
581 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 582 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
582 | "Hostlist file hostlists_learn_peer.file was removed\n"); | 583 | "Hostlist file hostlists_learn_peer.file was removed\n"); |
583 | } | 584 | } |
584 | return ret; | 585 | return ret; |
585 | } | 586 | } |
586 | 587 | ||