diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-15 14:27:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-15 14:27:01 +0000 |
commit | f8ef504cc5e9c2788cacddad202fec3f390f1980 (patch) | |
tree | 9eb6a2809dab0d0a9ff71129178d22cf3dadfea9 /src/nse/gnunet-service-nse.c | |
parent | eed7f472501226b6d6c4f32d3c88d14123f74236 (diff) | |
download | gnunet-f8ef504cc5e9c2788cacddad202fec3f390f1980.tar.gz gnunet-f8ef504cc5e9c2788cacddad202fec3f390f1980.zip |
-minor NSE cleanup
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 29a038d3b..08e187d35 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -53,8 +53,7 @@ | |||
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Should messages be delayed randomly? This option should be set to | 55 | * Should messages be delayed randomly? This option should be set to |
56 | * GNUNET_NO only for experiments, not in production. It should also | 56 | * #GNUNET_NO only for experiments, not in production. |
57 | * be removed once the initial experiments have been completed. | ||
58 | */ | 57 | */ |
59 | #define USE_RANDOM_DELAYS GNUNET_YES | 58 | #define USE_RANDOM_DELAYS GNUNET_YES |
60 | 59 | ||
@@ -231,7 +230,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *peers; | |||
231 | static double current_size_estimate; | 230 | static double current_size_estimate; |
232 | 231 | ||
233 | /** | 232 | /** |
234 | * The standard deviation of the last HISTORY_SIZE network | 233 | * The standard deviation of the last #HISTORY_SIZE network |
235 | * size estimates. | 234 | * size estimates. |
236 | */ | 235 | */ |
237 | static double current_std_dev = NAN; | 236 | static double current_std_dev = NAN; |
@@ -412,12 +411,14 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
412 | * @param message the message received | 411 | * @param message the message received |
413 | */ | 412 | */ |
414 | static void | 413 | static void |
415 | handle_start_message (void *cls, struct GNUNET_SERVER_Client *client, | 414 | handle_start_message (void *cls, |
415 | struct GNUNET_SERVER_Client *client, | ||
416 | const struct GNUNET_MessageHeader *message) | 416 | const struct GNUNET_MessageHeader *message) |
417 | { | 417 | { |
418 | struct GNUNET_NSE_ClientMessage em; | 418 | struct GNUNET_NSE_ClientMessage em; |
419 | 419 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
421 | "Received START message from client\n"); | ||
421 | GNUNET_SERVER_notification_context_add (nc, client); | 422 | GNUNET_SERVER_notification_context_add (nc, client); |
422 | setup_estimate_message (&em); | 423 | setup_estimate_message (&em); |
423 | GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, | 424 | GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, |
@@ -479,7 +480,7 @@ get_delay_randomization (uint32_t matching_bits) | |||
479 | * Calculate the 'proof-of-work' hash (an expensive hash). | 480 | * Calculate the 'proof-of-work' hash (an expensive hash). |
480 | * | 481 | * |
481 | * @param buf data to hash | 482 | * @param buf data to hash |
482 | * @param buf_len number of bytes in 'buf' | 483 | * @param buf_len number of bytes in @a buf |
483 | * @param result where to write the resulting hash | 484 | * @param result where to write the resulting hash |
484 | */ | 485 | */ |
485 | static void | 486 | static void |
@@ -570,24 +571,27 @@ get_transmit_delay (int round_offset) | |||
570 | /** | 571 | /** |
571 | * Task that triggers a NSE P2P transmission. | 572 | * Task that triggers a NSE P2P transmission. |
572 | * | 573 | * |
573 | * @param cls the 'struct NSEPeerEntry' | 574 | * @param cls the `struct NSEPeerEntry *` |
574 | * @param tc scheduler context | 575 | * @param tc scheduler context |
575 | */ | 576 | */ |
576 | static void | 577 | static void |
577 | transmit_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 578 | transmit_task_cb (void *cls, |
579 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
578 | 580 | ||
579 | 581 | ||
580 | /** | 582 | /** |
581 | * Called when core is ready to send a message we asked for | 583 | * Called when core is ready to send a message we asked for |
582 | * out to the destination. | 584 | * out to the destination. |
583 | * | 585 | * |
584 | * @param cls closure (NULL) | 586 | * @param cls closure with the `struct NSEPeerEntry *` |
585 | * @param size number of bytes available in buf | 587 | * @param size number of bytes available in @a buf |
586 | * @param buf where the callee should write the message | 588 | * @param buf where the callee should write the message |
587 | * @return number of bytes written to buf | 589 | * @return number of bytes written to @a buf |
588 | */ | 590 | */ |
589 | static size_t | 591 | static size_t |
590 | transmit_ready (void *cls, size_t size, void *buf) | 592 | transmit_ready (void *cls, |
593 | size_t size, | ||
594 | void *buf) | ||
591 | { | 595 | { |
592 | struct NSEPeerEntry *peer_entry = cls; | 596 | struct NSEPeerEntry *peer_entry = cls; |
593 | unsigned int idx; | 597 | unsigned int idx; |
@@ -646,11 +650,12 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
646 | /** | 650 | /** |
647 | * Task that triggers a NSE P2P transmission. | 651 | * Task that triggers a NSE P2P transmission. |
648 | * | 652 | * |
649 | * @param cls the 'struct NSEPeerEntry' | 653 | * @param cls the `struct NSEPeerEntry *` |
650 | * @param tc scheduler context | 654 | * @param tc scheduler context |
651 | */ | 655 | */ |
652 | static void | 656 | static void |
653 | transmit_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 657 | transmit_task_cb (void *cls, |
658 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
654 | { | 659 | { |
655 | struct NSEPeerEntry *peer_entry = cls; | 660 | struct NSEPeerEntry *peer_entry = cls; |
656 | 661 | ||
@@ -679,7 +684,9 @@ update_network_size_estimate () | |||
679 | struct GNUNET_NSE_ClientMessage em; | 684 | struct GNUNET_NSE_ClientMessage em; |
680 | 685 | ||
681 | setup_estimate_message (&em); | 686 | setup_estimate_message (&em); |
682 | GNUNET_SERVER_notification_context_broadcast (nc, &em.header, GNUNET_YES); | 687 | GNUNET_SERVER_notification_context_broadcast (nc, |
688 | &em.header, | ||
689 | GNUNET_YES); | ||
683 | } | 690 | } |
684 | 691 | ||
685 | 692 | ||
@@ -726,8 +733,8 @@ setup_flood_message (unsigned int slot, | |||
726 | * | 733 | * |
727 | * @param cls unused | 734 | * @param cls unused |
728 | * @param key hash of peer identity | 735 | * @param key hash of peer identity |
729 | * @param value the 'struct NSEPeerEntry' | 736 | * @param value the `struct NSEPeerEntry` |
730 | * @return GNUNET_OK (continue to iterate) | 737 | * @return #GNUNET_OK (continue to iterate) |
731 | */ | 738 | */ |
732 | static int | 739 | static int |
733 | schedule_current_round (void *cls, | 740 | schedule_current_round (void *cls, |
@@ -770,7 +777,8 @@ schedule_current_round (void *cls, | |||
770 | * @param tc context for this message | 777 | * @param tc context for this message |
771 | */ | 778 | */ |
772 | static void | 779 | static void |
773 | update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 780 | update_flood_message (void *cls, |
781 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
774 | { | 782 | { |
775 | struct GNUNET_TIME_Relative offset; | 783 | struct GNUNET_TIME_Relative offset; |
776 | unsigned int i; | 784 | unsigned int i; |
@@ -820,11 +828,11 @@ update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
820 | /** | 828 | /** |
821 | * Count the leading zeroes in hash. | 829 | * Count the leading zeroes in hash. |
822 | * | 830 | * |
823 | * @param hash | 831 | * @param hash to count leading zeros in |
824 | * @return the number of leading zero bits. | 832 | * @return the number of leading zero bits. |
825 | */ | 833 | */ |
826 | static unsigned int | 834 | static unsigned int |
827 | count_leading_zeroes (const struct GNUNET_HashCode * hash) | 835 | count_leading_zeroes (const struct GNUNET_HashCode *hash) |
828 | { | 836 | { |
829 | unsigned int hash_count; | 837 | unsigned int hash_count; |
830 | 838 | ||
@@ -836,13 +844,12 @@ count_leading_zeroes (const struct GNUNET_HashCode * hash) | |||
836 | 844 | ||
837 | 845 | ||
838 | /** | 846 | /** |
839 | * Check whether the given public key | 847 | * Check whether the given public key and integer are a valid proof of |
840 | * and integer are a valid proof of work. | 848 | * work. |
841 | * | 849 | * |
842 | * @param pkey the public key | 850 | * @param pkey the public key |
843 | * @param val the integer | 851 | * @param val the integer |
844 | * | 852 | * @return #GNUNET_YES if valid, #GNUNET_NO if not |
845 | * @return GNUNET_YES if valid, GNUNET_NO if not | ||
846 | */ | 853 | */ |
847 | static int | 854 | static int |
848 | check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicSignKey *pkey, | 855 | check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicSignKey *pkey, |
@@ -889,7 +896,8 @@ write_proof () | |||
889 | * @param tc task context | 896 | * @param tc task context |
890 | */ | 897 | */ |
891 | static void | 898 | static void |
892 | find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 899 | find_proof (void *cls, |
900 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
893 | { | 901 | { |
894 | #define ROUND_SIZE 10 | 902 | #define ROUND_SIZE 10 |
895 | uint64_t counter; | 903 | uint64_t counter; |
@@ -944,9 +952,8 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
944 | * period. Verify the signature and/or proof of work. | 952 | * period. Verify the signature and/or proof of work. |
945 | * | 953 | * |
946 | * @param incoming_flood the message to verify | 954 | * @param incoming_flood the message to verify |
947 | * | 955 | * @return #GNUNET_YES if the message is verified |
948 | * @return GNUNET_YES if the message is verified | 956 | * #GNUNET_NO if the key/signature don't verify |
949 | * GNUNET_NO if the key/signature don't verify | ||
950 | */ | 957 | */ |
951 | static int | 958 | static int |
952 | verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) | 959 | verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) |
@@ -981,11 +988,13 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) | |||
981 | * | 988 | * |
982 | * @param cls peer entry to exclude from updates | 989 | * @param cls peer entry to exclude from updates |
983 | * @param key hash of peer identity | 990 | * @param key hash of peer identity |
984 | * @param value the 'struct NSEPeerEntry' | 991 | * @param value the `struct NSEPeerEntry *` of a peer to transmit to |
985 | * @return GNUNET_OK (continue to iterate) | 992 | * @return #GNUNET_OK (continue to iterate) |
986 | */ | 993 | */ |
987 | static int | 994 | static int |
988 | update_flood_times (void *cls, const struct GNUNET_HashCode * key, void *value) | 995 | update_flood_times (void *cls, |
996 | const struct GNUNET_HashCode *key, | ||
997 | void *value) | ||
989 | { | 998 | { |
990 | struct NSEPeerEntry *exclude = cls; | 999 | struct NSEPeerEntry *exclude = cls; |
991 | struct NSEPeerEntry *peer_entry = value; | 1000 | struct NSEPeerEntry *peer_entry = value; |
@@ -1026,7 +1035,8 @@ update_flood_times (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
1026 | * @param peer peer identity this message is from (ignored) | 1035 | * @param peer peer identity this message is from (ignored) |
1027 | */ | 1036 | */ |
1028 | static int | 1037 | static int |
1029 | handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | 1038 | handle_p2p_size_estimate (void *cls, |
1039 | const struct GNUNET_PeerIdentity *peer, | ||
1030 | const struct GNUNET_MessageHeader *message) | 1040 | const struct GNUNET_MessageHeader *message) |
1031 | { | 1041 | { |
1032 | const struct GNUNET_NSE_FloodMessage *incoming_flood; | 1042 | const struct GNUNET_NSE_FloodMessage *incoming_flood; |
@@ -1210,13 +1220,14 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1210 | * @param peer peer identity this notification is about | 1220 | * @param peer peer identity this notification is about |
1211 | */ | 1221 | */ |
1212 | static void | 1222 | static void |
1213 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 1223 | handle_core_connect (void *cls, |
1224 | const struct GNUNET_PeerIdentity *peer) | ||
1214 | { | 1225 | { |
1215 | struct NSEPeerEntry *peer_entry; | 1226 | struct NSEPeerEntry *peer_entry; |
1216 | 1227 | ||
1217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected to us\n", | 1228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected to us\n", |
1218 | GNUNET_i2s (peer)); | 1229 | GNUNET_i2s (peer)); |
1219 | peer_entry = GNUNET_malloc (sizeof (struct NSEPeerEntry)); | 1230 | peer_entry = GNUNET_new (struct NSEPeerEntry); |
1220 | peer_entry->id = *peer; | 1231 | peer_entry->id = *peer; |
1221 | GNUNET_assert (GNUNET_OK == | 1232 | GNUNET_assert (GNUNET_OK == |
1222 | GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, | 1233 | GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, |
@@ -1237,11 +1248,13 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1237 | * @param peer peer identity this notification is about | 1248 | * @param peer peer identity this notification is about |
1238 | */ | 1249 | */ |
1239 | static void | 1250 | static void |
1240 | handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 1251 | handle_core_disconnect (void *cls, |
1252 | const struct GNUNET_PeerIdentity *peer) | ||
1241 | { | 1253 | { |
1242 | struct NSEPeerEntry *pos; | 1254 | struct NSEPeerEntry *pos; |
1243 | 1255 | ||
1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us\n", | 1256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1257 | "Peer `%s' disconnected from us\n", | ||
1245 | GNUNET_i2s (peer)); | 1258 | GNUNET_i2s (peer)); |
1246 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 1259 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
1247 | if (NULL == pos) | 1260 | if (NULL == pos) |
@@ -1272,10 +1285,11 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1272 | * message to the logger service | 1285 | * message to the logger service |
1273 | * | 1286 | * |
1274 | * @param cls NULL | 1287 | * @param cls NULL |
1275 | * @param size the amount of data sent | 1288 | * @param size the amount of data sent (ignored) |
1276 | */ | 1289 | */ |
1277 | static void | 1290 | static void |
1278 | flush_comp_cb (void *cls, size_t size) | 1291 | flush_comp_cb (void *cls, |
1292 | size_t size) | ||
1279 | { | 1293 | { |
1280 | GNUNET_TESTBED_LOGGER_disconnect (lh); | 1294 | GNUNET_TESTBED_LOGGER_disconnect (lh); |
1281 | lh = NULL; | 1295 | lh = NULL; |
@@ -1290,7 +1304,8 @@ flush_comp_cb (void *cls, size_t size) | |||
1290 | * @param tc unused | 1304 | * @param tc unused |
1291 | */ | 1305 | */ |
1292 | static void | 1306 | static void |
1293 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1307 | shutdown_task (void *cls, |
1308 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1294 | { | 1309 | { |
1295 | if (GNUNET_SCHEDULER_NO_TASK != flood_task) | 1310 | if (GNUNET_SCHEDULER_NO_TASK != flood_task) |
1296 | { | 1311 | { |
@@ -1515,7 +1530,8 @@ run (void *cls, | |||
1515 | * @return 0 ok, 1 on error | 1530 | * @return 0 ok, 1 on error |
1516 | */ | 1531 | */ |
1517 | int | 1532 | int |
1518 | main (int argc, char *const *argv) | 1533 | main (int argc, |
1534 | char *const *argv) | ||
1519 | { | 1535 | { |
1520 | return (GNUNET_OK == | 1536 | return (GNUNET_OK == |
1521 | GNUNET_SERVICE_run (argc, argv, "nse", GNUNET_SERVICE_OPTION_NONE, | 1537 | GNUNET_SERVICE_run (argc, argv, "nse", GNUNET_SERVICE_OPTION_NONE, |
@@ -1529,7 +1545,8 @@ main (int argc, char *const *argv) | |||
1529 | /** | 1545 | /** |
1530 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1546 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1531 | */ | 1547 | */ |
1532 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | 1548 | void __attribute__ ((constructor)) |
1549 | GNUNET_ARM_memory_init () | ||
1533 | { | 1550 | { |
1534 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | 1551 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1535 | mallopt (M_TOP_PAD, 1 * 1024); | 1552 | mallopt (M_TOP_PAD, 1 * 1024); |