diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hostlist | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 267 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.c | 1765 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_client.h | 14 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 881 | ||||
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.h | 12 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 226 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 647 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 245 |
8 files changed, 2035 insertions, 2022 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 7c1863dc0..bf6542d7f 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -102,7 +102,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
102 | * unaligned!) | 102 | * unaligned!) |
103 | * 4) address (address-length bytes; possibly unaligned!) | 103 | * 4) address (address-length bytes; possibly unaligned!) |
104 | */ | 104 | */ |
105 | struct GNUNET_HOSTLIST_ADV_Message { | 105 | struct GNUNET_HOSTLIST_ADV_Message |
106 | { | ||
106 | /** | 107 | /** |
107 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. | 108 | * Type will be GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT. |
108 | */ | 109 | */ |
@@ -129,8 +130,8 @@ static struct GNUNET_PeerIdentity me; | |||
129 | * @param my_identity our peer's identity | 130 | * @param my_identity our peer's identity |
130 | */ | 131 | */ |
131 | static void | 132 | static void |
132 | core_init(void *cls, | 133 | core_init (void *cls, |
133 | const struct GNUNET_PeerIdentity *my_identity) | 134 | const struct GNUNET_PeerIdentity *my_identity) |
134 | { | 135 | { |
135 | me = *my_identity; | 136 | me = *my_identity; |
136 | } | 137 | } |
@@ -144,26 +145,26 @@ core_init(void *cls, | |||
144 | * @return #GNUNET_OK if message is well-formed | 145 | * @return #GNUNET_OK if message is well-formed |
145 | */ | 146 | */ |
146 | static int | 147 | static int |
147 | check_advertisement(void *cls, | 148 | check_advertisement (void *cls, |
148 | const struct GNUNET_MessageHeader *message) | 149 | const struct GNUNET_MessageHeader *message) |
149 | { | 150 | { |
150 | size_t size; | 151 | size_t size; |
151 | size_t uri_size; | 152 | size_t uri_size; |
152 | const char *uri; | 153 | const char *uri; |
153 | 154 | ||
154 | size = ntohs(message->size); | 155 | size = ntohs (message->size); |
155 | if (size <= sizeof(struct GNUNET_MessageHeader)) | 156 | if (size <= sizeof(struct GNUNET_MessageHeader)) |
156 | { | 157 | { |
157 | GNUNET_break_op(0); | 158 | GNUNET_break_op (0); |
158 | return GNUNET_SYSERR; | 159 | return GNUNET_SYSERR; |
159 | } | 160 | } |
160 | uri = (const char *)&message[1]; | 161 | uri = (const char *) &message[1]; |
161 | uri_size = size - sizeof(struct GNUNET_MessageHeader); | 162 | uri_size = size - sizeof(struct GNUNET_MessageHeader); |
162 | if (uri[uri_size - 1] != '\0') | 163 | if (uri[uri_size - 1] != '\0') |
163 | { | 164 | { |
164 | GNUNET_break_op(0); | 165 | GNUNET_break_op (0); |
165 | return GNUNET_SYSERR; | 166 | return GNUNET_SYSERR; |
166 | } | 167 | } |
167 | return GNUNET_OK; | 168 | return GNUNET_OK; |
168 | } | 169 | } |
169 | 170 | ||
@@ -176,13 +177,13 @@ check_advertisement(void *cls, | |||
176 | * @return #GNUNET_OK on success | 177 | * @return #GNUNET_OK on success |
177 | */ | 178 | */ |
178 | static void | 179 | static void |
179 | handle_advertisement(void *cls, | 180 | handle_advertisement (void *cls, |
180 | const struct GNUNET_MessageHeader *message) | 181 | const struct GNUNET_MessageHeader *message) |
181 | { | 182 | { |
182 | const char *uri = (const char *)&message[1]; | 183 | const char *uri = (const char *) &message[1]; |
183 | 184 | ||
184 | GNUNET_assert(NULL != client_adv_handler); | 185 | GNUNET_assert (NULL != client_adv_handler); |
185 | (void)(*client_adv_handler)(uri); | 186 | (void) (*client_adv_handler)(uri); |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
@@ -196,28 +197,28 @@ handle_advertisement(void *cls, | |||
196 | * @return peer | 197 | * @return peer |
197 | */ | 198 | */ |
198 | static void * | 199 | static void * |
199 | connect_handler(void *cls, | 200 | connect_handler (void *cls, |
200 | const struct GNUNET_PeerIdentity *peer, | 201 | const struct GNUNET_PeerIdentity *peer, |
201 | struct GNUNET_MQ_Handle *mq) | 202 | struct GNUNET_MQ_Handle *mq) |
202 | { | 203 | { |
203 | if (0 == GNUNET_memcmp(&me, | 204 | if (0 == GNUNET_memcmp (&me, |
204 | peer)) | 205 | peer)) |
205 | return NULL; | 206 | return NULL; |
206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
207 | "A new peer connected, notifying client and server\n"); | 208 | "A new peer connected, notifying client and server\n"); |
208 | if (NULL != client_ch) | 209 | if (NULL != client_ch) |
209 | GNUNET_assert(NULL == | 210 | GNUNET_assert (NULL == |
210 | (*client_ch)(cls, | 211 | (*client_ch)(cls, |
211 | peer, | 212 | peer, |
212 | mq)); | 213 | mq)); |
213 | #if HAVE_MHD | 214 | #if HAVE_MHD |
214 | if (NULL != server_ch) | 215 | if (NULL != server_ch) |
215 | GNUNET_assert(NULL == | 216 | GNUNET_assert (NULL == |
216 | (*server_ch)(cls, | 217 | (*server_ch)(cls, |
217 | peer, | 218 | peer, |
218 | mq)); | 219 | mq)); |
219 | #endif | 220 | #endif |
220 | return (void *)peer; | 221 | return (void *) peer; |
221 | } | 222 | } |
222 | 223 | ||
223 | 224 | ||
@@ -229,12 +230,12 @@ connect_handler(void *cls, | |||
229 | * @param peer peer identity this notification is about | 230 | * @param peer peer identity this notification is about |
230 | */ | 231 | */ |
231 | static void | 232 | static void |
232 | disconnect_handler(void *cls, | 233 | disconnect_handler (void *cls, |
233 | const struct GNUNET_PeerIdentity *peer, | 234 | const struct GNUNET_PeerIdentity *peer, |
234 | void *internal_cls) | 235 | void *internal_cls) |
235 | { | 236 | { |
236 | if (0 == GNUNET_memcmp(&me, | 237 | if (0 == GNUNET_memcmp (&me, |
237 | peer)) | 238 | peer)) |
238 | return; | 239 | return; |
239 | /* call hostlist client disconnect handler */ | 240 | /* call hostlist client disconnect handler */ |
240 | if (NULL != client_dh) | 241 | if (NULL != client_dh) |
@@ -251,31 +252,31 @@ disconnect_handler(void *cls, | |||
251 | * @param cls NULL | 252 | * @param cls NULL |
252 | */ | 253 | */ |
253 | static void | 254 | static void |
254 | cleaning_task(void *cls) | 255 | cleaning_task (void *cls) |
255 | { | 256 | { |
256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
257 | "Hostlist daemon is shutting down\n"); | 258 | "Hostlist daemon is shutting down\n"); |
258 | if (NULL != core) | 259 | if (NULL != core) |
259 | { | 260 | { |
260 | GNUNET_CORE_disconnect(core); | 261 | GNUNET_CORE_disconnect (core); |
261 | core = NULL; | 262 | core = NULL; |
262 | } | 263 | } |
263 | if (bootstrapping) | 264 | if (bootstrapping) |
264 | { | 265 | { |
265 | GNUNET_HOSTLIST_client_stop(); | 266 | GNUNET_HOSTLIST_client_stop (); |
266 | } | 267 | } |
267 | #if HAVE_MHD | 268 | #if HAVE_MHD |
268 | if (provide_hostlist) | 269 | if (provide_hostlist) |
269 | { | 270 | { |
270 | GNUNET_HOSTLIST_server_stop(); | 271 | GNUNET_HOSTLIST_server_stop (); |
271 | } | 272 | } |
272 | #endif | 273 | #endif |
273 | if (NULL != stats) | 274 | if (NULL != stats) |
274 | { | 275 | { |
275 | GNUNET_STATISTICS_destroy(stats, | 276 | GNUNET_STATISTICS_destroy (stats, |
276 | GNUNET_NO); | 277 | GNUNET_NO); |
277 | stats = NULL; | 278 | stats = NULL; |
278 | } | 279 | } |
279 | } | 280 | } |
280 | 281 | ||
281 | 282 | ||
@@ -288,72 +289,73 @@ cleaning_task(void *cls) | |||
288 | * @param cfg configuration | 289 | * @param cfg configuration |
289 | */ | 290 | */ |
290 | static void | 291 | static void |
291 | run(void *cls, | 292 | run (void *cls, |
292 | char *const *args, | 293 | char *const *args, |
293 | const char *cfgfile, | 294 | const char *cfgfile, |
294 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 295 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
295 | { | 296 | { |
296 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 297 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
297 | GNUNET_MQ_hd_var_size(advertisement, | 298 | GNUNET_MQ_hd_var_size (advertisement, |
298 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 299 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
299 | struct GNUNET_MessageHeader, | 300 | struct GNUNET_MessageHeader, |
300 | NULL), | 301 | NULL), |
301 | GNUNET_MQ_handler_end() | 302 | GNUNET_MQ_handler_end () |
302 | }; | 303 | }; |
303 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { | 304 | struct GNUNET_MQ_MessageHandler no_learn_handlers[] = { |
304 | GNUNET_MQ_handler_end() | 305 | GNUNET_MQ_handler_end () |
305 | }; | 306 | }; |
306 | 307 | ||
307 | if ((!bootstrapping) && (!learning) | 308 | if ((! bootstrapping) && (! learning) |
308 | #if HAVE_MHD | 309 | #if HAVE_MHD |
309 | && (!provide_hostlist) | 310 | && (! provide_hostlist) |
310 | #endif | 311 | #endif |
311 | ) | 312 | ) |
312 | { | 313 | { |
313 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
314 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); | 315 | _ ( |
315 | return; | 316 | "None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); |
316 | } | 317 | return; |
317 | stats = GNUNET_STATISTICS_create("hostlist", cfg); | 318 | } |
319 | stats = GNUNET_STATISTICS_create ("hostlist", cfg); | ||
318 | if (NULL == stats) | 320 | if (NULL == stats) |
319 | { | 321 | { |
320 | GNUNET_break(0); | 322 | GNUNET_break (0); |
321 | return; | 323 | return; |
322 | } | 324 | } |
323 | if (bootstrapping) | 325 | if (bootstrapping) |
324 | GNUNET_HOSTLIST_client_start(cfg, | 326 | GNUNET_HOSTLIST_client_start (cfg, |
325 | stats, | 327 | stats, |
326 | &client_ch, | 328 | &client_ch, |
327 | &client_dh, | 329 | &client_dh, |
328 | &client_adv_handler, | 330 | &client_adv_handler, |
329 | learning); | 331 | learning); |
330 | core = | 332 | core = |
331 | GNUNET_CORE_connect(cfg, | 333 | GNUNET_CORE_connect (cfg, |
332 | NULL, | 334 | NULL, |
333 | &core_init, | 335 | &core_init, |
334 | &connect_handler, | 336 | &connect_handler, |
335 | &disconnect_handler, | 337 | &disconnect_handler, |
336 | learning ? learn_handlers : no_learn_handlers); | 338 | learning ? learn_handlers : no_learn_handlers); |
337 | 339 | ||
338 | 340 | ||
339 | #if HAVE_MHD | 341 | #if HAVE_MHD |
340 | if (provide_hostlist) | 342 | if (provide_hostlist) |
341 | GNUNET_HOSTLIST_server_start(cfg, | 343 | GNUNET_HOSTLIST_server_start (cfg, |
342 | stats, | 344 | stats, |
343 | core, | 345 | core, |
344 | &server_ch, | 346 | &server_ch, |
345 | advertising); | 347 | advertising); |
346 | #endif | 348 | #endif |
347 | GNUNET_SCHEDULER_add_shutdown(&cleaning_task, | 349 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, |
348 | NULL); | 350 | NULL); |
349 | 351 | ||
350 | if (NULL == core) | 352 | if (NULL == core) |
351 | { | 353 | { |
352 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
353 | _("Failed to connect to `%s' service.\n"), "core"); | 355 | _ ("Failed to connect to `%s' service.\n"), "core"); |
354 | GNUNET_SCHEDULER_shutdown(); | 356 | GNUNET_SCHEDULER_shutdown (); |
355 | return; | 357 | return; |
356 | } | 358 | } |
357 | } | 359 | } |
358 | 360 | ||
359 | 361 | ||
@@ -365,46 +367,49 @@ run(void *cls, | |||
365 | * @return 0 ok, 1 on error | 367 | * @return 0 ok, 1 on error |
366 | */ | 368 | */ |
367 | int | 369 | int |
368 | main(int argc, char *const *argv) | 370 | main (int argc, char *const *argv) |
369 | { | 371 | { |
370 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 372 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
371 | #if HAVE_MHD | 373 | #if HAVE_MHD |
372 | GNUNET_GETOPT_option_flag('a', | 374 | GNUNET_GETOPT_option_flag ('a', |
373 | "advertise", | 375 | "advertise", |
374 | gettext_noop("advertise our hostlist to other peers"), | 376 | gettext_noop ( |
375 | &advertising), | 377 | "advertise our hostlist to other peers"), |
378 | &advertising), | ||
376 | #endif | 379 | #endif |
377 | GNUNET_GETOPT_option_flag('b', | 380 | GNUNET_GETOPT_option_flag ('b', |
378 | "bootstrap", | 381 | "bootstrap", |
379 | gettext_noop("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 382 | gettext_noop ( |
380 | &bootstrapping), | 383 | "bootstrap using hostlists (it is highly recommended that you always use this option)"), |
381 | GNUNET_GETOPT_option_flag('e', | 384 | &bootstrapping), |
382 | "enable-learning", | 385 | GNUNET_GETOPT_option_flag ('e', |
383 | gettext_noop("enable learning about hostlist servers from other peers"), | 386 | "enable-learning", |
384 | &learning), | 387 | gettext_noop ( |
388 | "enable learning about hostlist servers from other peers"), | ||
389 | &learning), | ||
385 | #if HAVE_MHD | 390 | #if HAVE_MHD |
386 | GNUNET_GETOPT_option_flag('p', | 391 | GNUNET_GETOPT_option_flag ('p', |
387 | "provide-hostlist", | 392 | "provide-hostlist", |
388 | gettext_noop("provide a hostlist server"), | 393 | gettext_noop ("provide a hostlist server"), |
389 | &provide_hostlist), | 394 | &provide_hostlist), |
390 | #endif | 395 | #endif |
391 | GNUNET_GETOPT_OPTION_END | 396 | GNUNET_GETOPT_OPTION_END |
392 | }; | 397 | }; |
393 | 398 | ||
394 | int ret; | 399 | int ret; |
395 | 400 | ||
396 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 401 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
397 | return 2; | 402 | return 2; |
398 | 403 | ||
399 | GNUNET_log_setup("hostlist", "WARNING", NULL); | 404 | GNUNET_log_setup ("hostlist", "WARNING", NULL); |
400 | ret = | 405 | ret = |
401 | (GNUNET_OK == | 406 | (GNUNET_OK == |
402 | GNUNET_PROGRAM_run(argc, argv, | 407 | GNUNET_PROGRAM_run (argc, argv, |
403 | "hostlist", | 408 | "hostlist", |
404 | _("GNUnet hostlist server and client"), | 409 | _ ("GNUnet hostlist server and client"), |
405 | options, | 410 | options, |
406 | &run, NULL)) ? 0 : 1; | 411 | &run, NULL)) ? 0 : 1; |
407 | GNUNET_free((void*)argv); | 412 | GNUNET_free ((void*) argv); |
408 | return ret; | 413 | return ret; |
409 | } | 414 | } |
410 | 415 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index af3fd6fce..564aef2bd 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -49,19 +49,19 @@ | |||
49 | * Time interval hostlists are saved to disk | 49 | * Time interval hostlists are saved to disk |
50 | */ | 50 | */ |
51 | #define SAVING_INTERVAL \ | 51 | #define SAVING_INTERVAL \ |
52 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 52 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Time interval between two hostlist tests | 55 | * Time interval between two hostlist tests |
56 | */ | 56 | */ |
57 | #define TESTING_INTERVAL \ | 57 | #define TESTING_INTERVAL \ |
58 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) | 58 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Time interval for download dispatcher before a download is re-scheduled | 61 | * Time interval for download dispatcher before a download is re-scheduled |
62 | */ | 62 | */ |
63 | #define WAITING_INTERVAL \ | 63 | #define WAITING_INTERVAL \ |
64 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) | 64 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Defines concerning the hostlist quality metric | 67 | * Defines concerning the hostlist quality metric |
@@ -91,7 +91,8 @@ | |||
91 | /** | 91 | /** |
92 | * A single hostlist obtained by hostlist advertisements | 92 | * A single hostlist obtained by hostlist advertisements |
93 | */ | 93 | */ |
94 | struct Hostlist { | 94 | struct Hostlist |
95 | { | ||
95 | /** | 96 | /** |
96 | * previous entry, used to manage entries in a double linked list | 97 | * previous entry, used to manage entries in a double linked list |
97 | */ | 98 | */ |
@@ -320,7 +321,7 @@ static struct GNUNET_PEERINFO_Handle *pi; | |||
320 | * @return number of bytes that were processed (always size*nmemb) | 321 | * @return number of bytes that were processed (always size*nmemb) |
321 | */ | 322 | */ |
322 | static size_t | 323 | static size_t |
323 | callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | 324 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) |
324 | { | 325 | { |
325 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; | 326 | static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; |
326 | const char *cbuf = ptr; | 327 | const char *cbuf = ptr; |
@@ -333,85 +334,85 @@ callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | |||
333 | total = size * nmemb; | 334 | total = size * nmemb; |
334 | stat_bytes_downloaded += total; | 335 | stat_bytes_downloaded += total; |
335 | if ((total == 0) || (stat_bogus_url)) | 336 | if ((total == 0) || (stat_bogus_url)) |
336 | { | 337 | { |
337 | return total; /* ok, no data or bogus data */ | 338 | return total; /* ok, no data or bogus data */ |
338 | } | 339 | } |
339 | 340 | ||
340 | GNUNET_STATISTICS_update(stats, | 341 | GNUNET_STATISTICS_update (stats, |
341 | gettext_noop( | 342 | gettext_noop ( |
342 | "# bytes downloaded from hostlist servers"), | 343 | "# bytes downloaded from hostlist servers"), |
343 | (int64_t)total, | 344 | (int64_t) total, |
344 | GNUNET_NO); | 345 | GNUNET_NO); |
345 | left = total; | 346 | left = total; |
346 | while ((left > 0) || (download_pos > 0)) | 347 | while ((left > 0) || (download_pos > 0)) |
348 | { | ||
349 | cpy = GNUNET_MIN (left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
350 | GNUNET_memcpy (&download_buffer[download_pos], cbuf, cpy); | ||
351 | cbuf += cpy; | ||
352 | download_pos += cpy; | ||
353 | left -= cpy; | ||
354 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) | ||
347 | { | 355 | { |
348 | cpy = GNUNET_MIN(left, GNUNET_MAX_MESSAGE_SIZE - 1 - download_pos); | 356 | GNUNET_assert (0 == left); |
349 | GNUNET_memcpy(&download_buffer[download_pos], cbuf, cpy); | 357 | break; |
350 | cbuf += cpy; | 358 | } |
351 | download_pos += cpy; | 359 | msg = (const struct GNUNET_MessageHeader *) download_buffer; |
352 | left -= cpy; | 360 | msize = ntohs (msg->size); |
353 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) | 361 | if (msize < sizeof(struct GNUNET_MessageHeader)) |
354 | { | 362 | { |
355 | GNUNET_assert(0 == left); | 363 | GNUNET_STATISTICS_update ( |
356 | break; | 364 | stats, |
357 | } | 365 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), |
358 | msg = (const struct GNUNET_MessageHeader *)download_buffer; | 366 | 1, |
359 | msize = ntohs(msg->size); | 367 | GNUNET_NO); |
360 | if (msize < sizeof(struct GNUNET_MessageHeader)) | 368 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
361 | { | 369 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), |
362 | GNUNET_STATISTICS_update( | 370 | "HELLO", |
363 | stats, | 371 | current_url); |
364 | gettext_noop("# invalid HELLOs downloaded from hostlist servers"), | 372 | stat_hellos_obtained++; |
365 | 1, | 373 | stat_bogus_url = 1; |
366 | GNUNET_NO); | 374 | return total; |
367 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 375 | } |
368 | _("Invalid `%s' message received from hostlist at `%s'\n"), | 376 | if (download_pos < msize) |
369 | "HELLO", | 377 | { |
370 | current_url); | 378 | GNUNET_assert (left == 0); |
371 | stat_hellos_obtained++; | 379 | break; |
372 | stat_bogus_url = 1; | 380 | } |
373 | return total; | 381 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize) |
374 | } | 382 | { |
375 | if (download_pos < msize) | 383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
376 | { | 384 | "Received valid `%s' message from hostlist server.\n", |
377 | GNUNET_assert(left == 0); | 385 | "HELLO"); |
378 | break; | 386 | GNUNET_STATISTICS_update ( |
379 | } | 387 | stats, |
380 | if (GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)msg) == msize) | 388 | gettext_noop ("# valid HELLOs downloaded from hostlist servers"), |
381 | { | 389 | 1, |
382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_NO); |
383 | "Received valid `%s' message from hostlist server.\n", | 391 | stat_hellos_obtained++; |
384 | "HELLO"); | 392 | (void) |
385 | GNUNET_STATISTICS_update( | 393 | GNUNET_PEERINFO_add_peer (pi, |
386 | stats, | 394 | (const struct GNUNET_HELLO_Message *) msg, |
387 | gettext_noop("# valid HELLOs downloaded from hostlist servers"), | 395 | NULL, |
388 | 1, | 396 | NULL); |
389 | GNUNET_NO); | ||
390 | stat_hellos_obtained++; | ||
391 | (void) | ||
392 | GNUNET_PEERINFO_add_peer(pi, | ||
393 | (const struct GNUNET_HELLO_Message *)msg, | ||
394 | NULL, | ||
395 | NULL); | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | GNUNET_STATISTICS_update( | ||
400 | stats, | ||
401 | gettext_noop("# invalid HELLOs downloaded from hostlist servers"), | ||
402 | 1, | ||
403 | GNUNET_NO); | ||
404 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
405 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
406 | "HELLO", | ||
407 | current_url); | ||
408 | stat_bogus_url = GNUNET_YES; | ||
409 | stat_hellos_obtained++; | ||
410 | return total; | ||
411 | } | ||
412 | memmove(download_buffer, &download_buffer[msize], download_pos - msize); | ||
413 | download_pos -= msize; | ||
414 | } | 397 | } |
398 | else | ||
399 | { | ||
400 | GNUNET_STATISTICS_update ( | ||
401 | stats, | ||
402 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
403 | 1, | ||
404 | GNUNET_NO); | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
406 | _ ("Invalid `%s' message received from hostlist at `%s'\n"), | ||
407 | "HELLO", | ||
408 | current_url); | ||
409 | stat_bogus_url = GNUNET_YES; | ||
410 | stat_hellos_obtained++; | ||
411 | return total; | ||
412 | } | ||
413 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | ||
414 | download_pos -= msize; | ||
415 | } | ||
415 | return total; | 416 | return total; |
416 | } | 417 | } |
417 | 418 | ||
@@ -422,63 +423,63 @@ callback_download(void *ptr, size_t size, size_t nmemb, void *ctx) | |||
422 | * @return NULL if there is no URL available | 423 | * @return NULL if there is no URL available |
423 | */ | 424 | */ |
424 | static char * | 425 | static char * |
425 | get_bootstrap_server() | 426 | get_bootstrap_server () |
426 | { | 427 | { |
427 | char *servers; | 428 | char *servers; |
428 | char *ret; | 429 | char *ret; |
429 | size_t urls; | 430 | size_t urls; |
430 | size_t pos; | 431 | size_t pos; |
431 | 432 | ||
432 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 433 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
433 | "HOSTLIST", | 434 | "HOSTLIST", |
434 | "SERVERS", | 435 | "SERVERS", |
435 | &servers)) | 436 | &servers)) |
436 | { | 437 | { |
437 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 438 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
438 | "hostlist", | 439 | "hostlist", |
439 | "SERVERS"); | 440 | "SERVERS"); |
440 | return NULL; | 441 | return NULL; |
441 | } | 442 | } |
442 | 443 | ||
443 | urls = 0; | 444 | urls = 0; |
444 | if (strlen(servers) > 0) | 445 | if (strlen (servers) > 0) |
446 | { | ||
447 | urls++; | ||
448 | pos = strlen (servers) - 1; | ||
449 | while (pos > 0) | ||
445 | { | 450 | { |
446 | urls++; | 451 | if (servers[pos] == ' ') |
447 | pos = strlen(servers) - 1; | 452 | urls++; |
448 | while (pos > 0) | 453 | pos--; |
449 | { | ||
450 | if (servers[pos] == ' ') | ||
451 | urls++; | ||
452 | pos--; | ||
453 | } | ||
454 | } | 454 | } |
455 | } | ||
455 | if (urls == 0) | 456 | if (urls == 0) |
456 | { | 457 | { |
457 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 458 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
458 | "hostlist", | 459 | "hostlist", |
459 | "SERVERS"); | 460 | "SERVERS"); |
460 | GNUNET_free(servers); | 461 | GNUNET_free (servers); |
461 | return NULL; | 462 | return NULL; |
462 | } | 463 | } |
463 | 464 | ||
464 | urls = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | 465 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; |
465 | pos = strlen(servers) - 1; | 466 | pos = strlen (servers) - 1; |
466 | while (pos > 0) | 467 | while (pos > 0) |
468 | { | ||
469 | if (servers[pos] == ' ') | ||
467 | { | 470 | { |
468 | if (servers[pos] == ' ') | 471 | urls--; |
469 | { | 472 | servers[pos] = '\0'; |
470 | urls--; | 473 | } |
471 | servers[pos] = '\0'; | 474 | if (urls == 0) |
472 | } | 475 | { |
473 | if (urls == 0) | 476 | pos++; |
474 | { | 477 | break; |
475 | pos++; | ||
476 | break; | ||
477 | } | ||
478 | pos--; | ||
479 | } | 478 | } |
480 | ret = GNUNET_strdup(&servers[pos]); | 479 | pos--; |
481 | GNUNET_free(servers); | 480 | } |
481 | ret = GNUNET_strdup (&servers[pos]); | ||
482 | GNUNET_free (servers); | ||
482 | return ret; | 483 | return ret; |
483 | } | 484 | } |
484 | 485 | ||
@@ -488,64 +489,64 @@ get_bootstrap_server() | |||
488 | * @return uri to use, NULL if there is no URL available | 489 | * @return uri to use, NULL if there is no URL available |
489 | */ | 490 | */ |
490 | static char * | 491 | static char * |
491 | download_get_url() | 492 | download_get_url () |
492 | { | 493 | { |
493 | uint32_t index; | 494 | uint32_t index; |
494 | unsigned int counter; | 495 | unsigned int counter; |
495 | struct Hostlist *pos; | 496 | struct Hostlist *pos; |
496 | 497 | ||
497 | if (GNUNET_NO == stat_learning) | 498 | if (GNUNET_NO == stat_learning) |
498 | { | 499 | { |
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
500 | "Using preconfigured bootstrap server\n"); | 501 | "Using preconfigured bootstrap server\n"); |
501 | current_hostlist = NULL; | 502 | current_hostlist = NULL; |
502 | return get_bootstrap_server(); | 503 | return get_bootstrap_server (); |
503 | } | 504 | } |
504 | 505 | ||
505 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) | 506 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) |
506 | { | 507 | { |
507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
508 | "Testing new advertised hostlist if it is obtainable\n"); | 509 | "Testing new advertised hostlist if it is obtainable\n"); |
509 | current_hostlist = hostlist_to_test; | 510 | current_hostlist = hostlist_to_test; |
510 | return GNUNET_strdup(hostlist_to_test->hostlist_uri); | 511 | return GNUNET_strdup (hostlist_to_test->hostlist_uri); |
511 | } | 512 | } |
512 | 513 | ||
513 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) | 514 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) |
514 | { | 515 | { |
515 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
516 | "Using preconfigured bootstrap server\n"); | 517 | "Using preconfigured bootstrap server\n"); |
517 | current_hostlist = NULL; | 518 | current_hostlist = NULL; |
518 | return get_bootstrap_server(); | 519 | return get_bootstrap_server (); |
519 | } | 520 | } |
520 | index = | 521 | index = |
521 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); | 522 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); |
522 | counter = 0; | 523 | counter = 0; |
523 | pos = linked_list_head; | 524 | pos = linked_list_head; |
524 | while (counter < index) | 525 | while (counter < index) |
525 | { | 526 | { |
526 | pos = pos->next; | 527 | pos = pos->next; |
527 | counter++; | 528 | counter++; |
528 | } | 529 | } |
529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
530 | "Using learned hostlist `%s'\n", | 531 | "Using learned hostlist `%s'\n", |
531 | pos->hostlist_uri); | 532 | pos->hostlist_uri); |
532 | current_hostlist = pos; | 533 | current_hostlist = pos; |
533 | return GNUNET_strdup(pos->hostlist_uri); | 534 | return GNUNET_strdup (pos->hostlist_uri); |
534 | } | 535 | } |
535 | 536 | ||
536 | 537 | ||
537 | #define CURL_EASY_SETOPT(c, a, b) \ | 538 | #define CURL_EASY_SETOPT(c, a, b) \ |
538 | do \ | 539 | do \ |
539 | { \ | 540 | { \ |
540 | ret = curl_easy_setopt(c, a, b); \ | 541 | ret = curl_easy_setopt (c, a, b); \ |
541 | if (CURLE_OK != ret) \ | 542 | if (CURLE_OK != ret) \ |
542 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ | 543 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ |
543 | _("%s failed at %s:%d: `%s'\n"), \ | 544 | _ ("%s failed at %s:%d: `%s'\n"), \ |
544 | "curl_easy_setopt", \ | 545 | "curl_easy_setopt", \ |
545 | __FILE__, \ | 546 | __FILE__, \ |
546 | __LINE__, \ | 547 | __LINE__, \ |
547 | curl_easy_strerror(ret)); \ | 548 | curl_easy_strerror (ret)); \ |
548 | } while (0) | 549 | } while (0) |
549 | 550 | ||
550 | 551 | ||
551 | /** | 552 | /** |
@@ -554,7 +555,7 @@ download_get_url() | |||
554 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 555 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
555 | */ | 556 | */ |
556 | static void | 557 | static void |
557 | save_hostlist_file(int shutdown); | 558 | save_hostlist_file (int shutdown); |
558 | 559 | ||
559 | 560 | ||
560 | /** | 561 | /** |
@@ -565,7 +566,7 @@ save_hostlist_file(int shutdown); | |||
565 | * @return result | 566 | * @return result |
566 | */ | 567 | */ |
567 | static uint64_t | 568 | static uint64_t |
568 | checked_add(uint64_t val1, uint64_t val2) | 569 | checked_add (uint64_t val1, uint64_t val2) |
569 | { | 570 | { |
570 | static uint64_t temp; | 571 | static uint64_t temp; |
571 | static uint64_t maxv; | 572 | static uint64_t maxv; |
@@ -588,7 +589,7 @@ checked_add(uint64_t val1, uint64_t val2) | |||
588 | * @return result | 589 | * @return result |
589 | */ | 590 | */ |
590 | static uint64_t | 591 | static uint64_t |
591 | checked_sub(uint64_t val1, uint64_t val2) | 592 | checked_sub (uint64_t val1, uint64_t val2) |
592 | { | 593 | { |
593 | if (val1 <= val2) | 594 | if (val1 <= val2) |
594 | return 0; | 595 | return 0; |
@@ -603,17 +604,17 @@ checked_sub(uint64_t val1, uint64_t val2) | |||
603 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not | 604 | * @return #GNUNET_YES if existing in linked list, #GNUNET_NO if not |
604 | */ | 605 | */ |
605 | static int | 606 | static int |
606 | linked_list_contains(const char *uri) | 607 | linked_list_contains (const char *uri) |
607 | { | 608 | { |
608 | struct Hostlist *pos; | 609 | struct Hostlist *pos; |
609 | 610 | ||
610 | pos = linked_list_head; | 611 | pos = linked_list_head; |
611 | while (pos != NULL) | 612 | while (pos != NULL) |
612 | { | 613 | { |
613 | if (0 == strcmp(pos->hostlist_uri, uri)) | 614 | if (0 == strcmp (pos->hostlist_uri, uri)) |
614 | return GNUNET_YES; | 615 | return GNUNET_YES; |
615 | pos = pos->next; | 616 | pos = pos->next; |
616 | } | 617 | } |
617 | return GNUNET_NO; | 618 | return GNUNET_NO; |
618 | } | 619 | } |
619 | 620 | ||
@@ -623,7 +624,7 @@ linked_list_contains(const char *uri) | |||
623 | * @return hostlist with lowest quality | 624 | * @return hostlist with lowest quality |
624 | */ | 625 | */ |
625 | static struct Hostlist * | 626 | static struct Hostlist * |
626 | linked_list_get_lowest_quality() | 627 | linked_list_get_lowest_quality () |
627 | { | 628 | { |
628 | struct Hostlist *pos; | 629 | struct Hostlist *pos; |
629 | struct Hostlist *lowest; | 630 | struct Hostlist *lowest; |
@@ -633,11 +634,11 @@ linked_list_get_lowest_quality() | |||
633 | lowest = linked_list_head; | 634 | lowest = linked_list_head; |
634 | pos = linked_list_head->next; | 635 | pos = linked_list_head->next; |
635 | while (pos != NULL) | 636 | while (pos != NULL) |
636 | { | 637 | { |
637 | if (pos->quality < lowest->quality) | 638 | if (pos->quality < lowest->quality) |
638 | lowest = pos; | 639 | lowest = pos; |
639 | pos = pos->next; | 640 | pos = pos->next; |
640 | } | 641 | } |
641 | return lowest; | 642 | return lowest; |
642 | } | 643 | } |
643 | 644 | ||
@@ -648,34 +649,34 @@ linked_list_get_lowest_quality() | |||
648 | * quality is dismissed | 649 | * quality is dismissed |
649 | */ | 650 | */ |
650 | static void | 651 | static void |
651 | insert_hostlist() | 652 | insert_hostlist () |
652 | { | 653 | { |
653 | struct Hostlist *lowest_quality; | 654 | struct Hostlist *lowest_quality; |
654 | 655 | ||
655 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) | 656 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) |
656 | { | 657 | { |
657 | /* No free entries available, replace existing entry */ | 658 | /* No free entries available, replace existing entry */ |
658 | lowest_quality = linked_list_get_lowest_quality(); | 659 | lowest_quality = linked_list_get_lowest_quality (); |
659 | GNUNET_assert(lowest_quality != NULL); | 660 | GNUNET_assert (lowest_quality != NULL); |
660 | GNUNET_log( | 661 | GNUNET_log ( |
661 | GNUNET_ERROR_TYPE_DEBUG, | 662 | GNUNET_ERROR_TYPE_DEBUG, |
662 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", | 663 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", |
663 | lowest_quality->hostlist_uri, | 664 | lowest_quality->hostlist_uri, |
664 | (unsigned long long)lowest_quality->quality); | 665 | (unsigned long long) lowest_quality->quality); |
665 | GNUNET_CONTAINER_DLL_remove(linked_list_head, | 666 | GNUNET_CONTAINER_DLL_remove (linked_list_head, |
666 | linked_list_tail, | 667 | linked_list_tail, |
667 | lowest_quality); | 668 | lowest_quality); |
668 | linked_list_size--; | 669 | linked_list_size--; |
669 | GNUNET_free(lowest_quality); | 670 | GNUNET_free (lowest_quality); |
670 | } | 671 | } |
671 | GNUNET_CONTAINER_DLL_insert(linked_list_head, | 672 | GNUNET_CONTAINER_DLL_insert (linked_list_head, |
672 | linked_list_tail, | 673 | linked_list_tail, |
673 | hostlist_to_test); | 674 | hostlist_to_test); |
674 | linked_list_size++; | 675 | linked_list_size++; |
675 | GNUNET_STATISTICS_set(stats, | 676 | GNUNET_STATISTICS_set (stats, |
676 | gettext_noop("# advertised hostlist URIs"), | 677 | gettext_noop ("# advertised hostlist URIs"), |
677 | linked_list_size, | 678 | linked_list_size, |
678 | GNUNET_NO); | 679 | GNUNET_NO); |
679 | stat_testing_hostlist = GNUNET_NO; | 680 | stat_testing_hostlist = GNUNET_NO; |
680 | } | 681 | } |
681 | 682 | ||
@@ -684,37 +685,37 @@ insert_hostlist() | |||
684 | * Method updating hostlist statistics | 685 | * Method updating hostlist statistics |
685 | */ | 686 | */ |
686 | static void | 687 | static void |
687 | update_hostlist() | 688 | update_hostlist () |
688 | { | 689 | { |
689 | char *stat; | 690 | char *stat; |
690 | 691 | ||
691 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || | 692 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || |
692 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) | 693 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) |
694 | { | ||
695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
696 | "Updating hostlist statics for URI `%s'\n", | ||
697 | current_hostlist->hostlist_uri); | ||
698 | current_hostlist->hello_count = stat_hellos_obtained; | ||
699 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); | ||
700 | current_hostlist->quality = | ||
701 | checked_add (current_hostlist->quality, | ||
702 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | ||
703 | if (GNUNET_YES == stat_download_successful) | ||
693 | { | 704 | { |
694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 705 | current_hostlist->times_used++; |
695 | "Updating hostlist statics for URI `%s'\n", | ||
696 | current_hostlist->hostlist_uri); | ||
697 | current_hostlist->hello_count = stat_hellos_obtained; | ||
698 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get(); | ||
699 | current_hostlist->quality = | 706 | current_hostlist->quality = |
700 | checked_add(current_hostlist->quality, | 707 | checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); |
701 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | 708 | GNUNET_asprintf (&stat, |
702 | if (GNUNET_YES == stat_download_successful) | 709 | gettext_noop ("# advertised URI `%s' downloaded"), |
703 | { | 710 | current_hostlist->hostlist_uri); |
704 | current_hostlist->times_used++; | 711 | |
705 | current_hostlist->quality = | 712 | GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); |
706 | checked_add(current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | 713 | GNUNET_free (stat); |
707 | GNUNET_asprintf(&stat, | ||
708 | gettext_noop("# advertised URI `%s' downloaded"), | ||
709 | current_hostlist->hostlist_uri); | ||
710 | |||
711 | GNUNET_STATISTICS_update(stats, stat, 1, GNUNET_YES); | ||
712 | GNUNET_free(stat); | ||
713 | } | ||
714 | else | ||
715 | current_hostlist->quality = | ||
716 | checked_sub(current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
717 | } | 714 | } |
715 | else | ||
716 | current_hostlist->quality = | ||
717 | checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
718 | } | ||
718 | current_hostlist = NULL; | 719 | current_hostlist = NULL; |
719 | /* Alternating the usage of preconfigured and learned hostlists */ | 720 | /* Alternating the usage of preconfigured and learned hostlists */ |
720 | 721 | ||
@@ -722,12 +723,12 @@ update_hostlist() | |||
722 | return; | 723 | return; |
723 | 724 | ||
724 | if (GNUNET_YES == stat_learning) | 725 | if (GNUNET_YES == stat_learning) |
725 | { | 726 | { |
726 | if (stat_use_bootstrap == GNUNET_YES) | 727 | if (stat_use_bootstrap == GNUNET_YES) |
727 | stat_use_bootstrap = GNUNET_NO; | 728 | stat_use_bootstrap = GNUNET_NO; |
728 | else | 729 | else |
729 | stat_use_bootstrap = GNUNET_YES; | 730 | stat_use_bootstrap = GNUNET_YES; |
730 | } | 731 | } |
731 | else | 732 | else |
732 | stat_use_bootstrap = GNUNET_YES; | 733 | stat_use_bootstrap = GNUNET_YES; |
733 | } | 734 | } |
@@ -738,58 +739,58 @@ update_hostlist() | |||
738 | * hostlist and schedule the next task. | 739 | * hostlist and schedule the next task. |
739 | */ | 740 | */ |
740 | static void | 741 | static void |
741 | clean_up() | 742 | clean_up () |
742 | { | 743 | { |
743 | CURLMcode mret; | 744 | CURLMcode mret; |
744 | 745 | ||
745 | if ((stat_testing_hostlist == GNUNET_YES) && | 746 | if ((stat_testing_hostlist == GNUNET_YES) && |
746 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) | 747 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) |
747 | { | 748 | { |
748 | GNUNET_log( | 749 | GNUNET_log ( |
749 | GNUNET_ERROR_TYPE_INFO, | 750 | GNUNET_ERROR_TYPE_INFO, |
750 | _( | 751 | _ ( |
751 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), | 752 | "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), |
752 | hostlist_to_test->hostlist_uri); | 753 | hostlist_to_test->hostlist_uri); |
753 | } | 754 | } |
754 | 755 | ||
755 | if (stat_testing_hostlist == GNUNET_YES) | 756 | if (stat_testing_hostlist == GNUNET_YES) |
756 | { | 757 | { |
757 | stat_testing_hostlist = GNUNET_NO; | 758 | stat_testing_hostlist = GNUNET_NO; |
758 | } | 759 | } |
759 | if (NULL != hostlist_to_test) | 760 | if (NULL != hostlist_to_test) |
760 | { | 761 | { |
761 | GNUNET_free(hostlist_to_test); | 762 | GNUNET_free (hostlist_to_test); |
762 | hostlist_to_test = NULL; | 763 | hostlist_to_test = NULL; |
763 | } | 764 | } |
764 | 765 | ||
765 | if (NULL != multi) | 766 | if (NULL != multi) |
767 | { | ||
768 | mret = curl_multi_remove_handle (multi, curl); | ||
769 | if (mret != CURLM_OK) | ||
766 | { | 770 | { |
767 | mret = curl_multi_remove_handle(multi, curl); | 771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
768 | if (mret != CURLM_OK) | 772 | _ ("%s failed at %s:%d: `%s'\n"), |
769 | { | 773 | "curl_multi_remove_handle", |
770 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 774 | __FILE__, |
771 | _("%s failed at %s:%d: `%s'\n"), | 775 | __LINE__, |
772 | "curl_multi_remove_handle", | 776 | curl_multi_strerror (mret)); |
773 | __FILE__, | ||
774 | __LINE__, | ||
775 | curl_multi_strerror(mret)); | ||
776 | } | ||
777 | mret = curl_multi_cleanup(multi); | ||
778 | if (mret != CURLM_OK) | ||
779 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
780 | _("%s failed at %s:%d: `%s'\n"), | ||
781 | "curl_multi_cleanup", | ||
782 | __FILE__, | ||
783 | __LINE__, | ||
784 | curl_multi_strerror(mret)); | ||
785 | multi = NULL; | ||
786 | } | 777 | } |
778 | mret = curl_multi_cleanup (multi); | ||
779 | if (mret != CURLM_OK) | ||
780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
781 | _ ("%s failed at %s:%d: `%s'\n"), | ||
782 | "curl_multi_cleanup", | ||
783 | __FILE__, | ||
784 | __LINE__, | ||
785 | curl_multi_strerror (mret)); | ||
786 | multi = NULL; | ||
787 | } | ||
787 | if (NULL != curl) | 788 | if (NULL != curl) |
788 | { | 789 | { |
789 | curl_easy_cleanup(curl); | 790 | curl_easy_cleanup (curl); |
790 | curl = NULL; | 791 | curl = NULL; |
791 | } | 792 | } |
792 | GNUNET_free_non_null(current_url); | 793 | GNUNET_free_non_null (current_url); |
793 | current_url = NULL; | 794 | current_url = NULL; |
794 | stat_bytes_downloaded = 0; | 795 | stat_bytes_downloaded = 0; |
795 | stat_download_in_progress = GNUNET_NO; | 796 | stat_download_in_progress = GNUNET_NO; |
@@ -804,7 +805,7 @@ clean_up() | |||
804 | * @param tc task context, unused | 805 | * @param tc task context, unused |
805 | */ | 806 | */ |
806 | static void | 807 | static void |
807 | task_download(void *cls); | 808 | task_download (void *cls); |
808 | 809 | ||
809 | 810 | ||
810 | /** | 811 | /** |
@@ -812,7 +813,7 @@ task_download(void *cls); | |||
812 | * receiving task with the scheduler. | 813 | * receiving task with the scheduler. |
813 | */ | 814 | */ |
814 | static void | 815 | static void |
815 | download_prepare() | 816 | download_prepare () |
816 | { | 817 | { |
817 | CURLMcode mret; | 818 | CURLMcode mret; |
818 | fd_set rs; | 819 | fd_set rs; |
@@ -825,50 +826,50 @@ download_prepare() | |||
825 | struct GNUNET_TIME_Relative rtime; | 826 | struct GNUNET_TIME_Relative rtime; |
826 | 827 | ||
827 | max = -1; | 828 | max = -1; |
828 | FD_ZERO(&rs); | 829 | FD_ZERO (&rs); |
829 | FD_ZERO(&ws); | 830 | FD_ZERO (&ws); |
830 | FD_ZERO(&es); | 831 | FD_ZERO (&es); |
831 | mret = curl_multi_fdset(multi, &rs, &ws, &es, &max); | 832 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
832 | if (mret != CURLM_OK) | 833 | if (mret != CURLM_OK) |
833 | { | 834 | { |
834 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 835 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
835 | _("%s failed at %s:%d: `%s'\n"), | 836 | _ ("%s failed at %s:%d: `%s'\n"), |
836 | "curl_multi_fdset", | 837 | "curl_multi_fdset", |
837 | __FILE__, | 838 | __FILE__, |
838 | __LINE__, | 839 | __LINE__, |
839 | curl_multi_strerror(mret)); | 840 | curl_multi_strerror (mret)); |
840 | clean_up(); | 841 | clean_up (); |
841 | return; | 842 | return; |
842 | } | 843 | } |
843 | mret = curl_multi_timeout(multi, &timeout); | 844 | mret = curl_multi_timeout (multi, &timeout); |
844 | if (mret != CURLM_OK) | 845 | if (mret != CURLM_OK) |
845 | { | 846 | { |
846 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
847 | _("%s failed at %s:%d: `%s'\n"), | 848 | _ ("%s failed at %s:%d: `%s'\n"), |
848 | "curl_multi_timeout", | 849 | "curl_multi_timeout", |
849 | __FILE__, | 850 | __FILE__, |
850 | __LINE__, | 851 | __LINE__, |
851 | curl_multi_strerror(mret)); | 852 | curl_multi_strerror (mret)); |
852 | clean_up(); | 853 | clean_up (); |
853 | return; | 854 | return; |
854 | } | 855 | } |
855 | rtime = GNUNET_TIME_relative_min( | 856 | rtime = GNUNET_TIME_relative_min ( |
856 | GNUNET_TIME_absolute_get_remaining(end_time), | 857 | GNUNET_TIME_absolute_get_remaining (end_time), |
857 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, timeout)); | 858 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); |
858 | grs = GNUNET_NETWORK_fdset_create(); | 859 | grs = GNUNET_NETWORK_fdset_create (); |
859 | gws = GNUNET_NETWORK_fdset_create(); | 860 | gws = GNUNET_NETWORK_fdset_create (); |
860 | GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); | 861 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
861 | GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); | 862 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
862 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
863 | "Scheduling task for hostlist download using cURL\n"); | 864 | "Scheduling task for hostlist download using cURL\n"); |
864 | ti_download = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 865 | ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
865 | rtime, | 866 | rtime, |
866 | grs, | 867 | grs, |
867 | gws, | 868 | gws, |
868 | &task_download, | 869 | &task_download, |
869 | multi); | 870 | multi); |
870 | GNUNET_NETWORK_fdset_destroy(gws); | 871 | GNUNET_NETWORK_fdset_destroy (gws); |
871 | GNUNET_NETWORK_fdset_destroy(grs); | 872 | GNUNET_NETWORK_fdset_destroy (grs); |
872 | } | 873 | } |
873 | 874 | ||
874 | 875 | ||
@@ -879,95 +880,95 @@ download_prepare() | |||
879 | * @param cls closure, unused | 880 | * @param cls closure, unused |
880 | */ | 881 | */ |
881 | static void | 882 | static void |
882 | task_download(void *cls) | 883 | task_download (void *cls) |
883 | { | 884 | { |
884 | int running; | 885 | int running; |
885 | struct CURLMsg *msg; | 886 | struct CURLMsg *msg; |
886 | CURLMcode mret; | 887 | CURLMcode mret; |
887 | 888 | ||
888 | ti_download = NULL; | 889 | ti_download = NULL; |
889 | if (0 == GNUNET_TIME_absolute_get_remaining(end_time).rel_value_us) | 890 | if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us) |
891 | { | ||
892 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
893 | _ ("Timeout trying to download hostlist from `%s'\n"), | ||
894 | current_url); | ||
895 | update_hostlist (); | ||
896 | clean_up (); | ||
897 | return; | ||
898 | } | ||
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
900 | "Ready for processing hostlist client request\n"); | ||
901 | do | ||
902 | { | ||
903 | running = 0; | ||
904 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | ||
890 | { | 905 | { |
891 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 906 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
892 | _("Timeout trying to download hostlist from `%s'\n"), | 907 | _ ( |
893 | current_url); | 908 | "Download limit of %u bytes exceeded, stopping download\n"), |
894 | update_hostlist(); | 909 | MAX_BYTES_PER_HOSTLISTS); |
895 | clean_up(); | 910 | clean_up (); |
896 | return; | 911 | return; |
897 | } | 912 | } |
898 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 913 | mret = curl_multi_perform (multi, &running); |
899 | "Ready for processing hostlist client request\n"); | 914 | if (running == 0) |
900 | do | ||
901 | { | 915 | { |
902 | running = 0; | 916 | do |
903 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | 917 | { |
904 | { | 918 | msg = curl_multi_info_read (multi, &running); |
905 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 919 | GNUNET_break (msg != NULL); |
906 | _( | 920 | if (msg == NULL) |
907 | "Download limit of %u bytes exceeded, stopping download\n"), | 921 | break; |
908 | MAX_BYTES_PER_HOSTLISTS); | 922 | switch (msg->msg) |
909 | clean_up(); | ||
910 | return; | ||
911 | } | ||
912 | mret = curl_multi_perform(multi, &running); | ||
913 | if (running == 0) | ||
914 | { | 923 | { |
915 | do | 924 | case CURLMSG_DONE: |
925 | if ((msg->data.result != CURLE_OK) && | ||
926 | (msg->data.result != CURLE_GOT_NOTHING)) | ||
927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
928 | _ ("Download of hostlist from `%s' failed: `%s'\n"), | ||
929 | current_url, | ||
930 | curl_easy_strerror (msg->data.result)); | ||
931 | else | ||
932 | { | ||
933 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
934 | _ ("Download of hostlist `%s' completed.\n"), | ||
935 | current_url); | ||
936 | stat_download_successful = GNUNET_YES; | ||
937 | update_hostlist (); | ||
938 | if (GNUNET_YES == stat_testing_hostlist) | ||
916 | { | 939 | { |
917 | msg = curl_multi_info_read(multi, &running); | 940 | GNUNET_log ( |
918 | GNUNET_break(msg != NULL); | 941 | GNUNET_ERROR_TYPE_INFO, |
919 | if (msg == NULL) | 942 | _ ("Adding successfully tested hostlist `%s' datastore.\n"), |
920 | break; | 943 | current_url); |
921 | switch (msg->msg) | 944 | insert_hostlist (); |
922 | { | 945 | hostlist_to_test = NULL; |
923 | case CURLMSG_DONE: | 946 | stat_testing_hostlist = GNUNET_NO; |
924 | if ((msg->data.result != CURLE_OK) && | ||
925 | (msg->data.result != CURLE_GOT_NOTHING)) | ||
926 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
927 | _("Download of hostlist from `%s' failed: `%s'\n"), | ||
928 | current_url, | ||
929 | curl_easy_strerror(msg->data.result)); | ||
930 | else | ||
931 | { | ||
932 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
933 | _("Download of hostlist `%s' completed.\n"), | ||
934 | current_url); | ||
935 | stat_download_successful = GNUNET_YES; | ||
936 | update_hostlist(); | ||
937 | if (GNUNET_YES == stat_testing_hostlist) | ||
938 | { | ||
939 | GNUNET_log( | ||
940 | GNUNET_ERROR_TYPE_INFO, | ||
941 | _("Adding successfully tested hostlist `%s' datastore.\n"), | ||
942 | current_url); | ||
943 | insert_hostlist(); | ||
944 | hostlist_to_test = NULL; | ||
945 | stat_testing_hostlist = GNUNET_NO; | ||
946 | } | ||
947 | } | ||
948 | clean_up(); | ||
949 | return; | ||
950 | |||
951 | default: | ||
952 | break; | ||
953 | } | ||
954 | } | 947 | } |
955 | while ((running > 0)); | 948 | } |
949 | clean_up (); | ||
950 | return; | ||
951 | |||
952 | default: | ||
953 | break; | ||
956 | } | 954 | } |
955 | } | ||
956 | while ((running > 0)); | ||
957 | } | 957 | } |
958 | } | ||
958 | while (mret == CURLM_CALL_MULTI_PERFORM); | 959 | while (mret == CURLM_CALL_MULTI_PERFORM); |
959 | 960 | ||
960 | if (mret != CURLM_OK) | 961 | if (mret != CURLM_OK) |
961 | { | 962 | { |
962 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 963 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
963 | _("%s failed at %s:%d: `%s'\n"), | 964 | _ ("%s failed at %s:%d: `%s'\n"), |
964 | "curl_multi_perform", | 965 | "curl_multi_perform", |
965 | __FILE__, | 966 | __FILE__, |
966 | __LINE__, | 967 | __LINE__, |
967 | curl_multi_strerror(mret)); | 968 | curl_multi_strerror (mret)); |
968 | clean_up(); | 969 | clean_up (); |
969 | } | 970 | } |
970 | download_prepare(); | 971 | download_prepare (); |
971 | } | 972 | } |
972 | 973 | ||
973 | 974 | ||
@@ -976,133 +977,133 @@ task_download(void *cls) | |||
976 | * data. | 977 | * data. |
977 | */ | 978 | */ |
978 | static void | 979 | static void |
979 | download_hostlist() | 980 | download_hostlist () |
980 | { | 981 | { |
981 | CURLcode ret; | 982 | CURLcode ret; |
982 | CURLMcode mret; | 983 | CURLMcode mret; |
983 | 984 | ||
984 | 985 | ||
985 | current_url = download_get_url(); | 986 | current_url = download_get_url (); |
986 | if (current_url == NULL) | 987 | if (current_url == NULL) |
987 | return; | 988 | return; |
988 | curl = curl_easy_init(); | 989 | curl = curl_easy_init (); |
989 | multi = NULL; | 990 | multi = NULL; |
990 | if (curl == NULL) | 991 | if (curl == NULL) |
991 | { | 992 | { |
992 | GNUNET_break(0); | 993 | GNUNET_break (0); |
993 | clean_up(); | 994 | clean_up (); |
994 | return; | 995 | return; |
995 | } | 996 | } |
996 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 997 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
997 | _("Bootstrapping using hostlist at `%s'.\n"), | 998 | _ ("Bootstrapping using hostlist at `%s'.\n"), |
998 | current_url); | 999 | current_url); |
999 | 1000 | ||
1000 | stat_download_in_progress = GNUNET_YES; | 1001 | stat_download_in_progress = GNUNET_YES; |
1001 | stat_download_successful = GNUNET_NO; | 1002 | stat_download_successful = GNUNET_NO; |
1002 | stat_hellos_obtained = 0; | 1003 | stat_hellos_obtained = 0; |
1003 | stat_bytes_downloaded = 0; | 1004 | stat_bytes_downloaded = 0; |
1004 | 1005 | ||
1005 | GNUNET_STATISTICS_update(stats, | 1006 | GNUNET_STATISTICS_update (stats, |
1006 | gettext_noop("# hostlist downloads initiated"), | 1007 | gettext_noop ("# hostlist downloads initiated"), |
1007 | 1, | 1008 | 1, |
1008 | GNUNET_NO); | 1009 | GNUNET_NO); |
1009 | if (NULL != proxy) | 1010 | if (NULL != proxy) |
1010 | { | 1011 | { |
1011 | CURL_EASY_SETOPT(curl, CURLOPT_PROXY, proxy); | 1012 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); |
1012 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYTYPE, proxy_type); | 1013 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYTYPE, proxy_type); |
1013 | if (NULL != proxy_username) | 1014 | if (NULL != proxy_username) |
1014 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYUSERNAME, proxy_username); | 1015 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYUSERNAME, proxy_username); |
1015 | if (NULL != proxy_password) | 1016 | if (NULL != proxy_password) |
1016 | CURL_EASY_SETOPT(curl, CURLOPT_PROXYPASSWORD, proxy_password); | 1017 | CURL_EASY_SETOPT (curl, CURLOPT_PROXYPASSWORD, proxy_password); |
1017 | } | 1018 | } |
1018 | download_pos = 0; | 1019 | download_pos = 0; |
1019 | stat_bogus_url = 0; | 1020 | stat_bogus_url = 0; |
1020 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEFUNCTION, &callback_download); | 1021 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download); |
1021 | if (ret != CURLE_OK) | 1022 | if (ret != CURLE_OK) |
1022 | { | 1023 | { |
1023 | clean_up(); | 1024 | clean_up (); |
1024 | return; | 1025 | return; |
1025 | } | 1026 | } |
1026 | CURL_EASY_SETOPT(curl, CURLOPT_WRITEDATA, NULL); | 1027 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL); |
1027 | if (ret != CURLE_OK) | 1028 | if (ret != CURLE_OK) |
1028 | { | 1029 | { |
1029 | clean_up(); | 1030 | clean_up (); |
1030 | return; | 1031 | return; |
1031 | } | 1032 | } |
1032 | CURL_EASY_SETOPT(curl, CURLOPT_FOLLOWLOCATION, 1); | 1033 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); |
1033 | CURL_EASY_SETOPT(curl, | 1034 | CURL_EASY_SETOPT (curl, |
1034 | CURLOPT_REDIR_PROTOCOLS, | 1035 | CURLOPT_REDIR_PROTOCOLS, |
1035 | CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1036 | CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1036 | CURL_EASY_SETOPT(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); | 1037 | CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
1037 | CURL_EASY_SETOPT(curl, CURLOPT_MAXREDIRS, 4); | 1038 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); |
1038 | /* no need to abort if the above failed */ | 1039 | /* no need to abort if the above failed */ |
1039 | CURL_EASY_SETOPT(curl, CURLOPT_URL, current_url); | 1040 | CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url); |
1040 | if (ret != CURLE_OK) | 1041 | if (ret != CURLE_OK) |
1041 | { | 1042 | { |
1042 | clean_up(); | 1043 | clean_up (); |
1043 | return; | 1044 | return; |
1044 | } | 1045 | } |
1045 | CURL_EASY_SETOPT(curl, CURLOPT_FAILONERROR, 1); | 1046 | CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1); |
1046 | #if 0 | 1047 | #if 0 |
1047 | CURL_EASY_SETOPT(curl, CURLOPT_VERBOSE, 1); | 1048 | CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1); |
1048 | #endif | 1049 | #endif |
1049 | CURL_EASY_SETOPT(curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); | 1050 | CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_MAX_MESSAGE_SIZE); |
1050 | if (0 == strncmp(current_url, "http", 4)) | 1051 | if (0 == strncmp (current_url, "http", 4)) |
1051 | CURL_EASY_SETOPT(curl, CURLOPT_USERAGENT, "GNUnet"); | 1052 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); |
1052 | CURL_EASY_SETOPT(curl, CURLOPT_CONNECTTIMEOUT, 60L); | 1053 | CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L); |
1053 | CURL_EASY_SETOPT(curl, CURLOPT_TIMEOUT, 60L); | 1054 | CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L); |
1054 | multi = curl_multi_init(); | 1055 | multi = curl_multi_init (); |
1055 | if (multi == NULL) | 1056 | if (multi == NULL) |
1056 | { | 1057 | { |
1057 | GNUNET_break(0); | 1058 | GNUNET_break (0); |
1058 | /* clean_up (); */ | 1059 | /* clean_up (); */ |
1059 | return; | 1060 | return; |
1060 | } | 1061 | } |
1061 | mret = curl_multi_add_handle(multi, curl); | 1062 | mret = curl_multi_add_handle (multi, curl); |
1062 | if (mret != CURLM_OK) | 1063 | if (mret != CURLM_OK) |
1063 | { | 1064 | { |
1064 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1065 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1065 | _("%s failed at %s:%d: `%s'\n"), | 1066 | _ ("%s failed at %s:%d: `%s'\n"), |
1066 | "curl_multi_add_handle", | 1067 | "curl_multi_add_handle", |
1067 | __FILE__, | 1068 | __FILE__, |
1068 | __LINE__, | 1069 | __LINE__, |
1069 | curl_multi_strerror(mret)); | 1070 | curl_multi_strerror (mret)); |
1070 | mret = curl_multi_cleanup(multi); | 1071 | mret = curl_multi_cleanup (multi); |
1071 | if (mret != CURLM_OK) | 1072 | if (mret != CURLM_OK) |
1072 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1073 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1073 | _("%s failed at %s:%d: `%s'\n"), | 1074 | _ ("%s failed at %s:%d: `%s'\n"), |
1074 | "curl_multi_cleanup", | 1075 | "curl_multi_cleanup", |
1075 | __FILE__, | 1076 | __FILE__, |
1076 | __LINE__, | 1077 | __LINE__, |
1077 | curl_multi_strerror(mret)); | 1078 | curl_multi_strerror (mret)); |
1078 | multi = NULL; | 1079 | multi = NULL; |
1079 | clean_up(); | 1080 | clean_up (); |
1080 | return; | 1081 | return; |
1081 | } | 1082 | } |
1082 | end_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES); | 1083 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
1083 | download_prepare(); | 1084 | download_prepare (); |
1084 | } | 1085 | } |
1085 | 1086 | ||
1086 | 1087 | ||
1087 | static void | 1088 | static void |
1088 | task_download_dispatcher(void *cls) | 1089 | task_download_dispatcher (void *cls) |
1089 | { | 1090 | { |
1090 | ti_download_dispatcher_task = NULL; | 1091 | ti_download_dispatcher_task = NULL; |
1091 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); | 1092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
1092 | if (GNUNET_NO == stat_download_in_progress) | 1093 | if (GNUNET_NO == stat_download_in_progress) |
1093 | { | 1094 | { |
1094 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); | 1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); |
1095 | download_hostlist(); | 1096 | download_hostlist (); |
1096 | } | 1097 | } |
1097 | else | 1098 | else |
1098 | { | 1099 | { |
1099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1100 | "Download in progess, have to wait...\n"); | 1101 | "Download in progess, have to wait...\n"); |
1101 | ti_download_dispatcher_task = | 1102 | ti_download_dispatcher_task = |
1102 | GNUNET_SCHEDULER_add_delayed(WAITING_INTERVAL, | 1103 | GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, |
1103 | &task_download_dispatcher, | 1104 | &task_download_dispatcher, |
1104 | NULL); | 1105 | NULL); |
1105 | } | 1106 | } |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | 1109 | ||
@@ -1112,49 +1113,49 @@ task_download_dispatcher(void *cls) | |||
1112 | * this task again for a later time. | 1113 | * this task again for a later time. |
1113 | */ | 1114 | */ |
1114 | static void | 1115 | static void |
1115 | task_check(void *cls) | 1116 | task_check (void *cls) |
1116 | { | 1117 | { |
1117 | static int once; | 1118 | static int once; |
1118 | struct GNUNET_TIME_Relative delay; | 1119 | struct GNUNET_TIME_Relative delay; |
1119 | 1120 | ||
1120 | ti_check_download = NULL; | 1121 | ti_check_download = NULL; |
1121 | if (stats == NULL) | 1122 | if (stats == NULL) |
1122 | { | 1123 | { |
1123 | curl_global_cleanup(); | 1124 | curl_global_cleanup (); |
1124 | return; /* in shutdown */ | 1125 | return; /* in shutdown */ |
1125 | } | 1126 | } |
1126 | if ((stat_connection_count < MIN_CONNECTIONS) && | 1127 | if ((stat_connection_count < MIN_CONNECTIONS) && |
1127 | (NULL == ti_download_dispatcher_task)) | 1128 | (NULL == ti_download_dispatcher_task)) |
1128 | ti_download_dispatcher_task = | 1129 | ti_download_dispatcher_task = |
1129 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); | 1130 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1130 | 1131 | ||
1131 | delay = hostlist_delay; | 1132 | delay = hostlist_delay; |
1132 | if (0 == hostlist_delay.rel_value_us) | 1133 | if (0 == hostlist_delay.rel_value_us) |
1133 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; | 1134 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; |
1134 | else | 1135 | else |
1135 | hostlist_delay = GNUNET_TIME_relative_multiply(hostlist_delay, 2); | 1136 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); |
1136 | if (hostlist_delay.rel_value_us > | 1137 | if (hostlist_delay.rel_value_us > |
1137 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) | 1138 | GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) |
1138 | hostlist_delay = | 1139 | hostlist_delay = |
1139 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, | 1140 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, |
1140 | (1 + stat_connection_count)); | 1141 | (1 + stat_connection_count)); |
1141 | GNUNET_STATISTICS_set(stats, | 1142 | GNUNET_STATISTICS_set (stats, |
1142 | gettext_noop( | 1143 | gettext_noop ( |
1143 | "# milliseconds between hostlist downloads"), | 1144 | "# milliseconds between hostlist downloads"), |
1144 | hostlist_delay.rel_value_us / 1000LL, | 1145 | hostlist_delay.rel_value_us / 1000LL, |
1145 | GNUNET_YES); | 1146 | GNUNET_YES); |
1146 | if (0 == once) | 1147 | if (0 == once) |
1147 | { | 1148 | { |
1148 | delay = GNUNET_TIME_UNIT_ZERO; | 1149 | delay = GNUNET_TIME_UNIT_ZERO; |
1149 | once = 1; | 1150 | once = 1; |
1150 | } | 1151 | } |
1151 | GNUNET_log( | 1152 | GNUNET_log ( |
1152 | GNUNET_ERROR_TYPE_INFO, | 1153 | GNUNET_ERROR_TYPE_INFO, |
1153 | _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), | 1154 | _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"), |
1154 | stat_connection_count, | 1155 | stat_connection_count, |
1155 | MIN_CONNECTIONS, | 1156 | MIN_CONNECTIONS, |
1156 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); | 1157 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
1157 | ti_check_download = GNUNET_SCHEDULER_add_delayed(delay, &task_check, NULL); | 1158 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); |
1158 | } | 1159 | } |
1159 | 1160 | ||
1160 | 1161 | ||
@@ -1164,12 +1165,12 @@ task_check(void *cls) | |||
1164 | * @param cls closure | 1165 | * @param cls closure |
1165 | */ | 1166 | */ |
1166 | static void | 1167 | static void |
1167 | task_testing_intervall_reset(void *cls) | 1168 | task_testing_intervall_reset (void *cls) |
1168 | { | 1169 | { |
1169 | ti_testing_intervall_task = NULL; | 1170 | ti_testing_intervall_task = NULL; |
1170 | stat_testing_allowed = GNUNET_OK; | 1171 | stat_testing_allowed = GNUNET_OK; |
1171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1172 | "Testing new hostlist advertisements is allowed again\n"); | 1173 | "Testing new hostlist advertisements is allowed again\n"); |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | 1176 | ||
@@ -1179,17 +1180,17 @@ task_testing_intervall_reset(void *cls) | |||
1179 | * @param cls closure | 1180 | * @param cls closure |
1180 | */ | 1181 | */ |
1181 | static void | 1182 | static void |
1182 | task_hostlist_saving(void *cls) | 1183 | task_hostlist_saving (void *cls) |
1183 | { | 1184 | { |
1184 | ti_saving_task = NULL; | 1185 | ti_saving_task = NULL; |
1185 | save_hostlist_file(GNUNET_NO); | 1186 | save_hostlist_file (GNUNET_NO); |
1186 | 1187 | ||
1187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1188 | "Hostlists will be saved to file again in %s\n", | 1189 | "Hostlists will be saved to file again in %s\n", |
1189 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, | 1190 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, |
1190 | GNUNET_YES)); | 1191 | GNUNET_YES)); |
1191 | ti_saving_task = | 1192 | ti_saving_task = |
1192 | GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, &task_hostlist_saving, NULL); | 1193 | GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL); |
1193 | } | 1194 | } |
1194 | 1195 | ||
1195 | 1196 | ||
@@ -1201,16 +1202,16 @@ task_hostlist_saving(void *cls) | |||
1201 | * @param mq message queue for transmissions to @a peer | 1202 | * @param mq message queue for transmissions to @a peer |
1202 | */ | 1203 | */ |
1203 | static void * | 1204 | static void * |
1204 | handler_connect(void *cls, | 1205 | handler_connect (void *cls, |
1205 | const struct GNUNET_PeerIdentity *peer, | 1206 | const struct GNUNET_PeerIdentity *peer, |
1206 | struct GNUNET_MQ_Handle *mq) | 1207 | struct GNUNET_MQ_Handle *mq) |
1207 | { | 1208 | { |
1208 | GNUNET_assert(stat_connection_count < UINT_MAX); | 1209 | GNUNET_assert (stat_connection_count < UINT_MAX); |
1209 | stat_connection_count++; | 1210 | stat_connection_count++; |
1210 | GNUNET_STATISTICS_update(stats, | 1211 | GNUNET_STATISTICS_update (stats, |
1211 | gettext_noop("# active connections"), | 1212 | gettext_noop ("# active connections"), |
1212 | 1, | 1213 | 1, |
1213 | GNUNET_NO); | 1214 | GNUNET_NO); |
1214 | return NULL; | 1215 | return NULL; |
1215 | } | 1216 | } |
1216 | 1217 | ||
@@ -1222,16 +1223,16 @@ handler_connect(void *cls, | |||
1222 | * @param peer peer identity this notification is about | 1223 | * @param peer peer identity this notification is about |
1223 | */ | 1224 | */ |
1224 | static void | 1225 | static void |
1225 | handler_disconnect(void *cls, | 1226 | handler_disconnect (void *cls, |
1226 | const struct GNUNET_PeerIdentity *peer, | 1227 | const struct GNUNET_PeerIdentity *peer, |
1227 | void *internal_cls) | 1228 | void *internal_cls) |
1228 | { | 1229 | { |
1229 | GNUNET_assert(stat_connection_count > 0); | 1230 | GNUNET_assert (stat_connection_count > 0); |
1230 | stat_connection_count--; | 1231 | stat_connection_count--; |
1231 | GNUNET_STATISTICS_update(stats, | 1232 | GNUNET_STATISTICS_update (stats, |
1232 | gettext_noop("# active connections"), | 1233 | gettext_noop ("# active connections"), |
1233 | -1, | 1234 | -1, |
1234 | GNUNET_NO); | 1235 | GNUNET_NO); |
1235 | } | 1236 | } |
1236 | 1237 | ||
1237 | 1238 | ||
@@ -1241,57 +1242,57 @@ handler_disconnect(void *cls, | |||
1241 | * @param uri the advertised URI | 1242 | * @param uri the advertised URI |
1242 | */ | 1243 | */ |
1243 | static void | 1244 | static void |
1244 | handler_advertisement(const char *uri) | 1245 | handler_advertisement (const char *uri) |
1245 | { | 1246 | { |
1246 | size_t uri_size; | 1247 | size_t uri_size; |
1247 | struct Hostlist *hostlist; | 1248 | struct Hostlist *hostlist; |
1248 | 1249 | ||
1249 | uri_size = strlen(uri) + 1; | 1250 | uri_size = strlen (uri) + 1; |
1250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Hostlist client recieved advertisement containing URI `%s'\n", | 1252 | "Hostlist client recieved advertisement containing URI `%s'\n", |
1252 | uri); | 1253 | uri); |
1253 | if (GNUNET_NO != linked_list_contains(uri)) | 1254 | if (GNUNET_NO != linked_list_contains (uri)) |
1254 | { | 1255 | { |
1255 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); |
1256 | return; | 1257 | return; |
1257 | } | 1258 | } |
1258 | 1259 | ||
1259 | if (GNUNET_NO == stat_testing_allowed) | 1260 | if (GNUNET_NO == stat_testing_allowed) |
1260 | { | 1261 | { |
1261 | GNUNET_log( | 1262 | GNUNET_log ( |
1262 | GNUNET_ERROR_TYPE_DEBUG, | 1263 | GNUNET_ERROR_TYPE_DEBUG, |
1263 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); | 1264 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); |
1264 | return; | 1265 | return; |
1265 | } | 1266 | } |
1266 | if (GNUNET_YES == stat_testing_hostlist) | 1267 | if (GNUNET_YES == stat_testing_hostlist) |
1267 | { | 1268 | { |
1268 | GNUNET_log( | 1269 | GNUNET_log ( |
1269 | GNUNET_ERROR_TYPE_DEBUG, | 1270 | GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); | 1271 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); |
1271 | return; | 1272 | return; |
1272 | } | 1273 | } |
1273 | 1274 | ||
1274 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + uri_size); | 1275 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + uri_size); |
1275 | hostlist->hostlist_uri = (const char *)&hostlist[1]; | 1276 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1276 | GNUNET_memcpy(&hostlist[1], uri, uri_size); | 1277 | GNUNET_memcpy (&hostlist[1], uri, uri_size); |
1277 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | 1278 | hostlist->time_creation = GNUNET_TIME_absolute_get (); |
1278 | hostlist->quality = HOSTLIST_INITIAL; | 1279 | hostlist->quality = HOSTLIST_INITIAL; |
1279 | hostlist_to_test = hostlist; | 1280 | hostlist_to_test = hostlist; |
1280 | 1281 | ||
1281 | stat_testing_hostlist = GNUNET_YES; | 1282 | stat_testing_hostlist = GNUNET_YES; |
1282 | stat_testing_allowed = GNUNET_NO; | 1283 | stat_testing_allowed = GNUNET_NO; |
1283 | ti_testing_intervall_task = | 1284 | ti_testing_intervall_task = |
1284 | GNUNET_SCHEDULER_add_delayed(TESTING_INTERVAL, | 1285 | GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, |
1285 | &task_testing_intervall_reset, | 1286 | &task_testing_intervall_reset, |
1286 | NULL); | 1287 | NULL); |
1287 | 1288 | ||
1288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1289 | "Testing new hostlist advertisements is locked for the next %s\n", | 1290 | "Testing new hostlist advertisements is locked for the next %s\n", |
1290 | GNUNET_STRINGS_relative_time_to_string(TESTING_INTERVAL, | 1291 | GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL, |
1291 | GNUNET_YES)); | 1292 | GNUNET_YES)); |
1292 | 1293 | ||
1293 | ti_download_dispatcher_task = | 1294 | ti_download_dispatcher_task = |
1294 | GNUNET_SCHEDULER_add_now(&task_download_dispatcher, NULL); | 1295 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1295 | } | 1296 | } |
1296 | 1297 | ||
1297 | 1298 | ||
@@ -1304,18 +1305,18 @@ handler_advertisement(const char *uri) | |||
1304 | * successfully obtained, #GNUNET_SYSERR if not. | 1305 | * successfully obtained, #GNUNET_SYSERR if not. |
1305 | */ | 1306 | */ |
1306 | static void | 1307 | static void |
1307 | primary_task(void *cls, int success) | 1308 | primary_task (void *cls, int success) |
1308 | { | 1309 | { |
1309 | if (NULL != ti_check_download) | 1310 | if (NULL != ti_check_download) |
1310 | { | 1311 | { |
1311 | GNUNET_SCHEDULER_cancel(ti_check_download); | 1312 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1312 | ti_check_download = NULL; | 1313 | ti_check_download = NULL; |
1313 | } | 1314 | } |
1314 | sget = NULL; | 1315 | sget = NULL; |
1315 | GNUNET_assert(NULL != stats); | 1316 | GNUNET_assert (NULL != stats); |
1316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1317 | "Statistics request done, scheduling hostlist download\n"); | 1318 | "Statistics request done, scheduling hostlist download\n"); |
1318 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1319 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1319 | } | 1320 | } |
1320 | 1321 | ||
1321 | 1322 | ||
@@ -1328,11 +1329,11 @@ primary_task(void *cls, int success) | |||
1328 | * successfully obtained, #GNUNET_SYSERR if not. | 1329 | * successfully obtained, #GNUNET_SYSERR if not. |
1329 | */ | 1330 | */ |
1330 | static void | 1331 | static void |
1331 | stat_timeout_task(void *cls) | 1332 | stat_timeout_task (void *cls) |
1332 | { | 1333 | { |
1333 | GNUNET_STATISTICS_get_cancel(sget); | 1334 | GNUNET_STATISTICS_get_cancel (sget); |
1334 | sget = NULL; | 1335 | sget = NULL; |
1335 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1336 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1336 | } | 1337 | } |
1337 | 1338 | ||
1338 | 1339 | ||
@@ -1346,17 +1347,17 @@ stat_timeout_task(void *cls) | |||
1346 | * @param is_persistent unused, will be #GNUNET_YES | 1347 | * @param is_persistent unused, will be #GNUNET_YES |
1347 | */ | 1348 | */ |
1348 | static int | 1349 | static int |
1349 | process_stat(void *cls, | 1350 | process_stat (void *cls, |
1350 | const char *subsystem, | 1351 | const char *subsystem, |
1351 | const char *name, | 1352 | const char *name, |
1352 | uint64_t value, | 1353 | uint64_t value, |
1353 | int is_persistent) | 1354 | int is_persistent) |
1354 | { | 1355 | { |
1355 | hostlist_delay.rel_value_us = value * 1000LL; | 1356 | hostlist_delay.rel_value_us = value * 1000LL; |
1356 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1357 | "Initial time between hostlist downloads is %s\n", | 1358 | "Initial time between hostlist downloads is %s\n", |
1358 | GNUNET_STRINGS_relative_time_to_string(hostlist_delay, | 1359 | GNUNET_STRINGS_relative_time_to_string (hostlist_delay, |
1359 | GNUNET_YES)); | 1360 | GNUNET_YES)); |
1360 | return GNUNET_OK; | 1361 | return GNUNET_OK; |
1361 | } | 1362 | } |
1362 | 1363 | ||
@@ -1365,7 +1366,7 @@ process_stat(void *cls, | |||
1365 | * Method to load persistent hostlist file during hostlist client startup | 1366 | * Method to load persistent hostlist file during hostlist client startup |
1366 | */ | 1367 | */ |
1367 | static void | 1368 | static void |
1368 | load_hostlist_file() | 1369 | load_hostlist_file () |
1369 | { | 1370 | { |
1370 | char *filename; | 1371 | char *filename; |
1371 | char *uri; | 1372 | char *uri; |
@@ -1380,87 +1381,87 @@ load_hostlist_file() | |||
1380 | struct GNUNET_BIO_ReadHandle *rh; | 1381 | struct GNUNET_BIO_ReadHandle *rh; |
1381 | 1382 | ||
1382 | uri = NULL; | 1383 | uri = NULL; |
1383 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, | 1384 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
1384 | "HOSTLIST", | 1385 | "HOSTLIST", |
1385 | "HOSTLISTFILE", | 1386 | "HOSTLISTFILE", |
1386 | &filename)) | 1387 | &filename)) |
1387 | { | 1388 | { |
1388 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 1389 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1389 | "hostlist", | 1390 | "hostlist", |
1390 | "HOSTLISTFILE"); | 1391 | "HOSTLISTFILE"); |
1391 | return; | 1392 | return; |
1392 | } | 1393 | } |
1393 | 1394 | ||
1394 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1395 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1395 | _("Loading saved hostlist entries from file `%s' \n"), | 1396 | _ ("Loading saved hostlist entries from file `%s' \n"), |
1396 | filename); | 1397 | filename); |
1397 | if (GNUNET_NO == GNUNET_DISK_file_test(filename)) | 1398 | if (GNUNET_NO == GNUNET_DISK_file_test (filename)) |
1398 | { | 1399 | { |
1399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1400 | _("Hostlist file `%s' does not exist\n"), | 1401 | _ ("Hostlist file `%s' does not exist\n"), |
1401 | filename); | 1402 | filename); |
1402 | GNUNET_free(filename); | 1403 | GNUNET_free (filename); |
1403 | return; | 1404 | return; |
1404 | } | 1405 | } |
1405 | 1406 | ||
1406 | rh = GNUNET_BIO_read_open(filename); | 1407 | rh = GNUNET_BIO_read_open (filename); |
1407 | if (NULL == rh) | 1408 | if (NULL == rh) |
1408 | { | 1409 | { |
1409 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1410 | _( | 1411 | _ ( |
1411 | "Could not open file `%s' for reading to load hostlists: %s\n"), | 1412 | "Could not open file `%s' for reading to load hostlists: %s\n"), |
1412 | filename, | 1413 | filename, |
1413 | strerror(errno)); | 1414 | strerror (errno)); |
1414 | GNUNET_free(filename); | 1415 | GNUNET_free (filename); |
1415 | return; | 1416 | return; |
1416 | } | 1417 | } |
1417 | 1418 | ||
1418 | counter = 0; | 1419 | counter = 0; |
1419 | while ((GNUNET_OK == GNUNET_BIO_read_string(rh, "url", &uri, MAX_URL_LEN)) && | 1420 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1420 | (NULL != uri) && | 1421 | (NULL != uri) && |
1421 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, ×_used)) && | 1422 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && |
1422 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &quality)) && | 1423 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && |
1423 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &last_used)) && | 1424 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && |
1424 | (GNUNET_OK == GNUNET_BIO_read_int64(rh, &created)) && | 1425 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && |
1425 | (GNUNET_OK == GNUNET_BIO_read_int32(rh, &hellos_returned))) | 1426 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) |
1426 | { | 1427 | { |
1427 | hostlist = GNUNET_malloc(sizeof(struct Hostlist) + strlen(uri) + 1); | 1428 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); |
1428 | hostlist->hello_count = hellos_returned; | 1429 | hostlist->hello_count = hellos_returned; |
1429 | hostlist->hostlist_uri = (const char *)&hostlist[1]; | 1430 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1430 | GNUNET_memcpy(&hostlist[1], uri, strlen(uri) + 1); | 1431 | GNUNET_memcpy (&hostlist[1], uri, strlen (uri) + 1); |
1431 | hostlist->quality = quality; | 1432 | hostlist->quality = quality; |
1432 | hostlist->time_creation.abs_value_us = created; | 1433 | hostlist->time_creation.abs_value_us = created; |
1433 | hostlist->time_last_usage.abs_value_us = last_used; | 1434 | hostlist->time_last_usage.abs_value_us = last_used; |
1434 | GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); | 1435 | GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist); |
1435 | linked_list_size++; | 1436 | linked_list_size++; |
1436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1437 | "Added hostlist entry eith URI `%s' \n", | 1438 | "Added hostlist entry eith URI `%s' \n", |
1438 | hostlist->hostlist_uri); | 1439 | hostlist->hostlist_uri); |
1439 | GNUNET_free(uri); | 1440 | GNUNET_free (uri); |
1440 | uri = NULL; | 1441 | uri = NULL; |
1441 | counter++; | 1442 | counter++; |
1442 | if (counter >= MAX_NUMBER_HOSTLISTS) | 1443 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1443 | break; | 1444 | break; |
1444 | } | 1445 | } |
1445 | 1446 | ||
1446 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1447 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1447 | _("%u hostlist URIs loaded from file\n"), | 1448 | _ ("%u hostlist URIs loaded from file\n"), |
1448 | counter); | 1449 | counter); |
1449 | GNUNET_STATISTICS_set(stats, | 1450 | GNUNET_STATISTICS_set (stats, |
1450 | gettext_noop("# hostlist URIs read from file"), | 1451 | gettext_noop ("# hostlist URIs read from file"), |
1451 | counter, | 1452 | counter, |
1452 | GNUNET_YES); | 1453 | GNUNET_YES); |
1453 | GNUNET_STATISTICS_set(stats, | 1454 | GNUNET_STATISTICS_set (stats, |
1454 | gettext_noop("# advertised hostlist URIs"), | 1455 | gettext_noop ("# advertised hostlist URIs"), |
1455 | linked_list_size, | 1456 | linked_list_size, |
1456 | GNUNET_NO); | 1457 | GNUNET_NO); |
1457 | 1458 | ||
1458 | GNUNET_free_non_null(uri); | 1459 | GNUNET_free_non_null (uri); |
1459 | emsg = NULL; | 1460 | emsg = NULL; |
1460 | (void)GNUNET_BIO_read_close(rh, &emsg); | 1461 | (void) GNUNET_BIO_read_close (rh, &emsg); |
1461 | if (emsg != NULL) | 1462 | if (emsg != NULL) |
1462 | GNUNET_free(emsg); | 1463 | GNUNET_free (emsg); |
1463 | GNUNET_free(filename); | 1464 | GNUNET_free (filename); |
1464 | } | 1465 | } |
1465 | 1466 | ||
1466 | 1467 | ||
@@ -1470,7 +1471,7 @@ load_hostlist_file() | |||
1470 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 1471 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
1471 | */ | 1472 | */ |
1472 | static void | 1473 | static void |
1473 | save_hostlist_file(int shutdown) | 1474 | save_hostlist_file (int shutdown) |
1474 | { | 1475 | { |
1475 | char *filename; | 1476 | char *filename; |
1476 | struct Hostlist *pos; | 1477 | struct Hostlist *pos; |
@@ -1478,80 +1479,80 @@ save_hostlist_file(int shutdown) | |||
1478 | int ok; | 1479 | int ok; |
1479 | uint32_t counter; | 1480 | uint32_t counter; |
1480 | 1481 | ||
1481 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, | 1482 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
1482 | "HOSTLIST", | 1483 | "HOSTLIST", |
1483 | "HOSTLISTFILE", | 1484 | "HOSTLISTFILE", |
1484 | &filename)) | 1485 | &filename)) |
1485 | { | 1486 | { |
1486 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, | 1487 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1487 | "hostlist", | 1488 | "hostlist", |
1488 | "HOSTLISTFILE"); | 1489 | "HOSTLISTFILE"); |
1489 | return; | 1490 | return; |
1490 | } | 1491 | } |
1491 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file(filename)) | 1492 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
1492 | { | 1493 | { |
1493 | GNUNET_free(filename); | 1494 | GNUNET_free (filename); |
1494 | return; | 1495 | return; |
1495 | } | 1496 | } |
1496 | wh = GNUNET_BIO_write_open(filename); | 1497 | wh = GNUNET_BIO_write_open (filename); |
1497 | if (NULL == wh) | 1498 | if (NULL == wh) |
1498 | { | 1499 | { |
1499 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1500 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1500 | _( | 1501 | _ ( |
1501 | "Could not open file `%s' for writing to save hostlists: %s\n"), | 1502 | "Could not open file `%s' for writing to save hostlists: %s\n"), |
1502 | filename, | 1503 | filename, |
1503 | strerror(errno)); | 1504 | strerror (errno)); |
1504 | GNUNET_free(filename); | 1505 | GNUNET_free (filename); |
1505 | return; | 1506 | return; |
1506 | } | 1507 | } |
1507 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1508 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1508 | _("Writing %u hostlist URIs to `%s'\n"), | 1509 | _ ("Writing %u hostlist URIs to `%s'\n"), |
1509 | linked_list_size, | 1510 | linked_list_size, |
1510 | filename); | 1511 | filename); |
1511 | /* add code to write hostlists to file using bio */ | 1512 | /* add code to write hostlists to file using bio */ |
1512 | ok = GNUNET_YES; | 1513 | ok = GNUNET_YES; |
1513 | counter = 0; | 1514 | counter = 0; |
1514 | while (NULL != (pos = linked_list_head)) | 1515 | while (NULL != (pos = linked_list_head)) |
1516 | { | ||
1517 | if (GNUNET_YES == shutdown) | ||
1515 | { | 1518 | { |
1516 | if (GNUNET_YES == shutdown) | 1519 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); |
1517 | { | 1520 | linked_list_size--; |
1518 | GNUNET_CONTAINER_DLL_remove(linked_list_head, linked_list_tail, pos); | 1521 | } |
1519 | linked_list_size--; | 1522 | if (GNUNET_YES == ok) |
1520 | } | 1523 | { |
1521 | if (GNUNET_YES == ok) | 1524 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || |
1522 | { | 1525 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) || |
1523 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, pos->hostlist_uri)) || | 1526 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) || |
1524 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->times_used)) || | 1527 | (GNUNET_OK != |
1525 | (GNUNET_OK != GNUNET_BIO_write_int64(wh, pos->quality)) || | 1528 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) || |
1526 | (GNUNET_OK != | 1529 | (GNUNET_OK != |
1527 | GNUNET_BIO_write_int64(wh, pos->time_last_usage.abs_value_us)) || | 1530 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) || |
1528 | (GNUNET_OK != | 1531 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) |
1529 | GNUNET_BIO_write_int64(wh, pos->time_creation.abs_value_us)) || | 1532 | { |
1530 | (GNUNET_OK != GNUNET_BIO_write_int32(wh, pos->hello_count))) | 1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1531 | { | 1534 | _ ("Error writing hostlist URIs to file `%s'\n"), |
1532 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1535 | filename); |
1533 | _("Error writing hostlist URIs to file `%s'\n"), | 1536 | ok = GNUNET_NO; |
1534 | filename); | 1537 | } |
1535 | ok = GNUNET_NO; | ||
1536 | } | ||
1537 | } | ||
1538 | |||
1539 | if (GNUNET_YES == shutdown) | ||
1540 | GNUNET_free(pos); | ||
1541 | counter++; | ||
1542 | if (counter >= MAX_NUMBER_HOSTLISTS) | ||
1543 | break; | ||
1544 | } | 1538 | } |
1545 | GNUNET_STATISTICS_set(stats, | 1539 | |
1546 | gettext_noop("# hostlist URIs written to file"), | 1540 | if (GNUNET_YES == shutdown) |
1547 | counter, | 1541 | GNUNET_free (pos); |
1548 | GNUNET_YES); | 1542 | counter++; |
1549 | 1543 | if (counter >= MAX_NUMBER_HOSTLISTS) | |
1550 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) | 1544 | break; |
1551 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1545 | } |
1552 | _("Error writing hostlist URIs to file `%s'\n"), | 1546 | GNUNET_STATISTICS_set (stats, |
1553 | filename); | 1547 | gettext_noop ("# hostlist URIs written to file"), |
1554 | GNUNET_free(filename); | 1548 | counter, |
1549 | GNUNET_YES); | ||
1550 | |||
1551 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | ||
1552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1553 | _ ("Error writing hostlist URIs to file `%s'\n"), | ||
1554 | filename); | ||
1555 | GNUNET_free (filename); | ||
1555 | } | 1556 | } |
1556 | 1557 | ||
1557 | 1558 | ||
@@ -1567,94 +1568,94 @@ save_hostlist_file(int shutdown) | |||
1567 | * @return #GNUNET_OK on success | 1568 | * @return #GNUNET_OK on success |
1568 | */ | 1569 | */ |
1569 | int | 1570 | int |
1570 | GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | 1571 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
1571 | struct GNUNET_STATISTICS_Handle *st, | 1572 | struct GNUNET_STATISTICS_Handle *st, |
1572 | GNUNET_CORE_ConnectEventHandler *ch, | 1573 | GNUNET_CORE_ConnectEventHandler *ch, |
1573 | GNUNET_CORE_DisconnectEventHandler *dh, | 1574 | GNUNET_CORE_DisconnectEventHandler *dh, |
1574 | GNUNET_HOSTLIST_UriHandler *msgh, | 1575 | GNUNET_HOSTLIST_UriHandler *msgh, |
1575 | int learn) | 1576 | int learn) |
1576 | { | 1577 | { |
1577 | char *filename; | 1578 | char *filename; |
1578 | char *proxytype_str; | 1579 | char *proxytype_str; |
1579 | int result; | 1580 | int result; |
1580 | 1581 | ||
1581 | GNUNET_assert(NULL != st); | 1582 | GNUNET_assert (NULL != st); |
1582 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | 1583 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
1583 | { | 1584 | { |
1584 | GNUNET_break(0); | 1585 | GNUNET_break (0); |
1585 | return GNUNET_SYSERR; | 1586 | return GNUNET_SYSERR; |
1586 | } | 1587 | } |
1587 | cfg = c; | 1588 | cfg = c; |
1588 | stats = st; | 1589 | stats = st; |
1589 | 1590 | ||
1590 | /* Read proxy configuration */ | 1591 | /* Read proxy configuration */ |
1591 | pi = GNUNET_PEERINFO_connect(c); | 1592 | pi = GNUNET_PEERINFO_connect (c); |
1592 | if (GNUNET_OK == | 1593 | if (GNUNET_OK == |
1593 | GNUNET_CONFIGURATION_get_value_string(cfg, "HOSTLIST", "PROXY", &proxy)) | 1594 | GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy)) |
1595 | { | ||
1596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); | ||
1597 | /* proxy username */ | ||
1598 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1599 | "HOSTLIST", | ||
1600 | "PROXY_USERNAME", | ||
1601 | &proxy_username)) | ||
1594 | { | 1602 | { |
1595 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); | 1603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1596 | /* proxy username */ | 1604 | "Found proxy username name: `%s'\n", |
1597 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1605 | proxy_username); |
1598 | "HOSTLIST", | 1606 | } |
1599 | "PROXY_USERNAME", | ||
1600 | &proxy_username)) | ||
1601 | { | ||
1602 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1603 | "Found proxy username name: `%s'\n", | ||
1604 | proxy_username); | ||
1605 | } | ||
1606 | 1607 | ||
1607 | /* proxy password */ | 1608 | /* proxy password */ |
1608 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1609 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, |
1609 | "HOSTLIST", | 1610 | "HOSTLIST", |
1610 | "PROXY_PASSWORD", | 1611 | "PROXY_PASSWORD", |
1611 | &proxy_password)) | 1612 | &proxy_password)) |
1612 | { | 1613 | { |
1613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1614 | "Found proxy password name: `%s'\n", | 1615 | "Found proxy password name: `%s'\n", |
1615 | proxy_password); | 1616 | proxy_password); |
1616 | } | 1617 | } |
1617 | 1618 | ||
1618 | /* proxy type */ | 1619 | /* proxy type */ |
1619 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | 1620 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, |
1620 | "HOSTLIST", | 1621 | "HOSTLIST", |
1621 | "PROXY_TYPE", | 1622 | "PROXY_TYPE", |
1622 | &proxytype_str)) | 1623 | &proxytype_str)) |
1623 | { | 1624 | { |
1624 | GNUNET_STRINGS_utf8_toupper(proxytype_str, proxytype_str); | 1625 | GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); |
1625 | proxy_type = CURLPROXY_HTTP; | 1626 | proxy_type = CURLPROXY_HTTP; |
1626 | if (0 == strcmp(proxytype_str, "HTTP")) | 1627 | if (0 == strcmp (proxytype_str, "HTTP")) |
1627 | proxy_type = CURLPROXY_HTTP; | 1628 | proxy_type = CURLPROXY_HTTP; |
1628 | else if (0 == strcmp(proxytype_str, "HTTP_1_0")) | 1629 | else if (0 == strcmp (proxytype_str, "HTTP_1_0")) |
1629 | proxy_type = CURLPROXY_HTTP_1_0; | 1630 | proxy_type = CURLPROXY_HTTP_1_0; |
1630 | else if (0 == strcmp(proxytype_str, "SOCKS4")) | 1631 | else if (0 == strcmp (proxytype_str, "SOCKS4")) |
1631 | proxy_type = CURLPROXY_SOCKS4; | 1632 | proxy_type = CURLPROXY_SOCKS4; |
1632 | else if (0 == strcmp(proxytype_str, "SOCKS5")) | 1633 | else if (0 == strcmp (proxytype_str, "SOCKS5")) |
1633 | proxy_type = CURLPROXY_SOCKS5; | 1634 | proxy_type = CURLPROXY_SOCKS5; |
1634 | else if (0 == strcmp(proxytype_str, "SOCKS4A")) | 1635 | else if (0 == strcmp (proxytype_str, "SOCKS4A")) |
1635 | proxy_type = CURLPROXY_SOCKS4A; | 1636 | proxy_type = CURLPROXY_SOCKS4A; |
1636 | else if (0 == strcmp(proxytype_str, "SOCKS5_HOSTNAME")) | 1637 | else if (0 == strcmp (proxytype_str, "SOCKS5_HOSTNAME")) |
1637 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; | 1638 | proxy_type = CURLPROXY_SOCKS5_HOSTNAME; |
1638 | else | 1639 | else |
1639 | { | 1640 | { |
1640 | GNUNET_log( | 1641 | GNUNET_log ( |
1641 | GNUNET_ERROR_TYPE_ERROR, | 1642 | GNUNET_ERROR_TYPE_ERROR, |
1642 | _( | 1643 | _ ( |
1643 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), | 1644 | "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), |
1644 | proxytype_str); | 1645 | proxytype_str); |
1645 | GNUNET_free(proxytype_str); | 1646 | GNUNET_free (proxytype_str); |
1646 | GNUNET_free(proxy); | 1647 | GNUNET_free (proxy); |
1647 | proxy = NULL; | 1648 | proxy = NULL; |
1648 | GNUNET_free_non_null(proxy_username); | 1649 | GNUNET_free_non_null (proxy_username); |
1649 | proxy_username = NULL; | 1650 | proxy_username = NULL; |
1650 | GNUNET_free_non_null(proxy_password); | 1651 | GNUNET_free_non_null (proxy_password); |
1651 | proxy_password = NULL; | 1652 | proxy_password = NULL; |
1652 | 1653 | ||
1653 | return GNUNET_SYSERR; | 1654 | return GNUNET_SYSERR; |
1654 | } | 1655 | } |
1655 | } | ||
1656 | GNUNET_free_non_null(proxytype_str); | ||
1657 | } | 1656 | } |
1657 | GNUNET_free_non_null (proxytype_str); | ||
1658 | } | ||
1658 | 1659 | ||
1659 | stat_learning = learn; | 1660 | stat_learning = learn; |
1660 | *ch = &handler_connect; | 1661 | *ch = &handler_connect; |
@@ -1666,67 +1667,67 @@ GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
1666 | stat_testing_allowed = GNUNET_YES; | 1667 | stat_testing_allowed = GNUNET_YES; |
1667 | 1668 | ||
1668 | if (GNUNET_YES == stat_learning) | 1669 | if (GNUNET_YES == stat_learning) |
1669 | { | 1670 | { |
1670 | *msgh = &handler_advertisement; | 1671 | *msgh = &handler_advertisement; |
1671 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1672 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1672 | _("Learning is enabled on this peer\n")); | 1673 | _ ("Learning is enabled on this peer\n")); |
1673 | load_hostlist_file(); | 1674 | load_hostlist_file (); |
1674 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1675 | "Hostlists will be saved to file again in %s\n", | 1676 | "Hostlists will be saved to file again in %s\n", |
1676 | GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, | 1677 | GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, |
1677 | GNUNET_YES)); | 1678 | GNUNET_YES)); |
1678 | ti_saving_task = GNUNET_SCHEDULER_add_delayed(SAVING_INTERVAL, | 1679 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, |
1679 | &task_hostlist_saving, | 1680 | &task_hostlist_saving, |
1680 | NULL); | 1681 | NULL); |
1681 | } | 1682 | } |
1682 | else | 1683 | else |
1684 | { | ||
1685 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1686 | _ ("Learning is not enabled on this peer\n")); | ||
1687 | *msgh = NULL; | ||
1688 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1689 | "HOSTLIST", | ||
1690 | "HOSTLISTFILE", | ||
1691 | &filename)) | ||
1683 | { | 1692 | { |
1684 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1693 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
1685 | _("Learning is not enabled on this peer\n")); | 1694 | { |
1686 | *msgh = NULL; | 1695 | result = remove (filename); |
1687 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, | 1696 | if (0 == result) |
1688 | "HOSTLIST", | 1697 | GNUNET_log ( |
1689 | "HOSTLISTFILE", | 1698 | GNUNET_ERROR_TYPE_INFO, |
1690 | &filename)) | 1699 | _ ( |
1691 | { | 1700 | "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), |
1692 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) | 1701 | filename); |
1693 | { | 1702 | else |
1694 | result = remove(filename); | 1703 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
1695 | if (0 == result) | 1704 | "remove", |
1696 | GNUNET_log( | 1705 | filename); |
1697 | GNUNET_ERROR_TYPE_INFO, | 1706 | } |
1698 | _( | ||
1699 | "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | ||
1700 | filename); | ||
1701 | else | ||
1702 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | ||
1703 | "remove", | ||
1704 | filename); | ||
1705 | } | ||
1706 | } | ||
1707 | GNUNET_free(filename); | ||
1708 | } | 1707 | } |
1709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1708 | GNUNET_free (filename); |
1710 | "Loading stats value on hostlist download frequency\n"); | 1709 | } |
1711 | sget = GNUNET_STATISTICS_get(stats, | 1710 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1712 | "hostlist", | 1711 | "Loading stats value on hostlist download frequency\n"); |
1713 | gettext_noop( | 1712 | sget = GNUNET_STATISTICS_get (stats, |
1714 | "# milliseconds between hostlist downloads"), | 1713 | "hostlist", |
1715 | &primary_task, | 1714 | gettext_noop ( |
1716 | &process_stat, | 1715 | "# milliseconds between hostlist downloads"), |
1717 | NULL); | 1716 | &primary_task, |
1717 | &process_stat, | ||
1718 | NULL); | ||
1718 | if (NULL == sget) | 1719 | if (NULL == sget) |
1719 | { | 1720 | { |
1720 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1721 | "Statistics request failed, scheduling hostlist download\n"); | 1722 | "Statistics request failed, scheduling hostlist download\n"); |
1722 | ti_check_download = GNUNET_SCHEDULER_add_now(&task_check, NULL); | 1723 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1723 | } | 1724 | } |
1724 | else | 1725 | else |
1725 | { | 1726 | { |
1726 | ti_check_download = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 1727 | ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
1727 | &stat_timeout_task, | 1728 | &stat_timeout_task, |
1728 | NULL); | 1729 | NULL); |
1729 | } | 1730 | } |
1730 | return GNUNET_OK; | 1731 | return GNUNET_OK; |
1731 | } | 1732 | } |
1732 | 1733 | ||
@@ -1735,56 +1736,56 @@ GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
1735 | * Stop downloading hostlists from hostlist servers as necessary. | 1736 | * Stop downloading hostlists from hostlist servers as necessary. |
1736 | */ | 1737 | */ |
1737 | void | 1738 | void |
1738 | GNUNET_HOSTLIST_client_stop() | 1739 | GNUNET_HOSTLIST_client_stop () |
1739 | { | 1740 | { |
1740 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); | 1741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1741 | if (NULL != sget) | 1742 | if (NULL != sget) |
1742 | { | 1743 | { |
1743 | GNUNET_STATISTICS_get_cancel(sget); | 1744 | GNUNET_STATISTICS_get_cancel (sget); |
1744 | sget = NULL; | 1745 | sget = NULL; |
1745 | } | 1746 | } |
1746 | stats = NULL; | 1747 | stats = NULL; |
1747 | if (GNUNET_YES == stat_learning) | 1748 | if (GNUNET_YES == stat_learning) |
1748 | save_hostlist_file(GNUNET_YES); | 1749 | save_hostlist_file (GNUNET_YES); |
1749 | if (NULL != ti_saving_task) | 1750 | if (NULL != ti_saving_task) |
1750 | { | 1751 | { |
1751 | GNUNET_SCHEDULER_cancel(ti_saving_task); | 1752 | GNUNET_SCHEDULER_cancel (ti_saving_task); |
1752 | ti_saving_task = NULL; | 1753 | ti_saving_task = NULL; |
1753 | } | 1754 | } |
1754 | if (NULL != ti_download_dispatcher_task) | 1755 | if (NULL != ti_download_dispatcher_task) |
1755 | { | 1756 | { |
1756 | GNUNET_SCHEDULER_cancel(ti_download_dispatcher_task); | 1757 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); |
1757 | ti_download_dispatcher_task = NULL; | 1758 | ti_download_dispatcher_task = NULL; |
1758 | } | 1759 | } |
1759 | if (NULL != ti_testing_intervall_task) | 1760 | if (NULL != ti_testing_intervall_task) |
1760 | { | 1761 | { |
1761 | GNUNET_SCHEDULER_cancel(ti_testing_intervall_task); | 1762 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); |
1762 | ti_testing_intervall_task = NULL; | 1763 | ti_testing_intervall_task = NULL; |
1763 | } | 1764 | } |
1764 | if (NULL != ti_download) | 1765 | if (NULL != ti_download) |
1765 | { | 1766 | { |
1766 | GNUNET_SCHEDULER_cancel(ti_download); | 1767 | GNUNET_SCHEDULER_cancel (ti_download); |
1767 | ti_download = NULL; | 1768 | ti_download = NULL; |
1768 | update_hostlist(); | 1769 | update_hostlist (); |
1769 | clean_up(); | 1770 | clean_up (); |
1770 | } | 1771 | } |
1771 | if (NULL != ti_check_download) | 1772 | if (NULL != ti_check_download) |
1772 | { | 1773 | { |
1773 | GNUNET_SCHEDULER_cancel(ti_check_download); | 1774 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1774 | ti_check_download = NULL; | 1775 | ti_check_download = NULL; |
1775 | curl_global_cleanup(); | 1776 | curl_global_cleanup (); |
1776 | } | 1777 | } |
1777 | GNUNET_free_non_null(proxy); | 1778 | GNUNET_free_non_null (proxy); |
1778 | proxy = NULL; | 1779 | proxy = NULL; |
1779 | GNUNET_free_non_null(proxy_username); | 1780 | GNUNET_free_non_null (proxy_username); |
1780 | proxy_username = NULL; | 1781 | proxy_username = NULL; |
1781 | GNUNET_free_non_null(proxy_password); | 1782 | GNUNET_free_non_null (proxy_password); |
1782 | proxy_password = NULL; | 1783 | proxy_password = NULL; |
1783 | if (NULL != pi) | 1784 | if (NULL != pi) |
1784 | { | 1785 | { |
1785 | GNUNET_PEERINFO_disconnect(pi); | 1786 | GNUNET_PEERINFO_disconnect (pi); |
1786 | pi = NULL; | 1787 | pi = NULL; |
1787 | } | 1788 | } |
1788 | cfg = NULL; | 1789 | cfg = NULL; |
1789 | } | 1790 | } |
1790 | 1791 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.h b/src/hostlist/gnunet-daemon-hostlist_client.h index 4268b26dd..2ee40d961 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.h +++ b/src/hostlist/gnunet-daemon-hostlist_client.h | |||
@@ -51,19 +51,19 @@ typedef void | |||
51 | * @return #GNUNET_OK on success | 51 | * @return #GNUNET_OK on success |
52 | */ | 52 | */ |
53 | int | 53 | int |
54 | GNUNET_HOSTLIST_client_start(const struct GNUNET_CONFIGURATION_Handle *c, | 54 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
55 | struct GNUNET_STATISTICS_Handle *st, | 55 | struct GNUNET_STATISTICS_Handle *st, |
56 | GNUNET_CORE_ConnectEventHandler *ch, | 56 | GNUNET_CORE_ConnectEventHandler *ch, |
57 | GNUNET_CORE_DisconnectEventHandler *dh, | 57 | GNUNET_CORE_DisconnectEventHandler *dh, |
58 | GNUNET_HOSTLIST_UriHandler *msgh, | 58 | GNUNET_HOSTLIST_UriHandler *msgh, |
59 | int learn); | 59 | int learn); |
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Stop downloading hostlists from hostlist servers as necessary. | 63 | * Stop downloading hostlists from hostlist servers as necessary. |
64 | */ | 64 | */ |
65 | void | 65 | void |
66 | GNUNET_HOSTLIST_client_stop(void); | 66 | GNUNET_HOSTLIST_client_stop (void); |
67 | 67 | ||
68 | 68 | ||
69 | #endif | 69 | #endif |
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index b4e0df34e..43513930a 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c | |||
@@ -39,7 +39,7 @@ | |||
39 | * time out? | 39 | * time out? |
40 | */ | 40 | */ |
41 | #define GNUNET_ADV_TIMEOUT \ | 41 | #define GNUNET_ADV_TIMEOUT \ |
42 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -106,7 +106,8 @@ static char *hostlist_uri; | |||
106 | /** | 106 | /** |
107 | * Context for #host_processor(). | 107 | * Context for #host_processor(). |
108 | */ | 108 | */ |
109 | struct HostSet { | 109 | struct HostSet |
110 | { | ||
110 | /** | 111 | /** |
111 | * Iterator used to build @e data (NULL when done). | 112 | * Iterator used to build @e data (NULL when done). |
112 | */ | 113 | */ |
@@ -137,13 +138,13 @@ static struct HostSet *builder; | |||
137 | * @param response response to add headers to | 138 | * @param response response to add headers to |
138 | */ | 139 | */ |
139 | static void | 140 | static void |
140 | add_cors_headers(struct MHD_Response *response) | 141 | add_cors_headers (struct MHD_Response *response) |
141 | { | 142 | { |
142 | MHD_add_response_header(response, "Access-Control-Allow-Origin", "*"); | 143 | MHD_add_response_header (response, "Access-Control-Allow-Origin", "*"); |
143 | MHD_add_response_header(response, | 144 | MHD_add_response_header (response, |
144 | "Access-Control-Allow-Methods", | 145 | "Access-Control-Allow-Methods", |
145 | "GET, OPTIONS"); | 146 | "GET, OPTIONS"); |
146 | MHD_add_response_header(response, "Access-Control-Max-Age", "86400"); | 147 | MHD_add_response_header (response, "Access-Control-Max-Age", "86400"); |
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||
@@ -151,27 +152,27 @@ add_cors_headers(struct MHD_Response *response) | |||
151 | * Function that assembles our response. | 152 | * Function that assembles our response. |
152 | */ | 153 | */ |
153 | static void | 154 | static void |
154 | finish_response() | 155 | finish_response () |
155 | { | 156 | { |
156 | if (NULL != response) | 157 | if (NULL != response) |
157 | MHD_destroy_response(response); | 158 | MHD_destroy_response (response); |
158 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
159 | "Creating hostlist response with %u bytes\n", | 160 | "Creating hostlist response with %u bytes\n", |
160 | (unsigned int)builder->size); | 161 | (unsigned int) builder->size); |
161 | response = MHD_create_response_from_buffer(builder->size, | 162 | response = MHD_create_response_from_buffer (builder->size, |
162 | builder->data, | 163 | builder->data, |
163 | MHD_RESPMEM_MUST_FREE); | 164 | MHD_RESPMEM_MUST_FREE); |
164 | add_cors_headers(response); | 165 | add_cors_headers (response); |
165 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) | 166 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) |
166 | { | 167 | { |
167 | MHD_destroy_response(response); | 168 | MHD_destroy_response (response); |
168 | response = NULL; | 169 | response = NULL; |
169 | } | 170 | } |
170 | GNUNET_STATISTICS_set(stats, | 171 | GNUNET_STATISTICS_set (stats, |
171 | gettext_noop("bytes in hostlist"), | 172 | gettext_noop ("bytes in hostlist"), |
172 | builder->size, | 173 | builder->size, |
173 | GNUNET_YES); | 174 | GNUNET_YES); |
174 | GNUNET_free(builder); | 175 | GNUNET_free (builder); |
175 | builder = NULL; | 176 | builder = NULL; |
176 | } | 177 | } |
177 | 178 | ||
@@ -185,20 +186,20 @@ finish_response() | |||
185 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) | 186 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) |
186 | */ | 187 | */ |
187 | static int | 188 | static int |
188 | check_has_addr(void *cls, | 189 | check_has_addr (void *cls, |
189 | const struct GNUNET_HELLO_Address *address, | 190 | const struct GNUNET_HELLO_Address *address, |
190 | struct GNUNET_TIME_Absolute expiration) | 191 | struct GNUNET_TIME_Absolute expiration) |
191 | { | 192 | { |
192 | int *arg = cls; | 193 | int *arg = cls; |
193 | 194 | ||
194 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) | 195 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
195 | { | 196 | { |
196 | GNUNET_STATISTICS_update(stats, | 197 | GNUNET_STATISTICS_update (stats, |
197 | gettext_noop("expired addresses encountered"), | 198 | gettext_noop ("expired addresses encountered"), |
198 | 1, | 199 | 1, |
199 | GNUNET_YES); | 200 | GNUNET_YES); |
200 | return GNUNET_YES; /* ignore this address */ | 201 | return GNUNET_YES; /* ignore this address */ |
201 | } | 202 | } |
202 | *arg = GNUNET_YES; | 203 | *arg = GNUNET_YES; |
203 | return GNUNET_SYSERR; | 204 | return GNUNET_SYSERR; |
204 | } | 205 | } |
@@ -214,73 +215,73 @@ check_has_addr(void *cls, | |||
214 | * @param err_msg message | 215 | * @param err_msg message |
215 | */ | 216 | */ |
216 | static void | 217 | static void |
217 | host_processor(void *cls, | 218 | host_processor (void *cls, |
218 | const struct GNUNET_PeerIdentity *peer, | 219 | const struct GNUNET_PeerIdentity *peer, |
219 | const struct GNUNET_HELLO_Message *hello, | 220 | const struct GNUNET_HELLO_Message *hello, |
220 | const char *err_msg) | 221 | const char *err_msg) |
221 | { | 222 | { |
222 | size_t old; | 223 | size_t old; |
223 | size_t s; | 224 | size_t s; |
224 | int has_addr; | 225 | int has_addr; |
225 | 226 | ||
226 | if (NULL != err_msg) | 227 | if (NULL != err_msg) |
227 | { | 228 | { |
228 | GNUNET_assert(NULL == peer); | 229 | GNUNET_assert (NULL == peer); |
229 | builder->pitr = NULL; | 230 | builder->pitr = NULL; |
230 | GNUNET_free_non_null(builder->data); | 231 | GNUNET_free_non_null (builder->data); |
231 | GNUNET_free(builder); | 232 | GNUNET_free (builder); |
232 | builder = NULL; | 233 | builder = NULL; |
233 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
234 | _("Error in communication with PEERINFO service: %s\n"), | 235 | _ ("Error in communication with PEERINFO service: %s\n"), |
235 | err_msg); | 236 | err_msg); |
236 | return; | 237 | return; |
237 | } | 238 | } |
238 | if (NULL == peer) | 239 | if (NULL == peer) |
239 | { | 240 | { |
240 | builder->pitr = NULL; | 241 | builder->pitr = NULL; |
241 | finish_response(); | 242 | finish_response (); |
242 | return; | 243 | return; |
243 | } | 244 | } |
244 | if (NULL == hello) | 245 | if (NULL == hello) |
245 | return; | 246 | return; |
246 | has_addr = GNUNET_NO; | 247 | has_addr = GNUNET_NO; |
247 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &check_has_addr, &has_addr); | 248 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr); |
248 | if (GNUNET_NO == has_addr) | 249 | if (GNUNET_NO == has_addr) |
249 | { | 250 | { |
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
251 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", | 252 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", |
252 | GNUNET_i2s(peer)); | 253 | GNUNET_i2s (peer)); |
253 | GNUNET_STATISTICS_update(stats, | 254 | GNUNET_STATISTICS_update (stats, |
254 | gettext_noop( | 255 | gettext_noop ( |
255 | "HELLOs without addresses encountered (ignored)"), | 256 | "HELLOs without addresses encountered (ignored)"), |
256 | 1, | 257 | 1, |
257 | GNUNET_NO); | 258 | GNUNET_NO); |
258 | return; | 259 | return; |
259 | } | 260 | } |
260 | old = builder->size; | 261 | old = builder->size; |
261 | s = GNUNET_HELLO_size(hello); | 262 | s = GNUNET_HELLO_size (hello); |
262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
263 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", | 264 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", |
264 | (unsigned int)s, | 265 | (unsigned int) s, |
265 | "HELLO", | 266 | "HELLO", |
266 | GNUNET_i2s(peer)); | 267 | GNUNET_i2s (peer)); |
267 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || | 268 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || |
268 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) | 269 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) |
269 | { | 270 | { |
270 | /* too large, skip! */ | 271 | /* too large, skip! */ |
271 | GNUNET_STATISTICS_update(stats, | 272 | GNUNET_STATISTICS_update (stats, |
272 | gettext_noop( | 273 | gettext_noop ( |
273 | "bytes not included in hostlist (size limit)"), | 274 | "bytes not included in hostlist (size limit)"), |
274 | s, | 275 | s, |
275 | GNUNET_NO); | 276 | GNUNET_NO); |
276 | return; | 277 | return; |
277 | } | 278 | } |
278 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
279 | "Adding peer `%s' to hostlist (%u bytes)\n", | 280 | "Adding peer `%s' to hostlist (%u bytes)\n", |
280 | GNUNET_i2s(peer), | 281 | GNUNET_i2s (peer), |
281 | (unsigned int)s); | 282 | (unsigned int) s); |
282 | GNUNET_array_grow(builder->data, builder->size, old + s); | 283 | GNUNET_array_grow (builder->data, builder->size, old + s); |
283 | GNUNET_memcpy(&builder->data[old], hello, s); | 284 | GNUNET_memcpy (&builder->data[old], hello, s); |
284 | } | 285 | } |
285 | 286 | ||
286 | 287 | ||
@@ -294,17 +295,17 @@ host_processor(void *cls, | |||
294 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) | 295 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) |
295 | */ | 296 | */ |
296 | static int | 297 | static int |
297 | accept_policy_callback(void *cls, | 298 | accept_policy_callback (void *cls, |
298 | const struct sockaddr *addr, | 299 | const struct sockaddr *addr, |
299 | socklen_t addrlen) | 300 | socklen_t addrlen) |
300 | { | 301 | { |
301 | if (NULL == response) | 302 | if (NULL == response) |
302 | { | 303 | { |
303 | GNUNET_log( | 304 | GNUNET_log ( |
304 | GNUNET_ERROR_TYPE_DEBUG, | 305 | GNUNET_ERROR_TYPE_DEBUG, |
305 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | 306 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); |
306 | return MHD_NO; | 307 | return MHD_NO; |
307 | } | 308 | } |
308 | return MHD_YES; /* accept all */ | 309 | return MHD_YES; /* accept all */ |
309 | } | 310 | } |
310 | 311 | ||
@@ -345,80 +346,80 @@ accept_policy_callback(void *cls, | |||
345 | * error while handling the request | 346 | * error while handling the request |
346 | */ | 347 | */ |
347 | static int | 348 | static int |
348 | access_handler_callback(void *cls, | 349 | access_handler_callback (void *cls, |
349 | struct MHD_Connection *connection, | 350 | struct MHD_Connection *connection, |
350 | const char *url, | 351 | const char *url, |
351 | const char *method, | 352 | const char *method, |
352 | const char *version, | 353 | const char *version, |
353 | const char *upload_data, | 354 | const char *upload_data, |
354 | size_t *upload_data_size, | 355 | size_t *upload_data_size, |
355 | void **con_cls) | 356 | void **con_cls) |
356 | { | 357 | { |
357 | static int dummy; | 358 | static int dummy; |
358 | 359 | ||
359 | /* CORS pre-flight request */ | 360 | /* CORS pre-flight request */ |
360 | if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) | 361 | if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method)) |
361 | { | 362 | { |
362 | struct MHD_Response *options_response; | 363 | struct MHD_Response *options_response; |
363 | int rc; | 364 | int rc; |
364 | 365 | ||
365 | options_response = | 366 | options_response = |
366 | MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT); | 367 | MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT); |
367 | add_cors_headers(options_response); | 368 | add_cors_headers (options_response); |
368 | rc = MHD_queue_response(connection, MHD_HTTP_OK, options_response); | 369 | rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); |
369 | MHD_destroy_response(options_response); | 370 | MHD_destroy_response (options_response); |
370 | return rc; | 371 | return rc; |
371 | } | 372 | } |
372 | if (0 != strcmp(method, MHD_HTTP_METHOD_GET)) | 373 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
373 | { | 374 | { |
374 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
375 | _("Refusing `%s' request to hostlist server\n"), | 376 | _ ("Refusing `%s' request to hostlist server\n"), |
376 | method); | 377 | method); |
377 | GNUNET_STATISTICS_update(stats, | 378 | GNUNET_STATISTICS_update (stats, |
378 | gettext_noop( | 379 | gettext_noop ( |
379 | "hostlist requests refused (not HTTP GET)"), | 380 | "hostlist requests refused (not HTTP GET)"), |
380 | 1, | 381 | 1, |
381 | GNUNET_YES); | 382 | GNUNET_YES); |
382 | return MHD_NO; | 383 | return MHD_NO; |
383 | } | 384 | } |
384 | if (NULL == *con_cls) | 385 | if (NULL == *con_cls) |
385 | { | 386 | { |
386 | (*con_cls) = &dummy; | 387 | (*con_cls) = &dummy; |
387 | return MHD_YES; | 388 | return MHD_YES; |
388 | } | 389 | } |
389 | if (0 != *upload_data_size) | 390 | if (0 != *upload_data_size) |
390 | { | 391 | { |
391 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
392 | _("Refusing `%s' request with %llu bytes of upload data\n"), | 393 | _ ("Refusing `%s' request with %llu bytes of upload data\n"), |
393 | method, | 394 | method, |
394 | (unsigned long long)*upload_data_size); | 395 | (unsigned long long) *upload_data_size); |
395 | GNUNET_STATISTICS_update(stats, | 396 | GNUNET_STATISTICS_update (stats, |
396 | gettext_noop( | 397 | gettext_noop ( |
397 | "hostlist requests refused (upload data)"), | 398 | "hostlist requests refused (upload data)"), |
398 | 1, | 399 | 1, |
399 | GNUNET_YES); | 400 | GNUNET_YES); |
400 | return MHD_NO; /* do not support upload data */ | 401 | return MHD_NO; /* do not support upload data */ |
401 | } | 402 | } |
402 | if (NULL == response) | 403 | if (NULL == response) |
403 | { | 404 | { |
404 | GNUNET_log( | 405 | GNUNET_log ( |
405 | GNUNET_ERROR_TYPE_WARNING, | 406 | GNUNET_ERROR_TYPE_WARNING, |
406 | _( | 407 | _ ( |
407 | "Could not handle hostlist request since I do not have a response yet\n")); | 408 | "Could not handle hostlist request since I do not have a response yet\n")); |
408 | GNUNET_STATISTICS_update(stats, | 409 | GNUNET_STATISTICS_update (stats, |
409 | gettext_noop( | 410 | gettext_noop ( |
410 | "hostlist requests refused (not ready)"), | 411 | "hostlist requests refused (not ready)"), |
411 | 1, | 412 | 1, |
412 | GNUNET_YES); | 413 | GNUNET_YES); |
413 | return MHD_NO; /* internal error, no response yet */ | 414 | return MHD_NO; /* internal error, no response yet */ |
414 | } | 415 | } |
415 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
416 | _("Received request for our hostlist\n")); | 417 | _ ("Received request for our hostlist\n")); |
417 | GNUNET_STATISTICS_update(stats, | 418 | GNUNET_STATISTICS_update (stats, |
418 | gettext_noop("hostlist requests processed"), | 419 | gettext_noop ("hostlist requests processed"), |
419 | 1, | 420 | 1, |
420 | GNUNET_YES); | 421 | GNUNET_YES); |
421 | return MHD_queue_response(connection, MHD_HTTP_OK, response); | 422 | return MHD_queue_response (connection, MHD_HTTP_OK, response); |
422 | } | 423 | } |
423 | 424 | ||
424 | 425 | ||
@@ -432,33 +433,33 @@ access_handler_callback(void *cls, | |||
432 | * @return number of bytes copied to @a buf | 433 | * @return number of bytes copied to @a buf |
433 | */ | 434 | */ |
434 | static void | 435 | static void |
435 | adv_transmit(struct GNUNET_MQ_Handle *mq) | 436 | adv_transmit (struct GNUNET_MQ_Handle *mq) |
436 | { | 437 | { |
437 | static uint64_t hostlist_adv_count; | 438 | static uint64_t hostlist_adv_count; |
438 | size_t uri_size; /* Including \0 termination! */ | 439 | size_t uri_size; /* Including \0 termination! */ |
439 | struct GNUNET_MessageHeader *header; | 440 | struct GNUNET_MessageHeader *header; |
440 | struct GNUNET_MQ_Envelope *env; | 441 | struct GNUNET_MQ_Envelope *env; |
441 | 442 | ||
442 | uri_size = strlen(hostlist_uri) + 1; | 443 | uri_size = strlen (hostlist_uri) + 1; |
443 | env = GNUNET_MQ_msg_extra(header, | 444 | env = GNUNET_MQ_msg_extra (header, |
444 | uri_size, | 445 | uri_size, |
445 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 446 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
446 | GNUNET_memcpy(&header[1], hostlist_uri, uri_size); | 447 | GNUNET_memcpy (&header[1], hostlist_uri, uri_size); |
447 | GNUNET_MQ_env_set_options(env, | 448 | GNUNET_MQ_env_set_options (env, |
448 | GNUNET_MQ_PREF_CORK_ALLOWED | | 449 | GNUNET_MQ_PREF_CORK_ALLOWED |
449 | GNUNET_MQ_PREF_UNRELIABLE); | 450 | | GNUNET_MQ_PREF_UNRELIABLE); |
450 | GNUNET_MQ_send(mq, env); | 451 | GNUNET_MQ_send (mq, env); |
451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
452 | "Sent advertisement message: Copied %u bytes into buffer!\n", | 453 | "Sent advertisement message: Copied %u bytes into buffer!\n", |
453 | (unsigned int)uri_size); | 454 | (unsigned int) uri_size); |
454 | hostlist_adv_count++; | 455 | hostlist_adv_count++; |
455 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
456 | " # Sent advertisement message: %llu\n", | 457 | " # Sent advertisement message: %llu\n", |
457 | (unsigned long long)hostlist_adv_count); | 458 | (unsigned long long) hostlist_adv_count); |
458 | GNUNET_STATISTICS_update(stats, | 459 | GNUNET_STATISTICS_update (stats, |
459 | gettext_noop("# hostlist advertisements send"), | 460 | gettext_noop ("# hostlist advertisements send"), |
460 | 1, | 461 | 1, |
461 | GNUNET_NO); | 462 | GNUNET_NO); |
462 | } | 463 | } |
463 | 464 | ||
464 | 465 | ||
@@ -471,34 +472,34 @@ adv_transmit(struct GNUNET_MQ_Handle *mq) | |||
471 | * @return NULL (must!) | 472 | * @return NULL (must!) |
472 | */ | 473 | */ |
473 | static void * | 474 | static void * |
474 | connect_handler(void *cls, | 475 | connect_handler (void *cls, |
475 | const struct GNUNET_PeerIdentity *peer, | 476 | const struct GNUNET_PeerIdentity *peer, |
476 | struct GNUNET_MQ_Handle *mq) | 477 | struct GNUNET_MQ_Handle *mq) |
477 | { | 478 | { |
478 | size_t size; | 479 | size_t size; |
479 | 480 | ||
480 | if (!advertising) | 481 | if (! advertising) |
481 | return NULL; | 482 | return NULL; |
482 | if (NULL == hostlist_uri) | 483 | if (NULL == hostlist_uri) |
483 | return NULL; | 484 | return NULL; |
484 | size = strlen(hostlist_uri) + 1; | 485 | size = strlen (hostlist_uri) + 1; |
485 | if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) | 486 | if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) |
486 | { | 487 | { |
487 | GNUNET_break(0); | 488 | GNUNET_break (0); |
488 | return NULL; | 489 | return NULL; |
489 | } | 490 | } |
490 | size += sizeof(struct GNUNET_MessageHeader); | 491 | size += sizeof(struct GNUNET_MessageHeader); |
491 | if (NULL == core) | 492 | if (NULL == core) |
492 | { | 493 | { |
493 | GNUNET_break(0); | 494 | GNUNET_break (0); |
494 | return NULL; | 495 | return NULL; |
495 | } | 496 | } |
496 | GNUNET_log( | 497 | GNUNET_log ( |
497 | GNUNET_ERROR_TYPE_DEBUG, | 498 | GNUNET_ERROR_TYPE_DEBUG, |
498 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", | 499 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", |
499 | (unsigned int)size, | 500 | (unsigned int) size, |
500 | GNUNET_i2s(peer)); | 501 | GNUNET_i2s (peer)); |
501 | adv_transmit(mq); | 502 | adv_transmit (mq); |
502 | return NULL; | 503 | return NULL; |
503 | } | 504 | } |
504 | 505 | ||
@@ -513,36 +514,36 @@ connect_handler(void *cls, | |||
513 | * @param err_msg NULL if successful, otherwise contains error message | 514 | * @param err_msg NULL if successful, otherwise contains error message |
514 | */ | 515 | */ |
515 | static void | 516 | static void |
516 | process_notify(void *cls, | 517 | process_notify (void *cls, |
517 | const struct GNUNET_PeerIdentity *peer, | 518 | const struct GNUNET_PeerIdentity *peer, |
518 | const struct GNUNET_HELLO_Message *hello, | 519 | const struct GNUNET_HELLO_Message *hello, |
519 | const char *err_msg) | 520 | const char *err_msg) |
520 | { | 521 | { |
521 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
522 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 523 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
523 | if (NULL != err_msg) | 524 | if (NULL != err_msg) |
524 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 525 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
525 | _("Error in communication with PEERINFO service: %s\n"), | 526 | _ ("Error in communication with PEERINFO service: %s\n"), |
526 | err_msg); | 527 | err_msg); |
527 | if (NULL != builder) | 528 | if (NULL != builder) |
529 | { | ||
530 | /* restart re-build already in progress ... */ | ||
531 | if (NULL != builder->pitr) | ||
528 | { | 532 | { |
529 | /* restart re-build already in progress ... */ | 533 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); |
530 | if (NULL != builder->pitr) | 534 | builder->pitr = NULL; |
531 | { | ||
532 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
533 | builder->pitr = NULL; | ||
534 | } | ||
535 | GNUNET_free_non_null(builder->data); | ||
536 | builder->size = 0; | ||
537 | builder->data = NULL; | ||
538 | } | 535 | } |
536 | GNUNET_free_non_null (builder->data); | ||
537 | builder->size = 0; | ||
538 | builder->data = NULL; | ||
539 | } | ||
539 | else | 540 | else |
540 | { | 541 | { |
541 | builder = GNUNET_new(struct HostSet); | 542 | builder = GNUNET_new (struct HostSet); |
542 | } | 543 | } |
543 | GNUNET_assert(NULL != peerinfo); | 544 | GNUNET_assert (NULL != peerinfo); |
544 | builder->pitr = | 545 | builder->pitr = |
545 | GNUNET_PEERINFO_iterate(peerinfo, GNUNET_NO, NULL, &host_processor, NULL); | 546 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL); |
546 | } | 547 | } |
547 | 548 | ||
548 | 549 | ||
@@ -551,7 +552,7 @@ process_notify(void *cls, | |||
551 | * starts the task waiting for them. | 552 | * starts the task waiting for them. |
552 | */ | 553 | */ |
553 | static struct GNUNET_SCHEDULER_Task * | 554 | static struct GNUNET_SCHEDULER_Task * |
554 | prepare_daemon(struct MHD_Daemon *daemon_handle); | 555 | prepare_daemon (struct MHD_Daemon *daemon_handle); |
555 | 556 | ||
556 | 557 | ||
557 | /** | 558 | /** |
@@ -561,7 +562,7 @@ prepare_daemon(struct MHD_Daemon *daemon_handle); | |||
561 | * @param cls the `struct MHD_Daemon` of the HTTP server to run | 562 | * @param cls the `struct MHD_Daemon` of the HTTP server to run |
562 | */ | 563 | */ |
563 | static void | 564 | static void |
564 | run_daemon(void *cls) | 565 | run_daemon (void *cls) |
565 | { | 566 | { |
566 | struct MHD_Daemon *daemon_handle = cls; | 567 | struct MHD_Daemon *daemon_handle = cls; |
567 | 568 | ||
@@ -569,11 +570,11 @@ run_daemon(void *cls) | |||
569 | hostlist_task_v4 = NULL; | 570 | hostlist_task_v4 = NULL; |
570 | else | 571 | else |
571 | hostlist_task_v6 = NULL; | 572 | hostlist_task_v6 = NULL; |
572 | GNUNET_assert(MHD_YES == MHD_run(daemon_handle)); | 573 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); |
573 | if (daemon_handle == daemon_handle_v4) | 574 | if (daemon_handle == daemon_handle_v4) |
574 | hostlist_task_v4 = prepare_daemon(daemon_handle); | 575 | hostlist_task_v4 = prepare_daemon (daemon_handle); |
575 | else | 576 | else |
576 | hostlist_task_v6 = prepare_daemon(daemon_handle); | 577 | hostlist_task_v6 = prepare_daemon (daemon_handle); |
577 | } | 578 | } |
578 | 579 | ||
579 | 580 | ||
@@ -584,7 +585,7 @@ run_daemon(void *cls) | |||
584 | * @param daemon_handle HTTP server to prepare to run | 585 | * @param daemon_handle HTTP server to prepare to run |
585 | */ | 586 | */ |
586 | static struct GNUNET_SCHEDULER_Task * | 587 | static struct GNUNET_SCHEDULER_Task * |
587 | prepare_daemon(struct MHD_Daemon *daemon_handle) | 588 | prepare_daemon (struct MHD_Daemon *daemon_handle) |
588 | { | 589 | { |
589 | struct GNUNET_SCHEDULER_Task *ret; | 590 | struct GNUNET_SCHEDULER_Task *ret; |
590 | fd_set rs; | 591 | fd_set rs; |
@@ -597,28 +598,28 @@ prepare_daemon(struct MHD_Daemon *daemon_handle) | |||
597 | int haveto; | 598 | int haveto; |
598 | struct GNUNET_TIME_Relative tv; | 599 | struct GNUNET_TIME_Relative tv; |
599 | 600 | ||
600 | FD_ZERO(&rs); | 601 | FD_ZERO (&rs); |
601 | FD_ZERO(&ws); | 602 | FD_ZERO (&ws); |
602 | FD_ZERO(&es); | 603 | FD_ZERO (&es); |
603 | wrs = GNUNET_NETWORK_fdset_create(); | 604 | wrs = GNUNET_NETWORK_fdset_create (); |
604 | wws = GNUNET_NETWORK_fdset_create(); | 605 | wws = GNUNET_NETWORK_fdset_create (); |
605 | max = -1; | 606 | max = -1; |
606 | GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max)); | 607 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); |
607 | haveto = MHD_get_timeout(daemon_handle, &timeout); | 608 | haveto = MHD_get_timeout (daemon_handle, &timeout); |
608 | if (haveto == MHD_YES) | 609 | if (haveto == MHD_YES) |
609 | tv.rel_value_us = (uint64_t)timeout * 1000LL; | 610 | tv.rel_value_us = (uint64_t) timeout * 1000LL; |
610 | else | 611 | else |
611 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 612 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
612 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); | 613 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); |
613 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); | 614 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); |
614 | ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, | 615 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
615 | tv, | 616 | tv, |
616 | wrs, | 617 | wrs, |
617 | wws, | 618 | wws, |
618 | &run_daemon, | 619 | &run_daemon, |
619 | daemon_handle); | 620 | daemon_handle); |
620 | GNUNET_NETWORK_fdset_destroy(wrs); | 621 | GNUNET_NETWORK_fdset_destroy (wrs); |
621 | GNUNET_NETWORK_fdset_destroy(wws); | 622 | GNUNET_NETWORK_fdset_destroy (wws); |
622 | return ret; | 623 | return ret; |
623 | } | 624 | } |
624 | 625 | ||
@@ -634,11 +635,11 @@ prepare_daemon(struct MHD_Daemon *daemon_handle) | |||
634 | * @return #GNUNET_OK on success | 635 | * @return #GNUNET_OK on success |
635 | */ | 636 | */ |
636 | int | 637 | int |
637 | GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | 638 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, |
638 | struct GNUNET_STATISTICS_Handle *st, | 639 | struct GNUNET_STATISTICS_Handle *st, |
639 | struct GNUNET_CORE_Handle *co, | 640 | struct GNUNET_CORE_Handle *co, |
640 | GNUNET_CORE_ConnectEventHandler *server_ch, | 641 | GNUNET_CORE_ConnectEventHandler *server_ch, |
641 | int advertise) | 642 | int advertise) |
642 | { | 643 | { |
643 | unsigned long long port; | 644 | unsigned long long port; |
644 | char *hostname; | 645 | char *hostname; |
@@ -653,189 +654,189 @@ GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
653 | const struct sockaddr *sa6; | 654 | const struct sockaddr *sa6; |
654 | 655 | ||
655 | advertising = advertise; | 656 | advertising = advertise; |
656 | if (!advertising) | 657 | if (! advertising) |
657 | { | 658 | { |
658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
659 | "Advertising not enabled on this hostlist server\n"); | 660 | "Advertising not enabled on this hostlist server\n"); |
660 | } | 661 | } |
661 | else | 662 | else |
662 | { | 663 | { |
663 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
664 | "Advertising enabled on this hostlist server\n"); | 665 | "Advertising enabled on this hostlist server\n"); |
665 | } | 666 | } |
666 | cfg = c; | 667 | cfg = c; |
667 | stats = st; | 668 | stats = st; |
668 | peerinfo = GNUNET_PEERINFO_connect(cfg); | 669 | peerinfo = GNUNET_PEERINFO_connect (cfg); |
669 | if (NULL == peerinfo) | 670 | if (NULL == peerinfo) |
670 | { | 671 | { |
671 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
672 | _("Could not access PEERINFO service. Exiting.\n")); | 673 | _ ("Could not access PEERINFO service. Exiting.\n")); |
673 | return GNUNET_SYSERR; | 674 | return GNUNET_SYSERR; |
674 | } | 675 | } |
675 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 676 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
676 | "HOSTLIST", | 677 | "HOSTLIST", |
677 | "HTTPPORT", | 678 | "HTTPPORT", |
678 | &port)) | 679 | &port)) |
679 | return GNUNET_SYSERR; | 680 | return GNUNET_SYSERR; |
680 | if ((0 == port) || (port > UINT16_MAX)) | 681 | if ((0 == port) || (port > UINT16_MAX)) |
681 | { | 682 | { |
682 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 683 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
683 | _("Invalid port number %llu. Exiting.\n"), | 684 | _ ("Invalid port number %llu. Exiting.\n"), |
684 | port); | 685 | port); |
685 | return GNUNET_SYSERR; | 686 | return GNUNET_SYSERR; |
686 | } | 687 | } |
687 | 688 | ||
688 | if (GNUNET_SYSERR == | 689 | if (GNUNET_SYSERR == |
689 | GNUNET_CONFIGURATION_get_value_string(cfg, | 690 | GNUNET_CONFIGURATION_get_value_string (cfg, |
690 | "HOSTLIST", | 691 | "HOSTLIST", |
691 | "EXTERNAL_DNS_NAME", | 692 | "EXTERNAL_DNS_NAME", |
692 | &hostname)) | 693 | &hostname)) |
693 | hostname = GNUNET_RESOLVER_local_fqdn_get(); | 694 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
695 | _("Hostlist service starts on %s:%llu\n"), | 696 | _ ("Hostlist service starts on %s:%llu\n"), |
696 | hostname, | 697 | hostname, |
697 | port); | 698 | port); |
698 | if (NULL != hostname) | 699 | if (NULL != hostname) |
700 | { | ||
701 | size = strlen (hostname); | ||
702 | if (size + 15 > MAX_URL_LEN) | ||
699 | { | 703 | { |
700 | size = strlen(hostname); | 704 | GNUNET_break (0); |
701 | if (size + 15 > MAX_URL_LEN) | ||
702 | { | ||
703 | GNUNET_break(0); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | GNUNET_asprintf(&hostlist_uri, | ||
708 | "http://%s:%u/", | ||
709 | hostname, | ||
710 | (unsigned int)port); | ||
711 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
712 | _("Address to obtain hostlist: `%s'\n"), | ||
713 | hostlist_uri); | ||
714 | } | ||
715 | GNUNET_free(hostname); | ||
716 | } | 705 | } |
706 | else | ||
707 | { | ||
708 | GNUNET_asprintf (&hostlist_uri, | ||
709 | "http://%s:%u/", | ||
710 | hostname, | ||
711 | (unsigned int) port); | ||
712 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
713 | _ ("Address to obtain hostlist: `%s'\n"), | ||
714 | hostlist_uri); | ||
715 | } | ||
716 | GNUNET_free (hostname); | ||
717 | } | ||
717 | 718 | ||
718 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV4")) | 719 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) |
720 | { | ||
721 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | ||
722 | "HOSTLIST", | ||
723 | "BINDTOIP", | ||
724 | &ipv4)) | ||
719 | { | 725 | { |
720 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 726 | GNUNET_log ( |
721 | "HOSTLIST", | 727 | GNUNET_ERROR_TYPE_WARNING, |
722 | "BINDTOIP", | 728 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); |
723 | &ipv4)) | ||
724 | { | ||
725 | GNUNET_log( | ||
726 | GNUNET_ERROR_TYPE_WARNING, | ||
727 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | ||
728 | } | ||
729 | } | 729 | } |
730 | } | ||
730 | else | 731 | else |
731 | ipv4 = NULL; | 732 | ipv4 = NULL; |
732 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV6")) | 733 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6")) |
733 | { | 734 | { |
734 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 735 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
735 | "HOSTLIST", | 736 | "HOSTLIST", |
736 | "BINDTOIP", | 737 | "BINDTOIP", |
737 | &ipv6)) | 738 | &ipv6)) |
738 | { | 739 | { |
739 | GNUNET_log( | 740 | GNUNET_log ( |
740 | GNUNET_ERROR_TYPE_WARNING, | 741 | GNUNET_ERROR_TYPE_WARNING, |
741 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); | 742 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); |
742 | } | ||
743 | } | 743 | } |
744 | } | ||
744 | else | 745 | else |
745 | ipv6 = NULL; | 746 | ipv6 = NULL; |
746 | sa4 = NULL; | 747 | sa4 = NULL; |
747 | if (NULL != ipv4) | 748 | if (NULL != ipv4) |
749 | { | ||
750 | if (1 == inet_pton (AF_INET, ipv4, &i4)) | ||
748 | { | 751 | { |
749 | if (1 == inet_pton(AF_INET, ipv4, &i4)) | 752 | memset (&v4, 0, sizeof(v4)); |
750 | { | 753 | v4.sin_family = AF_INET; |
751 | memset(&v4, 0, sizeof(v4)); | 754 | v4.sin_addr = i4; |
752 | v4.sin_family = AF_INET; | 755 | v4.sin_port = htons (port); |
753 | v4.sin_addr = i4; | ||
754 | v4.sin_port = htons(port); | ||
755 | #if HAVE_SOCKADDR_IN_SIN_LEN | 756 | #if HAVE_SOCKADDR_IN_SIN_LEN |
756 | v4.sin_len = sizeof(v4); | 757 | v4.sin_len = sizeof(v4); |
757 | #endif | 758 | #endif |
758 | sa4 = (const struct sockaddr *)&v4; | 759 | sa4 = (const struct sockaddr *) &v4; |
759 | } | 760 | } |
760 | else | 761 | else |
761 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
762 | _( | 763 | _ ( |
763 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), | 764 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), |
764 | ipv4); | 765 | ipv4); |
765 | GNUNET_free(ipv4); | 766 | GNUNET_free (ipv4); |
766 | } | 767 | } |
767 | sa6 = NULL; | 768 | sa6 = NULL; |
768 | if (NULL != ipv6) | 769 | if (NULL != ipv6) |
770 | { | ||
771 | if (1 == inet_pton (AF_INET6, ipv6, &i6)) | ||
769 | { | 772 | { |
770 | if (1 == inet_pton(AF_INET6, ipv6, &i6)) | 773 | memset (&v6, 0, sizeof(v6)); |
771 | { | 774 | v6.sin6_family = AF_INET6; |
772 | memset(&v6, 0, sizeof(v6)); | 775 | v6.sin6_addr = i6; |
773 | v6.sin6_family = AF_INET6; | 776 | v6.sin6_port = htons (port); |
774 | v6.sin6_addr = i6; | ||
775 | v6.sin6_port = htons(port); | ||
776 | #if HAVE_SOCKADDR_IN_SIN_LEN | 777 | #if HAVE_SOCKADDR_IN_SIN_LEN |
777 | v6.sin6_len = sizeof(v6); | 778 | v6.sin6_len = sizeof(v6); |
778 | #endif | 779 | #endif |
779 | sa6 = (const struct sockaddr *)&v6; | 780 | sa6 = (const struct sockaddr *) &v6; |
780 | } | 781 | } |
781 | else | 782 | else |
782 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 783 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
783 | _( | 784 | _ ( |
784 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), | 785 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), |
785 | ipv6); | 786 | ipv6); |
786 | GNUNET_free(ipv6); | 787 | GNUNET_free (ipv6); |
787 | } | 788 | } |
788 | 789 | ||
789 | daemon_handle_v6 = MHD_start_daemon(MHD_USE_IPv6 | MHD_USE_DEBUG, | 790 | daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG, |
790 | (uint16_t)port, | 791 | (uint16_t) port, |
791 | &accept_policy_callback, | 792 | &accept_policy_callback, |
792 | NULL, | 793 | NULL, |
793 | &access_handler_callback, | 794 | &access_handler_callback, |
794 | NULL, | 795 | NULL, |
795 | MHD_OPTION_CONNECTION_LIMIT, | 796 | MHD_OPTION_CONNECTION_LIMIT, |
796 | (unsigned int)128, | 797 | (unsigned int) 128, |
797 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 798 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
798 | (unsigned int)32, | 799 | (unsigned int) 32, |
799 | MHD_OPTION_CONNECTION_TIMEOUT, | 800 | MHD_OPTION_CONNECTION_TIMEOUT, |
800 | (unsigned int)16, | 801 | (unsigned int) 16, |
801 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 802 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
802 | (size_t)(16 * 1024), | 803 | (size_t) (16 * 1024), |
803 | MHD_OPTION_SOCK_ADDR, | 804 | MHD_OPTION_SOCK_ADDR, |
804 | sa6, | 805 | sa6, |
805 | MHD_OPTION_END); | 806 | MHD_OPTION_END); |
806 | daemon_handle_v4 = MHD_start_daemon(MHD_NO_FLAG | MHD_USE_DEBUG, | 807 | daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, |
807 | (uint16_t)port, | 808 | (uint16_t) port, |
808 | &accept_policy_callback, | 809 | &accept_policy_callback, |
809 | NULL, | 810 | NULL, |
810 | &access_handler_callback, | 811 | &access_handler_callback, |
811 | NULL, | 812 | NULL, |
812 | MHD_OPTION_CONNECTION_LIMIT, | 813 | MHD_OPTION_CONNECTION_LIMIT, |
813 | (unsigned int)128, | 814 | (unsigned int) 128, |
814 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 815 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
815 | (unsigned int)32, | 816 | (unsigned int) 32, |
816 | MHD_OPTION_CONNECTION_TIMEOUT, | 817 | MHD_OPTION_CONNECTION_TIMEOUT, |
817 | (unsigned int)16, | 818 | (unsigned int) 16, |
818 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 819 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
819 | (size_t)(16 * 1024), | 820 | (size_t) (16 * 1024), |
820 | MHD_OPTION_SOCK_ADDR, | 821 | MHD_OPTION_SOCK_ADDR, |
821 | sa4, | 822 | sa4, |
822 | MHD_OPTION_END); | 823 | MHD_OPTION_END); |
823 | 824 | ||
824 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) | 825 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) |
825 | { | 826 | { |
826 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 827 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
827 | _("Could not start hostlist HTTP server on port %u\n"), | 828 | _ ("Could not start hostlist HTTP server on port %u\n"), |
828 | (unsigned short)port); | 829 | (unsigned short) port); |
829 | return GNUNET_SYSERR; | 830 | return GNUNET_SYSERR; |
830 | } | 831 | } |
831 | 832 | ||
832 | core = co; | 833 | core = co; |
833 | *server_ch = &connect_handler; | 834 | *server_ch = &connect_handler; |
834 | if (NULL != daemon_handle_v4) | 835 | if (NULL != daemon_handle_v4) |
835 | hostlist_task_v4 = prepare_daemon(daemon_handle_v4); | 836 | hostlist_task_v4 = prepare_daemon (daemon_handle_v4); |
836 | if (NULL != daemon_handle_v6) | 837 | if (NULL != daemon_handle_v6) |
837 | hostlist_task_v6 = prepare_daemon(daemon_handle_v6); | 838 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); |
838 | notify = GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_notify, NULL); | 839 | notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL); |
839 | return GNUNET_OK; | 840 | return GNUNET_OK; |
840 | } | 841 | } |
841 | 842 | ||
@@ -844,55 +845,55 @@ GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
844 | * Stop server offering our hostlist. | 845 | * Stop server offering our hostlist. |
845 | */ | 846 | */ |
846 | void | 847 | void |
847 | GNUNET_HOSTLIST_server_stop() | 848 | GNUNET_HOSTLIST_server_stop () |
848 | { | 849 | { |
849 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); | 850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); |
850 | if (NULL != hostlist_task_v6) | 851 | if (NULL != hostlist_task_v6) |
851 | { | 852 | { |
852 | GNUNET_SCHEDULER_cancel(hostlist_task_v6); | 853 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); |
853 | hostlist_task_v6 = NULL; | 854 | hostlist_task_v6 = NULL; |
854 | } | 855 | } |
855 | if (NULL != hostlist_task_v4) | 856 | if (NULL != hostlist_task_v4) |
856 | { | 857 | { |
857 | GNUNET_SCHEDULER_cancel(hostlist_task_v4); | 858 | GNUNET_SCHEDULER_cancel (hostlist_task_v4); |
858 | hostlist_task_v4 = NULL; | 859 | hostlist_task_v4 = NULL; |
859 | } | 860 | } |
860 | if (NULL != daemon_handle_v4) | 861 | if (NULL != daemon_handle_v4) |
861 | { | 862 | { |
862 | MHD_stop_daemon(daemon_handle_v4); | 863 | MHD_stop_daemon (daemon_handle_v4); |
863 | daemon_handle_v4 = NULL; | 864 | daemon_handle_v4 = NULL; |
864 | } | 865 | } |
865 | if (NULL != daemon_handle_v6) | 866 | if (NULL != daemon_handle_v6) |
866 | { | 867 | { |
867 | MHD_stop_daemon(daemon_handle_v6); | 868 | MHD_stop_daemon (daemon_handle_v6); |
868 | daemon_handle_v6 = NULL; | 869 | daemon_handle_v6 = NULL; |
869 | } | 870 | } |
870 | if (NULL != response) | 871 | if (NULL != response) |
871 | { | 872 | { |
872 | MHD_destroy_response(response); | 873 | MHD_destroy_response (response); |
873 | response = NULL; | 874 | response = NULL; |
874 | } | 875 | } |
875 | if (NULL != notify) | 876 | if (NULL != notify) |
876 | { | 877 | { |
877 | GNUNET_PEERINFO_notify_cancel(notify); | 878 | GNUNET_PEERINFO_notify_cancel (notify); |
878 | notify = NULL; | 879 | notify = NULL; |
879 | } | 880 | } |
880 | if (NULL != builder) | 881 | if (NULL != builder) |
882 | { | ||
883 | if (NULL != builder->pitr) | ||
881 | { | 884 | { |
882 | if (NULL != builder->pitr) | 885 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); |
883 | { | 886 | builder->pitr = NULL; |
884 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
885 | builder->pitr = NULL; | ||
886 | } | ||
887 | GNUNET_free_non_null(builder->data); | ||
888 | GNUNET_free(builder); | ||
889 | builder = NULL; | ||
890 | } | 887 | } |
888 | GNUNET_free_non_null (builder->data); | ||
889 | GNUNET_free (builder); | ||
890 | builder = NULL; | ||
891 | } | ||
891 | if (NULL != peerinfo) | 892 | if (NULL != peerinfo) |
892 | { | 893 | { |
893 | GNUNET_PEERINFO_disconnect(peerinfo); | 894 | GNUNET_PEERINFO_disconnect (peerinfo); |
894 | peerinfo = NULL; | 895 | peerinfo = NULL; |
895 | } | 896 | } |
896 | cfg = NULL; | 897 | cfg = NULL; |
897 | stats = NULL; | 898 | stats = NULL; |
898 | core = NULL; | 899 | core = NULL; |
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.h b/src/hostlist/gnunet-daemon-hostlist_server.h index 407675b41..13ba21e82 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.h +++ b/src/hostlist/gnunet-daemon-hostlist_server.h | |||
@@ -43,18 +43,18 @@ | |||
43 | * @return #GNUNET_OK on success | 43 | * @return #GNUNET_OK on success |
44 | */ | 44 | */ |
45 | int | 45 | int |
46 | GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | 46 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, |
47 | struct GNUNET_STATISTICS_Handle *st, | 47 | struct GNUNET_STATISTICS_Handle *st, |
48 | struct GNUNET_CORE_Handle *core, | 48 | struct GNUNET_CORE_Handle *core, |
49 | GNUNET_CORE_ConnectEventHandler *server_ch, | 49 | GNUNET_CORE_ConnectEventHandler *server_ch, |
50 | int advertise); | 50 | int advertise); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Stop server offering our hostlist. | 54 | * Stop server offering our hostlist. |
55 | */ | 55 | */ |
56 | void | 56 | void |
57 | GNUNET_HOSTLIST_server_stop(void); | 57 | GNUNET_HOSTLIST_server_stop (void); |
58 | 58 | ||
59 | 59 | ||
60 | #endif | 60 | #endif |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index d6853c184..182340f9b 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -32,13 +32,14 @@ | |||
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 | { | ||
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 43 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_TRANSPORT_CoreHandle *th; | 44 | struct GNUNET_TRANSPORT_CoreHandle *th; |
44 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
@@ -52,29 +53,29 @@ static struct PeerContext p2; | |||
52 | 53 | ||
53 | 54 | ||
54 | static void | 55 | static void |
55 | clean_up(void *cls) | 56 | clean_up (void *cls) |
56 | { | 57 | { |
57 | if (NULL != p1.th) | 58 | if (NULL != p1.th) |
59 | { | ||
60 | if (NULL != p1.ghh) | ||
58 | { | 61 | { |
59 | if (NULL != p1.ghh) | 62 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); |
60 | { | 63 | p1.ghh = NULL; |
61 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); | ||
62 | p1.ghh = NULL; | ||
63 | } | ||
64 | GNUNET_TRANSPORT_core_disconnect(p1.th); | ||
65 | p1.th = NULL; | ||
66 | } | 64 | } |
65 | GNUNET_TRANSPORT_core_disconnect (p1.th); | ||
66 | p1.th = NULL; | ||
67 | } | ||
67 | if (NULL != p2.th) | 68 | if (NULL != p2.th) |
69 | { | ||
70 | if (NULL != p2.ghh) | ||
68 | { | 71 | { |
69 | if (NULL != p2.ghh) | 72 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); |
70 | { | 73 | p2.ghh = NULL; |
71 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); | ||
72 | p2.ghh = NULL; | ||
73 | } | ||
74 | GNUNET_TRANSPORT_core_disconnect(p2.th); | ||
75 | p2.th = NULL; | ||
76 | } | 74 | } |
77 | GNUNET_SCHEDULER_shutdown(); | 75 | GNUNET_TRANSPORT_core_disconnect (p2.th); |
76 | p2.th = NULL; | ||
77 | } | ||
78 | GNUNET_SCHEDULER_shutdown (); | ||
78 | } | 79 | } |
79 | 80 | ||
80 | 81 | ||
@@ -82,12 +83,12 @@ clean_up(void *cls) | |||
82 | * Timeout, give up. | 83 | * Timeout, give up. |
83 | */ | 84 | */ |
84 | static void | 85 | static void |
85 | timeout_error(void *cls) | 86 | timeout_error (void *cls) |
86 | { | 87 | { |
87 | timeout_task = NULL; | 88 | timeout_task = NULL; |
88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
89 | "Timeout trying to connect peers, test failed.\n"); | 90 | "Timeout trying to connect peers, test failed.\n"); |
90 | clean_up(NULL); | 91 | clean_up (NULL); |
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
@@ -100,92 +101,92 @@ timeout_error(void *cls) | |||
100 | * @param mq message queue to send messages to the peer | 101 | * @param mq message queue to send messages to the peer |
101 | */ | 102 | */ |
102 | static void * | 103 | static void * |
103 | notify_connect(void *cls, | 104 | notify_connect (void *cls, |
104 | const struct GNUNET_PeerIdentity *peer, | 105 | const struct GNUNET_PeerIdentity *peer, |
105 | struct GNUNET_MQ_Handle *mq) | 106 | struct GNUNET_MQ_Handle *mq) |
106 | { | 107 | { |
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
108 | ok = 0; | 109 | ok = 0; |
109 | if (NULL != timeout_task) | 110 | if (NULL != timeout_task) |
110 | { | 111 | { |
111 | GNUNET_SCHEDULER_cancel(timeout_task); | 112 | GNUNET_SCHEDULER_cancel (timeout_task); |
112 | timeout_task = NULL; | 113 | timeout_task = NULL; |
113 | } | 114 | } |
114 | GNUNET_SCHEDULER_add_now(&clean_up, NULL); | 115 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
115 | return NULL; | 116 | return NULL; |
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
119 | static void | 120 | static void |
120 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) | 121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
121 | { | 122 | { |
122 | struct PeerContext *p = cls; | 123 | struct PeerContext *p = cls; |
123 | 124 | ||
124 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); | 125 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); |
125 | p->ghh = NULL; | 126 | p->ghh = NULL; |
126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
127 | "Received HELLO, starting hostlist service.\n"); | 128 | "Received HELLO, starting hostlist service.\n"); |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | static void | 132 | static void |
132 | setup_peer(struct PeerContext *p, const char *cfgname) | 133 | setup_peer (struct PeerContext *p, const char *cfgname) |
133 | { | 134 | { |
134 | char *binary; | 135 | char *binary; |
135 | 136 | ||
136 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 137 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
137 | p->cfg = GNUNET_CONFIGURATION_create(); | 138 | p->cfg = GNUNET_CONFIGURATION_create (); |
138 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, | 139 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
140 | NULL, | 141 | NULL, |
141 | NULL, | 142 | NULL, |
142 | NULL, | 143 | NULL, |
143 | binary, | 144 | binary, |
144 | "gnunet-service-arm", | 145 | "gnunet-service-arm", |
145 | "-c", | 146 | "-c", |
146 | cfgname, | 147 | cfgname, |
147 | NULL); | 148 | NULL); |
148 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); | 149 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
149 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, | 150 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
150 | NULL, | 151 | NULL, |
151 | NULL, | 152 | NULL, |
152 | p, | 153 | p, |
153 | ¬ify_connect, | 154 | ¬ify_connect, |
154 | NULL, | 155 | NULL, |
155 | NULL); | 156 | NULL); |
156 | GNUNET_assert(NULL != p->th); | 157 | GNUNET_assert (NULL != p->th); |
157 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, | 158 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
158 | GNUNET_TRANSPORT_AC_ANY, | 159 | GNUNET_TRANSPORT_AC_ANY, |
159 | &process_hello, | 160 | &process_hello, |
160 | p); | 161 | p); |
161 | GNUNET_free(binary); | 162 | GNUNET_free (binary); |
162 | } | 163 | } |
163 | 164 | ||
164 | 165 | ||
165 | static void | 166 | static void |
166 | waitpid_task(void *cls) | 167 | waitpid_task (void *cls) |
167 | { | 168 | { |
168 | struct PeerContext *p = cls; | 169 | struct PeerContext *p = cls; |
169 | 170 | ||
170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
171 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) | 172 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) |
172 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
173 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) | 174 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) |
174 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 175 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
175 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
176 | "ARM process %u stopped\n", | 177 | "ARM process %u stopped\n", |
177 | GNUNET_OS_process_get_pid(p->arm_proc)); | 178 | GNUNET_OS_process_get_pid (p->arm_proc)); |
178 | GNUNET_OS_process_destroy(p->arm_proc); | 179 | GNUNET_OS_process_destroy (p->arm_proc); |
179 | p->arm_proc = NULL; | 180 | p->arm_proc = NULL; |
180 | GNUNET_CONFIGURATION_destroy(p->cfg); | 181 | GNUNET_CONFIGURATION_destroy (p->cfg); |
181 | } | 182 | } |
182 | 183 | ||
183 | 184 | ||
184 | static void | 185 | static void |
185 | stop_arm(struct PeerContext *p) | 186 | stop_arm (struct PeerContext *p) |
186 | { | 187 | { |
187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
188 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
189 | } | 190 | } |
190 | 191 | ||
191 | 192 | ||
@@ -193,68 +194,69 @@ stop_arm(struct PeerContext *p) | |||
193 | * Try again to connect to transport service. | 194 | * Try again to connect to transport service. |
194 | */ | 195 | */ |
195 | static void | 196 | static void |
196 | shutdown_task(void *cls) | 197 | shutdown_task (void *cls) |
197 | { | 198 | { |
198 | stop_arm(&p1); | 199 | stop_arm (&p1); |
199 | stop_arm(&p2); | 200 | stop_arm (&p2); |
200 | } | 201 | } |
201 | 202 | ||
202 | 203 | ||
203 | static void | 204 | static void |
204 | run(void *cls, | 205 | run (void *cls, |
205 | char *const *args, | 206 | char *const *args, |
206 | const char *cfgfile, | 207 | const char *cfgfile, |
207 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 208 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
208 | { | 209 | { |
209 | GNUNET_assert(ok == 1); | 210 | GNUNET_assert (ok == 1); |
210 | ok++; | 211 | ok++; |
211 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); | 212 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
212 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
213 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 214 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
214 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 215 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
215 | } | 216 | } |
216 | 217 | ||
217 | 218 | ||
218 | static int | 219 | static int |
219 | check() | 220 | check () |
220 | { | 221 | { |
221 | char *const argv[] = { "test-gnunet-daemon-hostlist", | 222 | char *const argv[] = { "test-gnunet-daemon-hostlist", |
222 | "-c", | 223 | "-c", |
223 | "test_gnunet_daemon_hostlist_data.conf", | 224 | "test_gnunet_daemon_hostlist_data.conf", |
224 | NULL }; | 225 | NULL }; |
225 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; | 226 | struct GNUNET_GETOPT_CommandLineOption options[] = |
227 | { GNUNET_GETOPT_OPTION_END }; | ||
226 | 228 | ||
227 | ok = 1; | 229 | ok = 1; |
228 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 230 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
229 | argv, | 231 | argv, |
230 | "test-gnunet-daemon-hostlist", | 232 | "test-gnunet-daemon-hostlist", |
231 | "nohelp", | 233 | "nohelp", |
232 | options, | 234 | options, |
233 | &run, | 235 | &run, |
234 | &ok); | 236 | &ok); |
235 | return ok; | 237 | return ok; |
236 | } | 238 | } |
237 | 239 | ||
238 | 240 | ||
239 | int | 241 | int |
240 | main(int argc, char *argv[]) | 242 | main (int argc, char *argv[]) |
241 | { | 243 | { |
242 | int ret; | 244 | int ret; |
243 | 245 | ||
244 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 246 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
245 | "GNUNET_TEST_HOME"); | 247 | "GNUNET_TEST_HOME"); |
246 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 248 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
247 | "GNUNET_TEST_HOME"); | 249 | "GNUNET_TEST_HOME"); |
248 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 250 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
249 | "GNUNET_TEST_HOME"); | 251 | "GNUNET_TEST_HOME"); |
250 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); | 252 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); |
251 | ret = check(); | 253 | ret = check (); |
252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 254 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 255 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 256 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 257 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 258 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 259 | "GNUNET_TEST_HOME"); |
258 | return ret; | 260 | return ret; |
259 | } | 261 | } |
260 | 262 | ||
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index fa72ac828..f9fabab10 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -35,12 +35,14 @@ | |||
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, \ |
41 | 1) | ||
41 | 42 | ||
42 | 43 | ||
43 | struct PeerContext { | 44 | struct PeerContext |
45 | { | ||
44 | struct GNUNET_CONFIGURATION_Handle *cfg; | 46 | struct GNUNET_CONFIGURATION_Handle *cfg; |
45 | struct GNUNET_MessageHeader *hello; | 47 | struct GNUNET_MessageHeader *hello; |
46 | struct GNUNET_CORE_Handle *core; | 48 | struct GNUNET_CORE_Handle *core; |
@@ -78,86 +80,86 @@ static struct GNUNET_STATISTICS_GetHandle *advsent_stat; | |||
78 | 80 | ||
79 | 81 | ||
80 | static void | 82 | static void |
81 | shutdown_testcase() | 83 | shutdown_testcase () |
82 | { | 84 | { |
83 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
84 | "Shutdown testcase....\n"); | 86 | "Shutdown testcase....\n"); |
85 | if (NULL != timeout_task) | 87 | if (NULL != timeout_task) |
86 | { | 88 | { |
87 | GNUNET_SCHEDULER_cancel(timeout_task); | 89 | GNUNET_SCHEDULER_cancel (timeout_task); |
88 | timeout_task = NULL; | 90 | timeout_task = NULL; |
89 | } | 91 | } |
90 | if (NULL != download_stats) | 92 | if (NULL != download_stats) |
91 | { | 93 | { |
92 | GNUNET_STATISTICS_get_cancel(download_stats); | 94 | GNUNET_STATISTICS_get_cancel (download_stats); |
93 | download_stats = NULL; | 95 | download_stats = NULL; |
94 | } | 96 | } |
95 | if (NULL != urisrecv_stat) | 97 | if (NULL != urisrecv_stat) |
96 | { | 98 | { |
97 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); | 99 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
98 | urisrecv_stat = NULL; | 100 | urisrecv_stat = NULL; |
99 | } | 101 | } |
100 | if (NULL != advsent_stat) | 102 | if (NULL != advsent_stat) |
101 | { | 103 | { |
102 | GNUNET_STATISTICS_get_cancel(advsent_stat); | 104 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
103 | advsent_stat = NULL; | 105 | advsent_stat = NULL; |
104 | } | 106 | } |
105 | if (NULL != adv_peer.stats) | 107 | if (NULL != adv_peer.stats) |
106 | { | 108 | { |
107 | GNUNET_STATISTICS_destroy(adv_peer.stats, GNUNET_NO); | 109 | GNUNET_STATISTICS_destroy (adv_peer.stats, GNUNET_NO); |
108 | adv_peer.stats = NULL; | 110 | adv_peer.stats = NULL; |
109 | } | 111 | } |
110 | if (NULL != learn_peer.stats) | 112 | if (NULL != learn_peer.stats) |
111 | { | 113 | { |
112 | GNUNET_STATISTICS_destroy(learn_peer.stats, GNUNET_NO); | 114 | GNUNET_STATISTICS_destroy (learn_peer.stats, GNUNET_NO); |
113 | learn_peer.stats = NULL; | 115 | learn_peer.stats = NULL; |
114 | } | 116 | } |
115 | if (NULL != check_task) | 117 | if (NULL != check_task) |
116 | { | 118 | { |
117 | GNUNET_SCHEDULER_cancel(check_task); | 119 | GNUNET_SCHEDULER_cancel (check_task); |
118 | check_task = NULL; | 120 | check_task = NULL; |
119 | } | 121 | } |
120 | if (NULL != current_adv_uri) | 122 | if (NULL != current_adv_uri) |
121 | { | 123 | { |
122 | GNUNET_free(current_adv_uri); | 124 | GNUNET_free (current_adv_uri); |
123 | current_adv_uri = NULL; | 125 | current_adv_uri = NULL; |
124 | } | 126 | } |
125 | if (NULL != adv_peer.core) | 127 | if (NULL != adv_peer.core) |
126 | { | 128 | { |
127 | GNUNET_CORE_disconnect(adv_peer.core); | 129 | GNUNET_CORE_disconnect (adv_peer.core); |
128 | adv_peer.core = NULL; | 130 | adv_peer.core = NULL; |
129 | } | 131 | } |
130 | if (NULL != learn_peer.core) | 132 | if (NULL != learn_peer.core) |
131 | { | 133 | { |
132 | GNUNET_CORE_disconnect(learn_peer.core); | 134 | GNUNET_CORE_disconnect (learn_peer.core); |
133 | learn_peer.core = NULL; | 135 | learn_peer.core = NULL; |
134 | } | 136 | } |
135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
136 | "Killing hostlist server ARM process.\n"); | 138 | "Killing hostlist server ARM process.\n"); |
137 | if (0 != GNUNET_OS_process_kill(adv_peer.arm_proc, | 139 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, |
138 | GNUNET_TERM_SIG)) | 140 | GNUNET_TERM_SIG)) |
139 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 141 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
140 | "kill"); | 142 | "kill"); |
141 | if (GNUNET_OK != | 143 | if (GNUNET_OK != |
142 | GNUNET_OS_process_wait(adv_peer.arm_proc)) | 144 | GNUNET_OS_process_wait (adv_peer.arm_proc)) |
143 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 145 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
144 | "waitpid"); | 146 | "waitpid"); |
145 | GNUNET_OS_process_destroy(adv_peer.arm_proc); | 147 | GNUNET_OS_process_destroy (adv_peer.arm_proc); |
146 | adv_peer.arm_proc = NULL; | 148 | adv_peer.arm_proc = NULL; |
147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
148 | "Killing hostlist client ARM process.\n"); | 150 | "Killing hostlist client ARM process.\n"); |
149 | if (0 != GNUNET_OS_process_kill(learn_peer.arm_proc, | 151 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, |
150 | GNUNET_TERM_SIG)) | 152 | GNUNET_TERM_SIG)) |
151 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 153 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
152 | "kill"); | 154 | "kill"); |
153 | if (GNUNET_OK != | 155 | if (GNUNET_OK != |
154 | GNUNET_OS_process_wait(learn_peer.arm_proc)) | 156 | GNUNET_OS_process_wait (learn_peer.arm_proc)) |
155 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 157 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
156 | "waitpid"); | 158 | "waitpid"); |
157 | GNUNET_OS_process_destroy(learn_peer.arm_proc); | 159 | GNUNET_OS_process_destroy (learn_peer.arm_proc); |
158 | learn_peer.arm_proc = NULL; | 160 | learn_peer.arm_proc = NULL; |
159 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Shutdown complete....\n"); | 162 | "Shutdown complete....\n"); |
161 | } | 163 | } |
162 | 164 | ||
163 | 165 | ||
@@ -165,112 +167,112 @@ shutdown_testcase() | |||
165 | * Timeout, give up. | 167 | * Timeout, give up. |
166 | */ | 168 | */ |
167 | static void | 169 | static void |
168 | timeout_error(void *cls) | 170 | timeout_error (void *cls) |
169 | { | 171 | { |
170 | timeout_task = NULL; | 172 | timeout_task = NULL; |
171 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
172 | "Timeout while executing testcase, test failed.\n"); | 174 | "Timeout while executing testcase, test failed.\n"); |
173 | timeout = GNUNET_YES; | 175 | timeout = GNUNET_YES; |
174 | shutdown_testcase(); | 176 | shutdown_testcase (); |
175 | } | 177 | } |
176 | 178 | ||
177 | 179 | ||
178 | static void | 180 | static void |
179 | process_downloads_done(void *cls, int success) | 181 | process_downloads_done (void *cls, int success) |
180 | { | 182 | { |
181 | download_stats = NULL; | 183 | download_stats = NULL; |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
185 | static void | 187 | static void |
186 | do_shutdown(void *cls) | 188 | do_shutdown (void *cls) |
187 | { | 189 | { |
188 | shutdown_testcase(); | 190 | shutdown_testcase (); |
189 | } | 191 | } |
190 | 192 | ||
191 | 193 | ||
192 | static int | 194 | static int |
193 | process_downloads(void *cls, | 195 | process_downloads (void *cls, |
194 | const char *subsystem, | 196 | const char *subsystem, |
195 | const char *name, | 197 | const char *name, |
196 | uint64_t value, | 198 | uint64_t value, |
197 | int is_persistent) | 199 | int is_persistent) |
198 | { | 200 | { |
199 | if ((value >= 2) && | 201 | if ((value >= 2) && |
200 | (GNUNET_NO == learned_hostlist_downloaded)) | 202 | (GNUNET_NO == learned_hostlist_downloaded)) |
203 | { | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
205 | "Peer has successfully downloaded advertised URI\n"); | ||
206 | learned_hostlist_downloaded = GNUNET_YES; | ||
207 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) | ||
201 | { | 208 | { |
202 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 209 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
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 | } | 210 | } |
211 | } | ||
210 | return GNUNET_OK; | 212 | return GNUNET_OK; |
211 | } | 213 | } |
212 | 214 | ||
213 | 215 | ||
214 | static void | 216 | static void |
215 | process_uris_recv_done(void *cls, int success) | 217 | process_uris_recv_done (void *cls, int success) |
216 | { | 218 | { |
217 | urisrecv_stat = NULL; | 219 | urisrecv_stat = NULL; |
218 | } | 220 | } |
219 | 221 | ||
220 | 222 | ||
221 | static int | 223 | static int |
222 | process_uris_recv(void *cls, | 224 | process_uris_recv (void *cls, |
223 | const char *subsystem, | 225 | const char *subsystem, |
224 | const char *name, | 226 | const char *name, |
225 | uint64_t value, | 227 | uint64_t value, |
226 | int is_persistent) | 228 | int is_persistent) |
227 | { | 229 | { |
228 | struct PeerContext *pc = cls; | 230 | struct PeerContext *pc = cls; |
229 | 231 | ||
230 | if ((pc == &learn_peer) && | 232 | if ((pc == &learn_peer) && |
231 | (value == 1) && | 233 | (value == 1) && |
232 | (learned_hostlist_saved == GNUNET_NO)) | 234 | (learned_hostlist_saved == GNUNET_NO)) |
235 | { | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
237 | "Peer has successfully saved advertised URI\n"); | ||
238 | learned_hostlist_saved = GNUNET_YES; | ||
239 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
240 | (adv_sent == GNUNET_YES)) | ||
233 | { | 241 | { |
234 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 242 | GNUNET_SCHEDULER_add_now (&do_shutdown, |
235 | "Peer has successfully saved advertised URI\n"); | 243 | NULL); |
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 | } | ||
243 | } | 244 | } |
245 | } | ||
244 | return GNUNET_OK; | 246 | return GNUNET_OK; |
245 | } | 247 | } |
246 | 248 | ||
247 | 249 | ||
248 | static void | 250 | static void |
249 | process_adv_sent_done(void *cls, int success) | 251 | process_adv_sent_done (void *cls, int success) |
250 | { | 252 | { |
251 | advsent_stat = NULL; | 253 | advsent_stat = NULL; |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
255 | static int | 257 | static int |
256 | process_adv_sent(void *cls, | 258 | process_adv_sent (void *cls, |
257 | const char *subsystem, | 259 | const char *subsystem, |
258 | const char *name, | 260 | const char *name, |
259 | uint64_t value, | 261 | uint64_t value, |
260 | int is_persistent) | 262 | int is_persistent) |
261 | { | 263 | { |
262 | if ((value >= 1) && (adv_sent == GNUNET_NO)) | 264 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
265 | { | ||
266 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
267 | "Server has successfully sent advertisement\n"); | ||
268 | adv_sent = GNUNET_YES; | ||
269 | if ((learned_hostlist_downloaded == GNUNET_YES) && | ||
270 | (learned_hostlist_saved == GNUNET_YES)) | ||
263 | { | 271 | { |
264 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 272 | GNUNET_SCHEDULER_add_now (&do_shutdown, |
265 | "Server has successfully sent advertisement\n"); | 273 | NULL); |
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 | } | ||
273 | } | 274 | } |
275 | } | ||
274 | return GNUNET_OK; | 276 | return GNUNET_OK; |
275 | } | 277 | } |
276 | 278 | ||
@@ -279,70 +281,71 @@ process_adv_sent(void *cls, | |||
279 | * Check the server statistics regularly | 281 | * Check the server statistics regularly |
280 | */ | 282 | */ |
281 | static void | 283 | static void |
282 | check_statistics(void *cls) | 284 | check_statistics (void *cls) |
283 | { | 285 | { |
284 | char *stat; | 286 | char *stat; |
285 | 287 | ||
286 | check_task = NULL; | 288 | check_task = NULL; |
287 | GNUNET_asprintf(&stat, | 289 | GNUNET_asprintf (&stat, |
288 | gettext_noop("# advertised URI `%s' downloaded"), | 290 | gettext_noop ("# advertised URI `%s' downloaded"), |
289 | current_adv_uri); | 291 | current_adv_uri); |
290 | if (NULL != learn_peer.stats) | 292 | if (NULL != learn_peer.stats) |
291 | { | 293 | { |
292 | if (NULL != download_stats) | 294 | if (NULL != download_stats) |
293 | GNUNET_STATISTICS_get_cancel(download_stats); | 295 | GNUNET_STATISTICS_get_cancel (download_stats); |
294 | download_stats = | 296 | download_stats = |
295 | GNUNET_STATISTICS_get(learn_peer.stats, | 297 | GNUNET_STATISTICS_get (learn_peer.stats, |
296 | "hostlist", | 298 | "hostlist", |
297 | stat, | 299 | stat, |
298 | &process_downloads_done, | 300 | &process_downloads_done, |
299 | &process_downloads, | 301 | &process_downloads, |
300 | &learn_peer); | 302 | &learn_peer); |
301 | if (NULL != urisrecv_stat) | 303 | if (NULL != urisrecv_stat) |
302 | GNUNET_STATISTICS_get_cancel(urisrecv_stat); | 304 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
303 | urisrecv_stat = | 305 | urisrecv_stat = |
304 | GNUNET_STATISTICS_get(learn_peer.stats, "hostlist", | 306 | GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", |
305 | gettext_noop("# advertised hostlist URIs"), | 307 | gettext_noop ("# advertised hostlist URIs"), |
306 | &process_uris_recv_done, &process_uris_recv, | 308 | &process_uris_recv_done, &process_uris_recv, |
307 | &learn_peer); | 309 | &learn_peer); |
308 | } | 310 | } |
309 | GNUNET_free(stat); | 311 | GNUNET_free (stat); |
310 | if (NULL != adv_peer.stats) | 312 | if (NULL != adv_peer.stats) |
311 | { | 313 | { |
312 | if (NULL != advsent_stat) | 314 | if (NULL != advsent_stat) |
313 | GNUNET_STATISTICS_get_cancel(advsent_stat); | 315 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
314 | advsent_stat = | 316 | advsent_stat = |
315 | GNUNET_STATISTICS_get(adv_peer.stats, "hostlist", | 317 | GNUNET_STATISTICS_get (adv_peer.stats, "hostlist", |
316 | gettext_noop("# hostlist advertisements send"), | 318 | gettext_noop ("# hostlist advertisements send"), |
317 | &process_adv_sent_done, | 319 | &process_adv_sent_done, |
318 | &process_adv_sent, | 320 | &process_adv_sent, |
319 | NULL); | 321 | NULL); |
320 | } | 322 | } |
321 | check_task = | 323 | check_task = |
322 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, | 324 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, |
323 | &check_statistics, | 325 | &check_statistics, |
324 | NULL); | 326 | NULL); |
325 | } | 327 | } |
326 | 328 | ||
327 | 329 | ||
328 | static int | 330 | static int |
329 | check_ad_arrive(void *cls, | 331 | check_ad_arrive (void *cls, |
330 | const struct GNUNET_MessageHeader *message) | 332 | const struct GNUNET_MessageHeader *message) |
331 | { | 333 | { |
332 | const char *end = (const char *)&message[1]; | 334 | const char *end = (const char *) &message[1]; |
333 | 335 | ||
334 | if ('\0' != end[ntohs(message->size) - sizeof(struct GNUNET_MessageHeader) - 1]) | 336 | if ('\0' != end[ntohs (message->size) - sizeof(struct GNUNET_MessageHeader) |
335 | { | 337 | - 1]) |
336 | GNUNET_break(0); | 338 | { |
337 | return GNUNET_SYSERR; | 339 | GNUNET_break (0); |
338 | } | 340 | return GNUNET_SYSERR; |
341 | } | ||
339 | return GNUNET_OK; | 342 | return GNUNET_OK; |
340 | } | 343 | } |
341 | 344 | ||
342 | 345 | ||
343 | static void | 346 | static void |
344 | handle_ad_arrive(void *cls, | 347 | handle_ad_arrive (void *cls, |
345 | const struct GNUNET_MessageHeader *message) | 348 | const struct GNUNET_MessageHeader *message) |
346 | { | 349 | { |
347 | char *hostname; | 350 | char *hostname; |
348 | char *expected_uri; | 351 | char *expected_uri; |
@@ -350,132 +353,132 @@ handle_ad_arrive(void *cls, | |||
350 | const char *end; | 353 | const char *end; |
351 | 354 | ||
352 | if (GNUNET_SYSERR == | 355 | if (GNUNET_SYSERR == |
353 | GNUNET_CONFIGURATION_get_value_number(adv_peer.cfg, | 356 | GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, |
354 | "HOSTLIST", | 357 | "HOSTLIST", |
355 | "HTTPPORT", | 358 | "HTTPPORT", |
356 | &port)) | 359 | &port)) |
357 | { | 360 | { |
358 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
359 | "Could not read advertising server's configuration\n"); | 362 | "Could not read advertising server's configuration\n"); |
360 | return; | 363 | return; |
361 | } | 364 | } |
362 | 365 | ||
363 | if (GNUNET_SYSERR == | 366 | if (GNUNET_SYSERR == |
364 | GNUNET_CONFIGURATION_get_value_string(adv_peer.cfg, | 367 | GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, |
365 | "HOSTLIST", | 368 | "HOSTLIST", |
366 | "EXTERNAL_DNS_NAME", | 369 | "EXTERNAL_DNS_NAME", |
367 | &hostname)) | 370 | &hostname)) |
368 | hostname = GNUNET_RESOLVER_local_fqdn_get(); | 371 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
369 | GNUNET_asprintf(&expected_uri, | 372 | GNUNET_asprintf (&expected_uri, |
370 | "http://%s:%u/", | 373 | "http://%s:%u/", |
371 | hostname != NULL ? hostname : "localhost", | 374 | hostname != NULL ? hostname : "localhost", |
372 | (unsigned int)port); | 375 | (unsigned int) port); |
373 | end = (const char *)&message[1]; | 376 | end = (const char *) &message[1]; |
374 | current_adv_uri = GNUNET_strdup(end); | 377 | current_adv_uri = GNUNET_strdup (end); |
375 | if (0 == strcmp(expected_uri, | 378 | if (0 == strcmp (expected_uri, |
376 | current_adv_uri)) | 379 | current_adv_uri)) |
377 | { | 380 | { |
378 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
379 | "Received hostlist advertisement with URI `%s' as expected\n", | 382 | "Received hostlist advertisement with URI `%s' as expected\n", |
380 | current_adv_uri); | 383 | current_adv_uri); |
381 | adv_arrived = GNUNET_YES; | 384 | adv_arrived = GNUNET_YES; |
382 | adv_sent = GNUNET_YES; | 385 | adv_sent = GNUNET_YES; |
383 | } | 386 | } |
384 | else | 387 | else |
385 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
386 | "Expected URI `%s' and received URI `%s' differ\n", | 389 | "Expected URI `%s' and received URI `%s' differ\n", |
387 | expected_uri, | 390 | expected_uri, |
388 | current_adv_uri); | 391 | current_adv_uri); |
389 | GNUNET_free(expected_uri); | 392 | GNUNET_free (expected_uri); |
390 | GNUNET_free_non_null(hostname); | 393 | GNUNET_free_non_null (hostname); |
391 | } | 394 | } |
392 | 395 | ||
393 | 396 | ||
394 | static void | 397 | static void |
395 | setup_learn_peer(struct PeerContext *p, | 398 | setup_learn_peer (struct PeerContext *p, |
396 | const char *cfgname) | 399 | const char *cfgname) |
397 | { | 400 | { |
398 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { | 401 | struct GNUNET_MQ_MessageHandler learn_handlers[] = { |
399 | GNUNET_MQ_hd_var_size(ad_arrive, | 402 | GNUNET_MQ_hd_var_size (ad_arrive, |
400 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, | 403 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, |
401 | struct GNUNET_MessageHeader, | 404 | struct GNUNET_MessageHeader, |
402 | NULL), | 405 | NULL), |
403 | GNUNET_MQ_handler_end() | 406 | GNUNET_MQ_handler_end () |
404 | }; | 407 | }; |
405 | char *filename; | 408 | char *filename; |
406 | unsigned int result; | 409 | unsigned int result; |
407 | char *binary; | 410 | char *binary; |
408 | 411 | ||
409 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 412 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
410 | p->cfg = GNUNET_CONFIGURATION_create(); | 413 | p->cfg = GNUNET_CONFIGURATION_create (); |
411 | p->arm_proc = | 414 | p->arm_proc = |
412 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 415 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
413 | NULL, NULL, NULL, | 416 | NULL, NULL, NULL, |
414 | binary, | 417 | binary, |
415 | "gnunet-service-arm", | 418 | "gnunet-service-arm", |
416 | "-c", cfgname, NULL); | 419 | "-c", cfgname, NULL); |
417 | GNUNET_assert(GNUNET_OK == | 420 | GNUNET_assert (GNUNET_OK == |
418 | GNUNET_CONFIGURATION_load(p->cfg, | 421 | GNUNET_CONFIGURATION_load (p->cfg, |
419 | cfgname)); | 422 | cfgname)); |
420 | if (GNUNET_OK == | 423 | if (GNUNET_OK == |
421 | GNUNET_CONFIGURATION_get_value_string(p->cfg, | 424 | GNUNET_CONFIGURATION_get_value_string (p->cfg, |
422 | "HOSTLIST", | 425 | "HOSTLIST", |
423 | "HOSTLISTFILE", | 426 | "HOSTLISTFILE", |
424 | &filename)) | 427 | &filename)) |
428 | { | ||
429 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
425 | { | 430 | { |
426 | if (GNUNET_YES == GNUNET_DISK_file_test(filename)) | 431 | result = unlink (filename); |
427 | { | 432 | if (result == 0) |
428 | result = unlink(filename); | 433 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
429 | if (result == 0) | 434 | _ ("Hostlist file `%s' was removed\n"), |
430 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 435 | filename); |
431 | _("Hostlist file `%s' was removed\n"), | ||
432 | filename); | ||
433 | } | ||
434 | GNUNET_free(filename); | ||
435 | } | 436 | } |
436 | p->core = GNUNET_CORE_connect(p->cfg, | 437 | GNUNET_free (filename); |
437 | NULL, | 438 | } |
438 | NULL, | 439 | p->core = GNUNET_CORE_connect (p->cfg, |
439 | NULL, | 440 | NULL, |
440 | NULL, | 441 | NULL, |
441 | learn_handlers); | 442 | NULL, |
442 | GNUNET_assert(NULL != p->core); | 443 | NULL, |
443 | p->stats = GNUNET_STATISTICS_create("hostlist", | 444 | learn_handlers); |
444 | p->cfg); | 445 | GNUNET_assert (NULL != p->core); |
445 | GNUNET_assert(NULL != p->stats); | 446 | p->stats = GNUNET_STATISTICS_create ("hostlist", |
446 | GNUNET_free(binary); | 447 | p->cfg); |
448 | GNUNET_assert (NULL != p->stats); | ||
449 | GNUNET_free (binary); | ||
447 | } | 450 | } |
448 | 451 | ||
449 | 452 | ||
450 | static void | 453 | static void |
451 | setup_adv_peer(struct PeerContext *p, | 454 | setup_adv_peer (struct PeerContext *p, |
452 | const char *cfgname) | 455 | const char *cfgname) |
453 | { | 456 | { |
454 | char *binary; | 457 | char *binary; |
455 | 458 | ||
456 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 459 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
457 | p->cfg = GNUNET_CONFIGURATION_create(); | 460 | p->cfg = GNUNET_CONFIGURATION_create (); |
458 | p->arm_proc = | 461 | p->arm_proc = |
459 | GNUNET_OS_start_process(GNUNET_YES, | 462 | GNUNET_OS_start_process (GNUNET_YES, |
460 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 463 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
461 | NULL, NULL, NULL, | 464 | NULL, NULL, NULL, |
462 | binary, | 465 | binary, |
463 | "gnunet-service-arm", | 466 | "gnunet-service-arm", |
464 | "-c", cfgname, NULL); | 467 | "-c", cfgname, NULL); |
465 | GNUNET_assert(GNUNET_OK == | 468 | GNUNET_assert (GNUNET_OK == |
466 | GNUNET_CONFIGURATION_load(p->cfg, | 469 | GNUNET_CONFIGURATION_load (p->cfg, |
467 | cfgname)); | 470 | cfgname)); |
468 | p->stats = GNUNET_STATISTICS_create("hostlist", p->cfg); | 471 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
469 | GNUNET_assert(NULL != p->stats); | 472 | GNUNET_assert (NULL != p->stats); |
470 | GNUNET_free(binary); | 473 | GNUNET_free (binary); |
471 | } | 474 | } |
472 | 475 | ||
473 | 476 | ||
474 | static void | 477 | static void |
475 | run(void *cls, | 478 | run (void *cls, |
476 | char *const *args, | 479 | char *const *args, |
477 | const char *cfgfile, | 480 | const char *cfgfile, |
478 | const struct GNUNET_CONFIGURATION_Handle *c) | 481 | const struct GNUNET_CONFIGURATION_Handle *c) |
479 | { | 482 | { |
480 | timeout = GNUNET_NO; | 483 | timeout = GNUNET_NO; |
481 | adv_sent = GNUNET_NO; | 484 | adv_sent = GNUNET_NO; |
@@ -486,22 +489,22 @@ run(void *cls, | |||
486 | 489 | ||
487 | cfg = c; | 490 | cfg = c; |
488 | 491 | ||
489 | setup_adv_peer(&adv_peer, | 492 | setup_adv_peer (&adv_peer, |
490 | "test_learning_adv_peer.conf"); | 493 | "test_learning_adv_peer.conf"); |
491 | setup_learn_peer(&learn_peer, | 494 | setup_learn_peer (&learn_peer, |
492 | "test_learning_learn_peer.conf"); | 495 | "test_learning_learn_peer.conf"); |
493 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 496 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
494 | &timeout_error, | 497 | &timeout_error, |
495 | NULL); | 498 | NULL); |
496 | check_task = | 499 | check_task = |
497 | GNUNET_SCHEDULER_add_delayed(CHECK_INTERVAL, | 500 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, |
498 | &check_statistics, | 501 | &check_statistics, |
499 | NULL); | 502 | NULL); |
500 | } | 503 | } |
501 | 504 | ||
502 | 505 | ||
503 | static int | 506 | static int |
504 | check() | 507 | check () |
505 | { | 508 | { |
506 | unsigned int failed; | 509 | unsigned int failed; |
507 | 510 | ||
@@ -514,44 +517,44 @@ check() | |||
514 | GNUNET_GETOPT_OPTION_END | 517 | GNUNET_GETOPT_OPTION_END |
515 | }; | 518 | }; |
516 | 519 | ||
517 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 520 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
518 | argv, | 521 | argv, |
519 | "test-gnunet-daemon-hostlist-learning", | 522 | "test-gnunet-daemon-hostlist-learning", |
520 | "nohelp", | 523 | "nohelp", |
521 | options, | 524 | options, |
522 | &run, | 525 | &run, |
523 | NULL); | 526 | NULL); |
524 | failed = GNUNET_NO; | 527 | failed = GNUNET_NO; |
525 | if (timeout == GNUNET_YES) | 528 | if (timeout == GNUNET_YES) |
526 | { | 529 | { |
527 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 530 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
528 | "Testcase timeout\n"); | 531 | "Testcase timeout\n"); |
529 | failed = GNUNET_YES; | 532 | failed = GNUNET_YES; |
530 | } | 533 | } |
531 | if (adv_arrived != GNUNET_YES) | 534 | if (adv_arrived != GNUNET_YES) |
532 | { | 535 | { |
533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
534 | "Learning peer did not receive advertisement from server\n"); | 537 | "Learning peer did not receive advertisement from server\n"); |
535 | failed = GNUNET_YES; | 538 | failed = GNUNET_YES; |
536 | } | 539 | } |
537 | if (learned_hostlist_saved == GNUNET_NO) | 540 | if (learned_hostlist_saved == GNUNET_NO) |
538 | { | 541 | { |
539 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 542 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
540 | "Advertised hostlist was not saved in datastore\n"); | 543 | "Advertised hostlist was not saved in datastore\n"); |
541 | failed = GNUNET_YES; | 544 | failed = GNUNET_YES; |
542 | } | 545 | } |
543 | if (learned_hostlist_downloaded == GNUNET_NO) | 546 | if (learned_hostlist_downloaded == GNUNET_NO) |
544 | { | 547 | { |
545 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 548 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
546 | "Advertised hostlist could not be downloaded from server\n"); | 549 | "Advertised hostlist could not be downloaded from server\n"); |
547 | failed = GNUNET_YES; | 550 | failed = GNUNET_YES; |
548 | } | 551 | } |
549 | if (adv_sent == GNUNET_NO) | 552 | if (adv_sent == GNUNET_NO) |
550 | { | 553 | { |
551 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 554 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
552 | "Advertised was not sent from server to client\n"); | 555 | "Advertised was not sent from server to client\n"); |
553 | failed = GNUNET_YES; | 556 | failed = GNUNET_YES; |
554 | } | 557 | } |
555 | if (GNUNET_YES == failed) | 558 | if (GNUNET_YES == failed) |
556 | return GNUNET_YES; | 559 | return GNUNET_YES; |
557 | return GNUNET_NO; | 560 | return GNUNET_NO; |
@@ -559,29 +562,29 @@ check() | |||
559 | 562 | ||
560 | 563 | ||
561 | int | 564 | int |
562 | main(int argc, char *argv[]) | 565 | main (int argc, char *argv[]) |
563 | { | 566 | { |
564 | int ret; | 567 | int ret; |
565 | 568 | ||
566 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", | 569 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", |
567 | "GNUNET_TEST_HOME"); | 570 | "GNUNET_TEST_HOME"); |
568 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", | 571 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", |
569 | "GNUNET_TEST_HOME"); | 572 | "GNUNET_TEST_HOME"); |
570 | GNUNET_log_setup("test-gnunet-daemon-hostlist", | 573 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", |
571 | "WARNING", | 574 | "WARNING", |
572 | NULL); | 575 | NULL); |
573 | ret = check(); | 576 | ret = check (); |
574 | GNUNET_DISK_purge_cfg_dir("test_learning_learn_peer.conf", | 577 | GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf", |
575 | "GNUNET_TEST_HOME"); | 578 | "GNUNET_TEST_HOME"); |
576 | GNUNET_DISK_purge_cfg_dir("test_learning_adv_peer.conf", | 579 | GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf", |
577 | "GNUNET_TEST_HOME"); | 580 | "GNUNET_TEST_HOME"); |
578 | if (GNUNET_YES == | 581 | if (GNUNET_YES == |
579 | GNUNET_DISK_file_test("hostlists_learn_peer.file")) | 582 | GNUNET_DISK_file_test ("hostlists_learn_peer.file")) |
580 | { | 583 | { |
581 | if (0 == unlink("hostlists_learn_peer.file")) | 584 | if (0 == unlink ("hostlists_learn_peer.file")) |
582 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 585 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
583 | "Hostlist file hostlists_learn_peer.file was removed\n"); | 586 | "Hostlist file hostlists_learn_peer.file was removed\n"); |
584 | } | 587 | } |
585 | return ret; | 588 | return ret; |
586 | } | 589 | } |
587 | 590 | ||
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 783da1d20..ce17cfe4d 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | |||
@@ -32,13 +32,14 @@ | |||
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 | { | ||
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 43 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_TRANSPORT_CoreHandle *th; | 44 | struct GNUNET_TRANSPORT_CoreHandle *th; |
44 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
@@ -55,12 +56,12 @@ static struct PeerContext p2; | |||
55 | * Timeout, give up. | 56 | * Timeout, give up. |
56 | */ | 57 | */ |
57 | static void | 58 | static void |
58 | timeout_error(void *cls) | 59 | timeout_error (void *cls) |
59 | { | 60 | { |
60 | timeout_task = NULL; | 61 | timeout_task = NULL; |
61 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 62 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
62 | "Timeout trying to connect peers, test failed.\n"); | 63 | "Timeout trying to connect peers, test failed.\n"); |
63 | GNUNET_SCHEDULER_shutdown(); | 64 | GNUNET_SCHEDULER_shutdown (); |
64 | } | 65 | } |
65 | 66 | ||
66 | 67 | ||
@@ -74,87 +75,87 @@ timeout_error(void *cls) | |||
74 | * @return NULL | 75 | * @return NULL |
75 | */ | 76 | */ |
76 | static void * | 77 | static void * |
77 | notify_connect(void *cls, | 78 | notify_connect (void *cls, |
78 | const struct GNUNET_PeerIdentity *peer, | 79 | const struct GNUNET_PeerIdentity *peer, |
79 | struct GNUNET_MQ_Handle *mq) | 80 | struct GNUNET_MQ_Handle *mq) |
80 | { | 81 | { |
81 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
82 | ok = 0; | 83 | ok = 0; |
83 | GNUNET_SCHEDULER_shutdown(); | 84 | GNUNET_SCHEDULER_shutdown (); |
84 | return NULL; | 85 | return NULL; |
85 | } | 86 | } |
86 | 87 | ||
87 | 88 | ||
88 | static void | 89 | static void |
89 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) | 90 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
90 | { | 91 | { |
91 | struct PeerContext *p = cls; | 92 | struct PeerContext *p = cls; |
92 | 93 | ||
93 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); | 94 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); |
94 | p->ghh = NULL; | 95 | p->ghh = NULL; |
95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
96 | "Received HELLO, starting hostlist service.\n"); | 97 | "Received HELLO, starting hostlist service.\n"); |
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
100 | static void | 101 | static void |
101 | setup_peer(struct PeerContext *p, const char *cfgname) | 102 | setup_peer (struct PeerContext *p, const char *cfgname) |
102 | { | 103 | { |
103 | char *binary; | 104 | char *binary; |
104 | 105 | ||
105 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 106 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
106 | p->cfg = GNUNET_CONFIGURATION_create(); | 107 | p->cfg = GNUNET_CONFIGURATION_create (); |
107 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, | 108 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
108 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 109 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
109 | NULL, | 110 | NULL, |
110 | NULL, | 111 | NULL, |
111 | NULL, | 112 | NULL, |
112 | binary, | 113 | binary, |
113 | "gnunet-service-arm", | 114 | "gnunet-service-arm", |
114 | "-c", | 115 | "-c", |
115 | cfgname, | 116 | cfgname, |
116 | NULL); | 117 | NULL); |
117 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); | 118 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
118 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, | 119 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
119 | NULL, | 120 | NULL, |
120 | NULL, | 121 | NULL, |
121 | p, | 122 | p, |
122 | ¬ify_connect, | 123 | ¬ify_connect, |
123 | NULL, | 124 | NULL, |
124 | NULL); | 125 | NULL); |
125 | GNUNET_assert(NULL != p->th); | 126 | GNUNET_assert (NULL != p->th); |
126 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, | 127 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
127 | GNUNET_TRANSPORT_AC_ANY, | 128 | GNUNET_TRANSPORT_AC_ANY, |
128 | &process_hello, | 129 | &process_hello, |
129 | p); | 130 | p); |
130 | GNUNET_free(binary); | 131 | GNUNET_free (binary); |
131 | } | 132 | } |
132 | 133 | ||
133 | 134 | ||
134 | static void | 135 | static void |
135 | waitpid_task(void *cls) | 136 | waitpid_task (void *cls) |
136 | { | 137 | { |
137 | struct PeerContext *p = cls; | 138 | struct PeerContext *p = cls; |
138 | 139 | ||
139 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
140 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) | 141 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) |
141 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 142 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
142 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) | 143 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) |
143 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "ARM process %u stopped\n", | 146 | "ARM process %u stopped\n", |
146 | GNUNET_OS_process_get_pid(p->arm_proc)); | 147 | GNUNET_OS_process_get_pid (p->arm_proc)); |
147 | GNUNET_OS_process_destroy(p->arm_proc); | 148 | GNUNET_OS_process_destroy (p->arm_proc); |
148 | p->arm_proc = NULL; | 149 | p->arm_proc = NULL; |
149 | GNUNET_CONFIGURATION_destroy(p->cfg); | 150 | GNUNET_CONFIGURATION_destroy (p->cfg); |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | static void | 154 | static void |
154 | stop_arm(struct PeerContext *p) | 155 | stop_arm (struct PeerContext *p) |
155 | { | 156 | { |
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
157 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
158 | } | 159 | } |
159 | 160 | ||
160 | 161 | ||
@@ -162,55 +163,55 @@ stop_arm(struct PeerContext *p) | |||
162 | * Try again to connect to transport service. | 163 | * Try again to connect to transport service. |
163 | */ | 164 | */ |
164 | static void | 165 | static void |
165 | shutdown_task(void *cls) | 166 | shutdown_task (void *cls) |
166 | { | 167 | { |
167 | if (NULL != timeout_task) | 168 | if (NULL != timeout_task) |
168 | { | 169 | { |
169 | GNUNET_SCHEDULER_cancel(timeout_task); | 170 | GNUNET_SCHEDULER_cancel (timeout_task); |
170 | timeout_task = NULL; | 171 | timeout_task = NULL; |
171 | } | 172 | } |
172 | if (NULL != p1.ghh) | 173 | if (NULL != p1.ghh) |
173 | { | 174 | { |
174 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); | 175 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); |
175 | p1.ghh = NULL; | 176 | p1.ghh = NULL; |
176 | } | 177 | } |
177 | if (NULL != p1.th) | 178 | if (NULL != p1.th) |
178 | { | 179 | { |
179 | GNUNET_TRANSPORT_core_disconnect(p1.th); | 180 | GNUNET_TRANSPORT_core_disconnect (p1.th); |
180 | p1.th = NULL; | 181 | p1.th = NULL; |
181 | } | 182 | } |
182 | if (NULL != p2.ghh) | 183 | if (NULL != p2.ghh) |
183 | { | 184 | { |
184 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); | 185 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); |
185 | p2.ghh = NULL; | 186 | p2.ghh = NULL; |
186 | } | 187 | } |
187 | if (NULL != p2.th) | 188 | if (NULL != p2.th) |
188 | { | 189 | { |
189 | GNUNET_TRANSPORT_core_disconnect(p2.th); | 190 | GNUNET_TRANSPORT_core_disconnect (p2.th); |
190 | p2.th = NULL; | 191 | p2.th = NULL; |
191 | } | 192 | } |
192 | stop_arm(&p1); | 193 | stop_arm (&p1); |
193 | stop_arm(&p2); | 194 | stop_arm (&p2); |
194 | } | 195 | } |
195 | 196 | ||
196 | 197 | ||
197 | static void | 198 | static void |
198 | run(void *cls, | 199 | run (void *cls, |
199 | char *const *args, | 200 | char *const *args, |
200 | const char *cfgfile, | 201 | const char *cfgfile, |
201 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 202 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
202 | { | 203 | { |
203 | GNUNET_assert(ok == 1); | 204 | GNUNET_assert (ok == 1); |
204 | ok++; | 205 | ok++; |
205 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); | 206 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
206 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 207 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
207 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 208 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
208 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 209 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
209 | } | 210 | } |
210 | 211 | ||
211 | 212 | ||
212 | int | 213 | int |
213 | main(int argcx, char *argvx[]) | 214 | main (int argcx, char *argvx[]) |
214 | { | 215 | { |
215 | static char *const argv[] = { "test-gnunet-daemon-hostlist", | 216 | static char *const argv[] = { "test-gnunet-daemon-hostlist", |
216 | "-c", | 217 | "-c", |
@@ -220,41 +221,41 @@ main(int argcx, char *argvx[]) | |||
220 | GNUNET_GETOPT_OPTION_END | 221 | GNUNET_GETOPT_OPTION_END |
221 | }; | 222 | }; |
222 | 223 | ||
223 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 224 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
224 | "GNUNET_TEST_HOME"); | 225 | "GNUNET_TEST_HOME"); |
225 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 226 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
226 | "GNUNET_TEST_HOME"); | 227 | "GNUNET_TEST_HOME"); |
227 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 228 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
228 | "GNUNET_TEST_HOME"); | 229 | "GNUNET_TEST_HOME"); |
229 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); | 230 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); |
230 | ok = 1; | 231 | ok = 1; |
231 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 232 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
232 | argv, | 233 | argv, |
233 | "test-gnunet-daemon-hostlist", | 234 | "test-gnunet-daemon-hostlist", |
234 | "nohelp", | 235 | "nohelp", |
235 | options, | 236 | options, |
236 | &run, | 237 | &run, |
237 | &ok); | 238 | &ok); |
238 | if (0 == ok) | 239 | if (0 == ok) |
239 | { | 240 | { |
240 | fprintf(stderr, "%s", "."); | 241 | fprintf (stderr, "%s", "."); |
241 | /* now do it again */ | 242 | /* now do it again */ |
242 | ok = 1; | 243 | ok = 1; |
243 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 244 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
244 | argv, | 245 | argv, |
245 | "test-gnunet-daemon-hostlist", | 246 | "test-gnunet-daemon-hostlist", |
246 | "nohelp", | 247 | "nohelp", |
247 | options, | 248 | options, |
248 | &run, | 249 | &run, |
249 | &ok); | 250 | &ok); |
250 | fprintf(stderr, "%s", ".\n"); | 251 | fprintf (stderr, "%s", ".\n"); |
251 | } | 252 | } |
252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 253 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 254 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 255 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 256 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 257 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 258 | "GNUNET_TEST_HOME"); |
258 | return ok; | 259 | return ok; |
259 | } | 260 | } |
260 | 261 | ||