diff options
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 181 |
1 files changed, 81 insertions, 100 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 9da9abba2..5f880088f 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -315,8 +315,10 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
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 = |
319 | % HISTORY_SIZE].matching_bits); | 319 | htonl (size_estimate_messages |
320 | [(estimate_index - i + | ||
321 | HISTORY_SIZE) % HISTORY_SIZE].matching_bits); | ||
320 | weight = 1; /* was: estimate_count + 1 - i; */ | 322 | weight = 1; /* was: estimate_count + 1 - i; */ |
321 | 323 | ||
322 | temp = weight + sumweight; | 324 | temp = weight + sumweight; |
@@ -338,8 +340,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
338 | em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 340 | em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
339 | em->size_estimate = mean - 1.0 / 3.0; | 341 | em->size_estimate = mean - 1.0 / 3.0; |
340 | em->std_deviation = std_dev; | 342 | em->std_deviation = std_dev; |
341 | GNUNET_STATISTICS_set (stats, | 343 | GNUNET_STATISTICS_set (stats, "# nodes in the network (estimate)", |
342 | "# nodes in the network (estimate)", | ||
343 | (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO); | 344 | (uint64_t) pow (2, mean - 1.0 / 3.0), GNUNET_NO); |
344 | } | 345 | } |
345 | 346 | ||
@@ -385,8 +386,7 @@ get_matching_bits_delay (uint32_t matching_bits) | |||
385 | // f is frequency (gnunet_nse_interval) | 386 | // f is frequency (gnunet_nse_interval) |
386 | // x is matching_bits | 387 | // x is matching_bits |
387 | // p' is current_size_estimate | 388 | // p' is current_size_estimate |
388 | return ((double) gnunet_nse_interval.rel_value / (double) 2.0) | 389 | return ((double) gnunet_nse_interval.rel_value / (double) 2.0) - |
389 | - | ||
390 | ((gnunet_nse_interval.rel_value / M_PI) * | 390 | ((gnunet_nse_interval.rel_value / M_PI) * |
391 | atan (matching_bits - current_size_estimate)); | 391 | atan (matching_bits - current_size_estimate)); |
392 | } | 392 | } |
@@ -406,12 +406,12 @@ get_delay_randomization (uint32_t matching_bits) | |||
406 | 406 | ||
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 = |
410 | (uint32_t) (get_matching_bits_delay | 410 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
411 | (matching_bits - | 411 | (uint32_t) (get_matching_bits_delay |
412 | 1) / | 412 | (matching_bits - |
413 | (double) (hop_count_max | 413 | 1) / (double) (hop_count_max + |
414 | + 1))); | 414 | 1))); |
415 | return ret; | 415 | return ret; |
416 | #else | 416 | #else |
417 | return GNUNET_TIME_UNIT_ZERO; | 417 | return GNUNET_TIME_UNIT_ZERO; |
@@ -432,8 +432,8 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp, | |||
432 | { | 432 | { |
433 | GNUNET_HashCode timestamp_hash; | 433 | GNUNET_HashCode timestamp_hash; |
434 | 434 | ||
435 | GNUNET_CRYPTO_hash (×tamp.abs_value, | 435 | GNUNET_CRYPTO_hash (×tamp.abs_value, sizeof (timestamp.abs_value), |
436 | sizeof (timestamp.abs_value), ×tamp_hash); | 436 | ×tamp_hash); |
437 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &id->hashPubKey); | 437 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &id->hashPubKey); |
438 | } | 438 | } |
439 | 439 | ||
@@ -498,8 +498,8 @@ get_transmit_delay (int round_offset) | |||
498 | * @param cls the 'struct NSEPeerEntry' | 498 | * @param cls the 'struct NSEPeerEntry' |
499 | * @param tc scheduler context | 499 | * @param tc scheduler context |
500 | */ | 500 | */ |
501 | static void | 501 | static void transmit_task (void *cls, |
502 | transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 502 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
503 | 503 | ||
504 | 504 | ||
505 | /** | 505 | /** |
@@ -545,17 +545,15 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
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) | 547 | (unsigned long long) |
548 | GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx]. | 548 | GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp). |
549 | timestamp).abs_value, | 549 | abs_value, GNUNET_i2s (&peer_entry->id), |
550 | GNUNET_i2s (&peer_entry->id), | ||
551 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); | 550 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); |
552 | #endif | 551 | #endif |
553 | if (ntohl (size_estimate_messages[idx].hop_count) == 0) | 552 | if (ntohl (size_estimate_messages[idx].hop_count) == 0) |
554 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); | 553 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); |
555 | GNUNET_STATISTICS_update (stats, | 554 | GNUNET_STATISTICS_update (stats, "# flood messages transmitted", 1, |
556 | "# flood messages transmitted", 1, GNUNET_NO); | 555 | GNUNET_NO); |
557 | memcpy (buf, | 556 | memcpy (buf, &size_estimate_messages[idx], |
558 | &size_estimate_messages[idx], | ||
559 | sizeof (struct GNUNET_NSE_FloodMessage)); | 557 | sizeof (struct GNUNET_NSE_FloodMessage)); |
560 | GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO); | 558 | GNUNET_STATISTICS_update (stats, "# flood messages sent", 1, GNUNET_NO); |
561 | return sizeof (struct GNUNET_NSE_FloodMessage); | 559 | return sizeof (struct GNUNET_NSE_FloodMessage); |
@@ -575,15 +573,13 @@ transmit_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
575 | 573 | ||
576 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; | 574 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; |
577 | GNUNET_assert (NULL == peer_entry->th); | 575 | GNUNET_assert (NULL == peer_entry->th); |
578 | peer_entry->th | 576 | peer_entry->th = |
579 | = GNUNET_CORE_notify_transmit_ready (coreAPI, | 577 | GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_NO, NSE_PRIORITY, |
580 | GNUNET_NO, | 578 | GNUNET_TIME_UNIT_FOREVER_REL, |
581 | NSE_PRIORITY, | 579 | &peer_entry->id, |
582 | GNUNET_TIME_UNIT_FOREVER_REL, | 580 | sizeof (struct |
583 | &peer_entry->id, | 581 | GNUNET_NSE_FloodMessage), |
584 | sizeof (struct | 582 | &transmit_ready, peer_entry); |
585 | GNUNET_NSE_FloodMessage), | ||
586 | &transmit_ready, peer_entry); | ||
587 | } | 583 | } |
588 | 584 | ||
589 | 585 | ||
@@ -622,10 +618,10 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts) | |||
622 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); | 618 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); |
623 | fm->hop_count = htonl (0); | 619 | fm->hop_count = htonl (0); |
624 | fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); | 620 | fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); |
625 | fm->purpose.size = htonl (sizeof (struct GNUNET_NSE_FloodMessage) | 621 | fm->purpose.size = |
626 | - sizeof (struct GNUNET_MessageHeader) | 622 | htonl (sizeof (struct GNUNET_NSE_FloodMessage) - |
627 | - sizeof (uint32_t) | 623 | sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) - |
628 | - sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 624 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
629 | fm->matching_bits = htonl (matching_bits); | 625 | fm->matching_bits = htonl (matching_bits); |
630 | fm->timestamp = GNUNET_TIME_absolute_hton (ts); | 626 | fm->timestamp = GNUNET_TIME_absolute_hton (ts); |
631 | fm->pkey = my_public_key; | 627 | fm->pkey = my_public_key; |
@@ -684,13 +680,13 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
684 | if (0 != offset.rel_value) | 680 | if (0 != offset.rel_value) |
685 | { | 681 | { |
686 | /* somehow run early, delay more */ | 682 | /* somehow run early, delay more */ |
687 | flood_task | 683 | flood_task = |
688 | = GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL); | 684 | GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL); |
689 | return; | 685 | return; |
690 | } | 686 | } |
691 | current_timestamp = next_timestamp; | 687 | current_timestamp = next_timestamp; |
692 | next_timestamp = GNUNET_TIME_absolute_add (current_timestamp, | 688 | next_timestamp = |
693 | gnunet_nse_interval); | 689 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
694 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; | 690 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; |
695 | if (estimate_count < HISTORY_SIZE) | 691 | if (estimate_count < HISTORY_SIZE) |
696 | estimate_count++; | 692 | estimate_count++; |
@@ -699,16 +695,16 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
699 | { | 695 | { |
700 | /* we received a message for this round way early, use it! */ | 696 | /* we received a message for this round way early, use it! */ |
701 | size_estimate_messages[estimate_index] = next_message; | 697 | size_estimate_messages[estimate_index] = next_message; |
702 | size_estimate_messages[estimate_index].hop_count | 698 | size_estimate_messages[estimate_index].hop_count = |
703 | = htonl (1 + ntohl (next_message.hop_count)); | 699 | htonl (1 + ntohl (next_message.hop_count)); |
704 | } | 700 | } |
705 | else | 701 | else |
706 | setup_flood_message (estimate_index, current_timestamp); | 702 | setup_flood_message (estimate_index, current_timestamp); |
707 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ | 703 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ |
708 | hop_count_max = 0; | 704 | hop_count_max = 0; |
709 | for (i = 0; i < HISTORY_SIZE; i++) | 705 | for (i = 0; i < HISTORY_SIZE; i++) |
710 | hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), | 706 | hop_count_max = |
711 | hop_count_max); | 707 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); |
712 | GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL); | 708 | GNUNET_CONTAINER_multihashmap_iterate (peers, &schedule_current_round, NULL); |
713 | flood_task = | 709 | flood_task = |
714 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | 710 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
@@ -753,8 +749,8 @@ check_proof_of_work (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, | |||
753 | GNUNET_HashCode result; | 749 | GNUNET_HashCode result; |
754 | 750 | ||
755 | memcpy (buf, &val, sizeof (val)); | 751 | memcpy (buf, &val, sizeof (val)); |
756 | memcpy (&buf[sizeof (val)], | 752 | memcpy (&buf[sizeof (val)], pkey, |
757 | pkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 753 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
758 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); | 754 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); |
759 | return (count_leading_zeroes (&result) >= | 755 | return (count_leading_zeroes (&result) >= |
760 | nse_work_required) ? GNUNET_YES : GNUNET_NO; | 756 | nse_work_required) ? GNUNET_YES : GNUNET_NO; |
@@ -773,9 +769,7 @@ write_proof () | |||
773 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 769 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) |
774 | return; | 770 | return; |
775 | if (sizeof (my_proof) != | 771 | if (sizeof (my_proof) != |
776 | GNUNET_DISK_fn_write (proof, | 772 | GNUNET_DISK_fn_write (proof, &my_proof, sizeof (my_proof), |
777 | &my_proof, | ||
778 | sizeof (my_proof), | ||
779 | GNUNET_DISK_PERM_USER_READ | | 773 | GNUNET_DISK_PERM_USER_READ | |
780 | GNUNET_DISK_PERM_USER_WRITE)) | 774 | GNUNET_DISK_PERM_USER_WRITE)) |
781 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); | 775 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); |
@@ -801,8 +795,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
801 | unsigned int i; | 795 | unsigned int i; |
802 | 796 | ||
803 | proof_task = GNUNET_SCHEDULER_NO_TASK; | 797 | proof_task = GNUNET_SCHEDULER_NO_TASK; |
804 | memcpy (&buf[sizeof (uint64_t)], | 798 | memcpy (&buf[sizeof (uint64_t)], &my_public_key, |
805 | &my_public_key, | ||
806 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 799 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
807 | i = 0; | 800 | i = 0; |
808 | counter = my_proof; | 801 | counter = my_proof; |
@@ -814,8 +807,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
814 | { | 807 | { |
815 | my_proof = counter; | 808 | my_proof = counter; |
816 | #if DEBUG_NSE | 809 | #if DEBUG_NSE |
817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n", |
818 | "Proof of work found: %llu!\n", | ||
819 | (unsigned long long) GNUNET_ntohll (counter)); | 811 | (unsigned long long) GNUNET_ntohll (counter)); |
820 | #endif | 812 | #endif |
821 | for (i = 0; i < HISTORY_SIZE; i++) | 813 | for (i = 0; i < HISTORY_SIZE; i++) |
@@ -835,8 +827,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
835 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | 827 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) |
836 | { | 828 | { |
837 | #if DEBUG_NSE | 829 | #if DEBUG_NSE |
838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n", |
839 | "Testing proofs currently at %llu\n", | ||
840 | (unsigned long long) counter); | 831 | (unsigned long long) counter); |
841 | #endif | 832 | #endif |
842 | /* remember progress every 100 rounds */ | 833 | /* remember progress every 100 rounds */ |
@@ -847,8 +838,8 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
847 | { | 838 | { |
848 | my_proof = counter; | 839 | my_proof = counter; |
849 | } | 840 | } |
850 | proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay, | 841 | proof_task = |
851 | &find_proof, NULL); | 842 | GNUNET_SCHEDULER_add_delayed (proof_find_delay, &find_proof, NULL); |
852 | } | 843 | } |
853 | 844 | ||
854 | 845 | ||
@@ -869,10 +860,9 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) | |||
869 | check_proof_of_work (&incoming_flood->pkey, | 860 | check_proof_of_work (&incoming_flood->pkey, |
870 | incoming_flood->proof_of_work)) | 861 | incoming_flood->proof_of_work)) |
871 | { | 862 | { |
872 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Proof of work invalid: %llu!\n"), |
873 | _("Proof of work invalid: %llu!\n"), | 864 | (unsigned long long) GNUNET_ntohll (incoming_flood-> |
874 | (unsigned long long) | 865 | proof_of_work)); |
875 | GNUNET_ntohll (incoming_flood->proof_of_work)); | ||
876 | GNUNET_break_op (0); | 866 | GNUNET_break_op (0); |
877 | return GNUNET_NO; | 867 | return GNUNET_NO; |
878 | } | 868 | } |
@@ -923,9 +913,8 @@ update_flood_times (void *cls, const GNUNET_HashCode * key, void *value) | |||
923 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; | 913 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; |
924 | } | 914 | } |
925 | delay = get_transmit_delay (0); | 915 | delay = get_transmit_delay (0); |
926 | peer_entry->transmit_task = GNUNET_SCHEDULER_add_delayed (delay, | 916 | peer_entry->transmit_task = |
927 | &transmit_task, | 917 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_task, peer_entry); |
928 | peer_entry); | ||
929 | return GNUNET_OK; | 918 | return GNUNET_OK; |
930 | } | 919 | } |
931 | 920 | ||
@@ -940,8 +929,7 @@ update_flood_times (void *cls, const GNUNET_HashCode * key, void *value) | |||
940 | * | 929 | * |
941 | */ | 930 | */ |
942 | static int | 931 | static int |
943 | handle_p2p_size_estimate (void *cls, | 932 | handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, |
944 | const struct GNUNET_PeerIdentity *peer, | ||
945 | const struct GNUNET_MessageHeader *message, | 933 | const struct GNUNET_MessageHeader *message, |
946 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 934 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
947 | { | 935 | { |
@@ -971,9 +959,9 @@ handle_p2p_size_estimate (void *cls, | |||
971 | GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer)); | 959 | GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer)); |
972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
973 | "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n", | 961 | "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n", |
974 | (unsigned long long) | 962 | (unsigned long long) GNUNET_TIME_absolute_ntoh (incoming_flood-> |
975 | GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value, | 963 | timestamp). |
976 | origin, pred, GNUNET_i2s (&my_identity), | 964 | abs_value, origin, pred, GNUNET_i2s (&my_identity), |
977 | (unsigned int) matching_bits); | 965 | (unsigned int) matching_bits); |
978 | } | 966 | } |
979 | #endif | 967 | #endif |
@@ -1015,8 +1003,8 @@ handle_p2p_size_estimate (void *cls, | |||
1015 | if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))) | 1003 | if (0 == (memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))) |
1016 | { | 1004 | { |
1017 | /* send to self, update our own estimate IF this also comes from us! */ | 1005 | /* send to self, update our own estimate IF this also comes from us! */ |
1018 | if (0 == memcmp (&incoming_flood->pkey, | 1006 | if (0 == |
1019 | &my_public_key, sizeof (my_public_key))) | 1007 | memcmp (&incoming_flood->pkey, &my_public_key, sizeof (my_public_key))) |
1020 | update_network_size_estimate (); | 1008 | update_network_size_estimate (); |
1021 | return GNUNET_OK; | 1009 | return GNUNET_OK; |
1022 | } | 1010 | } |
@@ -1057,8 +1045,8 @@ handle_p2p_size_estimate (void *cls, | |||
1057 | { | 1045 | { |
1058 | if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) | 1046 | if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) |
1059 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1047 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
1060 | peer_entry->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_task, | 1048 | peer_entry->transmit_task = |
1061 | peer_entry); | 1049 | GNUNET_SCHEDULER_add_now (&transmit_task, peer_entry); |
1062 | } | 1050 | } |
1063 | /* Not closer than our most recent message, no need to do work here */ | 1051 | /* Not closer than our most recent message, no need to do work here */ |
1064 | GNUNET_STATISTICS_update (stats, | 1052 | GNUNET_STATISTICS_update (stats, |
@@ -1081,8 +1069,8 @@ handle_p2p_size_estimate (void *cls, | |||
1081 | update_network_size_estimate (); | 1069 | update_network_size_estimate (); |
1082 | 1070 | ||
1083 | /* flood to rest */ | 1071 | /* flood to rest */ |
1084 | GNUNET_CONTAINER_multihashmap_iterate (peers, | 1072 | GNUNET_CONTAINER_multihashmap_iterate (peers, &update_flood_times, |
1085 | &update_flood_times, peer_entry); | 1073 | peer_entry); |
1086 | return GNUNET_OK; | 1074 | return GNUNET_OK; |
1087 | } | 1075 | } |
1088 | 1076 | ||
@@ -1102,14 +1090,12 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1102 | struct NSEPeerEntry *peer_entry; | 1090 | struct NSEPeerEntry *peer_entry; |
1103 | 1091 | ||
1104 | #if DEBUG_NSE | 1092 | #if DEBUG_NSE |
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected to us\n", |
1106 | "Peer `%s' connected to us\n", GNUNET_i2s (peer)); | 1094 | GNUNET_i2s (peer)); |
1107 | #endif | 1095 | #endif |
1108 | peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry)); | 1096 | peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry)); |
1109 | peer_entry->id = *peer; | 1097 | peer_entry->id = *peer; |
1110 | GNUNET_CONTAINER_multihashmap_put (peers, | 1098 | GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_entry, |
1111 | &peer->hashPubKey, | ||
1112 | peer_entry, | ||
1113 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1099 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1114 | peer_entry->transmit_task = | 1100 | peer_entry->transmit_task = |
1115 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task, | 1101 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task, |
@@ -1129,8 +1115,8 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1129 | struct NSEPeerEntry *pos; | 1115 | struct NSEPeerEntry *pos; |
1130 | 1116 | ||
1131 | #if DEBUG_NSE | 1117 | #if DEBUG_NSE |
1132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us\n", |
1133 | "Peer `%s' disconnected from us\n", GNUNET_i2s (peer)); | 1119 | GNUNET_i2s (peer)); |
1134 | #endif | 1120 | #endif |
1135 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 1121 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
1136 | if (NULL == pos) | 1122 | if (NULL == pos) |
@@ -1139,8 +1125,8 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1139 | return; | 1125 | return; |
1140 | } | 1126 | } |
1141 | GNUNET_assert (GNUNET_YES == | 1127 | GNUNET_assert (GNUNET_YES == |
1142 | GNUNET_CONTAINER_multihashmap_remove (peers, | 1128 | GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, |
1143 | &peer->hashPubKey, pos)); | 1129 | pos)); |
1144 | if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK) | 1130 | if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK) |
1145 | GNUNET_SCHEDULER_cancel (pos->transmit_task); | 1131 | GNUNET_SCHEDULER_cancel (pos->transmit_task); |
1146 | if (pos->th != NULL) | 1132 | if (pos->th != NULL) |
@@ -1251,8 +1237,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1251 | } | 1237 | } |
1252 | estimate_index = HISTORY_SIZE - 1; | 1238 | estimate_index = HISTORY_SIZE - 1; |
1253 | estimate_count = 2; | 1239 | estimate_count = 2; |
1254 | flood_task | 1240 | flood_task = |
1255 | = | ||
1256 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | 1241 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
1257 | (next_timestamp), &update_flood_message, | 1242 | (next_timestamp), &update_flood_message, |
1258 | NULL); | 1243 | NULL); |
@@ -1286,16 +1271,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1286 | cfg = c; | 1271 | cfg = c; |
1287 | 1272 | ||
1288 | if ((GNUNET_OK != | 1273 | if ((GNUNET_OK != |
1289 | GNUNET_CONFIGURATION_get_value_time (cfg, | 1274 | GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "INTERVAL", |
1290 | "NSE", "INTERVAL", | ||
1291 | &gnunet_nse_interval)) || | 1275 | &gnunet_nse_interval)) || |
1292 | (GNUNET_OK != | 1276 | (GNUNET_OK != |
1293 | GNUNET_CONFIGURATION_get_value_time (cfg, | 1277 | GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "WORKDELAY", |
1294 | "NSE", "WORKDELAY", | ||
1295 | &proof_find_delay)) || | 1278 | &proof_find_delay)) || |
1296 | (GNUNET_OK != | 1279 | (GNUNET_OK != |
1297 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1280 | GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS", |
1298 | "NSE", "WORKBITS", | ||
1299 | &nse_work_required))) | 1281 | &nse_work_required))) |
1300 | { | 1282 | { |
1301 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1314,8 +1296,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1314 | 1296 | ||
1315 | 1297 | ||
1316 | if (GNUNET_OK != | 1298 | if (GNUNET_OK != |
1317 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1299 | GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", |
1318 | "GNUNETD", "HOSTKEY", &keyfile)) | 1300 | &keyfile)) |
1319 | { | 1301 | { |
1320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1321 | _ | 1303 | _ |
@@ -1374,8 +1356,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1374 | NULL, /* Don't want notified about all outbound messages */ | 1356 | NULL, /* Don't want notified about all outbound messages */ |
1375 | GNUNET_NO, /* For header only outbound notification */ | 1357 | GNUNET_NO, /* For header only outbound notification */ |
1376 | core_handlers); /* Register these handlers */ | 1358 | core_handlers); /* Register these handlers */ |
1377 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1359 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
1378 | &shutdown_task, NULL); | 1360 | NULL); |
1379 | #if ENABLE_HISTOGRAM | 1361 | #if ENABLE_HISTOGRAM |
1380 | if (GNUNET_OK == | 1362 | if (GNUNET_OK == |
1381 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM", &proof)) | 1363 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM", &proof)) |
@@ -1403,10 +1385,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1403 | int | 1385 | int |
1404 | main (int argc, char *const *argv) | 1386 | main (int argc, char *const *argv) |
1405 | { | 1387 | { |
1406 | return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, | 1388 | return (GNUNET_OK == |
1407 | "nse", | 1389 | GNUNET_SERVICE_run (argc, argv, "nse", GNUNET_SERVICE_OPTION_NONE, |
1408 | GNUNET_SERVICE_OPTION_NONE, &run, | 1390 | &run, NULL)) ? 0 : 1; |
1409 | NULL)) ? 0 : 1; | ||
1410 | } | 1391 | } |
1411 | 1392 | ||
1412 | /* end of gnunet-service-nse.c */ | 1393 | /* end of gnunet-service-nse.c */ |