diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-11 21:21:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-11 21:21:56 +0000 |
commit | 3d7fefedc9ba60bd8e8448efe8b628446d958536 (patch) | |
tree | 61ce41a52cd6e7232cead77818ef265993b2427e /src/nse/gnunet-service-nse.c | |
parent | 4a0398474db197abed243a123fb971fbeeffab4b (diff) | |
download | gnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.tar.gz gnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.zip |
changing time measurement from milliseconds to microseconds
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 832c43abc..978712d53 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -440,8 +440,8 @@ get_matching_bits_delay (uint32_t matching_bits) | |||
440 | // f is frequency (gnunet_nse_interval) | 440 | // f is frequency (gnunet_nse_interval) |
441 | // x is matching_bits | 441 | // x is matching_bits |
442 | // p' is current_size_estimate | 442 | // p' is current_size_estimate |
443 | return ((double) gnunet_nse_interval.rel_value / (double) 2.0) - | 443 | return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) - |
444 | ((gnunet_nse_interval.rel_value / M_PI) * | 444 | ((gnunet_nse_interval.rel_value_us / M_PI) * |
445 | atan (matching_bits - current_size_estimate)); | 445 | atan (matching_bits - current_size_estimate)); |
446 | } | 446 | } |
447 | 447 | ||
@@ -462,10 +462,12 @@ get_delay_randomization (uint32_t matching_bits) | |||
462 | 462 | ||
463 | d = get_matching_bits_delay (matching_bits); | 463 | d = get_matching_bits_delay (matching_bits); |
464 | i = (uint32_t) (d / (double) (hop_count_max + 1)); | 464 | i = (uint32_t) (d / (double) (hop_count_max + 1)); |
465 | ret.rel_value_us = i; | ||
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
466 | "Randomizing flood using latencies up to %u ms\n", | 467 | "Randomizing flood using latencies up to %s\n", |
467 | (unsigned int) i); | 468 | GNUNET_STRINGS_relative_time_to_string (ret, |
468 | ret.rel_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1); | 469 | GNUNET_YES)); |
470 | ret.rel_value_us = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1); | ||
469 | return ret; | 471 | return ret; |
470 | #else | 472 | #else |
471 | return GNUNET_TIME_UNIT_ZERO; | 473 | return GNUNET_TIME_UNIT_ZERO; |
@@ -508,7 +510,7 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp, | |||
508 | { | 510 | { |
509 | struct GNUNET_HashCode timestamp_hash; | 511 | struct GNUNET_HashCode timestamp_hash; |
510 | 512 | ||
511 | GNUNET_CRYPTO_hash (×tamp.abs_value, sizeof (timestamp.abs_value), | 513 | GNUNET_CRYPTO_hash (×tamp.abs_value_us, sizeof (timestamp.abs_value_us), |
512 | ×tamp_hash); | 514 | ×tamp_hash); |
513 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &id->hashPubKey); | 515 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &id->hashPubKey); |
514 | } | 516 | } |
@@ -535,26 +537,27 @@ get_transmit_delay (int round_offset) | |||
535 | case -1: | 537 | case -1: |
536 | /* previous round is randomized between 0 and 50 ms */ | 538 | /* previous round is randomized between 0 and 50 ms */ |
537 | #if USE_RANDOM_DELAYS | 539 | #if USE_RANDOM_DELAYS |
538 | ret.rel_value = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50); | 540 | ret.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50); |
539 | #else | 541 | #else |
540 | ret = GNUNET_TIME_UNIT_ZERO; | 542 | ret = GNUNET_TIME_UNIT_ZERO; |
541 | #endif | 543 | #endif |
542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
543 | "Transmitting previous round behind schedule in %llu ms\n", | 545 | "Transmitting previous round behind schedule in %s\n", |
544 | (unsigned long long) ret.rel_value); | 546 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
545 | return ret; | 547 | return ret; |
546 | case 0: | 548 | case 0: |
547 | /* current round is based on best-known matching_bits */ | 549 | /* current round is based on best-known matching_bits */ |
548 | matching_bits = | 550 | matching_bits = |
549 | ntohl (size_estimate_messages[estimate_index].matching_bits); | 551 | ntohl (size_estimate_messages[estimate_index].matching_bits); |
550 | dist_delay = get_matching_bits_delay (matching_bits); | 552 | dist_delay = get_matching_bits_delay (matching_bits); |
551 | dist_delay += get_delay_randomization (matching_bits).rel_value; | 553 | dist_delay += get_delay_randomization (matching_bits).rel_value_us; |
552 | ret.rel_value = (uint64_t) dist_delay; | 554 | ret.rel_value_us = (uint64_t) dist_delay; |
553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
554 | "For round %llu, delay for %u matching bits is %llu ms\n", | 556 | "For round %s, delay for %u matching bits is %s\n", |
555 | (unsigned long long) current_timestamp.abs_value, | 557 | GNUNET_STRINGS_absolute_time_to_string (current_timestamp), |
556 | (unsigned int) matching_bits, | 558 | (unsigned int) matching_bits, |
557 | (unsigned long long) ret.rel_value); | 559 | GNUNET_STRINGS_relative_time_to_string (ret, |
560 | GNUNET_YES)); | ||
558 | /* now consider round start time and add delay to it */ | 561 | /* now consider round start time and add delay to it */ |
559 | tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); | 562 | tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); |
560 | return GNUNET_TIME_absolute_get_remaining (tgt); | 563 | return GNUNET_TIME_absolute_get_remaining (tgt); |
@@ -621,10 +624,8 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
621 | return 0; | 624 | return 0; |
622 | } | 625 | } |
623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
624 | "In round %llu, sending to `%s' estimate with %u bits\n", | 627 | "In round s, sending to `%s' estimate with %u bits\n", |
625 | (unsigned long long) | 628 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)), |
626 | GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx]. | ||
627 | timestamp).abs_value, | ||
628 | GNUNET_i2s (&peer_entry->id), | 629 | GNUNET_i2s (&peer_entry->id), |
629 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); | 630 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); |
630 | if (ntohl (size_estimate_messages[idx].hop_count) == 0) | 631 | if (ntohl (size_estimate_messages[idx].hop_count) == 0) |
@@ -778,7 +779,7 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
778 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 779 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
779 | return; | 780 | return; |
780 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); | 781 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); |
781 | if (0 != offset.rel_value) | 782 | if (0 != offset.rel_value_us) |
782 | { | 783 | { |
783 | /* somehow run early, delay more */ | 784 | /* somehow run early, delay more */ |
784 | flood_task = | 785 | flood_task = |
@@ -791,8 +792,8 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
791 | current_timestamp = next_timestamp; | 792 | current_timestamp = next_timestamp; |
792 | next_timestamp = | 793 | next_timestamp = |
793 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 794 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
794 | if ((current_timestamp.abs_value == | 795 | if ((current_timestamp.abs_value_us == |
795 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value) && | 796 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && |
796 | (get_matching_bits (current_timestamp, &my_identity) < | 797 | (get_matching_bits (current_timestamp, &my_identity) < |
797 | ntohl(next_message.matching_bits))) | 798 | ntohl(next_message.matching_bits))) |
798 | { | 799 | { |
@@ -1038,7 +1039,7 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1038 | { | 1039 | { |
1039 | uint64_t t; | 1040 | uint64_t t; |
1040 | 1041 | ||
1041 | t = GNUNET_TIME_absolute_get().abs_value; | 1042 | t = GNUNET_TIME_absolute_get().abs_value_us; |
1042 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t)); | 1043 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t)); |
1043 | } | 1044 | } |
1044 | #endif | 1045 | #endif |
@@ -1078,12 +1079,12 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1078 | #endif | 1079 | #endif |
1079 | 1080 | ||
1080 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); | 1081 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); |
1081 | if (ts.abs_value == current_timestamp.abs_value) | 1082 | if (ts.abs_value_us == current_timestamp.abs_value_us) |
1082 | idx = estimate_index; | 1083 | idx = estimate_index; |
1083 | else if (ts.abs_value == | 1084 | else if (ts.abs_value_us == |
1084 | current_timestamp.abs_value - gnunet_nse_interval.rel_value) | 1085 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us) |
1085 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1086 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1086 | else if (ts.abs_value == next_timestamp.abs_value) | 1087 | else if (ts.abs_value_us == next_timestamp.abs_value_us) |
1087 | { | 1088 | { |
1088 | if (matching_bits <= ntohl (next_message.matching_bits)) | 1089 | if (matching_bits <= ntohl (next_message.matching_bits)) |
1089 | return GNUNET_OK; /* ignore, simply too early/late */ | 1090 | return GNUNET_OK; /* ignore, simply too early/late */ |
@@ -1359,9 +1360,9 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1359 | memcmp (&my_identity, identity, | 1360 | memcmp (&my_identity, identity, |
1360 | sizeof (struct GNUNET_PeerIdentity))); | 1361 | sizeof (struct GNUNET_PeerIdentity))); |
1361 | now = GNUNET_TIME_absolute_get (); | 1362 | now = GNUNET_TIME_absolute_get (); |
1362 | current_timestamp.abs_value = | 1363 | current_timestamp.abs_value_us = |
1363 | (now.abs_value / gnunet_nse_interval.rel_value) * | 1364 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * |
1364 | gnunet_nse_interval.rel_value; | 1365 | gnunet_nse_interval.rel_value_us; |
1365 | next_timestamp = | 1366 | next_timestamp = |
1366 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 1367 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); |
1367 | estimate_index = HISTORY_SIZE - 1; | 1368 | estimate_index = HISTORY_SIZE - 1; |
@@ -1369,8 +1370,8 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1369 | if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof)) | 1370 | if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof)) |
1370 | { | 1371 | { |
1371 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1372 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1372 | prev_time.abs_value = | 1373 | prev_time.abs_value_us = |
1373 | current_timestamp.abs_value - gnunet_nse_interval.rel_value; | 1374 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; |
1374 | setup_flood_message (idx, prev_time); | 1375 | setup_flood_message (idx, prev_time); |
1375 | setup_flood_message (estimate_index, current_timestamp); | 1376 | setup_flood_message (estimate_index, current_timestamp); |
1376 | estimate_count++; | 1377 | estimate_count++; |