aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-service-nse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r--src/nse/gnunet-service-nse.c1097
1 files changed, 530 insertions, 567 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 84a4ea9f0..9da9abba2 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -314,35 +314,33 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
314 sum = 0.0; 314 sum = 0.0;
315 sumweight = 0.0; 315 sumweight = 0.0;
316 for (i = 0; i < estimate_count; i++) 316 for (i = 0; i < estimate_count; i++)
317 { 317 {
318 val = htonl (size_estimate_messages[(estimate_index - i + HISTORY_SIZE) 318 val = htonl (size_estimate_messages[(estimate_index - i + HISTORY_SIZE)
319 % HISTORY_SIZE].matching_bits); 319 % HISTORY_SIZE].matching_bits);
320 weight = 1; /* was: estimate_count + 1 - i; */ 320 weight = 1; /* was: estimate_count + 1 - i; */
321 321
322 temp = weight + sumweight; 322 temp = weight + sumweight;
323 q = val - mean; 323 q = val - mean;
324 r = q * weight / temp; 324 r = q * weight / temp;
325 sum += sumweight * q * r; 325 sum += sumweight * q * r;
326 mean += r; 326 mean += r;
327 sumweight = temp; 327 sumweight = temp;
328 } 328 }
329 variance = sum / (sumweight - 1.0); 329 variance = sum / (sumweight - 1.0);
330 GNUNET_assert (variance >= 0); 330 GNUNET_assert (variance >= 0);
331 std_dev = sqrt (variance); 331 std_dev = sqrt (variance);
332 current_std_dev = std_dev; 332 current_std_dev = std_dev;
333 current_size_estimate = mean; 333 current_size_estimate = mean;
334 334
335 em->header.size 335 em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage));
336 = htons (sizeof(struct GNUNET_NSE_ClientMessage)); 336 em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
337 em->header.type
338 = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE);
339 em->reserved = htonl (0); 337 em->reserved = htonl (0);
340 em->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); 338 em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
341 em->size_estimate = mean - 1.0/3.0; 339 em->size_estimate = mean - 1.0 / 3.0;
342 em->std_deviation = std_dev; 340 em->std_deviation = std_dev;
343 GNUNET_STATISTICS_set (stats, 341 GNUNET_STATISTICS_set (stats,
344 "# nodes in the network (estimate)", 342 "# nodes in the network (estimate)",
345 (uint64_t) pow (2, mean - 1.0/3.0), GNUNET_NO); 343 (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO);
346} 344}
347 345
348 346
@@ -357,18 +355,18 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
357 * @param message the message received 355 * @param message the message received
358 */ 356 */
359static void 357static void
360handle_start_message(void *cls, struct GNUNET_SERVER_Client *client, 358handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
361 const struct GNUNET_MessageHeader *message) 359 const struct GNUNET_MessageHeader *message)
362{ 360{
363 struct GNUNET_NSE_ClientMessage em; 361 struct GNUNET_NSE_ClientMessage em;
364 362
365#if DEBUG_NSE 363#if DEBUG_NSE
366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
367 "Received START message from client\n");
368#endif 365#endif
369 GNUNET_SERVER_notification_context_add (nc, client); 366 GNUNET_SERVER_notification_context_add (nc, client);
370 setup_estimate_message (&em); 367 setup_estimate_message (&em);
371 GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 368 GNUNET_SERVER_notification_context_unicast (nc, client, &em.header,
369 GNUNET_YES);
372 GNUNET_SERVER_receive_done (client, GNUNET_OK); 370 GNUNET_SERVER_receive_done (client, GNUNET_OK);
373} 371}
374 372
@@ -382,13 +380,15 @@ handle_start_message(void *cls, struct GNUNET_SERVER_Client *client,
382static double 380static double
383get_matching_bits_delay (uint32_t matching_bits) 381get_matching_bits_delay (uint32_t matching_bits)
384{ 382{
385 /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/ 383 /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */
386 // S is next_timestamp (ignored in return value) 384 // S is next_timestamp (ignored in return value)
387 // f is frequency (gnunet_nse_interval) 385 // f is frequency (gnunet_nse_interval)
388 // x is matching_bits 386 // x is matching_bits
389 // p' is current_size_estimate 387 // p' is current_size_estimate
390 return ((double) gnunet_nse_interval.rel_value / (double) 2.0) 388 return ((double) gnunet_nse_interval.rel_value / (double) 2.0)
391 - ((gnunet_nse_interval.rel_value / M_PI) * atan (matching_bits - current_size_estimate)); 389 -
390 ((gnunet_nse_interval.rel_value / M_PI) *
391 atan (matching_bits - current_size_estimate));
392} 392}
393 393
394 394
@@ -398,7 +398,7 @@ get_matching_bits_delay (uint32_t matching_bits)
398 * @param matching_bits number of matching bits 398 * @param matching_bits number of matching bits
399 * @return random delay to apply 399 * @return random delay to apply
400 */ 400 */
401static struct GNUNET_TIME_Relative 401static struct GNUNET_TIME_Relative
402get_delay_randomization (uint32_t matching_bits) 402get_delay_randomization (uint32_t matching_bits)
403{ 403{
404#if USE_RANDOM_DELAYS 404#if USE_RANDOM_DELAYS
@@ -407,7 +407,11 @@ get_delay_randomization (uint32_t matching_bits)
407 if (matching_bits == 0) 407 if (matching_bits == 0)
408 return GNUNET_TIME_UNIT_ZERO; 408 return GNUNET_TIME_UNIT_ZERO;
409 ret.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 409 ret.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
410 (uint32_t) (get_matching_bits_delay (matching_bits - 1) / (double) (hop_count_max + 1))); 410 (uint32_t) (get_matching_bits_delay
411 (matching_bits -
412 1) /
413 (double) (hop_count_max
414 + 1)));
411 return ret; 415 return ret;
412#else 416#else
413 return GNUNET_TIME_UNIT_ZERO; 417 return GNUNET_TIME_UNIT_ZERO;
@@ -424,15 +428,13 @@ get_delay_randomization (uint32_t matching_bits)
424 */ 428 */
425static uint32_t 429static uint32_t
426get_matching_bits (struct GNUNET_TIME_Absolute timestamp, 430get_matching_bits (struct GNUNET_TIME_Absolute timestamp,
427 const struct GNUNET_PeerIdentity *id) 431 const struct GNUNET_PeerIdentity *id)
428{ 432{
429 GNUNET_HashCode timestamp_hash; 433 GNUNET_HashCode timestamp_hash;
430 434
431 GNUNET_CRYPTO_hash (&timestamp.abs_value, 435 GNUNET_CRYPTO_hash (&timestamp.abs_value,
432 sizeof(timestamp.abs_value), 436 sizeof (timestamp.abs_value), &timestamp_hash);
433 &timestamp_hash); 437 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash, &id->hashPubKey);
434 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash,
435 &id->hashPubKey);
436} 438}
437 439
438 440
@@ -453,38 +455,38 @@ get_transmit_delay (int round_offset)
453 uint32_t matching_bits; 455 uint32_t matching_bits;
454 456
455 switch (round_offset) 457 switch (round_offset)
456 { 458 {
457 case -1: 459 case -1:
458 /* previous round is randomized between 0 and 50 ms */ 460 /* previous round is randomized between 0 and 50 ms */
459#if USE_RANDOM_DELAYS 461#if USE_RANDOM_DELAYS
460 ret.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 462 ret.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50);
461 50);
462#else 463#else
463 ret = GNUNET_TIME_UNIT_ZERO; 464 ret = GNUNET_TIME_UNIT_ZERO;
464#endif 465#endif
465#if DEBUG_NSE 466#if DEBUG_NSE
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Transmitting previous round behind schedule in %llu ms\n", 468 "Transmitting previous round behind schedule in %llu ms\n",
468 (unsigned long long) ret.rel_value); 469 (unsigned long long) ret.rel_value);
469#endif 470#endif
470 return ret; 471 return ret;
471 case 0: 472 case 0:
472 /* current round is based on best-known matching_bits */ 473 /* current round is based on best-known matching_bits */
473 matching_bits = ntohl (size_estimate_messages[estimate_index].matching_bits); 474 matching_bits =
474 dist_delay = get_matching_bits_delay (matching_bits); 475 ntohl (size_estimate_messages[estimate_index].matching_bits);
475 dist_delay += get_delay_randomization (matching_bits).rel_value; 476 dist_delay = get_matching_bits_delay (matching_bits);
476 ret.rel_value = (uint64_t) dist_delay; 477 dist_delay += get_delay_randomization (matching_bits).rel_value;
478 ret.rel_value = (uint64_t) dist_delay;
477#if DEBUG_NSE 479#if DEBUG_NSE
478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "For round %llu, delay for %u matching bits is %llu ms\n", 481 "For round %llu, delay for %u matching bits is %llu ms\n",
480 (unsigned long long) current_timestamp.abs_value, 482 (unsigned long long) current_timestamp.abs_value,
481 (unsigned int) matching_bits, 483 (unsigned int) matching_bits,
482 (unsigned long long) ret.rel_value); 484 (unsigned long long) ret.rel_value);
483#endif 485#endif
484 /* now consider round start time and add delay to it */ 486 /* now consider round start time and add delay to it */
485 tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); 487 tgt = GNUNET_TIME_absolute_add (current_timestamp, ret);
486 return GNUNET_TIME_absolute_get_remaining (tgt); 488 return GNUNET_TIME_absolute_get_remaining (tgt);
487 } 489 }
488 GNUNET_break (0); 490 GNUNET_break (0);
489 return GNUNET_TIME_UNIT_FOREVER_REL; 491 return GNUNET_TIME_UNIT_FOREVER_REL;
490} 492}
@@ -497,8 +499,7 @@ get_transmit_delay (int round_offset)
497 * @param tc scheduler context 499 * @param tc scheduler context
498 */ 500 */
499static void 501static void
500transmit_task (void *cls, 502transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
501 const struct GNUNET_SCHEDULER_TaskContext *tc);
502 503
503 504
504/** 505/**
@@ -518,52 +519,45 @@ transmit_ready (void *cls, size_t size, void *buf)
518 519
519 peer_entry->th = NULL; 520 peer_entry->th = NULL;
520 if (buf == NULL) 521 if (buf == NULL)
521 { 522 {
522 /* client disconnected */ 523 /* client disconnected */
523 return 0; 524 return 0;
524 } 525 }
525 GNUNET_assert (size >= sizeof (struct GNUNET_NSE_FloodMessage)); 526 GNUNET_assert (size >= sizeof (struct GNUNET_NSE_FloodMessage));
526 idx = estimate_index; 527 idx = estimate_index;
527 if (peer_entry->previous_round == GNUNET_NO) 528 if (peer_entry->previous_round == GNUNET_NO)
528 { 529 {
529 idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; 530 idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
530 peer_entry->previous_round = GNUNET_YES; 531 peer_entry->previous_round = GNUNET_YES;
531 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), 532 peer_entry->transmit_task =
532 &transmit_task, 533 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), &transmit_task,
533 peer_entry); 534 peer_entry);
534 } 535 }
535 if ( (ntohl (size_estimate_messages[idx].hop_count) == 0) && 536 if ((ntohl (size_estimate_messages[idx].hop_count) == 0) &&
536 (GNUNET_SCHEDULER_NO_TASK != proof_task) ) 537 (GNUNET_SCHEDULER_NO_TASK != proof_task))
537 { 538 {
538 GNUNET_STATISTICS_update (stats, 539 GNUNET_STATISTICS_update (stats,
539 "# flood messages not generated (no proof yet)", 540 "# flood messages not generated (no proof yet)",
540 1, 541 1, GNUNET_NO);
541 GNUNET_NO); 542 return 0;
542 return 0; 543 }
543 }
544#if DEBUG_NSE 544#if DEBUG_NSE
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 "In round %llu, sending to `%s' estimate with %u bits\n", 546 "In round %llu, sending to `%s' estimate with %u bits\n",
547 (unsigned long long) GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp).abs_value, 547 (unsigned long long)
548 GNUNET_i2s (&peer_entry->id), 548 GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].
549 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); 549 timestamp).abs_value,
550 GNUNET_i2s (&peer_entry->id),
551 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
550#endif 552#endif
551 if (ntohl (size_estimate_messages[idx].hop_count) == 0) 553 if (ntohl (size_estimate_messages[idx].hop_count) == 0)
552 GNUNET_STATISTICS_update (stats, 554 GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
553 "# flood messages started", 555 GNUNET_STATISTICS_update (stats,
554 1, 556 "# flood messages transmitted", 1, GNUNET_NO);
555 GNUNET_NO);
556 GNUNET_STATISTICS_update (stats,
557 "# flood messages transmitted",
558 1,
559 GNUNET_NO);
560 memcpy (buf, 557 memcpy (buf,
561 &size_estimate_messages[idx], 558 &size_estimate_messages[idx],
562 sizeof (struct GNUNET_NSE_FloodMessage)); 559 sizeof (struct GNUNET_NSE_FloodMessage));
563 GNUNET_STATISTICS_update (stats, 560 GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO);
564 "# flood messages sent",
565 1,
566 GNUNET_NO);
567 return sizeof (struct GNUNET_NSE_FloodMessage); 561 return sizeof (struct GNUNET_NSE_FloodMessage);
568} 562}
569 563
@@ -575,21 +569,21 @@ transmit_ready (void *cls, size_t size, void *buf)
575 * @param tc scheduler context 569 * @param tc scheduler context
576 */ 570 */
577static void 571static void
578transmit_task (void *cls, 572transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
579 const struct GNUNET_SCHEDULER_TaskContext *tc)
580{ 573{
581 struct NSEPeerEntry *peer_entry = cls; 574 struct NSEPeerEntry *peer_entry = cls;
582 575
583 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 576 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
584 GNUNET_assert (NULL == peer_entry->th); 577 GNUNET_assert (NULL == peer_entry->th);
585 peer_entry->th 578 peer_entry->th
586 = GNUNET_CORE_notify_transmit_ready (coreAPI, 579 = GNUNET_CORE_notify_transmit_ready (coreAPI,
587 GNUNET_NO, 580 GNUNET_NO,
588 NSE_PRIORITY, 581 NSE_PRIORITY,
589 GNUNET_TIME_UNIT_FOREVER_REL, 582 GNUNET_TIME_UNIT_FOREVER_REL,
590 &peer_entry->id, 583 &peer_entry->id,
591 sizeof (struct GNUNET_NSE_FloodMessage), 584 sizeof (struct
592 &transmit_ready, peer_entry); 585 GNUNET_NSE_FloodMessage),
586 &transmit_ready, peer_entry);
593} 587}
594 588
595 589
@@ -605,9 +599,7 @@ update_network_size_estimate ()
605 struct GNUNET_NSE_ClientMessage em; 599 struct GNUNET_NSE_ClientMessage em;
606 600
607 setup_estimate_message (&em); 601 setup_estimate_message (&em);
608 GNUNET_SERVER_notification_context_broadcast (nc, 602 GNUNET_SERVER_notification_context_broadcast (nc, &em.header, GNUNET_YES);
609 &em.header,
610 GNUNET_YES);
611} 603}
612 604
613 605
@@ -619,29 +611,26 @@ update_network_size_estimate ()
619 * @param ts timestamp to use 611 * @param ts timestamp to use
620 */ 612 */
621static void 613static void
622setup_flood_message (unsigned int slot, 614setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
623 struct GNUNET_TIME_Absolute ts)
624{ 615{
625 struct GNUNET_NSE_FloodMessage *fm; 616 struct GNUNET_NSE_FloodMessage *fm;
626 uint32_t matching_bits; 617 uint32_t matching_bits;
627 618
628 matching_bits = get_matching_bits (ts, &my_identity); 619 matching_bits = get_matching_bits (ts, &my_identity);
629 fm = &size_estimate_messages[slot]; 620 fm = &size_estimate_messages[slot];
630 fm->header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage)); 621 fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage));
631 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); 622 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
632 fm->hop_count = htonl (0); 623 fm->hop_count = htonl (0);
633 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); 624 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
634 fm->purpose.size = htonl (sizeof(struct GNUNET_NSE_FloodMessage) 625 fm->purpose.size = htonl (sizeof (struct GNUNET_NSE_FloodMessage)
635 - sizeof (struct GNUNET_MessageHeader) 626 - sizeof (struct GNUNET_MessageHeader)
636 - sizeof (uint32_t) 627 - sizeof (uint32_t)
637 - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 628 - sizeof (struct GNUNET_CRYPTO_RsaSignature));
638 fm->matching_bits = htonl (matching_bits); 629 fm->matching_bits = htonl (matching_bits);
639 fm->timestamp = GNUNET_TIME_absolute_hton (ts); 630 fm->timestamp = GNUNET_TIME_absolute_hton (ts);
640 fm->pkey = my_public_key; 631 fm->pkey = my_public_key;
641 fm->proof_of_work = my_proof; 632 fm->proof_of_work = my_proof;
642 GNUNET_CRYPTO_rsa_sign (my_private_key, 633 GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, &fm->signature);
643 &fm->purpose,
644 &fm->signature);
645} 634}
646 635
647 636
@@ -655,27 +644,25 @@ setup_flood_message (unsigned int slot,
655 * @return GNUNET_OK (continue to iterate) 644 * @return GNUNET_OK (continue to iterate)
656 */ 645 */
657static int 646static int
658schedule_current_round (void *cls, 647schedule_current_round (void *cls, const GNUNET_HashCode * key, void *value)
659 const GNUNET_HashCode *key,
660 void *value)
661{ 648{
662 struct NSEPeerEntry *peer_entry = value; 649 struct NSEPeerEntry *peer_entry = value;
663 struct GNUNET_TIME_Relative delay; 650 struct GNUNET_TIME_Relative delay;
664 651
665 if (peer_entry->th != NULL) 652 if (peer_entry->th != NULL)
666 { 653 {
667 peer_entry->previous_round = GNUNET_NO; 654 peer_entry->previous_round = GNUNET_NO;
668 return GNUNET_OK; 655 return GNUNET_OK;
669 } 656 }
670 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) 657 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
671 { 658 {
672 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 659 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
673 peer_entry->previous_round = GNUNET_NO; 660 peer_entry->previous_round = GNUNET_NO;
674 } 661 }
675 delay = get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0); 662 delay =
676 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay, 663 get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0);
677 &transmit_task, 664 peer_entry->transmit_task =
678 peer_entry); 665 GNUNET_SCHEDULER_add_delayed (delay, &transmit_task, peer_entry);
679 return GNUNET_OK; 666 return GNUNET_OK;
680} 667}
681 668
@@ -687,8 +674,7 @@ schedule_current_round (void *cls,
687 * @param tc context for this message 674 * @param tc context for this message
688 */ 675 */
689static void 676static void
690update_flood_message(void *cls, 677update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
691 const struct GNUNET_SCHEDULER_TaskContext *tc)
692{ 678{
693 struct GNUNET_TIME_Relative offset; 679 struct GNUNET_TIME_Relative offset;
694 unsigned int i; 680 unsigned int i;
@@ -696,40 +682,38 @@ update_flood_message(void *cls,
696 flood_task = GNUNET_SCHEDULER_NO_TASK; 682 flood_task = GNUNET_SCHEDULER_NO_TASK;
697 offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); 683 offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
698 if (0 != offset.rel_value) 684 if (0 != offset.rel_value)
699 { 685 {
700 /* somehow run early, delay more */ 686 /* somehow run early, delay more */
701 flood_task 687 flood_task
702 = GNUNET_SCHEDULER_add_delayed (offset, 688 = GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
703 &update_flood_message, 689 return;
704 NULL); 690 }
705 return;
706 }
707 current_timestamp = next_timestamp; 691 current_timestamp = next_timestamp;
708 next_timestamp = GNUNET_TIME_absolute_add (current_timestamp, 692 next_timestamp = GNUNET_TIME_absolute_add (current_timestamp,
709 gnunet_nse_interval); 693 gnunet_nse_interval);
710 estimate_index = (estimate_index + 1) % HISTORY_SIZE; 694 estimate_index = (estimate_index + 1) % HISTORY_SIZE;
711 if (estimate_count < HISTORY_SIZE) 695 if (estimate_count < HISTORY_SIZE)
712 estimate_count++; 696 estimate_count++;
713 if (next_timestamp.abs_value == 697 if (next_timestamp.abs_value ==
714 GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value) 698 GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value)
715 { 699 {
716 /* we received a message for this round way early, use it! */ 700 /* we received a message for this round way early, use it! */
717 size_estimate_messages[estimate_index] = next_message; 701 size_estimate_messages[estimate_index] = next_message;
718 size_estimate_messages[estimate_index].hop_count 702 size_estimate_messages[estimate_index].hop_count
719 = htonl (1 + ntohl (next_message.hop_count)); 703 = htonl (1 + ntohl (next_message.hop_count));
720 } 704 }
721 else 705 else
722 setup_flood_message (estimate_index, current_timestamp); 706 setup_flood_message (estimate_index, current_timestamp);
723 next_message.matching_bits = htonl (0); /* reset for 'next' round */ 707 next_message.matching_bits = htonl (0); /* reset for 'next' round */
724 hop_count_max = 0; 708 hop_count_max = 0;
725 for (i = 0; i < HISTORY_SIZE; i++) 709 for (i = 0; i < HISTORY_SIZE; i++)
726 hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), 710 hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count),
727 hop_count_max); 711 hop_count_max);
728 GNUNET_CONTAINER_multihashmap_iterate (peers, 712 GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL);
729 &schedule_current_round, 713 flood_task =
730 NULL); 714 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
731 flood_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (next_timestamp), 715 (next_timestamp), &update_flood_message,
732 &update_flood_message, NULL); 716 NULL);
733} 717}
734 718
735 719
@@ -739,13 +723,13 @@ update_flood_message(void *cls,
739 * @param hash 723 * @param hash
740 * @return the number of leading zero bits. 724 * @return the number of leading zero bits.
741 */ 725 */
742static unsigned int 726static unsigned int
743count_leading_zeroes(const GNUNET_HashCode *hash) 727count_leading_zeroes (const GNUNET_HashCode * hash)
744{ 728{
745 unsigned int hash_count; 729 unsigned int hash_count;
746 730
747 hash_count = 0; 731 hash_count = 0;
748 while ((0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count))) 732 while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
749 hash_count++; 733 hash_count++;
750 return hash_count; 734 return hash_count;
751} 735}
@@ -761,20 +745,19 @@ count_leading_zeroes(const GNUNET_HashCode *hash)
761 * @return GNUNET_YES if valid, GNUNET_NO if not 745 * @return GNUNET_YES if valid, GNUNET_NO if not
762 */ 746 */
763static int 747static int
764check_proof_of_work(const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, 748check_proof_of_work (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
765 uint64_t val) 749 uint64_t val)
766{ 750{
767 char buf[sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + sizeof(val)]; 751 char buf[sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
752 sizeof (val)];
768 GNUNET_HashCode result; 753 GNUNET_HashCode result;
769 754
770 memcpy (buf, 755 memcpy (buf, &val, sizeof (val));
771 &val, 756 memcpy (&buf[sizeof (val)],
772 sizeof (val)); 757 pkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
773 memcpy (&buf[sizeof(val)],
774 pkey,
775 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
776 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); 758 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
777 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES : GNUNET_NO; 759 return (count_leading_zeroes (&result) >=
760 nse_work_required) ? GNUNET_YES : GNUNET_NO;
778} 761}
779 762
780 763
@@ -786,19 +769,16 @@ write_proof ()
786{ 769{
787 char *proof; 770 char *proof;
788 771
789 if (GNUNET_OK != 772 if (GNUNET_OK !=
790 GNUNET_CONFIGURATION_get_value_filename (cfg, 773 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
791 "NSE", "PROOFFILE", 774 return;
792 &proof))
793 return;
794 if (sizeof (my_proof) != 775 if (sizeof (my_proof) !=
795 GNUNET_DISK_fn_write (proof, 776 GNUNET_DISK_fn_write (proof,
796 &my_proof, 777 &my_proof,
797 sizeof (my_proof), 778 sizeof (my_proof),
798 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) 779 GNUNET_DISK_PERM_USER_READ |
799 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 780 GNUNET_DISK_PERM_USER_WRITE))
800 "write", 781 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
801 proof);
802 GNUNET_free (proof); 782 GNUNET_free (proof);
803 783
804} 784}
@@ -811,67 +791,64 @@ write_proof ()
811 * @param tc task context 791 * @param tc task context
812 */ 792 */
813static void 793static void
814find_proof (void *cls, 794find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
815 const struct GNUNET_SCHEDULER_TaskContext *tc)
816{ 795{
817#define ROUND_SIZE 10 796#define ROUND_SIZE 10
818 uint64_t counter; 797 uint64_t counter;
819 char buf[sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + sizeof(uint64_t)]; 798 char buf[sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
799 sizeof (uint64_t)];
820 GNUNET_HashCode result; 800 GNUNET_HashCode result;
821 unsigned int i; 801 unsigned int i;
822 802
823 proof_task = GNUNET_SCHEDULER_NO_TASK; 803 proof_task = GNUNET_SCHEDULER_NO_TASK;
824 memcpy (&buf[sizeof(uint64_t)], 804 memcpy (&buf[sizeof (uint64_t)],
825 &my_public_key, 805 &my_public_key,
826 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
827 i = 0; 807 i = 0;
828 counter = my_proof; 808 counter = my_proof;
829 while ( (counter != UINT64_MAX) && (i < ROUND_SIZE) ) 809 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
810 {
811 memcpy (buf, &counter, sizeof (uint64_t));
812 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
813 if (nse_work_required <= count_leading_zeroes (&result))
830 { 814 {
831 memcpy (buf, 815 my_proof = counter;
832 &counter,
833 sizeof(uint64_t));
834 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result);
835 if (nse_work_required <= count_leading_zeroes(&result))
836 {
837 my_proof = counter;
838#if DEBUG_NSE 816#if DEBUG_NSE
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
840 "Proof of work found: %llu!\n", 818 "Proof of work found: %llu!\n",
841 (unsigned long long) GNUNET_ntohll (counter)); 819 (unsigned long long) GNUNET_ntohll (counter));
842#endif 820#endif
843 for (i=0;i<HISTORY_SIZE;i++) 821 for (i = 0; i < HISTORY_SIZE; i++)
844 if (ntohl (size_estimate_messages[i].hop_count) == 0) 822 if (ntohl (size_estimate_messages[i].hop_count) == 0)
845 { 823 {
846 size_estimate_messages[i].proof_of_work = my_proof; 824 size_estimate_messages[i].proof_of_work = my_proof;
847 GNUNET_CRYPTO_rsa_sign (my_private_key, 825 GNUNET_CRYPTO_rsa_sign (my_private_key,
848 &size_estimate_messages[i].purpose, 826 &size_estimate_messages[i].purpose,
849 &size_estimate_messages[i].signature); 827 &size_estimate_messages[i].signature);
850 } 828 }
851 write_proof (); 829 write_proof ();
852 return; 830 return;
853 }
854 counter++;
855 i++;
856 } 831 }
832 counter++;
833 i++;
834 }
857 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) 835 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
858 { 836 {
859#if DEBUG_NSE 837#if DEBUG_NSE
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
861 "Testing proofs currently at %llu\n", 839 "Testing proofs currently at %llu\n",
862 (unsigned long long) counter); 840 (unsigned long long) counter);
863#endif 841#endif
864 /* remember progress every 100 rounds */ 842 /* remember progress every 100 rounds */
865 my_proof = counter; 843 my_proof = counter;
866 write_proof (); 844 write_proof ();
867 } 845 }
868 else 846 else
869 { 847 {
870 my_proof = counter; 848 my_proof = counter;
871 } 849 }
872 proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay, 850 proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay,
873 &find_proof, 851 &find_proof, NULL);
874 NULL);
875} 852}
876 853
877 854
@@ -885,28 +862,29 @@ find_proof (void *cls,
885 * @return GNUNET_YES if the message is verified 862 * @return GNUNET_YES if the message is verified
886 * GNUNET_NO if the key/signature don't verify 863 * GNUNET_NO if the key/signature don't verify
887 */ 864 */
888static int 865static int
889verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood) 866verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
890{ 867{
891 if (GNUNET_YES != 868 if (GNUNET_YES !=
892 check_proof_of_work (&incoming_flood->pkey, 869 check_proof_of_work (&incoming_flood->pkey,
893 incoming_flood->proof_of_work)) 870 incoming_flood->proof_of_work))
894 { 871 {
895 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 872 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
896 _("Proof of work invalid: %llu!\n"), 873 _("Proof of work invalid: %llu!\n"),
897 (unsigned long long) GNUNET_ntohll (incoming_flood->proof_of_work)); 874 (unsigned long long)
898 GNUNET_break_op (0); 875 GNUNET_ntohll (incoming_flood->proof_of_work));
899 return GNUNET_NO; 876 GNUNET_break_op (0);
900 } 877 return GNUNET_NO;
901 if (GNUNET_OK != 878 }
879 if (GNUNET_OK !=
902 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND, 880 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND,
903 &incoming_flood->purpose, 881 &incoming_flood->purpose,
904 &incoming_flood->signature, 882 &incoming_flood->signature,
905 &incoming_flood->pkey)) 883 &incoming_flood->pkey))
906 { 884 {
907 GNUNET_break_op (0); 885 GNUNET_break_op (0);
908 return GNUNET_NO; 886 return GNUNET_NO;
909 } 887 }
910 return GNUNET_YES; 888 return GNUNET_YES;
911} 889}
912 890
@@ -921,35 +899,33 @@ verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood)
921 * @return GNUNET_OK (continue to iterate) 899 * @return GNUNET_OK (continue to iterate)
922 */ 900 */
923static int 901static int
924update_flood_times (void *cls, 902update_flood_times (void *cls, const GNUNET_HashCode * key, void *value)
925 const GNUNET_HashCode *key,
926 void *value)
927{ 903{
928 struct NSEPeerEntry *exclude = cls; 904 struct NSEPeerEntry *exclude = cls;
929 struct NSEPeerEntry *peer_entry = value; 905 struct NSEPeerEntry *peer_entry = value;
930 struct GNUNET_TIME_Relative delay; 906 struct GNUNET_TIME_Relative delay;
931 907
932 if (peer_entry->th != NULL) 908 if (peer_entry->th != NULL)
933 return GNUNET_OK; /* already active */ 909 return GNUNET_OK; /* already active */
934 if (peer_entry == exclude) 910 if (peer_entry == exclude)
935 return GNUNET_OK; /* trigger of the update */ 911 return GNUNET_OK; /* trigger of the update */
936 if (peer_entry->previous_round == GNUNET_NO) 912 if (peer_entry->previous_round == GNUNET_NO)
937 { 913 {
938 /* still stuck in previous round, no point to update, check that 914 /* still stuck in previous round, no point to update, check that
939 we are active here though... */ 915 * we are active here though... */
940 GNUNET_break ( (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) || 916 GNUNET_break ((peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) ||
941 (peer_entry->th != NULL) ); 917 (peer_entry->th != NULL));
942 return GNUNET_OK; 918 return GNUNET_OK;
943 } 919 }
944 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) 920 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
945 { 921 {
946 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 922 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
947 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 923 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
948 } 924 }
949 delay = get_transmit_delay (0); 925 delay = get_transmit_delay (0);
950 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay, 926 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay,
951 &transmit_task, 927 &transmit_task,
952 peer_entry); 928 peer_entry);
953 return GNUNET_OK; 929 return GNUNET_OK;
954} 930}
955 931
@@ -964,15 +940,15 @@ update_flood_times (void *cls,
964 * 940 *
965 */ 941 */
966static int 942static int
967handle_p2p_size_estimate(void *cls, 943handle_p2p_size_estimate (void *cls,
968 const struct GNUNET_PeerIdentity *peer, 944 const struct GNUNET_PeerIdentity *peer,
969 const struct GNUNET_MessageHeader *message, 945 const struct GNUNET_MessageHeader *message,
970 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 946 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
971{ 947{
972 const struct GNUNET_NSE_FloodMessage *incoming_flood; 948 const struct GNUNET_NSE_FloodMessage *incoming_flood;
973 struct GNUNET_TIME_Absolute ts; 949 struct GNUNET_TIME_Absolute ts;
974 struct NSEPeerEntry *peer_entry; 950 struct NSEPeerEntry *peer_entry;
975 uint32_t matching_bits; 951 uint32_t matching_bits;
976 unsigned int idx; 952 unsigned int idx;
977 953
978#if ENABLE_HISTOGRAM 954#if ENABLE_HISTOGRAM
@@ -980,10 +956,7 @@ handle_p2p_size_estimate(void *cls,
980 GNUNET_BIO_write_int64 (wh, GNUNET_TIME_absolute_get ().abs_value); 956 GNUNET_BIO_write_int64 (wh, GNUNET_TIME_absolute_get ().abs_value);
981#endif 957#endif
982 incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message; 958 incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message;
983 GNUNET_STATISTICS_update (stats, 959 GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
984 "# flood messages received",
985 1,
986 GNUNET_NO);
987 matching_bits = ntohl (incoming_flood->matching_bits); 960 matching_bits = ntohl (incoming_flood->matching_bits);
988#if DEBUG_NSE 961#if DEBUG_NSE
989 { 962 {
@@ -992,133 +965,124 @@ handle_p2p_size_estimate(void *cls,
992 struct GNUNET_PeerIdentity os; 965 struct GNUNET_PeerIdentity os;
993 966
994 GNUNET_CRYPTO_hash (&incoming_flood->pkey, 967 GNUNET_CRYPTO_hash (&incoming_flood->pkey,
995 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 968 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
996 &os.hashPubKey); 969 &os.hashPubKey);
997 GNUNET_snprintf (origin, sizeof (origin), 970 GNUNET_snprintf (origin, sizeof (origin), "%s", GNUNET_i2s (&os));
998 "%s", 971 GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer));
999 GNUNET_i2s (&os));
1000 GNUNET_snprintf (pred, sizeof (pred),
1001 "%s",
1002 GNUNET_i2s (peer));
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1004 "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n", 973 "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n",
1005 (unsigned long long) GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value, 974 (unsigned long long)
1006 origin, 975 GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value,
1007 pred, 976 origin, pred, GNUNET_i2s (&my_identity),
1008 GNUNET_i2s (&my_identity), 977 (unsigned int) matching_bits);
1009 (unsigned int) matching_bits);
1010 } 978 }
1011#endif 979#endif
1012 980
1013 peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 981 peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
1014 if (NULL == peer_entry) 982 if (NULL == peer_entry)
1015 { 983 {
1016 GNUNET_break (0); 984 GNUNET_break (0);
1017 return GNUNET_OK; 985 return GNUNET_OK;
1018 } 986 }
1019 987
1020 ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); 988 ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
1021 989
1022 if (ts.abs_value == current_timestamp.abs_value) 990 if (ts.abs_value == current_timestamp.abs_value)
1023 idx = estimate_index; 991 idx = estimate_index;
1024 else if (ts.abs_value == current_timestamp.abs_value - gnunet_nse_interval.rel_value) 992 else if (ts.abs_value ==
993 current_timestamp.abs_value - gnunet_nse_interval.rel_value)
1025 idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; 994 idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
1026 else if (ts.abs_value == next_timestamp.abs_value - gnunet_nse_interval.rel_value) 995 else if (ts.abs_value ==
996 next_timestamp.abs_value - gnunet_nse_interval.rel_value)
997 {
998 if (matching_bits <= ntohl (next_message.matching_bits))
999 return GNUNET_OK; /* ignore, simply too early/late */
1000 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1027 { 1001 {
1028 if (matching_bits <= ntohl (next_message.matching_bits)) 1002 GNUNET_break_op (0);
1029 return GNUNET_OK; /* ignore, simply too early/late */
1030 if (GNUNET_YES !=
1031 verify_message_crypto (incoming_flood))
1032 {
1033 GNUNET_break_op (0);
1034 return GNUNET_OK;
1035 }
1036 next_message = *incoming_flood;
1037 return GNUNET_OK; 1003 return GNUNET_OK;
1038 } 1004 }
1005 next_message = *incoming_flood;
1006 return GNUNET_OK;
1007 }
1039 else 1008 else
1009 {
1010 GNUNET_STATISTICS_update (stats,
1011 "# flood messages discarded (clock skew too large)",
1012 1, GNUNET_NO);
1013 return GNUNET_OK;
1014 }
1015 if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))))
1016 {
1017 /* send to self, update our own estimate IF this also comes from us! */
1018 if (0 == memcmp (&incoming_flood->pkey,
1019 &my_public_key, sizeof (my_public_key)))
1020 update_network_size_estimate ();
1021 return GNUNET_OK;
1022 }
1023 if (matching_bits >= ntohl (size_estimate_messages[idx].matching_bits))
1024 {
1025 /* cancel transmission from us to this peer for this round */
1026 if (idx == estimate_index)
1040 { 1027 {
1041 GNUNET_STATISTICS_update (stats, 1028 if (peer_entry->previous_round == GNUNET_YES)
1042 "# flood messages discarded (clock skew too large)", 1029 {
1043 1, 1030 /* cancel any activity for current round */
1044 GNUNET_NO); 1031 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1045 return GNUNET_OK; 1032 {
1033 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1034 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
1035 }
1036 if (peer_entry->th != NULL)
1037 {
1038 GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th);
1039 peer_entry->th = NULL;
1040 }
1041 }
1046 } 1042 }
1047 if (0 == (memcmp (peer, &my_identity, sizeof(struct GNUNET_PeerIdentity)))) 1043 else
1048 { 1044 {
1049 /* send to self, update our own estimate IF this also comes from us! */ 1045 /* cancel previous round only */
1050 if (0 == memcmp (&incoming_flood->pkey, 1046 peer_entry->previous_round = GNUNET_YES;
1051 &my_public_key,
1052 sizeof (my_public_key)))
1053 update_network_size_estimate ();
1054 return GNUNET_OK;
1055 }
1056 if (matching_bits >= ntohl (size_estimate_messages[idx].matching_bits))
1057 {
1058 /* cancel transmission from us to this peer for this round */
1059 if (idx == estimate_index)
1060 {
1061 if (peer_entry->previous_round == GNUNET_YES)
1062 {
1063 /* cancel any activity for current round */
1064 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1065 {
1066 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1067 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK;
1068 }
1069 if (peer_entry->th != NULL)
1070 {
1071 GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th);
1072 peer_entry->th = NULL;
1073 }
1074 }
1075 }
1076 else
1077 {
1078 /* cancel previous round only */
1079 peer_entry->previous_round = GNUNET_YES;
1080 }
1081 } 1047 }
1048 }
1082 if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) 1049 if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits))
1083 return GNUNET_OK; 1050 return GNUNET_OK;
1084 if (matching_bits <= ntohl (size_estimate_messages[idx].matching_bits)) 1051 if (matching_bits <= ntohl (size_estimate_messages[idx].matching_bits))
1085 { 1052 {
1086 if ( (idx < estimate_index) && 1053 if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
1087 (peer_entry->previous_round == GNUNET_YES) ) 1054 peer_entry->previous_round = GNUNET_NO;
1088 peer_entry->previous_round = GNUNET_NO; 1055 /* push back our result now, that peer is spreading bad information... */
1089 /* push back our result now, that peer is spreading bad information... */ 1056 if (NULL == peer_entry->th)
1090 if (NULL == peer_entry->th)
1091 {
1092 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1093 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1094 peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task,
1095 peer_entry);
1096 }
1097 /* Not closer than our most recent message, no need to do work here */
1098 GNUNET_STATISTICS_update (stats,
1099 "# flood messages ignored (had closer already)",
1100 1,
1101 GNUNET_NO);
1102 return GNUNET_OK;
1103 }
1104 if (GNUNET_YES !=
1105 verify_message_crypto (incoming_flood))
1106 { 1057 {
1107 GNUNET_break_op (0); 1058 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1108 return GNUNET_OK; 1059 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1060 peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task,
1061 peer_entry);
1109 } 1062 }
1063 /* Not closer than our most recent message, no need to do work here */
1064 GNUNET_STATISTICS_update (stats,
1065 "# flood messages ignored (had closer already)",
1066 1, GNUNET_NO);
1067 return GNUNET_OK;
1068 }
1069 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1070 {
1071 GNUNET_break_op (0);
1072 return GNUNET_OK;
1073 }
1110 size_estimate_messages[idx] = *incoming_flood; 1074 size_estimate_messages[idx] = *incoming_flood;
1111 size_estimate_messages[idx].hop_count = htonl (ntohl (incoming_flood->hop_count) + 1); 1075 size_estimate_messages[idx].hop_count =
1112 hop_count_max = GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, 1076 htonl (ntohl (incoming_flood->hop_count) + 1);
1113 hop_count_max); 1077 hop_count_max =
1078 GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
1114 1079
1115 /* have a new, better size estimate, inform clients */ 1080 /* have a new, better size estimate, inform clients */
1116 update_network_size_estimate (); 1081 update_network_size_estimate ();
1117 1082
1118 /* flood to rest */ 1083 /* flood to rest */
1119 GNUNET_CONTAINER_multihashmap_iterate (peers, 1084 GNUNET_CONTAINER_multihashmap_iterate (peers,
1120 &update_flood_times, 1085 &update_flood_times, peer_entry);
1121 peer_entry);
1122 return GNUNET_OK; 1086 return GNUNET_OK;
1123} 1087}
1124 1088
@@ -1132,25 +1096,24 @@ handle_p2p_size_estimate(void *cls,
1132 * @param atsi performance data 1096 * @param atsi performance data
1133 */ 1097 */
1134static void 1098static void
1135handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, 1099handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1136 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1100 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1137{ 1101{
1138 struct NSEPeerEntry *peer_entry; 1102 struct NSEPeerEntry *peer_entry;
1139 1103
1140 #if DEBUG_NSE 1104#if DEBUG_NSE
1141 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 "Peer `%s' connected to us\n", 1106 "Peer `%s' connected to us\n", GNUNET_i2s (peer));
1143 GNUNET_i2s (peer));
1144#endif 1107#endif
1145 peer_entry = GNUNET_malloc(sizeof(struct NSEPeerEntry)); 1108 peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry));
1146 peer_entry->id = *peer; 1109 peer_entry->id = *peer;
1147 GNUNET_CONTAINER_multihashmap_put (peers, 1110 GNUNET_CONTAINER_multihashmap_put (peers,
1148 &peer->hashPubKey, 1111 &peer->hashPubKey,
1149 peer_entry, 1112 peer_entry,
1150 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1151 peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), 1114 peer_entry->transmit_task =
1152 &transmit_task, 1115 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task,
1153 peer_entry); 1116 peer_entry);
1154} 1117}
1155 1118
1156 1119
@@ -1161,34 +1124,31 @@ handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer,
1161 * @param peer peer identity this notification is about 1124 * @param peer peer identity this notification is about
1162 */ 1125 */
1163static void 1126static void
1164handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer) 1127handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1165{ 1128{
1166 struct NSEPeerEntry *pos; 1129 struct NSEPeerEntry *pos;
1167 1130
1168 #if DEBUG_NSE 1131#if DEBUG_NSE
1169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1170 "Peer `%s' disconnected from us\n", 1133 "Peer `%s' disconnected from us\n", GNUNET_i2s (peer));
1171 GNUNET_i2s (peer));
1172#endif 1134#endif
1173 pos = GNUNET_CONTAINER_multihashmap_get (peers, 1135 pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
1174 &peer->hashPubKey);
1175 if (NULL == pos) 1136 if (NULL == pos)
1176 { 1137 {
1177 GNUNET_break (0); 1138 GNUNET_break (0);
1178 return; 1139 return;
1179 } 1140 }
1180 GNUNET_assert (GNUNET_YES == 1141 GNUNET_assert (GNUNET_YES ==
1181 GNUNET_CONTAINER_multihashmap_remove (peers, 1142 GNUNET_CONTAINER_multihashmap_remove (peers,
1182 &peer->hashPubKey, 1143 &peer->hashPubKey, pos));
1183 pos));
1184 if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK) 1144 if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK)
1185 GNUNET_SCHEDULER_cancel (pos->transmit_task); 1145 GNUNET_SCHEDULER_cancel (pos->transmit_task);
1186 if (pos->th != NULL) 1146 if (pos->th != NULL)
1187 { 1147 {
1188 GNUNET_CORE_notify_transmit_ready_cancel (pos->th); 1148 GNUNET_CORE_notify_transmit_ready_cancel (pos->th);
1189 pos->th = NULL; 1149 pos->th = NULL;
1190 } 1150 }
1191 GNUNET_free(pos); 1151 GNUNET_free (pos);
1192} 1152}
1193 1153
1194 1154
@@ -1199,51 +1159,50 @@ handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer)
1199 * @param tc unused 1159 * @param tc unused
1200 */ 1160 */
1201static void 1161static void
1202shutdown_task(void *cls, 1162shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1203 const struct GNUNET_SCHEDULER_TaskContext *tc)
1204{ 1163{
1205 if (flood_task != GNUNET_SCHEDULER_NO_TASK) 1164 if (flood_task != GNUNET_SCHEDULER_NO_TASK)
1206 { 1165 {
1207 GNUNET_SCHEDULER_cancel (flood_task); 1166 GNUNET_SCHEDULER_cancel (flood_task);
1208 flood_task = GNUNET_SCHEDULER_NO_TASK; 1167 flood_task = GNUNET_SCHEDULER_NO_TASK;
1209 } 1168 }
1210 if (proof_task != GNUNET_SCHEDULER_NO_TASK) 1169 if (proof_task != GNUNET_SCHEDULER_NO_TASK)
1211 { 1170 {
1212 GNUNET_SCHEDULER_cancel (proof_task); 1171 GNUNET_SCHEDULER_cancel (proof_task);
1213 proof_task = GNUNET_SCHEDULER_NO_TASK; 1172 proof_task = GNUNET_SCHEDULER_NO_TASK;
1214 write_proof (); /* remember progress */ 1173 write_proof (); /* remember progress */
1215 } 1174 }
1216 if (nc != NULL) 1175 if (nc != NULL)
1217 { 1176 {
1218 GNUNET_SERVER_notification_context_destroy (nc); 1177 GNUNET_SERVER_notification_context_destroy (nc);
1219 nc = NULL; 1178 nc = NULL;
1220 } 1179 }
1221 if (coreAPI != NULL) 1180 if (coreAPI != NULL)
1222 { 1181 {
1223 GNUNET_CORE_disconnect (coreAPI); 1182 GNUNET_CORE_disconnect (coreAPI);
1224 coreAPI = NULL; 1183 coreAPI = NULL;
1225 } 1184 }
1226 if (stats != NULL) 1185 if (stats != NULL)
1227 { 1186 {
1228 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1187 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1229 stats = NULL; 1188 stats = NULL;
1230 } 1189 }
1231 if (peers != NULL) 1190 if (peers != NULL)
1232 { 1191 {
1233 GNUNET_CONTAINER_multihashmap_destroy (peers); 1192 GNUNET_CONTAINER_multihashmap_destroy (peers);
1234 peers = NULL; 1193 peers = NULL;
1235 } 1194 }
1236 if (my_private_key != NULL) 1195 if (my_private_key != NULL)
1237 { 1196 {
1238 GNUNET_CRYPTO_rsa_key_free (my_private_key); 1197 GNUNET_CRYPTO_rsa_key_free (my_private_key);
1239 my_private_key = NULL; 1198 my_private_key = NULL;
1240 } 1199 }
1241#if ENABLE_HISTOGRAM 1200#if ENABLE_HISTOGRAM
1242 if (wh != NULL) 1201 if (wh != NULL)
1243 { 1202 {
1244 GNUNET_BIO_write_close (wh); 1203 GNUNET_BIO_write_close (wh);
1245 wh = NULL; 1204 wh = NULL;
1246 } 1205 }
1247#endif 1206#endif
1248} 1207}
1249 1208
@@ -1258,37 +1217,45 @@ shutdown_task(void *cls,
1258 */ 1217 */
1259static void 1218static void
1260core_init (void *cls, struct GNUNET_CORE_Handle *server, 1219core_init (void *cls, struct GNUNET_CORE_Handle *server,
1261 const struct GNUNET_PeerIdentity *identity, 1220 const struct GNUNET_PeerIdentity *identity,
1262 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 1221 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
1263{ 1222{
1264 struct GNUNET_TIME_Absolute now; 1223 struct GNUNET_TIME_Absolute now;
1265 struct GNUNET_TIME_Absolute prev_time; 1224 struct GNUNET_TIME_Absolute prev_time;
1266 unsigned int i; 1225 unsigned int i;
1267 1226
1268 if (server == NULL) 1227 if (server == NULL)
1269 { 1228 {
1270#if DEBUG_NSE 1229#if DEBUG_NSE
1271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to core FAILED!\n");
1272 "Connection to core FAILED!\n");
1273#endif 1231#endif
1274 GNUNET_SCHEDULER_shutdown (); 1232 GNUNET_SCHEDULER_shutdown ();
1275 return; 1233 return;
1276 } 1234 }
1277 GNUNET_assert (0 == memcmp (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity))); 1235 GNUNET_assert (0 ==
1236 memcmp (&my_identity, identity,
1237 sizeof (struct GNUNET_PeerIdentity)));
1278 now = GNUNET_TIME_absolute_get (); 1238 now = GNUNET_TIME_absolute_get ();
1279 current_timestamp.abs_value = (now.abs_value / gnunet_nse_interval.rel_value) * gnunet_nse_interval.rel_value; 1239 current_timestamp.abs_value =
1280 next_timestamp.abs_value = current_timestamp.abs_value + gnunet_nse_interval.rel_value; 1240 (now.abs_value / gnunet_nse_interval.rel_value) *
1281 1241 gnunet_nse_interval.rel_value;
1242 next_timestamp.abs_value =
1243 current_timestamp.abs_value + gnunet_nse_interval.rel_value;
1244
1282 for (i = 0; i < HISTORY_SIZE; i++) 1245 for (i = 0; i < HISTORY_SIZE; i++)
1283 { 1246 {
1284 prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i - 1) * gnunet_nse_interval.rel_value; 1247 prev_time.abs_value =
1285 setup_flood_message (i, prev_time); 1248 current_timestamp.abs_value - (HISTORY_SIZE - i -
1286 } 1249 1) * gnunet_nse_interval.rel_value;
1250 setup_flood_message (i, prev_time);
1251 }
1287 estimate_index = HISTORY_SIZE - 1; 1252 estimate_index = HISTORY_SIZE - 1;
1288 estimate_count = 2; 1253 estimate_count = 2;
1289 flood_task 1254 flood_task
1290 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (next_timestamp), 1255 =
1291 &update_flood_message, NULL); 1256 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1257 (next_timestamp), &update_flood_message,
1258 NULL);
1292} 1259}
1293 1260
1294 1261
@@ -1300,131 +1267,128 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1300 * @param c configuration to use 1267 * @param c configuration to use
1301 */ 1268 */
1302static void 1269static void
1303run(void *cls, struct GNUNET_SERVER_Handle *server, 1270run (void *cls, struct GNUNET_SERVER_Handle *server,
1304 const struct GNUNET_CONFIGURATION_Handle *c) 1271 const struct GNUNET_CONFIGURATION_Handle *c)
1305{ 1272{
1306 char *keyfile; 1273 char *keyfile;
1307 char *proof; 1274 char *proof;
1308 1275
1309 static const struct GNUNET_SERVER_MessageHandler handlers[] = 1276 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1310 { 1277 {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START,
1311 { &handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, sizeof (struct GNUNET_MessageHeader) }, 1278 sizeof (struct GNUNET_MessageHeader)},
1312 { NULL, NULL, 0, 0 } 1279 {NULL, NULL, 0, 0}
1313 }; 1280 };
1314 static const struct GNUNET_CORE_MessageHandler core_handlers[] = 1281 static const struct GNUNET_CORE_MessageHandler core_handlers[] = {
1315 { 1282 {&handle_p2p_size_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD,
1316 { &handle_p2p_size_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, sizeof (struct GNUNET_NSE_FloodMessage) }, 1283 sizeof (struct GNUNET_NSE_FloodMessage)},
1317 { NULL, 0, 0 } 1284 {NULL, 0, 0}
1318 }; 1285 };
1319 cfg = c; 1286 cfg = c;
1320 1287
1321 if ( (GNUNET_OK != 1288 if ((GNUNET_OK !=
1322 GNUNET_CONFIGURATION_get_value_time (cfg, 1289 GNUNET_CONFIGURATION_get_value_time (cfg,
1323 "NSE", "INTERVAL", 1290 "NSE", "INTERVAL",
1324 &gnunet_nse_interval)) || 1291 &gnunet_nse_interval)) ||
1325 (GNUNET_OK != 1292 (GNUNET_OK !=
1326 GNUNET_CONFIGURATION_get_value_time (cfg, 1293 GNUNET_CONFIGURATION_get_value_time (cfg,
1327 "NSE", "WORKDELAY", 1294 "NSE", "WORKDELAY",
1328 &proof_find_delay)) || 1295 &proof_find_delay)) ||
1329 (GNUNET_OK != 1296 (GNUNET_OK !=
1330 GNUNET_CONFIGURATION_get_value_number (cfg, 1297 GNUNET_CONFIGURATION_get_value_number (cfg,
1331 "NSE", "WORKBITS", 1298 "NSE", "WORKBITS",
1332 &nse_work_required)) ) 1299 &nse_work_required)))
1333 { 1300 {
1334 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1335 _ ("NSE service is lacking key configuration settings. Exiting.\n")); 1302 _
1336 GNUNET_SCHEDULER_shutdown (); 1303 ("NSE service is lacking key configuration settings. Exiting.\n"));
1337 return; 1304 GNUNET_SCHEDULER_shutdown ();
1338 } 1305 return;
1306 }
1339 if (nse_work_required >= sizeof (GNUNET_HashCode) * 8) 1307 if (nse_work_required >= sizeof (GNUNET_HashCode) * 8)
1340 { 1308 {
1341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1342 _ ("Invalid work requirement for NSE service. Exiting.\n")); 1310 _("Invalid work requirement for NSE service. Exiting.\n"));
1343 GNUNET_SCHEDULER_shutdown (); 1311 GNUNET_SCHEDULER_shutdown ();
1344 return; 1312 return;
1345 } 1313 }
1346 1314
1347 1315
1348 if (GNUNET_OK != 1316 if (GNUNET_OK !=
1349 GNUNET_CONFIGURATION_get_value_filename (cfg, 1317 GNUNET_CONFIGURATION_get_value_filename (cfg,
1350 "GNUNETD", "HOSTKEY", 1318 "GNUNETD", "HOSTKEY", &keyfile))
1351 &keyfile)) 1319 {
1352 { 1320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1321 _
1354 _ ("NSE service is lacking key configuration settings. Exiting.\n")); 1322 ("NSE service is lacking key configuration settings. Exiting.\n"));
1355 GNUNET_SCHEDULER_shutdown (); 1323 GNUNET_SCHEDULER_shutdown ();
1356 return; 1324 return;
1357 } 1325 }
1358 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1326 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1359 GNUNET_free (keyfile); 1327 GNUNET_free (keyfile);
1360 if (my_private_key == NULL) 1328 if (my_private_key == NULL)
1361 { 1329 {
1362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1363 _("NSE service could not access hostkey. Exiting.\n")); 1331 _("NSE service could not access hostkey. Exiting.\n"));
1364 GNUNET_SCHEDULER_shutdown (); 1332 GNUNET_SCHEDULER_shutdown ();
1365 return; 1333 return;
1366 } 1334 }
1367 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 1335 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1368 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); 1336 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
1369 if (GNUNET_OK != 1337 &my_identity.hashPubKey);
1370 GNUNET_CONFIGURATION_get_value_filename (cfg, 1338 if (GNUNET_OK !=
1371 "NSE", "PROOFFILE", 1339 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
1372 &proof)) 1340 {
1341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1342 _
1343 ("NSE service is lacking key configuration settings. Exiting.\n"));
1344 if (my_private_key != NULL)
1373 { 1345 {
1374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1346 GNUNET_CRYPTO_rsa_key_free (my_private_key);
1375 _ ("NSE service is lacking key configuration settings. Exiting.\n")); 1347 my_private_key = NULL;
1376 if (my_private_key != NULL)
1377 {
1378 GNUNET_CRYPTO_rsa_key_free (my_private_key);
1379 my_private_key = NULL;
1380 }
1381 GNUNET_SCHEDULER_shutdown ();
1382 return;
1383 } 1348 }
1384 if ( (GNUNET_YES != GNUNET_DISK_file_test (proof)) || 1349 GNUNET_SCHEDULER_shutdown ();
1385 (sizeof (my_proof) != 1350 return;
1386 GNUNET_DISK_fn_read (proof, 1351 }
1387 &my_proof, 1352 if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
1388 sizeof (my_proof))) ) 1353 (sizeof (my_proof) !=
1389 my_proof = 0; 1354 GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof))))
1355 my_proof = 0;
1390 GNUNET_free (proof); 1356 GNUNET_free (proof);
1391 proof_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1357 proof_task =
1392 &find_proof, 1358 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1393 NULL); 1359 &find_proof, NULL);
1394 1360
1395 peers = GNUNET_CONTAINER_multihashmap_create (128); 1361 peers = GNUNET_CONTAINER_multihashmap_create (128);
1396 GNUNET_SERVER_add_handlers (server, handlers); 1362 GNUNET_SERVER_add_handlers (server, handlers);
1397 nc = GNUNET_SERVER_notification_context_create (server, 1); 1363 nc = GNUNET_SERVER_notification_context_create (server, 1);
1398 /* Connect to core service and register core handlers */ 1364 /* Connect to core service and register core handlers */
1399 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ 1365 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */
1400 CORE_QUEUE_SIZE, /* queue size */ 1366 CORE_QUEUE_SIZE, /* queue size */
1401 NULL, /* Closure passed to functions */ 1367 NULL, /* Closure passed to functions */
1402 &core_init, /* Call core_init once connected */ 1368 &core_init, /* Call core_init once connected */
1403 &handle_core_connect, /* Handle connects */ 1369 &handle_core_connect, /* Handle connects */
1404 &handle_core_disconnect, /* Handle disconnects */ 1370 &handle_core_disconnect, /* Handle disconnects */
1405 NULL, /* Do we care about "status" updates? */ 1371 NULL, /* Do we care about "status" updates? */
1406 NULL, /* Don't want notified about all incoming messages */ 1372 NULL, /* Don't want notified about all incoming messages */
1407 GNUNET_NO, /* For header only inbound notification */ 1373 GNUNET_NO, /* For header only inbound notification */
1408 NULL, /* Don't want notified about all outbound messages */ 1374 NULL, /* Don't want notified about all outbound messages */
1409 GNUNET_NO, /* For header only outbound notification */ 1375 GNUNET_NO, /* For header only outbound notification */
1410 core_handlers); /* Register these handlers */ 1376 core_handlers); /* Register these handlers */
1411 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1377 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1412 &shutdown_task, NULL); 1378 &shutdown_task, NULL);
1413#if ENABLE_HISTOGRAM 1379#if ENABLE_HISTOGRAM
1414 if (GNUNET_OK == 1380 if (GNUNET_OK ==
1415 GNUNET_CONFIGURATION_get_value_filename (cfg, 1381 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM", &proof))
1416 "NSE", "HISTOGRAM", 1382 {
1417 &proof)) 1383 wh = GNUNET_BIO_write_open (proof);
1418 { 1384 GNUNET_free (proof);
1419 wh = GNUNET_BIO_write_open (proof); 1385 }
1420 GNUNET_free (proof);
1421 }
1422#endif 1386#endif
1423 if (coreAPI == NULL) 1387 if (coreAPI == NULL)
1424 { 1388 {
1425 GNUNET_SCHEDULER_shutdown (); 1389 GNUNET_SCHEDULER_shutdown ();
1426 return; 1390 return;
1427 } 1391 }
1428 stats = GNUNET_STATISTICS_create ("nse", cfg); 1392 stats = GNUNET_STATISTICS_create ("nse", cfg);
1429} 1393}
1430 1394
@@ -1437,13 +1401,12 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
1437 * @return 0 ok, 1 on error 1401 * @return 0 ok, 1 on error
1438 */ 1402 */
1439int 1403int
1440main(int argc, char * const *argv) 1404main (int argc, char *const *argv)
1441{ 1405{
1442 return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, 1406 return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv,
1443 "nse", 1407 "nse",
1444 GNUNET_SERVICE_OPTION_NONE, &run, 1408 GNUNET_SERVICE_OPTION_NONE, &run,
1445 NULL)) ? 0 : 1; 1409 NULL)) ? 0 : 1;
1446} 1410}
1447 1411
1448/* end of gnunet-service-nse.c */ 1412/* end of gnunet-service-nse.c */
1449