From 3137ebd45e94b3555cc5c1c37d1ee6b980568886 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 23 Jul 2011 20:27:17 +0000 Subject: [PATCH] fixes --- src/nse/gnunet-service-nse.c | 92 ++++++++++++++++++++++++++++++------ src/nse/test_nse.conf | 11 ++++- 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 066ba3463..2e7a7248d 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -45,6 +45,8 @@ #include "gnunet_nse_service.h" #include "nse.h" +#define DEBUG_NSE GNUNET_YES + /** * Over how many values do we calculate the weighted average? */ @@ -63,17 +65,17 @@ /** * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. */ -#define NSE_WORK_REQUIRED 0 +#define NSE_WORK_REQUIRED 8 /** * Interval for sending network size estimation flood requests. */ -#define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) +#define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) /** * Interval between proof find runs. */ -#define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) +#define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5) /** @@ -357,12 +359,12 @@ static double get_matching_bits_delay (uint32_t matching_bits) { /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/ - // S is next_timestamp + // S is next_timestamp (ignored in return value) // f is frequency (GNUNET_NSE_INTERVAL) // x is matching_bits // p' is current_size_estimate - return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2) - - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (matching_bits - current_size_estimate)); + return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2.0) + - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (current_size_estimate - matching_bits)); } @@ -786,15 +788,38 @@ find_proof (void *cls, if (NSE_WORK_REQUIRED <= count_leading_zeroes(&result)) { my_proof = counter; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Proof of work found: %llu!\n"), + (unsigned long long) GNUNET_ntohll (counter)); + for (i=0;ipkey, incoming_flood->proof_of_work)) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Proof of work invalid: %llu!\n"), + (unsigned long long) GNUNET_ntohll (incoming_flood->proof_of_work)); GNUNET_break_op (0); return GNUNET_NO; } @@ -903,6 +931,31 @@ handle_p2p_size_estimate(void *cls, 1, GNUNET_NO); matching_bits = ntohl (incoming_flood->matching_bits); +#if DEBUG_NSE + { + char origin[5]; + char pred[5]; + struct GNUNET_PeerIdentity os; + + GNUNET_CRYPTO_hash (&incoming_flood->pkey, + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &os.hashPubKey); + GNUNET_snprintf (origin, sizeof (origin), + "%s", + GNUNET_i2s (&os)); + GNUNET_snprintf (pred, sizeof (pred), + "%s", + GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n", + (unsigned long long) GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value, + origin, + pred, + GNUNET_i2s (&my_identity), + (unsigned int) matching_bits); + } +#endif + peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (NULL == peer_entry) { @@ -1018,6 +1071,11 @@ handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, { struct NSEPeerEntry *peer_entry; + #if DEBUG_NSE + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' connected to us\n", + GNUNET_i2s (peer)); +#endif peer_entry = GNUNET_malloc(sizeof(struct NSEPeerEntry)); peer_entry->id = *peer; GNUNET_CONTAINER_multihashmap_put (peers, @@ -1041,7 +1099,12 @@ handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer) { struct NSEPeerEntry *pos; - pos = GNUNET_CONTAINER_multihashmap_get (peers, + #if DEBUG_NSE + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Peer `%s' disconnected from us\n", + GNUNET_i2s (peer)); +#endif + pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (NULL == pos) { @@ -1214,10 +1277,11 @@ run(void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_SCHEDULER_shutdown (); return; } - if (sizeof (my_proof) != - GNUNET_DISK_fn_read (proof, - &my_proof, - sizeof (my_proof))) + if ( (GNUNET_YES != GNUNET_DISK_file_test (proof)) || + (sizeof (my_proof) != + GNUNET_DISK_fn_read (proof, + &my_proof, + sizeof (my_proof))) ) my_proof = 0; GNUNET_free (proof); proof_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, diff --git a/src/nse/test_nse.conf b/src/nse/test_nse.conf index abd623687..e8e612d45 100644 --- a/src/nse/test_nse.conf +++ b/src/nse/test_nse.conf @@ -36,11 +36,20 @@ AUTOSTART = YES [peerinfo] AUTOSTART = YES +[nat] +DISABLEV6 = YES +BINDTO = 127.0.0.1 +ENABLE_UPNP = NO +BEHIND_NAT = NO +ALLOW_NAT = NO +INTERNAL_ADDRESS = 127.0.0.1 +EXTERNAL_ADDRESS = 127.0.0.1 + [dns] AUTOSTART = NO [testing] -NUM_PEERS = 1000 +NUM_PEERS = 10 WEAKRANDOM = YES TOPOLOGY = NONE CONNECT_TOPOLOGY = SMALL_WORLD_RING -- 2.25.1