- /* Get the current UTC time */
- curr_time = GNUNET_TIME_absolute_get ();
- /* Find the previous interval start time */
- previous_timestamp.abs_value = (curr_time.abs_value / GNUNET_NSE_INTERVAL)
- * GNUNET_NSE_INTERVAL;
- /* Find the next interval start time */
- next_timestamp.abs_value = previous_timestamp.abs_value + GNUNET_NSE_INTERVAL;
-#if DEBUG_NSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s: curr_time %lu, prev timestamp %lu, next timestamp %lu\n",
- GNUNET_i2s (&my_identity), curr_time.abs_value,
- previous_timestamp.abs_value, next_timestamp.abs_value);
-#endif
- GNUNET_CRYPTO_hash (&next_timestamp.abs_value,
- sizeof(next_timestamp.abs_value), ×tamp_hash);
- matching_bits = GNUNET_CRYPTO_hash_matching_bits (×tamp_hash,
- &my_identity.hashPubKey);
-
- flood_message.header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage));
- flood_message.header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
- flood_message.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
- flood_message.purpose.size = htonl (sizeof(struct GNUNET_NSE_FloodMessage)
- - sizeof(struct GNUNET_MessageHeader) - sizeof(flood_message.signature));
- flood_message.distance = htonl (matching_bits);
- flood_message.timestamp = GNUNET_TIME_absolute_hton (next_timestamp);
- memcpy (&flood_message.pkey, &my_public_key,
- sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- flood_message.proof_of_work = htonl (0);
- GNUNET_CRYPTO_rsa_sign (my_private_key, &flood_message.purpose,
- &flood_message.signature);
-
- /*S + f/2 - (f / pi) * (atan(x - p'))*/
-
- // S is next_timestamp
- // f is frequency (GNUNET_NSE_INTERVAL)
- // x is matching_bits
- // p' is current_size_estimate
- millisecond_offset = ((double) GNUNET_NSE_INTERVAL / (double) 2)
- - ((GNUNET_NSE_INTERVAL / M_PI) * atan (matching_bits
- - current_size_estimate));
-#if DEBUG_NSE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s: id matches %d bits, offset is %lu\n\n",
- GNUNET_i2s (&my_identity), matching_bits,
- (uint64_t) millisecond_offset);
-#endif
- /* Stop initial call from incrementing */
- if (size_estimate_messages[estimate_index].distance != 0)
- estimate_index += 1;
-
- if (estimate_index >= DEFAULT_HISTORY_SIZE)
- estimate_index = 0;
-
- if (millisecond_offset < curr_time.abs_value - previous_timestamp.abs_value)
- offset.rel_value = 0;
- else
- offset.rel_value = (uint64_t) millisecond_offset + curr_time.abs_value
- - previous_timestamp.abs_value;
-#if DEBUG_NSE
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- "%s: %u bits match, %lu milliseconds to timestamp , sending flood in %lu\n",
- GNUNET_i2s (&my_identity), matching_bits,
- GNUNET_TIME_absolute_get_remaining (next_timestamp).rel_value,
- offset.rel_value);
-#endif
- flood_task = GNUNET_SCHEDULER_add_delayed (offset, &send_flood_message, NULL);