diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-31 08:46:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-31 08:46:59 +0000 |
commit | 8b2a3260e6aafc2ad31c8b7bff5f7d25b57bfc14 (patch) | |
tree | 2bca288ecebd1a8a3bfe15f79c0dde6ea63cdbd5 | |
parent | 2e6182b575ae98c87d216b107a640eb1c15578c9 (diff) | |
download | gnunet-8b2a3260e6aafc2ad31c8b7bff5f7d25b57bfc14.tar.gz gnunet-8b2a3260e6aafc2ad31c8b7bff5f7d25b57bfc14.zip |
-convert NSE to new core MQ API
-rw-r--r-- | src/nse/gnunet-service-nse.c | 516 |
1 files changed, 272 insertions, 244 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 7bf186e83..262f85c8d 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011, 2012, 2013 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2012, 2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -51,6 +51,7 @@ | |||
51 | #include <gcrypt.h> | 51 | #include <gcrypt.h> |
52 | 52 | ||
53 | 53 | ||
54 | |||
54 | /** | 55 | /** |
55 | * Should messages be delayed randomly? This option should be set to | 56 | * Should messages be delayed randomly? This option should be set to |
56 | * #GNUNET_NO only for experiments, not in production. | 57 | * #GNUNET_NO only for experiments, not in production. |
@@ -120,17 +121,17 @@ struct NSEPeerEntry | |||
120 | /** | 121 | /** |
121 | * Core handle for sending messages to this peer. | 122 | * Core handle for sending messages to this peer. |
122 | */ | 123 | */ |
123 | struct GNUNET_CORE_TransmitHandle *th; | 124 | struct GNUNET_MQ_Handle *mq; |
124 | 125 | ||
125 | /** | 126 | /** |
126 | * What is the identity of the peer? | 127 | * What is the identity of the peer? |
127 | */ | 128 | */ |
128 | struct GNUNET_PeerIdentity id; | 129 | const struct GNUNET_PeerIdentity *id; |
129 | 130 | ||
130 | /** | 131 | /** |
131 | * Task scheduled to send message to this peer. | 132 | * Task scheduled to send message to this peer. |
132 | */ | 133 | */ |
133 | struct GNUNET_SCHEDULER_Task * transmit_task; | 134 | struct GNUNET_SCHEDULER_Task *transmit_task; |
134 | 135 | ||
135 | /** | 136 | /** |
136 | * Did we receive or send a message about the previous round | 137 | * Did we receive or send a message about the previous round |
@@ -434,11 +435,15 @@ handle_start_message (void *cls, | |||
434 | 435 | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
436 | "Received START message from client\n"); | 437 | "Received START message from client\n"); |
437 | GNUNET_SERVER_notification_context_add (nc, client); | 438 | GNUNET_SERVER_notification_context_add (nc, |
439 | client); | ||
438 | setup_estimate_message (&em); | 440 | setup_estimate_message (&em); |
439 | GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, | 441 | GNUNET_SERVER_notification_context_unicast (nc, |
442 | client, | ||
443 | &em.header, | ||
440 | GNUNET_YES); | 444 | GNUNET_YES); |
441 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 445 | GNUNET_SERVER_receive_done (client, |
446 | GNUNET_OK); | ||
442 | } | 447 | } |
443 | 448 | ||
444 | 449 | ||
@@ -507,9 +512,11 @@ pow_hash (const void *buf, | |||
507 | gcry_kdf_derive (buf, buf_len, | 512 | gcry_kdf_derive (buf, buf_len, |
508 | GCRY_KDF_SCRYPT, | 513 | GCRY_KDF_SCRYPT, |
509 | 1 /* subalgo */, | 514 | 1 /* subalgo */, |
510 | "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"), | 515 | "gnunet-proof-of-work", |
516 | strlen ("gnunet-proof-of-work"), | ||
511 | 2 /* iterations; keep cost of individual op small */, | 517 | 2 /* iterations; keep cost of individual op small */, |
512 | sizeof (struct GNUNET_HashCode), result)); | 518 | sizeof (struct GNUNET_HashCode), |
519 | result)); | ||
513 | } | 520 | } |
514 | 521 | ||
515 | 522 | ||
@@ -559,13 +566,15 @@ get_transmit_delay (int round_offset) | |||
559 | case -1: | 566 | case -1: |
560 | /* previous round is randomized between 0 and 50 ms */ | 567 | /* previous round is randomized between 0 and 50 ms */ |
561 | #if USE_RANDOM_DELAYS | 568 | #if USE_RANDOM_DELAYS |
562 | ret.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50); | 569 | ret.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
570 | 50); | ||
563 | #else | 571 | #else |
564 | ret = GNUNET_TIME_UNIT_ZERO; | 572 | ret = GNUNET_TIME_UNIT_ZERO; |
565 | #endif | 573 | #endif |
566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
567 | "Transmitting previous round behind schedule in %s\n", | 575 | "Transmitting previous round behind schedule in %s\n", |
568 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 576 | GNUNET_STRINGS_relative_time_to_string (ret, |
577 | GNUNET_YES)); | ||
569 | return ret; | 578 | return ret; |
570 | case 0: | 579 | case 0: |
571 | /* current round is based on best-known matching_bits */ | 580 | /* current round is based on best-known matching_bits */ |
@@ -581,7 +590,8 @@ get_transmit_delay (int round_offset) | |||
581 | GNUNET_STRINGS_relative_time_to_string (ret, | 590 | GNUNET_STRINGS_relative_time_to_string (ret, |
582 | GNUNET_YES)); | 591 | GNUNET_YES)); |
583 | /* now consider round start time and add delay to it */ | 592 | /* now consider round start time and add delay to it */ |
584 | tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); | 593 | tgt = GNUNET_TIME_absolute_add (current_timestamp, |
594 | ret); | ||
585 | return GNUNET_TIME_absolute_get_remaining (tgt); | 595 | return GNUNET_TIME_absolute_get_remaining (tgt); |
586 | } | 596 | } |
587 | GNUNET_break (0); | 597 | GNUNET_break (0); |
@@ -595,99 +605,62 @@ get_transmit_delay (int round_offset) | |||
595 | * @param cls the `struct NSEPeerEntry *` | 605 | * @param cls the `struct NSEPeerEntry *` |
596 | */ | 606 | */ |
597 | static void | 607 | static void |
598 | transmit_task_cb (void *cls); | 608 | transmit_task_cb (void *cls) |
599 | |||
600 | |||
601 | /** | ||
602 | * Called when core is ready to send a message we asked for | ||
603 | * out to the destination. | ||
604 | * | ||
605 | * @param cls closure with the `struct NSEPeerEntry *` | ||
606 | * @param size number of bytes available in @a buf | ||
607 | * @param buf where the callee should write the message | ||
608 | * @return number of bytes written to @a buf | ||
609 | */ | ||
610 | static size_t | ||
611 | transmit_ready (void *cls, | ||
612 | size_t size, | ||
613 | void *buf) | ||
614 | { | 609 | { |
615 | struct NSEPeerEntry *peer_entry = cls; | 610 | struct NSEPeerEntry *peer_entry = cls; |
616 | unsigned int idx; | 611 | unsigned int idx; |
617 | 612 | struct GNUNET_MQ_Envelope *env; | |
618 | peer_entry->th = NULL; | 613 | |
619 | if (NULL == buf) | 614 | peer_entry->transmit_task = NULL; |
620 | { | ||
621 | /* client disconnected */ | ||
622 | return 0; | ||
623 | } | ||
624 | GNUNET_assert (size >= sizeof (struct GNUNET_NSE_FloodMessage)); | ||
625 | idx = estimate_index; | 615 | idx = estimate_index; |
626 | if (GNUNET_NO == peer_entry->previous_round) | 616 | if (GNUNET_NO == peer_entry->previous_round) |
627 | { | 617 | { |
628 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; | 618 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; |
629 | peer_entry->previous_round = GNUNET_YES; | 619 | peer_entry->previous_round = GNUNET_YES; |
630 | peer_entry->transmit_task = | 620 | peer_entry->transmit_task |
631 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), | 621 | = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), |
632 | &transmit_task_cb, | 622 | &transmit_task_cb, |
633 | peer_entry); | 623 | peer_entry); |
634 | } | 624 | } |
635 | if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && | 625 | if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && |
636 | (NULL != proof_task)) | 626 | (NULL != proof_task)) |
637 | { | 627 | { |
638 | GNUNET_STATISTICS_update (stats, | 628 | GNUNET_STATISTICS_update (stats, |
639 | "# flood messages not generated (no proof yet)", | 629 | "# flood messages not generated (no proof yet)", |
640 | 1, GNUNET_NO); | 630 | 1, |
641 | return 0; | 631 | GNUNET_NO); |
632 | return; | ||
642 | } | 633 | } |
643 | if (0 == ntohs (size_estimate_messages[idx].header.size)) | 634 | if (0 == ntohs (size_estimate_messages[idx].header.size)) |
644 | { | 635 | { |
645 | GNUNET_STATISTICS_update (stats, | 636 | GNUNET_STATISTICS_update (stats, |
646 | "# flood messages not generated (lack of history)", | 637 | "# flood messages not generated (lack of history)", |
647 | 1, GNUNET_NO); | 638 | 1, |
648 | return 0; | 639 | GNUNET_NO); |
640 | return; | ||
649 | } | 641 | } |
650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
651 | "In round %s, sending to `%s' estimate with %u bits\n", | 643 | "In round %s, sending to `%s' estimate with %u bits\n", |
652 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)), | 644 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)), |
653 | GNUNET_i2s (&peer_entry->id), | 645 | GNUNET_i2s (peer_entry->id), |
654 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); | 646 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); |
655 | if (ntohl (size_estimate_messages[idx].hop_count) == 0) | 647 | if (0 == ntohl (size_estimate_messages[idx].hop_count)) |
656 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); | 648 | GNUNET_STATISTICS_update (stats, |
657 | GNUNET_STATISTICS_update (stats, "# flood messages transmitted", 1, | 649 | "# flood messages started", |
650 | 1, | ||
651 | GNUNET_NO); | ||
652 | GNUNET_STATISTICS_update (stats, | ||
653 | "# flood messages transmitted", | ||
654 | 1, | ||
658 | GNUNET_NO); | 655 | GNUNET_NO); |
659 | #if ENABLE_NSE_HISTOGRAM | 656 | #if ENABLE_NSE_HISTOGRAM |
660 | peer_entry->transmitted_messages++; | 657 | peer_entry->transmitted_messages++; |
661 | peer_entry->last_transmitted_size = | 658 | peer_entry->last_transmitted_size |
662 | ntohl(size_estimate_messages[idx].matching_bits); | 659 | = ntohl(size_estimate_messages[idx].matching_bits); |
663 | #endif | 660 | #endif |
664 | GNUNET_memcpy (buf, &size_estimate_messages[idx], | 661 | env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header); |
665 | sizeof (struct GNUNET_NSE_FloodMessage)); | 662 | GNUNET_MQ_send (peer_entry->mq, |
666 | return sizeof (struct GNUNET_NSE_FloodMessage); | 663 | env); |
667 | } | ||
668 | |||
669 | |||
670 | /** | ||
671 | * Task that triggers a NSE P2P transmission. | ||
672 | * | ||
673 | * @param cls the `struct NSEPeerEntry *` | ||
674 | */ | ||
675 | static void | ||
676 | transmit_task_cb (void *cls) | ||
677 | { | ||
678 | struct NSEPeerEntry *peer_entry = cls; | ||
679 | |||
680 | peer_entry->transmit_task = NULL; | ||
681 | |||
682 | GNUNET_assert (NULL == peer_entry->th); | ||
683 | peer_entry->th = | ||
684 | GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, | ||
685 | NSE_PRIORITY, | ||
686 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
687 | &peer_entry->id, | ||
688 | sizeof (struct | ||
689 | GNUNET_NSE_FloodMessage), | ||
690 | &transmit_ready, peer_entry); | ||
691 | } | 664 | } |
692 | 665 | ||
693 | 666 | ||
@@ -723,7 +696,8 @@ setup_flood_message (unsigned int slot, | |||
723 | struct GNUNET_NSE_FloodMessage *fm; | 696 | struct GNUNET_NSE_FloodMessage *fm; |
724 | uint32_t matching_bits; | 697 | uint32_t matching_bits; |
725 | 698 | ||
726 | matching_bits = get_matching_bits (ts, &my_identity); | 699 | matching_bits = get_matching_bits (ts, |
700 | &my_identity); | ||
727 | fm = &size_estimate_messages[slot]; | 701 | fm = &size_estimate_messages[slot]; |
728 | fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage)); | 702 | fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage)); |
729 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); | 703 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); |
@@ -739,10 +713,13 @@ setup_flood_message (unsigned int slot, | |||
739 | fm->proof_of_work = my_proof; | 713 | fm->proof_of_work = my_proof; |
740 | if (nse_work_required > 0) | 714 | if (nse_work_required > 0) |
741 | GNUNET_assert (GNUNET_OK == | 715 | GNUNET_assert (GNUNET_OK == |
742 | GNUNET_CRYPTO_eddsa_sign (my_private_key, &fm->purpose, | 716 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
743 | &fm->signature)); | 717 | &fm->purpose, |
718 | &fm->signature)); | ||
744 | else | 719 | else |
745 | memset (&fm->signature, 0, sizeof (fm->signature)); | 720 | memset (&fm->signature, |
721 | 0, | ||
722 | sizeof (fm->signature)); | ||
746 | } | 723 | } |
747 | 724 | ||
748 | 725 | ||
@@ -763,11 +740,6 @@ schedule_current_round (void *cls, | |||
763 | struct NSEPeerEntry *peer_entry = value; | 740 | struct NSEPeerEntry *peer_entry = value; |
764 | struct GNUNET_TIME_Relative delay; | 741 | struct GNUNET_TIME_Relative delay; |
765 | 742 | ||
766 | if (NULL != peer_entry->th) | ||
767 | { | ||
768 | peer_entry->previous_round = GNUNET_NO; | ||
769 | return GNUNET_OK; | ||
770 | } | ||
771 | if (NULL != peer_entry->transmit_task) | 743 | if (NULL != peer_entry->transmit_task) |
772 | { | 744 | { |
773 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 745 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
@@ -775,14 +747,16 @@ schedule_current_round (void *cls, | |||
775 | } | 747 | } |
776 | #if ENABLE_NSE_HISTOGRAM | 748 | #if ENABLE_NSE_HISTOGRAM |
777 | if (peer_entry->received_messages > 1) | 749 | if (peer_entry->received_messages > 1) |
778 | GNUNET_STATISTICS_update(stats, "# extra messages", | 750 | GNUNET_STATISTICS_update(stats, |
779 | peer_entry->received_messages - 1, GNUNET_NO); | 751 | "# extra messages", |
752 | peer_entry->received_messages - 1, | ||
753 | GNUNET_NO); | ||
780 | peer_entry->transmitted_messages = 0; | 754 | peer_entry->transmitted_messages = 0; |
781 | peer_entry->last_transmitted_size = 0; | 755 | peer_entry->last_transmitted_size = 0; |
782 | peer_entry->received_messages = 0; | 756 | peer_entry->received_messages = 0; |
783 | #endif | 757 | #endif |
784 | delay = | 758 | delay = |
785 | get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0); | 759 | get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); |
786 | peer_entry->transmit_task = | 760 | peer_entry->transmit_task = |
787 | GNUNET_SCHEDULER_add_delayed (delay, | 761 | GNUNET_SCHEDULER_add_delayed (delay, |
788 | &transmit_task_cb, | 762 | &transmit_task_cb, |
@@ -809,7 +783,8 @@ update_flood_message (void *cls) | |||
809 | /* somehow run early, delay more */ | 783 | /* somehow run early, delay more */ |
810 | flood_task = | 784 | flood_task = |
811 | GNUNET_SCHEDULER_add_delayed (offset, | 785 | GNUNET_SCHEDULER_add_delayed (offset, |
812 | &update_flood_message, NULL); | 786 | &update_flood_message, |
787 | NULL); | ||
813 | return; | 788 | return; |
814 | } | 789 | } |
815 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; | 790 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; |
@@ -818,10 +793,10 @@ update_flood_message (void *cls) | |||
818 | current_timestamp = next_timestamp; | 793 | current_timestamp = next_timestamp; |
819 | next_timestamp = | 794 | next_timestamp = |
820 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 795 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
821 | if ((current_timestamp.abs_value_us == | 796 | if ( (current_timestamp.abs_value_us == |
822 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && | 797 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && |
823 | (get_matching_bits (current_timestamp, &my_identity) < | 798 | (get_matching_bits (current_timestamp, &my_identity) < |
824 | ntohl(next_message.matching_bits))) | 799 | ntohl(next_message.matching_bits)) ) |
825 | { | 800 | { |
826 | /* we received a message for this round way early, use it! */ | 801 | /* we received a message for this round way early, use it! */ |
827 | size_estimate_messages[estimate_index] = next_message; | 802 | size_estimate_messages[estimate_index] = next_message; |
@@ -829,12 +804,13 @@ update_flood_message (void *cls) | |||
829 | htonl (1 + ntohl (next_message.hop_count)); | 804 | htonl (1 + ntohl (next_message.hop_count)); |
830 | } | 805 | } |
831 | else | 806 | else |
832 | setup_flood_message (estimate_index, current_timestamp); | 807 | setup_flood_message (estimate_index, |
808 | current_timestamp); | ||
833 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ | 809 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ |
834 | hop_count_max = 0; | 810 | hop_count_max = 0; |
835 | for (i = 0; i < HISTORY_SIZE; i++) | 811 | for (i = 0; i < HISTORY_SIZE; i++) |
836 | hop_count_max = | 812 | hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), |
837 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); | 813 | hop_count_max); |
838 | GNUNET_CONTAINER_multipeermap_iterate (peers, | 814 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
839 | &schedule_current_round, | 815 | &schedule_current_round, |
840 | NULL); | 816 | NULL); |
@@ -858,7 +834,8 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
858 | unsigned int hash_count; | 834 | unsigned int hash_count; |
859 | 835 | ||
860 | hash_count = 0; | 836 | hash_count = 0; |
861 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 837 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, |
838 | hash_count)) | ||
862 | hash_count++; | 839 | hash_count++; |
863 | return hash_count; | 840 | return hash_count; |
864 | } | 841 | } |
@@ -880,10 +857,15 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | |||
880 | sizeof (val)] GNUNET_ALIGN; | 857 | sizeof (val)] GNUNET_ALIGN; |
881 | struct GNUNET_HashCode result; | 858 | struct GNUNET_HashCode result; |
882 | 859 | ||
883 | GNUNET_memcpy (buf, &val, sizeof (val)); | 860 | GNUNET_memcpy (buf, |
884 | GNUNET_memcpy (&buf[sizeof (val)], pkey, | 861 | &val, |
885 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 862 | sizeof (val)); |
886 | pow_hash (buf, sizeof (buf), &result); | 863 | GNUNET_memcpy (&buf[sizeof (val)], |
864 | pkey, | ||
865 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | ||
866 | pow_hash (buf, | ||
867 | sizeof (buf), | ||
868 | &result); | ||
887 | return (count_leading_zeroes (&result) >= | 869 | return (count_leading_zeroes (&result) >= |
888 | nse_work_required) ? GNUNET_YES : GNUNET_NO; | 870 | nse_work_required) ? GNUNET_YES : GNUNET_NO; |
889 | } | 871 | } |
@@ -898,15 +880,21 @@ write_proof () | |||
898 | char *proof; | 880 | char *proof; |
899 | 881 | ||
900 | if (GNUNET_OK != | 882 | if (GNUNET_OK != |
901 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 883 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
884 | "NSE", | ||
885 | "PROOFFILE", | ||
886 | &proof)) | ||
902 | return; | 887 | return; |
903 | if (sizeof (my_proof) != | 888 | if (sizeof (my_proof) != |
904 | GNUNET_DISK_fn_write (proof, &my_proof, sizeof (my_proof), | 889 | GNUNET_DISK_fn_write (proof, |
890 | &my_proof, | ||
891 | sizeof (my_proof), | ||
905 | GNUNET_DISK_PERM_USER_READ | | 892 | GNUNET_DISK_PERM_USER_READ | |
906 | GNUNET_DISK_PERM_USER_WRITE)) | 893 | GNUNET_DISK_PERM_USER_WRITE)) |
907 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); | 894 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
895 | "write", | ||
896 | proof); | ||
908 | GNUNET_free (proof); | 897 | GNUNET_free (proof); |
909 | |||
910 | } | 898 | } |
911 | 899 | ||
912 | 900 | ||
@@ -1021,18 +1009,15 @@ update_flood_times (void *cls, | |||
1021 | struct NSEPeerEntry *peer_entry = value; | 1009 | struct NSEPeerEntry *peer_entry = value; |
1022 | struct GNUNET_TIME_Relative delay; | 1010 | struct GNUNET_TIME_Relative delay; |
1023 | 1011 | ||
1024 | if (NULL != peer_entry->th) | ||
1025 | return GNUNET_OK; /* already active */ | ||
1026 | if (peer_entry == exclude) | 1012 | if (peer_entry == exclude) |
1027 | return GNUNET_OK; /* trigger of the update */ | 1013 | return GNUNET_OK; /* trigger of the update */ |
1028 | if (peer_entry->previous_round == GNUNET_NO) | 1014 | if (GNUNET_NO == peer_entry->previous_round) |
1029 | { | 1015 | { |
1030 | /* still stuck in previous round, no point to update, check that | 1016 | /* still stuck in previous round, no point to update, check that |
1031 | * we are active here though... */ | 1017 | * we are active here though... */ |
1032 | if ( (NULL == peer_entry->transmit_task) && | 1018 | if (NULL == peer_entry->transmit_task) |
1033 | (NULL == peer_entry->th) ) | ||
1034 | { | 1019 | { |
1035 | GNUNET_break (0); | 1020 | GNUNET_break (0); |
1036 | } | 1021 | } |
1037 | return GNUNET_OK; | 1022 | return GNUNET_OK; |
1038 | } | 1023 | } |
@@ -1052,18 +1037,15 @@ update_flood_times (void *cls, | |||
1052 | /** | 1037 | /** |
1053 | * Core handler for size estimate flooding messages. | 1038 | * Core handler for size estimate flooding messages. |
1054 | * | 1039 | * |
1055 | * @param cls closure unused | 1040 | * @param cls peer this message is from |
1056 | * @param message message | 1041 | * @param incoming_flood received message |
1057 | * @param peer peer identity this message is from (ignored) | ||
1058 | */ | 1042 | */ |
1059 | static int | 1043 | static void |
1060 | handle_p2p_size_estimate (void *cls, | 1044 | handle_p2p_estimate (void *cls, |
1061 | const struct GNUNET_PeerIdentity *peer, | 1045 | const struct GNUNET_NSE_FloodMessage *incoming_flood) |
1062 | const struct GNUNET_MessageHeader *message) | ||
1063 | { | 1046 | { |
1064 | const struct GNUNET_NSE_FloodMessage *incoming_flood; | 1047 | struct NSEPeerEntry *peer_entry = cls; |
1065 | struct GNUNET_TIME_Absolute ts; | 1048 | struct GNUNET_TIME_Absolute ts; |
1066 | struct NSEPeerEntry *peer_entry; | ||
1067 | uint32_t matching_bits; | 1049 | uint32_t matching_bits; |
1068 | unsigned int idx; | 1050 | unsigned int idx; |
1069 | 1051 | ||
@@ -1078,8 +1060,10 @@ handle_p2p_size_estimate (void *cls, | |||
1078 | GNUNET_BIO_write_int64 (histogram, t); | 1060 | GNUNET_BIO_write_int64 (histogram, t); |
1079 | } | 1061 | } |
1080 | #endif | 1062 | #endif |
1081 | incoming_flood = (const struct GNUNET_NSE_FloodMessage *) message; | 1063 | GNUNET_STATISTICS_update (stats, |
1082 | GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO); | 1064 | "# flood messages received", |
1065 | 1, | ||
1066 | GNUNET_NO); | ||
1083 | matching_bits = ntohl (incoming_flood->matching_bits); | 1067 | matching_bits = ntohl (incoming_flood->matching_bits); |
1084 | #if DEBUG_NSE | 1068 | #if DEBUG_NSE |
1085 | { | 1069 | { |
@@ -1089,31 +1073,30 @@ handle_p2p_size_estimate (void *cls, | |||
1089 | 1073 | ||
1090 | GNUNET_snprintf (origin, | 1074 | GNUNET_snprintf (origin, |
1091 | sizeof (origin), | 1075 | sizeof (origin), |
1092 | "%4s", | 1076 | "%s", |
1093 | GNUNET_i2s (&incoming_flood->origin)); | 1077 | GNUNET_i2s (&incoming_flood->origin)); |
1094 | GNUNET_snprintf (pred, | 1078 | GNUNET_snprintf (pred, |
1095 | sizeof (pred), | 1079 | sizeof (pred), |
1096 | "%4s", | 1080 | "%s", |
1097 | GNUNET_i2s (peer)); | 1081 | GNUNET_i2s (peer_entry->id)); |
1098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1099 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", | 1083 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", |
1100 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)), | 1084 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)), |
1101 | origin, pred, GNUNET_i2s (&my_identity), | 1085 | origin, |
1086 | pred, | ||
1087 | GNUNET_i2s (&my_identity), | ||
1102 | (unsigned int) matching_bits); | 1088 | (unsigned int) matching_bits); |
1103 | } | 1089 | } |
1104 | #endif | 1090 | #endif |
1105 | 1091 | ||
1106 | peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
1107 | if (NULL == peer_entry) | ||
1108 | { | ||
1109 | GNUNET_break (0); | ||
1110 | return GNUNET_OK; | ||
1111 | } | ||
1112 | #if ENABLE_NSE_HISTOGRAM | 1092 | #if ENABLE_NSE_HISTOGRAM |
1113 | peer_entry->received_messages++; | 1093 | peer_entry->received_messages++; |
1114 | if (peer_entry->transmitted_messages > 0 && | 1094 | if (peer_entry->transmitted_messages > 0 && |
1115 | peer_entry->last_transmitted_size >= matching_bits) | 1095 | peer_entry->last_transmitted_size >= matching_bits) |
1116 | GNUNET_STATISTICS_update(stats, "# cross messages", 1, GNUNET_NO); | 1096 | GNUNET_STATISTICS_update(stats, |
1097 | "# cross messages", | ||
1098 | 1, | ||
1099 | GNUNET_NO); | ||
1117 | #endif | 1100 | #endif |
1118 | 1101 | ||
1119 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); | 1102 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); |
@@ -1125,35 +1108,39 @@ handle_p2p_size_estimate (void *cls, | |||
1125 | else if (ts.abs_value_us == next_timestamp.abs_value_us) | 1108 | else if (ts.abs_value_us == next_timestamp.abs_value_us) |
1126 | { | 1109 | { |
1127 | if (matching_bits <= ntohl (next_message.matching_bits)) | 1110 | if (matching_bits <= ntohl (next_message.matching_bits)) |
1128 | return GNUNET_OK; /* ignore, simply too early/late */ | 1111 | return; /* ignore, simply too early/late */ |
1129 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | 1112 | if (GNUNET_YES != |
1113 | verify_message_crypto (incoming_flood)) | ||
1130 | { | 1114 | { |
1131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1132 | "Peer %s is likely ill-configured!\n", | 1116 | "Peer %s is likely ill-configured!\n", |
1133 | GNUNET_i2s (peer)); | 1117 | GNUNET_i2s (peer_entry->id)); |
1134 | GNUNET_break_op (0); | 1118 | GNUNET_break_op (0); |
1135 | return GNUNET_OK; | 1119 | return; |
1136 | } | 1120 | } |
1137 | next_message = *incoming_flood; | 1121 | next_message = *incoming_flood; |
1138 | return GNUNET_OK; | 1122 | return; |
1139 | } | 1123 | } |
1140 | else | 1124 | else |
1141 | { | 1125 | { |
1142 | GNUNET_STATISTICS_update (stats, | 1126 | GNUNET_STATISTICS_update (stats, |
1143 | "# flood messages discarded (clock skew too large)", | 1127 | "# flood messages discarded (clock skew too large)", |
1144 | 1, GNUNET_NO); | 1128 | 1, GNUNET_NO); |
1145 | return GNUNET_OK; | 1129 | return; |
1146 | } | 1130 | } |
1147 | if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))) | 1131 | if (0 == (memcmp (peer_entry->id, |
1132 | &my_identity, | ||
1133 | sizeof (struct GNUNET_PeerIdentity)))) | ||
1148 | { | 1134 | { |
1149 | /* send to self, update our own estimate IF this also comes from us! */ | 1135 | /* send to self, update our own estimate IF this also comes from us! */ |
1150 | if (0 == | 1136 | if (0 == |
1151 | memcmp (&incoming_flood->origin, | 1137 | memcmp (&incoming_flood->origin, |
1152 | &my_identity, sizeof (my_identity))) | 1138 | &my_identity, sizeof (my_identity))) |
1153 | update_network_size_estimate (); | 1139 | update_network_size_estimate (); |
1154 | return GNUNET_OK; | 1140 | return; |
1155 | } | 1141 | } |
1156 | if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) | 1142 | if (matching_bits == |
1143 | ntohl (size_estimate_messages[idx].matching_bits)) | ||
1157 | { | 1144 | { |
1158 | /* Cancel transmission in the other direction, as this peer clearly has | 1145 | /* Cancel transmission in the other direction, as this peer clearly has |
1159 | up-to-date information already. Even if we didn't talk to this peer in | 1146 | up-to-date information already. Even if we didn't talk to this peer in |
@@ -1164,7 +1151,7 @@ handle_p2p_size_estimate (void *cls, | |||
1164 | { | 1151 | { |
1165 | /* do not transmit information for the previous round to this peer | 1152 | /* do not transmit information for the previous round to this peer |
1166 | anymore (but allow current round) */ | 1153 | anymore (but allow current round) */ |
1167 | return GNUNET_OK; | 1154 | return; |
1168 | } | 1155 | } |
1169 | /* got up-to-date information for current round, cancel transmission to | 1156 | /* got up-to-date information for current round, cancel transmission to |
1170 | * this peer altogether */ | 1157 | * this peer altogether */ |
@@ -1173,36 +1160,33 @@ handle_p2p_size_estimate (void *cls, | |||
1173 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1160 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1174 | peer_entry->transmit_task = NULL; | 1161 | peer_entry->transmit_task = NULL; |
1175 | } | 1162 | } |
1176 | if (NULL != peer_entry->th) | 1163 | return; |
1177 | { | ||
1178 | GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th); | ||
1179 | peer_entry->th = NULL; | ||
1180 | } | ||
1181 | return GNUNET_OK; | ||
1182 | } | 1164 | } |
1183 | if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) | 1165 | if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) |
1184 | { | 1166 | { |
1185 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) { | 1167 | if ( (idx < estimate_index) && |
1168 | (peer_entry->previous_round == GNUNET_YES)) | ||
1169 | { | ||
1186 | peer_entry->previous_round = GNUNET_NO; | 1170 | peer_entry->previous_round = GNUNET_NO; |
1187 | } | 1171 | } |
1188 | /* push back our result now, that peer is spreading bad information... */ | 1172 | /* push back our result now, that peer is spreading bad information... */ |
1189 | if (NULL == peer_entry->th) | 1173 | if (NULL != peer_entry->transmit_task) |
1190 | { | 1174 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1191 | if (peer_entry->transmit_task != NULL) | 1175 | peer_entry->transmit_task |
1192 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1176 | = GNUNET_SCHEDULER_add_now (&transmit_task_cb, |
1193 | peer_entry->transmit_task = | 1177 | peer_entry); |
1194 | GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry); | ||
1195 | } | ||
1196 | /* Not closer than our most recent message, no need to do work here */ | 1178 | /* Not closer than our most recent message, no need to do work here */ |
1197 | GNUNET_STATISTICS_update (stats, | 1179 | GNUNET_STATISTICS_update (stats, |
1198 | "# flood messages ignored (had closer already)", | 1180 | "# flood messages ignored (had closer already)", |
1199 | 1, GNUNET_NO); | 1181 | 1, |
1200 | return GNUNET_OK; | 1182 | GNUNET_NO); |
1183 | return; | ||
1201 | } | 1184 | } |
1202 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | 1185 | if (GNUNET_YES != |
1186 | verify_message_crypto (incoming_flood)) | ||
1203 | { | 1187 | { |
1204 | GNUNET_break_op (0); | 1188 | GNUNET_break_op (0); |
1205 | return GNUNET_OK; | 1189 | return; |
1206 | } | 1190 | } |
1207 | GNUNET_assert (matching_bits > | 1191 | GNUNET_assert (matching_bits > |
1208 | ntohl (size_estimate_messages[idx].matching_bits)); | 1192 | ntohl (size_estimate_messages[idx].matching_bits)); |
@@ -1212,23 +1196,19 @@ handle_p2p_size_estimate (void *cls, | |||
1212 | peer_entry->previous_round = GNUNET_YES; | 1196 | peer_entry->previous_round = GNUNET_YES; |
1213 | if (idx == estimate_index) | 1197 | if (idx == estimate_index) |
1214 | { | 1198 | { |
1215 | /* cancel any activity for current round */ | 1199 | /* cancel any activity for current round */ |
1216 | if (peer_entry->transmit_task != NULL) | 1200 | if (NULL != peer_entry->transmit_task) |
1217 | { | 1201 | { |
1218 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1202 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1219 | peer_entry->transmit_task = NULL; | 1203 | peer_entry->transmit_task = NULL; |
1220 | } | 1204 | } |
1221 | if (peer_entry->th != NULL) | ||
1222 | { | ||
1223 | GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th); | ||
1224 | peer_entry->th = NULL; | ||
1225 | } | ||
1226 | } | 1205 | } |
1227 | size_estimate_messages[idx] = *incoming_flood; | 1206 | size_estimate_messages[idx] = *incoming_flood; |
1228 | size_estimate_messages[idx].hop_count = | 1207 | size_estimate_messages[idx].hop_count = |
1229 | htonl (ntohl (incoming_flood->hop_count) + 1); | 1208 | htonl (ntohl (incoming_flood->hop_count) + 1); |
1230 | hop_count_max = | 1209 | hop_count_max = |
1231 | GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max); | 1210 | GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, |
1211 | hop_count_max); | ||
1232 | GNUNET_STATISTICS_set (stats, | 1212 | GNUNET_STATISTICS_set (stats, |
1233 | "# estimated network diameter", | 1213 | "# estimated network diameter", |
1234 | hop_count_max, GNUNET_NO); | 1214 | hop_count_max, GNUNET_NO); |
@@ -1237,9 +1217,9 @@ handle_p2p_size_estimate (void *cls, | |||
1237 | update_network_size_estimate (); | 1217 | update_network_size_estimate (); |
1238 | 1218 | ||
1239 | /* flood to rest */ | 1219 | /* flood to rest */ |
1240 | GNUNET_CONTAINER_multipeermap_iterate (peers, &update_flood_times, | 1220 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
1221 | &update_flood_times, | ||
1241 | peer_entry); | 1222 | peer_entry); |
1242 | return GNUNET_OK; | ||
1243 | } | 1223 | } |
1244 | 1224 | ||
1245 | 1225 | ||
@@ -1250,20 +1230,32 @@ handle_p2p_size_estimate (void *cls, | |||
1250 | * @param cls closure | 1230 | * @param cls closure |
1251 | * @param peer peer identity this notification is about | 1231 | * @param peer peer identity this notification is about |
1252 | */ | 1232 | */ |
1253 | static void | 1233 | static void * |
1254 | handle_core_connect (void *cls, | 1234 | handle_core_connect (void *cls, |
1255 | const struct GNUNET_PeerIdentity *peer) | 1235 | const struct GNUNET_PeerIdentity *peer, |
1236 | struct GNUNET_MQ_Handle *mq) | ||
1256 | { | 1237 | { |
1257 | struct NSEPeerEntry *peer_entry; | 1238 | struct NSEPeerEntry *peer_entry; |
1239 | uint64_t flags; | ||
1240 | const void *extra; | ||
1258 | 1241 | ||
1259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1260 | "Peer `%s' connected to us\n", | 1243 | "Peer `%s' connected to us\n", |
1261 | GNUNET_i2s (peer)); | 1244 | GNUNET_i2s (peer)); |
1245 | /* set our default transmission options */ | ||
1246 | extra = GNUNET_CORE_get_mq_options (GNUNET_NO, | ||
1247 | NSE_PRIORITY, | ||
1248 | &flags); | ||
1249 | GNUNET_MQ_set_options (mq, | ||
1250 | flags, | ||
1251 | extra); | ||
1252 | /* create our peer entry for this peer */ | ||
1262 | peer_entry = GNUNET_new (struct NSEPeerEntry); | 1253 | peer_entry = GNUNET_new (struct NSEPeerEntry); |
1263 | peer_entry->id = *peer; | 1254 | peer_entry->id = peer; |
1255 | peer_entry->mq = mq; | ||
1264 | GNUNET_assert (GNUNET_OK == | 1256 | GNUNET_assert (GNUNET_OK == |
1265 | GNUNET_CONTAINER_multipeermap_put (peers, | 1257 | GNUNET_CONTAINER_multipeermap_put (peers, |
1266 | peer, | 1258 | peer_entry->id, |
1267 | peer_entry, | 1259 | peer_entry, |
1268 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1260 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1269 | peer_entry->transmit_task = | 1261 | peer_entry->transmit_task = |
@@ -1274,6 +1266,7 @@ handle_core_connect (void *cls, | |||
1274 | "# peers connected", | 1266 | "# peers connected", |
1275 | 1, | 1267 | 1, |
1276 | GNUNET_NO); | 1268 | GNUNET_NO); |
1269 | return peer_entry; | ||
1277 | } | 1270 | } |
1278 | 1271 | ||
1279 | 1272 | ||
@@ -1283,36 +1276,32 @@ handle_core_connect (void *cls, | |||
1283 | * | 1276 | * |
1284 | * @param cls closure | 1277 | * @param cls closure |
1285 | * @param peer peer identity this notification is about | 1278 | * @param peer peer identity this notification is about |
1279 | * @parma internal_cls the `struct NSEPeerEntry` for the @a peer | ||
1286 | */ | 1280 | */ |
1287 | static void | 1281 | static void |
1288 | handle_core_disconnect (void *cls, | 1282 | handle_core_disconnect (void *cls, |
1289 | const struct GNUNET_PeerIdentity *peer) | 1283 | const struct GNUNET_PeerIdentity *peer, |
1284 | void *internal_cls) | ||
1290 | { | 1285 | { |
1291 | struct NSEPeerEntry *pos; | 1286 | struct NSEPeerEntry *pos = internal_cls; |
1292 | 1287 | ||
1293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1294 | "Peer `%s' disconnected from us\n", | 1289 | "Peer `%s' disconnected from us\n", |
1295 | GNUNET_i2s (peer)); | 1290 | GNUNET_i2s (peer)); |
1296 | pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
1297 | if (NULL == pos) | ||
1298 | { | ||
1299 | GNUNET_break (0); | ||
1300 | return; | ||
1301 | } | ||
1302 | GNUNET_assert (GNUNET_YES == | 1291 | GNUNET_assert (GNUNET_YES == |
1303 | GNUNET_CONTAINER_multipeermap_remove (peers, peer, | 1292 | GNUNET_CONTAINER_multipeermap_remove (peers, |
1293 | peer, | ||
1304 | pos)); | 1294 | pos)); |
1305 | if (pos->transmit_task != NULL) { | 1295 | if (pos->transmit_task != NULL) |
1296 | { | ||
1306 | GNUNET_SCHEDULER_cancel (pos->transmit_task); | 1297 | GNUNET_SCHEDULER_cancel (pos->transmit_task); |
1307 | pos->transmit_task = NULL; | 1298 | pos->transmit_task = NULL; |
1308 | } | 1299 | } |
1309 | if (NULL != pos->th) | ||
1310 | { | ||
1311 | GNUNET_CORE_notify_transmit_ready_cancel (pos->th); | ||
1312 | pos->th = NULL; | ||
1313 | } | ||
1314 | GNUNET_free (pos); | 1300 | GNUNET_free (pos); |
1315 | GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO); | 1301 | GNUNET_STATISTICS_update (stats, |
1302 | "# peers connected", | ||
1303 | -1, | ||
1304 | GNUNET_NO); | ||
1316 | } | 1305 | } |
1317 | 1306 | ||
1318 | 1307 | ||
@@ -1360,7 +1349,7 @@ shutdown_task (void *cls) | |||
1360 | } | 1349 | } |
1361 | if (NULL != core_api) | 1350 | if (NULL != core_api) |
1362 | { | 1351 | { |
1363 | GNUNET_CORE_disconnect (core_api); | 1352 | GNUNET_CORE_disconnecT (core_api); |
1364 | core_api = NULL; | 1353 | core_api = NULL; |
1365 | } | 1354 | } |
1366 | if (NULL != stats) | 1355 | if (NULL != stats) |
@@ -1414,28 +1403,35 @@ core_init (void *cls, | |||
1414 | 1403 | ||
1415 | if (NULL == identity) | 1404 | if (NULL == identity) |
1416 | { | 1405 | { |
1417 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); | 1406 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1407 | "Connection to core FAILED!\n"); | ||
1418 | GNUNET_SCHEDULER_shutdown (); | 1408 | GNUNET_SCHEDULER_shutdown (); |
1419 | return; | 1409 | return; |
1420 | } | 1410 | } |
1421 | GNUNET_assert (0 == | 1411 | GNUNET_assert (0 == |
1422 | memcmp (&my_identity, identity, | 1412 | memcmp (&my_identity, |
1413 | identity, | ||
1423 | sizeof (struct GNUNET_PeerIdentity))); | 1414 | sizeof (struct GNUNET_PeerIdentity))); |
1424 | now = GNUNET_TIME_absolute_get (); | 1415 | now = GNUNET_TIME_absolute_get (); |
1425 | current_timestamp.abs_value_us = | 1416 | current_timestamp.abs_value_us = |
1426 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * | 1417 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * |
1427 | gnunet_nse_interval.rel_value_us; | 1418 | gnunet_nse_interval.rel_value_us; |
1428 | next_timestamp = | 1419 | next_timestamp = |
1429 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 1420 | GNUNET_TIME_absolute_add (current_timestamp, |
1421 | gnunet_nse_interval); | ||
1430 | estimate_index = HISTORY_SIZE - 1; | 1422 | estimate_index = HISTORY_SIZE - 1; |
1431 | estimate_count = 0; | 1423 | estimate_count = 0; |
1432 | if (GNUNET_YES == check_proof_of_work (&my_identity.public_key, my_proof)) | 1424 | if (GNUNET_YES == |
1425 | check_proof_of_work (&my_identity.public_key, | ||
1426 | my_proof)) | ||
1433 | { | 1427 | { |
1434 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1428 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1435 | prev_time.abs_value_us = | 1429 | prev_time.abs_value_us = |
1436 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; | 1430 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; |
1437 | setup_flood_message (idx, prev_time); | 1431 | setup_flood_message (idx, |
1438 | setup_flood_message (estimate_index, current_timestamp); | 1432 | prev_time); |
1433 | setup_flood_message (estimate_index, | ||
1434 | current_timestamp); | ||
1439 | estimate_count++; | 1435 | estimate_count++; |
1440 | } | 1436 | } |
1441 | flood_task = | 1437 | flood_task = |
@@ -1445,22 +1441,25 @@ core_init (void *cls, | |||
1445 | NULL); | 1441 | NULL); |
1446 | } | 1442 | } |
1447 | 1443 | ||
1444 | |||
1448 | #if ENABLE_NSE_HISTOGRAM | 1445 | #if ENABLE_NSE_HISTOGRAM |
1449 | /** | 1446 | /** |
1450 | * Function called with the status of the testbed logger service | 1447 | * Function called with the status of the testbed logger service |
1451 | * | 1448 | * |
1452 | * @param cls NULL | 1449 | * @param cls NULL |
1453 | * @param status GNUNET_YES if the service is running, | 1450 | * @param status #GNUNET_YES if the service is running, |
1454 | * GNUNET_NO if the service is not running | 1451 | * #GNUNET_NO if the service is not running |
1455 | * GNUNET_SYSERR if the configuration is invalid | 1452 | * #GNUNET_SYSERR if the configuration is invalid |
1456 | */ | 1453 | */ |
1457 | static void | 1454 | static void |
1458 | status_cb (void *cls, int status) | 1455 | status_cb (void *cls, |
1456 | int status) | ||
1459 | { | 1457 | { |
1460 | logger_test = NULL; | 1458 | logger_test = NULL; |
1461 | if (GNUNET_YES != status) | 1459 | if (GNUNET_YES != status) |
1462 | { | 1460 | { |
1463 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n"); | 1461 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1462 | "Testbed logger not running\n"); | ||
1464 | return; | 1463 | return; |
1465 | } | 1464 | } |
1466 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg))) | 1465 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg))) |
@@ -1485,15 +1484,17 @@ run (void *cls, | |||
1485 | struct GNUNET_SERVER_Handle *server, | 1484 | struct GNUNET_SERVER_Handle *server, |
1486 | const struct GNUNET_CONFIGURATION_Handle *c) | 1485 | const struct GNUNET_CONFIGURATION_Handle *c) |
1487 | { | 1486 | { |
1487 | GNUNET_MQ_hd_fixed_size (p2p_estimate, | ||
1488 | GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, | ||
1489 | struct GNUNET_NSE_FloodMessage); | ||
1488 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1490 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1489 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, | 1491 | {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_NSE_START, |
1490 | sizeof (struct GNUNET_MessageHeader)}, | 1492 | sizeof (struct GNUNET_MessageHeader)}, |
1491 | {NULL, NULL, 0, 0} | 1493 | {NULL, NULL, 0, 0} |
1492 | }; | 1494 | }; |
1493 | static const struct GNUNET_CORE_MessageHandler core_handlers[] = { | 1495 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
1494 | {&handle_p2p_size_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, | 1496 | make_p2p_estimate_handler (NULL), |
1495 | sizeof (struct GNUNET_NSE_FloodMessage)}, | 1497 | GNUNET_MQ_handler_end (), |
1496 | {NULL, 0, 0} | ||
1497 | }; | 1498 | }; |
1498 | char *proof; | 1499 | char *proof; |
1499 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 1500 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
@@ -1501,29 +1502,38 @@ run (void *cls, | |||
1501 | cfg = c; | 1502 | cfg = c; |
1502 | srv = server; | 1503 | srv = server; |
1503 | if (GNUNET_OK != | 1504 | if (GNUNET_OK != |
1504 | GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "INTERVAL", | 1505 | GNUNET_CONFIGURATION_get_value_time (cfg, |
1506 | "NSE", | ||
1507 | "INTERVAL", | ||
1505 | &gnunet_nse_interval)) | 1508 | &gnunet_nse_interval)) |
1506 | { | 1509 | { |
1507 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1510 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1508 | "NSE", "INTERVAL"); | 1511 | "NSE", |
1512 | "INTERVAL"); | ||
1509 | GNUNET_SCHEDULER_shutdown (); | 1513 | GNUNET_SCHEDULER_shutdown (); |
1510 | return; | 1514 | return; |
1511 | } | 1515 | } |
1512 | if (GNUNET_OK != | 1516 | if (GNUNET_OK != |
1513 | GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "WORKDELAY", | 1517 | GNUNET_CONFIGURATION_get_value_time (cfg, |
1518 | "NSE", | ||
1519 | "WORKDELAY", | ||
1514 | &proof_find_delay)) | 1520 | &proof_find_delay)) |
1515 | { | 1521 | { |
1516 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1522 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1517 | "NSE", "WORKDELAY"); | 1523 | "NSE", |
1524 | "WORKDELAY"); | ||
1518 | GNUNET_SCHEDULER_shutdown (); | 1525 | GNUNET_SCHEDULER_shutdown (); |
1519 | return; | 1526 | return; |
1520 | } | 1527 | } |
1521 | if (GNUNET_OK != | 1528 | if (GNUNET_OK != |
1522 | GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS", | 1529 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1530 | "NSE", | ||
1531 | "WORKBITS", | ||
1523 | &nse_work_required)) | 1532 | &nse_work_required)) |
1524 | { | 1533 | { |
1525 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1534 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1526 | "NSE", "WORKBITS"); | 1535 | "NSE", |
1536 | "WORKBITS"); | ||
1527 | GNUNET_SCHEDULER_shutdown (); | 1537 | GNUNET_SCHEDULER_shutdown (); |
1528 | return; | 1538 | return; |
1529 | } | 1539 | } |
@@ -1543,21 +1553,28 @@ run (void *cls, | |||
1543 | char *histogram_fn; | 1553 | char *histogram_fn; |
1544 | 1554 | ||
1545 | if (GNUNET_OK == | 1555 | if (GNUNET_OK == |
1546 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM_DIR", | 1556 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1557 | "NSE", | ||
1558 | "HISTOGRAM_DIR", | ||
1547 | &histogram_dir)) | 1559 | &histogram_dir)) |
1548 | { | 1560 | { |
1549 | GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", | 1561 | GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn, |
1562 | "%s/timestamps", | ||
1550 | histogram_dir)); | 1563 | histogram_dir)); |
1551 | GNUNET_free (histogram_dir); | 1564 | GNUNET_free (histogram_dir); |
1552 | histogram = GNUNET_BIO_write_open (histogram_fn); | 1565 | histogram = GNUNET_BIO_write_open (histogram_fn); |
1553 | GNUNET_free (histogram_fn); | ||
1554 | if (NULL == histogram) | 1566 | if (NULL == histogram) |
1555 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open histogram file\n"); | 1567 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1568 | "Unable to open histogram file `%s'\n", | ||
1569 | histogram_fn); | ||
1570 | GNUNET_free (histogram_fn); | ||
1556 | } | 1571 | } |
1557 | logger_test = | 1572 | logger_test = |
1558 | GNUNET_CLIENT_service_test ("testbed-logger", cfg, | 1573 | GNUNET_CLIENT_service_test ("testbed-logger", |
1574 | cfg, | ||
1559 | GNUNET_TIME_UNIT_SECONDS, | 1575 | GNUNET_TIME_UNIT_SECONDS, |
1560 | &status_cb, NULL); | 1576 | &status_cb, |
1577 | NULL); | ||
1561 | 1578 | ||
1562 | } | 1579 | } |
1563 | #endif | 1580 | #endif |
@@ -1568,11 +1585,16 @@ run (void *cls, | |||
1568 | GNUNET_assert (NULL != pk); | 1585 | GNUNET_assert (NULL != pk); |
1569 | my_private_key = pk; | 1586 | my_private_key = pk; |
1570 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, | 1587 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, |
1571 | &my_identity.public_key); | 1588 | &my_identity.public_key); |
1572 | if (GNUNET_OK != | 1589 | if (GNUNET_OK != |
1573 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 1590 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1591 | "NSE", | ||
1592 | "PROOFFILE", | ||
1593 | &proof)) | ||
1574 | { | 1594 | { |
1575 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); | 1595 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1596 | "NSE", | ||
1597 | "PROOFFILE"); | ||
1576 | GNUNET_free (my_private_key); | 1598 | GNUNET_free (my_private_key); |
1577 | my_private_key = NULL; | 1599 | my_private_key = NULL; |
1578 | GNUNET_SCHEDULER_shutdown (); | 1600 | GNUNET_SCHEDULER_shutdown (); |
@@ -1580,33 +1602,35 @@ run (void *cls, | |||
1580 | } | 1602 | } |
1581 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | 1603 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || |
1582 | (sizeof (my_proof) != | 1604 | (sizeof (my_proof) != |
1583 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | 1605 | GNUNET_DISK_fn_read (proof, |
1606 | &my_proof, | ||
1607 | sizeof (my_proof)))) | ||
1584 | my_proof = 0; | 1608 | my_proof = 0; |
1585 | GNUNET_free (proof); | 1609 | GNUNET_free (proof); |
1586 | proof_task = | 1610 | proof_task = |
1587 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1611 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1588 | &find_proof, NULL); | 1612 | &find_proof, |
1613 | NULL); | ||
1589 | 1614 | ||
1590 | peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 1615 | peers = GNUNET_CONTAINER_multipeermap_create (128, |
1591 | GNUNET_SERVER_add_handlers (srv, handlers); | 1616 | GNUNET_YES); |
1617 | GNUNET_SERVER_add_handlers (srv, | ||
1618 | handlers); | ||
1592 | nc = GNUNET_SERVER_notification_context_create (srv, 1); | 1619 | nc = GNUNET_SERVER_notification_context_create (srv, 1); |
1593 | /* Connect to core service and register core handlers */ | 1620 | /* Connect to core service and register core handlers */ |
1594 | core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ | 1621 | core_api = GNUNET_CORE_connecT (cfg, /* Main configuration */ |
1595 | NULL, /* Closure passed to functions */ | 1622 | NULL, /* Closure passed to functions */ |
1596 | &core_init, /* Call core_init once connected */ | 1623 | &core_init, /* Call core_init once connected */ |
1597 | &handle_core_connect, /* Handle connects */ | 1624 | &handle_core_connect, /* Handle connects */ |
1598 | &handle_core_disconnect, /* Handle disconnects */ | 1625 | &handle_core_disconnect, /* Handle disconnects */ |
1599 | NULL, /* Don't want notified about all incoming messages */ | 1626 | core_handlers); /* Register these handlers */ |
1600 | GNUNET_NO, /* For header only inbound notification */ | ||
1601 | NULL, /* Don't want notified about all outbound messages */ | ||
1602 | GNUNET_NO, /* For header only outbound notification */ | ||
1603 | core_handlers); /* Register these handlers */ | ||
1604 | if (NULL == core_api) | 1627 | if (NULL == core_api) |
1605 | { | 1628 | { |
1606 | GNUNET_SCHEDULER_shutdown (); | 1629 | GNUNET_SCHEDULER_shutdown (); |
1607 | return; | 1630 | return; |
1608 | } | 1631 | } |
1609 | stats = GNUNET_STATISTICS_create ("nse", cfg); | 1632 | stats = GNUNET_STATISTICS_create ("nse", |
1633 | cfg); | ||
1610 | } | 1634 | } |
1611 | 1635 | ||
1612 | 1636 | ||
@@ -1622,8 +1646,12 @@ main (int argc, | |||
1622 | char *const *argv) | 1646 | char *const *argv) |
1623 | { | 1647 | { |
1624 | return (GNUNET_OK == | 1648 | return (GNUNET_OK == |
1625 | GNUNET_SERVICE_run (argc, argv, "nse", GNUNET_SERVICE_OPTION_NONE, | 1649 | GNUNET_SERVICE_run (argc, |
1626 | &run, NULL)) ? 0 : 1; | 1650 | argv, |
1651 | "nse", | ||
1652 | GNUNET_SERVICE_OPTION_NONE, | ||
1653 | &run, | ||
1654 | NULL)) ? 0 : 1; | ||
1627 | } | 1655 | } |
1628 | 1656 | ||
1629 | 1657 | ||