aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-service-nse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r--src/nse/gnunet-service-nse.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 23144b346..86b75c9c9 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -305,6 +305,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
305 double variance; 305 double variance;
306 double val; 306 double val;
307 double nsize; 307 double nsize;
308
308#define WEST 1 309#define WEST 1
309 /* Weighted incremental algorithm for stddev according to West (1979) */ 310 /* Weighted incremental algorithm for stddev according to West (1979) */
310#if WEST 311#if WEST
@@ -353,13 +354,13 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
353 if (0 != estimate_count) 354 if (0 != estimate_count)
354 { 355 {
355 mean = sum / estimate_count; 356 mean = sum / estimate_count;
356 variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability... 357 variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability...
357 } 358 }
358#endif 359#endif
359 if (variance >= 0) 360 if (variance >= 0)
360 std_dev = sqrt (variance); 361 std_dev = sqrt (variance);
361 else 362 else
362 std_dev = variance; /* must be infinity due to estimate_count == 0 */ 363 std_dev = variance; /* must be infinity due to estimate_count == 0 */
363 current_std_dev = std_dev; 364 current_std_dev = std_dev;
364 current_size_estimate = mean; 365 current_size_estimate = mean;
365 366
@@ -564,8 +565,8 @@ transmit_ready (void *cls, size_t size, void *buf)
564 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), &transmit_task, 565 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), &transmit_task,
565 peer_entry); 566 peer_entry);
566 } 567 }
567 if ( (ntohl (size_estimate_messages[idx].hop_count) == 0) && 568 if ((ntohl (size_estimate_messages[idx].hop_count) == 0) &&
568 (GNUNET_SCHEDULER_NO_TASK != proof_task) ) 569 (GNUNET_SCHEDULER_NO_TASK != proof_task))
569 { 570 {
570 GNUNET_STATISTICS_update (stats, 571 GNUNET_STATISTICS_update (stats,
571 "# flood messages not generated (no proof yet)", 572 "# flood messages not generated (no proof yet)",
@@ -667,8 +668,8 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
667 fm->proof_of_work = my_proof; 668 fm->proof_of_work = my_proof;
668 if (nse_work_required > 0) 669 if (nse_work_required > 0)
669 GNUNET_assert (GNUNET_OK == 670 GNUNET_assert (GNUNET_OK ==
670 GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose, 671 GNUNET_CRYPTO_rsa_sign (my_private_key, &fm->purpose,
671 &fm->signature)); 672 &fm->signature));
672 else 673 else
673 memset (&fm->signature, 0, sizeof (fm->signature)); 674 memset (&fm->signature, 0, sizeof (fm->signature));
674} 675}
@@ -905,12 +906,12 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
905 GNUNET_break_op (0); 906 GNUNET_break_op (0);
906 return GNUNET_NO; 907 return GNUNET_NO;
907 } 908 }
908 if ( (nse_work_required > 0) && 909 if ((nse_work_required > 0) &&
909 (GNUNET_OK != 910 (GNUNET_OK !=
910 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND, 911 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND,
911 &incoming_flood->purpose, 912 &incoming_flood->purpose,
912 &incoming_flood->signature, 913 &incoming_flood->signature,
913 &incoming_flood->pkey)) ) 914 &incoming_flood->pkey)))
914 { 915 {
915 GNUNET_break_op (0); 916 GNUNET_break_op (0);
916 return GNUNET_NO; 917 return GNUNET_NO;
@@ -1139,8 +1140,9 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
1139 peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry)); 1140 peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry));
1140 peer_entry->id = *peer; 1141 peer_entry->id = *peer;
1141 GNUNET_assert (GNUNET_OK == 1142 GNUNET_assert (GNUNET_OK ==
1142 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, peer_entry, 1143 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey,
1143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1144 peer_entry,
1145 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1144 peer_entry->transmit_task = 1146 peer_entry->transmit_task =
1145 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task, 1147 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), &transmit_task,
1146 peer_entry); 1148 peer_entry);
@@ -1267,14 +1269,14 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server,
1267 (now.abs_value / gnunet_nse_interval.rel_value) * 1269 (now.abs_value / gnunet_nse_interval.rel_value) *
1268 gnunet_nse_interval.rel_value; 1270 gnunet_nse_interval.rel_value;
1269 next_timestamp.abs_value = 1271 next_timestamp.abs_value =
1270 current_timestamp.abs_value + gnunet_nse_interval.rel_value; 1272 current_timestamp.abs_value + gnunet_nse_interval.rel_value;
1271 estimate_index = HISTORY_SIZE - 1; 1273 estimate_index = HISTORY_SIZE - 1;
1272 estimate_count = 0; 1274 estimate_count = 0;
1273 if (GNUNET_YES == check_proof_of_work (&my_public_key, 1275 if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof))
1274 my_proof))
1275 { 1276 {
1276 prev_time.abs_value = 1277 prev_time.abs_value =
1277 current_timestamp.abs_value - (estimate_index - 1) * gnunet_nse_interval.rel_value; 1278 current_timestamp.abs_value - (estimate_index -
1279 1) * gnunet_nse_interval.rel_value;
1278 setup_flood_message (estimate_index, prev_time); 1280 setup_flood_message (estimate_index, prev_time);
1279 estimate_count++; 1281 estimate_count++;
1280 } 1282 }
@@ -1386,8 +1388,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1386 nc = GNUNET_SERVER_notification_context_create (server, 1); 1388 nc = GNUNET_SERVER_notification_context_create (server, 1);
1387 /* Connect to core service and register core handlers */ 1389 /* Connect to core service and register core handlers */
1388 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */ 1390 coreAPI = GNUNET_CORE_connect (cfg, /* Main configuration */
1389 1, 1391 1, NULL, /* Closure passed to functions */
1390 NULL, /* Closure passed to functions */
1391 &core_init, /* Call core_init once connected */ 1392 &core_init, /* Call core_init once connected */
1392 &handle_core_connect, /* Handle connects */ 1393 &handle_core_connect, /* Handle connects */
1393 &handle_core_disconnect, /* Handle disconnects */ 1394 &handle_core_disconnect, /* Handle disconnects */