diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/nse | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-nse-profiler.c | 713 | ||||
-rw-r--r-- | src/nse/gnunet-nse.c | 77 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 1300 | ||||
-rw-r--r-- | src/nse/nse.h | 7 | ||||
-rw-r--r-- | src/nse/nse_api.c | 95 | ||||
-rw-r--r-- | src/nse/perf_kdf.c | 50 | ||||
-rw-r--r-- | src/nse/test_nse_api.c | 54 | ||||
-rw-r--r-- | src/nse/test_nse_multipeer.c | 115 |
8 files changed, 1203 insertions, 1208 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index 12f5f37fb..eaa06b8ed 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file nse/gnunet-nse-profiler.c | 21 | * @file nse/gnunet-nse-profiler.c |
22 | * | 22 | * |
@@ -36,19 +36,18 @@ | |||
36 | /** | 36 | /** |
37 | * Generic loggins shorthand | 37 | * Generic loggins shorthand |
38 | */ | 38 | */ |
39 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Debug logging shorthand | 42 | * Debug logging shorthand |
43 | */ | 43 | */ |
44 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Information we track for a peer in the testbed. | 48 | * Information we track for a peer in the testbed. |
49 | */ | 49 | */ |
50 | struct NSEPeer | 50 | struct NSEPeer { |
51 | { | ||
52 | /** | 51 | /** |
53 | * Prev reference in DLL. | 52 | * Prev reference in DLL. |
54 | */ | 53 | */ |
@@ -84,8 +83,7 @@ struct NSEPeer | |||
84 | /** | 83 | /** |
85 | * Operation map entry | 84 | * Operation map entry |
86 | */ | 85 | */ |
87 | struct OpListEntry | 86 | struct OpListEntry { |
88 | { | ||
89 | /** | 87 | /** |
90 | * DLL next ptr | 88 | * DLL next ptr |
91 | */ | 89 | */ |
@@ -208,7 +206,7 @@ static char *data_filename; | |||
208 | * How long to wait before triggering next round? | 206 | * How long to wait before triggering next round? |
209 | * Default: 60 s. | 207 | * Default: 60 s. |
210 | */ | 208 | */ |
211 | static struct GNUNET_TIME_Relative wait_time = {60 * 1000}; | 209 | static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 }; |
212 | 210 | ||
213 | /** | 211 | /** |
214 | * DLL head for operation list | 212 | * DLL head for operation list |
@@ -231,26 +229,26 @@ static struct GNUNET_SCHEDULER_Task *round_task; | |||
231 | * STATISTICS that we keep to selected peers. | 229 | * STATISTICS that we keep to selected peers. |
232 | */ | 230 | */ |
233 | static void | 231 | static void |
234 | close_monitor_connections () | 232 | close_monitor_connections() |
235 | { | 233 | { |
236 | struct NSEPeer *pos; | 234 | struct NSEPeer *pos; |
237 | struct OpListEntry *oplist_entry; | 235 | struct OpListEntry *oplist_entry; |
238 | 236 | ||
239 | while (NULL != (pos = peer_head)) | 237 | while (NULL != (pos = peer_head)) |
240 | { | 238 | { |
241 | if (NULL != pos->nse_op) | 239 | if (NULL != pos->nse_op) |
242 | GNUNET_TESTBED_operation_done (pos->nse_op); | 240 | GNUNET_TESTBED_operation_done(pos->nse_op); |
243 | if (NULL != pos->stat_op) | 241 | if (NULL != pos->stat_op) |
244 | GNUNET_TESTBED_operation_done (pos->stat_op); | 242 | GNUNET_TESTBED_operation_done(pos->stat_op); |
245 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos); | 243 | GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); |
246 | GNUNET_free (pos); | 244 | GNUNET_free(pos); |
247 | } | 245 | } |
248 | while (NULL != (oplist_entry = oplist_head)) | 246 | while (NULL != (oplist_entry = oplist_head)) |
249 | { | 247 | { |
250 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry); | 248 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, oplist_entry); |
251 | GNUNET_TESTBED_operation_done (oplist_entry->op); | 249 | GNUNET_TESTBED_operation_done(oplist_entry->op); |
252 | GNUNET_free (oplist_entry); | 250 | GNUNET_free(oplist_entry); |
253 | } | 251 | } |
254 | } | 252 | } |
255 | 253 | ||
256 | 254 | ||
@@ -260,30 +258,30 @@ close_monitor_connections () | |||
260 | * @param cls unused | 258 | * @param cls unused |
261 | */ | 259 | */ |
262 | static void | 260 | static void |
263 | shutdown_task (void *cls) | 261 | shutdown_task(void *cls) |
264 | { | 262 | { |
265 | LOG_DEBUG ("Ending test.\n"); | 263 | LOG_DEBUG("Ending test.\n"); |
266 | close_monitor_connections (); | 264 | close_monitor_connections(); |
267 | if (NULL != round_task) | 265 | if (NULL != round_task) |
268 | { | 266 | { |
269 | GNUNET_SCHEDULER_cancel (round_task); | 267 | GNUNET_SCHEDULER_cancel(round_task); |
270 | round_task = NULL; | 268 | round_task = NULL; |
271 | } | 269 | } |
272 | if (NULL != data_file) | 270 | if (NULL != data_file) |
273 | { | 271 | { |
274 | GNUNET_DISK_file_close (data_file); | 272 | GNUNET_DISK_file_close(data_file); |
275 | data_file = NULL; | 273 | data_file = NULL; |
276 | } | 274 | } |
277 | if (NULL != output_file) | 275 | if (NULL != output_file) |
278 | { | 276 | { |
279 | GNUNET_DISK_file_close (output_file); | 277 | GNUNET_DISK_file_close(output_file); |
280 | output_file = NULL; | 278 | output_file = NULL; |
281 | } | 279 | } |
282 | if (NULL != testing_cfg) | 280 | if (NULL != testing_cfg) |
283 | { | 281 | { |
284 | GNUNET_CONFIGURATION_destroy (testing_cfg); | 282 | GNUNET_CONFIGURATION_destroy(testing_cfg); |
285 | testing_cfg = NULL; | 283 | testing_cfg = NULL; |
286 | } | 284 | } |
287 | } | 285 | } |
288 | 286 | ||
289 | 287 | ||
@@ -297,35 +295,35 @@ shutdown_task (void *cls) | |||
297 | * of the size estimation values seen | 295 | * of the size estimation values seen |
298 | */ | 296 | */ |
299 | static void | 297 | static void |
300 | handle_estimate (void *cls, | 298 | handle_estimate(void *cls, |
301 | struct GNUNET_TIME_Absolute timestamp, | 299 | struct GNUNET_TIME_Absolute timestamp, |
302 | double estimate, | 300 | double estimate, |
303 | double std_dev) | 301 | double std_dev) |
304 | { | 302 | { |
305 | struct NSEPeer *peer = cls; | 303 | struct NSEPeer *peer = cls; |
306 | char output_buffer[512]; | 304 | char output_buffer[512]; |
307 | size_t size; | 305 | size_t size; |
308 | 306 | ||
309 | if (NULL == output_file) | 307 | if (NULL == output_file) |
310 | { | 308 | { |
311 | fprintf (stderr, | 309 | fprintf(stderr, |
312 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", | 310 | "Received network size estimate from peer %p. Size: %f std.dev. %f\n", |
313 | peer, | 311 | peer, |
314 | estimate, | 312 | estimate, |
315 | std_dev); | 313 | std_dev); |
316 | return; | 314 | return; |
317 | } | 315 | } |
318 | size = GNUNET_snprintf (output_buffer, | 316 | size = GNUNET_snprintf(output_buffer, |
319 | sizeof (output_buffer), | 317 | sizeof(output_buffer), |
320 | "%p %llu %llu %f %f %f\n", | 318 | "%p %llu %llu %f %f %f\n", |
321 | peer, | 319 | peer, |
322 | peers_running, | 320 | peers_running, |
323 | (unsigned long long) timestamp.abs_value_us, | 321 | (unsigned long long)timestamp.abs_value_us, |
324 | GNUNET_NSE_log_estimate_to_n (estimate), | 322 | GNUNET_NSE_log_estimate_to_n(estimate), |
325 | estimate, | 323 | estimate, |
326 | std_dev); | 324 | std_dev); |
327 | if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) | 325 | if (size != GNUNET_DISK_file_write(output_file, output_buffer, size)) |
328 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 326 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
329 | } | 327 | } |
330 | 328 | ||
331 | 329 | ||
@@ -340,11 +338,11 @@ handle_estimate (void *cls, | |||
340 | * @return service handle to return in 'op_result', NULL on error | 338 | * @return service handle to return in 'op_result', NULL on error |
341 | */ | 339 | */ |
342 | static void * | 340 | static void * |
343 | nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 341 | nse_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
344 | { | 342 | { |
345 | struct NSEPeer *current_peer = cls; | 343 | struct NSEPeer *current_peer = cls; |
346 | 344 | ||
347 | return GNUNET_NSE_connect (cfg, &handle_estimate, current_peer); | 345 | return GNUNET_NSE_connect(cfg, &handle_estimate, current_peer); |
348 | } | 346 | } |
349 | 347 | ||
350 | 348 | ||
@@ -356,9 +354,9 @@ nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
356 | * @param op_result service handle returned from the connect adapter | 354 | * @param op_result service handle returned from the connect adapter |
357 | */ | 355 | */ |
358 | static void | 356 | static void |
359 | nse_disconnect_adapter (void *cls, void *op_result) | 357 | nse_disconnect_adapter(void *cls, void *op_result) |
360 | { | 358 | { |
361 | GNUNET_NSE_disconnect (op_result); | 359 | GNUNET_NSE_disconnect(op_result); |
362 | } | 360 | } |
363 | 361 | ||
364 | 362 | ||
@@ -373,40 +371,40 @@ nse_disconnect_adapter (void *cls, void *op_result) | |||
373 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 371 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
374 | */ | 372 | */ |
375 | static int | 373 | static int |
376 | stat_iterator (void *cls, | 374 | stat_iterator(void *cls, |
377 | const char *subsystem, | 375 | const char *subsystem, |
378 | const char *name, | 376 | const char *name, |
379 | uint64_t value, | 377 | uint64_t value, |
380 | int is_persistent) | 378 | int is_persistent) |
381 | { | 379 | { |
382 | char *output_buffer; | 380 | char *output_buffer; |
383 | struct GNUNET_TIME_Absolute now; | 381 | struct GNUNET_TIME_Absolute now; |
384 | int size; | 382 | int size; |
385 | unsigned int flag; | 383 | unsigned int flag; |
386 | 384 | ||
387 | GNUNET_assert (NULL != data_file); | 385 | GNUNET_assert(NULL != data_file); |
388 | now = GNUNET_TIME_absolute_get (); | 386 | now = GNUNET_TIME_absolute_get(); |
389 | flag = strcasecmp (subsystem, "core"); | 387 | flag = strcasecmp(subsystem, "core"); |
390 | if (0 != flag) | 388 | if (0 != flag) |
391 | flag = 1; | 389 | flag = 1; |
392 | size = GNUNET_asprintf (&output_buffer, | 390 | size = GNUNET_asprintf(&output_buffer, |
393 | "%llu %llu %u\n", | 391 | "%llu %llu %u\n", |
394 | now.abs_value_us / 1000LL / 1000LL, | 392 | now.abs_value_us / 1000LL / 1000LL, |
395 | value, | 393 | value, |
396 | flag); | 394 | flag); |
397 | if (0 > size) | 395 | if (0 > size) |
398 | { | 396 | { |
399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); | 397 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); |
400 | GNUNET_free (output_buffer); | 398 | GNUNET_free(output_buffer); |
401 | return GNUNET_SYSERR; | 399 | return GNUNET_SYSERR; |
402 | } | 400 | } |
403 | if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size)) | 401 | if (size != GNUNET_DISK_file_write(data_file, output_buffer, (size_t)size)) |
404 | { | 402 | { |
405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 403 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
406 | GNUNET_free (output_buffer); | 404 | GNUNET_free(output_buffer); |
407 | return GNUNET_SYSERR; | 405 | return GNUNET_SYSERR; |
408 | } | 406 | } |
409 | GNUNET_free (output_buffer); | 407 | GNUNET_free(output_buffer); |
410 | return GNUNET_OK; | 408 | return GNUNET_OK; |
411 | } | 409 | } |
412 | 410 | ||
@@ -421,11 +419,11 @@ stat_iterator (void *cls, | |||
421 | * @return service handle to return in 'op_result', NULL on error | 419 | * @return service handle to return in 'op_result', NULL on error |
422 | */ | 420 | */ |
423 | static void * | 421 | static void * |
424 | stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 422 | stat_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
425 | { | 423 | { |
426 | struct NSEPeer *peer = cls; | 424 | struct NSEPeer *peer = cls; |
427 | 425 | ||
428 | peer->sh = GNUNET_STATISTICS_create ("nse-profiler", cfg); | 426 | peer->sh = GNUNET_STATISTICS_create("nse-profiler", cfg); |
429 | return peer->sh; | 427 | return peer->sh; |
430 | } | 428 | } |
431 | 429 | ||
@@ -437,23 +435,23 @@ stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
437 | * @param op_result service handle returned from the connect adapter | 435 | * @param op_result service handle returned from the connect adapter |
438 | */ | 436 | */ |
439 | static void | 437 | static void |
440 | stat_disconnect_adapter (void *cls, void *op_result) | 438 | stat_disconnect_adapter(void *cls, void *op_result) |
441 | { | 439 | { |
442 | struct NSEPeer *peer = cls; | 440 | struct NSEPeer *peer = cls; |
443 | 441 | ||
444 | GNUNET_break (GNUNET_OK == | 442 | GNUNET_break(GNUNET_OK == |
445 | GNUNET_STATISTICS_watch_cancel (peer->sh, | 443 | GNUNET_STATISTICS_watch_cancel(peer->sh, |
446 | "core", | 444 | "core", |
447 | "# peers connected", | 445 | "# peers connected", |
448 | stat_iterator, | 446 | stat_iterator, |
449 | peer)); | 447 | peer)); |
450 | GNUNET_break (GNUNET_OK == | 448 | GNUNET_break(GNUNET_OK == |
451 | GNUNET_STATISTICS_watch_cancel (peer->sh, | 449 | GNUNET_STATISTICS_watch_cancel(peer->sh, |
452 | "nse", | 450 | "nse", |
453 | "# peers connected", | 451 | "# peers connected", |
454 | stat_iterator, | 452 | stat_iterator, |
455 | peer)); | 453 | peer)); |
456 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | 454 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); |
457 | peer->sh = NULL; | 455 | peer->sh = NULL; |
458 | } | 456 | } |
459 | 457 | ||
@@ -469,29 +467,29 @@ stat_disconnect_adapter (void *cls, void *op_result) | |||
469 | * operation has executed successfully. | 467 | * operation has executed successfully. |
470 | */ | 468 | */ |
471 | static void | 469 | static void |
472 | stat_comp_cb (void *cls, | 470 | stat_comp_cb(void *cls, |
473 | struct GNUNET_TESTBED_Operation *op, | 471 | struct GNUNET_TESTBED_Operation *op, |
474 | void *ca_result, | 472 | void *ca_result, |
475 | const char *emsg) | 473 | const char *emsg) |
476 | { | 474 | { |
477 | struct GNUNET_STATISTICS_Handle *sh = ca_result; | 475 | struct GNUNET_STATISTICS_Handle *sh = ca_result; |
478 | struct NSEPeer *peer = cls; | 476 | struct NSEPeer *peer = cls; |
479 | 477 | ||
480 | if (NULL != emsg) | 478 | if (NULL != emsg) |
481 | { | 479 | { |
482 | GNUNET_break (0); | 480 | GNUNET_break(0); |
483 | return; | 481 | return; |
484 | } | 482 | } |
485 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, | 483 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, |
486 | "core", | 484 | "core", |
487 | "# peers connected", | 485 | "# peers connected", |
488 | stat_iterator, | 486 | stat_iterator, |
489 | peer)); | 487 | peer)); |
490 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh, | 488 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch(sh, |
491 | "nse", | 489 | "nse", |
492 | "# peers connected", | 490 | "# peers connected", |
493 | stat_iterator, | 491 | stat_iterator, |
494 | peer)); | 492 | peer)); |
495 | } | 493 | } |
496 | 494 | ||
497 | 495 | ||
@@ -500,7 +498,7 @@ stat_comp_cb (void *cls, | |||
500 | * all of the running peers. | 498 | * all of the running peers. |
501 | */ | 499 | */ |
502 | static void | 500 | static void |
503 | connect_nse_service () | 501 | connect_nse_service() |
504 | { | 502 | { |
505 | struct NSEPeer *current_peer; | 503 | struct NSEPeer *current_peer; |
506 | unsigned int i; | 504 | unsigned int i; |
@@ -508,39 +506,39 @@ connect_nse_service () | |||
508 | 506 | ||
509 | if (0 == connection_limit) | 507 | if (0 == connection_limit) |
510 | return; | 508 | return; |
511 | LOG_DEBUG ("Connecting to nse service of peers\n"); | 509 | LOG_DEBUG("Connecting to nse service of peers\n"); |
512 | connections = 0; | 510 | connections = 0; |
513 | for (i = 0; i < num_peers_in_round[current_round]; i++) | 511 | for (i = 0; i < num_peers_in_round[current_round]; i++) |
514 | { | 512 | { |
515 | if ((num_peers_in_round[current_round] > connection_limit) && | 513 | if ((num_peers_in_round[current_round] > connection_limit) && |
516 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) | 514 | (0 != (i % (num_peers_in_round[current_round] / connection_limit)))) |
517 | continue; | 515 | continue; |
518 | LOG_DEBUG ("Connecting to nse service of peer %d\n", i); | 516 | LOG_DEBUG("Connecting to nse service of peer %d\n", i); |
519 | current_peer = GNUNET_new (struct NSEPeer); | 517 | current_peer = GNUNET_new(struct NSEPeer); |
520 | current_peer->daemon = daemons[i]; | 518 | current_peer->daemon = daemons[i]; |
521 | current_peer->nse_op = | 519 | current_peer->nse_op = |
522 | GNUNET_TESTBED_service_connect (NULL, | 520 | GNUNET_TESTBED_service_connect(NULL, |
523 | current_peer->daemon, | 521 | current_peer->daemon, |
524 | "nse", | 522 | "nse", |
525 | NULL, | 523 | NULL, |
526 | NULL, | 524 | NULL, |
527 | &nse_connect_adapter, | 525 | &nse_connect_adapter, |
528 | &nse_disconnect_adapter, | 526 | &nse_disconnect_adapter, |
529 | current_peer); | 527 | current_peer); |
530 | if (NULL != data_file) | 528 | if (NULL != data_file) |
531 | current_peer->stat_op = | 529 | current_peer->stat_op = |
532 | GNUNET_TESTBED_service_connect (NULL, | 530 | GNUNET_TESTBED_service_connect(NULL, |
533 | current_peer->daemon, | 531 | current_peer->daemon, |
534 | "statistics", | 532 | "statistics", |
535 | stat_comp_cb, | 533 | stat_comp_cb, |
536 | current_peer, | 534 | current_peer, |
537 | &stat_connect_adapter, | 535 | &stat_connect_adapter, |
538 | &stat_disconnect_adapter, | 536 | &stat_disconnect_adapter, |
539 | current_peer); | 537 | current_peer); |
540 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); | 538 | GNUNET_CONTAINER_DLL_insert(peer_head, peer_tail, current_peer); |
541 | if (++connections == connection_limit) | 539 | if (++connections == connection_limit) |
542 | break; | 540 | break; |
543 | } | 541 | } |
544 | } | 542 | } |
545 | 543 | ||
546 | 544 | ||
@@ -550,7 +548,7 @@ connect_nse_service () | |||
550 | * @param cls NULL, unused | 548 | * @param cls NULL, unused |
551 | */ | 549 | */ |
552 | static void | 550 | static void |
553 | next_round (void *cls); | 551 | next_round(void *cls); |
554 | 552 | ||
555 | 553 | ||
556 | /** | 554 | /** |
@@ -561,11 +559,11 @@ next_round (void *cls); | |||
561 | * @param cls unused, NULL | 559 | * @param cls unused, NULL |
562 | */ | 560 | */ |
563 | static void | 561 | static void |
564 | finish_round (void *cls) | 562 | finish_round(void *cls) |
565 | { | 563 | { |
566 | LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); | 564 | LOG(GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); |
567 | close_monitor_connections (); | 565 | close_monitor_connections(); |
568 | round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL); | 566 | round_task = GNUNET_SCHEDULER_add_now(&next_round, NULL); |
569 | } | 567 | } |
570 | 568 | ||
571 | 569 | ||
@@ -575,11 +573,11 @@ finish_round (void *cls) | |||
575 | * specified delay before finishing the round). | 573 | * specified delay before finishing the round). |
576 | */ | 574 | */ |
577 | static void | 575 | static void |
578 | run_round () | 576 | run_round() |
579 | { | 577 | { |
580 | LOG_DEBUG ("Running round %u\n", current_round); | 578 | LOG_DEBUG("Running round %u\n", current_round); |
581 | connect_nse_service (); | 579 | connect_nse_service(); |
582 | GNUNET_SCHEDULER_add_delayed (wait_time, &finish_round, NULL); | 580 | GNUNET_SCHEDULER_add_delayed(wait_time, &finish_round, NULL); |
583 | } | 581 | } |
584 | 582 | ||
585 | 583 | ||
@@ -587,12 +585,12 @@ run_round () | |||
587 | * Creates an oplist entry and adds it to the oplist DLL | 585 | * Creates an oplist entry and adds it to the oplist DLL |
588 | */ | 586 | */ |
589 | static struct OpListEntry * | 587 | static struct OpListEntry * |
590 | make_oplist_entry () | 588 | make_oplist_entry() |
591 | { | 589 | { |
592 | struct OpListEntry *entry; | 590 | struct OpListEntry *entry; |
593 | 591 | ||
594 | entry = GNUNET_new (struct OpListEntry); | 592 | entry = GNUNET_new(struct OpListEntry); |
595 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | 593 | GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); |
596 | return entry; | 594 | return entry; |
597 | } | 595 | } |
598 | 596 | ||
@@ -605,25 +603,25 @@ make_oplist_entry () | |||
605 | * @param emsg NULL on success; otherwise an error description | 603 | * @param emsg NULL on success; otherwise an error description |
606 | */ | 604 | */ |
607 | static void | 605 | static void |
608 | manage_service_cb (void *cls, | 606 | manage_service_cb(void *cls, |
609 | struct GNUNET_TESTBED_Operation *op, | 607 | struct GNUNET_TESTBED_Operation *op, |
610 | const char *emsg) | 608 | const char *emsg) |
611 | { | 609 | { |
612 | struct OpListEntry *entry = cls; | 610 | struct OpListEntry *entry = cls; |
613 | 611 | ||
614 | GNUNET_TESTBED_operation_done (entry->op); | 612 | GNUNET_TESTBED_operation_done(entry->op); |
615 | if (NULL != emsg) | 613 | if (NULL != emsg) |
616 | { | 614 | { |
617 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); | 615 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); |
618 | GNUNET_SCHEDULER_shutdown (); | 616 | GNUNET_SCHEDULER_shutdown(); |
619 | return; | 617 | return; |
620 | } | 618 | } |
621 | GNUNET_assert (0 != entry->delta); | 619 | GNUNET_assert(0 != entry->delta); |
622 | peers_running += entry->delta; | 620 | peers_running += entry->delta; |
623 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 621 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
624 | GNUNET_free (entry); | 622 | GNUNET_free(entry); |
625 | if (num_peers_in_round[current_round] == peers_running) | 623 | if (num_peers_in_round[current_round] == peers_running) |
626 | run_round (); | 624 | run_round(); |
627 | } | 625 | } |
628 | 626 | ||
629 | 627 | ||
@@ -632,35 +630,35 @@ manage_service_cb (void *cls, | |||
632 | * peers for the round | 630 | * peers for the round |
633 | */ | 631 | */ |
634 | static void | 632 | static void |
635 | adjust_running_peers () | 633 | adjust_running_peers() |
636 | { | 634 | { |
637 | struct OpListEntry *entry; | 635 | struct OpListEntry *entry; |
638 | unsigned int i; | 636 | unsigned int i; |
639 | 637 | ||
640 | /* start peers if we have too few */ | 638 | /* start peers if we have too few */ |
641 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) | 639 | for (i = peers_running; i < num_peers_in_round[current_round]; i++) |
642 | { | 640 | { |
643 | entry = make_oplist_entry (); | 641 | entry = make_oplist_entry(); |
644 | entry->delta = 1; | 642 | entry->delta = 1; |
645 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | 643 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, |
646 | daemons[i], | 644 | daemons[i], |
647 | "nse", | 645 | "nse", |
648 | &manage_service_cb, | 646 | &manage_service_cb, |
649 | entry, | 647 | entry, |
650 | 1); | 648 | 1); |
651 | } | 649 | } |
652 | /* stop peers if we have too many */ | 650 | /* stop peers if we have too many */ |
653 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) | 651 | for (i = num_peers_in_round[current_round]; i < peers_running; i++) |
654 | { | 652 | { |
655 | entry = make_oplist_entry (); | 653 | entry = make_oplist_entry(); |
656 | entry->delta = -1; | 654 | entry->delta = -1; |
657 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | 655 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, |
658 | daemons[i], | 656 | daemons[i], |
659 | "nse", | 657 | "nse", |
660 | &manage_service_cb, | 658 | &manage_service_cb, |
661 | entry, | 659 | entry, |
662 | 0); | 660 | 0); |
663 | } | 661 | } |
664 | } | 662 | } |
665 | 663 | ||
666 | 664 | ||
@@ -671,25 +669,25 @@ adjust_running_peers () | |||
671 | * @param cls NULL, unused | 669 | * @param cls NULL, unused |
672 | */ | 670 | */ |
673 | static void | 671 | static void |
674 | next_round (void *cls) | 672 | next_round(void *cls) |
675 | { | 673 | { |
676 | round_task = NULL; | 674 | round_task = NULL; |
677 | LOG_DEBUG ("Disconnecting nse service of peers\n"); | 675 | LOG_DEBUG("Disconnecting nse service of peers\n"); |
678 | current_round++; | 676 | current_round++; |
679 | if (current_round == num_rounds) | 677 | if (current_round == num_rounds) |
680 | { | 678 | { |
681 | /* this was the last round, terminate */ | 679 | /* this was the last round, terminate */ |
682 | ok = 0; | 680 | ok = 0; |
683 | GNUNET_SCHEDULER_shutdown (); | 681 | GNUNET_SCHEDULER_shutdown(); |
684 | return; | 682 | return; |
685 | } | 683 | } |
686 | if (num_peers_in_round[current_round] == peers_running) | 684 | if (num_peers_in_round[current_round] == peers_running) |
687 | { | 685 | { |
688 | /* no need to churn, just run next round */ | 686 | /* no need to churn, just run next round */ |
689 | run_round (); | 687 | run_round(); |
690 | return; | 688 | return; |
691 | } | 689 | } |
692 | adjust_running_peers (); | 690 | adjust_running_peers(); |
693 | } | 691 | } |
694 | 692 | ||
695 | 693 | ||
@@ -701,20 +699,22 @@ next_round (void *cls) | |||
701 | * @param event information on what is happening | 699 | * @param event information on what is happening |
702 | */ | 700 | */ |
703 | static void | 701 | static void |
704 | master_controller_cb (void *cls, | 702 | master_controller_cb(void *cls, |
705 | const struct GNUNET_TESTBED_EventInformation *event) | 703 | const struct GNUNET_TESTBED_EventInformation *event) |
706 | { | 704 | { |
707 | switch (event->type) | 705 | switch (event->type) |
708 | { | 706 | { |
709 | case GNUNET_TESTBED_ET_CONNECT: | 707 | case GNUNET_TESTBED_ET_CONNECT: |
710 | total_connections++; | 708 | total_connections++; |
711 | break; | 709 | break; |
712 | case GNUNET_TESTBED_ET_DISCONNECT: | 710 | |
713 | total_connections--; | 711 | case GNUNET_TESTBED_ET_DISCONNECT: |
714 | break; | 712 | total_connections--; |
715 | default: | 713 | break; |
716 | break; | 714 | |
717 | } | 715 | default: |
716 | break; | ||
717 | } | ||
718 | } | 718 | } |
719 | 719 | ||
720 | 720 | ||
@@ -732,28 +732,28 @@ master_controller_cb (void *cls, | |||
732 | * failed | 732 | * failed |
733 | */ | 733 | */ |
734 | static void | 734 | static void |
735 | test_master (void *cls, | 735 | test_master(void *cls, |
736 | struct GNUNET_TESTBED_RunHandle *h, | 736 | struct GNUNET_TESTBED_RunHandle *h, |
737 | unsigned int num_peers_, | 737 | unsigned int num_peers_, |
738 | struct GNUNET_TESTBED_Peer **peers, | 738 | struct GNUNET_TESTBED_Peer **peers, |
739 | unsigned int links_succeeded, | 739 | unsigned int links_succeeded, |
740 | unsigned int links_failed) | 740 | unsigned int links_failed) |
741 | { | 741 | { |
742 | if (NULL == peers) | 742 | if (NULL == peers) |
743 | { | 743 | { |
744 | GNUNET_SCHEDULER_shutdown (); | 744 | GNUNET_SCHEDULER_shutdown(); |
745 | return; | 745 | return; |
746 | } | 746 | } |
747 | daemons = peers; | 747 | daemons = peers; |
748 | GNUNET_break (num_peers_ == num_peers); | 748 | GNUNET_break(num_peers_ == num_peers); |
749 | peers_running = num_peers; | 749 | peers_running = num_peers; |
750 | if (num_peers_in_round[current_round] == peers_running) | 750 | if (num_peers_in_round[current_round] == peers_running) |
751 | { | 751 | { |
752 | /* no need to churn, just run the starting round */ | 752 | /* no need to churn, just run the starting round */ |
753 | run_round (); | 753 | run_round(); |
754 | return; | 754 | return; |
755 | } | 755 | } |
756 | adjust_running_peers (); | 756 | adjust_running_peers(); |
757 | } | 757 | } |
758 | 758 | ||
759 | 759 | ||
@@ -766,75 +766,75 @@ test_master (void *cls, | |||
766 | * @param cfg configuration handle | 766 | * @param cfg configuration handle |
767 | */ | 767 | */ |
768 | static void | 768 | static void |
769 | run (void *cls, | 769 | run(void *cls, |
770 | char *const *args, | 770 | char *const *args, |
771 | const char *cfgfile, | 771 | const char *cfgfile, |
772 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 772 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
773 | { | 773 | { |
774 | char *tok; | 774 | char *tok; |
775 | uint64_t event_mask; | 775 | uint64_t event_mask; |
776 | unsigned int num; | 776 | unsigned int num; |
777 | 777 | ||
778 | ok = 1; | 778 | ok = 1; |
779 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | 779 | testing_cfg = GNUNET_CONFIGURATION_dup(cfg); |
780 | LOG_DEBUG ("Starting daemons.\n"); | 780 | LOG_DEBUG("Starting daemons.\n"); |
781 | if (NULL == num_peer_spec) | 781 | if (NULL == num_peer_spec) |
782 | { | ||
783 | fprintf (stderr, "You need to specify the number of peers to run\n"); | ||
784 | return; | ||
785 | } | ||
786 | for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ",")) | ||
787 | { | ||
788 | if (1 != sscanf (tok, "%u", &num)) | ||
789 | { | 782 | { |
790 | fprintf (stderr, "You need to specify numbers, not `%s'\n", tok); | 783 | fprintf(stderr, "You need to specify the number of peers to run\n"); |
791 | return; | 784 | return; |
792 | } | 785 | } |
793 | if (0 == num) | 786 | for (tok = strtok(num_peer_spec, ","); NULL != tok; tok = strtok(NULL, ",")) |
794 | { | 787 | { |
795 | fprintf (stderr, "Refusing to run a round with 0 peers\n"); | 788 | if (1 != sscanf(tok, "%u", &num)) |
796 | return; | 789 | { |
790 | fprintf(stderr, "You need to specify numbers, not `%s'\n", tok); | ||
791 | return; | ||
792 | } | ||
793 | if (0 == num) | ||
794 | { | ||
795 | fprintf(stderr, "Refusing to run a round with 0 peers\n"); | ||
796 | return; | ||
797 | } | ||
798 | GNUNET_array_append(num_peers_in_round, num_rounds, num); | ||
799 | num_peers = GNUNET_MAX(num_peers, num); | ||
797 | } | 800 | } |
798 | GNUNET_array_append (num_peers_in_round, num_rounds, num); | ||
799 | num_peers = GNUNET_MAX (num_peers, num); | ||
800 | } | ||
801 | if (0 == num_peers) | 801 | if (0 == num_peers) |
802 | { | 802 | { |
803 | fprintf (stderr, "Refusing to run a testbed with no rounds\n"); | 803 | fprintf(stderr, "Refusing to run a testbed with no rounds\n"); |
804 | return; | 804 | return; |
805 | } | 805 | } |
806 | if ((NULL != data_filename) && | 806 | if ((NULL != data_filename) && |
807 | (NULL == | 807 | (NULL == |
808 | (data_file = GNUNET_DISK_file_open (data_filename, | 808 | (data_file = GNUNET_DISK_file_open(data_filename, |
809 | GNUNET_DISK_OPEN_READWRITE | | 809 | GNUNET_DISK_OPEN_READWRITE | |
810 | GNUNET_DISK_OPEN_TRUNCATE | | 810 | GNUNET_DISK_OPEN_TRUNCATE | |
811 | GNUNET_DISK_OPEN_CREATE, | 811 | GNUNET_DISK_OPEN_CREATE, |
812 | GNUNET_DISK_PERM_USER_READ | | 812 | GNUNET_DISK_PERM_USER_READ | |
813 | GNUNET_DISK_PERM_USER_WRITE)))) | 813 | GNUNET_DISK_PERM_USER_WRITE)))) |
814 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", data_filename); | 814 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", data_filename); |
815 | 815 | ||
816 | if ((NULL != output_filename) && | 816 | if ((NULL != output_filename) && |
817 | (NULL == | 817 | (NULL == |
818 | (output_file = GNUNET_DISK_file_open (output_filename, | 818 | (output_file = GNUNET_DISK_file_open(output_filename, |
819 | GNUNET_DISK_OPEN_READWRITE | | 819 | GNUNET_DISK_OPEN_READWRITE | |
820 | GNUNET_DISK_OPEN_CREATE, | 820 | GNUNET_DISK_OPEN_CREATE, |
821 | GNUNET_DISK_PERM_USER_READ | | 821 | GNUNET_DISK_PERM_USER_READ | |
822 | GNUNET_DISK_PERM_USER_WRITE)))) | 822 | GNUNET_DISK_PERM_USER_WRITE)))) |
823 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", output_filename); | 823 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", output_filename); |
824 | event_mask = 0LL; | 824 | event_mask = 0LL; |
825 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 825 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
826 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 826 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
827 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 827 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
828 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); | 828 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); |
829 | GNUNET_TESTBED_run (hosts_file, | 829 | GNUNET_TESTBED_run(hosts_file, |
830 | cfg, | 830 | cfg, |
831 | num_peers, | 831 | num_peers, |
832 | event_mask, | 832 | event_mask, |
833 | master_controller_cb, | 833 | master_controller_cb, |
834 | NULL, /* master_controller_cb cls */ | 834 | NULL, /* master_controller_cb cls */ |
835 | &test_master, | 835 | &test_master, |
836 | NULL); /* test_master cls */ | 836 | NULL); /* test_master cls */ |
837 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 837 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
838 | } | 838 | } |
839 | 839 | ||
840 | 840 | ||
@@ -844,72 +844,73 @@ run (void *cls, | |||
844 | * @return 0 on success | 844 | * @return 0 on success |
845 | */ | 845 | */ |
846 | int | 846 | int |
847 | main (int argc, char *const *argv) | 847 | main(int argc, char *const *argv) |
848 | { | 848 | { |
849 | struct GNUNET_GETOPT_CommandLineOption options[] = | 849 | struct GNUNET_GETOPT_CommandLineOption options[] = |
850 | {GNUNET_GETOPT_option_uint ( | 850 | { GNUNET_GETOPT_option_uint( |
851 | 'C', | 851 | 'C', |
852 | "connections", | 852 | "connections", |
853 | "COUNT", | 853 | "COUNT", |
854 | gettext_noop ( | 854 | gettext_noop( |
855 | "limit to the number of connections to NSE services, 0 for none"), | 855 | "limit to the number of connections to NSE services, 0 for none"), |
856 | &connection_limit), | 856 | &connection_limit), |
857 | GNUNET_GETOPT_option_string ( | 857 | GNUNET_GETOPT_option_string( |
858 | 'd', | 858 | 'd', |
859 | "details", | 859 | "details", |
860 | "FILENAME", | 860 | "FILENAME", |
861 | gettext_noop ( | 861 | gettext_noop( |
862 | "name of the file for writing connection information and statistics"), | 862 | "name of the file for writing connection information and statistics"), |
863 | &data_filename), | 863 | &data_filename), |
864 | 864 | ||
865 | GNUNET_GETOPT_option_string ( | 865 | GNUNET_GETOPT_option_string( |
866 | 'H', | 866 | 'H', |
867 | "hosts", | 867 | "hosts", |
868 | "FILENAME", | 868 | "FILENAME", |
869 | gettext_noop ( | 869 | gettext_noop( |
870 | "name of the file with the login information for the testbed"), | 870 | "name of the file with the login information for the testbed"), |
871 | &hosts_file), | 871 | &hosts_file), |
872 | 872 | ||
873 | GNUNET_GETOPT_option_string ( | 873 | GNUNET_GETOPT_option_string( |
874 | 'o', | 874 | 'o', |
875 | "output", | 875 | "output", |
876 | "FILENAME", | 876 | "FILENAME", |
877 | gettext_noop ("name of the file for writing the main results"), | 877 | gettext_noop("name of the file for writing the main results"), |
878 | &output_filename), | 878 | &output_filename), |
879 | 879 | ||
880 | 880 | ||
881 | GNUNET_GETOPT_option_string ( | 881 | GNUNET_GETOPT_option_string( |
882 | 'p', | 882 | 'p', |
883 | "peers", | 883 | "peers", |
884 | "NETWORKSIZESPEC", | 884 | "NETWORKSIZESPEC", |
885 | gettext_noop ( | 885 | gettext_noop( |
886 | "Number of peers to run in each round, separated by commas"), | 886 | "Number of peers to run in each round, separated by commas"), |
887 | &num_peer_spec), | 887 | &num_peer_spec), |
888 | 888 | ||
889 | GNUNET_GETOPT_option_increment_uint ( | 889 | GNUNET_GETOPT_option_increment_uint( |
890 | 'V', | 890 | 'V', |
891 | "verbose", | 891 | "verbose", |
892 | gettext_noop ("be verbose (print progress information)"), | 892 | gettext_noop("be verbose (print progress information)"), |
893 | &verbose), | 893 | &verbose), |
894 | 894 | ||
895 | GNUNET_GETOPT_option_relative_time ('w', | 895 | GNUNET_GETOPT_option_relative_time('w', |
896 | "wait", | 896 | "wait", |
897 | "DELAY", | 897 | "DELAY", |
898 | gettext_noop ("delay between rounds"), | 898 | gettext_noop("delay between rounds"), |
899 | &wait_time), | 899 | &wait_time), |
900 | GNUNET_GETOPT_OPTION_END}; | 900 | GNUNET_GETOPT_OPTION_END }; |
901 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 901 | |
902 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | ||
902 | return 2; | 903 | return 2; |
903 | if ( | 904 | if ( |
904 | GNUNET_OK != | 905 | GNUNET_OK != |
905 | GNUNET_PROGRAM_run (argc, | 906 | GNUNET_PROGRAM_run(argc, |
906 | argv, | 907 | argv, |
907 | "nse-profiler", | 908 | "nse-profiler", |
908 | gettext_noop ( | 909 | gettext_noop( |
909 | "Measure quality and performance of the NSE service."), | 910 | "Measure quality and performance of the NSE service."), |
910 | options, | 911 | options, |
911 | &run, | 912 | &run, |
912 | NULL)) | 913 | NULL)) |
913 | ok = 1; | 914 | ok = 1; |
914 | return ok; | 915 | return ok; |
915 | } | 916 | } |
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c index 73b80e28b..3735373b5 100644 --- a/src/nse/gnunet-nse.c +++ b/src/nse/gnunet-nse.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file nse/gnunet-nse.c | 22 | * @file nse/gnunet-nse.c |
@@ -44,14 +44,14 @@ static int status; | |||
44 | * @param cls NULL | 44 | * @param cls NULL |
45 | */ | 45 | */ |
46 | static void | 46 | static void |
47 | do_shutdown (void *cls) | 47 | do_shutdown(void *cls) |
48 | { | 48 | { |
49 | (void) cls; | 49 | (void)cls; |
50 | if (NULL != nse) | 50 | if (NULL != nse) |
51 | { | 51 | { |
52 | GNUNET_NSE_disconnect (nse); | 52 | GNUNET_NSE_disconnect(nse); |
53 | nse = NULL; | 53 | nse = NULL; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
@@ -65,19 +65,19 @@ do_shutdown (void *cls) | |||
65 | * of the size estimation values seen | 65 | * of the size estimation values seen |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | handle_estimate (void *cls, | 68 | handle_estimate(void *cls, |
69 | struct GNUNET_TIME_Absolute timestamp, | 69 | struct GNUNET_TIME_Absolute timestamp, |
70 | double estimate, | 70 | double estimate, |
71 | double std_dev) | 71 | double std_dev) |
72 | { | 72 | { |
73 | (void) cls; | 73 | (void)cls; |
74 | status = 0; | 74 | status = 0; |
75 | fprintf (stdout, | 75 | fprintf(stdout, |
76 | "%llu %f %f %f\n", | 76 | "%llu %f %f %f\n", |
77 | (unsigned long long) timestamp.abs_value_us, | 77 | (unsigned long long)timestamp.abs_value_us, |
78 | GNUNET_NSE_log_estimate_to_n (estimate), | 78 | GNUNET_NSE_log_estimate_to_n(estimate), |
79 | estimate, | 79 | estimate, |
80 | std_dev); | 80 | std_dev); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
@@ -90,16 +90,16 @@ handle_estimate (void *cls, | |||
90 | * @param cfg configuration handle | 90 | * @param cfg configuration handle |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | run (void *cls, | 93 | run(void *cls, |
94 | char *const *args, | 94 | char *const *args, |
95 | const char *cfgfile, | 95 | const char *cfgfile, |
96 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 96 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
97 | { | 97 | { |
98 | (void) cls; | 98 | (void)cls; |
99 | (void) args; | 99 | (void)args; |
100 | (void) cfgfile; | 100 | (void)cfgfile; |
101 | nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); | 101 | nse = GNUNET_NSE_connect(cfg, &handle_estimate, NULL); |
102 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 102 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
@@ -109,21 +109,22 @@ run (void *cls, | |||
109 | * @return 0 on success | 109 | * @return 0 on success |
110 | */ | 110 | */ |
111 | int | 111 | int |
112 | main (int argc, char *const *argv) | 112 | main(int argc, char *const *argv) |
113 | { | 113 | { |
114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
115 | GNUNET_GETOPT_OPTION_END}; | 115 | GNUNET_GETOPT_OPTION_END |
116 | }; | ||
116 | 117 | ||
117 | status = 1; | 118 | status = 1; |
118 | if (GNUNET_OK != | 119 | if (GNUNET_OK != |
119 | GNUNET_PROGRAM_run (argc, | 120 | GNUNET_PROGRAM_run(argc, |
120 | argv, | 121 | argv, |
121 | "gnunet-nse", | 122 | "gnunet-nse", |
122 | gettext_noop ( | 123 | gettext_noop( |
123 | "Show network size estimates from NSE service."), | 124 | "Show network size estimates from NSE service."), |
124 | options, | 125 | options, |
125 | &run, | 126 | &run, |
126 | NULL)) | 127 | NULL)) |
127 | return 2; | 128 | return 2; |
128 | return status; | 129 | return status; |
129 | } | 130 | } |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index fd83d2b67..d71c62541 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011, 2012, 2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2012, 2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -76,7 +76,7 @@ | |||
76 | GNUNET_MQ_PREF_CORK_ALLOWED) | 76 | GNUNET_MQ_PREF_CORK_ALLOWED) |
77 | 77 | ||
78 | #if FREEBSD | 78 | #if FREEBSD |
79 | #define log2(a) (log (a) / log (2)) | 79 | #define log2(a) (log(a) / log(2)) |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | /** | 82 | /** |
@@ -117,9 +117,7 @@ static struct GNUNET_BIO_WriteHandle *histogram; | |||
117 | /** | 117 | /** |
118 | * Per-peer information. | 118 | * Per-peer information. |
119 | */ | 119 | */ |
120 | struct NSEPeerEntry | 120 | struct NSEPeerEntry { |
121 | { | ||
122 | |||
123 | /** | 121 | /** |
124 | * Core handle for sending messages to this peer. | 122 | * Core handle for sending messages to this peer. |
125 | */ | 123 | */ |
@@ -143,7 +141,6 @@ struct NSEPeerEntry | |||
143 | int previous_round; | 141 | int previous_round; |
144 | 142 | ||
145 | #if ENABLE_NSE_HISTOGRAM | 143 | #if ENABLE_NSE_HISTOGRAM |
146 | |||
147 | /** | 144 | /** |
148 | * Amount of messages received from this peer on this round. | 145 | * Amount of messages received from this peer on this round. |
149 | */ | 146 | */ |
@@ -158,7 +155,6 @@ struct NSEPeerEntry | |||
158 | * Which size did we tell the peer the network is? | 155 | * Which size did we tell the peer the network is? |
159 | */ | 156 | */ |
160 | unsigned int last_transmitted_size; | 157 | unsigned int last_transmitted_size; |
161 | |||
162 | #endif | 158 | #endif |
163 | }; | 159 | }; |
164 | 160 | ||
@@ -170,8 +166,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
170 | * peer's timer has run out before receiving a | 166 | * peer's timer has run out before receiving a |
171 | * valid reply from another peer. | 167 | * valid reply from another peer. |
172 | */ | 168 | */ |
173 | struct GNUNET_NSE_FloodMessage | 169 | struct GNUNET_NSE_FloodMessage { |
174 | { | ||
175 | /** | 170 | /** |
176 | * Type: #GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD | 171 | * Type: #GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD |
177 | */ | 172 | */ |
@@ -322,7 +317,7 @@ static uint64_t my_proof; | |||
322 | * @param em message to fill in | 317 | * @param em message to fill in |
323 | */ | 318 | */ |
324 | static void | 319 | static void |
325 | setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | 320 | setup_estimate_message(struct GNUNET_NSE_ClientMessage *em) |
326 | { | 321 | { |
327 | double mean; | 322 | double mean; |
328 | double sum; | 323 | double sum; |
@@ -345,19 +340,19 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
345 | sumweight = 0.0; | 340 | sumweight = 0.0; |
346 | variance = 0.0; | 341 | variance = 0.0; |
347 | for (unsigned int i = 0; i < estimate_count; i++) | 342 | for (unsigned int i = 0; i < estimate_count; i++) |
348 | { | 343 | { |
349 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; | 344 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
350 | 345 | ||
351 | val = htonl (size_estimate_messages[j].matching_bits); | 346 | val = htonl(size_estimate_messages[j].matching_bits); |
352 | weight = estimate_count + 1 - i; | 347 | weight = estimate_count + 1 - i; |
353 | 348 | ||
354 | temp = weight + sumweight; | 349 | temp = weight + sumweight; |
355 | q = val - mean; | 350 | q = val - mean; |
356 | r = q * weight / temp; | 351 | r = q * weight / temp; |
357 | mean += r; | 352 | mean += r; |
358 | sum += sumweight * q * r; | 353 | sum += sumweight * q * r; |
359 | sumweight = temp; | 354 | sumweight = temp; |
360 | } | 355 | } |
361 | if (estimate_count > 0) | 356 | if (estimate_count > 0) |
362 | variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0); | 357 | variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0); |
363 | #else | 358 | #else |
@@ -371,44 +366,44 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
371 | mean = 0.0; | 366 | mean = 0.0; |
372 | 367 | ||
373 | for (unsigned int i = 0; i < estimate_count; i++) | 368 | for (unsigned int i = 0; i < estimate_count; i++) |
374 | { | 369 | { |
375 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; | 370 | unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
376 | 371 | ||
377 | val = htonl (size_estimate_messages[j].matching_bits); | 372 | val = htonl(size_estimate_messages[j].matching_bits); |
378 | sum += val; | 373 | sum += val; |
379 | vsq += val * val; | 374 | vsq += val * val; |
380 | } | 375 | } |
381 | if (0 != estimate_count) | 376 | if (0 != estimate_count) |
382 | { | 377 | { |
383 | mean = sum / estimate_count; | 378 | mean = sum / estimate_count; |
384 | variance = (vsq - mean * sum) / | 379 | variance = (vsq - mean * sum) / |
385 | (estimate_count - 1.0); // terrible for numerical stability... | 380 | (estimate_count - 1.0); // terrible for numerical stability... |
386 | } | 381 | } |
387 | #endif | 382 | #endif |
388 | if (variance >= 0) | 383 | if (variance >= 0) |
389 | std_dev = sqrt (variance); | 384 | std_dev = sqrt(variance); |
390 | else | 385 | else |
391 | std_dev = variance; /* must be infinity due to estimate_count == 0 */ | 386 | std_dev = variance; /* must be infinity due to estimate_count == 0 */ |
392 | current_std_dev = std_dev; | 387 | current_std_dev = std_dev; |
393 | current_size_estimate = mean; | 388 | current_size_estimate = mean; |
394 | 389 | ||
395 | em->header.size = htons (sizeof (struct GNUNET_NSE_ClientMessage)); | 390 | em->header.size = htons(sizeof(struct GNUNET_NSE_ClientMessage)); |
396 | em->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); | 391 | em->header.type = htons(GNUNET_MESSAGE_TYPE_NSE_ESTIMATE); |
397 | em->reserved = htonl (0); | 392 | em->reserved = htonl(0); |
398 | em->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 393 | em->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); |
399 | { | 394 | { |
400 | double se = mean - 0.332747; | 395 | double se = mean - 0.332747; |
401 | unsigned int j = GNUNET_CONTAINER_multipeermap_size (peers); | 396 | unsigned int j = GNUNET_CONTAINER_multipeermap_size(peers); |
402 | if (0 == j) | 397 | if (0 == j) |
403 | j = 1; /* Avoid log2(0); can only happen if CORE didn't report | 398 | j = 1; /* Avoid log2(0); can only happen if CORE didn't report |
404 | connection to self yet */ | 399 | connection to self yet */ |
405 | nsize = log2 (j); | 400 | nsize = log2(j); |
406 | em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize)); | 401 | em->size_estimate = GNUNET_hton_double(GNUNET_MAX(se, nsize)); |
407 | em->std_deviation = GNUNET_hton_double (std_dev); | 402 | em->std_deviation = GNUNET_hton_double(std_dev); |
408 | GNUNET_STATISTICS_set (stats, | 403 | GNUNET_STATISTICS_set(stats, |
409 | "# nodes in the network (estimate)", | 404 | "# nodes in the network (estimate)", |
410 | (uint64_t) pow (2, GNUNET_MAX (se, nsize)), | 405 | (uint64_t)pow(2, GNUNET_MAX(se, nsize)), |
411 | GNUNET_NO); | 406 | GNUNET_NO); |
412 | } | 407 | } |
413 | } | 408 | } |
414 | 409 | ||
@@ -423,21 +418,21 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
423 | * @param message the message received | 418 | * @param message the message received |
424 | */ | 419 | */ |
425 | static void | 420 | static void |
426 | handle_start (void *cls, const struct GNUNET_MessageHeader *message) | 421 | handle_start(void *cls, const struct GNUNET_MessageHeader *message) |
427 | { | 422 | { |
428 | struct GNUNET_SERVICE_Client *client = cls; | 423 | struct GNUNET_SERVICE_Client *client = cls; |
429 | struct GNUNET_MQ_Handle *mq; | 424 | struct GNUNET_MQ_Handle *mq; |
430 | struct GNUNET_NSE_ClientMessage em; | 425 | struct GNUNET_NSE_ClientMessage em; |
431 | struct GNUNET_MQ_Envelope *env; | 426 | struct GNUNET_MQ_Envelope *env; |
432 | 427 | ||
433 | (void) message; | 428 | (void)message; |
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); | 429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); |
435 | mq = GNUNET_SERVICE_client_get_mq (client); | 430 | mq = GNUNET_SERVICE_client_get_mq(client); |
436 | GNUNET_notification_context_add (nc, mq); | 431 | GNUNET_notification_context_add(nc, mq); |
437 | setup_estimate_message (&em); | 432 | setup_estimate_message(&em); |
438 | env = GNUNET_MQ_msg_copy (&em.header); | 433 | env = GNUNET_MQ_msg_copy(&em.header); |
439 | GNUNET_MQ_send (mq, env); | 434 | GNUNET_MQ_send(mq, env); |
440 | GNUNET_SERVICE_client_continue (client); | 435 | GNUNET_SERVICE_client_continue(client); |
441 | } | 436 | } |
442 | 437 | ||
443 | 438 | ||
@@ -448,16 +443,16 @@ handle_start (void *cls, const struct GNUNET_MessageHeader *message) | |||
448 | * @param matching_bits number of matching bits to consider | 443 | * @param matching_bits number of matching bits to consider |
449 | */ | 444 | */ |
450 | static double | 445 | static double |
451 | get_matching_bits_delay (uint32_t matching_bits) | 446 | get_matching_bits_delay(uint32_t matching_bits) |
452 | { | 447 | { |
453 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */ | 448 | /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */ |
454 | // S is next_timestamp (ignored in return value) | 449 | // S is next_timestamp (ignored in return value) |
455 | // f is frequency (gnunet_nse_interval) | 450 | // f is frequency (gnunet_nse_interval) |
456 | // x is matching_bits | 451 | // x is matching_bits |
457 | // p' is current_size_estimate | 452 | // p' is current_size_estimate |
458 | return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) - | 453 | return ((double)gnunet_nse_interval.rel_value_us / (double)2.0) - |
459 | ((gnunet_nse_interval.rel_value_us / M_PI) * | 454 | ((gnunet_nse_interval.rel_value_us / M_PI) * |
460 | atan (matching_bits - current_size_estimate)); | 455 | atan(matching_bits - current_size_estimate)); |
461 | } | 456 | } |
462 | 457 | ||
463 | 458 | ||
@@ -468,21 +463,21 @@ get_matching_bits_delay (uint32_t matching_bits) | |||
468 | * @return random delay to apply | 463 | * @return random delay to apply |
469 | */ | 464 | */ |
470 | static struct GNUNET_TIME_Relative | 465 | static struct GNUNET_TIME_Relative |
471 | get_delay_randomization (uint32_t matching_bits) | 466 | get_delay_randomization(uint32_t matching_bits) |
472 | { | 467 | { |
473 | #if USE_RANDOM_DELAYS | 468 | #if USE_RANDOM_DELAYS |
474 | struct GNUNET_TIME_Relative ret; | 469 | struct GNUNET_TIME_Relative ret; |
475 | uint32_t i; | 470 | uint32_t i; |
476 | double d; | 471 | double d; |
477 | 472 | ||
478 | d = get_matching_bits_delay (matching_bits); | 473 | d = get_matching_bits_delay(matching_bits); |
479 | i = (uint32_t) (d / (double) (hop_count_max + 1)); | 474 | i = (uint32_t)(d / (double)(hop_count_max + 1)); |
480 | ret.rel_value_us = i; | 475 | ret.rel_value_us = i; |
481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 476 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
482 | "Randomizing flood using latencies up to %s\n", | 477 | "Randomizing flood using latencies up to %s\n", |
483 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 478 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); |
484 | ret.rel_value_us = | 479 | ret.rel_value_us = |
485 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1); | 480 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, i + 1); |
486 | return ret; | 481 | return ret; |
487 | #else | 482 | #else |
488 | return GNUNET_TIME_UNIT_ZERO; | 483 | return GNUNET_TIME_UNIT_ZERO; |
@@ -498,18 +493,18 @@ get_delay_randomization (uint32_t matching_bits) | |||
498 | * @param result where to write the resulting hash | 493 | * @param result where to write the resulting hash |
499 | */ | 494 | */ |
500 | static void | 495 | static void |
501 | pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) | 496 | pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result) |
502 | { | 497 | { |
503 | GNUNET_break ( | 498 | GNUNET_break( |
504 | 0 == gcry_kdf_derive (buf, | 499 | 0 == gcry_kdf_derive(buf, |
505 | buf_len, | 500 | buf_len, |
506 | GCRY_KDF_SCRYPT, | 501 | GCRY_KDF_SCRYPT, |
507 | 1 /* subalgo */, | 502 | 1 /* subalgo */, |
508 | "gnunet-proof-of-work", | 503 | "gnunet-proof-of-work", |
509 | strlen ("gnunet-proof-of-work"), | 504 | strlen("gnunet-proof-of-work"), |
510 | 2 /* iterations; keep cost of individual op small */, | 505 | 2 /* iterations; keep cost of individual op small */, |
511 | sizeof (struct GNUNET_HashCode), | 506 | sizeof(struct GNUNET_HashCode), |
512 | result)); | 507 | result)); |
513 | } | 508 | } |
514 | 509 | ||
515 | 510 | ||
@@ -521,17 +516,17 @@ pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) | |||
521 | * @return number of matching bits | 516 | * @return number of matching bits |
522 | */ | 517 | */ |
523 | static uint32_t | 518 | static uint32_t |
524 | get_matching_bits (struct GNUNET_TIME_Absolute timestamp, | 519 | get_matching_bits(struct GNUNET_TIME_Absolute timestamp, |
525 | const struct GNUNET_PeerIdentity *id) | 520 | const struct GNUNET_PeerIdentity *id) |
526 | { | 521 | { |
527 | struct GNUNET_HashCode timestamp_hash; | 522 | struct GNUNET_HashCode timestamp_hash; |
528 | struct GNUNET_HashCode pid_hash; | 523 | struct GNUNET_HashCode pid_hash; |
529 | 524 | ||
530 | GNUNET_CRYPTO_hash (×tamp.abs_value_us, | 525 | GNUNET_CRYPTO_hash(×tamp.abs_value_us, |
531 | sizeof (timestamp.abs_value_us), | 526 | sizeof(timestamp.abs_value_us), |
532 | ×tamp_hash); | 527 | ×tamp_hash); |
533 | GNUNET_CRYPTO_hash (id, sizeof (struct GNUNET_PeerIdentity), &pid_hash); | 528 | GNUNET_CRYPTO_hash(id, sizeof(struct GNUNET_PeerIdentity), &pid_hash); |
534 | return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &pid_hash); | 529 | return GNUNET_CRYPTO_hash_matching_bits(×tamp_hash, &pid_hash); |
535 | } | 530 | } |
536 | 531 | ||
537 | 532 | ||
@@ -544,7 +539,7 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp, | |||
544 | * @return delay that should be applied | 539 | * @return delay that should be applied |
545 | */ | 540 | */ |
546 | static struct GNUNET_TIME_Relative | 541 | static struct GNUNET_TIME_Relative |
547 | get_transmit_delay (int round_offset) | 542 | get_transmit_delay(int round_offset) |
548 | { | 543 | { |
549 | struct GNUNET_TIME_Relative ret; | 544 | struct GNUNET_TIME_Relative ret; |
550 | struct GNUNET_TIME_Absolute tgt; | 545 | struct GNUNET_TIME_Absolute tgt; |
@@ -552,36 +547,37 @@ get_transmit_delay (int round_offset) | |||
552 | uint32_t matching_bits; | 547 | uint32_t matching_bits; |
553 | 548 | ||
554 | switch (round_offset) | 549 | switch (round_offset) |
555 | { | 550 | { |
556 | case -1: | 551 | case -1: |
557 | /* previous round is randomized between 0 and 50 ms */ | 552 | /* previous round is randomized between 0 and 50 ms */ |
558 | #if USE_RANDOM_DELAYS | 553 | #if USE_RANDOM_DELAYS |
559 | ret.rel_value_us = | 554 | ret.rel_value_us = |
560 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50); | 555 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 50); |
561 | #else | 556 | #else |
562 | ret = GNUNET_TIME_UNIT_ZERO; | 557 | ret = GNUNET_TIME_UNIT_ZERO; |
563 | #endif | 558 | #endif |
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
565 | "Transmitting previous round behind schedule in %s\n", | 560 | "Transmitting previous round behind schedule in %s\n", |
566 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 561 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); |
567 | return ret; | 562 | return ret; |
568 | case 0: | 563 | |
569 | /* current round is based on best-known matching_bits */ | 564 | case 0: |
570 | matching_bits = | 565 | /* current round is based on best-known matching_bits */ |
571 | ntohl (size_estimate_messages[estimate_index].matching_bits); | 566 | matching_bits = |
572 | dist_delay = get_matching_bits_delay (matching_bits); | 567 | ntohl(size_estimate_messages[estimate_index].matching_bits); |
573 | dist_delay += get_delay_randomization (matching_bits).rel_value_us; | 568 | dist_delay = get_matching_bits_delay(matching_bits); |
574 | ret.rel_value_us = (uint64_t) dist_delay; | 569 | dist_delay += get_delay_randomization(matching_bits).rel_value_us; |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 570 | ret.rel_value_us = (uint64_t)dist_delay; |
576 | "For round %s, delay for %u matching bits is %s\n", | 571 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
577 | GNUNET_STRINGS_absolute_time_to_string (current_timestamp), | 572 | "For round %s, delay for %u matching bits is %s\n", |
578 | (unsigned int) matching_bits, | 573 | GNUNET_STRINGS_absolute_time_to_string(current_timestamp), |
579 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 574 | (unsigned int)matching_bits, |
580 | /* now consider round start time and add delay to it */ | 575 | GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); |
581 | tgt = GNUNET_TIME_absolute_add (current_timestamp, ret); | 576 | /* now consider round start time and add delay to it */ |
582 | return GNUNET_TIME_absolute_get_remaining (tgt); | 577 | tgt = GNUNET_TIME_absolute_add(current_timestamp, ret); |
583 | } | 578 | return GNUNET_TIME_absolute_get_remaining(tgt); |
584 | GNUNET_break (0); | 579 | } |
580 | GNUNET_break(0); | ||
585 | return GNUNET_TIME_UNIT_FOREVER_REL; | 581 | return GNUNET_TIME_UNIT_FOREVER_REL; |
586 | } | 582 | } |
587 | 583 | ||
@@ -592,7 +588,7 @@ get_transmit_delay (int round_offset) | |||
592 | * @param cls the `struct NSEPeerEntry *` | 588 | * @param cls the `struct NSEPeerEntry *` |
593 | */ | 589 | */ |
594 | static void | 590 | static void |
595 | transmit_task_cb (void *cls) | 591 | transmit_task_cb(void *cls) |
596 | { | 592 | { |
597 | struct NSEPeerEntry *peer_entry = cls; | 593 | struct NSEPeerEntry *peer_entry = cls; |
598 | unsigned int idx; | 594 | unsigned int idx; |
@@ -601,51 +597,51 @@ transmit_task_cb (void *cls) | |||
601 | peer_entry->transmit_task = NULL; | 597 | peer_entry->transmit_task = NULL; |
602 | idx = estimate_index; | 598 | idx = estimate_index; |
603 | if (GNUNET_NO == peer_entry->previous_round) | 599 | if (GNUNET_NO == peer_entry->previous_round) |
604 | { | 600 | { |
605 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; | 601 | idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; |
606 | peer_entry->previous_round = GNUNET_YES; | 602 | peer_entry->previous_round = GNUNET_YES; |
607 | peer_entry->transmit_task = | 603 | peer_entry->transmit_task = |
608 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), | 604 | GNUNET_SCHEDULER_add_delayed(get_transmit_delay(0), |
609 | &transmit_task_cb, | 605 | &transmit_task_cb, |
610 | peer_entry); | 606 | peer_entry); |
611 | } | 607 | } |
612 | if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && | 608 | if ((0 == ntohl(size_estimate_messages[idx].hop_count)) && |
613 | (NULL != proof_task)) | 609 | (NULL != proof_task)) |
614 | { | 610 | { |
615 | GNUNET_STATISTICS_update (stats, | 611 | GNUNET_STATISTICS_update(stats, |
616 | "# flood messages not generated (no proof yet)", | 612 | "# flood messages not generated (no proof yet)", |
617 | 1, | 613 | 1, |
618 | GNUNET_NO); | 614 | GNUNET_NO); |
619 | return; | 615 | return; |
620 | } | 616 | } |
621 | if (0 == ntohs (size_estimate_messages[idx].header.size)) | 617 | if (0 == ntohs(size_estimate_messages[idx].header.size)) |
622 | { | 618 | { |
623 | GNUNET_STATISTICS_update (stats, | 619 | GNUNET_STATISTICS_update(stats, |
624 | "# flood messages not generated (lack of history)", | 620 | "# flood messages not generated (lack of history)", |
625 | 1, | 621 | 1, |
626 | GNUNET_NO); | 622 | GNUNET_NO); |
627 | return; | 623 | return; |
628 | } | 624 | } |
629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 625 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
630 | "In round %s, sending to `%s' estimate with %u bits\n", | 626 | "In round %s, sending to `%s' estimate with %u bits\n", |
631 | GNUNET_STRINGS_absolute_time_to_string ( | 627 | GNUNET_STRINGS_absolute_time_to_string( |
632 | GNUNET_TIME_absolute_ntoh ( | 628 | GNUNET_TIME_absolute_ntoh( |
633 | size_estimate_messages[idx].timestamp)), | 629 | size_estimate_messages[idx].timestamp)), |
634 | GNUNET_i2s (peer_entry->id), | 630 | GNUNET_i2s(peer_entry->id), |
635 | (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); | 631 | (unsigned int)ntohl(size_estimate_messages[idx].matching_bits)); |
636 | if (0 == ntohl (size_estimate_messages[idx].hop_count)) | 632 | if (0 == ntohl(size_estimate_messages[idx].hop_count)) |
637 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); | 633 | GNUNET_STATISTICS_update(stats, "# flood messages started", 1, GNUNET_NO); |
638 | GNUNET_STATISTICS_update (stats, | 634 | GNUNET_STATISTICS_update(stats, |
639 | "# flood messages transmitted", | 635 | "# flood messages transmitted", |
640 | 1, | 636 | 1, |
641 | GNUNET_NO); | 637 | GNUNET_NO); |
642 | #if ENABLE_NSE_HISTOGRAM | 638 | #if ENABLE_NSE_HISTOGRAM |
643 | peer_entry->transmitted_messages++; | 639 | peer_entry->transmitted_messages++; |
644 | peer_entry->last_transmitted_size = | 640 | peer_entry->last_transmitted_size = |
645 | ntohl (size_estimate_messages[idx].matching_bits); | 641 | ntohl(size_estimate_messages[idx].matching_bits); |
646 | #endif | 642 | #endif |
647 | env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header); | 643 | env = GNUNET_MQ_msg_copy(&size_estimate_messages[idx].header); |
648 | GNUNET_MQ_send (peer_entry->mq, env); | 644 | GNUNET_MQ_send(peer_entry->mq, env); |
649 | } | 645 | } |
650 | 646 | ||
651 | 647 | ||
@@ -656,12 +652,12 @@ transmit_task_cb (void *cls) | |||
656 | * clients. | 652 | * clients. |
657 | */ | 653 | */ |
658 | static void | 654 | static void |
659 | update_network_size_estimate () | 655 | update_network_size_estimate() |
660 | { | 656 | { |
661 | struct GNUNET_NSE_ClientMessage em; | 657 | struct GNUNET_NSE_ClientMessage em; |
662 | 658 | ||
663 | setup_estimate_message (&em); | 659 | setup_estimate_message(&em); |
664 | GNUNET_notification_context_broadcast (nc, &em.header, GNUNET_YES); | 660 | GNUNET_notification_context_broadcast(nc, &em.header, GNUNET_YES); |
665 | } | 661 | } |
666 | 662 | ||
667 | 663 | ||
@@ -673,31 +669,31 @@ update_network_size_estimate () | |||
673 | * @param ts timestamp to use | 669 | * @param ts timestamp to use |
674 | */ | 670 | */ |
675 | static void | 671 | static void |
676 | setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts) | 672 | setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts) |
677 | { | 673 | { |
678 | struct GNUNET_NSE_FloodMessage *fm; | 674 | struct GNUNET_NSE_FloodMessage *fm; |
679 | uint32_t matching_bits; | 675 | uint32_t matching_bits; |
680 | 676 | ||
681 | matching_bits = get_matching_bits (ts, &my_identity); | 677 | matching_bits = get_matching_bits(ts, &my_identity); |
682 | fm = &size_estimate_messages[slot]; | 678 | fm = &size_estimate_messages[slot]; |
683 | fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage)); | 679 | fm->header.size = htons(sizeof(struct GNUNET_NSE_FloodMessage)); |
684 | fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); | 680 | fm->header.type = htons(GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); |
685 | fm->hop_count = htonl (0); | 681 | fm->hop_count = htonl(0); |
686 | fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); | 682 | fm->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_NSE_SEND); |
687 | fm->purpose.size = | 683 | fm->purpose.size = |
688 | htonl (sizeof (struct GNUNET_NSE_FloodMessage) - | 684 | htonl(sizeof(struct GNUNET_NSE_FloodMessage) - |
689 | sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) - | 685 | sizeof(struct GNUNET_MessageHeader) - sizeof(uint32_t) - |
690 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | 686 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)); |
691 | fm->matching_bits = htonl (matching_bits); | 687 | fm->matching_bits = htonl(matching_bits); |
692 | fm->timestamp = GNUNET_TIME_absolute_hton (ts); | 688 | fm->timestamp = GNUNET_TIME_absolute_hton(ts); |
693 | fm->origin = my_identity; | 689 | fm->origin = my_identity; |
694 | fm->proof_of_work = my_proof; | 690 | fm->proof_of_work = my_proof; |
695 | if (nse_work_required > 0) | 691 | if (nse_work_required > 0) |
696 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, | 692 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, |
697 | &fm->purpose, | 693 | &fm->purpose, |
698 | &fm->signature)); | 694 | &fm->signature)); |
699 | else | 695 | else |
700 | memset (&fm->signature, 0, sizeof (fm->signature)); | 696 | memset(&fm->signature, 0, sizeof(fm->signature)); |
701 | } | 697 | } |
702 | 698 | ||
703 | 699 | ||
@@ -711,34 +707,34 @@ setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts) | |||
711 | * @return #GNUNET_OK (continue to iterate) | 707 | * @return #GNUNET_OK (continue to iterate) |
712 | */ | 708 | */ |
713 | static int | 709 | static int |
714 | schedule_current_round (void *cls, | 710 | schedule_current_round(void *cls, |
715 | const struct GNUNET_PeerIdentity *key, | 711 | const struct GNUNET_PeerIdentity *key, |
716 | void *value) | 712 | void *value) |
717 | { | 713 | { |
718 | struct NSEPeerEntry *peer_entry = value; | 714 | struct NSEPeerEntry *peer_entry = value; |
719 | struct GNUNET_TIME_Relative delay; | 715 | struct GNUNET_TIME_Relative delay; |
720 | 716 | ||
721 | (void) cls; | 717 | (void)cls; |
722 | (void) key; | 718 | (void)key; |
723 | if (NULL != peer_entry->transmit_task) | 719 | if (NULL != peer_entry->transmit_task) |
724 | { | 720 | { |
725 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 721 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); |
726 | peer_entry->previous_round = GNUNET_NO; | 722 | peer_entry->previous_round = GNUNET_NO; |
727 | } | 723 | } |
728 | #if ENABLE_NSE_HISTOGRAM | 724 | #if ENABLE_NSE_HISTOGRAM |
729 | if (peer_entry->received_messages > 1) | 725 | if (peer_entry->received_messages > 1) |
730 | GNUNET_STATISTICS_update (stats, | 726 | GNUNET_STATISTICS_update(stats, |
731 | "# extra messages", | 727 | "# extra messages", |
732 | peer_entry->received_messages - 1, | 728 | peer_entry->received_messages - 1, |
733 | GNUNET_NO); | 729 | GNUNET_NO); |
734 | peer_entry->transmitted_messages = 0; | 730 | peer_entry->transmitted_messages = 0; |
735 | peer_entry->last_transmitted_size = 0; | 731 | peer_entry->last_transmitted_size = 0; |
736 | peer_entry->received_messages = 0; | 732 | peer_entry->received_messages = 0; |
737 | #endif | 733 | #endif |
738 | delay = | 734 | delay = |
739 | get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); | 735 | get_transmit_delay((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); |
740 | peer_entry->transmit_task = | 736 | peer_entry->transmit_task = |
741 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry); | 737 | GNUNET_SCHEDULER_add_delayed(delay, &transmit_task_cb, peer_entry); |
742 | return GNUNET_OK; | 738 | return GNUNET_OK; |
743 | } | 739 | } |
744 | 740 | ||
@@ -749,46 +745,46 @@ schedule_current_round (void *cls, | |||
749 | * @param cls unused | 745 | * @param cls unused |
750 | */ | 746 | */ |
751 | static void | 747 | static void |
752 | update_flood_message (void *cls) | 748 | update_flood_message(void *cls) |
753 | { | 749 | { |
754 | struct GNUNET_TIME_Relative offset; | 750 | struct GNUNET_TIME_Relative offset; |
755 | 751 | ||
756 | (void) cls; | 752 | (void)cls; |
757 | flood_task = NULL; | 753 | flood_task = NULL; |
758 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); | 754 | offset = GNUNET_TIME_absolute_get_remaining(next_timestamp); |
759 | if (0 != offset.rel_value_us) | 755 | if (0 != offset.rel_value_us) |
760 | { | 756 | { |
761 | /* somehow run early, delay more */ | 757 | /* somehow run early, delay more */ |
762 | flood_task = | 758 | flood_task = |
763 | GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL); | 759 | GNUNET_SCHEDULER_add_delayed(offset, &update_flood_message, NULL); |
764 | return; | 760 | return; |
765 | } | 761 | } |
766 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; | 762 | estimate_index = (estimate_index + 1) % HISTORY_SIZE; |
767 | if (estimate_count < HISTORY_SIZE) | 763 | if (estimate_count < HISTORY_SIZE) |
768 | estimate_count++; | 764 | estimate_count++; |
769 | current_timestamp = next_timestamp; | 765 | current_timestamp = next_timestamp; |
770 | next_timestamp = | 766 | next_timestamp = |
771 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 767 | GNUNET_TIME_absolute_add(current_timestamp, gnunet_nse_interval); |
772 | if ((current_timestamp.abs_value_us == | 768 | if ((current_timestamp.abs_value_us == |
773 | GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && | 769 | GNUNET_TIME_absolute_ntoh(next_message.timestamp).abs_value_us) && |
774 | (get_matching_bits (current_timestamp, &my_identity) < | 770 | (get_matching_bits(current_timestamp, &my_identity) < |
775 | ntohl (next_message.matching_bits))) | 771 | ntohl(next_message.matching_bits))) |
776 | { | 772 | { |
777 | /* we received a message for this round way early, use it! */ | 773 | /* we received a message for this round way early, use it! */ |
778 | size_estimate_messages[estimate_index] = next_message; | 774 | size_estimate_messages[estimate_index] = next_message; |
779 | size_estimate_messages[estimate_index].hop_count = | 775 | size_estimate_messages[estimate_index].hop_count = |
780 | htonl (1 + ntohl (next_message.hop_count)); | 776 | htonl(1 + ntohl(next_message.hop_count)); |
781 | } | 777 | } |
782 | else | 778 | else |
783 | setup_flood_message (estimate_index, current_timestamp); | 779 | setup_flood_message(estimate_index, current_timestamp); |
784 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ | 780 | next_message.matching_bits = htonl(0); /* reset for 'next' round */ |
785 | hop_count_max = 0; | 781 | hop_count_max = 0; |
786 | for (unsigned int i = 0; i < HISTORY_SIZE; i++) | 782 | for (unsigned int i = 0; i < HISTORY_SIZE; i++) |
787 | hop_count_max = | 783 | hop_count_max = |
788 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); | 784 | GNUNET_MAX(ntohl(size_estimate_messages[i].hop_count), hop_count_max); |
789 | GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL); | 785 | GNUNET_CONTAINER_multipeermap_iterate(peers, &schedule_current_round, NULL); |
790 | flood_task = | 786 | flood_task = |
791 | GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL); | 787 | GNUNET_SCHEDULER_add_at(next_timestamp, &update_flood_message, NULL); |
792 | } | 788 | } |
793 | 789 | ||
794 | 790 | ||
@@ -799,12 +795,12 @@ update_flood_message (void *cls) | |||
799 | * @return the number of leading zero bits. | 795 | * @return the number of leading zero bits. |
800 | */ | 796 | */ |
801 | static unsigned int | 797 | static unsigned int |
802 | count_leading_zeroes (const struct GNUNET_HashCode *hash) | 798 | count_leading_zeroes(const struct GNUNET_HashCode *hash) |
803 | { | 799 | { |
804 | unsigned int hash_count; | 800 | unsigned int hash_count; |
805 | 801 | ||
806 | hash_count = 0; | 802 | hash_count = 0; |
807 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 803 | while (0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count)) |
808 | hash_count++; | 804 | hash_count++; |
809 | return hash_count; | 805 | return hash_count; |
810 | } | 806 | } |
@@ -819,20 +815,20 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
819 | * @return #GNUNET_YES if valid, #GNUNET_NO if not | 815 | * @return #GNUNET_YES if valid, #GNUNET_NO if not |
820 | */ | 816 | */ |
821 | static int | 817 | static int |
822 | check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | 818 | check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, |
823 | uint64_t val) | 819 | uint64_t val) |
824 | { | 820 | { |
825 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 821 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + |
826 | sizeof (val)] GNUNET_ALIGN; | 822 | sizeof(val)] GNUNET_ALIGN; |
827 | struct GNUNET_HashCode result; | 823 | struct GNUNET_HashCode result; |
828 | 824 | ||
829 | GNUNET_memcpy (buf, &val, sizeof (val)); | 825 | GNUNET_memcpy(buf, &val, sizeof(val)); |
830 | GNUNET_memcpy (&buf[sizeof (val)], | 826 | GNUNET_memcpy(&buf[sizeof(val)], |
831 | pkey, | 827 | pkey, |
832 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 828 | sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); |
833 | pow_hash (buf, sizeof (buf), &result); | 829 | pow_hash(buf, sizeof(buf), &result); |
834 | return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES | 830 | return (count_leading_zeroes(&result) >= nse_work_required) ? GNUNET_YES |
835 | : GNUNET_NO; | 831 | : GNUNET_NO; |
836 | } | 832 | } |
837 | 833 | ||
838 | 834 | ||
@@ -840,20 +836,20 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | |||
840 | * Write our current proof to disk. | 836 | * Write our current proof to disk. |
841 | */ | 837 | */ |
842 | static void | 838 | static void |
843 | write_proof () | 839 | write_proof() |
844 | { | 840 | { |
845 | char *proof; | 841 | char *proof; |
846 | 842 | ||
847 | if (GNUNET_OK != | 843 | if (GNUNET_OK != |
848 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 844 | GNUNET_CONFIGURATION_get_value_filename(cfg, "NSE", "PROOFFILE", &proof)) |
849 | return; | 845 | return; |
850 | if (sizeof (my_proof) != GNUNET_DISK_fn_write (proof, | 846 | if (sizeof(my_proof) != GNUNET_DISK_fn_write(proof, |
851 | &my_proof, | 847 | &my_proof, |
852 | sizeof (my_proof), | 848 | sizeof(my_proof), |
853 | GNUNET_DISK_PERM_USER_READ | | 849 | GNUNET_DISK_PERM_USER_READ | |
854 | GNUNET_DISK_PERM_USER_WRITE)) | 850 | GNUNET_DISK_PERM_USER_WRITE)) |
855 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); | 851 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", proof); |
856 | GNUNET_free (proof); | 852 | GNUNET_free(proof); |
857 | } | 853 | } |
858 | 854 | ||
859 | 855 | ||
@@ -863,57 +859,57 @@ write_proof () | |||
863 | * @param cls closure (unused) | 859 | * @param cls closure (unused) |
864 | */ | 860 | */ |
865 | static void | 861 | static void |
866 | find_proof (void *cls) | 862 | find_proof(void *cls) |
867 | { | 863 | { |
868 | #define ROUND_SIZE 10 | 864 | #define ROUND_SIZE 10 |
869 | uint64_t counter; | 865 | uint64_t counter; |
870 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 866 | char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + |
871 | sizeof (uint64_t)] GNUNET_ALIGN; | 867 | sizeof(uint64_t)] GNUNET_ALIGN; |
872 | struct GNUNET_HashCode result; | 868 | struct GNUNET_HashCode result; |
873 | unsigned int i; | 869 | unsigned int i; |
874 | 870 | ||
875 | (void) cls; | 871 | (void)cls; |
876 | proof_task = NULL; | 872 | proof_task = NULL; |
877 | GNUNET_memcpy (&buf[sizeof (uint64_t)], | 873 | GNUNET_memcpy(&buf[sizeof(uint64_t)], |
878 | &my_identity, | 874 | &my_identity, |
879 | sizeof (struct GNUNET_PeerIdentity)); | 875 | sizeof(struct GNUNET_PeerIdentity)); |
880 | i = 0; | 876 | i = 0; |
881 | counter = my_proof; | 877 | counter = my_proof; |
882 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) | 878 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) |
883 | { | ||
884 | GNUNET_memcpy (buf, &counter, sizeof (uint64_t)); | ||
885 | pow_hash (buf, sizeof (buf), &result); | ||
886 | if (nse_work_required <= count_leading_zeroes (&result)) | ||
887 | { | 879 | { |
888 | my_proof = counter; | 880 | GNUNET_memcpy(buf, &counter, sizeof(uint64_t)); |
889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 881 | pow_hash(buf, sizeof(buf), &result); |
890 | "Proof of work found: %llu!\n", | 882 | if (nse_work_required <= count_leading_zeroes(&result)) |
891 | (unsigned long long) GNUNET_ntohll (counter)); | 883 | { |
892 | write_proof (); | 884 | my_proof = counter; |
893 | setup_flood_message (estimate_index, current_timestamp); | 885 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
894 | return; | 886 | "Proof of work found: %llu!\n", |
887 | (unsigned long long)GNUNET_ntohll(counter)); | ||
888 | write_proof(); | ||
889 | setup_flood_message(estimate_index, current_timestamp); | ||
890 | return; | ||
891 | } | ||
892 | counter++; | ||
893 | i++; | ||
895 | } | 894 | } |
896 | counter++; | ||
897 | i++; | ||
898 | } | ||
899 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | 895 | if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) |
900 | { | 896 | { |
901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 897 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
902 | "Testing proofs currently at %llu\n", | 898 | "Testing proofs currently at %llu\n", |
903 | (unsigned long long) counter); | 899 | (unsigned long long)counter); |
904 | /* remember progress every 100 rounds */ | 900 | /* remember progress every 100 rounds */ |
905 | my_proof = counter; | 901 | my_proof = counter; |
906 | write_proof (); | 902 | write_proof(); |
907 | } | 903 | } |
908 | else | 904 | else |
909 | { | 905 | { |
910 | my_proof = counter; | 906 | my_proof = counter; |
911 | } | 907 | } |
912 | proof_task = | 908 | proof_task = |
913 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, | 909 | GNUNET_SCHEDULER_add_delayed_with_priority(proof_find_delay, |
914 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 910 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
915 | &find_proof, | 911 | &find_proof, |
916 | NULL); | 912 | NULL); |
917 | } | 913 | } |
918 | 914 | ||
919 | 915 | ||
@@ -927,28 +923,28 @@ find_proof (void *cls) | |||
927 | * #GNUNET_NO if the key/signature don't verify | 923 | * #GNUNET_NO if the key/signature don't verify |
928 | */ | 924 | */ |
929 | static int | 925 | static int |
930 | verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) | 926 | verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood) |
931 | { | 927 | { |
932 | if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key, | 928 | if (GNUNET_YES != check_proof_of_work(&incoming_flood->origin.public_key, |
933 | incoming_flood->proof_of_work)) | 929 | incoming_flood->proof_of_work)) |
934 | { | 930 | { |
935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 931 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
936 | "Proof of work invalid: %llu!\n", | 932 | "Proof of work invalid: %llu!\n", |
937 | (unsigned long long) GNUNET_ntohll ( | 933 | (unsigned long long)GNUNET_ntohll( |
938 | incoming_flood->proof_of_work)); | 934 | incoming_flood->proof_of_work)); |
939 | GNUNET_break_op (0); | 935 | GNUNET_break_op(0); |
940 | return GNUNET_NO; | 936 | return GNUNET_NO; |
941 | } | 937 | } |
942 | if ((nse_work_required > 0) && | 938 | if ((nse_work_required > 0) && |
943 | (GNUNET_OK != | 939 | (GNUNET_OK != |
944 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND, | 940 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_NSE_SEND, |
945 | &incoming_flood->purpose, | 941 | &incoming_flood->purpose, |
946 | &incoming_flood->signature, | 942 | &incoming_flood->signature, |
947 | &incoming_flood->origin.public_key))) | 943 | &incoming_flood->origin.public_key))) |
948 | { | 944 | { |
949 | GNUNET_break_op (0); | 945 | GNUNET_break_op(0); |
950 | return GNUNET_NO; | 946 | return GNUNET_NO; |
951 | } | 947 | } |
952 | return GNUNET_YES; | 948 | return GNUNET_YES; |
953 | } | 949 | } |
954 | 950 | ||
@@ -963,35 +959,35 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) | |||
963 | * @return #GNUNET_OK (continue to iterate) | 959 | * @return #GNUNET_OK (continue to iterate) |
964 | */ | 960 | */ |
965 | static int | 961 | static int |
966 | update_flood_times (void *cls, | 962 | update_flood_times(void *cls, |
967 | const struct GNUNET_PeerIdentity *key, | 963 | const struct GNUNET_PeerIdentity *key, |
968 | void *value) | 964 | void *value) |
969 | { | 965 | { |
970 | struct NSEPeerEntry *exclude = cls; | 966 | struct NSEPeerEntry *exclude = cls; |
971 | struct NSEPeerEntry *peer_entry = value; | 967 | struct NSEPeerEntry *peer_entry = value; |
972 | struct GNUNET_TIME_Relative delay; | 968 | struct GNUNET_TIME_Relative delay; |
973 | 969 | ||
974 | (void) key; | 970 | (void)key; |
975 | if (peer_entry == exclude) | 971 | if (peer_entry == exclude) |
976 | return GNUNET_OK; /* trigger of the update */ | 972 | return GNUNET_OK; /* trigger of the update */ |
977 | if (GNUNET_NO == peer_entry->previous_round) | 973 | if (GNUNET_NO == peer_entry->previous_round) |
978 | { | ||
979 | /* still stuck in previous round, no point to update, check that | ||
980 | * we are active here though... */ | ||
981 | if (NULL == peer_entry->transmit_task) | ||
982 | { | 974 | { |
983 | GNUNET_break (0); | 975 | /* still stuck in previous round, no point to update, check that |
976 | * we are active here though... */ | ||
977 | if (NULL == peer_entry->transmit_task) | ||
978 | { | ||
979 | GNUNET_break(0); | ||
980 | } | ||
981 | return GNUNET_OK; | ||
984 | } | 982 | } |
985 | return GNUNET_OK; | ||
986 | } | ||
987 | if (NULL != peer_entry->transmit_task) | 983 | if (NULL != peer_entry->transmit_task) |
988 | { | 984 | { |
989 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 985 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); |
990 | peer_entry->transmit_task = NULL; | 986 | peer_entry->transmit_task = NULL; |
991 | } | 987 | } |
992 | delay = get_transmit_delay (0); | 988 | delay = get_transmit_delay(0); |
993 | peer_entry->transmit_task = | 989 | peer_entry->transmit_task = |
994 | GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry); | 990 | GNUNET_SCHEDULER_add_delayed(delay, &transmit_task_cb, peer_entry); |
995 | return GNUNET_OK; | 991 | return GNUNET_OK; |
996 | } | 992 | } |
997 | 993 | ||
@@ -1003,8 +999,8 @@ update_flood_times (void *cls, | |||
1003 | * @param incoming_flood received message | 999 | * @param incoming_flood received message |
1004 | */ | 1000 | */ |
1005 | static void | 1001 | static void |
1006 | handle_p2p_estimate (void *cls, | 1002 | handle_p2p_estimate(void *cls, |
1007 | const struct GNUNET_NSE_FloodMessage *incoming_flood) | 1003 | const struct GNUNET_NSE_FloodMessage *incoming_flood) |
1008 | { | 1004 | { |
1009 | struct NSEPeerEntry *peer_entry = cls; | 1005 | struct NSEPeerEntry *peer_entry = cls; |
1010 | struct GNUNET_TIME_Absolute ts; | 1006 | struct GNUNET_TIME_Absolute ts; |
@@ -1015,34 +1011,34 @@ handle_p2p_estimate (void *cls, | |||
1015 | { | 1011 | { |
1016 | uint64_t t; | 1012 | uint64_t t; |
1017 | 1013 | ||
1018 | t = GNUNET_TIME_absolute_get ().abs_value_us; | 1014 | t = GNUNET_TIME_absolute_get().abs_value_us; |
1019 | if (NULL != lh) | 1015 | if (NULL != lh) |
1020 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t)); | 1016 | GNUNET_TESTBED_LOGGER_write(lh, &t, sizeof(uint64_t)); |
1021 | if (NULL != histogram) | 1017 | if (NULL != histogram) |
1022 | GNUNET_BIO_write_int64 (histogram, t); | 1018 | GNUNET_BIO_write_int64(histogram, t); |
1023 | } | 1019 | } |
1024 | #endif | 1020 | #endif |
1025 | GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO); | 1021 | GNUNET_STATISTICS_update(stats, "# flood messages received", 1, GNUNET_NO); |
1026 | matching_bits = ntohl (incoming_flood->matching_bits); | 1022 | matching_bits = ntohl(incoming_flood->matching_bits); |
1027 | #if DEBUG_NSE | 1023 | #if DEBUG_NSE |
1028 | { | 1024 | { |
1029 | char origin[5]; | 1025 | char origin[5]; |
1030 | char pred[5]; | 1026 | char pred[5]; |
1031 | struct GNUNET_PeerIdentity os; | 1027 | struct GNUNET_PeerIdentity os; |
1032 | 1028 | ||
1033 | GNUNET_snprintf (origin, | 1029 | GNUNET_snprintf(origin, |
1034 | sizeof (origin), | 1030 | sizeof(origin), |
1035 | "%s", | 1031 | "%s", |
1036 | GNUNET_i2s (&incoming_flood->origin)); | 1032 | GNUNET_i2s(&incoming_flood->origin)); |
1037 | GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer_entry->id)); | 1033 | GNUNET_snprintf(pred, sizeof(pred), "%s", GNUNET_i2s(peer_entry->id)); |
1038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1034 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1039 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", | 1035 | "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", |
1040 | GNUNET_STRINGS_absolute_time_to_string ( | 1036 | GNUNET_STRINGS_absolute_time_to_string( |
1041 | GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)), | 1037 | GNUNET_TIME_absolute_ntoh(incoming_flood->timestamp)), |
1042 | origin, | 1038 | origin, |
1043 | pred, | 1039 | pred, |
1044 | GNUNET_i2s (&my_identity), | 1040 | GNUNET_i2s(&my_identity), |
1045 | (unsigned int) matching_bits); | 1041 | (unsigned int)matching_bits); |
1046 | } | 1042 | } |
1047 | #endif | 1043 | #endif |
1048 | 1044 | ||
@@ -1050,122 +1046,122 @@ handle_p2p_estimate (void *cls, | |||
1050 | peer_entry->received_messages++; | 1046 | peer_entry->received_messages++; |
1051 | if (peer_entry->transmitted_messages > 0 && | 1047 | if (peer_entry->transmitted_messages > 0 && |
1052 | peer_entry->last_transmitted_size >= matching_bits) | 1048 | peer_entry->last_transmitted_size >= matching_bits) |
1053 | GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO); | 1049 | GNUNET_STATISTICS_update(stats, "# cross messages", 1, GNUNET_NO); |
1054 | #endif | 1050 | #endif |
1055 | 1051 | ||
1056 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); | 1052 | ts = GNUNET_TIME_absolute_ntoh(incoming_flood->timestamp); |
1057 | if (ts.abs_value_us == current_timestamp.abs_value_us) | 1053 | if (ts.abs_value_us == current_timestamp.abs_value_us) |
1058 | idx = estimate_index; | 1054 | idx = estimate_index; |
1059 | else if (ts.abs_value_us == | 1055 | else if (ts.abs_value_us == |
1060 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us) | 1056 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us) |
1061 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1057 | idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1062 | else if (ts.abs_value_us == next_timestamp.abs_value_us) | 1058 | else if (ts.abs_value_us == next_timestamp.abs_value_us) |
1063 | { | ||
1064 | if (matching_bits <= ntohl (next_message.matching_bits)) | ||
1065 | return; /* ignore, simply too early/late */ | ||
1066 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | ||
1067 | { | 1059 | { |
1068 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1060 | if (matching_bits <= ntohl(next_message.matching_bits)) |
1069 | "Peer %s is likely ill-configured!\n", | 1061 | return; /* ignore, simply too early/late */ |
1070 | GNUNET_i2s (peer_entry->id)); | 1062 | if (GNUNET_YES != verify_message_crypto(incoming_flood)) |
1071 | GNUNET_break_op (0); | 1063 | { |
1064 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1065 | "Peer %s is likely ill-configured!\n", | ||
1066 | GNUNET_i2s(peer_entry->id)); | ||
1067 | GNUNET_break_op(0); | ||
1068 | return; | ||
1069 | } | ||
1070 | next_message = *incoming_flood; | ||
1072 | return; | 1071 | return; |
1073 | } | 1072 | } |
1074 | next_message = *incoming_flood; | ||
1075 | return; | ||
1076 | } | ||
1077 | else | 1073 | else |
1078 | { | ||
1079 | GNUNET_STATISTICS_update (stats, | ||
1080 | "# flood messages discarded (clock skew too large)", | ||
1081 | 1, | ||
1082 | GNUNET_NO); | ||
1083 | return; | ||
1084 | } | ||
1085 | if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity))) | ||
1086 | { | ||
1087 | /* send to self, update our own estimate IF this also comes from us! */ | ||
1088 | if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity)) | ||
1089 | update_network_size_estimate (); | ||
1090 | return; | ||
1091 | } | ||
1092 | if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) | ||
1093 | { | ||
1094 | /* Cancel transmission in the other direction, as this peer clearly has | ||
1095 | up-to-date information already. Even if we didn't talk to this peer in | ||
1096 | the previous round, we should no longer send it stale information as it | ||
1097 | told us about the current round! */ | ||
1098 | peer_entry->previous_round = GNUNET_YES; | ||
1099 | if (idx != estimate_index) | ||
1100 | { | 1074 | { |
1101 | /* do not transmit information for the previous round to this peer | 1075 | GNUNET_STATISTICS_update(stats, |
1102 | anymore (but allow current round) */ | 1076 | "# flood messages discarded (clock skew too large)", |
1077 | 1, | ||
1078 | GNUNET_NO); | ||
1103 | return; | 1079 | return; |
1104 | } | 1080 | } |
1105 | /* got up-to-date information for current round, cancel transmission to | 1081 | if (0 == (GNUNET_memcmp(peer_entry->id, &my_identity))) |
1106 | * this peer altogether */ | ||
1107 | if (NULL != peer_entry->transmit_task) | ||
1108 | { | 1082 | { |
1109 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1083 | /* send to self, update our own estimate IF this also comes from us! */ |
1110 | peer_entry->transmit_task = NULL; | 1084 | if (0 == GNUNET_memcmp(&incoming_flood->origin, &my_identity)) |
1085 | update_network_size_estimate(); | ||
1086 | return; | ||
1111 | } | 1087 | } |
1112 | return; | 1088 | if (matching_bits == ntohl(size_estimate_messages[idx].matching_bits)) |
1113 | } | ||
1114 | if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) | ||
1115 | { | ||
1116 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) | ||
1117 | { | 1089 | { |
1118 | peer_entry->previous_round = GNUNET_NO; | 1090 | /* Cancel transmission in the other direction, as this peer clearly has |
1091 | up-to-date information already. Even if we didn't talk to this peer in | ||
1092 | the previous round, we should no longer send it stale information as it | ||
1093 | told us about the current round! */ | ||
1094 | peer_entry->previous_round = GNUNET_YES; | ||
1095 | if (idx != estimate_index) | ||
1096 | { | ||
1097 | /* do not transmit information for the previous round to this peer | ||
1098 | anymore (but allow current round) */ | ||
1099 | return; | ||
1100 | } | ||
1101 | /* got up-to-date information for current round, cancel transmission to | ||
1102 | * this peer altogether */ | ||
1103 | if (NULL != peer_entry->transmit_task) | ||
1104 | { | ||
1105 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | ||
1106 | peer_entry->transmit_task = NULL; | ||
1107 | } | ||
1108 | return; | ||
1119 | } | 1109 | } |
1120 | /* push back our result now, that peer is spreading bad information... */ | 1110 | if (matching_bits < ntohl(size_estimate_messages[idx].matching_bits)) |
1121 | if (NULL != peer_entry->transmit_task) | 1111 | { |
1122 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1112 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) |
1123 | peer_entry->transmit_task = | 1113 | { |
1124 | GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry); | 1114 | peer_entry->previous_round = GNUNET_NO; |
1125 | /* Not closer than our most recent message, no need to do work here */ | 1115 | } |
1126 | GNUNET_STATISTICS_update (stats, | 1116 | /* push back our result now, that peer is spreading bad information... */ |
1127 | "# flood messages ignored (had closer already)", | 1117 | if (NULL != peer_entry->transmit_task) |
1128 | 1, | 1118 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); |
1129 | GNUNET_NO); | 1119 | peer_entry->transmit_task = |
1130 | return; | 1120 | GNUNET_SCHEDULER_add_now(&transmit_task_cb, peer_entry); |
1131 | } | 1121 | /* Not closer than our most recent message, no need to do work here */ |
1132 | if (GNUNET_YES != verify_message_crypto (incoming_flood)) | 1122 | GNUNET_STATISTICS_update(stats, |
1133 | { | 1123 | "# flood messages ignored (had closer already)", |
1134 | GNUNET_break_op (0); | 1124 | 1, |
1135 | return; | 1125 | GNUNET_NO); |
1136 | } | 1126 | return; |
1137 | GNUNET_assert (matching_bits > | 1127 | } |
1138 | ntohl (size_estimate_messages[idx].matching_bits)); | 1128 | if (GNUNET_YES != verify_message_crypto(incoming_flood)) |
1129 | { | ||
1130 | GNUNET_break_op(0); | ||
1131 | return; | ||
1132 | } | ||
1133 | GNUNET_assert(matching_bits > | ||
1134 | ntohl(size_estimate_messages[idx].matching_bits)); | ||
1139 | /* Cancel transmission in the other direction, as this peer clearly has | 1135 | /* Cancel transmission in the other direction, as this peer clearly has |
1140 | * up-to-date information already. | 1136 | * up-to-date information already. |
1141 | */ | 1137 | */ |
1142 | peer_entry->previous_round = GNUNET_YES; | 1138 | peer_entry->previous_round = GNUNET_YES; |
1143 | if (idx == estimate_index) | 1139 | if (idx == estimate_index) |
1144 | { | ||
1145 | /* cancel any activity for current round */ | ||
1146 | if (NULL != peer_entry->transmit_task) | ||
1147 | { | 1140 | { |
1148 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1141 | /* cancel any activity for current round */ |
1149 | peer_entry->transmit_task = NULL; | 1142 | if (NULL != peer_entry->transmit_task) |
1143 | { | ||
1144 | GNUNET_SCHEDULER_cancel(peer_entry->transmit_task); | ||
1145 | peer_entry->transmit_task = NULL; | ||
1146 | } | ||
1150 | } | 1147 | } |
1151 | } | ||
1152 | size_estimate_messages[idx] = *incoming_flood; | 1148 | size_estimate_messages[idx] = *incoming_flood; |
1153 | size_estimate_messages[idx].hop_count = | 1149 | size_estimate_messages[idx].hop_count = |
1154 | htonl (ntohl (incoming_flood->hop_count) + 1); | 1150 | htonl(ntohl(incoming_flood->hop_count) + 1); |
1155 | hop_count_max = | 1151 | hop_count_max = |
1156 | GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max); | 1152 | GNUNET_MAX(ntohl(incoming_flood->hop_count) + 1, hop_count_max); |
1157 | GNUNET_STATISTICS_set (stats, | 1153 | GNUNET_STATISTICS_set(stats, |
1158 | "# estimated network diameter", | 1154 | "# estimated network diameter", |
1159 | hop_count_max, | 1155 | hop_count_max, |
1160 | GNUNET_NO); | 1156 | GNUNET_NO); |
1161 | 1157 | ||
1162 | /* have a new, better size estimate, inform clients */ | 1158 | /* have a new, better size estimate, inform clients */ |
1163 | update_network_size_estimate (); | 1159 | update_network_size_estimate(); |
1164 | 1160 | ||
1165 | /* flood to rest */ | 1161 | /* flood to rest */ |
1166 | GNUNET_CONTAINER_multipeermap_iterate (peers, | 1162 | GNUNET_CONTAINER_multipeermap_iterate(peers, |
1167 | &update_flood_times, | 1163 | &update_flood_times, |
1168 | peer_entry); | 1164 | peer_entry); |
1169 | } | 1165 | } |
1170 | 1166 | ||
1171 | 1167 | ||
@@ -1177,33 +1173,33 @@ handle_p2p_estimate (void *cls, | |||
1177 | * @param peer peer identity this notification is about | 1173 | * @param peer peer identity this notification is about |
1178 | */ | 1174 | */ |
1179 | static void * | 1175 | static void * |
1180 | handle_core_connect (void *cls, | 1176 | handle_core_connect(void *cls, |
1181 | const struct GNUNET_PeerIdentity *peer, | 1177 | const struct GNUNET_PeerIdentity *peer, |
1182 | struct GNUNET_MQ_Handle *mq) | 1178 | struct GNUNET_MQ_Handle *mq) |
1183 | { | 1179 | { |
1184 | struct NSEPeerEntry *peer_entry; | 1180 | struct NSEPeerEntry *peer_entry; |
1185 | 1181 | ||
1186 | (void) cls; | 1182 | (void)cls; |
1187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1183 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1188 | "Peer `%s' connected to us\n", | 1184 | "Peer `%s' connected to us\n", |
1189 | GNUNET_i2s (peer)); | 1185 | GNUNET_i2s(peer)); |
1190 | /* set our default transmission options */ | 1186 | /* set our default transmission options */ |
1191 | GNUNET_MQ_set_options (mq, NSE_PRIORITY); | 1187 | GNUNET_MQ_set_options(mq, NSE_PRIORITY); |
1192 | /* create our peer entry for this peer */ | 1188 | /* create our peer entry for this peer */ |
1193 | peer_entry = GNUNET_new (struct NSEPeerEntry); | 1189 | peer_entry = GNUNET_new(struct NSEPeerEntry); |
1194 | peer_entry->id = peer; | 1190 | peer_entry->id = peer; |
1195 | peer_entry->mq = mq; | 1191 | peer_entry->mq = mq; |
1196 | GNUNET_assert (GNUNET_OK == | 1192 | GNUNET_assert(GNUNET_OK == |
1197 | GNUNET_CONTAINER_multipeermap_put ( | 1193 | GNUNET_CONTAINER_multipeermap_put( |
1198 | peers, | 1194 | peers, |
1199 | peer_entry->id, | 1195 | peer_entry->id, |
1200 | peer_entry, | 1196 | peer_entry, |
1201 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1197 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1202 | peer_entry->transmit_task = | 1198 | peer_entry->transmit_task = |
1203 | GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), | 1199 | GNUNET_SCHEDULER_add_delayed(get_transmit_delay(-1), |
1204 | &transmit_task_cb, | 1200 | &transmit_task_cb, |
1205 | peer_entry); | 1201 | peer_entry); |
1206 | GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO); | 1202 | GNUNET_STATISTICS_update(stats, "# peers connected", 1, GNUNET_NO); |
1207 | return peer_entry; | 1203 | return peer_entry; |
1208 | } | 1204 | } |
1209 | 1205 | ||
@@ -1217,25 +1213,25 @@ handle_core_connect (void *cls, | |||
1217 | * @parma internal_cls the `struct NSEPeerEntry` for the @a peer | 1213 | * @parma internal_cls the `struct NSEPeerEntry` for the @a peer |
1218 | */ | 1214 | */ |
1219 | static void | 1215 | static void |
1220 | handle_core_disconnect (void *cls, | 1216 | handle_core_disconnect(void *cls, |
1221 | const struct GNUNET_PeerIdentity *peer, | 1217 | const struct GNUNET_PeerIdentity *peer, |
1222 | void *internal_cls) | 1218 | void *internal_cls) |
1223 | { | 1219 | { |
1224 | struct NSEPeerEntry *pos = internal_cls; | 1220 | struct NSEPeerEntry *pos = internal_cls; |
1225 | 1221 | ||
1226 | (void) cls; | 1222 | (void)cls; |
1227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1228 | "Peer `%s' disconnected from us\n", | 1224 | "Peer `%s' disconnected from us\n", |
1229 | GNUNET_i2s (peer)); | 1225 | GNUNET_i2s(peer)); |
1230 | GNUNET_assert (GNUNET_YES == | 1226 | GNUNET_assert(GNUNET_YES == |
1231 | GNUNET_CONTAINER_multipeermap_remove (peers, peer, pos)); | 1227 | GNUNET_CONTAINER_multipeermap_remove(peers, peer, pos)); |
1232 | if (NULL != pos->transmit_task) | 1228 | if (NULL != pos->transmit_task) |
1233 | { | 1229 | { |
1234 | GNUNET_SCHEDULER_cancel (pos->transmit_task); | 1230 | GNUNET_SCHEDULER_cancel(pos->transmit_task); |
1235 | pos->transmit_task = NULL; | 1231 | pos->transmit_task = NULL; |
1236 | } | 1232 | } |
1237 | GNUNET_free (pos); | 1233 | GNUNET_free(pos); |
1238 | GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO); | 1234 | GNUNET_STATISTICS_update(stats, "# peers connected", -1, GNUNET_NO); |
1239 | } | 1235 | } |
1240 | 1236 | ||
1241 | 1237 | ||
@@ -1248,11 +1244,11 @@ handle_core_disconnect (void *cls, | |||
1248 | * @param size the amount of data sent (ignored) | 1244 | * @param size the amount of data sent (ignored) |
1249 | */ | 1245 | */ |
1250 | static void | 1246 | static void |
1251 | flush_comp_cb (void *cls, size_t size) | 1247 | flush_comp_cb(void *cls, size_t size) |
1252 | { | 1248 | { |
1253 | (void) cls; | 1249 | (void)cls; |
1254 | (void) size; | 1250 | (void)size; |
1255 | GNUNET_TESTBED_LOGGER_disconnect (lh); | 1251 | GNUNET_TESTBED_LOGGER_disconnect(lh); |
1256 | lh = NULL; | 1252 | lh = NULL; |
1257 | } | 1253 | } |
1258 | #endif | 1254 | #endif |
@@ -1264,60 +1260,60 @@ flush_comp_cb (void *cls, size_t size) | |||
1264 | * @param cls unused | 1260 | * @param cls unused |
1265 | */ | 1261 | */ |
1266 | static void | 1262 | static void |
1267 | shutdown_task (void *cls) | 1263 | shutdown_task(void *cls) |
1268 | { | 1264 | { |
1269 | (void) cls; | 1265 | (void)cls; |
1270 | if (NULL != flood_task) | 1266 | if (NULL != flood_task) |
1271 | { | 1267 | { |
1272 | GNUNET_SCHEDULER_cancel (flood_task); | 1268 | GNUNET_SCHEDULER_cancel(flood_task); |
1273 | flood_task = NULL; | 1269 | flood_task = NULL; |
1274 | } | 1270 | } |
1275 | if (NULL != proof_task) | 1271 | if (NULL != proof_task) |
1276 | { | 1272 | { |
1277 | GNUNET_SCHEDULER_cancel (proof_task); | 1273 | GNUNET_SCHEDULER_cancel(proof_task); |
1278 | proof_task = NULL; | 1274 | proof_task = NULL; |
1279 | write_proof (); /* remember progress */ | 1275 | write_proof(); /* remember progress */ |
1280 | } | 1276 | } |
1281 | if (NULL != nc) | 1277 | if (NULL != nc) |
1282 | { | 1278 | { |
1283 | GNUNET_notification_context_destroy (nc); | 1279 | GNUNET_notification_context_destroy(nc); |
1284 | nc = NULL; | 1280 | nc = NULL; |
1285 | } | 1281 | } |
1286 | if (NULL != core_api) | 1282 | if (NULL != core_api) |
1287 | { | 1283 | { |
1288 | GNUNET_CORE_disconnect (core_api); | 1284 | GNUNET_CORE_disconnect(core_api); |
1289 | core_api = NULL; | 1285 | core_api = NULL; |
1290 | } | 1286 | } |
1291 | if (NULL != stats) | 1287 | if (NULL != stats) |
1292 | { | 1288 | { |
1293 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1289 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
1294 | stats = NULL; | 1290 | stats = NULL; |
1295 | } | 1291 | } |
1296 | if (NULL != peers) | 1292 | if (NULL != peers) |
1297 | { | 1293 | { |
1298 | GNUNET_CONTAINER_multipeermap_destroy (peers); | 1294 | GNUNET_CONTAINER_multipeermap_destroy(peers); |
1299 | peers = NULL; | 1295 | peers = NULL; |
1300 | } | 1296 | } |
1301 | if (NULL != my_private_key) | 1297 | if (NULL != my_private_key) |
1302 | { | 1298 | { |
1303 | GNUNET_free (my_private_key); | 1299 | GNUNET_free(my_private_key); |
1304 | my_private_key = NULL; | 1300 | my_private_key = NULL; |
1305 | } | 1301 | } |
1306 | #if ENABLE_NSE_HISTOGRAM | 1302 | #if ENABLE_NSE_HISTOGRAM |
1307 | if (NULL != logger_test) | 1303 | if (NULL != logger_test) |
1308 | { | 1304 | { |
1309 | GNUNET_CLIENT_service_test_cancel (logger_test); | 1305 | GNUNET_CLIENT_service_test_cancel(logger_test); |
1310 | logger_test = NULL; | 1306 | logger_test = NULL; |
1311 | } | 1307 | } |
1312 | if (NULL != lh) | 1308 | if (NULL != lh) |
1313 | { | 1309 | { |
1314 | GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL); | 1310 | GNUNET_TESTBED_LOGGER_flush(lh, &flush_comp_cb, NULL); |
1315 | } | 1311 | } |
1316 | if (NULL != histogram) | 1312 | if (NULL != histogram) |
1317 | { | 1313 | { |
1318 | GNUNET_BIO_write_close (histogram); | 1314 | GNUNET_BIO_write_close(histogram); |
1319 | histogram = NULL; | 1315 | histogram = NULL; |
1320 | } | 1316 | } |
1321 | #endif | 1317 | #endif |
1322 | } | 1318 | } |
1323 | 1319 | ||
@@ -1329,38 +1325,38 @@ shutdown_task (void *cls) | |||
1329 | * @param identity the public identity of this peer | 1325 | * @param identity the public identity of this peer |
1330 | */ | 1326 | */ |
1331 | static void | 1327 | static void |
1332 | core_init (void *cls, const struct GNUNET_PeerIdentity *identity) | 1328 | core_init(void *cls, const struct GNUNET_PeerIdentity *identity) |
1333 | { | 1329 | { |
1334 | struct GNUNET_TIME_Absolute now; | 1330 | struct GNUNET_TIME_Absolute now; |
1335 | struct GNUNET_TIME_Absolute prev_time; | 1331 | struct GNUNET_TIME_Absolute prev_time; |
1336 | 1332 | ||
1337 | (void) cls; | 1333 | (void)cls; |
1338 | if (NULL == identity) | 1334 | if (NULL == identity) |
1339 | { | 1335 | { |
1340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); | 1336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); |
1341 | GNUNET_SCHEDULER_shutdown (); | 1337 | GNUNET_SCHEDULER_shutdown(); |
1342 | return; | 1338 | return; |
1343 | } | 1339 | } |
1344 | GNUNET_assert (0 == GNUNET_memcmp (&my_identity, identity)); | 1340 | GNUNET_assert(0 == GNUNET_memcmp(&my_identity, identity)); |
1345 | now = GNUNET_TIME_absolute_get (); | 1341 | now = GNUNET_TIME_absolute_get(); |
1346 | current_timestamp.abs_value_us = | 1342 | current_timestamp.abs_value_us = |
1347 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * | 1343 | (now.abs_value_us / gnunet_nse_interval.rel_value_us) * |
1348 | gnunet_nse_interval.rel_value_us; | 1344 | gnunet_nse_interval.rel_value_us; |
1349 | next_timestamp = | 1345 | next_timestamp = |
1350 | GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); | 1346 | GNUNET_TIME_absolute_add(current_timestamp, gnunet_nse_interval); |
1351 | estimate_index = HISTORY_SIZE - 1; | 1347 | estimate_index = HISTORY_SIZE - 1; |
1352 | estimate_count = 0; | 1348 | estimate_count = 0; |
1353 | if (GNUNET_YES == check_proof_of_work (&my_identity.public_key, my_proof)) | 1349 | if (GNUNET_YES == check_proof_of_work(&my_identity.public_key, my_proof)) |
1354 | { | 1350 | { |
1355 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; | 1351 | int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; |
1356 | prev_time.abs_value_us = | 1352 | prev_time.abs_value_us = |
1357 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; | 1353 | current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; |
1358 | setup_flood_message (idx, prev_time); | 1354 | setup_flood_message(idx, prev_time); |
1359 | setup_flood_message (estimate_index, current_timestamp); | 1355 | setup_flood_message(estimate_index, current_timestamp); |
1360 | estimate_count++; | 1356 | estimate_count++; |
1361 | } | 1357 | } |
1362 | flood_task = | 1358 | flood_task = |
1363 | GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL); | 1359 | GNUNET_SCHEDULER_add_at(next_timestamp, &update_flood_message, NULL); |
1364 | } | 1360 | } |
1365 | 1361 | ||
1366 | 1362 | ||
@@ -1374,21 +1370,21 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity) | |||
1374 | * #GNUNET_SYSERR if the configuration is invalid | 1370 | * #GNUNET_SYSERR if the configuration is invalid |
1375 | */ | 1371 | */ |
1376 | static void | 1372 | static void |
1377 | status_cb (void *cls, int status) | 1373 | status_cb(void *cls, int status) |
1378 | { | 1374 | { |
1379 | (void) cls; | 1375 | (void)cls; |
1380 | logger_test = NULL; | 1376 | logger_test = NULL; |
1381 | if (GNUNET_YES != status) | 1377 | if (GNUNET_YES != status) |
1382 | { | 1378 | { |
1383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n"); | 1379 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n"); |
1384 | return; | 1380 | return; |
1385 | } | 1381 | } |
1386 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg))) | 1382 | if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect(cfg))) |
1387 | { | 1383 | { |
1388 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1384 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1389 | "Cannot connect to the testbed logger. Exiting.\n"); | 1385 | "Cannot connect to the testbed logger. Exiting.\n"); |
1390 | GNUNET_SCHEDULER_shutdown (); | 1386 | GNUNET_SCHEDULER_shutdown(); |
1391 | } | 1387 | } |
1392 | } | 1388 | } |
1393 | #endif | 1389 | #endif |
1394 | 1390 | ||
@@ -1401,127 +1397,127 @@ status_cb (void *cls, int status) | |||
1401 | * @param service the initialized service | 1397 | * @param service the initialized service |
1402 | */ | 1398 | */ |
1403 | static void | 1399 | static void |
1404 | run (void *cls, | 1400 | run(void *cls, |
1405 | const struct GNUNET_CONFIGURATION_Handle *c, | 1401 | const struct GNUNET_CONFIGURATION_Handle *c, |
1406 | struct GNUNET_SERVICE_Handle *service) | 1402 | struct GNUNET_SERVICE_Handle *service) |
1407 | { | 1403 | { |
1408 | struct GNUNET_MQ_MessageHandler core_handlers[] = | 1404 | struct GNUNET_MQ_MessageHandler core_handlers[] = |
1409 | {GNUNET_MQ_hd_fixed_size (p2p_estimate, | 1405 | { GNUNET_MQ_hd_fixed_size(p2p_estimate, |
1410 | GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, | 1406 | GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, |
1411 | struct GNUNET_NSE_FloodMessage, | 1407 | struct GNUNET_NSE_FloodMessage, |
1412 | NULL), | 1408 | NULL), |
1413 | GNUNET_MQ_handler_end ()}; | 1409 | GNUNET_MQ_handler_end() }; |
1414 | char *proof; | 1410 | char *proof; |
1415 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 1411 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
1416 | 1412 | ||
1417 | (void) cls; | 1413 | (void)cls; |
1418 | (void) service; | 1414 | (void)service; |
1419 | cfg = c; | 1415 | cfg = c; |
1420 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | 1416 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, |
1421 | "NSE", | 1417 | "NSE", |
1422 | "INTERVAL", | 1418 | "INTERVAL", |
1423 | &gnunet_nse_interval)) | 1419 | &gnunet_nse_interval)) |
1424 | { | 1420 | { |
1425 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL"); | 1421 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL"); |
1426 | GNUNET_SCHEDULER_shutdown (); | 1422 | GNUNET_SCHEDULER_shutdown(); |
1427 | return; | 1423 | return; |
1428 | } | 1424 | } |
1429 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | 1425 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, |
1430 | "NSE", | 1426 | "NSE", |
1431 | "WORKDELAY", | 1427 | "WORKDELAY", |
1432 | &proof_find_delay)) | 1428 | &proof_find_delay)) |
1433 | { | 1429 | { |
1434 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY"); | 1430 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY"); |
1435 | GNUNET_SCHEDULER_shutdown (); | 1431 | GNUNET_SCHEDULER_shutdown(); |
1436 | return; | 1432 | return; |
1437 | } | 1433 | } |
1438 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | 1434 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, |
1439 | "NSE", | 1435 | "NSE", |
1440 | "WORKBITS", | 1436 | "WORKBITS", |
1441 | &nse_work_required)) | 1437 | &nse_work_required)) |
1442 | { | 1438 | { |
1443 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); | 1439 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); |
1444 | GNUNET_SCHEDULER_shutdown (); | 1440 | GNUNET_SCHEDULER_shutdown(); |
1445 | return; | 1441 | return; |
1446 | } | 1442 | } |
1447 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) | 1443 | if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8) |
1448 | { | 1444 | { |
1449 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 1445 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, |
1450 | "NSE", | 1446 | "NSE", |
1451 | "WORKBITS", | 1447 | "WORKBITS", |
1452 | _ ("Value is too large.\n")); | 1448 | _("Value is too large.\n")); |
1453 | GNUNET_SCHEDULER_shutdown (); | 1449 | GNUNET_SCHEDULER_shutdown(); |
1454 | return; | 1450 | return; |
1455 | } | 1451 | } |
1456 | 1452 | ||
1457 | #if ENABLE_NSE_HISTOGRAM | 1453 | #if ENABLE_NSE_HISTOGRAM |
1458 | { | 1454 | { |
1459 | char *histogram_dir; | 1455 | char *histogram_dir; |
1460 | char *histogram_fn; | 1456 | char *histogram_fn; |
1461 | 1457 | ||
1462 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | 1458 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, |
1463 | "NSE", | 1459 | "NSE", |
1464 | "HISTOGRAM_DIR", | 1460 | "HISTOGRAM_DIR", |
1465 | &histogram_dir)) | 1461 | &histogram_dir)) |
1466 | { | 1462 | { |
1467 | GNUNET_assert ( | 1463 | GNUNET_assert( |
1468 | 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir)); | 1464 | 0 < GNUNET_asprintf(&histogram_fn, "%s/timestamps", histogram_dir)); |
1469 | GNUNET_free (histogram_dir); | 1465 | GNUNET_free(histogram_dir); |
1470 | histogram = GNUNET_BIO_write_open (histogram_fn); | 1466 | histogram = GNUNET_BIO_write_open(histogram_fn); |
1471 | if (NULL == histogram) | 1467 | if (NULL == histogram) |
1472 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1468 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1473 | "Unable to open histogram file `%s'\n", | 1469 | "Unable to open histogram file `%s'\n", |
1474 | histogram_fn); | 1470 | histogram_fn); |
1475 | GNUNET_free (histogram_fn); | 1471 | GNUNET_free(histogram_fn); |
1476 | } | 1472 | } |
1477 | logger_test = GNUNET_CLIENT_service_test ("testbed-logger", | 1473 | logger_test = GNUNET_CLIENT_service_test("testbed-logger", |
1478 | cfg, | 1474 | cfg, |
1479 | GNUNET_TIME_UNIT_SECONDS, | 1475 | GNUNET_TIME_UNIT_SECONDS, |
1480 | &status_cb, | 1476 | &status_cb, |
1481 | NULL); | 1477 | NULL); |
1482 | } | 1478 | } |
1483 | #endif | 1479 | #endif |
1484 | 1480 | ||
1485 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1481 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1486 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | 1482 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); |
1487 | GNUNET_assert (NULL != pk); | 1483 | GNUNET_assert(NULL != pk); |
1488 | my_private_key = pk; | 1484 | my_private_key = pk; |
1489 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); | 1485 | GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); |
1490 | if (GNUNET_OK != | 1486 | if (GNUNET_OK != |
1491 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 1487 | GNUNET_CONFIGURATION_get_value_filename(cfg, "NSE", "PROOFFILE", &proof)) |
1492 | { | 1488 | { |
1493 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); | 1489 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); |
1494 | GNUNET_free (my_private_key); | 1490 | GNUNET_free(my_private_key); |
1495 | my_private_key = NULL; | 1491 | my_private_key = NULL; |
1496 | GNUNET_SCHEDULER_shutdown (); | 1492 | GNUNET_SCHEDULER_shutdown(); |
1497 | return; | 1493 | return; |
1498 | } | 1494 | } |
1499 | if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || | 1495 | if ((GNUNET_YES != GNUNET_DISK_file_test(proof)) || |
1500 | (sizeof (my_proof) != | 1496 | (sizeof(my_proof) != |
1501 | GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) | 1497 | GNUNET_DISK_fn_read(proof, &my_proof, sizeof(my_proof)))) |
1502 | my_proof = 0; | 1498 | my_proof = 0; |
1503 | GNUNET_free (proof); | 1499 | GNUNET_free(proof); |
1504 | proof_task = | 1500 | proof_task = |
1505 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1501 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, |
1506 | &find_proof, | 1502 | &find_proof, |
1507 | NULL); | 1503 | NULL); |
1508 | 1504 | ||
1509 | peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); | 1505 | peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); |
1510 | nc = GNUNET_notification_context_create (1); | 1506 | nc = GNUNET_notification_context_create(1); |
1511 | /* Connect to core service and register core handlers */ | 1507 | /* Connect to core service and register core handlers */ |
1512 | core_api = | 1508 | core_api = |
1513 | GNUNET_CORE_connect (cfg, /* Main configuration */ | 1509 | GNUNET_CORE_connect(cfg, /* Main configuration */ |
1514 | NULL, /* Closure passed to functions */ | 1510 | NULL, /* Closure passed to functions */ |
1515 | &core_init, /* Call core_init once connected */ | 1511 | &core_init, /* Call core_init once connected */ |
1516 | &handle_core_connect, /* Handle connects */ | 1512 | &handle_core_connect, /* Handle connects */ |
1517 | &handle_core_disconnect, /* Handle disconnects */ | 1513 | &handle_core_disconnect, /* Handle disconnects */ |
1518 | core_handlers); /* Register these handlers */ | 1514 | core_handlers); /* Register these handlers */ |
1519 | if (NULL == core_api) | 1515 | if (NULL == core_api) |
1520 | { | 1516 | { |
1521 | GNUNET_SCHEDULER_shutdown (); | 1517 | GNUNET_SCHEDULER_shutdown(); |
1522 | return; | 1518 | return; |
1523 | } | 1519 | } |
1524 | stats = GNUNET_STATISTICS_create ("nse", cfg); | 1520 | stats = GNUNET_STATISTICS_create("nse", cfg); |
1525 | } | 1521 | } |
1526 | 1522 | ||
1527 | 1523 | ||
@@ -1534,12 +1530,12 @@ run (void *cls, | |||
1534 | * @return @a c | 1530 | * @return @a c |
1535 | */ | 1531 | */ |
1536 | static void * | 1532 | static void * |
1537 | client_connect_cb (void *cls, | 1533 | client_connect_cb(void *cls, |
1538 | struct GNUNET_SERVICE_Client *c, | 1534 | struct GNUNET_SERVICE_Client *c, |
1539 | struct GNUNET_MQ_Handle *mq) | 1535 | struct GNUNET_MQ_Handle *mq) |
1540 | { | 1536 | { |
1541 | (void) cls; | 1537 | (void)cls; |
1542 | (void) mq; | 1538 | (void)mq; |
1543 | return c; | 1539 | return c; |
1544 | } | 1540 | } |
1545 | 1541 | ||
@@ -1552,29 +1548,29 @@ client_connect_cb (void *cls, | |||
1552 | * @param internal_cls should be equal to @a c | 1548 | * @param internal_cls should be equal to @a c |
1553 | */ | 1549 | */ |
1554 | static void | 1550 | static void |
1555 | client_disconnect_cb (void *cls, | 1551 | client_disconnect_cb(void *cls, |
1556 | struct GNUNET_SERVICE_Client *c, | 1552 | struct GNUNET_SERVICE_Client *c, |
1557 | void *internal_cls) | 1553 | void *internal_cls) |
1558 | { | 1554 | { |
1559 | (void) cls; | 1555 | (void)cls; |
1560 | GNUNET_assert (c == internal_cls); | 1556 | GNUNET_assert(c == internal_cls); |
1561 | } | 1557 | } |
1562 | 1558 | ||
1563 | 1559 | ||
1564 | /** | 1560 | /** |
1565 | * Define "main" method using service macro. | 1561 | * Define "main" method using service macro. |
1566 | */ | 1562 | */ |
1567 | GNUNET_SERVICE_MAIN ("nse", | 1563 | GNUNET_SERVICE_MAIN("nse", |
1568 | GNUNET_SERVICE_OPTION_NONE, | 1564 | GNUNET_SERVICE_OPTION_NONE, |
1569 | &run, | 1565 | &run, |
1570 | &client_connect_cb, | 1566 | &client_connect_cb, |
1571 | &client_disconnect_cb, | 1567 | &client_disconnect_cb, |
1572 | NULL, | 1568 | NULL, |
1573 | GNUNET_MQ_hd_fixed_size (start, | 1569 | GNUNET_MQ_hd_fixed_size(start, |
1574 | GNUNET_MESSAGE_TYPE_NSE_START, | 1570 | GNUNET_MESSAGE_TYPE_NSE_START, |
1575 | struct GNUNET_MessageHeader, | 1571 | struct GNUNET_MessageHeader, |
1576 | NULL), | 1572 | NULL), |
1577 | GNUNET_MQ_handler_end ()); | 1573 | GNUNET_MQ_handler_end()); |
1578 | 1574 | ||
1579 | 1575 | ||
1580 | #if defined(LINUX) && defined(__GLIBC__) | 1576 | #if defined(LINUX) && defined(__GLIBC__) |
@@ -1583,11 +1579,11 @@ GNUNET_SERVICE_MAIN ("nse", | |||
1583 | /** | 1579 | /** |
1584 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1580 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1585 | */ | 1581 | */ |
1586 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | 1582 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init() |
1587 | { | 1583 | { |
1588 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | 1584 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); |
1589 | mallopt (M_TOP_PAD, 1 * 1024); | 1585 | mallopt(M_TOP_PAD, 1 * 1024); |
1590 | malloc_trim (0); | 1586 | malloc_trim(0); |
1591 | } | 1587 | } |
1592 | #endif | 1588 | #endif |
1593 | 1589 | ||
diff --git a/src/nse/nse.h b/src/nse/nse.h index efff57679..b0129addd 100644 --- a/src/nse/nse.h +++ b/src/nse/nse.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Nathan Evans | 22 | * @author Nathan Evans |
@@ -39,8 +39,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
39 | * standard deviation of known estimates. | 39 | * standard deviation of known estimates. |
40 | * | 40 | * |
41 | */ | 41 | */ |
42 | struct GNUNET_NSE_ClientMessage | 42 | struct GNUNET_NSE_ClientMessage { |
43 | { | ||
44 | /** | 43 | /** |
45 | * Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE | 44 | * Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE |
46 | */ | 45 | */ |
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index 259be75ed..93716eb5f 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file nse/nse_api.c | 22 | * @file nse/nse_api.c |
@@ -32,13 +32,12 @@ | |||
32 | #include "gnunet_nse_service.h" | 32 | #include "gnunet_nse_service.h" |
33 | #include "nse.h" | 33 | #include "nse.h" |
34 | 34 | ||
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 talking with the NSE service. | 38 | * Handle for talking with the NSE service. |
39 | */ | 39 | */ |
40 | struct GNUNET_NSE_Handle | 40 | struct GNUNET_NSE_Handle { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Configuration to use. | 42 | * Configuration to use. |
44 | */ | 43 | */ |
@@ -77,7 +76,7 @@ struct GNUNET_NSE_Handle | |||
77 | * @param cls closure with the `struct GNUNET_NSE_Handle *` | 76 | * @param cls closure with the `struct GNUNET_NSE_Handle *` |
78 | */ | 77 | */ |
79 | static void | 78 | static void |
80 | reconnect (void *cls); | 79 | reconnect(void *cls); |
81 | 80 | ||
82 | 81 | ||
83 | /** | 82 | /** |
@@ -90,16 +89,16 @@ reconnect (void *cls); | |||
90 | * @param error error code | 89 | * @param error error code |
91 | */ | 90 | */ |
92 | static void | 91 | static void |
93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 92 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
94 | { | 93 | { |
95 | struct GNUNET_NSE_Handle *h = cls; | 94 | struct GNUNET_NSE_Handle *h = cls; |
96 | 95 | ||
97 | (void) error; | 96 | (void)error; |
98 | GNUNET_MQ_destroy (h->mq); | 97 | GNUNET_MQ_destroy(h->mq); |
99 | h->mq = NULL; | 98 | h->mq = NULL; |
100 | h->reconnect_task = | 99 | h->reconnect_task = |
101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 100 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 101 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
103 | } | 102 | } |
104 | 103 | ||
105 | 104 | ||
@@ -111,15 +110,15 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
111 | * @param client_msg message received | 110 | * @param client_msg message received |
112 | */ | 111 | */ |
113 | static void | 112 | static void |
114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | 113 | handle_estimate(void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
115 | { | 114 | { |
116 | struct GNUNET_NSE_Handle *h = cls; | 115 | struct GNUNET_NSE_Handle *h = cls; |
117 | 116 | ||
118 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 117 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
119 | h->recv_cb (h->recv_cb_cls, | 118 | h->recv_cb(h->recv_cb_cls, |
120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), | 119 | GNUNET_TIME_absolute_ntoh(client_msg->timestamp), |
121 | GNUNET_ntoh_double (client_msg->size_estimate), | 120 | GNUNET_ntoh_double(client_msg->size_estimate), |
122 | GNUNET_ntoh_double (client_msg->std_deviation)); | 121 | GNUNET_ntoh_double(client_msg->std_deviation)); |
123 | } | 122 | } |
124 | 123 | ||
125 | 124 | ||
@@ -129,27 +128,27 @@ handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) | |||
129 | * @param cls the `struct GNUNET_NSE_Handle *` | 128 | * @param cls the `struct GNUNET_NSE_Handle *` |
130 | */ | 129 | */ |
131 | static void | 130 | static void |
132 | reconnect (void *cls) | 131 | reconnect(void *cls) |
133 | { | 132 | { |
134 | struct GNUNET_NSE_Handle *h = cls; | 133 | struct GNUNET_NSE_Handle *h = cls; |
135 | struct GNUNET_MQ_MessageHandler handlers[] = | 134 | struct GNUNET_MQ_MessageHandler handlers[] = |
136 | {GNUNET_MQ_hd_fixed_size (estimate, | 135 | { GNUNET_MQ_hd_fixed_size(estimate, |
137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 136 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
138 | struct GNUNET_NSE_ClientMessage, | 137 | struct GNUNET_NSE_ClientMessage, |
139 | h), | 138 | h), |
140 | GNUNET_MQ_handler_end ()}; | 139 | GNUNET_MQ_handler_end() }; |
141 | struct GNUNET_MessageHeader *msg; | 140 | struct GNUNET_MessageHeader *msg; |
142 | struct GNUNET_MQ_Envelope *env; | 141 | struct GNUNET_MQ_Envelope *env; |
143 | 142 | ||
144 | h->reconnect_task = NULL; | 143 | h->reconnect_task = NULL; |
145 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 144 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
146 | "Connecting to network size estimation service.\n"); | 145 | "Connecting to network size estimation service.\n"); |
147 | GNUNET_assert (NULL == h->mq); | 146 | GNUNET_assert(NULL == h->mq); |
148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); | 147 | h->mq = GNUNET_CLIENT_connect(h->cfg, "nse", handlers, &mq_error_handler, h); |
149 | if (NULL == h->mq) | 148 | if (NULL == h->mq) |
150 | return; | 149 | return; |
151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); | 150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NSE_START); |
152 | GNUNET_MQ_send (h->mq, env); | 151 | GNUNET_MQ_send(h->mq, env); |
153 | } | 152 | } |
154 | 153 | ||
155 | 154 | ||
@@ -162,24 +161,24 @@ reconnect (void *cls) | |||
162 | * @return handle to use | 161 | * @return handle to use |
163 | */ | 162 | */ |
164 | struct GNUNET_NSE_Handle * | 163 | struct GNUNET_NSE_Handle * |
165 | GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 164 | GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
166 | GNUNET_NSE_Callback func, | 165 | GNUNET_NSE_Callback func, |
167 | void *func_cls) | 166 | void *func_cls) |
168 | { | 167 | { |
169 | struct GNUNET_NSE_Handle *h; | 168 | struct GNUNET_NSE_Handle *h; |
170 | 169 | ||
171 | GNUNET_assert (NULL != func); | 170 | GNUNET_assert(NULL != func); |
172 | h = GNUNET_new (struct GNUNET_NSE_Handle); | 171 | h = GNUNET_new(struct GNUNET_NSE_Handle); |
173 | h->cfg = cfg; | 172 | h->cfg = cfg; |
174 | h->recv_cb = func; | 173 | h->recv_cb = func; |
175 | h->recv_cb_cls = func_cls; | 174 | h->recv_cb_cls = func_cls; |
176 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 175 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
177 | reconnect (h); | 176 | reconnect(h); |
178 | if (NULL == h->mq) | 177 | if (NULL == h->mq) |
179 | { | 178 | { |
180 | GNUNET_free (h); | 179 | GNUNET_free(h); |
181 | return NULL; | 180 | return NULL; |
182 | } | 181 | } |
183 | return h; | 182 | return h; |
184 | } | 183 | } |
185 | 184 | ||
@@ -190,19 +189,19 @@ GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | * @param h handle to destroy | 189 | * @param h handle to destroy |
191 | */ | 190 | */ |
192 | void | 191 | void |
193 | GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h) | 192 | GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h) |
194 | { | 193 | { |
195 | if (NULL != h->reconnect_task) | 194 | if (NULL != h->reconnect_task) |
196 | { | 195 | { |
197 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 196 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
198 | h->reconnect_task = NULL; | 197 | h->reconnect_task = NULL; |
199 | } | 198 | } |
200 | if (NULL != h->mq) | 199 | if (NULL != h->mq) |
201 | { | 200 | { |
202 | GNUNET_MQ_destroy (h->mq); | 201 | GNUNET_MQ_destroy(h->mq); |
203 | h->mq = NULL; | 202 | h->mq = NULL; |
204 | } | 203 | } |
205 | GNUNET_free (h); | 204 | GNUNET_free(h); |
206 | } | 205 | } |
207 | 206 | ||
208 | /* end of nse_api.c */ | 207 | /* end of nse_api.c */ |
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c index 5178f178b..bf4dbe0b2 100644 --- a/src/nse/perf_kdf.c +++ b/src/nse/perf_kdf.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -38,47 +38,47 @@ | |||
38 | * @param result where to write the resulting hash | 38 | * @param result where to write the resulting hash |
39 | */ | 39 | */ |
40 | static void | 40 | static void |
41 | pow_hash (const void *buf, | 41 | pow_hash(const void *buf, |
42 | size_t buf_len, | 42 | size_t buf_len, |
43 | struct GNUNET_HashCode *result) | 43 | struct GNUNET_HashCode *result) |
44 | { | 44 | { |
45 | GNUNET_break (0 == | 45 | GNUNET_break(0 == |
46 | gcry_kdf_derive (buf, buf_len, | 46 | gcry_kdf_derive(buf, buf_len, |
47 | GCRY_KDF_SCRYPT, | 47 | GCRY_KDF_SCRYPT, |
48 | 1 /* subalgo */, | 48 | 1 /* subalgo */, |
49 | "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"), | 49 | "gnunet-proof-of-work", strlen("gnunet-proof-of-work"), |
50 | 2 /* iterations; keep cost of individual op small */, | 50 | 2 /* iterations; keep cost of individual op small */, |
51 | sizeof (struct GNUNET_HashCode), result)); | 51 | sizeof(struct GNUNET_HashCode), result)); |
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | static void | 55 | static void |
56 | perfHash () | 56 | perfHash() |
57 | { | 57 | { |
58 | struct GNUNET_HashCode hc; | 58 | struct GNUNET_HashCode hc; |
59 | unsigned int i; | 59 | unsigned int i; |
60 | char buf[64]; | 60 | char buf[64]; |
61 | 61 | ||
62 | memset (buf, 1, sizeof (buf)); | 62 | memset(buf, 1, sizeof(buf)); |
63 | for (i = 0; i < 1024; i++) | 63 | for (i = 0; i < 1024; i++) |
64 | pow_hash (buf, sizeof (buf), &hc); | 64 | pow_hash(buf, sizeof(buf), &hc); |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | int | 68 | int |
69 | main (int argc, char *argv[]) | 69 | main(int argc, char *argv[]) |
70 | { | 70 | { |
71 | struct GNUNET_TIME_Absolute start; | 71 | struct GNUNET_TIME_Absolute start; |
72 | 72 | ||
73 | start = GNUNET_TIME_absolute_get (); | 73 | start = GNUNET_TIME_absolute_get(); |
74 | perfHash (); | 74 | perfHash(); |
75 | printf ("Hash perf took %s\n", | 75 | printf("Hash perf took %s\n", |
76 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), | 76 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), |
77 | GNUNET_YES)); | 77 | GNUNET_YES)); |
78 | GAUGER ("NSE", "Proof-of-work hashing", | 78 | GAUGER("NSE", "Proof-of-work hashing", |
79 | 1024.0 / (1.0 + | 79 | 1024.0 / (1.0 + |
80 | GNUNET_TIME_absolute_get_duration | 80 | GNUNET_TIME_absolute_get_duration |
81 | (start).rel_value_us / 1000.0), "hashes/ms"); | 81 | (start).rel_value_us / 1000.0), "hashes/ms"); |
82 | return 0; | 82 | return 0; |
83 | } | 83 | } |
84 | 84 | ||
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c index 67ca17127..b739e05a2 100644 --- a/src/nse/test_nse_api.c +++ b/src/nse/test_nse_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file nse/test_nse_api.c | 21 | * @file nse/test_nse_api.c |
22 | * @brief testcase for nse_api.c | 22 | * @brief testcase for nse_api.c |
@@ -38,13 +38,13 @@ static struct GNUNET_SCHEDULER_Task * die_task; | |||
38 | * @param cls closure | 38 | * @param cls closure |
39 | */ | 39 | */ |
40 | static void | 40 | static void |
41 | end_test (void *cls) | 41 | end_test(void *cls) |
42 | { | 42 | { |
43 | if (h != NULL) | 43 | if (h != NULL) |
44 | { | 44 | { |
45 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n"); | 45 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from NSE service.\n"); |
46 | GNUNET_NSE_disconnect (h); | 46 | GNUNET_NSE_disconnect(h); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
@@ -58,46 +58,46 @@ end_test (void *cls) | |||
58 | * | 58 | * |
59 | */ | 59 | */ |
60 | static void | 60 | static void |
61 | check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp, | 61 | check_nse_message(void *cls, struct GNUNET_TIME_Absolute timestamp, |
62 | double estimate, double std_dev) | 62 | double estimate, double std_dev) |
63 | { | 63 | { |
64 | int *ok = cls; | 64 | int *ok = cls; |
65 | 65 | ||
66 | fprintf (stderr, | 66 | fprintf(stderr, |
67 | "Received NSE message, estimate %f, standard deviation %f.\n", | 67 | "Received NSE message, estimate %f, standard deviation %f.\n", |
68 | estimate, std_dev); | 68 | estimate, std_dev); |
69 | /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ | 69 | /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ |
70 | (*ok) = 0; | 70 | (*ok) = 0; |
71 | if (die_task != NULL) | 71 | if (die_task != NULL) |
72 | GNUNET_SCHEDULER_cancel (die_task); | 72 | GNUNET_SCHEDULER_cancel(die_task); |
73 | die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL); | 73 | die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static void | 77 | static void |
78 | run (void *cls, | 78 | run(void *cls, |
79 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 79 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
80 | struct GNUNET_TESTING_Peer *peer) | 80 | struct GNUNET_TESTING_Peer *peer) |
81 | { | 81 | { |
82 | die_task = | 82 | die_task = |
83 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 83 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
84 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_test, | 84 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_test, |
85 | NULL); | 85 | NULL); |
86 | 86 | ||
87 | h = GNUNET_NSE_connect (cfg, &check_nse_message, cls); | 87 | h = GNUNET_NSE_connect(cfg, &check_nse_message, cls); |
88 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n"); | 88 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to NSE service.\n"); |
89 | GNUNET_assert (h != NULL); | 89 | GNUNET_assert(h != NULL); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | int | 93 | int |
94 | main (int argc, char *argv[]) | 94 | main(int argc, char *argv[]) |
95 | { | 95 | { |
96 | int ok = 1; | 96 | int ok = 1; |
97 | 97 | ||
98 | if (0 != GNUNET_TESTING_peer_run ("test_nse_api", | 98 | if (0 != GNUNET_TESTING_peer_run("test_nse_api", |
99 | "test_nse.conf", | 99 | "test_nse.conf", |
100 | &run, &ok)) | 100 | &run, &ok)) |
101 | return 1; | 101 | return 1; |
102 | return ok; | 102 | return ok; |
103 | } | 103 | } |
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c index ec5a94f76..88ced26d2 100644 --- a/src/nse/test_nse_multipeer.c +++ b/src/nse/test_nse_multipeer.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file nse/test_nse_multipeer.c | 21 | * @file nse/test_nse_multipeer.c |
22 | * @brief Testcase for the network size estimation service. Starts | 22 | * @brief Testcase for the network size estimation service. Starts |
@@ -37,14 +37,13 @@ | |||
37 | /** | 37 | /** |
38 | * How long do we run the test? | 38 | * How long do we run the test? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Information we track for each peer. | 44 | * Information we track for each peer. |
45 | */ | 45 | */ |
46 | struct NSEPeer | 46 | struct NSEPeer { |
47 | { | ||
48 | /** | 47 | /** |
49 | * Handle for NSE connect operation. | 48 | * Handle for NSE connect operation. |
50 | */ | 49 | */ |
@@ -72,13 +71,13 @@ static int ok; | |||
72 | * Task run on timeout to shut everything down. | 71 | * Task run on timeout to shut everything down. |
73 | */ | 72 | */ |
74 | static void | 73 | static void |
75 | shutdown_task (void *cls) | 74 | shutdown_task(void *cls) |
76 | { | 75 | { |
77 | unsigned int i; | 76 | unsigned int i; |
78 | 77 | ||
79 | for (i=0;i<NUM_PEERS;i++) | 78 | for (i = 0; i < NUM_PEERS; i++) |
80 | GNUNET_TESTBED_operation_done (nse_peers[i].op); | 79 | GNUNET_TESTBED_operation_done(nse_peers[i].op); |
81 | GNUNET_SCHEDULER_shutdown (); | 80 | GNUNET_SCHEDULER_shutdown(); |
82 | } | 81 | } |
83 | 82 | ||
84 | 83 | ||
@@ -93,17 +92,17 @@ shutdown_task (void *cls) | |||
93 | * | 92 | * |
94 | */ | 93 | */ |
95 | static void | 94 | static void |
96 | handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, | 95 | handle_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, |
97 | double estimate, double std_dev) | 96 | double estimate, double std_dev) |
98 | { | 97 | { |
99 | struct NSEPeer *peer = cls; | 98 | struct NSEPeer *peer = cls; |
100 | 99 | ||
101 | fprintf (stderr, | 100 | fprintf(stderr, |
102 | "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", | 101 | "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", |
103 | (unsigned int) (peer - nse_peers), | 102 | (unsigned int)(peer - nse_peers), |
104 | estimate, std_dev, | 103 | estimate, std_dev, |
105 | GNUNET_NSE_log_estimate_to_n (estimate), | 104 | GNUNET_NSE_log_estimate_to_n(estimate), |
106 | NUM_PEERS); | 105 | NUM_PEERS); |
107 | ok = 0; | 106 | ok = 0; |
108 | } | 107 | } |
109 | 108 | ||
@@ -118,22 +117,22 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, | |||
118 | * operation has executed successfully. | 117 | * operation has executed successfully. |
119 | */ | 118 | */ |
120 | static void | 119 | static void |
121 | nse_connect_complete_cb (void *cls, | 120 | nse_connect_complete_cb(void *cls, |
122 | struct GNUNET_TESTBED_Operation *op, | 121 | struct GNUNET_TESTBED_Operation *op, |
123 | void *ca_result, | 122 | void *ca_result, |
124 | const char *emsg) | 123 | const char *emsg) |
125 | { | 124 | { |
126 | struct NSEPeer *peer = cls; | 125 | struct NSEPeer *peer = cls; |
127 | struct GNUNET_NSE_Handle *nse = ca_result; | 126 | struct GNUNET_NSE_Handle *nse = ca_result; |
128 | 127 | ||
129 | GNUNET_assert (op == peer->op); | 128 | GNUNET_assert(op == peer->op); |
130 | if (NULL != emsg) | 129 | if (NULL != emsg) |
131 | { | 130 | { |
132 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 131 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
133 | "Failed to connect to NSE service: %s\n", | 132 | "Failed to connect to NSE service: %s\n", |
134 | emsg); | 133 | emsg); |
135 | ok = 1; | 134 | ok = 1; |
136 | GNUNET_SCHEDULER_shutdown (); | 135 | GNUNET_SCHEDULER_shutdown(); |
137 | return; | 136 | return; |
138 | } | 137 | } |
139 | peer->nse_handle = nse; | 138 | peer->nse_handle = nse; |
@@ -151,12 +150,12 @@ nse_connect_complete_cb (void *cls, | |||
151 | * @return service handle to return in 'op_result', NULL on error | 150 | * @return service handle to return in 'op_result', NULL on error |
152 | */ | 151 | */ |
153 | static void * | 152 | static void * |
154 | nse_connect_adapter (void *cls, | 153 | nse_connect_adapter(void *cls, |
155 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 154 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
156 | { | 155 | { |
157 | return GNUNET_NSE_connect (cfg, | 156 | return GNUNET_NSE_connect(cfg, |
158 | &handle_estimate, | 157 | &handle_estimate, |
159 | cls); | 158 | cls); |
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
@@ -168,10 +167,10 @@ nse_connect_adapter (void *cls, | |||
168 | * @param op_result service handle returned from the connect adapter | 167 | * @param op_result service handle returned from the connect adapter |
169 | */ | 168 | */ |
170 | static void | 169 | static void |
171 | nse_disconnect_adapter (void *cls, | 170 | nse_disconnect_adapter(void *cls, |
172 | void *op_result) | 171 | void *op_result) |
173 | { | 172 | { |
174 | GNUNET_NSE_disconnect (op_result); | 173 | GNUNET_NSE_disconnect(op_result); |
175 | } | 174 | } |
176 | 175 | ||
177 | 176 | ||
@@ -188,27 +187,27 @@ nse_disconnect_adapter (void *cls, | |||
188 | * failed | 187 | * failed |
189 | */ | 188 | */ |
190 | static void | 189 | static void |
191 | run (void *cls, | 190 | run(void *cls, |
192 | struct GNUNET_TESTBED_RunHandle *h, | 191 | struct GNUNET_TESTBED_RunHandle *h, |
193 | unsigned int num_peers, | 192 | unsigned int num_peers, |
194 | struct GNUNET_TESTBED_Peer **peers, | 193 | struct GNUNET_TESTBED_Peer **peers, |
195 | unsigned int links_succeeded, | 194 | unsigned int links_succeeded, |
196 | unsigned int links_failed) | 195 | unsigned int links_failed) |
197 | { | 196 | { |
198 | unsigned int i; | 197 | unsigned int i; |
199 | 198 | ||
200 | GNUNET_assert (NUM_PEERS == num_peers); | 199 | GNUNET_assert(NUM_PEERS == num_peers); |
201 | for (i=0;i<num_peers;i++) | 200 | for (i = 0; i < num_peers; i++) |
202 | nse_peers[i].op = GNUNET_TESTBED_service_connect (&nse_peers[i], | 201 | nse_peers[i].op = GNUNET_TESTBED_service_connect(&nse_peers[i], |
203 | peers[i], | 202 | peers[i], |
204 | "nse", | 203 | "nse", |
205 | &nse_connect_complete_cb, | 204 | &nse_connect_complete_cb, |
206 | &nse_peers[i], | 205 | &nse_peers[i], |
207 | &nse_connect_adapter, | 206 | &nse_connect_adapter, |
208 | &nse_disconnect_adapter, | 207 | &nse_disconnect_adapter, |
209 | &nse_peers[i]); | 208 | &nse_peers[i]); |
210 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 209 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
211 | &shutdown_task, NULL); | 210 | &shutdown_task, NULL); |
212 | } | 211 | } |
213 | 212 | ||
214 | 213 | ||
@@ -220,14 +219,14 @@ run (void *cls, | |||
220 | * @return 0 on success | 219 | * @return 0 on success |
221 | */ | 220 | */ |
222 | int | 221 | int |
223 | main (int argc, char *argv[]) | 222 | main(int argc, char *argv[]) |
224 | { | 223 | { |
225 | ok = 1; | 224 | ok = 1; |
226 | (void) GNUNET_TESTBED_test_run ("test-nse-multipeer", | 225 | (void)GNUNET_TESTBED_test_run("test-nse-multipeer", |
227 | "test_nse.conf", | 226 | "test_nse.conf", |
228 | NUM_PEERS, | 227 | NUM_PEERS, |
229 | 0, NULL, NULL, | 228 | 0, NULL, NULL, |
230 | &run, NULL); | 229 | &run, NULL); |
231 | return ok; | 230 | return ok; |
232 | } | 231 | } |
233 | 232 | ||