aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-service-nse.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/nse/gnunet-service-nse.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r--src/nse/gnunet-service-nse.c1280
1 files changed, 641 insertions, 639 deletions
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 */
120struct NSEPeerEntry { 120struct 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 */
169struct GNUNET_NSE_FloodMessage { 170struct 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 */
319static void 321static void
320setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) 322setup_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 */
420static void 422static void
421handle_start(void *cls, const struct GNUNET_MessageHeader *message) 423handle_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 */
445static double 447static double
446get_matching_bits_delay(uint32_t matching_bits) 448get_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 */
465static struct GNUNET_TIME_Relative 467static struct GNUNET_TIME_Relative
466get_delay_randomization(uint32_t matching_bits) 468get_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 */
495static void 497static void
496pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result) 498pow_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 */
518static uint32_t 520static uint32_t
519get_matching_bits(struct GNUNET_TIME_Absolute timestamp, 521get_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(&timestamp.abs_value_us, 527 GNUNET_CRYPTO_hash (&timestamp.abs_value_us,
526 sizeof(timestamp.abs_value_us), 528 sizeof(timestamp.abs_value_us),
527 &timestamp_hash); 529 &timestamp_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(&timestamp_hash, &pid_hash); 531 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_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 */
541static struct GNUNET_TIME_Relative 543static struct GNUNET_TIME_Relative
542get_transmit_delay(int round_offset) 544get_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 */
590static void 592static void
591transmit_task_cb(void *cls) 593transmit_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 */
654static void 656static void
655update_network_size_estimate() 657update_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 */
671static void 673static void
672setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts) 674setup_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 */
709static int 711static int
710schedule_current_round(void *cls, 712schedule_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 */
747static void 749static void
748update_flood_message(void *cls) 750update_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 */
797static unsigned int 799static unsigned int
798count_leading_zeroes(const struct GNUNET_HashCode *hash) 800count_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 */
817static int 819static int
818check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, 820check_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 */
838static void 840static void
839write_proof() 841write_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 */
861static void 863static void
862find_proof(void *cls) 864find_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 */
925static int 927static int
926verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood) 928verify_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 */
961static int 963static int
962update_flood_times(void *cls, 964update_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 */
1001static void 1003static void
1002handle_p2p_estimate(void *cls, 1004handle_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 */
1175static void * 1177static void *
1176handle_core_connect(void *cls, 1178handle_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 */
1215static void 1217static void
1216handle_core_disconnect(void *cls, 1218handle_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 */
1246static void 1248static void
1247flush_comp_cb(void *cls, size_t size) 1249flush_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 */
1262static void 1264static void
1263shutdown_task(void *cls) 1265shutdown_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 */
1327static void 1329static void
1328core_init(void *cls, const struct GNUNET_PeerIdentity *identity) 1330core_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 */
1372static void 1374static void
1373status_cb(void *cls, int status) 1375status_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 */
1399static void 1401static void
1400run(void *cls, 1402run (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 */
1532static void * 1534static void *
1533client_connect_cb(void *cls, 1535client_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 */
1550static void 1552static void
1551client_disconnect_cb(void *cls, 1553client_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 */
1563GNUNET_SERVICE_MAIN("nse", 1565GNUNET_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 */
1582void __attribute__ ((constructor)) GNUNET_ARM_memory_init() 1584void __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