diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-24 11:43:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-24 11:43:32 +0000 |
commit | 8cfd6503c9292c8fb2d5b4a6ee00193645bd86d4 (patch) | |
tree | 192971a5f3bd0290d727400bf0a0674f94ea7896 /src/nse | |
parent | 7f935fa396f06a7b2bfa02549ff833316c7c9022 (diff) | |
download | gnunet-8cfd6503c9292c8fb2d5b4a6ee00193645bd86d4.tar.gz gnunet-8cfd6503c9292c8fb2d5b4a6ee00193645bd86d4.zip |
move to config instead of hard-coding for testing
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 58 | ||||
-rw-r--r-- | src/nse/test_nse.conf | 10 |
2 files changed, 52 insertions, 16 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index ad7a0bef1..4c0dae0e1 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -63,17 +63,17 @@ | |||
63 | /** | 63 | /** |
64 | * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. | 64 | * Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. |
65 | */ | 65 | */ |
66 | #define NSE_WORK_REQUIRED 8 | 66 | static unsigned long long nse_work_required; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Interval for sending network size estimation flood requests. | 69 | * Interval for sending network size estimation flood requests. |
70 | */ | 70 | */ |
71 | #define GNUNET_NSE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 71 | static struct GNUNET_TIME_Relative gnunet_nse_interval; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Interval between proof find runs. | 74 | * Interval between proof find runs. |
75 | */ | 75 | */ |
76 | #define PROOF_FIND_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5) | 76 | static struct GNUNET_TIME_Relative proof_find_delay; |
77 | 77 | ||
78 | 78 | ||
79 | /** | 79 | /** |
@@ -360,11 +360,11 @@ get_matching_bits_delay (uint32_t matching_bits) | |||
360 | { | 360 | { |
361 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/ | 361 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p'))*/ |
362 | // S is next_timestamp (ignored in return value) | 362 | // S is next_timestamp (ignored in return value) |
363 | // f is frequency (GNUNET_NSE_INTERVAL) | 363 | // f is frequency (gnunet_nse_interval) |
364 | // x is matching_bits | 364 | // x is matching_bits |
365 | // p' is current_size_estimate | 365 | // p' is current_size_estimate |
366 | return ((double) GNUNET_NSE_INTERVAL.rel_value / (double) 2.0) | 366 | return ((double) gnunet_nse_interval.rel_value / (double) 2.0) |
367 | - ((GNUNET_NSE_INTERVAL.rel_value / M_PI) * atan (matching_bits - current_size_estimate)); | 367 | - ((gnunet_nse_interval.rel_value / M_PI) * atan (matching_bits - current_size_estimate)); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
@@ -673,7 +673,7 @@ update_flood_message(void *cls, | |||
673 | } | 673 | } |
674 | current_timestamp = next_timestamp; | 674 | current_timestamp = next_timestamp; |
675 | next_timestamp = GNUNET_TIME_absolute_add (current_timestamp, | 675 | next_timestamp = GNUNET_TIME_absolute_add (current_timestamp, |
676 | GNUNET_NSE_INTERVAL); | 676 | gnunet_nse_interval); |
677 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; | 677 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; |
678 | if (estimate_count < HISTORY_SIZE) | 678 | if (estimate_count < HISTORY_SIZE) |
679 | estimate_count++; | 679 | estimate_count++; |
@@ -741,7 +741,7 @@ check_proof_of_work(const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, | |||
741 | pkey, | 741 | pkey, |
742 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 742 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
743 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); | 743 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); |
744 | return (count_leading_zeroes (&result) >= NSE_WORK_REQUIRED) ? GNUNET_YES : GNUNET_NO; | 744 | return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES : GNUNET_NO; |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
@@ -799,7 +799,7 @@ find_proof (void *cls, | |||
799 | &counter, | 799 | &counter, |
800 | sizeof(uint64_t)); | 800 | sizeof(uint64_t)); |
801 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); | 801 | GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); |
802 | if (NSE_WORK_REQUIRED <= count_leading_zeroes(&result)) | 802 | if (nse_work_required <= count_leading_zeroes(&result)) |
803 | { | 803 | { |
804 | my_proof = counter; | 804 | my_proof = counter; |
805 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 805 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -834,7 +834,7 @@ find_proof (void *cls, | |||
834 | { | 834 | { |
835 | my_proof = counter; | 835 | my_proof = counter; |
836 | } | 836 | } |
837 | proof_task = GNUNET_SCHEDULER_add_delayed (PROOF_FIND_DELAY, | 837 | proof_task = GNUNET_SCHEDULER_add_delayed (proof_find_delay, |
838 | &find_proof, | 838 | &find_proof, |
839 | NULL); | 839 | NULL); |
840 | } | 840 | } |
@@ -979,9 +979,9 @@ handle_p2p_size_estimate(void *cls, | |||
979 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); | 979 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); |
980 | if (ts.abs_value == current_timestamp.abs_value) | 980 | if (ts.abs_value == current_timestamp.abs_value) |
981 | idx = estimate_index; | 981 | idx = estimate_index; |
982 | else if (ts.abs_value == current_timestamp.abs_value - GNUNET_NSE_INTERVAL.rel_value) | 982 | else if (ts.abs_value == current_timestamp.abs_value - gnunet_nse_interval.rel_value) |
983 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 983 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
984 | else if (ts.abs_value == next_timestamp.abs_value - GNUNET_NSE_INTERVAL.rel_value) | 984 | else if (ts.abs_value == next_timestamp.abs_value - gnunet_nse_interval.rel_value) |
985 | { | 985 | { |
986 | if (matching_bits <= ntohl (next_message.matching_bits)) | 986 | if (matching_bits <= ntohl (next_message.matching_bits)) |
987 | return GNUNET_OK; /* ignore, simply too early */ | 987 | return GNUNET_OK; /* ignore, simply too early */ |
@@ -1212,12 +1212,12 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1212 | } | 1212 | } |
1213 | GNUNET_assert (0 == memcmp (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity))); | 1213 | GNUNET_assert (0 == memcmp (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity))); |
1214 | now = GNUNET_TIME_absolute_get (); | 1214 | now = GNUNET_TIME_absolute_get (); |
1215 | current_timestamp.abs_value = (now.abs_value / GNUNET_NSE_INTERVAL.rel_value) * GNUNET_NSE_INTERVAL.rel_value; | 1215 | current_timestamp.abs_value = (now.abs_value / gnunet_nse_interval.rel_value) * gnunet_nse_interval.rel_value; |
1216 | next_timestamp.abs_value = current_timestamp.abs_value + GNUNET_NSE_INTERVAL.rel_value; | 1216 | next_timestamp.abs_value = current_timestamp.abs_value + gnunet_nse_interval.rel_value; |
1217 | 1217 | ||
1218 | for (i=0;i<HISTORY_SIZE;i++) | 1218 | for (i=0;i<HISTORY_SIZE;i++) |
1219 | { | 1219 | { |
1220 | prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i - 1) * GNUNET_NSE_INTERVAL.rel_value; | 1220 | prev_time.abs_value = current_timestamp.abs_value - (HISTORY_SIZE - i - 1) * gnunet_nse_interval.rel_value; |
1221 | setup_flood_message (i, prev_time); | 1221 | setup_flood_message (i, prev_time); |
1222 | } | 1222 | } |
1223 | estimate_index = HISTORY_SIZE - 1; | 1223 | estimate_index = HISTORY_SIZE - 1; |
@@ -1253,6 +1253,34 @@ run(void *cls, struct GNUNET_SERVER_Handle *server, | |||
1253 | { NULL, 0, 0 } | 1253 | { NULL, 0, 0 } |
1254 | }; | 1254 | }; |
1255 | cfg = c; | 1255 | cfg = c; |
1256 | |||
1257 | if ( (GNUNET_OK != | ||
1258 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
1259 | "NSE", "INTERVAL", | ||
1260 | &gnunet_nse_interval)) || | ||
1261 | (GNUNET_OK != | ||
1262 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
1263 | "NSE", "WORKDELAY", | ||
1264 | &proof_find_delay)) || | ||
1265 | (GNUNET_OK != | ||
1266 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
1267 | "NSE", "WORKBITS", | ||
1268 | &nse_work_required)) ) | ||
1269 | { | ||
1270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1271 | _ ("NSE service is lacking key configuration settings. Exiting.\n")); | ||
1272 | GNUNET_SCHEDULER_shutdown (); | ||
1273 | return; | ||
1274 | } | ||
1275 | if (nse_work_required >= sizeof (GNUNET_HashCode) * 8) | ||
1276 | { | ||
1277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1278 | _ ("Invalid work requirement for NSE service. Exiting.\n")); | ||
1279 | GNUNET_SCHEDULER_shutdown (); | ||
1280 | return; | ||
1281 | } | ||
1282 | |||
1283 | |||
1256 | if (GNUNET_OK != | 1284 | if (GNUNET_OK != |
1257 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1285 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1258 | "GNUNETD", "HOSTKEY", | 1286 | "GNUNETD", "HOSTKEY", |
diff --git a/src/nse/test_nse.conf b/src/nse/test_nse.conf index ee3c208a2..35adc0cad 100644 --- a/src/nse/test_nse.conf +++ b/src/nse/test_nse.conf | |||
@@ -12,6 +12,14 @@ AUTOSTART = YES | |||
12 | DEBUG = YES | 12 | DEBUG = YES |
13 | CONFIG = $DEFAULTCONFIG | 13 | CONFIG = $DEFAULTCONFIG |
14 | 14 | ||
15 | # Overriding network settings for faster testing (do NOT use | ||
16 | # these values in production just because they are here) | ||
17 | WORKDELAY = 1 | ||
18 | INTERVAL = 15000 | ||
19 | WORKBITS = 8 | ||
20 | |||
21 | |||
22 | |||
15 | [arm] | 23 | [arm] |
16 | PORT = 22354 | 24 | PORT = 22354 |
17 | DEFAULTSERVICES = nse core | 25 | DEFAULTSERVICES = nse core |
@@ -49,7 +57,7 @@ EXTERNAL_ADDRESS = 127.0.0.1 | |||
49 | AUTOSTART = NO | 57 | AUTOSTART = NO |
50 | 58 | ||
51 | [testing] | 59 | [testing] |
52 | NUM_PEERS = 100 | 60 | NUM_PEERS = 10 |
53 | WEAKRANDOM = YES | 61 | WEAKRANDOM = YES |
54 | TOPOLOGY = NONE | 62 | TOPOLOGY = NONE |
55 | CONNECT_TOPOLOGY = SMALL_WORLD_RING | 63 | CONNECT_TOPOLOGY = SMALL_WORLD_RING |