aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-15 14:27:01 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-15 14:27:01 +0000
commitf8ef504cc5e9c2788cacddad202fec3f390f1980 (patch)
tree9eb6a2809dab0d0a9ff71129178d22cf3dadfea9 /src/nse
parenteed7f472501226b6d6c4f32d3c88d14123f74236 (diff)
downloadgnunet-f8ef504cc5e9c2788cacddad202fec3f390f1980.tar.gz
gnunet-f8ef504cc5e9c2788cacddad202fec3f390f1980.zip
-minor NSE cleanup
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/gnunet-service-nse.c99
-rw-r--r--src/nse/nse_api.c33
2 files changed, 76 insertions, 56 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;
231static double current_size_estimate; 230static 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 */
237static double current_std_dev = NAN; 236static 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 */
414static void 413static void
415handle_start_message (void *cls, struct GNUNET_SERVER_Client *client, 414handle_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 */
485static void 486static 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 */
576static void 577static void
577transmit_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 578transmit_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 */
589static size_t 591static size_t
590transmit_ready (void *cls, size_t size, void *buf) 592transmit_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 */
652static void 656static void
653transmit_task_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 657transmit_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 */
732static int 739static int
733schedule_current_round (void *cls, 740schedule_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 */
772static void 779static void
773update_flood_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 780update_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 */
826static unsigned int 834static unsigned int
827count_leading_zeroes (const struct GNUNET_HashCode * hash) 835count_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 */
847static int 854static int
848check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicSignKey *pkey, 855check_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 */
891static void 898static void
892find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 899find_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 */
951static int 958static int
952verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) 959verify_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 */
987static int 994static int
988update_flood_times (void *cls, const struct GNUNET_HashCode * key, void *value) 995update_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 */
1028static int 1037static int
1029handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, 1038handle_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 */
1212static void 1222static void
1213handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 1223handle_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 */
1239static void 1250static void
1240handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 1251handle_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 */
1277static void 1290static void
1278flush_comp_cb (void *cls, size_t size) 1291flush_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 */
1292static void 1306static void
1293shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1307shutdown_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 */
1517int 1532int
1518main (int argc, char *const *argv) 1533main (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 */
1532void __attribute__ ((constructor)) GNUNET_ARM_memory_init () 1548void __attribute__ ((constructor))
1549GNUNET_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);
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index 211071c0d..3542b5f8a 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -35,7 +35,7 @@
35#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__)
36 36
37/** 37/**
38 * Handle for the service. 38 * Handle for talking with the NSE service.
39 */ 39 */
40struct GNUNET_NSE_Handle 40struct GNUNET_NSE_Handle
41{ 41{
@@ -70,7 +70,7 @@ struct GNUNET_NSE_Handle
70 GNUNET_NSE_Callback recv_cb; 70 GNUNET_NSE_Callback recv_cb;
71 71
72 /** 72 /**
73 * Closure to pass to callback. 73 * Closure to pass to @e recv_cb callback.
74 */ 74 */
75 void *recv_cb_cls; 75 void *recv_cb_cls;
76 76
@@ -100,13 +100,14 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
100 struct GNUNET_NSE_Handle *h = cls; 100 struct GNUNET_NSE_Handle *h = cls;
101 const struct GNUNET_NSE_ClientMessage *client_msg; 101 const struct GNUNET_NSE_ClientMessage *client_msg;
102 102
103 if (msg == NULL) 103 if (NULL == msg)
104 { 104 {
105 /* Error, timeout, death */ 105 /* Error, timeout, death */
106 GNUNET_CLIENT_disconnect (h->client); 106 GNUNET_CLIENT_disconnect (h->client);
107 h->client = NULL; 107 h->client = NULL;
108 h->reconnect_task = 108 h->reconnect_task =
109 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 109 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
110 &reconnect, h);
110 return; 111 return;
111 } 112 }
112 if ((ntohs (msg->size) != sizeof (struct GNUNET_NSE_ClientMessage)) || 113 if ((ntohs (msg->size) != sizeof (struct GNUNET_NSE_ClientMessage)) ||
@@ -124,7 +125,6 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
124} 125}
125 126
126 127
127
128/** 128/**
129 * Reschedule a connect attempt to the service. 129 * Reschedule a connect attempt to the service.
130 * 130 *
@@ -159,10 +159,10 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
159/** 159/**
160 * Transmit START message to service. 160 * Transmit START message to service.
161 * 161 *
162 * @param cls unused 162 * @param cls the `struct GNUNET_NSE_Handle *`
163 * @param size number of bytes available in buf 163 * @param size number of bytes available in @a buf
164 * @param buf where to copy the message 164 * @param buf where to copy the message
165 * @return number of bytes copied to buf 165 * @return number of bytes copied to @a buf
166 */ 166 */
167static size_t 167static size_t
168send_start (void *cls, size_t size, void *buf) 168send_start (void *cls, size_t size, void *buf)
@@ -175,11 +175,14 @@ send_start (void *cls, size_t size, void *buf)
175 { 175 {
176 /* Connect error... */ 176 /* Connect error... */
177 LOG (GNUNET_ERROR_TYPE_DEBUG, 177 LOG (GNUNET_ERROR_TYPE_DEBUG,
178 "Error while trying to transmit `%s' request.\n", "START"); 178 "Error while trying to transmit `%s' request.\n",
179 "START");
179 reschedule_connect (h); 180 reschedule_connect (h);
180 return 0; 181 return 0;
181 } 182 }
182 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "START"); 183 LOG (GNUNET_ERROR_TYPE_DEBUG,
184 "Transmitting `%s' request.\n",
185 "START");
183 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 186 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
184 187
185 msg = (struct GNUNET_MessageHeader *) buf; 188 msg = (struct GNUNET_MessageHeader *) buf;
@@ -194,11 +197,12 @@ send_start (void *cls, size_t size, void *buf)
194/** 197/**
195 * Try again to connect to network size estimation service. 198 * Try again to connect to network size estimation service.
196 * 199 *
197 * @param cls the handle to the transport service 200 * @param cls the `struct GNUNET_NSE_Handle *`
198 * @param tc scheduler context 201 * @param tc scheduler context
199 */ 202 */
200static void 203static void
201reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 204reconnect (void *cls,
205 const struct GNUNET_SCHEDULER_TaskContext *tc)
202{ 206{
203 struct GNUNET_NSE_Handle *h = cls; 207 struct GNUNET_NSE_Handle *h = cls;
204 208
@@ -223,8 +227,7 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223 * 227 *
224 * @param cfg the configuration to use 228 * @param cfg the configuration to use
225 * @param func funtion to call with network size estimate 229 * @param func funtion to call with network size estimate
226 * @param func_cls closure to pass for network size estimate callback 230 * @param func_cls closure to pass to @a func
227 *
228 * @return handle to use 231 * @return handle to use
229 */ 232 */
230struct GNUNET_NSE_Handle * 233struct GNUNET_NSE_Handle *
@@ -234,7 +237,7 @@ GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
234 struct GNUNET_NSE_Handle *ret; 237 struct GNUNET_NSE_Handle *ret;
235 238
236 GNUNET_assert (func != NULL); 239 GNUNET_assert (func != NULL);
237 ret = GNUNET_malloc (sizeof (struct GNUNET_NSE_Handle)); 240 ret = GNUNET_new (struct GNUNET_NSE_Handle);
238 ret->cfg = cfg; 241 ret->cfg = cfg;
239 ret->recv_cb = func; 242 ret->recv_cb = func;
240 ret->recv_cb_cls = func_cls; 243 ret->recv_cb_cls = func_cls;