aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-23 20:27:17 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-23 20:27:17 +0000
commit3137ebd45e94b3555cc5c1c37d1ee6b980568886 (patch)
tree1ff734f21d68781406f58e36787e4883be09d4c2 /src
parentaf47957f8380b4810f11ad69322c69576375e809 (diff)
downloadgnunet-3137ebd45e94b3555cc5c1c37d1ee6b980568886.tar.gz
gnunet-3137ebd45e94b3555cc5c1c37d1ee6b980568886.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/nse/gnunet-service-nse.c92
-rw-r--r--src/nse/test_nse.conf11
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 @@
45#include "gnunet_nse_service.h" 45#include "gnunet_nse_service.h"
46#include "nse.h" 46#include "nse.h"
47 47
48#define DEBUG_NSE GNUNET_YES
49
48/** 50/**
49 * Over how many values do we calculate the weighted average? 51 * Over how many values do we calculate the weighted average?
50 */ 52 */
@@ -63,17 +65,17 @@
63/** 65/**
64 * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. 66 * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
65 */ 67 */
66#define NSE_WORK_REQUIRED 0 68#define NSE_WORK_REQUIRED 8
67 69
68/** 70/**
69 * Interval for sending network size estimation flood requests. 71 * Interval for sending network size estimation flood requests.
70 */ 72 */
71#define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 73#define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
72 74
73/** 75/**
74 * Interval between proof find runs. 76 * Interval between proof find runs.
75 */ 77 */
76#define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) 78#define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5)
77 79
78 80
79/** 81/**
@@ -357,12 +359,12 @@ static double
357get_matching_bits_delay (uint32_t matching_bits) 359get_matching_bits_delay (uint32_t matching_bits)
358{ 360{
359 /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/ 361 /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/
360 // S is next_timestamp 362 // S is next_timestamp (ignored in return value)
361 // f is frequency (GNUNET_NSE_INTERVAL) 363 // f is frequency (GNUNET_NSE_INTERVAL)
362 // x is matching_bits 364 // x is matching_bits
363 // p' is current_size_estimate 365 // p' is current_size_estimate
364 return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2) 366 return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2.0)
365 - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (matching_bits - current_size_estimate)); 367 - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (current_size_estimate - matching_bits));
366} 368}
367 369
368 370
@@ -786,15 +788,38 @@ find_proof (void *cls,
786 if (NSE_WORK_REQUIRED <= count_leading_zeroes(&result)) 788 if (NSE_WORK_REQUIRED <= count_leading_zeroes(&result))
787 { 789 {
788 my_proof = counter; 790 my_proof = counter;
791 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
792 _("Proof of work found: %llu!\n"),
793 (unsigned long long) GNUNET_ntohll (counter));
794 for (i=0;i<HISTORY_SIZE;i++)
795 if (ntohl (size_estimate_messages[i].hop_count) == 0)
796 {
797 size_estimate_messages[i].proof_of_work = my_proof;
798 GNUNET_CRYPTO_rsa_sign (my_private_key,
799 &size_estimate_messages[i].purpose,
800 &size_estimate_messages[i].signature);
801 }
789 write_proof (); 802 write_proof ();
790 return; 803 return;
791 } 804 }
792 counter++; 805 counter++;
793 i++; 806 i++;
794 } 807 }
795 my_proof = counter; 808 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
796 if (0 == (my_proof % 100 * ROUND_SIZE)) 809 {
797 write_proof (); /* remember progress every 100 rounds */ 810#if DEBUG_NSE
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Testing proofs currently at %llu\n",
813 (unsigned long long) counter);
814#endif
815 /* remember progress every 100 rounds */
816 my_proof = counter;
817 write_proof ();
818 }
819 else
820 {
821 my_proof = counter;
822 }
798 proof_task = GNUNET_SCHEDULER_add_delayed (PROOF_FIND_DELAY, 823 proof_task = GNUNET_SCHEDULER_add_delayed (PROOF_FIND_DELAY,
799 &find_proof, 824 &find_proof,
800 NULL); 825 NULL);
@@ -818,6 +843,9 @@ verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood)
818 check_proof_of_work (&incoming_flood->pkey, 843 check_proof_of_work (&incoming_flood->pkey,
819 incoming_flood->proof_of_work)) 844 incoming_flood->proof_of_work))
820 { 845 {
846 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
847 _("Proof of work invalid: %llu!\n"),
848 (unsigned long long) GNUNET_ntohll (incoming_flood->proof_of_work));
821 GNUNET_break_op (0); 849 GNUNET_break_op (0);
822 return GNUNET_NO; 850 return GNUNET_NO;
823 } 851 }
@@ -903,6 +931,31 @@ handle_p2p_size_estimate(void *cls,
903 1, 931 1,
904 GNUNET_NO); 932 GNUNET_NO);
905 matching_bits = ntohl (incoming_flood->matching_bits); 933 matching_bits = ntohl (incoming_flood->matching_bits);
934#if DEBUG_NSE
935 {
936 char origin[5];
937 char pred[5];
938 struct GNUNET_PeerIdentity os;
939
940 GNUNET_CRYPTO_hash (&incoming_flood->pkey,
941 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
942 &os.hashPubKey);
943 GNUNET_snprintf (origin, sizeof (origin),
944 "%s",
945 GNUNET_i2s (&os));
946 GNUNET_snprintf (pred, sizeof (pred),
947 "%s",
948 GNUNET_i2s (peer));
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "Flood at %llu from `%s' via `%s' at `%s' with bits %u\n",
951 (unsigned long long) GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp).abs_value,
952 origin,
953 pred,
954 GNUNET_i2s (&my_identity),
955 (unsigned int) matching_bits);
956 }
957#endif
958
906 peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 959 peer_entry = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
907 if (NULL == peer_entry) 960 if (NULL == peer_entry)
908 { 961 {
@@ -1018,6 +1071,11 @@ handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer,
1018{ 1071{
1019 struct NSEPeerEntry *peer_entry; 1072 struct NSEPeerEntry *peer_entry;
1020 1073
1074 #if DEBUG_NSE
1075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1076 "Peer `%s' connected to us\n",
1077 GNUNET_i2s (peer));
1078#endif
1021 peer_entry = GNUNET_malloc(sizeof(struct NSEPeerEntry)); 1079 peer_entry = GNUNET_malloc(sizeof(struct NSEPeerEntry));
1022 peer_entry->id = *peer; 1080 peer_entry->id = *peer;
1023 GNUNET_CONTAINER_multihashmap_put (peers, 1081 GNUNET_CONTAINER_multihashmap_put (peers,
@@ -1041,7 +1099,12 @@ handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer)
1041{ 1099{
1042 struct NSEPeerEntry *pos; 1100 struct NSEPeerEntry *pos;
1043 1101
1044 pos = GNUNET_CONTAINER_multihashmap_get (peers, 1102 #if DEBUG_NSE
1103 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1104 "Peer `%s' disconnected from us\n",
1105 GNUNET_i2s (peer));
1106#endif
1107 pos = GNUNET_CONTAINER_multihashmap_get (peers,
1045 &peer->hashPubKey); 1108 &peer->hashPubKey);
1046 if (NULL == pos) 1109 if (NULL == pos)
1047 { 1110 {
@@ -1214,10 +1277,11 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
1214 GNUNET_SCHEDULER_shutdown (); 1277 GNUNET_SCHEDULER_shutdown ();
1215 return; 1278 return;
1216 } 1279 }
1217 if (sizeof (my_proof) != 1280 if ( (GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
1218 GNUNET_DISK_fn_read (proof, 1281 (sizeof (my_proof) !=
1219 &my_proof, 1282 GNUNET_DISK_fn_read (proof,
1220 sizeof (my_proof))) 1283 &my_proof,
1284 sizeof (my_proof))) )
1221 my_proof = 0; 1285 my_proof = 0;
1222 GNUNET_free (proof); 1286 GNUNET_free (proof);
1223 proof_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1287 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
36[peerinfo] 36[peerinfo]
37AUTOSTART = YES 37AUTOSTART = YES
38 38
39[nat]
40DISABLEV6 = YES
41BINDTO = 127.0.0.1
42ENABLE_UPNP = NO
43BEHIND_NAT = NO
44ALLOW_NAT = NO
45INTERNAL_ADDRESS = 127.0.0.1
46EXTERNAL_ADDRESS = 127.0.0.1
47
39[dns] 48[dns]
40AUTOSTART = NO 49AUTOSTART = NO
41 50
42[testing] 51[testing]
43NUM_PEERS = 1000 52NUM_PEERS = 10
44WEAKRANDOM = YES 53WEAKRANDOM = YES
45TOPOLOGY = NONE 54TOPOLOGY = NONE
46CONNECT_TOPOLOGY = SMALL_WORLD_RING 55CONNECT_TOPOLOGY = SMALL_WORLD_RING