diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/hostlist/test_gnunet_daemon_hostlist_learning.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_learning.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 131 |
1 files changed, 58 insertions, 73 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 7ecca8a85..2538e42fb 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -182,9 +182,8 @@ process_downloads_done (void *cls, int success) | |||
182 | 182 | ||
183 | 183 | ||
184 | static int | 184 | static int |
185 | process_downloads (void *cls, | 185 | process_downloads (void *cls, const char *subsystem, const char *name, |
186 | const char *subsystem, | 186 | uint64_t value, int is_persistent) |
187 | const char *name, uint64_t value, int is_persistent) | ||
188 | { | 187 | { |
189 | if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO)) | 188 | if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO)) |
190 | { | 189 | { |
@@ -206,12 +205,11 @@ process_uris_recv_done (void *cls, int success) | |||
206 | 205 | ||
207 | 206 | ||
208 | static int | 207 | static int |
209 | process_uris_recv (void *cls, | 208 | process_uris_recv (void *cls, const char *subsystem, const char *name, |
210 | const char *subsystem, | 209 | uint64_t value, int is_persistent) |
211 | const char *name, uint64_t value, int is_persistent) | ||
212 | { | 210 | { |
213 | if (((struct PeerContext *) cls == &learn_peer) && | 211 | if (((struct PeerContext *) cls == &learn_peer) && (value == 1) && |
214 | (value == 1) && (learned_hostlist_saved == GNUNET_NO)) | 212 | (learned_hostlist_saved == GNUNET_NO)) |
215 | { | 213 | { |
216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
217 | "Peer has successfully saved advertised URI\n"); | 215 | "Peer has successfully saved advertised URI\n"); |
@@ -231,9 +229,8 @@ process_adv_sent_done (void *cls, int success) | |||
231 | 229 | ||
232 | 230 | ||
233 | static int | 231 | static int |
234 | process_adv_sent (void *cls, | 232 | process_adv_sent (void *cls, const char *subsystem, const char *name, |
235 | const char *subsystem, | 233 | uint64_t value, int is_persistent) |
236 | const char *name, uint64_t value, int is_persistent) | ||
237 | { | 234 | { |
238 | if ((value >= 1) && (adv_sent == GNUNET_NO)) | 235 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
239 | { | 236 | { |
@@ -259,44 +256,39 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
259 | check_task = GNUNET_SCHEDULER_NO_TASK; | 256 | check_task = GNUNET_SCHEDULER_NO_TASK; |
260 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 257 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
261 | return; | 258 | return; |
262 | GNUNET_asprintf (&stat, | 259 | GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), |
263 | gettext_noop ("# advertised URI `%s' downloaded"), | ||
264 | current_adv_uri); | 260 | current_adv_uri); |
265 | if (NULL != learn_peer.stats) | 261 | if (NULL != learn_peer.stats) |
266 | { | 262 | { |
267 | if (NULL != download_stats) | 263 | if (NULL != download_stats) |
268 | GNUNET_STATISTICS_get_cancel (download_stats); | 264 | GNUNET_STATISTICS_get_cancel (download_stats); |
269 | download_stats = GNUNET_STATISTICS_get (learn_peer.stats, | 265 | download_stats = |
270 | "hostlist", | 266 | GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", stat, |
271 | stat, | 267 | GNUNET_TIME_UNIT_MINUTES, |
272 | GNUNET_TIME_UNIT_MINUTES, | 268 | &process_downloads_done, &process_downloads, |
273 | &process_downloads_done, | 269 | &learn_peer); |
274 | &process_downloads, &learn_peer); | ||
275 | if (NULL != urisrecv_stat) | 270 | if (NULL != urisrecv_stat) |
276 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 271 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
277 | urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, | 272 | urisrecv_stat = |
278 | "hostlist", | 273 | GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", |
279 | gettext_noop | 274 | gettext_noop ("# advertised hostlist URIs"), |
280 | ("# advertised hostlist URIs"), | 275 | GNUNET_TIME_UNIT_MINUTES, |
281 | GNUNET_TIME_UNIT_MINUTES, | 276 | &process_uris_recv_done, &process_uris_recv, |
282 | &process_uris_recv_done, | 277 | &learn_peer); |
283 | &process_uris_recv, &learn_peer); | ||
284 | } | 278 | } |
285 | GNUNET_free (stat); | 279 | GNUNET_free (stat); |
286 | if (NULL != adv_peer.stats) | 280 | if (NULL != adv_peer.stats) |
287 | { | 281 | { |
288 | if (NULL != advsent_stat) | 282 | if (NULL != advsent_stat) |
289 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 283 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
290 | advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, | 284 | advsent_stat = |
291 | "hostlist", | 285 | GNUNET_STATISTICS_get (adv_peer.stats, "hostlist", |
292 | gettext_noop | 286 | gettext_noop ("# hostlist advertisements send"), |
293 | ("# hostlist advertisements send"), | 287 | GNUNET_TIME_UNIT_MINUTES, &process_adv_sent_done, |
294 | GNUNET_TIME_UNIT_MINUTES, | 288 | &process_adv_sent, NULL); |
295 | &process_adv_sent_done, | ||
296 | &process_adv_sent, NULL); | ||
297 | } | 289 | } |
298 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 290 | check_task = |
299 | &check_statistics, NULL); | 291 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL); |
300 | } | 292 | } |
301 | 293 | ||
302 | 294 | ||
@@ -304,8 +296,7 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
304 | * Core handler for p2p hostlist advertisements | 296 | * Core handler for p2p hostlist advertisements |
305 | */ | 297 | */ |
306 | static int | 298 | static int |
307 | ad_arrive_handler (void *cls, | 299 | ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer, |
308 | const struct GNUNET_PeerIdentity *peer, | ||
309 | const struct GNUNET_MessageHeader *message, | 300 | const struct GNUNET_MessageHeader *message, |
310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 301 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
311 | { | 302 | { |
@@ -315,22 +306,20 @@ ad_arrive_handler (void *cls, | |||
315 | const struct GNUNET_MessageHeader *incoming; | 306 | const struct GNUNET_MessageHeader *incoming; |
316 | const char *end; | 307 | const char *end; |
317 | 308 | ||
318 | if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, | 309 | if (-1 == |
319 | "HOSTLIST", | 310 | GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, "HOSTLIST", |
320 | "HTTPPORT", &port)) | 311 | "HTTPPORT", &port)) |
321 | { | 312 | { |
322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
323 | "Could not read advertising server's configuration\n"); | 314 | "Could not read advertising server's configuration\n"); |
324 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
325 | } | 316 | } |
326 | 317 | ||
327 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | 318 | if (GNUNET_SYSERR == |
328 | "HOSTLIST", | 319 | GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, "HOSTLIST", |
329 | "EXTERNAL_DNS_NAME", | 320 | "EXTERNAL_DNS_NAME", &hostname)) |
330 | &hostname)) | ||
331 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 321 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
332 | GNUNET_asprintf (&expected_uri, | 322 | GNUNET_asprintf (&expected_uri, "http://%s:%u/", |
333 | "http://%s:%u/", | ||
334 | hostname != NULL ? hostname : "localhost", | 323 | hostname != NULL ? hostname : "localhost", |
335 | (unsigned int) port); | 324 | (unsigned int) port); |
336 | incoming = (const struct GNUNET_MessageHeader *) message; | 325 | incoming = (const struct GNUNET_MessageHeader *) message; |
@@ -379,18 +368,18 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) | |||
379 | 368 | ||
380 | p->cfg = GNUNET_CONFIGURATION_create (); | 369 | p->cfg = GNUNET_CONFIGURATION_create (); |
381 | #if START_ARM | 370 | #if START_ARM |
382 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 371 | p->arm_proc = |
383 | "gnunet-service-arm", | 372 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
373 | "gnunet-service-arm", | ||
384 | #if VERBOSE | 374 | #if VERBOSE |
385 | "-L", "DEBUG", | 375 | "-L", "DEBUG", |
386 | #endif | 376 | #endif |
387 | "-c", cfgname, NULL); | 377 | "-c", cfgname, NULL); |
388 | #endif | 378 | #endif |
389 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 379 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
390 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, | 380 | if (GNUNET_OK == |
391 | "HOSTLIST", | 381 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE", |
392 | "HOSTLISTFILE", | 382 | &filename)) |
393 | &filename)) | ||
394 | { | 383 | { |
395 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 384 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
396 | { | 385 | { |
@@ -401,13 +390,9 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) | |||
401 | } | 390 | } |
402 | GNUNET_free (filename); | 391 | GNUNET_free (filename); |
403 | } | 392 | } |
404 | p->core = GNUNET_CORE_connect (p->cfg, | 393 | p->core = |
405 | 1, | 394 | GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, NULL, |
406 | NULL, | 395 | GNUNET_NO, NULL, GNUNET_NO, learn_handlers); |
407 | NULL, | ||
408 | NULL, NULL, NULL, | ||
409 | NULL, GNUNET_NO, | ||
410 | NULL, GNUNET_NO, learn_handlers); | ||
411 | GNUNET_assert (NULL != p->core); | 396 | GNUNET_assert (NULL != p->core); |
412 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 397 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
413 | GNUNET_assert (NULL != p->stats); | 398 | GNUNET_assert (NULL != p->stats); |
@@ -419,12 +404,13 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname) | |||
419 | { | 404 | { |
420 | p->cfg = GNUNET_CONFIGURATION_create (); | 405 | p->cfg = GNUNET_CONFIGURATION_create (); |
421 | #if START_ARM | 406 | #if START_ARM |
422 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 407 | p->arm_proc = |
423 | "gnunet-service-arm", | 408 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
409 | "gnunet-service-arm", | ||
424 | #if VERBOSE | 410 | #if VERBOSE |
425 | "-L", "DEBUG", | 411 | "-L", "DEBUG", |
426 | #endif | 412 | #endif |
427 | "-c", cfgname, NULL); | 413 | "-c", cfgname, NULL); |
428 | #endif | 414 | #endif |
429 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 415 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
430 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 416 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
@@ -433,9 +419,8 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname) | |||
433 | 419 | ||
434 | 420 | ||
435 | static void | 421 | static void |
436 | run (void *cls, | 422 | run (void *cls, char *const *args, const char *cfgfile, |
437 | char *const *args, | 423 | const struct GNUNET_CONFIGURATION_Handle *c) |
438 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | ||
439 | { | 424 | { |
440 | timeout = GNUNET_NO; | 425 | timeout = GNUNET_NO; |
441 | adv_sent = GNUNET_NO; | 426 | adv_sent = GNUNET_NO; |
@@ -450,8 +435,8 @@ run (void *cls, | |||
450 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); | 435 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); |
451 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); | 436 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
452 | 437 | ||
453 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 438 | check_task = |
454 | &check_statistics, NULL); | 439 | GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL); |
455 | } | 440 | } |
456 | 441 | ||
457 | 442 | ||
@@ -472,9 +457,9 @@ check () | |||
472 | GNUNET_GETOPT_OPTION_END | 457 | GNUNET_GETOPT_OPTION_END |
473 | }; | 458 | }; |
474 | 459 | ||
475 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 460 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
476 | argv, "test-gnunet-daemon-hostlist-learning", | 461 | "test-gnunet-daemon-hostlist-learning", "nohelp", options, |
477 | "nohelp", options, &run, NULL); | 462 | &run, NULL); |
478 | failed = GNUNET_NO; | 463 | failed = GNUNET_NO; |
479 | if (timeout == GNUNET_YES) | 464 | if (timeout == GNUNET_YES) |
480 | { | 465 | { |