diff options
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-nse-profiler.c | 640 | ||||
-rw-r--r-- | src/nse/gnunet-nse.c | 70 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 1280 | ||||
-rw-r--r-- | src/nse/nse.h | 3 | ||||
-rw-r--r-- | src/nse/nse_api.c | 91 | ||||
-rw-r--r-- | src/nse/perf_kdf.c | 48 | ||||
-rw-r--r-- | src/nse/test_nse_api.c | 52 | ||||
-rw-r--r-- | src/nse/test_nse_multipeer.c | 115 |
8 files changed, 1154 insertions, 1145 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index eaa06b8ed..c97798772 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c | |||
@@ -36,18 +36,19 @@ | |||
36 | /** | 36 | /** |
37 | * Generic loggins shorthand | 37 | * Generic loggins shorthand |
38 | */ | 38 | */ |
39 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Debug logging shorthand | 42 | * Debug logging shorthand |
43 | */ | 43 | */ |
44 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Information we track for a peer in the testbed. | 48 | * Information we track for a peer in the testbed. |
49 | */ | 49 | */ |
50 | struct NSEPeer { | 50 | struct NSEPeer |
51 | { | ||
51 | /** | 52 | /** |
52 | * Prev reference in DLL. | 53 | * Prev reference in DLL. |
53 | */ | 54 | */ |
@@ -83,7 +84,8 @@ struct NSEPeer { | |||
83 | /** | 84 | /** |
84 | * Operation map entry | 85 | * Operation map entry |
85 | */ | 86 | */ |
86 | struct OpListEntry { | 87 | struct OpListEntry |
88 | { | ||
87 | /** | 89 | /** |
88 | * DLL next ptr | 90 | * DLL next ptr |
89 | */ | 91 | */ |
@@ -229,26 +231,26 @@ static struct GNUNET_SCHEDULER_Task *round_task; | |||
229 | * STATISTICS that we keep to selected peers. | 231 | * STATISTICS that we keep to selected peers. |
230 | */ | 232 | */ |
231 | static void | 233 | static void |
232 | close_monitor_connections() | 234 | close_monitor_connections () |
233 | { | 235 | { |
234 | struct NSEPeer *pos; | 236 | struct NSEPeer *pos; |
235 | struct OpListEntry *oplist_entry; | 237 | struct OpListEntry *oplist_entry; |
236 | 238 | ||
237 | while (NULL != (pos = peer_head)) | 239 | while (NULL != (pos = peer_head)) |
238 | { | 240 | { |
239 | if (NULL != pos->nse_op) | 241 | if (NULL != pos->nse_op) |
240 | GNUNET_TESTBED_operation_done(pos->nse_op); | 242 | GNUNET_TESTBED_operation_done (pos->nse_op); |
241 | if (NULL != pos->stat_op) | 243 | if (NULL != pos->stat_op) |
242 | GNUNET_TESTBED_operation_done(pos->stat_op); | 244 | GNUNET_TESTBED_operation_done (pos->stat_op); |
243 | GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); | 245 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos); |
244 | GNUNET_free(pos); | 246 | GNUNET_free (pos); |
245 | } | 247 | } |
246 | while (NULL != (oplist_entry = oplist_head)) | 248 | while (NULL != (oplist_entry = oplist_head)) |
247 | { | 249 | { |
248 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, oplist_entry); | 250 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry); |
249 | GNUNET_TESTBED_operation_done(oplist_entry->op); | 251 | GNUNET_TESTBED_operation_done (oplist_entry->op); |
250 | GNUNET_free(oplist_entry); | 252 | GNUNET_free (oplist_entry); |
251 | } | 253 | } |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
@@ -258,30 +260,30 @@ close_monitor_connections() | |||
258 | * @param cls unused | 260 | * @param cls unused |
259 | */ | 261 | */ |
260 | static void | 262 | static void |
261 | shutdown_task(void *cls) | 263 | shutdown_task (void *cls) |
262 | { | 264 | { |
263 | LOG_DEBUG("Ending test.\n"); | 265 | LOG_DEBUG ("Ending test.\n"); |
264 | close_monitor_connections(); | 266 | close_monitor_connections (); |
265 | if (NULL != round_task) | 267 | if (NULL != round_task) |
266 | { | 268 | { |
267 | GNUNET_SCHEDULER_cancel(round_task); | 269 | GNUNET_SCHEDULER_cancel (round_task); |
268 | round_task = NULL; | 270 | round_task = NULL; |
269 | } | 271 | } |
270 | if (NULL != data_file) | 272 | if (NULL != data_file) |
271 | { | 273 | { |
272 | GNUNET_DISK_file_close(data_file); | 274 | GNUNET_DISK_file_close (data_file); |
273 | data_file = NULL; | 275 | data_file = NULL; |
274 | } | 276 | } |
275 | if (NULL != output_file) | 277 | if (NULL != output_file) |
276 | { | 278 | { |
277 | GNUNET_DISK_file_close(output_file); | 279 | GNUNET_DISK_file_close (output_file); |
278 | output_file = NULL; | 280 | output_file = NULL; |
279 | } | 281 | } |
280 | if (NULL != testing_cfg) | 282 | if (NULL != testing_cfg) |
281 | { | 283 | { |
282 | GNUNET_CONFIGURATION_destroy(testing_cfg); | 284 | GNUNET_CONFIGURATION_destroy (testing_cfg); |
283 | testing_cfg = NULL; | 285 | testing_cfg = NULL; |
284 | } | 286 | } |
285 | } | 287 | } |
286 | 288 | ||
287 | 289 | ||
@@ -295,35 +297,35 @@ shutdown_task(void *cls) | |||
295 | * of the size estimation values seen | 297 | * of the size estimation values seen |
296 | */ | 298 | */ |
297 | static void | 299 | static void |
298 | handle_estimate(void *cls, | 300 | handle_estimate (void *cls, |
299 | struct GNUNET_TIME_Absolute timestamp, | 301 | struct GNUNET_TIME_Absolute timestamp, |
300 | double estimate, | 302 | double estimate, |
301 | double std_dev) | 303 | double std_dev) |
302 | { | 304 | { |
303 | struct NSEPeer *peer = cls; | 305 | struct NSEPeer *peer = cls; |
304 | char output_buffer[512]; | 306 | char output_buffer[512]; |
305 | size_t size; | 307 | size_t size; |
306 | 308 | ||
307 | if (NULL == output_file) | 309 | if (NULL == output_file) |
308 | { | 310 | { |
309 | fprintf(stderr, | 311 | fprintf (stderr, |
310 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", | 312 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", |
311 | peer, | 313 | peer, |
312 | estimate, | 314 | estimate, |
313 | std_dev); | 315 | std_dev); |
314 | return; | 316 | return; |
315 | } | 317 | } |
316 | size = GNUNET_snprintf(output_buffer, | 318 | size = GNUNET_snprintf (output_buffer, |
317 | sizeof(output_buffer), | 319 | sizeof(output_buffer), |
318 | "%p %llu %llu %f %f %f\n", | 320 | "%p %llu %llu %f %f %f\n", |
319 | peer, | 321 | peer, |
320 | peers_running, | 322 | peers_running, |
321 | (unsigned long long)timestamp.abs_value_us, | 323 | (unsigned long long) timestamp.abs_value_us, |
322 | GNUNET_NSE_log_estimate_to_n(estimate), | 324 | GNUNET_NSE_log_estimate_to_n (estimate), |
323 | estimate, | 325 | estimate, |
324 | std_dev); | 326 | std_dev); |
325 | if (size != GNUNET_DISK_file_write(output_file, output_buffer, size)) | 327 | if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) |
326 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 328 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
327 | } | 329 | } |
328 | 330 | ||
329 | 331 | ||
@@ -338,11 +340,11 @@ handle_estimate(void *cls, | |||
338 | * @return service handle to return in 'op_result', NULL on error | 340 | * @return service handle to return in 'op_result', NULL on error |
339 | */ | 341 | */ |
340 | static void * | 342 | static void * |
341 | nse_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 343 | nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
342 | { | 344 | { |
343 | struct NSEPeer *current_peer = cls; | 345 | struct NSEPeer *current_peer = cls; |
344 | 346 | ||
345 | return GNUNET_NSE_connect(cfg, &handle_estimate, current_peer); | 347 | return GNUNET_NSE_connect (cfg, &handle_estimate, current_peer); |
346 | } | 348 | } |
347 | 349 | ||
348 | 350 | ||
@@ -354,9 +356,9 @@ nse_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
354 | * @param op_result service handle returned from the connect adapter | 356 | * @param op_result service handle returned from the connect adapter |
355 | */ | 357 | */ |
356 | static void | 358 | static void |
357 | nse_disconnect_adapter(void *cls, void *op_result) | 359 | nse_disconnect_adapter (void *cls, void *op_result) |
358 | { | 360 | { |
359 | GNUNET_NSE_disconnect(op_result); | 361 | GNUNET_NSE_disconnect (op_result); |
360 | } | 362 | } |
361 | 363 | ||
362 | 364 | ||
@@ -371,40 +373,40 @@ nse_disconnect_adapter(void *cls, void *op_result) | |||
371 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 373 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
372 | */ | 374 | */ |
373 | static int | 375 | static int |
374 | stat_iterator(void *cls, | 376 | stat_iterator (void *cls, |
375 | const char *subsystem, | 377 | const char *subsystem, |
376 | const char *name, | 378 | const char *name, |
377 | uint64_t value, | 379 | uint64_t value, |
378 | int is_persistent) | 380 | int is_persistent) |
379 | { | 381 | { |
380 | char *output_buffer; | 382 | char *output_buffer; |
381 | struct GNUNET_TIME_Absolute now; | 383 | struct GNUNET_TIME_Absolute now; |
382 | int size; | 384 | int size; |
383 | unsigned int flag; | 385 | unsigned int flag; |
384 | 386 | ||
385 | GNUNET_assert(NULL != data_file); | 387 | GNUNET_assert (NULL != data_file); |
386 | now = GNUNET_TIME_absolute_get(); | 388 | now = GNUNET_TIME_absolute_get (); |
387 | flag = strcasecmp(subsystem, "core"); | 389 | flag = strcasecmp (subsystem, "core"); |
388 | if (0 != flag) | 390 | if (0 != flag) |
389 | flag = 1; | 391 | flag = 1; |
390 | size = GNUNET_asprintf(&output_buffer, | 392 | size = GNUNET_asprintf (&output_buffer, |
391 | "%llu %llu %u\n", | 393 | "%llu %llu %u\n", |
392 | now.abs_value_us / 1000LL / 1000LL, | 394 | now.abs_value_us / 1000LL / 1000LL, |
393 | value, | 395 | value, |
394 | flag); | 396 | flag); |
395 | if (0 > size) | 397 | if (0 > size) |
396 | { | 398 | { |
397 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); |
398 | GNUNET_free(output_buffer); | 400 | GNUNET_free (output_buffer); |
399 | return GNUNET_SYSERR; | 401 | return GNUNET_SYSERR; |
400 | } | 402 | } |
401 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, (size_t)size)) | 403 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size)) |
402 | { | 404 | { |
403 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
404 | GNUNET_free(output_buffer); | 406 | GNUNET_free (output_buffer); |
405 | return GNUNET_SYSERR; | 407 | return GNUNET_SYSERR; |
406 | } | 408 | } |
407 | GNUNET_free(output_buffer); | 409 | GNUNET_free (output_buffer); |
408 | return GNUNET_OK; | 410 | return GNUNET_OK; |
409 | } | 411 | } |
410 | 412 | ||
@@ -419,11 +421,11 @@ stat_iterator(void *cls, | |||
419 | * @return service handle to return in 'op_result', NULL on error | 421 | * @return service handle to return in 'op_result', NULL on error |
420 | */ | 422 | */ |
421 | static void * | 423 | static void * |
422 | stat_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 424 | stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
423 | { | 425 | { |
424 | struct NSEPeer *peer = cls; | 426 | struct NSEPeer *peer = cls; |
425 | 427 | ||
426 | peer->sh = GNUNET_STATISTICS_create("nse-profiler", cfg); | 428 | peer->sh = GNUNET_STATISTICS_create ("nse-profiler", cfg); |
427 | return peer->sh; | 429 | return peer->sh; |
428 | } | 430 | } |
429 | 431 | ||
@@ -435,23 +437,23 @@ stat_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
435 | * @param op_result service handle returned from the connect adapter | 437 | * @param op_result service handle returned from the connect adapter |
436 | */ | 438 | */ |
437 | static void | 439 | static void |
438 | stat_disconnect_adapter(void *cls, void *op_result) | 440 | stat_disconnect_adapter (void *cls, void *op_result) |
439 | { | 441 | { |
440 | struct NSEPeer *peer = cls; | 442 | struct NSEPeer *peer = cls; |
441 | 443 | ||
442 | GNUNET_break(GNUNET_OK == | 444 | GNUNET_break (GNUNET_OK == |
443 | GNUNET_STATISTICS_watch_cancel(peer->sh, | 445 | GNUNET_STATISTICS_watch_cancel (peer->sh, |
444 | "core", | 446 | "core", |
445 | "# peers connected", | 447 | "# peers connected", |
446 | stat_iterator, | 448 | stat_iterator, |
447 | peer)); | 449 | peer)); |
448 | GNUNET_break(GNUNET_OK == | 450 | GNUNET_break (GNUNET_OK == |
449 | GNUNET_STATISTICS_watch_cancel(peer->sh, | 451 | GNUNET_STATISTICS_watch_cancel (peer->sh, |
450 | "nse", | 452 | "nse", |
451 | "# peers connected", | 453 | "# peers connected", |
452 | stat_iterator, | 454 | stat_iterator, |
453 | peer)); | 455 | peer)); |
454 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); | 456 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); |
455 | peer->sh = NULL; | 457 | peer->sh = NULL; |
456 | } | 458 | } |
457 | 459 | ||
@@ -467,29 +469,29 @@ stat_disconnect_adapter(void *cls, void *op_result) | |||
467 | * operation has executed successfully. | 469 | * operation has executed successfully. |
468 | */ | 470 | */ |
469 | static void | 471 | static void |
470 | stat_comp_cb(void *cls, | 472 | stat_comp_cb (void *cls, |
471 | struct GNUNET_TESTBED_Operation *op, | 473 | struct GNUNET_TESTBED_Operation *op, |
472 | void *ca_result, | 474 | void *ca_result, |
473 | const char *emsg) | 475 | const char *emsg) |
474 | { | 476 | { |
475 | struct GNUNET_STATISTICS_Handle *sh = ca_result; | 477 | struct GNUNET_STATISTICS_Handle *sh = ca_result; |
476 | struct NSEPeer *peer = cls; | 478 | struct NSEPeer *peer = cls; |
477 | 479 | ||
478 | if (NULL != emsg) | 480 | if (NULL != emsg) |
479 | { | 481 | { |
480 | GNUNET_break(0); | 482 | GNUNET_break (0); |
481 | return; | 483 | return; |
482 | } | 484 | } |
483 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, | 485 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, |
484 | "core", | 486 | "core", |
485 | "# peers connected", | 487 | "# peers connected", |
486 | stat_iterator, | 488 | stat_iterator, |
487 | peer)); | 489 | peer)); |
488 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, | 490 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, |
489 | "nse", | 491 | "nse", |
490 | "# peers connected", | 492 | "# peers connected", |
491 | stat_iterator, | 493 | stat_iterator, |
492 | peer)); | 494 | peer)); |
493 | } | 495 | } |
494 | 496 | ||
495 | 497 | ||
@@ -498,7 +500,7 @@ stat_comp_cb(void *cls, | |||
498 | * all of the running peers. | 500 | * all of the running peers. |
499 | */ | 501 | */ |
500 | static void | 502 | static void |
501 | connect_nse_service() | 503 | connect_nse_service () |
502 | { | 504 | { |
503 | struct NSEPeer *current_peer; | 505 | struct NSEPeer *current_peer; |
504 | unsigned int i; | 506 | unsigned int i; |
@@ -506,39 +508,39 @@ connect_nse_service() | |||
506 | 508 | ||
507 | if (0 == connection_limit) | 509 | if (0 == connection_limit) |
508 | return; | 510 | return; |
509 | LOG_DEBUG("Connecting to nse service of peers\n"); | 511 | LOG_DEBUG ("Connecting to nse service of peers\n"); |
510 | connections = 0; | 512 | connections = 0; |
511 | for (i = 0; i < num_peers_in_round[current_round]; i++) | 513 | for (i = 0; i < num_peers_in_round[current_round]; i++) |
512 | { | 514 | { |
513 | if ((num_peers_in_round[current_round] > connection_limit) && | 515 | if ((num_peers_in_round[current_round] > connection_limit) && |
514 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) | 516 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) |
515 | continue; | 517 | continue; |
516 | LOG_DEBUG("Connecting to nse service of peer %d\n", i); | 518 | LOG_DEBUG ("Connecting to nse service of peer %d\n", i); |
517 | current_peer = GNUNET_new(struct NSEPeer); | 519 | current_peer = GNUNET_new (struct NSEPeer); |
518 | current_peer->daemon = daemons[i]; | 520 | current_peer->daemon = daemons[i]; |
519 | current_peer->nse_op = | 521 | current_peer->nse_op = |
520 | GNUNET_TESTBED_service_connect(NULL, | 522 | GNUNET_TESTBED_service_connect (NULL, |
521 | current_peer->daemon, | 523 | current_peer->daemon, |
522 | "nse", | 524 | "nse", |
523 | NULL, | 525 | NULL, |
524 | NULL, | 526 | NULL, |
525 | &nse_connect_adapter, | 527 | &nse_connect_adapter, |
526 | &nse_disconnect_adapter, | 528 | &nse_disconnect_adapter, |
527 | current_peer); | 529 | current_peer); |
528 | if (NULL != data_file) | 530 | if (NULL != data_file) |
529 | current_peer->stat_op = | 531 | current_peer->stat_op = |
530 | GNUNET_TESTBED_service_connect(NULL, | 532 | GNUNET_TESTBED_service_connect (NULL, |
531 | current_peer->daemon, | 533 | current_peer->daemon, |
532 | "statistics", | 534 | "statistics", |
533 | stat_comp_cb, | 535 | stat_comp_cb, |
534 | current_peer, | 536 | current_peer, |
535 | &stat_connect_adapter, | 537 | &stat_connect_adapter, |
536 | &stat_disconnect_adapter, | 538 | &stat_disconnect_adapter, |
537 | current_peer); | 539 | current_peer); |
538 | GNUNET_CONTAINER_DLL_insert(peer_head, peer_tail, current_peer); | 540 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); |
539 | if (++connections == connection_limit) | 541 | if (++connections == connection_limit) |
540 | break; | 542 | break; |
541 | } | 543 | } |
542 | } | 544 | } |
543 | 545 | ||
544 | 546 | ||
@@ -548,7 +550,7 @@ connect_nse_service() | |||
548 | * @param cls NULL, unused | 550 | * @param cls NULL, unused |
549 | */ | 551 | */ |
550 | static void | 552 | static void |
551 | next_round(void *cls); | 553 | next_round (void *cls); |
552 | 554 | ||
553 | 555 | ||
554 | /** | 556 | /** |
@@ -559,11 +561,11 @@ next_round(void *cls); | |||
559 | * @param cls unused, NULL | 561 | * @param cls unused, NULL |
560 | */ | 562 | */ |
561 | static void | 563 | static void |
562 | finish_round(void *cls) | 564 | finish_round (void *cls) |
563 | { | 565 | { |
564 | LOG(GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); | 566 | LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); |
565 | close_monitor_connections(); | 567 | close_monitor_connections (); |
566 | round_task = GNUNET_SCHEDULER_add_now(&next_round, NULL); | 568 | round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL); |
567 | } | 569 | } |
568 | 570 | ||
569 | 571 | ||
@@ -573,11 +575,11 @@ finish_round(void *cls) | |||
573 | * specified delay before finishing the round). | 575 | * specified delay before finishing the round). |
574 | */ | 576 | */ |
575 | static void | 577 | static void |
576 | run_round() | 578 | run_round () |
577 | { | 579 | { |
578 | LOG_DEBUG("Running round %u\n", current_round); | 580 | LOG_DEBUG ("Running round %u\n", current_round); |
579 | connect_nse_service(); | 581 | connect_nse_service (); |
580 | GNUNET_SCHEDULER_add_delayed(wait_time, &finish_round, NULL); | 582 | GNUNET_SCHEDULER_add_delayed (wait_time, &finish_round, NULL); |
581 | } | 583 | } |
582 | 584 | ||
583 | 585 | ||
@@ -585,12 +587,12 @@ run_round() | |||
585 | * Creates an oplist entry and adds it to the oplist DLL | 587 | * Creates an oplist entry and adds it to the oplist DLL |
586 | */ | 588 | */ |
587 | static struct OpListEntry * | 589 | static struct OpListEntry * |
588 | make_oplist_entry() | 590 | make_oplist_entry () |
589 | { | 591 | { |
590 | struct OpListEntry *entry; | 592 | struct OpListEntry *entry; |
591 | 593 | ||
592 | entry = GNUNET_new(struct OpListEntry); | 594 | entry = GNUNET_new (struct OpListEntry); |
593 | GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); | 595 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); |
594 | return entry; | 596 | return entry; |
595 | } | 597 | } |
596 | 598 | ||
@@ -603,25 +605,25 @@ make_oplist_entry() | |||
603 | * @param emsg NULL on success; otherwise an error description | 605 | * @param emsg NULL on success; otherwise an error description |
604 | */ | 606 | */ |
605 | static void | 607 | static void |
606 | manage_service_cb(void *cls, | 608 | manage_service_cb (void *cls, |
607 | struct GNUNET_TESTBED_Operation *op, | 609 | struct GNUNET_TESTBED_Operation *op, |
608 | const char *emsg) | 610 | const char *emsg) |
609 | { | 611 | { |
610 | struct OpListEntry *entry = cls; | 612 | struct OpListEntry *entry = cls; |
611 | 613 | ||
612 | GNUNET_TESTBED_operation_done(entry->op); | 614 | GNUNET_TESTBED_operation_done (entry->op); |
613 | if (NULL != emsg) | 615 | if (NULL != emsg) |
614 | { | 616 | { |
615 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); | 617 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); |
616 | GNUNET_SCHEDULER_shutdown(); | 618 | GNUNET_SCHEDULER_shutdown (); |
617 | return; | 619 | return; |
618 | } | 620 | } |
619 | GNUNET_assert(0 != entry->delta); | 621 | GNUNET_assert (0 != entry->delta); |
620 | peers_running += entry->delta; | 622 | peers_running += entry->delta; |
621 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); | 623 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); |
622 | GNUNET_free(entry); | 624 | GNUNET_free (entry); |
623 | if (num_peers_in_round[current_round] == peers_running) | 625 | if (num_peers_in_round[current_round] == peers_running) |
624 | run_round(); | 626 | run_round (); |
625 | } | 627 | } |
626 | 628 | ||
627 | 629 | ||
@@ -630,35 +632,35 @@ manage_service_cb(void *cls, | |||
630 | * peers for the round | 632 | * peers for the round |
631 | */ | 633 | */ |
632 | static void | 634 | static void |
633 | adjust_running_peers() | 635 | adjust_running_peers () |
634 | { | 636 | { |
635 | struct OpListEntry *entry; | 637 | struct OpListEntry *entry; |
636 | unsigned int i; | 638 | unsigned int i; |
637 | 639 | ||
638 | /* start peers if we have too few */ | 640 | /* start peers if we have too few */ |
639 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) | 641 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) |
640 | { | 642 | { |
641 | entry = make_oplist_entry(); | 643 | entry = make_oplist_entry (); |
642 | entry->delta = 1; | 644 | entry->delta = 1; |
643 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, | 645 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, |
644 | daemons[i], | 646 | daemons[i], |
645 | "nse", | 647 | "nse", |
646 | &manage_service_cb, | 648 | &manage_service_cb, |
647 | entry, | 649 | entry, |
648 | 1); | 650 | 1); |
649 | } | 651 | } |
650 | /* stop peers if we have too many */ | 652 | /* stop peers if we have too many */ |
651 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) | 653 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) |
652 | { | 654 | { |
653 | entry = make_oplist_entry(); | 655 | entry = make_oplist_entry (); |
654 | entry->delta = -1; | 656 | entry->delta = -1; |
655 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, | 657 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, |
656 | daemons[i], | 658 | daemons[i], |
657 | "nse", | 659 | "nse", |
658 | &manage_service_cb, | 660 | &manage_service_cb, |
659 | entry, | 661 | entry, |
660 | 0); | 662 | 0); |
661 | } | 663 | } |
662 | } | 664 | } |
663 | 665 | ||
664 | 666 | ||
@@ -669,25 +671,25 @@ adjust_running_peers() | |||
669 | * @param cls NULL, unused | 671 | * @param cls NULL, unused |
670 | */ | 672 | */ |
671 | static void | 673 | static void |
672 | next_round(void *cls) | 674 | next_round (void *cls) |
673 | { | 675 | { |
674 | round_task = NULL; | 676 | round_task = NULL; |
675 | LOG_DEBUG("Disconnecting nse service of peers\n"); | 677 | LOG_DEBUG ("Disconnecting nse service of peers\n"); |
676 | current_round++; | 678 | current_round++; |
677 | if (current_round == num_rounds) | 679 | if (current_round == num_rounds) |
678 | { | 680 | { |
679 | /* this was the last round, terminate */ | 681 | /* this was the last round, terminate */ |
680 | ok = 0; | 682 | ok = 0; |
681 | GNUNET_SCHEDULER_shutdown(); | 683 | GNUNET_SCHEDULER_shutdown (); |
682 | return; | 684 | return; |
683 | } | 685 | } |
684 | if (num_peers_in_round[current_round] == peers_running) | 686 | if (num_peers_in_round[current_round] == peers_running) |
685 | { | 687 | { |
686 | /* no need to churn, just run next round */ | 688 | /* no need to churn, just run next round */ |
687 | run_round(); | 689 | run_round (); |
688 | return; | 690 | return; |
689 | } | 691 | } |
690 | adjust_running_peers(); | 692 | adjust_running_peers (); |
691 | } | 693 | } |
692 | 694 | ||
693 | 695 | ||
@@ -699,22 +701,22 @@ next_round(void *cls) | |||
699 | * @param event information on what is happening | 701 | * @param event information on what is happening |
700 | */ | 702 | */ |
701 | static void | 703 | static void |
702 | master_controller_cb(void *cls, | 704 | master_controller_cb (void *cls, |
703 | const struct GNUNET_TESTBED_EventInformation *event) | 705 | const struct GNUNET_TESTBED_EventInformation *event) |
704 | { | 706 | { |
705 | switch (event->type) | 707 | switch (event->type) |
706 | { | 708 | { |
707 | case GNUNET_TESTBED_ET_CONNECT: | 709 | case GNUNET_TESTBED_ET_CONNECT: |
708 | total_connections++; | 710 | total_connections++; |
709 | break; | 711 | break; |
710 | 712 | ||
711 | case GNUNET_TESTBED_ET_DISCONNECT: | 713 | case GNUNET_TESTBED_ET_DISCONNECT: |
712 | total_connections--; | 714 | total_connections--; |
713 | break; | 715 | break; |
714 | 716 | ||
715 | default: | 717 | default: |
716 | break; | 718 | break; |
717 | } | 719 | } |
718 | } | 720 | } |
719 | 721 | ||
720 | 722 | ||
@@ -732,28 +734,28 @@ master_controller_cb(void *cls, | |||
732 | * failed | 734 | * failed |
733 | */ | 735 | */ |
734 | static void | 736 | static void |
735 | test_master(void *cls, | 737 | test_master (void *cls, |
736 | struct GNUNET_TESTBED_RunHandle *h, | 738 | struct GNUNET_TESTBED_RunHandle *h, |
737 | unsigned int num_peers_, | 739 | unsigned int num_peers_, |
738 | struct GNUNET_TESTBED_Peer **peers, | 740 | struct GNUNET_TESTBED_Peer **peers, |
739 | unsigned int links_succeeded, | 741 | unsigned int links_succeeded, |
740 | unsigned int links_failed) | 742 | unsigned int links_failed) |
741 | { | 743 | { |
742 | if (NULL == peers) | 744 | if (NULL == peers) |
743 | { | 745 | { |
744 | GNUNET_SCHEDULER_shutdown(); | 746 | GNUNET_SCHEDULER_shutdown (); |
745 | return; | 747 | return; |
746 | } | 748 | } |
747 | daemons = peers; | 749 | daemons = peers; |
748 | GNUNET_break(num_peers_ == num_peers); | 750 | GNUNET_break (num_peers_ == num_peers); |
749 | peers_running = num_peers; | 751 | peers_running = num_peers; |
750 | if (num_peers_in_round[current_round] == peers_running) | 752 | if (num_peers_in_round[current_round] == peers_running) |
751 | { | 753 | { |
752 | /* no need to churn, just run the starting round */ | 754 | /* no need to churn, just run the starting round */ |
753 | run_round(); | 755 | run_round (); |
754 | return; | 756 | return; |
755 | } | 757 | } |
756 | adjust_running_peers(); | 758 | adjust_running_peers (); |
757 | } | 759 | } |
758 | 760 | ||
759 | 761 | ||
@@ -766,75 +768,75 @@ test_master(void *cls, | |||
766 | * @param cfg configuration handle | 768 | * @param cfg configuration handle |
767 | */ | 769 | */ |
768 | static void | 770 | static void |
769 | run(void *cls, | 771 | run (void *cls, |
770 | char *const *args, | 772 | char *const *args, |
771 | const char *cfgfile, | 773 | const char *cfgfile, |
772 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 774 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
773 | { | 775 | { |
774 | char *tok; | 776 | char *tok; |
775 | uint64_t event_mask; | 777 | uint64_t event_mask; |
776 | unsigned int num; | 778 | unsigned int num; |
777 | 779 | ||
778 | ok = 1; | 780 | ok = 1; |
779 | testing_cfg = GNUNET_CONFIGURATION_dup(cfg); | 781 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); |
780 | LOG_DEBUG("Starting daemons.\n"); | 782 | LOG_DEBUG ("Starting daemons.\n"); |
781 | if (NULL == num_peer_spec) | 783 | if (NULL == num_peer_spec) |
784 | { | ||
785 | fprintf (stderr, "You need to specify the number of peers to run\n"); | ||
786 | return; | ||
787 | } | ||
788 | for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ",")) | ||
789 | { | ||
790 | if (1 != sscanf (tok, "%u", &num)) | ||
782 | { | 791 | { |
783 | fprintf(stderr, "You need to specify the number of peers to run\n"); | 792 | fprintf (stderr, "You need to specify numbers, not `%s'\n", tok); |
784 | return; | 793 | return; |
785 | } | 794 | } |
786 | for (tok = strtok(num_peer_spec, ","); NULL != tok; tok = strtok(NULL, ",")) | 795 | if (0 == num) |
787 | { | ||
788 | if (1 != sscanf(tok, "%u", &num)) | ||
789 | { | ||
790 | fprintf(stderr, "You need to specify numbers, not `%s'\n", tok); | ||
791 | return; | ||
792 | } | ||
793 | if (0 == num) | ||
794 | { | ||
795 | fprintf(stderr, "Refusing to run a round with 0 peers\n"); | ||
796 | return; | ||
797 | } | ||
798 | GNUNET_array_append(num_peers_in_round, num_rounds, num); | ||
799 | num_peers = GNUNET_MAX(num_peers, num); | ||
800 | } | ||
801 | if (0 == num_peers) | ||
802 | { | 796 | { |
803 | fprintf(stderr, "Refusing to run a testbed with no rounds\n"); | 797 | fprintf (stderr, "Refusing to run a round with 0 peers\n"); |
804 | return; | 798 | return; |
805 | } | 799 | } |
800 | GNUNET_array_append (num_peers_in_round, num_rounds, num); | ||
801 | num_peers = GNUNET_MAX (num_peers, num); | ||
802 | } | ||
803 | if (0 == num_peers) | ||
804 | { | ||
805 | fprintf (stderr, "Refusing to run a testbed with no rounds\n"); | ||
806 | return; | ||
807 | } | ||
806 | if ((NULL != data_filename) && | 808 | if ((NULL != data_filename) && |
807 | (NULL == | 809 | (NULL == |
808 | (data_file = GNUNET_DISK_file_open(data_filename, | 810 | (data_file = GNUNET_DISK_file_open (data_filename, |
809 | GNUNET_DISK_OPEN_READWRITE | | 811 | GNUNET_DISK_OPEN_READWRITE |
810 | GNUNET_DISK_OPEN_TRUNCATE | | 812 | | GNUNET_DISK_OPEN_TRUNCATE |
811 | GNUNET_DISK_OPEN_CREATE, | 813 | | GNUNET_DISK_OPEN_CREATE, |
812 | GNUNET_DISK_PERM_USER_READ | | 814 | GNUNET_DISK_PERM_USER_READ |
813 | GNUNET_DISK_PERM_USER_WRITE)))) | 815 | | GNUNET_DISK_PERM_USER_WRITE)))) |
814 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", data_filename); | 816 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", data_filename); |
815 | 817 | ||
816 | if ((NULL != output_filename) && | 818 | if ((NULL != output_filename) && |
817 | (NULL == | 819 | (NULL == |
818 | (output_file = GNUNET_DISK_file_open(output_filename, | 820 | (output_file = GNUNET_DISK_file_open (output_filename, |
819 | GNUNET_DISK_OPEN_READWRITE | | 821 | GNUNET_DISK_OPEN_READWRITE |
820 | GNUNET_DISK_OPEN_CREATE, | 822 | | GNUNET_DISK_OPEN_CREATE, |
821 | GNUNET_DISK_PERM_USER_READ | | 823 | GNUNET_DISK_PERM_USER_READ |
822 | GNUNET_DISK_PERM_USER_WRITE)))) | 824 | | GNUNET_DISK_PERM_USER_WRITE)))) |
823 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", output_filename); | 825 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", output_filename); |
824 | event_mask = 0LL; | 826 | event_mask = 0LL; |
825 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 827 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
826 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 828 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
827 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 829 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
828 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | 830 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); |
829 | GNUNET_TESTBED_run(hosts_file, | 831 | GNUNET_TESTBED_run (hosts_file, |
830 | cfg, | 832 | cfg, |
831 | num_peers, | 833 | num_peers, |
832 | event_mask, | 834 | event_mask, |
833 | master_controller_cb, | 835 | master_controller_cb, |
834 | NULL, /* master_controller_cb cls */ | 836 | NULL, /* master_controller_cb cls */ |
835 | &test_master, | 837 | &test_master, |
836 | NULL); /* test_master cls */ | 838 | NULL); /* test_master cls */ |
837 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 839 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
838 | } | 840 | } |
839 | 841 | ||
840 | 842 | ||
@@ -844,73 +846,73 @@ run(void *cls, | |||
844 | * @return 0 on success | 846 | * @return 0 on success |
845 | */ | 847 | */ |
846 | int | 848 | int |
847 | main(int argc, char *const *argv) | 849 | main (int argc, char *const *argv) |
848 | { | 850 | { |
849 | struct GNUNET_GETOPT_CommandLineOption options[] = | 851 | struct GNUNET_GETOPT_CommandLineOption options[] = |
850 | { GNUNET_GETOPT_option_uint( | 852 | { GNUNET_GETOPT_option_uint ( |
851 | 'C', | 853 | 'C', |
852 | "connections", | 854 | "connections", |
853 | "COUNT", | 855 | "COUNT", |
854 | gettext_noop( | 856 | gettext_noop ( |
855 | "limit to the number of connections to NSE services, 0 for none"), | 857 | "limit to the number of connections to NSE services, 0 for none"), |
856 | &connection_limit), | 858 | &connection_limit), |
857 | GNUNET_GETOPT_option_string( | 859 | GNUNET_GETOPT_option_string ( |
858 | 'd', | 860 | 'd', |
859 | "details", | 861 | "details", |
860 | "FILENAME", | 862 | "FILENAME", |
861 | gettext_noop( | 863 | gettext_noop ( |
862 | "name of the file for writing connection information and statistics"), | 864 | "name of the file for writing connection information and statistics"), |
863 | &data_filename), | 865 | &data_filename), |
864 | 866 | ||
865 | GNUNET_GETOPT_option_string( | 867 | GNUNET_GETOPT_option_string ( |
866 | 'H', | 868 | 'H', |
867 | "hosts", | 869 | "hosts", |
868 | "FILENAME", | 870 | "FILENAME", |
869 | gettext_noop( | 871 | gettext_noop ( |
870 | "name of the file with the login information for the testbed"), | 872 | "name of the file with the login information for the testbed"), |
871 | &hosts_file), | 873 | &hosts_file), |
872 | 874 | ||
873 | GNUNET_GETOPT_option_string( | 875 | GNUNET_GETOPT_option_string ( |
874 | 'o', | 876 | 'o', |
875 | "output", | 877 | "output", |
876 | "FILENAME", | 878 | "FILENAME", |
877 | gettext_noop("name of the file for writing the main results"), | 879 | gettext_noop ("name of the file for writing the main results"), |
878 | &output_filename), | 880 | &output_filename), |
879 | 881 | ||
880 | 882 | ||
881 | GNUNET_GETOPT_option_string( | 883 | GNUNET_GETOPT_option_string ( |
882 | 'p', | 884 | 'p', |
883 | "peers", | 885 | "peers", |
884 | "NETWORKSIZESPEC", | 886 | "NETWORKSIZESPEC", |
885 | gettext_noop( | 887 | gettext_noop ( |
886 | "Number of peers to run in each round, separated by commas"), | 888 | "Number of peers to run in each round, separated by commas"), |
887 | &num_peer_spec), | 889 | &num_peer_spec), |
888 | 890 | ||
889 | GNUNET_GETOPT_option_increment_uint( | 891 | GNUNET_GETOPT_option_increment_uint ( |
890 | 'V', | 892 | 'V', |
891 | "verbose", | 893 | "verbose", |
892 | gettext_noop("be verbose (print progress information)"), | 894 | gettext_noop ("be verbose (print progress information)"), |
893 | &verbose), | 895 | &verbose), |
894 | 896 | ||
895 | GNUNET_GETOPT_option_relative_time('w', | 897 | GNUNET_GETOPT_option_relative_time ('w', |
896 | "wait", | 898 | "wait", |
897 | "DELAY", | 899 | "DELAY", |
898 | gettext_noop("delay between rounds"), | 900 | gettext_noop ("delay between rounds"), |
899 | &wait_time), | 901 | &wait_time), |
900 | GNUNET_GETOPT_OPTION_END }; | 902 | GNUNET_GETOPT_OPTION_END }; |
901 | 903 | ||
902 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 904 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
903 | return 2; | 905 | return 2; |
904 | if ( | 906 | if ( |
905 | GNUNET_OK != | 907 | GNUNET_OK != |
906 | GNUNET_PROGRAM_run(argc, | 908 | GNUNET_PROGRAM_run (argc, |
907 | argv, | 909 | argv, |
908 | "nse-profiler", | 910 | "nse-profiler", |
909 | gettext_noop( | 911 | gettext_noop ( |
910 | "Measure quality and performance of the NSE service."), | 912 | "Measure quality and performance of the NSE service."), |
911 | options, | 913 | options, |
912 | &run, | 914 | &run, |
913 | NULL)) | 915 | NULL)) |
914 | ok = 1; | 916 | ok = 1; |
915 | return ok; | 917 | return ok; |
916 | } | 918 | } |
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c index 3735373b5..edb73c0fc 100644 --- a/src/nse/gnunet-nse.c +++ b/src/nse/gnunet-nse.c | |||
@@ -44,14 +44,14 @@ static int status; | |||
44 | * @param cls NULL | 44 | * @param cls NULL |
45 | */ | 45 | */ |
46 | static void | 46 | static void |
47 | do_shutdown(void *cls) | 47 | do_shutdown (void *cls) |
48 | { | 48 | { |
49 | (void)cls; | 49 | (void) cls; |
50 | if (NULL != nse) | 50 | if (NULL != nse) |
51 | { | 51 | { |
52 | GNUNET_NSE_disconnect(nse); | 52 | GNUNET_NSE_disconnect (nse); |
53 | nse = NULL; | 53 | nse = NULL; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
@@ -65,19 +65,19 @@ do_shutdown(void *cls) | |||
65 | * of the size estimation values seen | 65 | * of the size estimation values seen |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | handle_estimate(void *cls, | 68 | handle_estimate (void *cls, |
69 | struct GNUNET_TIME_Absolute timestamp, | 69 | struct GNUNET_TIME_Absolute timestamp, |
70 | double estimate, | 70 | double estimate, |
71 | double std_dev) | 71 | double std_dev) |
72 | { | 72 | { |
73 | (void)cls; | 73 | (void) cls; |
74 | status = 0; | 74 | status = 0; |
75 | fprintf(stdout, | 75 | fprintf (stdout, |
76 | "%llu %f %f %f\n", | 76 | "%llu %f %f %f\n", |
77 | (unsigned long long)timestamp.abs_value_us, | 77 | (unsigned long long) timestamp.abs_value_us, |
78 | GNUNET_NSE_log_estimate_to_n(estimate), | 78 | GNUNET_NSE_log_estimate_to_n (estimate), |
79 | estimate, | 79 | estimate, |
80 | std_dev); | 80 | std_dev); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
@@ -90,16 +90,16 @@ handle_estimate(void *cls, | |||
90 | * @param cfg configuration handle | 90 | * @param cfg configuration handle |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | run(void *cls, | 93 | run (void *cls, |
94 | char *const *args, | 94 | char *const *args, |
95 | const char *cfgfile, | 95 | const char *cfgfile, |
96 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 96 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
97 | { | 97 | { |
98 | (void)cls; | 98 | (void) cls; |
99 | (void)args; | 99 | (void) args; |
100 | (void)cfgfile; | 100 | (void) cfgfile; |
101 | nse = GNUNET_NSE_connect(cfg, &handle_estimate, NULL); | 101 | nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); |
102 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 102 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
@@ -109,7 +109,7 @@ run(void *cls, | |||
109 | * @return 0 on success | 109 | * @return 0 on success |
110 | */ | 110 | */ |
111 | int | 111 | int |
112 | main(int argc, char *const *argv) | 112 | main (int argc, char *const *argv) |
113 | { | 113 | { |
114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
115 | GNUNET_GETOPT_OPTION_END | 115 | GNUNET_GETOPT_OPTION_END |
@@ -117,14 +117,14 @@ main(int argc, char *const *argv) | |||
117 | 117 | ||
118 | status = 1; | 118 | status = 1; |
119 | if (GNUNET_OK != | 119 | if (GNUNET_OK != |
120 | GNUNET_PROGRAM_run(argc, | 120 | GNUNET_PROGRAM_run (argc, |
121 | argv, | 121 | argv, |
122 | "gnunet-nse", | 122 | "gnunet-nse", |
123 | gettext_noop( | 123 | gettext_noop ( |
124 | "Show network size estimates from NSE service."), | 124 | "Show network size estimates from NSE service."), |
125 | options, | 125 | options, |
126 | &run, | 126 | &run, |
127 | NULL)) | 127 | NULL)) |
128 | return 2; | 128 | return 2; |
129 | return status; | 129 | return status; |
130 | } | 130 | } |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index d71c62541..fe32dc30b 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -72,11 +72,11 @@ | |||
72 | * required. Corking OK. | 72 | * required. Corking OK. |
73 | */ | 73 | */ |
74 | #define NSE_PRIORITY \ | 74 | #define NSE_PRIORITY \ |
75 | (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE | \ | 75 | (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE \ |
76 | GNUNET_MQ_PREF_CORK_ALLOWED) | 76 | | GNUNET_MQ_PREF_CORK_ALLOWED) |
77 | 77 | ||
78 | #if FREEBSD | 78 | #if FREEBSD |
79 | #define log2(a) (log(a) / log(2)) | 79 | #define log2(a) (log (a) / log (2)) |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | /** | 82 | /** |
@@ -117,7 +117,8 @@ static struct GNUNET_BIO_WriteHandle *histogram; | |||
117 | /** | 117 | /** |
118 | * Per-peer information. | 118 | * Per-peer information. |
119 | */ | 119 | */ |
120 | struct NSEPeerEntry { | 120 | struct NSEPeerEntry |
121 | { | ||
121 | /** | 122 | /** |
122 | * Core handle for sending messages to this peer. | 123 | * Core handle for sending messages to this peer. |
123 | */ | 124 | */ |
@@ -166,7 +167,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
166 | * peer's timer has run out before receiving a | 167 | * peer's timer has run out before receiving a |
167 | * valid reply from another peer. | 168 | * valid reply from another peer. |
168 | */ | 169 | */ |
169 | struct GNUNET_NSE_FloodMessage { | 170 | struct GNUNET_NSE_FloodMessage |
171 | { | ||
170 | /** | 172 | /** |
171 | * Type: #GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD | 173 | * Type: #GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD |
172 | */ | 174 | */ |
@@ -317,7 +319,7 @@ static uint64_t my_proof; | |||
317 | * @param em message to fill in | 319 | * @param em message to fill in |
318 | */ | 320 | */ |
319 | static void | 321 | static void |
320 | setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) | 322 | setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) |
321 | { | 323 | { |
322 | double mean; | 324 | double mean; |
323 | double sum; | 325 | double sum; |
@@ -340,19 +342,19 @@ setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) | |||
340 | sumweight = 0.0; | 342 | sumweight = 0.0; |
341 | variance = 0.0; | 343 | variance = 0.0; |
342 | for (unsigned int i = 0; i < estimate_count; i++) | 344 | for (unsigned int i = 0; i < estimate_count; i++) |
343 | { | 345 | { |
344 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; | 346 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
345 | 347 | ||
346 | val = htonl(size_estimate_messages[j].matching_bits); | 348 | val = htonl (size_estimate_messages[j].matching_bits); |
347 | weight = estimate_count + 1 - i; | 349 | weight = estimate_count + 1 - i; |
348 | 350 | ||
349 | temp = weight + sumweight; | 351 | temp = weight + sumweight; |
350 | q = val - mean; | 352 | q = val - mean; |
351 | r = q * weight / temp; | 353 | r = q * weight / temp; |
352 | mean += r; | 354 | mean += r; |
353 | sum += sumweight * q * r; | 355 | sum += sumweight * q * r; |
354 | sumweight = temp; | 356 | sumweight = temp; |
355 | } | 357 | } |
356 | if (estimate_count > 0) | 358 | if (estimate_count > 0) |
357 | variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0); | 359 | variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0); |
358 | #else | 360 | #else |
@@ -366,44 +368,44 @@ setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) | |||
366 | mean = 0.0; | 368 | mean = 0.0; |
367 | 369 | ||
368 | for (unsigned int i = 0; i < estimate_count; i++) | 370 | for (unsigned int i = 0; i < estimate_count; i++) |
369 | { | 371 | { |
370 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; | 372 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
371 | 373 | ||
372 | val = htonl(size_estimate_messages[j].matching_bits); | 374 | val = htonl (size_estimate_messages[j].matching_bits); |
373 | sum += val; | 375 | sum += val; |
374 | vsq += val * val; | 376 | vsq += val * val; |
375 | } | 377 | } |
376 | if (0 != estimate_count) | 378 | if (0 != estimate_count) |
377 | { | 379 | { |
378 | mean = sum / estimate_count; | 380 | mean = sum / estimate_count; |
379 | variance = (vsq - mean * sum) / | 381 | variance = (vsq - mean * sum) |
380 | (estimate_count - 1.0); // terrible for numerical stability... | 382 | / (estimate_count - 1.0); // terrible for numerical stability... |
381 | } | 383 | } |
382 | #endif | 384 | #endif |
383 | if (variance >= 0) | 385 | if (variance >= 0) |
384 | std_dev = sqrt(variance); | 386 | std_dev = sqrt (variance); |
385 | else | 387 | else |
386 | std_dev = variance; /* must be infinity due to estimate_count == 0 */ | 388 | std_dev = variance; /* must be infinity due to estimate_count == 0 */ |
387 | current_std_dev = std_dev; | 389 | current_std_dev = std_dev; |
388 | current_size_estimate = mean; | 390 | current_size_estimate = mean; |
389 | 391 | ||
390 | em->header.size = htons(sizeof(struct GNUNET_NSE_ClientMessage)); | 392 | em->header.size = htons (sizeof(struct GNUNET_NSE_ClientMessage)); |
391 | em->header.type = htons(GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); | 393 | em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); |
392 | em->reserved = htonl(0); | 394 | em->reserved = htonl (0); |
393 | em->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); | 395 | em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
394 | { | 396 | { |
395 | double se = mean - 0.332747; | 397 | double se = mean - 0.332747; |
396 | unsigned int j = GNUNET_CONTAINER_multipeermap_size(peers); | 398 | unsigned int j = GNUNET_CONTAINER_multipeermap_size (peers); |
397 | if (0 == j) | 399 | if (0 == j) |
398 | j = 1; /* Avoid log2(0); can only happen if CORE didn't report | 400 | j = 1; /* Avoid log2(0); can only happen if CORE didn't report |
399 | connection to self yet */ | 401 | connection to self yet */ |
400 | nsize = log2(j); | 402 | nsize = log2 (j); |
401 | em->size_estimate = GNUNET_hton_double(GNUNET_MAX(se, nsize)); | 403 | em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize)); |
402 | em->std_deviation = GNUNET_hton_double(std_dev); | 404 | em->std_deviation = GNUNET_hton_double (std_dev); |
403 | GNUNET_STATISTICS_set(stats, | 405 | GNUNET_STATISTICS_set (stats, |
404 | "# nodes in the network (estimate)", | 406 | "# nodes in the network (estimate)", |
405 | (uint64_t)pow(2, GNUNET_MAX(se, nsize)), | 407 | (uint64_t) pow (2, GNUNET_MAX (se, nsize)), |
406 | GNUNET_NO); | 408 | GNUNET_NO); |
407 | } | 409 | } |
408 | } | 410 | } |
409 | 411 | ||
@@ -418,21 +420,21 @@ setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) | |||
418 | * @param message the message received | 420 | * @param message the message received |
419 | */ | 421 | */ |
420 | static void | 422 | static void |
421 | handle_start(void *cls, const struct GNUNET_MessageHeader *message) | 423 | handle_start (void *cls, const struct GNUNET_MessageHeader *message) |
422 | { | 424 | { |
423 | struct GNUNET_SERVICE_Client *client = cls; | 425 | struct GNUNET_SERVICE_Client *client = cls; |
424 | struct GNUNET_MQ_Handle *mq; | 426 | struct GNUNET_MQ_Handle *mq; |
425 | struct GNUNET_NSE_ClientMessage em; | 427 | struct GNUNET_NSE_ClientMessage em; |
426 | struct GNUNET_MQ_Envelope *env; | 428 | struct GNUNET_MQ_Envelope *env; |
427 | 429 | ||
428 | (void)message; | 430 | (void) message; |
429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); | 431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); |
430 | mq = GNUNET_SERVICE_client_get_mq(client); | 432 | mq = GNUNET_SERVICE_client_get_mq (client); |
431 | GNUNET_notification_context_add(nc, mq); | 433 | GNUNET_notification_context_add (nc, mq); |
432 | setup_estimate_message(&em); | 434 | setup_estimate_message (&em); |
433 | env = GNUNET_MQ_msg_copy(&em.header); | 435 | env = GNUNET_MQ_msg_copy (&em.header); |
434 | GNUNET_MQ_send(mq, env); | 436 | GNUNET_MQ_send (mq, env); |
435 | GNUNET_SERVICE_client_continue(client); | 437 | GNUNET_SERVICE_client_continue (client); |
436 | } | 438 | } |
437 | 439 | ||
438 | 440 | ||
@@ -443,16 +445,16 @@ handle_start(void *cls, const struct GNUNET_MessageHeader *message) | |||
443 | * @param matching_bits number of matching bits to consider | 445 | * @param matching_bits number of matching bits to consider |
444 | */ | 446 | */ |
445 | static double | 447 | static double |
446 | get_matching_bits_delay(uint32_t matching_bits) | 448 | get_matching_bits_delay (uint32_t matching_bits) |
447 | { | 449 | { |
448 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */ | 450 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */ |
449 | // S is next_timestamp (ignored in return value) | 451 | // S is next_timestamp (ignored in return value) |
450 | // f is frequency (gnunet_nse_interval) | 452 | // f is frequency (gnunet_nse_interval) |
451 | // x is matching_bits | 453 | // x is matching_bits |
452 | // p' is current_size_estimate | 454 | // p' is current_size_estimate |
453 | return ((double)gnunet_nse_interval.rel_value_us / (double)2.0) - | 455 | return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) |
454 | ((gnunet_nse_interval.rel_value_us / M_PI) * | 456 | - ((gnunet_nse_interval.rel_value_us / M_PI) |
455 | atan(matching_bits - current_size_estimate)); | 457 | * atan (matching_bits - current_size_estimate)); |
456 | } | 458 | } |
457 | 459 | ||
458 | 460 | ||
@@ -463,21 +465,21 @@ get_matching_bits_delay(uint32_t matching_bits) | |||
463 | * @return random delay to apply | 465 | * @return random delay to apply |
464 | */ | 466 | */ |
465 | static struct GNUNET_TIME_Relative | 467 | static struct GNUNET_TIME_Relative |
466 | get_delay_randomization(uint32_t matching_bits) | 468 | get_delay_randomization (uint32_t matching_bits) |
467 | { | 469 | { |
468 | #if USE_RANDOM_DELAYS | 470 | #if USE_RANDOM_DELAYS |
469 | struct GNUNET_TIME_Relative ret; | 471 | struct GNUNET_TIME_Relative ret; |
470 | uint32_t i; | 472 | uint32_t i; |
471 | double d; | 473 | double d; |
472 | 474 | ||
473 | d = get_matching_bits_delay(matching_bits); | 475 | d = get_matching_bits_delay (matching_bits); |
474 | i = (uint32_t)(d / (double)(hop_count_max + 1)); | 476 | i = (uint32_t) (d / (double) (hop_count_max + 1)); |
475 | ret.rel_value_us = i; | 477 | ret.rel_value_us = i; |
476 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
477 | "Randomizing flood using latencies up to %s\n", | 479 | "Randomizing flood using latencies up to %s\n", |
478 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); | 480 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
479 | ret.rel_value_us = | 481 | ret.rel_value_us = |
480 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, i + 1); | 482 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1); |
481 | return ret; | 483 | return ret; |
482 | #else | 484 | #else |
483 | return GNUNET_TIME_UNIT_ZERO; | 485 | return GNUNET_TIME_UNIT_ZERO; |
@@ -493,18 +495,18 @@ get_delay_randomization(uint32_t matching_bits) | |||
493 | * @param result where to write the resulting hash | 495 | * @param result where to write the resulting hash |
494 | */ | 496 | */ |
495 | static void | 497 | static void |
496 | pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result) | 498 | pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) |
497 | { | 499 | { |
498 | GNUNET_break( | 500 | GNUNET_break ( |
499 | 0 == gcry_kdf_derive(buf, | 501 | 0 == gcry_kdf_derive (buf, |
500 | buf_len, | 502 | buf_len, |
501 | GCRY_KDF_SCRYPT, | 503 | GCRY_KDF_SCRYPT, |
502 | 1 /* subalgo */, | 504 | 1 /* subalgo */, |
503 | "gnunet-proof-of-work", | 505 | "gnunet-proof-of-work", |
504 | strlen("gnunet-proof-of-work"), | 506 | strlen ("gnunet-proof-of-work"), |
505 | 2 /* iterations; keep cost of individual op small */, | 507 | 2 /* iterations; keep cost of individual op small */, |
506 | sizeof(struct GNUNET_HashCode), | 508 | sizeof(struct GNUNET_HashCode), |
507 | result)); | 509 | result)); |
508 | } | 510 | } |
509 | 511 | ||
510 | 512 | ||
@@ -516,17 +518,17 @@ pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result) | |||
516 | * @return number of matching bits | 518 | * @return number of matching bits |
517 | */ | 519 | */ |
518 | static uint32_t | 520 | static uint32_t |
519 | get_matching_bits(struct GNUNET_TIME_Absolute timestamp, | 521 | get_matching_bits (struct GNUNET_TIME_Absolute timestamp, |
520 | const struct GNUNET_PeerIdentity *id) | 522 | const struct GNUNET_PeerIdentity *id) |
521 | { | 523 | { |
522 | struct GNUNET_HashCode timestamp_hash; | 524 | struct GNUNET_HashCode timestamp_hash; |
523 | struct GNUNET_HashCode pid_hash; | 525 | struct GNUNET_HashCode pid_hash; |
524 | 526 | ||
525 | GNUNET_CRYPTO_hash(×tamp.abs_value_us, | 527 | GNUNET_CRYPTO_hash (×tamp.abs_value_us, |
526 | sizeof(timestamp.abs_value_us), | 528 | sizeof(timestamp.abs_value_us), |
527 | ×tamp_hash); | 529 | ×tamp_hash); |
528 | GNUNET_CRYPTO_hash(id, sizeof(struct GNUNET_PeerIdentity), &pid_hash); | 530 | GNUNET_CRYPTO_hash (id, sizeof(struct GNUNET_PeerIdentity), &pid_hash); |
529 | return GNUNET_CRYPTO_hash_matching_bits(×tamp_hash, &pid_hash); | 531 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &pid_hash); |
530 | } | 532 | } |
531 | 533 | ||
532 | 534 | ||
@@ -539,7 +541,7 @@ get_matching_bits(struct GNUNET_TIME_Absolute timestamp, | |||
539 | * @return delay that should be applied | 541 | * @return delay that should be applied |
540 | */ | 542 | */ |
541 | static struct GNUNET_TIME_Relative | 543 | static struct GNUNET_TIME_Relative |
542 | get_transmit_delay(int round_offset) | 544 | get_transmit_delay (int round_offset) |
543 | { | 545 | { |
544 | struct GNUNET_TIME_Relative ret; | 546 | struct GNUNET_TIME_Relative ret; |
545 | struct GNUNET_TIME_Absolute tgt; | 547 | struct GNUNET_TIME_Absolute tgt; |
@@ -547,37 +549,37 @@ get_transmit_delay(int round_offset) | |||
547 | uint32_t matching_bits; | 549 | uint32_t matching_bits; |
548 | 550 | ||
549 | switch (round_offset) | 551 | switch (round_offset) |
550 | { | 552 | { |
551 | case -1: | 553 | case -1: |
552 | /* previous round is randomized between 0 and 50 ms */ | 554 | /* previous round is randomized between 0 and 50 ms */ |
553 | #if USE_RANDOM_DELAYS | 555 | #if USE_RANDOM_DELAYS |
554 | ret.rel_value_us = | 556 | ret.rel_value_us = |
555 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 50); | 557 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50); |
556 | #else | 558 | #else |
557 | ret = GNUNET_TIME_UNIT_ZERO; | 559 | ret = GNUNET_TIME_UNIT_ZERO; |
558 | #endif | 560 | #endif |
559 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
560 | "Transmitting previous round behind schedule in %s\n", | 562 | "Transmitting previous round behind schedule in %s\n", |
561 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); | 563 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
562 | return ret; | 564 | return ret; |
563 | 565 | ||
564 | case 0: | 566 | case 0: |
565 | /* current round is based on best-known matching_bits */ | 567 | /* current round is based on best-known matching_bits */ |
566 | matching_bits = | 568 | matching_bits = |
567 | ntohl(size_estimate_messages[estimate_index].matching_bits); | 569 | ntohl (size_estimate_messages[estimate_index].matching_bits); |
568 | dist_delay = get_matching_bits_delay(matching_bits); | 570 | dist_delay = get_matching_bits_delay (matching_bits); |
569 | dist_delay += get_delay_randomization(matching_bits).rel_value_us; | 571 | dist_delay += get_delay_randomization (matching_bits).rel_value_us; |
570 | ret.rel_value_us = (uint64_t)dist_delay; | 572 | ret.rel_value_us = (uint64_t) dist_delay; |
571 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
572 | "For round %s, delay for %u matching bits is %s\n", | 574 | "For round %s, delay for %u matching bits is %s\n", |
573 | GNUNET_STRINGS_absolute_time_to_string(current_timestamp), | 575 | GNUNET_STRINGS_absolute_time_to_string (current_timestamp), |
574 | (unsigned int)matching_bits, | 576 | (unsigned int) matching_bits, |
575 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); | 577 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
576 | /* now consider round start time and add delay to it */ | 578 | /* now consider round start time and add delay to it */ |
577 | tgt = GNUNET_TIME_absolute_add(current_timestamp, ret); | 579 | tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); |
578 | return GNUNET_TIME_absolute_get_remaining(tgt); | 580 | return GNUNET_TIME_absolute_get_remaining (tgt); |
579 | } | 581 | } |
580 | GNUNET_break(0); | 582 | GNUNET_break (0); |
581 | return GNUNET_TIME_UNIT_FOREVER_REL; | 583 | return GNUNET_TIME_UNIT_FOREVER_REL; |
582 | } | 584 | } |
583 | 585 | ||
@@ -588,7 +590,7 @@ get_transmit_delay(int round_offset) | |||
588 | * @param cls the `struct NSEPeerEntry *` | 590 | * @param cls the `struct NSEPeerEntry *` |
589 | */ | 591 | */ |
590 | static void | 592 | static void |
591 | transmit_task_cb(void *cls) | 593 | transmit_task_cb (void *cls) |
592 | { | 594 | { |
593 | struct NSEPeerEntry *peer_entry = cls; | 595 | struct NSEPeerEntry *peer_entry = cls; |
594 | unsigned int idx; | 596 | unsigned int idx; |
@@ -597,51 +599,51 @@ transmit_task_cb(void *cls) | |||
597 | peer_entry->transmit_task = NULL; | 599 | peer_entry->transmit_task = NULL; |
598 | idx = estimate_index; | 600 | idx = estimate_index; |
599 | if (GNUNET_NO == peer_entry->previous_round) | 601 | if (GNUNET_NO == peer_entry->previous_round) |
600 | { | 602 | { |
601 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; | 603 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; |
602 | peer_entry->previous_round = GNUNET_YES; | 604 | peer_entry->previous_round = GNUNET_YES; |
603 | peer_entry->transmit_task = | 605 | peer_entry->transmit_task = |
604 | GNUNET_SCHEDULER_add_delayed(get_transmit_delay(0), | 606 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), |
605 | &transmit_task_cb, | 607 | &transmit_task_cb, |
606 | peer_entry); | 608 | peer_entry); |
607 | } | 609 | } |
608 | if ((0 == ntohl(size_estimate_messages[idx].hop_count)) && | 610 | if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && |
609 | (NULL != proof_task)) | 611 | (NULL != proof_task)) |
610 | { | 612 | { |
611 | GNUNET_STATISTICS_update(stats, | 613 | GNUNET_STATISTICS_update (stats, |
612 | "# flood messages not generated (no proof yet)", | 614 | "# flood messages not generated (no proof yet)", |
613 | 1, | 615 | 1, |
614 | GNUNET_NO); | 616 | GNUNET_NO); |
615 | return; | 617 | return; |
616 | } | 618 | } |
617 | if (0 == ntohs(size_estimate_messages[idx].header.size)) | 619 | if (0 == ntohs (size_estimate_messages[idx].header.size)) |
618 | { | 620 | { |
619 | GNUNET_STATISTICS_update(stats, | 621 | GNUNET_STATISTICS_update (stats, |
620 | "# flood messages not generated (lack of history)", | 622 | "# flood messages not generated (lack of history)", |
621 | 1, | 623 | 1, |
622 | GNUNET_NO); | 624 | GNUNET_NO); |
623 | return; | 625 | return; |
624 | } | 626 | } |
625 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
626 | "In round %s, sending to `%s' estimate with %u bits\n", | 628 | "In round %s, sending to `%s' estimate with %u bits\n", |
627 | GNUNET_STRINGS_absolute_time_to_string( | 629 | GNUNET_STRINGS_absolute_time_to_string ( |
628 | GNUNET_TIME_absolute_ntoh( | 630 | GNUNET_TIME_absolute_ntoh ( |
629 | size_estimate_messages[idx].timestamp)), | 631 | size_estimate_messages[idx].timestamp)), |
630 | GNUNET_i2s(peer_entry->id), | 632 | GNUNET_i2s (peer_entry->id), |
631 | (unsigned int)ntohl(size_estimate_messages[idx].matching_bits)); | 633 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); |
632 | if (0 == ntohl(size_estimate_messages[idx].hop_count)) | 634 | if (0 == ntohl (size_estimate_messages[idx].hop_count)) |
633 | GNUNET_STATISTICS_update(stats, "# flood messages started", 1, GNUNET_NO); | 635 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); |
634 | GNUNET_STATISTICS_update(stats, | 636 | GNUNET_STATISTICS_update (stats, |
635 | "# flood messages transmitted", | 637 | "# flood messages transmitted", |
636 | 1, | 638 | 1, |
637 | GNUNET_NO); | 639 | GNUNET_NO); |
638 | #if ENABLE_NSE_HISTOGRAM | 640 | #if ENABLE_NSE_HISTOGRAM |
639 | peer_entry->transmitted_messages++; | 641 | peer_entry->transmitted_messages++; |
640 | peer_entry->last_transmitted_size = | 642 | peer_entry->last_transmitted_size = |
641 | ntohl(size_estimate_messages[idx].matching_bits); | 643 | ntohl (size_estimate_messages[idx].matching_bits); |
642 | #endif | 644 | #endif |
643 | env = GNUNET_MQ_msg_copy(&size_estimate_messages[idx].header); | 645 | env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header); |
644 | GNUNET_MQ_send(peer_entry->mq, env); | 646 | GNUNET_MQ_send (peer_entry->mq, env); |
645 | } | 647 | } |
646 | 648 | ||
647 | 649 | ||
@@ -652,12 +654,12 @@ transmit_task_cb(void *cls) | |||
652 | * clients. | 654 | * clients. |
653 | */ | 655 | */ |
654 | static void | 656 | static void |
655 | update_network_size_estimate() | 657 | update_network_size_estimate () |
656 | { | 658 | { |
657 | struct GNUNET_NSE_ClientMessage em; | 659 | struct GNUNET_NSE_ClientMessage em; |
658 | 660 | ||
659 | setup_estimate_message(&em); | 661 | setup_estimate_message (&em); |
660 | GNUNET_notification_context_broadcast(nc, &em.header, GNUNET_YES); | 662 | GNUNET_notification_context_broadcast (nc, &em.header, GNUNET_YES); |
661 | } | 663 | } |
662 | 664 | ||
663 | 665 | ||
@@ -669,31 +671,31 @@ update_network_size_estimate() | |||
669 | * @param ts timestamp to use | 671 | * @param ts timestamp to use |
670 | */ | 672 | */ |
671 | static void | 673 | static void |
672 | setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts) | 674 | setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts) |
673 | { | 675 | { |
674 | struct GNUNET_NSE_FloodMessage *fm; | 676 | struct GNUNET_NSE_FloodMessage *fm; |
675 | uint32_t matching_bits; | 677 | uint32_t matching_bits; |
676 | 678 | ||
677 | matching_bits = get_matching_bits(ts, &my_identity); | 679 | matching_bits = get_matching_bits (ts, &my_identity); |
678 | fm = &size_estimate_messages[slot]; | 680 | fm = &size_estimate_messages[slot]; |
679 | fm->header.size = htons(sizeof(struct GNUNET_NSE_FloodMessage)); | 681 | fm->header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage)); |
680 | fm->header.type = htons(GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); | 682 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); |
681 | fm->hop_count = htonl(0); | 683 | fm->hop_count = htonl (0); |
682 | fm->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_NSE_SEND); | 684 | fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); |
683 | fm->purpose.size = | 685 | fm->purpose.size = |
684 | htonl(sizeof(struct GNUNET_NSE_FloodMessage) - | 686 | htonl (sizeof(struct GNUNET_NSE_FloodMessage) |
685 | sizeof(struct GNUNET_MessageHeader) - sizeof(uint32_t) - | 687 | - sizeof(struct GNUNET_MessageHeader) - sizeof(uint32_t) |
686 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)); | 688 | - sizeof(struct GNUNET_CRYPTO_EddsaSignature)); |
687 | fm->matching_bits = htonl(matching_bits); | 689 | fm->matching_bits = htonl (matching_bits); |
688 | fm->timestamp = GNUNET_TIME_absolute_hton(ts); | 690 | fm->timestamp = GNUNET_TIME_absolute_hton (ts); |
689 | fm->origin = my_identity; | 691 | fm->origin = my_identity; |
690 | fm->proof_of_work = my_proof; | 692 | fm->proof_of_work = my_proof; |
691 | if (nse_work_required > 0) | 693 | if (nse_work_required > 0) |
692 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, | 694 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, |
693 | &fm->purpose, | 695 | &fm->purpose, |
694 | &fm->signature)); | 696 | &fm->signature)); |
695 | else | 697 | else |
696 | memset(&fm->signature, 0, sizeof(fm->signature)); | 698 | memset (&fm->signature, 0, sizeof(fm->signature)); |
697 | } | 699 | } |
698 | 700 | ||
699 | 701 | ||
@@ -707,34 +709,34 @@ setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts) | |||
707 | * @return #GNUNET_OK (continue to iterate) | 709 | * @return #GNUNET_OK (continue to iterate) |
708 | */ | 710 | */ |
709 | static int | 711 | static int |
710 | schedule_current_round(void *cls, | 712 | schedule_current_round (void *cls, |
711 | const struct GNUNET_PeerIdentity *key, | 713 | const struct GNUNET_PeerIdentity *key, |
712 | void *value) | 714 | void *value) |
713 | { | 715 | { |
714 | struct NSEPeerEntry *peer_entry = value; | 716 | struct NSEPeerEntry *peer_entry = value; |
715 | struct GNUNET_TIME_Relative delay; | 717 | struct GNUNET_TIME_Relative delay; |
716 | 718 | ||
717 | (void)cls; | 719 | (void) cls; |
718 | (void)key; | 720 | (void) key; |
719 | if (NULL != peer_entry->transmit_task) | 721 | if (NULL != peer_entry->transmit_task) |
720 | { | 722 | { |
721 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | 723 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
722 | peer_entry->previous_round = GNUNET_NO; | 724 | peer_entry->previous_round = GNUNET_NO; |
723 | } | 725 | } |
724 | #if ENABLE_NSE_HISTOGRAM | 726 | #if ENABLE_NSE_HISTOGRAM |
725 | if (peer_entry->received_messages > 1) | 727 | if (peer_entry->received_messages > 1) |
726 | GNUNET_STATISTICS_update(stats, | 728 | GNUNET_STATISTICS_update (stats, |
727 | "# extra messages", | 729 | "# extra messages", |
728 | peer_entry->received_messages - 1, | 730 | peer_entry->received_messages - 1, |
729 | GNUNET_NO); | 731 | GNUNET_NO); |
730 | peer_entry->transmitted_messages = 0; | 732 | peer_entry->transmitted_messages = 0; |
731 | peer_entry->last_transmitted_size = 0; | 733 | peer_entry->last_transmitted_size = 0; |
732 | peer_entry->received_messages = 0; | 734 | peer_entry->received_messages = 0; |
733 | #endif | 735 | #endif |
734 | delay = | 736 | delay = |
735 | get_transmit_delay((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); | 737 | get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); |
736 | peer_entry->transmit_task = | 738 | peer_entry->transmit_task = |
737 | GNUNET_SCHEDULER_add_delayed(delay, &transmit_task_cb, peer_entry); | 739 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry); |
738 | return GNUNET_OK; | 740 | return GNUNET_OK; |
739 | } | 741 | } |
740 | 742 | ||
@@ -745,46 +747,46 @@ schedule_current_round(void *cls, | |||
745 | * @param cls unused | 747 | * @param cls unused |
746 | */ | 748 | */ |
747 | static void | 749 | static void |
748 | update_flood_message(void *cls) | 750 | update_flood_message (void *cls) |
749 | { | 751 | { |
750 | struct GNUNET_TIME_Relative offset; | 752 | struct GNUNET_TIME_Relative offset; |
751 | 753 | ||
752 | (void)cls; | 754 | (void) cls; |
753 | flood_task = NULL; | 755 | flood_task = NULL; |
754 | offset = GNUNET_TIME_absolute_get_remaining(next_timestamp); | 756 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); |
755 | if (0 != offset.rel_value_us) | 757 | if (0 != offset.rel_value_us) |
756 | { | 758 | { |
757 | /* somehow run early, delay more */ | 759 | /* somehow run early, delay more */ |
758 | flood_task = | 760 | flood_task = |
759 | GNUNET_SCHEDULER_add_delayed(offset, &update_flood_message, NULL); | 761 | GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL); |
760 | return; | 762 | return; |
761 | } | 763 | } |
762 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; | 764 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; |
763 | if (estimate_count < HISTORY_SIZE) | 765 | if (estimate_count < HISTORY_SIZE) |
764 | estimate_count++; | 766 | estimate_count++; |
765 | current_timestamp = next_timestamp; | 767 | current_timestamp = next_timestamp; |
766 | next_timestamp = | 768 | next_timestamp = |
767 | GNUNET_TIME_absolute_add(current_timestamp, gnunet_nse_interval); | 769 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
768 | if ((current_timestamp.abs_value_us == | 770 | if ((current_timestamp.abs_value_us == |
769 | GNUNET_TIME_absolute_ntoh(next_message.timestamp).abs_value_us) && | 771 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && |
770 | (get_matching_bits(current_timestamp, &my_identity) < | 772 | (get_matching_bits (current_timestamp, &my_identity) < |
771 | ntohl(next_message.matching_bits))) | 773 | ntohl (next_message.matching_bits))) |
772 | { | 774 | { |
773 | /* we received a message for this round way early, use it! */ | 775 | /* we received a message for this round way early, use it! */ |
774 | size_estimate_messages[estimate_index] = next_message; | 776 | size_estimate_messages[estimate_index] = next_message; |
775 | size_estimate_messages[estimate_index].hop_count = | 777 | size_estimate_messages[estimate_index].hop_count = |
776 | htonl(1 + ntohl(next_message.hop_count)); | 778 | htonl (1 + ntohl (next_message.hop_count)); |
777 | } | 779 | } |
778 | else | 780 | else |
779 | setup_flood_message(estimate_index, current_timestamp); | 781 | setup_flood_message (estimate_index, current_timestamp); |
780 | next_message.matching_bits = htonl(0); /* reset for 'next' round */ | 782 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ |
781 | hop_count_max = 0; | 783 | hop_count_max = 0; |
782 | for (unsigned int i = 0; i < HISTORY_SIZE; i++) | 784 | for (unsigned int i = 0; i < HISTORY_SIZE; i++) |
783 | hop_count_max = | 785 | hop_count_max = |
784 | GNUNET_MAX(ntohl(size_estimate_messages[i].hop_count), hop_count_max); | 786 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); |
785 | GNUNET_CONTAINER_multipeermap_iterate(peers, &schedule_current_round, NULL); | 787 | GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL); |
786 | flood_task = | 788 | flood_task = |
787 | GNUNET_SCHEDULER_add_at(next_timestamp, &update_flood_message, NULL); | 789 | GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL); |
788 | } | 790 | } |
789 | 791 | ||
790 | 792 | ||
@@ -795,12 +797,12 @@ update_flood_message(void *cls) | |||
795 | * @return the number of leading zero bits. | 797 | * @return the number of leading zero bits. |
796 | */ | 798 | */ |
797 | static unsigned int | 799 | static unsigned int |
798 | count_leading_zeroes(const struct GNUNET_HashCode *hash) | 800 | count_leading_zeroes (const struct GNUNET_HashCode *hash) |
799 | { | 801 | { |
800 | unsigned int hash_count; | 802 | unsigned int hash_count; |
801 | 803 | ||
802 | hash_count = 0; | 804 | hash_count = 0; |
803 | while (0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count)) | 805 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) |
804 | hash_count++; | 806 | hash_count++; |
805 | return hash_count; | 807 | return hash_count; |
806 | } | 808 | } |
@@ -815,19 +817,19 @@ count_leading_zeroes(const struct GNUNET_HashCode *hash) | |||
815 | * @return #GNUNET_YES if valid, #GNUNET_NO if not | 817 | * @return #GNUNET_YES if valid, #GNUNET_NO if not |
816 | */ | 818 | */ |
817 | static int | 819 | static int |
818 | check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | 820 | check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, |
819 | uint64_t val) | 821 | uint64_t val) |
820 | { | 822 | { |
821 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + | 823 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) |
822 | sizeof(val)] GNUNET_ALIGN; | 824 | + sizeof(val)] GNUNET_ALIGN; |
823 | struct GNUNET_HashCode result; | 825 | struct GNUNET_HashCode result; |
824 | 826 | ||
825 | GNUNET_memcpy(buf, &val, sizeof(val)); | 827 | GNUNET_memcpy (buf, &val, sizeof(val)); |
826 | GNUNET_memcpy(&buf[sizeof(val)], | 828 | GNUNET_memcpy (&buf[sizeof(val)], |
827 | pkey, | 829 | pkey, |
828 | sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); | 830 | sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); |
829 | pow_hash(buf, sizeof(buf), &result); | 831 | pow_hash (buf, sizeof(buf), &result); |
830 | return (count_leading_zeroes(&result) >= nse_work_required) ? GNUNET_YES | 832 | return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES |
831 | : GNUNET_NO; | 833 | : GNUNET_NO; |
832 | } | 834 | } |
833 | 835 | ||
@@ -836,20 +838,20 @@ check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | |||
836 | * Write our current proof to disk. | 838 | * Write our current proof to disk. |
837 | */ | 839 | */ |
838 | static void | 840 | static void |
839 | write_proof() | 841 | write_proof () |
840 | { | 842 | { |
841 | char *proof; | 843 | char *proof; |
842 | 844 | ||
843 | if (GNUNET_OK != | 845 | if (GNUNET_OK != |
844 | GNUNET_CONFIGURATION_get_value_filename(cfg, "NSE", "PROOFFILE", &proof)) | 846 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) |
845 | return; | 847 | return; |
846 | if (sizeof(my_proof) != GNUNET_DISK_fn_write(proof, | 848 | if (sizeof(my_proof) != GNUNET_DISK_fn_write (proof, |
847 | &my_proof, | 849 | &my_proof, |
848 | sizeof(my_proof), | 850 | sizeof(my_proof), |
849 | GNUNET_DISK_PERM_USER_READ | | 851 | GNUNET_DISK_PERM_USER_READ |
850 | GNUNET_DISK_PERM_USER_WRITE)) | 852 | | GNUNET_DISK_PERM_USER_WRITE)) |
851 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", proof); | 853 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); |
852 | GNUNET_free(proof); | 854 | GNUNET_free (proof); |
853 | } | 855 | } |
854 | 856 | ||
855 | 857 | ||
@@ -859,57 +861,57 @@ write_proof() | |||
859 | * @param cls closure (unused) | 861 | * @param cls closure (unused) |
860 | */ | 862 | */ |
861 | static void | 863 | static void |
862 | find_proof(void *cls) | 864 | find_proof (void *cls) |
863 | { | 865 | { |
864 | #define ROUND_SIZE 10 | 866 | #define ROUND_SIZE 10 |
865 | uint64_t counter; | 867 | uint64_t counter; |
866 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + | 868 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) |
867 | sizeof(uint64_t)] GNUNET_ALIGN; | 869 | + sizeof(uint64_t)] GNUNET_ALIGN; |
868 | struct GNUNET_HashCode result; | 870 | struct GNUNET_HashCode result; |
869 | unsigned int i; | 871 | unsigned int i; |
870 | 872 | ||
871 | (void)cls; | 873 | (void) cls; |
872 | proof_task = NULL; | 874 | proof_task = NULL; |
873 | GNUNET_memcpy(&buf[sizeof(uint64_t)], | 875 | GNUNET_memcpy (&buf[sizeof(uint64_t)], |
874 | &my_identity, | 876 | &my_identity, |
875 | sizeof(struct GNUNET_PeerIdentity)); | 877 | sizeof(struct GNUNET_PeerIdentity)); |
876 | i = 0; | 878 | i = 0; |
877 | counter = my_proof; | 879 | counter = my_proof; |
878 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) | 880 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) |
881 | { | ||
882 | GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); | ||
883 | pow_hash (buf, sizeof(buf), &result); | ||
884 | if (nse_work_required <= count_leading_zeroes (&result)) | ||
879 | { | 885 | { |
880 | GNUNET_memcpy(buf, &counter, sizeof(uint64_t)); | ||
881 | pow_hash(buf, sizeof(buf), &result); | ||
882 | if (nse_work_required <= count_leading_zeroes(&result)) | ||
883 | { | ||
884 | my_proof = counter; | ||
885 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
886 | "Proof of work found: %llu!\n", | ||
887 | (unsigned long long)GNUNET_ntohll(counter)); | ||
888 | write_proof(); | ||
889 | setup_flood_message(estimate_index, current_timestamp); | ||
890 | return; | ||
891 | } | ||
892 | counter++; | ||
893 | i++; | ||
894 | } | ||
895 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | ||
896 | { | ||
897 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
898 | "Testing proofs currently at %llu\n", | ||
899 | (unsigned long long)counter); | ||
900 | /* remember progress every 100 rounds */ | ||
901 | my_proof = counter; | 886 | my_proof = counter; |
902 | write_proof(); | 887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
888 | "Proof of work found: %llu!\n", | ||
889 | (unsigned long long) GNUNET_ntohll (counter)); | ||
890 | write_proof (); | ||
891 | setup_flood_message (estimate_index, current_timestamp); | ||
892 | return; | ||
903 | } | 893 | } |
894 | counter++; | ||
895 | i++; | ||
896 | } | ||
897 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | ||
898 | { | ||
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
900 | "Testing proofs currently at %llu\n", | ||
901 | (unsigned long long) counter); | ||
902 | /* remember progress every 100 rounds */ | ||
903 | my_proof = counter; | ||
904 | write_proof (); | ||
905 | } | ||
904 | else | 906 | else |
905 | { | 907 | { |
906 | my_proof = counter; | 908 | my_proof = counter; |
907 | } | 909 | } |
908 | proof_task = | 910 | proof_task = |
909 | GNUNET_SCHEDULER_add_delayed_with_priority(proof_find_delay, | 911 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, |
910 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 912 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
911 | &find_proof, | 913 | &find_proof, |
912 | NULL); | 914 | NULL); |
913 | } | 915 | } |
914 | 916 | ||
915 | 917 | ||
@@ -923,28 +925,28 @@ find_proof(void *cls) | |||
923 | * #GNUNET_NO if the key/signature don't verify | 925 | * #GNUNET_NO if the key/signature don't verify |
924 | */ | 926 | */ |
925 | static int | 927 | static int |
926 | verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood) | 928 | verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) |
927 | { | 929 | { |
928 | if (GNUNET_YES != check_proof_of_work(&incoming_flood->origin.public_key, | 930 | if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key, |
929 | incoming_flood->proof_of_work)) | 931 | incoming_flood->proof_of_work)) |
930 | { | 932 | { |
931 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 933 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
932 | "Proof of work invalid: %llu!\n", | 934 | "Proof of work invalid: %llu!\n", |
933 | (unsigned long long)GNUNET_ntohll( | 935 | (unsigned long long) GNUNET_ntohll ( |
934 | incoming_flood->proof_of_work)); | 936 | incoming_flood->proof_of_work)); |
935 | GNUNET_break_op(0); | 937 | GNUNET_break_op (0); |
936 | return GNUNET_NO; | 938 | return GNUNET_NO; |
937 | } | 939 | } |
938 | if ((nse_work_required > 0) && | 940 | if ((nse_work_required > 0) && |
939 | (GNUNET_OK != | 941 | (GNUNET_OK != |
940 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_NSE_SEND, | 942 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND, |
941 | &incoming_flood->purpose, | 943 | &incoming_flood->purpose, |
942 | &incoming_flood->signature, | 944 | &incoming_flood->signature, |
943 | &incoming_flood->origin.public_key))) | 945 | &incoming_flood->origin.public_key))) |
944 | { | 946 | { |
945 | GNUNET_break_op(0); | 947 | GNUNET_break_op (0); |
946 | return GNUNET_NO; | 948 | return GNUNET_NO; |
947 | } | 949 | } |
948 | return GNUNET_YES; | 950 | return GNUNET_YES; |
949 | } | 951 | } |
950 | 952 | ||
@@ -959,35 +961,35 @@ verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood) | |||
959 | * @return #GNUNET_OK (continue to iterate) | 961 | * @return #GNUNET_OK (continue to iterate) |
960 | */ | 962 | */ |
961 | static int | 963 | static int |
962 | update_flood_times(void *cls, | 964 | update_flood_times (void *cls, |
963 | const struct GNUNET_PeerIdentity *key, | 965 | const struct GNUNET_PeerIdentity *key, |
964 | void *value) | 966 | void *value) |
965 | { | 967 | { |
966 | struct NSEPeerEntry *exclude = cls; | 968 | struct NSEPeerEntry *exclude = cls; |
967 | struct NSEPeerEntry *peer_entry = value; | 969 | struct NSEPeerEntry *peer_entry = value; |
968 | struct GNUNET_TIME_Relative delay; | 970 | struct GNUNET_TIME_Relative delay; |
969 | 971 | ||
970 | (void)key; | 972 | (void) key; |
971 | if (peer_entry == exclude) | 973 | if (peer_entry == exclude) |
972 | return GNUNET_OK; /* trigger of the update */ | 974 | return GNUNET_OK; /* trigger of the update */ |
973 | if (GNUNET_NO == peer_entry->previous_round) | 975 | if (GNUNET_NO == peer_entry->previous_round) |
976 | { | ||
977 | /* still stuck in previous round, no point to update, check that | ||
978 | * we are active here though... */ | ||
979 | if (NULL == peer_entry->transmit_task) | ||
974 | { | 980 | { |
975 | /* still stuck in previous round, no point to update, check that | 981 | GNUNET_break (0); |
976 | * we are active here though... */ | ||
977 | if (NULL == peer_entry->transmit_task) | ||
978 | { | ||
979 | GNUNET_break(0); | ||
980 | } | ||
981 | return GNUNET_OK; | ||
982 | } | 982 | } |
983 | return GNUNET_OK; | ||
984 | } | ||
983 | if (NULL != peer_entry->transmit_task) | 985 | if (NULL != peer_entry->transmit_task) |
984 | { | 986 | { |
985 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | 987 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
986 | peer_entry->transmit_task = NULL; | 988 | peer_entry->transmit_task = NULL; |
987 | } | 989 | } |
988 | delay = get_transmit_delay(0); | 990 | delay = get_transmit_delay (0); |
989 | peer_entry->transmit_task = | 991 | peer_entry->transmit_task = |
990 | GNUNET_SCHEDULER_add_delayed(delay, &transmit_task_cb, peer_entry); | 992 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry); |
991 | return GNUNET_OK; | 993 | return GNUNET_OK; |
992 | } | 994 | } |
993 | 995 | ||
@@ -999,8 +1001,8 @@ update_flood_times(void *cls, | |||
999 | * @param incoming_flood received message | 1001 | * @param incoming_flood received message |
1000 | */ | 1002 | */ |
1001 | static void | 1003 | static void |
1002 | handle_p2p_estimate(void *cls, | 1004 | handle_p2p_estimate (void *cls, |
1003 | const struct GNUNET_NSE_FloodMessage *incoming_flood) | 1005 | const struct GNUNET_NSE_FloodMessage *incoming_flood) |
1004 | { | 1006 | { |
1005 | struct NSEPeerEntry *peer_entry = cls; | 1007 | struct NSEPeerEntry *peer_entry = cls; |
1006 | struct GNUNET_TIME_Absolute ts; | 1008 | struct GNUNET_TIME_Absolute ts; |
@@ -1011,157 +1013,157 @@ handle_p2p_estimate(void *cls, | |||
1011 | { | 1013 | { |
1012 | uint64_t t; | 1014 | uint64_t t; |
1013 | 1015 | ||
1014 | t = GNUNET_TIME_absolute_get().abs_value_us; | 1016 | t = GNUNET_TIME_absolute_get ().abs_value_us; |
1015 | if (NULL != lh) | 1017 | if (NULL != lh) |
1016 | GNUNET_TESTBED_LOGGER_write(lh, &t, sizeof(uint64_t)); | 1018 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t)); |
1017 | if (NULL != histogram) | 1019 | if (NULL != histogram) |
1018 | GNUNET_BIO_write_int64(histogram, t); | 1020 | GNUNET_BIO_write_int64 (histogram, t); |
1019 | } | 1021 | } |
1020 | #endif | 1022 | #endif |
1021 | GNUNET_STATISTICS_update(stats, "# flood messages received", 1, GNUNET_NO); | 1023 | GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO); |
1022 | matching_bits = ntohl(incoming_flood->matching_bits); | 1024 | matching_bits = ntohl (incoming_flood->matching_bits); |
1023 | #if DEBUG_NSE | 1025 | #if DEBUG_NSE |
1024 | { | 1026 | { |
1025 | char origin[5]; | 1027 | char origin[5]; |
1026 | char pred[5]; | 1028 | char pred[5]; |
1027 | struct GNUNET_PeerIdentity os; | 1029 | struct GNUNET_PeerIdentity os; |
1028 | 1030 | ||
1029 | GNUNET_snprintf(origin, | 1031 | GNUNET_snprintf (origin, |
1030 | sizeof(origin), | 1032 | sizeof(origin), |
1031 | "%s", | 1033 | "%s", |
1032 | GNUNET_i2s(&incoming_flood->origin)); | 1034 | GNUNET_i2s (&incoming_flood->origin)); |
1033 | GNUNET_snprintf(pred, sizeof(pred), "%s", GNUNET_i2s(peer_entry->id)); | 1035 | GNUNET_snprintf (pred, sizeof(pred), "%s", GNUNET_i2s (peer_entry->id)); |
1034 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1035 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", | 1037 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", |
1036 | GNUNET_STRINGS_absolute_time_to_string( | 1038 | GNUNET_STRINGS_absolute_time_to_string ( |
1037 | GNUNET_TIME_absolute_ntoh(incoming_flood->timestamp)), | 1039 | GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)), |
1038 | origin, | 1040 | origin, |
1039 | pred, | 1041 | pred, |
1040 | GNUNET_i2s(&my_identity), | 1042 | GNUNET_i2s (&my_identity), |
1041 | (unsigned int)matching_bits); | 1043 | (unsigned int) matching_bits); |
1042 | } | 1044 | } |
1043 | #endif | 1045 | #endif |
1044 | 1046 | ||
1045 | #if ENABLE_NSE_HISTOGRAM | 1047 | #if ENABLE_NSE_HISTOGRAM |
1046 | peer_entry->received_messages++; | 1048 | peer_entry->received_messages++; |
1047 | if (peer_entry->transmitted_messages > 0 && | 1049 | if ((peer_entry->transmitted_messages > 0)&& |
1048 | peer_entry->last_transmitted_size >= matching_bits) | 1050 | (peer_entry->last_transmitted_size >= matching_bits) ) |
1049 | GNUNET_STATISTICS_update(stats, "# cross messages", 1, GNUNET_NO); | 1051 | GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO); |
1050 | #endif | 1052 | #endif |
1051 | 1053 | ||
1052 | ts = GNUNET_TIME_absolute_ntoh(incoming_flood->timestamp); | 1054 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); |
1053 | if (ts.abs_value_us == current_timestamp.abs_value_us) | 1055 | if (ts.abs_value_us == current_timestamp.abs_value_us) |
1054 | idx = estimate_index; | 1056 | idx = estimate_index; |
1055 | else if (ts.abs_value_us == | 1057 | else if (ts.abs_value_us == |
1056 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us) | 1058 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us) |
1057 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1059 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1058 | else if (ts.abs_value_us == next_timestamp.abs_value_us) | 1060 | else if (ts.abs_value_us == next_timestamp.abs_value_us) |
1061 | { | ||
1062 | if (matching_bits <= ntohl (next_message.matching_bits)) | ||
1063 | return; /* ignore, simply too early/late */ | ||
1064 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | ||
1059 | { | 1065 | { |
1060 | if (matching_bits <= ntohl(next_message.matching_bits)) | 1066 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1061 | return; /* ignore, simply too early/late */ | 1067 | "Peer %s is likely ill-configured!\n", |
1062 | if (GNUNET_YES != verify_message_crypto(incoming_flood)) | 1068 | GNUNET_i2s (peer_entry->id)); |
1063 | { | 1069 | GNUNET_break_op (0); |
1064 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1065 | "Peer %s is likely ill-configured!\n", | ||
1066 | GNUNET_i2s(peer_entry->id)); | ||
1067 | GNUNET_break_op(0); | ||
1068 | return; | ||
1069 | } | ||
1070 | next_message = *incoming_flood; | ||
1071 | return; | 1070 | return; |
1072 | } | 1071 | } |
1072 | next_message = *incoming_flood; | ||
1073 | return; | ||
1074 | } | ||
1073 | else | 1075 | else |
1076 | { | ||
1077 | GNUNET_STATISTICS_update (stats, | ||
1078 | "# flood messages discarded (clock skew too large)", | ||
1079 | 1, | ||
1080 | GNUNET_NO); | ||
1081 | return; | ||
1082 | } | ||
1083 | if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity))) | ||
1084 | { | ||
1085 | /* send to self, update our own estimate IF this also comes from us! */ | ||
1086 | if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity)) | ||
1087 | update_network_size_estimate (); | ||
1088 | return; | ||
1089 | } | ||
1090 | if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) | ||
1091 | { | ||
1092 | /* Cancel transmission in the other direction, as this peer clearly has | ||
1093 | up-to-date information already. Even if we didn't talk to this peer in | ||
1094 | the previous round, we should no longer send it stale information as it | ||
1095 | told us about the current round! */ | ||
1096 | peer_entry->previous_round = GNUNET_YES; | ||
1097 | if (idx != estimate_index) | ||
1074 | { | 1098 | { |
1075 | GNUNET_STATISTICS_update(stats, | 1099 | /* do not transmit information for the previous round to this peer |
1076 | "# flood messages discarded (clock skew too large)", | 1100 | anymore (but allow current round) */ |
1077 | 1, | ||
1078 | GNUNET_NO); | ||
1079 | return; | ||
1080 | } | ||
1081 | if (0 == (GNUNET_memcmp(peer_entry->id, &my_identity))) | ||
1082 | { | ||
1083 | /* send to self, update our own estimate IF this also comes from us! */ | ||
1084 | if (0 == GNUNET_memcmp(&incoming_flood->origin, &my_identity)) | ||
1085 | update_network_size_estimate(); | ||
1086 | return; | ||
1087 | } | ||
1088 | if (matching_bits == ntohl(size_estimate_messages[idx].matching_bits)) | ||
1089 | { | ||
1090 | /* Cancel transmission in the other direction, as this peer clearly has | ||
1091 | up-to-date information already. Even if we didn't talk to this peer in | ||
1092 | the previous round, we should no longer send it stale information as it | ||
1093 | told us about the current round! */ | ||
1094 | peer_entry->previous_round = GNUNET_YES; | ||
1095 | if (idx != estimate_index) | ||
1096 | { | ||
1097 | /* do not transmit information for the previous round to this peer | ||
1098 | anymore (but allow current round) */ | ||
1099 | return; | ||
1100 | } | ||
1101 | /* got up-to-date information for current round, cancel transmission to | ||
1102 | * this peer altogether */ | ||
1103 | if (NULL != peer_entry->transmit_task) | ||
1104 | { | ||
1105 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | ||
1106 | peer_entry->transmit_task = NULL; | ||
1107 | } | ||
1108 | return; | 1101 | return; |
1109 | } | 1102 | } |
1110 | if (matching_bits < ntohl(size_estimate_messages[idx].matching_bits)) | 1103 | /* got up-to-date information for current round, cancel transmission to |
1104 | * this peer altogether */ | ||
1105 | if (NULL != peer_entry->transmit_task) | ||
1111 | { | 1106 | { |
1112 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) | 1107 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1113 | { | 1108 | peer_entry->transmit_task = NULL; |
1114 | peer_entry->previous_round = GNUNET_NO; | ||
1115 | } | ||
1116 | /* push back our result now, that peer is spreading bad information... */ | ||
1117 | if (NULL != peer_entry->transmit_task) | ||
1118 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | ||
1119 | peer_entry->transmit_task = | ||
1120 | GNUNET_SCHEDULER_add_now(&transmit_task_cb, peer_entry); | ||
1121 | /* Not closer than our most recent message, no need to do work here */ | ||
1122 | GNUNET_STATISTICS_update(stats, | ||
1123 | "# flood messages ignored (had closer already)", | ||
1124 | 1, | ||
1125 | GNUNET_NO); | ||
1126 | return; | ||
1127 | } | 1109 | } |
1128 | if (GNUNET_YES != verify_message_crypto(incoming_flood)) | 1110 | return; |
1111 | } | ||
1112 | if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) | ||
1113 | { | ||
1114 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) | ||
1129 | { | 1115 | { |
1130 | GNUNET_break_op(0); | 1116 | peer_entry->previous_round = GNUNET_NO; |
1131 | return; | ||
1132 | } | 1117 | } |
1133 | GNUNET_assert(matching_bits > | 1118 | /* push back our result now, that peer is spreading bad information... */ |
1134 | ntohl(size_estimate_messages[idx].matching_bits)); | 1119 | if (NULL != peer_entry->transmit_task) |
1120 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
1121 | peer_entry->transmit_task = | ||
1122 | GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry); | ||
1123 | /* Not closer than our most recent message, no need to do work here */ | ||
1124 | GNUNET_STATISTICS_update (stats, | ||
1125 | "# flood messages ignored (had closer already)", | ||
1126 | 1, | ||
1127 | GNUNET_NO); | ||
1128 | return; | ||
1129 | } | ||
1130 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | ||
1131 | { | ||
1132 | GNUNET_break_op (0); | ||
1133 | return; | ||
1134 | } | ||
1135 | GNUNET_assert (matching_bits > | ||
1136 | ntohl (size_estimate_messages[idx].matching_bits)); | ||
1135 | /* Cancel transmission in the other direction, as this peer clearly has | 1137 | /* Cancel transmission in the other direction, as this peer clearly has |
1136 | * up-to-date information already. | 1138 | * up-to-date information already. |
1137 | */ | 1139 | */ |
1138 | peer_entry->previous_round = GNUNET_YES; | 1140 | peer_entry->previous_round = GNUNET_YES; |
1139 | if (idx == estimate_index) | 1141 | if (idx == estimate_index) |
1142 | { | ||
1143 | /* cancel any activity for current round */ | ||
1144 | if (NULL != peer_entry->transmit_task) | ||
1140 | { | 1145 | { |
1141 | /* cancel any activity for current round */ | 1146 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1142 | if (NULL != peer_entry->transmit_task) | 1147 | peer_entry->transmit_task = NULL; |
1143 | { | ||
1144 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | ||
1145 | peer_entry->transmit_task = NULL; | ||
1146 | } | ||
1147 | } | 1148 | } |
1149 | } | ||
1148 | size_estimate_messages[idx] = *incoming_flood; | 1150 | size_estimate_messages[idx] = *incoming_flood; |
1149 | size_estimate_messages[idx].hop_count = | 1151 | size_estimate_messages[idx].hop_count = |
1150 | htonl(ntohl(incoming_flood->hop_count) + 1); | 1152 | htonl (ntohl (incoming_flood->hop_count) + 1); |
1151 | hop_count_max = | 1153 | hop_count_max = |
1152 | GNUNET_MAX(ntohl(incoming_flood->hop_count) + 1, hop_count_max); | 1154 | GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max); |
1153 | GNUNET_STATISTICS_set(stats, | 1155 | GNUNET_STATISTICS_set (stats, |
1154 | "# estimated network diameter", | 1156 | "# estimated network diameter", |
1155 | hop_count_max, | 1157 | hop_count_max, |
1156 | GNUNET_NO); | 1158 | GNUNET_NO); |
1157 | 1159 | ||
1158 | /* have a new, better size estimate, inform clients */ | 1160 | /* have a new, better size estimate, inform clients */ |
1159 | update_network_size_estimate(); | 1161 | update_network_size_estimate (); |
1160 | 1162 | ||
1161 | /* flood to rest */ | 1163 | /* flood to rest */ |
1162 | GNUNET_CONTAINER_multipeermap_iterate(peers, | 1164 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
1163 | &update_flood_times, | 1165 | &update_flood_times, |
1164 | peer_entry); | 1166 | peer_entry); |
1165 | } | 1167 | } |
1166 | 1168 | ||
1167 | 1169 | ||
@@ -1173,33 +1175,33 @@ handle_p2p_estimate(void *cls, | |||
1173 | * @param peer peer identity this notification is about | 1175 | * @param peer peer identity this notification is about |
1174 | */ | 1176 | */ |
1175 | static void * | 1177 | static void * |
1176 | handle_core_connect(void *cls, | 1178 | handle_core_connect (void *cls, |
1177 | const struct GNUNET_PeerIdentity *peer, | 1179 | const struct GNUNET_PeerIdentity *peer, |
1178 | struct GNUNET_MQ_Handle *mq) | 1180 | struct GNUNET_MQ_Handle *mq) |
1179 | { | 1181 | { |
1180 | struct NSEPeerEntry *peer_entry; | 1182 | struct NSEPeerEntry *peer_entry; |
1181 | 1183 | ||
1182 | (void)cls; | 1184 | (void) cls; |
1183 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1184 | "Peer `%s' connected to us\n", | 1186 | "Peer `%s' connected to us\n", |
1185 | GNUNET_i2s(peer)); | 1187 | GNUNET_i2s (peer)); |
1186 | /* set our default transmission options */ | 1188 | /* set our default transmission options */ |
1187 | GNUNET_MQ_set_options(mq, NSE_PRIORITY); | 1189 | GNUNET_MQ_set_options (mq, NSE_PRIORITY); |
1188 | /* create our peer entry for this peer */ | 1190 | /* create our peer entry for this peer */ |
1189 | peer_entry = GNUNET_new(struct NSEPeerEntry); | 1191 | peer_entry = GNUNET_new (struct NSEPeerEntry); |
1190 | peer_entry->id = peer; | 1192 | peer_entry->id = peer; |
1191 | peer_entry->mq = mq; | 1193 | peer_entry->mq = mq; |
1192 | GNUNET_assert(GNUNET_OK == | 1194 | GNUNET_assert (GNUNET_OK == |
1193 | GNUNET_CONTAINER_multipeermap_put( | 1195 | GNUNET_CONTAINER_multipeermap_put ( |
1194 | peers, | 1196 | peers, |
1195 | peer_entry->id, | 1197 | peer_entry->id, |
1196 | peer_entry, | 1198 | peer_entry, |
1197 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1199 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1198 | peer_entry->transmit_task = | 1200 | peer_entry->transmit_task = |
1199 | GNUNET_SCHEDULER_add_delayed(get_transmit_delay(-1), | 1201 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), |
1200 | &transmit_task_cb, | 1202 | &transmit_task_cb, |
1201 | peer_entry); | 1203 | peer_entry); |
1202 | GNUNET_STATISTICS_update(stats, "# peers connected", 1, GNUNET_NO); | 1204 | GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO); |
1203 | return peer_entry; | 1205 | return peer_entry; |
1204 | } | 1206 | } |
1205 | 1207 | ||
@@ -1213,25 +1215,25 @@ handle_core_connect(void *cls, | |||
1213 | * @parma internal_cls the `struct NSEPeerEntry` for the @a peer | 1215 | * @parma internal_cls the `struct NSEPeerEntry` for the @a peer |
1214 | */ | 1216 | */ |
1215 | static void | 1217 | static void |
1216 | handle_core_disconnect(void *cls, | 1218 | handle_core_disconnect (void *cls, |
1217 | const struct GNUNET_PeerIdentity *peer, | 1219 | const struct GNUNET_PeerIdentity *peer, |
1218 | void *internal_cls) | 1220 | void *internal_cls) |
1219 | { | 1221 | { |
1220 | struct NSEPeerEntry *pos = internal_cls; | 1222 | struct NSEPeerEntry *pos = internal_cls; |
1221 | 1223 | ||
1222 | (void)cls; | 1224 | (void) cls; |
1223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1224 | "Peer `%s' disconnected from us\n", | 1226 | "Peer `%s' disconnected from us\n", |
1225 | GNUNET_i2s(peer)); | 1227 | GNUNET_i2s (peer)); |
1226 | GNUNET_assert(GNUNET_YES == | 1228 | GNUNET_assert (GNUNET_YES == |
1227 | GNUNET_CONTAINER_multipeermap_remove(peers, peer, pos)); | 1229 | GNUNET_CONTAINER_multipeermap_remove (peers, peer, pos)); |
1228 | if (NULL != pos->transmit_task) | 1230 | if (NULL != pos->transmit_task) |
1229 | { | 1231 | { |
1230 | GNUNET_SCHEDULER_cancel(pos->transmit_task); | 1232 | GNUNET_SCHEDULER_cancel (pos->transmit_task); |
1231 | pos->transmit_task = NULL; | 1233 | pos->transmit_task = NULL; |
1232 | } | 1234 | } |
1233 | GNUNET_free(pos); | 1235 | GNUNET_free (pos); |
1234 | GNUNET_STATISTICS_update(stats, "# peers connected", -1, GNUNET_NO); | 1236 | GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO); |
1235 | } | 1237 | } |
1236 | 1238 | ||
1237 | 1239 | ||
@@ -1244,11 +1246,11 @@ handle_core_disconnect(void *cls, | |||
1244 | * @param size the amount of data sent (ignored) | 1246 | * @param size the amount of data sent (ignored) |
1245 | */ | 1247 | */ |
1246 | static void | 1248 | static void |
1247 | flush_comp_cb(void *cls, size_t size) | 1249 | flush_comp_cb (void *cls, size_t size) |
1248 | { | 1250 | { |
1249 | (void)cls; | 1251 | (void) cls; |
1250 | (void)size; | 1252 | (void) size; |
1251 | GNUNET_TESTBED_LOGGER_disconnect(lh); | 1253 | GNUNET_TESTBED_LOGGER_disconnect (lh); |
1252 | lh = NULL; | 1254 | lh = NULL; |
1253 | } | 1255 | } |
1254 | #endif | 1256 | #endif |
@@ -1260,60 +1262,60 @@ flush_comp_cb(void *cls, size_t size) | |||
1260 | * @param cls unused | 1262 | * @param cls unused |
1261 | */ | 1263 | */ |
1262 | static void | 1264 | static void |
1263 | shutdown_task(void *cls) | 1265 | shutdown_task (void *cls) |
1264 | { | 1266 | { |
1265 | (void)cls; | 1267 | (void) cls; |
1266 | if (NULL != flood_task) | 1268 | if (NULL != flood_task) |
1267 | { | 1269 | { |
1268 | GNUNET_SCHEDULER_cancel(flood_task); | 1270 | GNUNET_SCHEDULER_cancel (flood_task); |
1269 | flood_task = NULL; | 1271 | flood_task = NULL; |
1270 | } | 1272 | } |
1271 | if (NULL != proof_task) | 1273 | if (NULL != proof_task) |
1272 | { | 1274 | { |
1273 | GNUNET_SCHEDULER_cancel(proof_task); | 1275 | GNUNET_SCHEDULER_cancel (proof_task); |
1274 | proof_task = NULL; | 1276 | proof_task = NULL; |
1275 | write_proof(); /* remember progress */ | 1277 | write_proof (); /* remember progress */ |
1276 | } | 1278 | } |
1277 | if (NULL != nc) | 1279 | if (NULL != nc) |
1278 | { | 1280 | { |
1279 | GNUNET_notification_context_destroy(nc); | 1281 | GNUNET_notification_context_destroy (nc); |
1280 | nc = NULL; | 1282 | nc = NULL; |
1281 | } | 1283 | } |
1282 | if (NULL != core_api) | 1284 | if (NULL != core_api) |
1283 | { | 1285 | { |
1284 | GNUNET_CORE_disconnect(core_api); | 1286 | GNUNET_CORE_disconnect (core_api); |
1285 | core_api = NULL; | 1287 | core_api = NULL; |
1286 | } | 1288 | } |
1287 | if (NULL != stats) | 1289 | if (NULL != stats) |
1288 | { | 1290 | { |
1289 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 1291 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1290 | stats = NULL; | 1292 | stats = NULL; |
1291 | } | 1293 | } |
1292 | if (NULL != peers) | 1294 | if (NULL != peers) |
1293 | { | 1295 | { |
1294 | GNUNET_CONTAINER_multipeermap_destroy(peers); | 1296 | GNUNET_CONTAINER_multipeermap_destroy (peers); |
1295 | peers = NULL; | 1297 | peers = NULL; |
1296 | } | 1298 | } |
1297 | if (NULL != my_private_key) | 1299 | if (NULL != my_private_key) |
1298 | { | 1300 | { |
1299 | GNUNET_free(my_private_key); | 1301 | GNUNET_free (my_private_key); |
1300 | my_private_key = NULL; | 1302 | my_private_key = NULL; |
1301 | } | 1303 | } |
1302 | #if ENABLE_NSE_HISTOGRAM | 1304 | #if ENABLE_NSE_HISTOGRAM |
1303 | if (NULL != logger_test) | 1305 | if (NULL != logger_test) |
1304 | { | 1306 | { |
1305 | GNUNET_CLIENT_service_test_cancel(logger_test); | 1307 | GNUNET_CLIENT_service_test_cancel (logger_test); |
1306 | logger_test = NULL; | 1308 | logger_test = NULL; |
1307 | } | 1309 | } |
1308 | if (NULL != lh) | 1310 | if (NULL != lh) |
1309 | { | 1311 | { |
1310 | GNUNET_TESTBED_LOGGER_flush(lh, &flush_comp_cb, NULL); | 1312 | GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL); |
1311 | } | 1313 | } |
1312 | if (NULL != histogram) | 1314 | if (NULL != histogram) |
1313 | { | 1315 | { |
1314 | GNUNET_BIO_write_close(histogram); | 1316 | GNUNET_BIO_write_close (histogram); |
1315 | histogram = NULL; | 1317 | histogram = NULL; |
1316 | } | 1318 | } |
1317 | #endif | 1319 | #endif |
1318 | } | 1320 | } |
1319 | 1321 | ||
@@ -1325,38 +1327,38 @@ shutdown_task(void *cls) | |||
1325 | * @param identity the public identity of this peer | 1327 | * @param identity the public identity of this peer |
1326 | */ | 1328 | */ |
1327 | static void | 1329 | static void |
1328 | core_init(void *cls, const struct GNUNET_PeerIdentity *identity) | 1330 | core_init (void *cls, const struct GNUNET_PeerIdentity *identity) |
1329 | { | 1331 | { |
1330 | struct GNUNET_TIME_Absolute now; | 1332 | struct GNUNET_TIME_Absolute now; |
1331 | struct GNUNET_TIME_Absolute prev_time; | 1333 | struct GNUNET_TIME_Absolute prev_time; |
1332 | 1334 | ||
1333 | (void)cls; | 1335 | (void) cls; |
1334 | if (NULL == identity) | 1336 | if (NULL == identity) |
1335 | { | 1337 | { |
1336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); | 1338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); |
1337 | GNUNET_SCHEDULER_shutdown(); | 1339 | GNUNET_SCHEDULER_shutdown (); |
1338 | return; | 1340 | return; |
1339 | } | 1341 | } |
1340 | GNUNET_assert(0 == GNUNET_memcmp(&my_identity, identity)); | 1342 | GNUNET_assert (0 == GNUNET_memcmp (&my_identity, identity)); |
1341 | now = GNUNET_TIME_absolute_get(); | 1343 | now = GNUNET_TIME_absolute_get (); |
1342 | current_timestamp.abs_value_us = | 1344 | current_timestamp.abs_value_us = |
1343 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * | 1345 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) |
1344 | gnunet_nse_interval.rel_value_us; | 1346 | * gnunet_nse_interval.rel_value_us; |
1345 | next_timestamp = | 1347 | next_timestamp = |
1346 | GNUNET_TIME_absolute_add(current_timestamp, gnunet_nse_interval); | 1348 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
1347 | estimate_index = HISTORY_SIZE - 1; | 1349 | estimate_index = HISTORY_SIZE - 1; |
1348 | estimate_count = 0; | 1350 | estimate_count = 0; |
1349 | if (GNUNET_YES == check_proof_of_work(&my_identity.public_key, my_proof)) | 1351 | if (GNUNET_YES == check_proof_of_work (&my_identity.public_key, my_proof)) |
1350 | { | 1352 | { |
1351 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1353 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1352 | prev_time.abs_value_us = | 1354 | prev_time.abs_value_us = |
1353 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; | 1355 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; |
1354 | setup_flood_message(idx, prev_time); | 1356 | setup_flood_message (idx, prev_time); |
1355 | setup_flood_message(estimate_index, current_timestamp); | 1357 | setup_flood_message (estimate_index, current_timestamp); |
1356 | estimate_count++; | 1358 | estimate_count++; |
1357 | } | 1359 | } |
1358 | flood_task = | 1360 | flood_task = |
1359 | GNUNET_SCHEDULER_add_at(next_timestamp, &update_flood_message, NULL); | 1361 | GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL); |
1360 | } | 1362 | } |
1361 | 1363 | ||
1362 | 1364 | ||
@@ -1370,21 +1372,21 @@ core_init(void *cls, const struct GNUNET_PeerIdentity *identity) | |||
1370 | * #GNUNET_SYSERR if the configuration is invalid | 1372 | * #GNUNET_SYSERR if the configuration is invalid |
1371 | */ | 1373 | */ |
1372 | static void | 1374 | static void |
1373 | status_cb(void *cls, int status) | 1375 | status_cb (void *cls, int status) |
1374 | { | 1376 | { |
1375 | (void)cls; | 1377 | (void) cls; |
1376 | logger_test = NULL; | 1378 | logger_test = NULL; |
1377 | if (GNUNET_YES != status) | 1379 | if (GNUNET_YES != status) |
1378 | { | 1380 | { |
1379 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n"); | 1381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n"); |
1380 | return; | 1382 | return; |
1381 | } | 1383 | } |
1382 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect(cfg))) | 1384 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg))) |
1383 | { | 1385 | { |
1384 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1385 | "Cannot connect to the testbed logger. Exiting.\n"); | 1387 | "Cannot connect to the testbed logger. Exiting.\n"); |
1386 | GNUNET_SCHEDULER_shutdown(); | 1388 | GNUNET_SCHEDULER_shutdown (); |
1387 | } | 1389 | } |
1388 | } | 1390 | } |
1389 | #endif | 1391 | #endif |
1390 | 1392 | ||
@@ -1397,127 +1399,127 @@ status_cb(void *cls, int status) | |||
1397 | * @param service the initialized service | 1399 | * @param service the initialized service |
1398 | */ | 1400 | */ |
1399 | static void | 1401 | static void |
1400 | run(void *cls, | 1402 | run (void *cls, |
1401 | const struct GNUNET_CONFIGURATION_Handle *c, | 1403 | const struct GNUNET_CONFIGURATION_Handle *c, |
1402 | struct GNUNET_SERVICE_Handle *service) | 1404 | struct GNUNET_SERVICE_Handle *service) |
1403 | { | 1405 | { |
1404 | struct GNUNET_MQ_MessageHandler core_handlers[] = | 1406 | struct GNUNET_MQ_MessageHandler core_handlers[] = |
1405 | { GNUNET_MQ_hd_fixed_size(p2p_estimate, | 1407 | { GNUNET_MQ_hd_fixed_size (p2p_estimate, |
1406 | GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, | 1408 | GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, |
1407 | struct GNUNET_NSE_FloodMessage, | 1409 | struct GNUNET_NSE_FloodMessage, |
1408 | NULL), | 1410 | NULL), |
1409 | GNUNET_MQ_handler_end() }; | 1411 | GNUNET_MQ_handler_end () }; |
1410 | char *proof; | 1412 | char *proof; |
1411 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 1413 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
1412 | 1414 | ||
1413 | (void)cls; | 1415 | (void) cls; |
1414 | (void)service; | 1416 | (void) service; |
1415 | cfg = c; | 1417 | cfg = c; |
1416 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, | 1418 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, |
1417 | "NSE", | 1419 | "NSE", |
1418 | "INTERVAL", | 1420 | "INTERVAL", |
1419 | &gnunet_nse_interval)) | 1421 | &gnunet_nse_interval)) |
1420 | { | 1422 | { |
1421 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL"); | 1423 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL"); |
1422 | GNUNET_SCHEDULER_shutdown(); | 1424 | GNUNET_SCHEDULER_shutdown (); |
1423 | return; | 1425 | return; |
1424 | } | 1426 | } |
1425 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, | 1427 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, |
1426 | "NSE", | 1428 | "NSE", |
1427 | "WORKDELAY", | 1429 | "WORKDELAY", |
1428 | &proof_find_delay)) | 1430 | &proof_find_delay)) |
1429 | { | 1431 | { |
1430 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY"); | 1432 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY"); |
1431 | GNUNET_SCHEDULER_shutdown(); | 1433 | GNUNET_SCHEDULER_shutdown (); |
1432 | return; | 1434 | return; |
1433 | } | 1435 | } |
1434 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 1436 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
1435 | "NSE", | 1437 | "NSE", |
1436 | "WORKBITS", | 1438 | "WORKBITS", |
1437 | &nse_work_required)) | 1439 | &nse_work_required)) |
1438 | { | 1440 | { |
1439 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); | 1441 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); |
1440 | GNUNET_SCHEDULER_shutdown(); | 1442 | GNUNET_SCHEDULER_shutdown (); |
1441 | return; | 1443 | return; |
1442 | } | 1444 | } |
1443 | if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8) | 1445 | if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8) |
1444 | { | 1446 | { |
1445 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 1447 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
1446 | "NSE", | 1448 | "NSE", |
1447 | "WORKBITS", | 1449 | "WORKBITS", |
1448 | _("Value is too large.\n")); | 1450 | _ ("Value is too large.\n")); |
1449 | GNUNET_SCHEDULER_shutdown(); | 1451 | GNUNET_SCHEDULER_shutdown (); |
1450 | return; | 1452 | return; |
1451 | } | 1453 | } |
1452 | 1454 | ||
1453 | #if ENABLE_NSE_HISTOGRAM | 1455 | #if ENABLE_NSE_HISTOGRAM |
1454 | { | 1456 | { |
1455 | char *histogram_dir; | 1457 | char *histogram_dir; |
1456 | char *histogram_fn; | 1458 | char *histogram_fn; |
1457 | 1459 | ||
1458 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, | 1460 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
1459 | "NSE", | 1461 | "NSE", |
1460 | "HISTOGRAM_DIR", | 1462 | "HISTOGRAM_DIR", |
1461 | &histogram_dir)) | 1463 | &histogram_dir)) |
1462 | { | 1464 | { |
1463 | GNUNET_assert( | 1465 | GNUNET_assert ( |
1464 | 0 < GNUNET_asprintf(&histogram_fn, "%s/timestamps", histogram_dir)); | 1466 | 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir)); |
1465 | GNUNET_free(histogram_dir); | 1467 | GNUNET_free (histogram_dir); |
1466 | histogram = GNUNET_BIO_write_open(histogram_fn); | 1468 | histogram = GNUNET_BIO_write_open (histogram_fn); |
1467 | if (NULL == histogram) | 1469 | if (NULL == histogram) |
1468 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1470 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1469 | "Unable to open histogram file `%s'\n", | 1471 | "Unable to open histogram file `%s'\n", |
1470 | histogram_fn); | 1472 | histogram_fn); |
1471 | GNUNET_free(histogram_fn); | 1473 | GNUNET_free (histogram_fn); |
1472 | } | 1474 | } |
1473 | logger_test = GNUNET_CLIENT_service_test("testbed-logger", | 1475 | logger_test = GNUNET_CLIENT_service_test ("testbed-logger", |
1474 | cfg, | 1476 | cfg, |
1475 | GNUNET_TIME_UNIT_SECONDS, | 1477 | GNUNET_TIME_UNIT_SECONDS, |
1476 | &status_cb, | 1478 | &status_cb, |
1477 | NULL); | 1479 | NULL); |
1478 | } | 1480 | } |
1479 | #endif | 1481 | #endif |
1480 | 1482 | ||
1481 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 1483 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
1482 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); | 1484 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); |
1483 | GNUNET_assert(NULL != pk); | 1485 | GNUNET_assert (NULL != pk); |
1484 | my_private_key = pk; | 1486 | my_private_key = pk; |
1485 | GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); | 1487 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); |
1486 | if (GNUNET_OK != | 1488 | if (GNUNET_OK != |
1487 | GNUNET_CONFIGURATION_get_value_filename(cfg, "NSE", "PROOFFILE", &proof)) | 1489 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) |
1488 | { | 1490 | { |
1489 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); | 1491 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); |
1490 | GNUNET_free(my_private_key); | 1492 | GNUNET_free (my_private_key); |
1491 | my_private_key = NULL; | 1493 | my_private_key = NULL; |
1492 | GNUNET_SCHEDULER_shutdown(); | 1494 | GNUNET_SCHEDULER_shutdown (); |
1493 | return; | 1495 | return; |
1494 | } | 1496 | } |
1495 | if ((GNUNET_YES != GNUNET_DISK_file_test(proof)) || | 1497 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || |
1496 | (sizeof(my_proof) != | 1498 | (sizeof(my_proof) != |
1497 | GNUNET_DISK_fn_read(proof, &my_proof, sizeof(my_proof)))) | 1499 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof(my_proof)))) |
1498 | my_proof = 0; | 1500 | my_proof = 0; |
1499 | GNUNET_free(proof); | 1501 | GNUNET_free (proof); |
1500 | proof_task = | 1502 | proof_task = |
1501 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | 1503 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1502 | &find_proof, | 1504 | &find_proof, |
1503 | NULL); | 1505 | NULL); |
1504 | 1506 | ||
1505 | peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); | 1507 | peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); |
1506 | nc = GNUNET_notification_context_create(1); | 1508 | nc = GNUNET_notification_context_create (1); |
1507 | /* Connect to core service and register core handlers */ | 1509 | /* Connect to core service and register core handlers */ |
1508 | core_api = | 1510 | core_api = |
1509 | GNUNET_CORE_connect(cfg, /* Main configuration */ | 1511 | GNUNET_CORE_connect (cfg, /* Main configuration */ |
1510 | NULL, /* Closure passed to functions */ | 1512 | NULL, /* Closure passed to functions */ |
1511 | &core_init, /* Call core_init once connected */ | 1513 | &core_init, /* Call core_init once connected */ |
1512 | &handle_core_connect, /* Handle connects */ | 1514 | &handle_core_connect, /* Handle connects */ |
1513 | &handle_core_disconnect, /* Handle disconnects */ | 1515 | &handle_core_disconnect, /* Handle disconnects */ |
1514 | core_handlers); /* Register these handlers */ | 1516 | core_handlers); /* Register these handlers */ |
1515 | if (NULL == core_api) | 1517 | if (NULL == core_api) |
1516 | { | 1518 | { |
1517 | GNUNET_SCHEDULER_shutdown(); | 1519 | GNUNET_SCHEDULER_shutdown (); |
1518 | return; | 1520 | return; |
1519 | } | 1521 | } |
1520 | stats = GNUNET_STATISTICS_create("nse", cfg); | 1522 | stats = GNUNET_STATISTICS_create ("nse", cfg); |
1521 | } | 1523 | } |
1522 | 1524 | ||
1523 | 1525 | ||
@@ -1530,12 +1532,12 @@ run(void *cls, | |||
1530 | * @return @a c | 1532 | * @return @a c |
1531 | */ | 1533 | */ |
1532 | static void * | 1534 | static void * |
1533 | client_connect_cb(void *cls, | 1535 | client_connect_cb (void *cls, |
1534 | struct GNUNET_SERVICE_Client *c, | 1536 | struct GNUNET_SERVICE_Client *c, |
1535 | struct GNUNET_MQ_Handle *mq) | 1537 | struct GNUNET_MQ_Handle *mq) |
1536 | { | 1538 | { |
1537 | (void)cls; | 1539 | (void) cls; |
1538 | (void)mq; | 1540 | (void) mq; |
1539 | return c; | 1541 | return c; |
1540 | } | 1542 | } |
1541 | 1543 | ||
@@ -1548,29 +1550,29 @@ client_connect_cb(void *cls, | |||
1548 | * @param internal_cls should be equal to @a c | 1550 | * @param internal_cls should be equal to @a c |
1549 | */ | 1551 | */ |
1550 | static void | 1552 | static void |
1551 | client_disconnect_cb(void *cls, | 1553 | client_disconnect_cb (void *cls, |
1552 | struct GNUNET_SERVICE_Client *c, | 1554 | struct GNUNET_SERVICE_Client *c, |
1553 | void *internal_cls) | 1555 | void *internal_cls) |
1554 | { | 1556 | { |
1555 | (void)cls; | 1557 | (void) cls; |
1556 | GNUNET_assert(c == internal_cls); | 1558 | GNUNET_assert (c == internal_cls); |
1557 | } | 1559 | } |
1558 | 1560 | ||
1559 | 1561 | ||
1560 | /** | 1562 | /** |
1561 | * Define "main" method using service macro. | 1563 | * Define "main" method using service macro. |
1562 | */ | 1564 | */ |
1563 | GNUNET_SERVICE_MAIN("nse", | 1565 | GNUNET_SERVICE_MAIN ("nse", |
1564 | GNUNET_SERVICE_OPTION_NONE, | 1566 | GNUNET_SERVICE_OPTION_NONE, |
1565 | &run, | 1567 | &run, |
1566 | &client_connect_cb, | 1568 | &client_connect_cb, |
1567 | &client_disconnect_cb, | 1569 | &client_disconnect_cb, |
1568 | NULL, | 1570 | NULL, |
1569 | GNUNET_MQ_hd_fixed_size(start, | 1571 | GNUNET_MQ_hd_fixed_size (start, |
1570 | GNUNET_MESSAGE_TYPE_NSE_START, | 1572 | GNUNET_MESSAGE_TYPE_NSE_START, |
1571 | struct GNUNET_MessageHeader, | 1573 | struct GNUNET_MessageHeader, |
1572 | NULL), | 1574 | NULL), |
1573 | GNUNET_MQ_handler_end()); | 1575 | GNUNET_MQ_handler_end ()); |
1574 | 1576 | ||
1575 | 1577 | ||
1576 | #if defined(LINUX) && defined(__GLIBC__) | 1578 | #if defined(LINUX) && defined(__GLIBC__) |
@@ -1579,11 +1581,11 @@ GNUNET_SERVICE_MAIN("nse", | |||
1579 | /** | 1581 | /** |
1580 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1582 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1581 | */ | 1583 | */ |
1582 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init() | 1584 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () |
1583 | { | 1585 | { |
1584 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); | 1586 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1585 | mallopt(M_TOP_PAD, 1 * 1024); | 1587 | mallopt (M_TOP_PAD, 1 * 1024); |
1586 | malloc_trim(0); | 1588 | malloc_trim (0); |
1587 | } | 1589 | } |
1588 | #endif | 1590 | #endif |
1589 | 1591 | ||
diff --git a/src/nse/nse.h b/src/nse/nse.h index b0129addd..5d1fccb7e 100644 --- a/src/nse/nse.h +++ b/src/nse/nse.h | |||
@@ -39,7 +39,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
39 | * standard deviation of known estimates. | 39 | * standard deviation of known estimates. |
40 | * | 40 | * |
41 | */ | 41 | */ |
42 | struct GNUNET_NSE_ClientMessage { | 42 | struct GNUNET_NSE_ClientMessage |
43 | { | ||
43 | /** | 44 | /** |
44 | * Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE | 45 | * Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE |
45 | */ | 46 | */ |
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index 93716eb5f..af6a2065b 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c | |||
@@ -32,12 +32,13 @@ | |||
32 | #include "gnunet_nse_service.h" | 32 | #include "gnunet_nse_service.h" |
33 | #include "nse.h" | 33 | #include "nse.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind, "nse-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for talking with the NSE service. | 38 | * Handle for talking with the NSE service. |
39 | */ | 39 | */ |
40 | struct GNUNET_NSE_Handle { | 40 | struct GNUNET_NSE_Handle |
41 | { | ||
41 | /** | 42 | /** |
42 | * Configuration to use. | 43 | * Configuration to use. |
43 | */ | 44 | */ |
@@ -76,7 +77,7 @@ struct GNUNET_NSE_Handle { | |||
76 | * @param cls closure with the `struct GNUNET_NSE_Handle *` | 77 | * @param cls closure with the `struct GNUNET_NSE_Handle *` |
77 | */ | 78 | */ |
78 | static void | 79 | static void |
79 | reconnect(void *cls); | 80 | reconnect (void *cls); |
80 | 81 | ||
81 | 82 | ||
82 | /** | 83 | /** |
@@ -89,16 +90,16 @@ reconnect(void *cls); | |||
89 | * @param error error code | 90 | * @param error error code |
90 | */ | 91 | */ |
91 | static void | 92 | static void |
92 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
93 | { | 94 | { |
94 | struct GNUNET_NSE_Handle *h = cls; | 95 | struct GNUNET_NSE_Handle *h = cls; |
95 | 96 | ||
96 | (void)error; | 97 | (void) error; |
97 | GNUNET_MQ_destroy(h->mq); | 98 | GNUNET_MQ_destroy (h->mq); |
98 | h->mq = NULL; | 99 | h->mq = NULL; |
99 | h->reconnect_task = | 100 | h->reconnect_task = |
100 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); | 101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
101 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); | 102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
@@ -110,15 +111,15 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
110 | * @param client_msg message received | 111 | * @param client_msg message received |
111 | */ | 112 | */ |
112 | static void | 113 | static void |
113 | handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | 114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
114 | { | 115 | { |
115 | struct GNUNET_NSE_Handle *h = cls; | 116 | struct GNUNET_NSE_Handle *h = cls; |
116 | 117 | ||
117 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 118 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
118 | h->recv_cb(h->recv_cb_cls, | 119 | h->recv_cb (h->recv_cb_cls, |
119 | GNUNET_TIME_absolute_ntoh(client_msg->timestamp), | 120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), |
120 | GNUNET_ntoh_double(client_msg->size_estimate), | 121 | GNUNET_ntoh_double (client_msg->size_estimate), |
121 | GNUNET_ntoh_double(client_msg->std_deviation)); | 122 | GNUNET_ntoh_double (client_msg->std_deviation)); |
122 | } | 123 | } |
123 | 124 | ||
124 | 125 | ||
@@ -128,27 +129,27 @@ handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | |||
128 | * @param cls the `struct GNUNET_NSE_Handle *` | 129 | * @param cls the `struct GNUNET_NSE_Handle *` |
129 | */ | 130 | */ |
130 | static void | 131 | static void |
131 | reconnect(void *cls) | 132 | reconnect (void *cls) |
132 | { | 133 | { |
133 | struct GNUNET_NSE_Handle *h = cls; | 134 | struct GNUNET_NSE_Handle *h = cls; |
134 | struct GNUNET_MQ_MessageHandler handlers[] = | 135 | struct GNUNET_MQ_MessageHandler handlers[] = |
135 | { GNUNET_MQ_hd_fixed_size(estimate, | 136 | { GNUNET_MQ_hd_fixed_size (estimate, |
136 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
137 | struct GNUNET_NSE_ClientMessage, | 138 | struct GNUNET_NSE_ClientMessage, |
138 | h), | 139 | h), |
139 | GNUNET_MQ_handler_end() }; | 140 | GNUNET_MQ_handler_end () }; |
140 | struct GNUNET_MessageHeader *msg; | 141 | struct GNUNET_MessageHeader *msg; |
141 | struct GNUNET_MQ_Envelope *env; | 142 | struct GNUNET_MQ_Envelope *env; |
142 | 143 | ||
143 | h->reconnect_task = NULL; | 144 | h->reconnect_task = NULL; |
144 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 145 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Connecting to network size estimation service.\n"); | 146 | "Connecting to network size estimation service.\n"); |
146 | GNUNET_assert(NULL == h->mq); | 147 | GNUNET_assert (NULL == h->mq); |
147 | h->mq = GNUNET_CLIENT_connect(h->cfg, "nse", handlers, &mq_error_handler, h); | 148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); |
148 | if (NULL == h->mq) | 149 | if (NULL == h->mq) |
149 | return; | 150 | return; |
150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NSE_START); | 151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); |
151 | GNUNET_MQ_send(h->mq, env); | 152 | GNUNET_MQ_send (h->mq, env); |
152 | } | 153 | } |
153 | 154 | ||
154 | 155 | ||
@@ -161,24 +162,24 @@ reconnect(void *cls) | |||
161 | * @return handle to use | 162 | * @return handle to use |
162 | */ | 163 | */ |
163 | struct GNUNET_NSE_Handle * | 164 | struct GNUNET_NSE_Handle * |
164 | GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 165 | GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
165 | GNUNET_NSE_Callback func, | 166 | GNUNET_NSE_Callback func, |
166 | void *func_cls) | 167 | void *func_cls) |
167 | { | 168 | { |
168 | struct GNUNET_NSE_Handle *h; | 169 | struct GNUNET_NSE_Handle *h; |
169 | 170 | ||
170 | GNUNET_assert(NULL != func); | 171 | GNUNET_assert (NULL != func); |
171 | h = GNUNET_new(struct GNUNET_NSE_Handle); | 172 | h = GNUNET_new (struct GNUNET_NSE_Handle); |
172 | h->cfg = cfg; | 173 | h->cfg = cfg; |
173 | h->recv_cb = func; | 174 | h->recv_cb = func; |
174 | h->recv_cb_cls = func_cls; | 175 | h->recv_cb_cls = func_cls; |
175 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 176 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
176 | reconnect(h); | 177 | reconnect (h); |
177 | if (NULL == h->mq) | 178 | if (NULL == h->mq) |
178 | { | 179 | { |
179 | GNUNET_free(h); | 180 | GNUNET_free (h); |
180 | return NULL; | 181 | return NULL; |
181 | } | 182 | } |
182 | return h; | 183 | return h; |
183 | } | 184 | } |
184 | 185 | ||
@@ -189,19 +190,19 @@ GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
189 | * @param h handle to destroy | 190 | * @param h handle to destroy |
190 | */ | 191 | */ |
191 | void | 192 | void |
192 | GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h) | 193 | GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h) |
193 | { | 194 | { |
194 | if (NULL != h->reconnect_task) | 195 | if (NULL != h->reconnect_task) |
195 | { | 196 | { |
196 | GNUNET_SCHEDULER_cancel(h->reconnect_task); | 197 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
197 | h->reconnect_task = NULL; | 198 | h->reconnect_task = NULL; |
198 | } | 199 | } |
199 | if (NULL != h->mq) | 200 | if (NULL != h->mq) |
200 | { | 201 | { |
201 | GNUNET_MQ_destroy(h->mq); | 202 | GNUNET_MQ_destroy (h->mq); |
202 | h->mq = NULL; | 203 | h->mq = NULL; |
203 | } | 204 | } |
204 | GNUNET_free(h); | 205 | GNUNET_free (h); |
205 | } | 206 | } |
206 | 207 | ||
207 | /* end of nse_api.c */ | 208 | /* end of nse_api.c */ |
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c index bf4dbe0b2..a6c1432c8 100644 --- a/src/nse/perf_kdf.c +++ b/src/nse/perf_kdf.c | |||
@@ -38,47 +38,49 @@ | |||
38 | * @param result where to write the resulting hash | 38 | * @param result where to write the resulting hash |
39 | */ | 39 | */ |
40 | static void | 40 | static void |
41 | pow_hash(const void *buf, | 41 | pow_hash (const void *buf, |
42 | size_t buf_len, | 42 | size_t buf_len, |
43 | struct GNUNET_HashCode *result) | 43 | struct GNUNET_HashCode *result) |
44 | { | 44 | { |
45 | GNUNET_break(0 == | 45 | GNUNET_break (0 == |
46 | gcry_kdf_derive(buf, buf_len, | 46 | gcry_kdf_derive (buf, buf_len, |
47 | GCRY_KDF_SCRYPT, | 47 | GCRY_KDF_SCRYPT, |
48 | 1 /* subalgo */, | 48 | 1 /* subalgo */, |
49 | "gnunet-proof-of-work", strlen("gnunet-proof-of-work"), | 49 | "gnunet-proof-of-work", strlen ( |
50 | 2 /* iterations; keep cost of individual op small */, | 50 | "gnunet-proof-of-work"), |
51 | sizeof(struct GNUNET_HashCode), result)); | 51 | 2 /* iterations; keep cost of individual op small */, |
52 | sizeof(struct GNUNET_HashCode), result)); | ||
52 | } | 53 | } |
53 | 54 | ||
54 | 55 | ||
55 | static void | 56 | static void |
56 | perfHash() | 57 | perfHash () |
57 | { | 58 | { |
58 | struct GNUNET_HashCode hc; | 59 | struct GNUNET_HashCode hc; |
59 | unsigned int i; | 60 | unsigned int i; |
60 | char buf[64]; | 61 | char buf[64]; |
61 | 62 | ||
62 | memset(buf, 1, sizeof(buf)); | 63 | memset (buf, 1, sizeof(buf)); |
63 | for (i = 0; i < 1024; i++) | 64 | for (i = 0; i < 1024; i++) |
64 | pow_hash(buf, sizeof(buf), &hc); | 65 | pow_hash (buf, sizeof(buf), &hc); |
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
68 | int | 69 | int |
69 | main(int argc, char *argv[]) | 70 | main (int argc, char *argv[]) |
70 | { | 71 | { |
71 | struct GNUNET_TIME_Absolute start; | 72 | struct GNUNET_TIME_Absolute start; |
72 | 73 | ||
73 | start = GNUNET_TIME_absolute_get(); | 74 | start = GNUNET_TIME_absolute_get (); |
74 | perfHash(); | 75 | perfHash (); |
75 | printf("Hash perf took %s\n", | 76 | printf ("Hash perf took %s\n", |
76 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), | 77 | GNUNET_STRINGS_relative_time_to_string ( |
77 | GNUNET_YES)); | 78 | GNUNET_TIME_absolute_get_duration (start), |
78 | GAUGER("NSE", "Proof-of-work hashing", | 79 | GNUNET_YES)); |
79 | 1024.0 / (1.0 + | 80 | GAUGER ("NSE", "Proof-of-work hashing", |
80 | GNUNET_TIME_absolute_get_duration | 81 | 1024.0 / (1.0 |
81 | (start).rel_value_us / 1000.0), "hashes/ms"); | 82 | + GNUNET_TIME_absolute_get_duration |
83 | (start).rel_value_us / 1000.0), "hashes/ms"); | ||
82 | return 0; | 84 | return 0; |
83 | } | 85 | } |
84 | 86 | ||
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c index b739e05a2..3b9682696 100644 --- a/src/nse/test_nse_api.c +++ b/src/nse/test_nse_api.c | |||
@@ -29,7 +29,7 @@ | |||
29 | 29 | ||
30 | static struct GNUNET_NSE_Handle *h; | 30 | static struct GNUNET_NSE_Handle *h; |
31 | 31 | ||
32 | static struct GNUNET_SCHEDULER_Task * die_task; | 32 | static struct GNUNET_SCHEDULER_Task *die_task; |
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
@@ -38,13 +38,13 @@ static struct GNUNET_SCHEDULER_Task * die_task; | |||
38 | * @param cls closure | 38 | * @param cls closure |
39 | */ | 39 | */ |
40 | static void | 40 | static void |
41 | end_test(void *cls) | 41 | end_test (void *cls) |
42 | { | 42 | { |
43 | if (h != NULL) | 43 | if (h != NULL) |
44 | { | 44 | { |
45 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n"); | 45 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n"); |
46 | GNUNET_NSE_disconnect(h); | 46 | GNUNET_NSE_disconnect (h); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
@@ -58,46 +58,46 @@ end_test(void *cls) | |||
58 | * | 58 | * |
59 | */ | 59 | */ |
60 | static void | 60 | static void |
61 | check_nse_message(void *cls, struct GNUNET_TIME_Absolute timestamp, | 61 | check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp, |
62 | double estimate, double std_dev) | 62 | double estimate, double std_dev) |
63 | { | 63 | { |
64 | int *ok = cls; | 64 | int *ok = cls; |
65 | 65 | ||
66 | fprintf(stderr, | 66 | fprintf (stderr, |
67 | "Received NSE message, estimate %f, standard deviation %f.\n", | 67 | "Received NSE message, estimate %f, standard deviation %f.\n", |
68 | estimate, std_dev); | 68 | estimate, std_dev); |
69 | /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ | 69 | /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ |
70 | (*ok) = 0; | 70 | (*ok) = 0; |
71 | if (die_task != NULL) | 71 | if (die_task != NULL) |
72 | GNUNET_SCHEDULER_cancel(die_task); | 72 | GNUNET_SCHEDULER_cancel (die_task); |
73 | die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL); | 73 | die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static void | 77 | static void |
78 | run(void *cls, | 78 | run (void *cls, |
79 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 79 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
80 | struct GNUNET_TESTING_Peer *peer) | 80 | struct GNUNET_TESTING_Peer *peer) |
81 | { | 81 | { |
82 | die_task = | 82 | die_task = |
83 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply | 83 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
84 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_test, | 84 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_test, |
85 | NULL); | 85 | NULL); |
86 | 86 | ||
87 | h = GNUNET_NSE_connect(cfg, &check_nse_message, cls); | 87 | h = GNUNET_NSE_connect (cfg, &check_nse_message, cls); |
88 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n"); | 88 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n"); |
89 | GNUNET_assert(h != NULL); | 89 | GNUNET_assert (h != NULL); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | int | 93 | int |
94 | main(int argc, char *argv[]) | 94 | main (int argc, char *argv[]) |
95 | { | 95 | { |
96 | int ok = 1; | 96 | int ok = 1; |
97 | 97 | ||
98 | if (0 != GNUNET_TESTING_peer_run("test_nse_api", | 98 | if (0 != GNUNET_TESTING_peer_run ("test_nse_api", |
99 | "test_nse.conf", | 99 | "test_nse.conf", |
100 | &run, &ok)) | 100 | &run, &ok)) |
101 | return 1; | 101 | return 1; |
102 | return ok; | 102 | return ok; |
103 | } | 103 | } |
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c index 88ced26d2..4c998373e 100644 --- a/src/nse/test_nse_multipeer.c +++ b/src/nse/test_nse_multipeer.c | |||
@@ -37,13 +37,14 @@ | |||
37 | /** | 37 | /** |
38 | * How long do we run the test? | 38 | * How long do we run the test? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Information we track for each peer. | 44 | * Information we track for each peer. |
45 | */ | 45 | */ |
46 | struct NSEPeer { | 46 | struct NSEPeer |
47 | { | ||
47 | /** | 48 | /** |
48 | * Handle for NSE connect operation. | 49 | * Handle for NSE connect operation. |
49 | */ | 50 | */ |
@@ -71,13 +72,13 @@ static int ok; | |||
71 | * Task run on timeout to shut everything down. | 72 | * Task run on timeout to shut everything down. |
72 | */ | 73 | */ |
73 | static void | 74 | static void |
74 | shutdown_task(void *cls) | 75 | shutdown_task (void *cls) |
75 | { | 76 | { |
76 | unsigned int i; | 77 | unsigned int i; |
77 | 78 | ||
78 | for (i = 0; i < NUM_PEERS; i++) | 79 | for (i = 0; i < NUM_PEERS; i++) |
79 | GNUNET_TESTBED_operation_done(nse_peers[i].op); | 80 | GNUNET_TESTBED_operation_done (nse_peers[i].op); |
80 | GNUNET_SCHEDULER_shutdown(); | 81 | GNUNET_SCHEDULER_shutdown (); |
81 | } | 82 | } |
82 | 83 | ||
83 | 84 | ||
@@ -92,17 +93,17 @@ shutdown_task(void *cls) | |||
92 | * | 93 | * |
93 | */ | 94 | */ |
94 | static void | 95 | static void |
95 | handle_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, | 96 | handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, |
96 | double estimate, double std_dev) | 97 | double estimate, double std_dev) |
97 | { | 98 | { |
98 | struct NSEPeer *peer = cls; | 99 | struct NSEPeer *peer = cls; |
99 | 100 | ||
100 | fprintf(stderr, | 101 | fprintf (stderr, |
101 | "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", | 102 | "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", |
102 | (unsigned int)(peer - nse_peers), | 103 | (unsigned int) (peer - nse_peers), |
103 | estimate, std_dev, | 104 | estimate, std_dev, |
104 | GNUNET_NSE_log_estimate_to_n(estimate), | 105 | GNUNET_NSE_log_estimate_to_n (estimate), |
105 | NUM_PEERS); | 106 | NUM_PEERS); |
106 | ok = 0; | 107 | ok = 0; |
107 | } | 108 | } |
108 | 109 | ||
@@ -117,24 +118,24 @@ handle_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, | |||
117 | * operation has executed successfully. | 118 | * operation has executed successfully. |
118 | */ | 119 | */ |
119 | static void | 120 | static void |
120 | nse_connect_complete_cb(void *cls, | 121 | nse_connect_complete_cb (void *cls, |
121 | struct GNUNET_TESTBED_Operation *op, | 122 | struct GNUNET_TESTBED_Operation *op, |
122 | void *ca_result, | 123 | void *ca_result, |
123 | const char *emsg) | 124 | const char *emsg) |
124 | { | 125 | { |
125 | struct NSEPeer *peer = cls; | 126 | struct NSEPeer *peer = cls; |
126 | struct GNUNET_NSE_Handle *nse = ca_result; | 127 | struct GNUNET_NSE_Handle *nse = ca_result; |
127 | 128 | ||
128 | GNUNET_assert(op == peer->op); | 129 | GNUNET_assert (op == peer->op); |
129 | if (NULL != emsg) | 130 | if (NULL != emsg) |
130 | { | 131 | { |
131 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
132 | "Failed to connect to NSE service: %s\n", | 133 | "Failed to connect to NSE service: %s\n", |
133 | emsg); | 134 | emsg); |
134 | ok = 1; | 135 | ok = 1; |
135 | GNUNET_SCHEDULER_shutdown(); | 136 | GNUNET_SCHEDULER_shutdown (); |
136 | return; | 137 | return; |
137 | } | 138 | } |
138 | peer->nse_handle = nse; | 139 | peer->nse_handle = nse; |
139 | } | 140 | } |
140 | 141 | ||
@@ -150,12 +151,12 @@ nse_connect_complete_cb(void *cls, | |||
150 | * @return service handle to return in 'op_result', NULL on error | 151 | * @return service handle to return in 'op_result', NULL on error |
151 | */ | 152 | */ |
152 | static void * | 153 | static void * |
153 | nse_connect_adapter(void *cls, | 154 | nse_connect_adapter (void *cls, |
154 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 155 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
155 | { | 156 | { |
156 | return GNUNET_NSE_connect(cfg, | 157 | return GNUNET_NSE_connect (cfg, |
157 | &handle_estimate, | 158 | &handle_estimate, |
158 | cls); | 159 | cls); |
159 | } | 160 | } |
160 | 161 | ||
161 | 162 | ||
@@ -167,10 +168,10 @@ nse_connect_adapter(void *cls, | |||
167 | * @param op_result service handle returned from the connect adapter | 168 | * @param op_result service handle returned from the connect adapter |
168 | */ | 169 | */ |
169 | static void | 170 | static void |
170 | nse_disconnect_adapter(void *cls, | 171 | nse_disconnect_adapter (void *cls, |
171 | void *op_result) | 172 | void *op_result) |
172 | { | 173 | { |
173 | GNUNET_NSE_disconnect(op_result); | 174 | GNUNET_NSE_disconnect (op_result); |
174 | } | 175 | } |
175 | 176 | ||
176 | 177 | ||
@@ -187,27 +188,27 @@ nse_disconnect_adapter(void *cls, | |||
187 | * failed | 188 | * failed |
188 | */ | 189 | */ |
189 | static void | 190 | static void |
190 | run(void *cls, | 191 | run (void *cls, |
191 | struct GNUNET_TESTBED_RunHandle *h, | 192 | struct GNUNET_TESTBED_RunHandle *h, |
192 | unsigned int num_peers, | 193 | unsigned int num_peers, |
193 | struct GNUNET_TESTBED_Peer **peers, | 194 | struct GNUNET_TESTBED_Peer **peers, |
194 | unsigned int links_succeeded, | 195 | unsigned int links_succeeded, |
195 | unsigned int links_failed) | 196 | unsigned int links_failed) |
196 | { | 197 | { |
197 | unsigned int i; | 198 | unsigned int i; |
198 | 199 | ||
199 | GNUNET_assert(NUM_PEERS == num_peers); | 200 | GNUNET_assert (NUM_PEERS == num_peers); |
200 | for (i = 0; i < num_peers; i++) | 201 | for (i = 0; i < num_peers; i++) |
201 | nse_peers[i].op = GNUNET_TESTBED_service_connect(&nse_peers[i], | 202 | nse_peers[i].op = GNUNET_TESTBED_service_connect (&nse_peers[i], |
202 | peers[i], | 203 | peers[i], |
203 | "nse", | 204 | "nse", |
204 | &nse_connect_complete_cb, | 205 | &nse_connect_complete_cb, |
205 | &nse_peers[i], | 206 | &nse_peers[i], |
206 | &nse_connect_adapter, | 207 | &nse_connect_adapter, |
207 | &nse_disconnect_adapter, | 208 | &nse_disconnect_adapter, |
208 | &nse_peers[i]); | 209 | &nse_peers[i]); |
209 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 210 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
210 | &shutdown_task, NULL); | 211 | &shutdown_task, NULL); |
211 | } | 212 | } |
212 | 213 | ||
213 | 214 | ||
@@ -219,14 +220,14 @@ run(void *cls, | |||
219 | * @return 0 on success | 220 | * @return 0 on success |
220 | */ | 221 | */ |
221 | int | 222 | int |
222 | main(int argc, char *argv[]) | 223 | main (int argc, char *argv[]) |
223 | { | 224 | { |
224 | ok = 1; | 225 | ok = 1; |
225 | (void)GNUNET_TESTBED_test_run("test-nse-multipeer", | 226 | (void) GNUNET_TESTBED_test_run ("test-nse-multipeer", |
226 | "test_nse.conf", | 227 | "test_nse.conf", |
227 | NUM_PEERS, | 228 | NUM_PEERS, |
228 | 0, NULL, NULL, | 229 | 0, NULL, NULL, |
229 | &run, NULL); | 230 | &run, NULL); |
230 | return ok; | 231 | return ok; |
231 | } | 232 | } |
232 | 233 | ||