diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 1702 |
1 files changed, 844 insertions, 858 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 6abe8d2d2..71f43fada 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -16,7 +16,7 @@ | |||
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 transport/gnunet-service-transport_validation.c | 22 | * @file transport/gnunet-service-transport_validation.c |
@@ -42,8 +42,7 @@ | |||
42 | * was successful? If that is clarified/determined, "UGH" in | 42 | * was successful? If that is clarified/determined, "UGH" in |
43 | * ~gnunetpeerinfogtk.c:1103 should be resolved. | 43 | * ~gnunetpeerinfogtk.c:1103 should be resolved. |
44 | */ | 44 | */ |
45 | enum GNUNET_TRANSPORT_ValidationState | 45 | enum GNUNET_TRANSPORT_ValidationState { |
46 | { | ||
47 | /** | 46 | /** |
48 | * Undefined state | 47 | * Undefined state |
49 | * | 48 | * |
@@ -90,14 +89,14 @@ enum GNUNET_TRANSPORT_ValidationState | |||
90 | * OTOH, we don't want to spend too much time generating PONG signatures, | 89 | * OTOH, we don't want to spend too much time generating PONG signatures, |
91 | * so they must have some lifetime to reduce our CPU usage. | 90 | * so they must have some lifetime to reduce our CPU usage. |
92 | */ | 91 | */ |
93 | #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1) | 92 | #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1) |
94 | 93 | ||
95 | /** | 94 | /** |
96 | * After how long do we expire an address in a HELLO that we just | 95 | * After how long do we expire an address in a HELLO that we just |
97 | * validated? This value is also used for our own addresses when we | 96 | * validated? This value is also used for our own addresses when we |
98 | * create a HELLO. | 97 | * create a HELLO. |
99 | */ | 98 | */ |
100 | #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) | 99 | #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 12) |
101 | 100 | ||
102 | /** | 101 | /** |
103 | * How often do we allow PINGing an address that we have not yet | 102 | * How often do we allow PINGing an address that we have not yet |
@@ -105,24 +104,24 @@ enum GNUNET_TRANSPORT_ValidationState | |||
105 | * we cannot validate (because after this time we can destroy the | 104 | * we cannot validate (because after this time we can destroy the |
106 | * validation record). | 105 | * validation record). |
107 | */ | 106 | */ |
108 | #define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 107 | #define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) |
109 | 108 | ||
110 | /** | 109 | /** |
111 | * How often do we PING an address that we have successfully validated | 110 | * How often do we PING an address that we have successfully validated |
112 | * in the past but are not actively using? Should be (significantly) | 111 | * in the past but are not actively using? Should be (significantly) |
113 | * smaller than HELLO_ADDRESS_EXPIRATION. | 112 | * smaller than HELLO_ADDRESS_EXPIRATION. |
114 | */ | 113 | */ |
115 | #define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 114 | #define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) |
116 | 115 | ||
117 | /** | 116 | /** |
118 | * How often do we PING an address that we are currently using? | 117 | * How often do we PING an address that we are currently using? |
119 | */ | 118 | */ |
120 | #define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | 119 | #define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) |
121 | 120 | ||
122 | /** | 121 | /** |
123 | * How much delay is acceptable for sending the PING or PONG? | 122 | * How much delay is acceptable for sending the PING or PONG? |
124 | */ | 123 | */ |
125 | #define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 124 | #define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) |
126 | 125 | ||
127 | /** | 126 | /** |
128 | * Size of the validation map hashmap. | 127 | * Size of the validation map hashmap. |
@@ -148,9 +147,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
148 | * or an empty address if we are just sending a PING to confirm that a | 147 | * or an empty address if we are just sending a PING to confirm that a |
149 | * connection which the receiver (of the PING) initiated is still valid. | 148 | * connection which the receiver (of the PING) initiated is still valid. |
150 | */ | 149 | */ |
151 | struct TransportPingMessage | 150 | struct TransportPingMessage { |
152 | { | ||
153 | |||
154 | /** | 151 | /** |
155 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING | 152 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING |
156 | */ | 153 | */ |
@@ -165,7 +162,6 @@ struct TransportPingMessage | |||
165 | * Who is the intended recipient? | 162 | * Who is the intended recipient? |
166 | */ | 163 | */ |
167 | struct GNUNET_PeerIdentity target; | 164 | struct GNUNET_PeerIdentity target; |
168 | |||
169 | }; | 165 | }; |
170 | 166 | ||
171 | 167 | ||
@@ -179,9 +175,7 @@ struct TransportPingMessage | |||
179 | * if the PING had not address either (and we received the request via | 175 | * if the PING had not address either (and we received the request via |
180 | * a connection that we initiated). | 176 | * a connection that we initiated). |
181 | */ | 177 | */ |
182 | struct TransportPongMessage | 178 | struct TransportPongMessage { |
183 | { | ||
184 | |||
185 | /** | 179 | /** |
186 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG | 180 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG |
187 | */ | 181 | */ |
@@ -214,16 +208,13 @@ struct TransportPongMessage | |||
214 | * being signed, hence not redundant). | 208 | * being signed, hence not redundant). |
215 | */ | 209 | */ |
216 | uint32_t addrlen GNUNET_PACKED; | 210 | uint32_t addrlen GNUNET_PACKED; |
217 | |||
218 | }; | 211 | }; |
219 | GNUNET_NETWORK_STRUCT_END | 212 | GNUNET_NETWORK_STRUCT_END |
220 | 213 | ||
221 | /** | 214 | /** |
222 | * Information about an address under validation | 215 | * Information about an address under validation |
223 | */ | 216 | */ |
224 | struct ValidationEntry | 217 | struct ValidationEntry { |
225 | { | ||
226 | |||
227 | /** | 218 | /** |
228 | * The address. | 219 | * The address. |
229 | */ | 220 | */ |
@@ -361,8 +352,7 @@ static struct GNUNET_TIME_Absolute validation_next; | |||
361 | /** | 352 | /** |
362 | * Context for the validation entry match function. | 353 | * Context for the validation entry match function. |
363 | */ | 354 | */ |
364 | struct ValidationEntryMatchContext | 355 | struct ValidationEntryMatchContext { |
365 | { | ||
366 | /** | 356 | /** |
367 | * Where to store the result? | 357 | * Where to store the result? |
368 | */ | 358 | */ |
@@ -372,7 +362,6 @@ struct ValidationEntryMatchContext | |||
372 | * Address we're interested in. | 362 | * Address we're interested in. |
373 | */ | 363 | */ |
374 | const struct GNUNET_HELLO_Address *address; | 364 | const struct GNUNET_HELLO_Address *address; |
375 | |||
376 | }; | 365 | }; |
377 | 366 | ||
378 | 367 | ||
@@ -382,12 +371,12 @@ struct ValidationEntryMatchContext | |||
382 | * is changed. | 371 | * is changed. |
383 | */ | 372 | */ |
384 | static void | 373 | static void |
385 | publish_ve_stat_update () | 374 | publish_ve_stat_update() |
386 | { | 375 | { |
387 | GNUNET_STATISTICS_set (GST_stats, | 376 | GNUNET_STATISTICS_set(GST_stats, |
388 | gettext_noop ("# Addresses in validation map"), | 377 | gettext_noop("# Addresses in validation map"), |
389 | GNUNET_CONTAINER_multipeermap_size (validation_map), | 378 | GNUNET_CONTAINER_multipeermap_size(validation_map), |
390 | GNUNET_NO); | 379 | GNUNET_NO); |
391 | } | 380 | } |
392 | 381 | ||
393 | 382 | ||
@@ -401,19 +390,19 @@ publish_ve_stat_update () | |||
401 | * #GNUNET_NO if the entry does match | 390 | * #GNUNET_NO if the entry does match |
402 | */ | 391 | */ |
403 | static int | 392 | static int |
404 | validation_entry_match (void *cls, | 393 | validation_entry_match(void *cls, |
405 | const struct GNUNET_PeerIdentity *key, | 394 | const struct GNUNET_PeerIdentity *key, |
406 | void *value) | 395 | void *value) |
407 | { | 396 | { |
408 | struct ValidationEntryMatchContext *vemc = cls; | 397 | struct ValidationEntryMatchContext *vemc = cls; |
409 | struct ValidationEntry *ve = value; | 398 | struct ValidationEntry *ve = value; |
410 | 399 | ||
411 | if (0 == GNUNET_HELLO_address_cmp (ve->address, | 400 | if (0 == GNUNET_HELLO_address_cmp(ve->address, |
412 | vemc->address)) | 401 | vemc->address)) |
413 | { | 402 | { |
414 | vemc->ve = ve; | 403 | vemc->ve = ve; |
415 | return GNUNET_NO; | 404 | return GNUNET_NO; |
416 | } | 405 | } |
417 | return GNUNET_YES; | 406 | return GNUNET_YES; |
418 | } | 407 | } |
419 | 408 | ||
@@ -426,8 +415,8 @@ validation_entry_match (void *cls, | |||
426 | * @param state new state | 415 | * @param state new state |
427 | */ | 416 | */ |
428 | static void | 417 | static void |
429 | validation_entry_changed (struct ValidationEntry *ve, | 418 | validation_entry_changed(struct ValidationEntry *ve, |
430 | enum GNUNET_TRANSPORT_ValidationState state) | 419 | enum GNUNET_TRANSPORT_ValidationState state) |
431 | { | 420 | { |
432 | ve->state = state; | 421 | ve->state = state; |
433 | } | 422 | } |
@@ -442,9 +431,9 @@ validation_entry_changed (struct ValidationEntry *ve, | |||
442 | * @return #GNUNET_YES (continue to iterate) | 431 | * @return #GNUNET_YES (continue to iterate) |
443 | */ | 432 | */ |
444 | static int | 433 | static int |
445 | cleanup_validation_entry (void *cls, | 434 | cleanup_validation_entry(void *cls, |
446 | const struct GNUNET_PeerIdentity *key, | 435 | const struct GNUNET_PeerIdentity *key, |
447 | void *value) | 436 | void *value) |
448 | { | 437 | { |
449 | struct ValidationEntry *ve = value; | 438 | struct ValidationEntry *ve = value; |
450 | 439 | ||
@@ -452,47 +441,47 @@ cleanup_validation_entry (void *cls, | |||
452 | ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; | 441 | ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; |
453 | 442 | ||
454 | /* Notify about deleted entry */ | 443 | /* Notify about deleted entry */ |
455 | validation_entry_changed (ve, | 444 | validation_entry_changed(ve, |
456 | GNUNET_TRANSPORT_VS_REMOVE); | 445 | GNUNET_TRANSPORT_VS_REMOVE); |
457 | 446 | ||
458 | if (NULL != ve->bc) | 447 | if (NULL != ve->bc) |
459 | { | 448 | { |
460 | GST_blacklist_test_cancel (ve->bc); | 449 | GST_blacklist_test_cancel(ve->bc); |
461 | ve->bc = NULL; | 450 | ve->bc = NULL; |
462 | } | 451 | } |
463 | GNUNET_break (GNUNET_OK == | 452 | GNUNET_break(GNUNET_OK == |
464 | GNUNET_CONTAINER_multipeermap_remove (validation_map, | 453 | GNUNET_CONTAINER_multipeermap_remove(validation_map, |
465 | &ve->address->peer, | 454 | &ve->address->peer, |
466 | ve)); | 455 | ve)); |
467 | publish_ve_stat_update (); | 456 | publish_ve_stat_update(); |
468 | if (GNUNET_YES == ve->known_to_ats) | 457 | if (GNUNET_YES == ve->known_to_ats) |
469 | { | 458 | { |
470 | GST_ats_expire_address (ve->address); | 459 | GST_ats_expire_address(ve->address); |
471 | GNUNET_assert (GNUNET_NO == | 460 | GNUNET_assert(GNUNET_NO == |
472 | GST_ats_is_known_no_session (ve->address)); | 461 | GST_ats_is_known_no_session(ve->address)); |
473 | ve->known_to_ats = GNUNET_NO; | 462 | ve->known_to_ats = GNUNET_NO; |
474 | } | 463 | } |
475 | GNUNET_HELLO_address_free (ve->address); | 464 | GNUNET_HELLO_address_free(ve->address); |
476 | if (NULL != ve->timeout_task) | 465 | if (NULL != ve->timeout_task) |
477 | { | 466 | { |
478 | GNUNET_SCHEDULER_cancel (ve->timeout_task); | 467 | GNUNET_SCHEDULER_cancel(ve->timeout_task); |
479 | ve->timeout_task = NULL; | 468 | ve->timeout_task = NULL; |
480 | } | 469 | } |
481 | if (NULL != ve->revalidation_task) | 470 | if (NULL != ve->revalidation_task) |
482 | { | 471 | { |
483 | GNUNET_SCHEDULER_cancel (ve->revalidation_task); | 472 | GNUNET_SCHEDULER_cancel(ve->revalidation_task); |
484 | ve->revalidation_task = NULL; | 473 | ve->revalidation_task = NULL; |
485 | } | 474 | } |
486 | if ( (GNUNET_YES == ve->expecting_pong) && | 475 | if ((GNUNET_YES == ve->expecting_pong) && |
487 | (validations_running > 0) ) | 476 | (validations_running > 0)) |
488 | { | 477 | { |
489 | validations_running--; | 478 | validations_running--; |
490 | GNUNET_STATISTICS_set (GST_stats, | 479 | GNUNET_STATISTICS_set(GST_stats, |
491 | gettext_noop ("# validations running"), | 480 | gettext_noop("# validations running"), |
492 | validations_running, | 481 | validations_running, |
493 | GNUNET_NO); | 482 | GNUNET_NO); |
494 | } | 483 | } |
495 | GNUNET_free (ve); | 484 | GNUNET_free(ve); |
496 | return GNUNET_OK; | 485 | return GNUNET_OK; |
497 | } | 486 | } |
498 | 487 | ||
@@ -504,7 +493,7 @@ cleanup_validation_entry (void *cls, | |||
504 | * @param cls the `struct ValidationEntry` | 493 | * @param cls the `struct ValidationEntry` |
505 | */ | 494 | */ |
506 | static void | 495 | static void |
507 | timeout_hello_validation (void *cls) | 496 | timeout_hello_validation(void *cls) |
508 | { | 497 | { |
509 | struct ValidationEntry *ve = cls; | 498 | struct ValidationEntry *ve = cls; |
510 | struct GNUNET_TIME_Absolute max; | 499 | struct GNUNET_TIME_Absolute max; |
@@ -514,27 +503,27 @@ timeout_hello_validation (void *cls) | |||
514 | /* For valid addresses, we want to wait until the expire; | 503 | /* For valid addresses, we want to wait until the expire; |
515 | for addresses under PING validation, we want to wait | 504 | for addresses under PING validation, we want to wait |
516 | until we give up on the PING */ | 505 | until we give up on the PING */ |
517 | max = GNUNET_TIME_absolute_max (ve->valid_until, | 506 | max = GNUNET_TIME_absolute_max(ve->valid_until, |
518 | ve->revalidation_block); | 507 | ve->revalidation_block); |
519 | left = GNUNET_TIME_absolute_get_remaining (max); | 508 | left = GNUNET_TIME_absolute_get_remaining(max); |
520 | if (left.rel_value_us > 0) | 509 | if (left.rel_value_us > 0) |
521 | { | 510 | { |
522 | /* We should wait a bit longer. This happens when | 511 | /* We should wait a bit longer. This happens when |
523 | address lifetimes are extended due to successful | 512 | address lifetimes are extended due to successful |
524 | validations. */ | 513 | validations. */ |
525 | ve->timeout_task = | 514 | ve->timeout_task = |
526 | GNUNET_SCHEDULER_add_delayed (left, | 515 | GNUNET_SCHEDULER_add_delayed(left, |
527 | &timeout_hello_validation, | 516 | &timeout_hello_validation, |
528 | ve); | 517 | ve); |
529 | return; | 518 | return; |
530 | } | 519 | } |
531 | GNUNET_STATISTICS_update (GST_stats, | 520 | GNUNET_STATISTICS_update(GST_stats, |
532 | gettext_noop ("# address records discarded (timeout)"), | 521 | gettext_noop("# address records discarded (timeout)"), |
533 | 1, | 522 | 1, |
534 | GNUNET_NO); | 523 | GNUNET_NO); |
535 | cleanup_validation_entry (NULL, | 524 | cleanup_validation_entry(NULL, |
536 | &ve->address->peer, | 525 | &ve->address->peer, |
537 | ve); | 526 | ve); |
538 | } | 527 | } |
539 | 528 | ||
540 | 529 | ||
@@ -551,11 +540,11 @@ timeout_hello_validation (void *cls) | |||
551 | * #GNUNET_SYSERR if operation was aborted | 540 | * #GNUNET_SYSERR if operation was aborted |
552 | */ | 541 | */ |
553 | static void | 542 | static void |
554 | transmit_ping_if_allowed (void *cls, | 543 | transmit_ping_if_allowed(void *cls, |
555 | const struct GNUNET_PeerIdentity *pid, | 544 | const struct GNUNET_PeerIdentity *pid, |
556 | const struct GNUNET_HELLO_Address *address_null, | 545 | const struct GNUNET_HELLO_Address *address_null, |
557 | struct GNUNET_ATS_Session *session_null, | 546 | struct GNUNET_ATS_Session *session_null, |
558 | int result) | 547 | int result) |
559 | { | 548 | { |
560 | struct ValidationEntry *ve = cls; | 549 | struct ValidationEntry *ve = cls; |
561 | struct TransportPingMessage ping; | 550 | struct TransportPingMessage ping; |
@@ -570,117 +559,116 @@ transmit_ping_if_allowed (void *cls, | |||
570 | 559 | ||
571 | ve->bc = NULL; | 560 | ve->bc = NULL; |
572 | if (GNUNET_OK != result) | 561 | if (GNUNET_OK != result) |
573 | { | 562 | { |
574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 563 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
575 | "Blacklist denies sending PING to `%s' `%s' `%s'\n", | 564 | "Blacklist denies sending PING to `%s' `%s' `%s'\n", |
576 | GNUNET_i2s (pid), | 565 | GNUNET_i2s(pid), |
577 | GST_plugins_a2s (ve->address), | 566 | GST_plugins_a2s(ve->address), |
578 | ve->address->transport_name); | 567 | ve->address->transport_name); |
579 | GNUNET_STATISTICS_update (GST_stats, | 568 | GNUNET_STATISTICS_update(GST_stats, |
580 | gettext_noop ("# address records discarded (blacklist)"), | 569 | gettext_noop("# address records discarded (blacklist)"), |
581 | 1, | 570 | 1, |
582 | GNUNET_NO); | 571 | GNUNET_NO); |
583 | cleanup_validation_entry (NULL, | 572 | cleanup_validation_entry(NULL, |
584 | pid, | 573 | pid, |
585 | ve); | 574 | ve); |
586 | return; | 575 | return; |
587 | } | 576 | } |
588 | hello = GST_hello_get (); | 577 | hello = GST_hello_get(); |
589 | GNUNET_assert (NULL != hello); | 578 | GNUNET_assert(NULL != hello); |
590 | slen = strlen (ve->address->transport_name) + 1; | 579 | slen = strlen(ve->address->transport_name) + 1; |
591 | hsize = ntohs (hello->size); | 580 | hsize = ntohs(hello->size); |
592 | tsize = sizeof (struct TransportPingMessage) + | 581 | tsize = sizeof(struct TransportPingMessage) + |
593 | ve->address->address_length + slen + hsize; | 582 | ve->address->address_length + slen + hsize; |
594 | 583 | ||
595 | ping.header.size = | 584 | ping.header.size = |
596 | htons (sizeof (struct TransportPingMessage) + | 585 | htons(sizeof(struct TransportPingMessage) + |
597 | ve->address->address_length + slen); | 586 | ve->address->address_length + slen); |
598 | ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); | 587 | ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); |
599 | ping.challenge = htonl (ve->challenge); | 588 | ping.challenge = htonl(ve->challenge); |
600 | ping.target = *pid; | 589 | ping.target = *pid; |
601 | 590 | ||
602 | if (tsize >= GNUNET_MAX_MESSAGE_SIZE) | 591 | if (tsize >= GNUNET_MAX_MESSAGE_SIZE) |
603 | { | 592 | { |
604 | GNUNET_break (0); | 593 | GNUNET_break(0); |
605 | hsize = 0; | 594 | hsize = 0; |
606 | tsize = | 595 | tsize = |
607 | sizeof (struct TransportPingMessage) + ve->address->address_length + | 596 | sizeof(struct TransportPingMessage) + ve->address->address_length + |
608 | slen + hsize; | 597 | slen + hsize; |
609 | } | 598 | } |
610 | { | 599 | { |
611 | char message_buf[tsize] GNUNET_ALIGN; | 600 | char message_buf[tsize] GNUNET_ALIGN; |
612 | 601 | ||
613 | GNUNET_memcpy (message_buf, | 602 | GNUNET_memcpy(message_buf, |
614 | hello, | 603 | hello, |
615 | hsize); | 604 | hsize); |
616 | GNUNET_memcpy (&message_buf[hsize], | 605 | GNUNET_memcpy(&message_buf[hsize], |
617 | &ping, | 606 | &ping, |
618 | sizeof (struct TransportPingMessage)); | 607 | sizeof(struct TransportPingMessage)); |
619 | GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize], | 608 | GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + hsize], |
620 | ve->address->transport_name, | 609 | ve->address->transport_name, |
621 | slen); | 610 | slen); |
622 | GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], | 611 | GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + slen + hsize], |
623 | ve->address->address, | 612 | ve->address->address, |
624 | ve->address->address_length); | 613 | ve->address->address_length); |
625 | papi = GST_plugins_find (ve->address->transport_name); | 614 | papi = GST_plugins_find(ve->address->transport_name); |
626 | GNUNET_assert (NULL != papi); | 615 | GNUNET_assert(NULL != papi); |
627 | session = papi->get_session (papi->cls, | 616 | session = papi->get_session(papi->cls, |
628 | ve->address); | 617 | ve->address); |
629 | if (NULL == session) | 618 | if (NULL == session) |
630 | { | 619 | { |
631 | /* Could not get a valid session */ | 620 | /* Could not get a valid session */ |
632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 621 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
633 | "Failed to get session to send PING to `%s' at `%s'\n", | 622 | "Failed to get session to send PING to `%s' at `%s'\n", |
634 | GNUNET_i2s (pid), | 623 | GNUNET_i2s(pid), |
635 | GST_plugins_a2s (ve->address)); | 624 | GST_plugins_a2s(ve->address)); |
636 | return; | 625 | return; |
637 | } | 626 | } |
638 | 627 | ||
639 | ret = papi->send (papi->cls, session, | 628 | ret = papi->send(papi->cls, session, |
640 | message_buf, tsize, | 629 | message_buf, tsize, |
641 | PING_PRIORITY, | 630 | PING_PRIORITY, |
642 | ACCEPTABLE_PING_DELAY, | 631 | ACCEPTABLE_PING_DELAY, |
643 | NULL, NULL); | 632 | NULL, NULL); |
644 | if (-1 == ret) | 633 | if (-1 == ret) |
645 | { | 634 | { |
646 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 635 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
647 | "Failed to send PING to `%s' at `%s'\n", | 636 | "Failed to send PING to `%s' at `%s'\n", |
648 | GNUNET_i2s (pid), | 637 | GNUNET_i2s(pid), |
649 | GST_plugins_a2s (ve->address)); | 638 | GST_plugins_a2s(ve->address)); |
650 | return; | 639 | return; |
651 | } | 640 | } |
652 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 641 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
653 | "Transmitted plain PING to `%s' `%s' `%s'\n", | 642 | "Transmitted plain PING to `%s' `%s' `%s'\n", |
654 | GNUNET_i2s (pid), | 643 | GNUNET_i2s(pid), |
655 | GST_plugins_a2s (ve->address), | 644 | GST_plugins_a2s(ve->address), |
656 | ve->address->transport_name); | 645 | ve->address->transport_name); |
657 | ve->network = papi->get_network (papi->cls, | 646 | ve->network = papi->get_network(papi->cls, |
658 | session); | 647 | session); |
659 | GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); | 648 | GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); |
660 | GST_neighbours_notify_data_sent (ve->address, | 649 | GST_neighbours_notify_data_sent(ve->address, |
661 | session, | 650 | session, |
662 | tsize); | 651 | tsize); |
663 | next = GNUNET_TIME_relative_to_absolute (validation_delay); | 652 | next = GNUNET_TIME_relative_to_absolute(validation_delay); |
664 | validation_next = GNUNET_TIME_absolute_max (next, | 653 | validation_next = GNUNET_TIME_absolute_max(next, |
665 | validation_next); | 654 | validation_next); |
666 | ve->send_time = GNUNET_TIME_absolute_get (); | 655 | ve->send_time = GNUNET_TIME_absolute_get(); |
667 | GNUNET_STATISTICS_update (GST_stats, | 656 | GNUNET_STATISTICS_update(GST_stats, |
668 | gettext_noop ("# PINGs for address validation sent"), | 657 | gettext_noop("# PINGs for address validation sent"), |
669 | 1, | 658 | 1, |
670 | GNUNET_NO); | 659 | GNUNET_NO); |
671 | ve->expecting_pong = GNUNET_YES; | 660 | ve->expecting_pong = GNUNET_YES; |
672 | validations_running++; | 661 | validations_running++; |
673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 662 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
674 | "Validation started, %u validation processes running\n", | 663 | "Validation started, %u validation processes running\n", |
675 | validations_running); | 664 | validations_running); |
676 | GNUNET_STATISTICS_set (GST_stats, | 665 | GNUNET_STATISTICS_set(GST_stats, |
677 | gettext_noop ("# validations running"), | 666 | gettext_noop("# validations running"), |
678 | validations_running, | 667 | validations_running, |
679 | GNUNET_NO); | 668 | GNUNET_NO); |
680 | /* Notify about PING sent */ | 669 | /* Notify about PING sent */ |
681 | validation_entry_changed (ve, | 670 | validation_entry_changed(ve, |
682 | GNUNET_TRANSPORT_VS_UPDATE); | 671 | GNUNET_TRANSPORT_VS_UPDATE); |
683 | |||
684 | } | 672 | } |
685 | } | 673 | } |
686 | 674 | ||
@@ -691,7 +679,7 @@ transmit_ping_if_allowed (void *cls, | |||
691 | * @param cls the `struct ValidationEntry` | 679 | * @param cls the `struct ValidationEntry` |
692 | */ | 680 | */ |
693 | static void | 681 | static void |
694 | revalidate_address (void *cls) | 682 | revalidate_address(void *cls) |
695 | { | 683 | { |
696 | struct ValidationEntry *ve = cls; | 684 | struct ValidationEntry *ve = cls; |
697 | struct GNUNET_TIME_Relative canonical_delay; | 685 | struct GNUNET_TIME_Relative canonical_delay; |
@@ -701,12 +689,12 @@ revalidate_address (void *cls) | |||
701 | uint32_t rdelay; | 689 | uint32_t rdelay; |
702 | 690 | ||
703 | ve->revalidation_task = NULL; | 691 | ve->revalidation_task = NULL; |
704 | delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); | 692 | delay = GNUNET_TIME_absolute_get_remaining(ve->revalidation_block); |
705 | /* Considering current connectivity situation, what is the maximum | 693 | /* Considering current connectivity situation, what is the maximum |
706 | block period permitted? */ | 694 | block period permitted? */ |
707 | if (GNUNET_YES == ve->in_use) | 695 | if (GNUNET_YES == ve->in_use) |
708 | canonical_delay = CONNECTED_PING_FREQUENCY; | 696 | canonical_delay = CONNECTED_PING_FREQUENCY; |
709 | else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0) | 697 | else if (GNUNET_TIME_absolute_get_remaining(ve->valid_until).rel_value_us > 0) |
710 | canonical_delay = VALIDATED_PING_FREQUENCY; | 698 | canonical_delay = VALIDATED_PING_FREQUENCY; |
711 | else | 699 | else |
712 | canonical_delay = UNVALIDATED_PING_KEEPALIVE; | 700 | canonical_delay = UNVALIDATED_PING_KEEPALIVE; |
@@ -714,94 +702,94 @@ revalidate_address (void *cls) | |||
714 | new maximum delay (which may be lower); the real delay | 702 | new maximum delay (which may be lower); the real delay |
715 | is originally randomized between "canonical_delay" and "2 * canonical_delay", | 703 | is originally randomized between "canonical_delay" and "2 * canonical_delay", |
716 | so continue to permit that window for the operation. */ | 704 | so continue to permit that window for the operation. */ |
717 | delay = GNUNET_TIME_relative_min (delay, | 705 | delay = GNUNET_TIME_relative_min(delay, |
718 | GNUNET_TIME_relative_multiply (canonical_delay, | 706 | GNUNET_TIME_relative_multiply(canonical_delay, |
719 | 2)); | 707 | 2)); |
720 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); | 708 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute(delay); |
721 | if (delay.rel_value_us > 0) | 709 | if (delay.rel_value_us > 0) |
722 | { | 710 | { |
723 | /* should wait a bit longer */ | 711 | /* should wait a bit longer */ |
724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 712 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
725 | "Waiting for %s longer before (re)validating address `%s'\n", | 713 | "Waiting for %s longer before (re)validating address `%s'\n", |
726 | GNUNET_STRINGS_relative_time_to_string (delay, | 714 | GNUNET_STRINGS_relative_time_to_string(delay, |
727 | GNUNET_YES), | 715 | GNUNET_YES), |
728 | GST_plugins_a2s (ve->address)); | 716 | GST_plugins_a2s(ve->address)); |
729 | ve->revalidation_task = | 717 | ve->revalidation_task = |
730 | GNUNET_SCHEDULER_add_delayed (delay, | 718 | GNUNET_SCHEDULER_add_delayed(delay, |
731 | &revalidate_address, ve); | 719 | &revalidate_address, ve); |
732 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); | 720 | ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); |
733 | return; | 721 | return; |
734 | } | 722 | } |
735 | /* check if globally we have too many active validations at a | 723 | /* check if globally we have too many active validations at a |
736 | too high rate, if so, delay ours */ | 724 | too high rate, if so, delay ours */ |
737 | blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next); | 725 | blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); |
738 | if ( (validations_running > validations_fast_start_threshold) && | 726 | if ((validations_running > validations_fast_start_threshold) && |
739 | (blocked_for.rel_value_us > 0) ) | 727 | (blocked_for.rel_value_us > 0)) |
740 | { | 728 | { |
741 | /* Validations are blocked, have to wait for blocked_for time */ | 729 | /* Validations are blocked, have to wait for blocked_for time */ |
742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 730 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
743 | "Validations blocked for another %s, delaying validating address `%s'\n", | 731 | "Validations blocked for another %s, delaying validating address `%s'\n", |
744 | GNUNET_STRINGS_relative_time_to_string (blocked_for, | 732 | GNUNET_STRINGS_relative_time_to_string(blocked_for, |
745 | GNUNET_YES), | 733 | GNUNET_YES), |
746 | GST_plugins_a2s (ve->address)); | 734 | GST_plugins_a2s(ve->address)); |
747 | GNUNET_STATISTICS_update (GST_stats, | 735 | GNUNET_STATISTICS_update(GST_stats, |
748 | gettext_noop ("# validations delayed by global throttle"), | 736 | gettext_noop("# validations delayed by global throttle"), |
749 | 1, | 737 | 1, |
750 | GNUNET_NO); | 738 | GNUNET_NO); |
751 | ve->revalidation_task = | 739 | ve->revalidation_task = |
752 | GNUNET_SCHEDULER_add_delayed (blocked_for, | 740 | GNUNET_SCHEDULER_add_delayed(blocked_for, |
753 | &revalidate_address, | 741 | &revalidate_address, |
754 | ve); | 742 | ve); |
755 | ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for); | 743 | ve->next_validation = GNUNET_TIME_relative_to_absolute(blocked_for); |
756 | return; | 744 | return; |
757 | } | 745 | } |
758 | 746 | ||
759 | /* We are good to go; remember to not go again for `canonical_delay` time; | 747 | /* We are good to go; remember to not go again for `canonical_delay` time; |
760 | add up to `canonical_delay` to randomize start time */ | 748 | add up to `canonical_delay` to randomize start time */ |
761 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); | 749 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute(canonical_delay); |
762 | /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ | 750 | /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ |
763 | rdelay = | 751 | rdelay = |
764 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 752 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
765 | canonical_delay.rel_value_us); | 753 | canonical_delay.rel_value_us); |
766 | 754 | ||
767 | delay = GNUNET_TIME_relative_add (canonical_delay, | 755 | delay = GNUNET_TIME_relative_add(canonical_delay, |
768 | GNUNET_TIME_relative_multiply | 756 | GNUNET_TIME_relative_multiply |
769 | (GNUNET_TIME_UNIT_MICROSECONDS, | 757 | (GNUNET_TIME_UNIT_MICROSECONDS, |
770 | rdelay)); | 758 | rdelay)); |
771 | 759 | ||
772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 760 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
773 | "Validating now, next scheduled for %s, now validating address `%s'\n", | 761 | "Validating now, next scheduled for %s, now validating address `%s'\n", |
774 | GNUNET_STRINGS_relative_time_to_string (blocked_for, | 762 | GNUNET_STRINGS_relative_time_to_string(blocked_for, |
775 | GNUNET_YES), | 763 | GNUNET_YES), |
776 | GST_plugins_a2s (ve->address)); | 764 | GST_plugins_a2s(ve->address)); |
777 | ve->revalidation_task = | 765 | ve->revalidation_task = |
778 | GNUNET_SCHEDULER_add_delayed (delay, | 766 | GNUNET_SCHEDULER_add_delayed(delay, |
779 | &revalidate_address, | 767 | &revalidate_address, |
780 | ve); | 768 | ve); |
781 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); | 769 | ve->next_validation = GNUNET_TIME_relative_to_absolute(delay); |
782 | 770 | ||
783 | /* start PINGing by checking blacklist */ | 771 | /* start PINGing by checking blacklist */ |
784 | GNUNET_STATISTICS_update (GST_stats, | 772 | GNUNET_STATISTICS_update(GST_stats, |
785 | gettext_noop ("# address revalidations started"), 1, | 773 | gettext_noop("# address revalidations started"), 1, |
786 | GNUNET_NO); | 774 | GNUNET_NO); |
787 | if (NULL != ve->bc) | 775 | if (NULL != ve->bc) |
788 | { | 776 | { |
789 | GST_blacklist_test_cancel (ve->bc); | 777 | GST_blacklist_test_cancel(ve->bc); |
790 | ve->bc = NULL; | 778 | ve->bc = NULL; |
791 | } | 779 | } |
792 | bc = GST_blacklist_test_allowed (&ve->address->peer, | 780 | bc = GST_blacklist_test_allowed(&ve->address->peer, |
793 | ve->address->transport_name, | 781 | ve->address->transport_name, |
794 | &transmit_ping_if_allowed, | 782 | &transmit_ping_if_allowed, |
795 | ve, | 783 | ve, |
796 | NULL, | 784 | NULL, |
797 | NULL); | 785 | NULL); |
798 | if (NULL != bc) | 786 | if (NULL != bc) |
799 | { | 787 | { |
800 | /* If transmit_ping_if_allowed was already called it may have freed ve, | 788 | /* If transmit_ping_if_allowed was already called it may have freed ve, |
801 | * so only set ve->bc if it has not been called. | 789 | * so only set ve->bc if it has not been called. |
802 | */ | 790 | */ |
803 | ve->bc = bc; | 791 | ve->bc = bc; |
804 | } | 792 | } |
805 | } | 793 | } |
806 | 794 | ||
807 | 795 | ||
@@ -815,41 +803,41 @@ revalidate_address (void *cls) | |||
815 | * if we don't have an existing entry and no public key was given | 803 | * if we don't have an existing entry and no public key was given |
816 | */ | 804 | */ |
817 | static struct ValidationEntry * | 805 | static struct ValidationEntry * |
818 | find_validation_entry (const struct GNUNET_HELLO_Address *address) | 806 | find_validation_entry(const struct GNUNET_HELLO_Address *address) |
819 | { | 807 | { |
820 | struct ValidationEntryMatchContext vemc; | 808 | struct ValidationEntryMatchContext vemc; |
821 | struct ValidationEntry *ve; | 809 | struct ValidationEntry *ve; |
822 | 810 | ||
823 | vemc.ve = NULL; | 811 | vemc.ve = NULL; |
824 | vemc.address = address; | 812 | vemc.address = address; |
825 | GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 813 | GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, |
826 | &address->peer, | 814 | &address->peer, |
827 | &validation_entry_match, &vemc); | 815 | &validation_entry_match, &vemc); |
828 | if (NULL != (ve = vemc.ve)) | 816 | if (NULL != (ve = vemc.ve)) |
829 | return ve; | 817 | return ve; |
830 | GNUNET_assert (GNUNET_NO == | 818 | GNUNET_assert(GNUNET_NO == |
831 | GST_ats_is_known_no_session (address)); | 819 | GST_ats_is_known_no_session(address)); |
832 | ve = GNUNET_new (struct ValidationEntry); | 820 | ve = GNUNET_new(struct ValidationEntry); |
833 | ve->in_use = GNUNET_SYSERR; /* not defined */ | 821 | ve->in_use = GNUNET_SYSERR; /* not defined */ |
834 | ve->address = GNUNET_HELLO_address_copy (address); | 822 | ve->address = GNUNET_HELLO_address_copy(address); |
835 | ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; | 823 | ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; |
836 | memset (&ve->pong_sig_cache, | 824 | memset(&ve->pong_sig_cache, |
837 | '\0', | 825 | '\0', |
838 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | 826 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)); |
839 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; | 827 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; |
840 | ve->challenge = | 828 | ve->challenge = |
841 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 829 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
842 | ve->timeout_task = | 830 | ve->timeout_task = |
843 | GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, | 831 | GNUNET_SCHEDULER_add_delayed(UNVALIDATED_PING_KEEPALIVE, |
844 | &timeout_hello_validation, | 832 | &timeout_hello_validation, |
845 | ve); | 833 | ve); |
846 | GNUNET_CONTAINER_multipeermap_put (validation_map, | 834 | GNUNET_CONTAINER_multipeermap_put(validation_map, |
847 | &address->peer, | 835 | &address->peer, |
848 | ve, | 836 | ve, |
849 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 837 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
850 | publish_ve_stat_update (); | 838 | publish_ve_stat_update(); |
851 | validation_entry_changed (ve, | 839 | validation_entry_changed(ve, |
852 | GNUNET_TRANSPORT_VS_NEW); | 840 | GNUNET_TRANSPORT_VS_NEW); |
853 | return ve; | 841 | return ve; |
854 | } | 842 | } |
855 | 843 | ||
@@ -866,9 +854,9 @@ find_validation_entry (const struct GNUNET_HELLO_Address *address) | |||
866 | * #GNUNET_SYSERR would abort iteration (but we always iterate all) | 854 | * #GNUNET_SYSERR would abort iteration (but we always iterate all) |
867 | */ | 855 | */ |
868 | static int | 856 | static int |
869 | add_valid_address (void *cls, | 857 | add_valid_address(void *cls, |
870 | const struct GNUNET_HELLO_Address *address, | 858 | const struct GNUNET_HELLO_Address *address, |
871 | struct GNUNET_TIME_Absolute expiration) | 859 | struct GNUNET_TIME_Absolute expiration) |
872 | { | 860 | { |
873 | const struct GNUNET_HELLO_Message *hello = cls; | 861 | const struct GNUNET_HELLO_Message *hello = cls; |
874 | struct ValidationEntry *ve; | 862 | struct ValidationEntry *ve; |
@@ -876,60 +864,60 @@ add_valid_address (void *cls, | |||
876 | struct GNUNET_ATS_Properties prop; | 864 | struct GNUNET_ATS_Properties prop; |
877 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 865 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
878 | 866 | ||
879 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 867 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) |
880 | return GNUNET_OK; /* expired */ | 868 | return GNUNET_OK; /* expired */ |
881 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 869 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) |
882 | { | 870 | { |
883 | GNUNET_break (0); | 871 | GNUNET_break(0); |
884 | return GNUNET_OK; /* invalid HELLO !? */ | 872 | return GNUNET_OK; /* invalid HELLO !? */ |
885 | } | 873 | } |
886 | if (NULL == (papi = GST_plugins_find (address->transport_name))) | 874 | if (NULL == (papi = GST_plugins_find(address->transport_name))) |
887 | { | 875 | { |
888 | /* might have been valid in the past, but we don't have that | 876 | /* might have been valid in the past, but we don't have that |
889 | plugin loaded right now */ | 877 | plugin loaded right now */ |
890 | return GNUNET_OK; | 878 | return GNUNET_OK; |
891 | } | 879 | } |
892 | if (NULL == | 880 | if (NULL == |
893 | papi->address_to_string (papi->cls, | 881 | papi->address_to_string(papi->cls, |
894 | address->address, | 882 | address->address, |
895 | address->address_length)) | 883 | address->address_length)) |
896 | { | 884 | { |
897 | /* Why do we try to add an ill-formed address? */ | 885 | /* Why do we try to add an ill-formed address? */ |
898 | GNUNET_break (0); | 886 | GNUNET_break(0); |
899 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 887 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
900 | "Address with %u bytes for plugin %s and peer %s is malformed\n", | 888 | "Address with %u bytes for plugin %s and peer %s is malformed\n", |
901 | (unsigned int) address->address_length, | 889 | (unsigned int)address->address_length, |
902 | address->transport_name, | 890 | address->transport_name, |
903 | GNUNET_i2s (&pid)); | 891 | GNUNET_i2s(&pid)); |
904 | return GNUNET_OK; | 892 | return GNUNET_OK; |
905 | } | 893 | } |
906 | 894 | ||
907 | ve = find_validation_entry (address); | 895 | ve = find_validation_entry(address); |
908 | ve->network = papi->get_network_for_address (papi->cls, | 896 | ve->network = papi->get_network_for_address(papi->cls, |
909 | address); | 897 | address); |
910 | GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); | 898 | GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); |
911 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, | 899 | ve->valid_until = GNUNET_TIME_absolute_max(ve->valid_until, |
912 | expiration); | 900 | expiration); |
913 | if (NULL == ve->revalidation_task) | 901 | if (NULL == ve->revalidation_task) |
914 | { | 902 | { |
915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 903 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
916 | "Starting revalidations for valid address `%s'\n", | 904 | "Starting revalidations for valid address `%s'\n", |
917 | GST_plugins_a2s (ve->address)); | 905 | GST_plugins_a2s(ve->address)); |
918 | ve->next_validation = GNUNET_TIME_absolute_get(); | 906 | ve->next_validation = GNUNET_TIME_absolute_get(); |
919 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | 907 | ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); |
920 | } | 908 | } |
921 | validation_entry_changed (ve, | 909 | validation_entry_changed(ve, |
922 | GNUNET_TRANSPORT_VS_UPDATE); | 910 | GNUNET_TRANSPORT_VS_UPDATE); |
923 | memset (&prop, 0, sizeof (prop)); | 911 | memset(&prop, 0, sizeof(prop)); |
924 | prop.scope = ve->network; | 912 | prop.scope = ve->network; |
925 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); | 913 | prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2); |
926 | if (GNUNET_YES != ve->known_to_ats) | 914 | if (GNUNET_YES != ve->known_to_ats) |
927 | { | 915 | { |
928 | ve->known_to_ats = GNUNET_YES; | 916 | ve->known_to_ats = GNUNET_YES; |
929 | GST_ats_add_address (address, &prop); | 917 | GST_ats_add_address(address, &prop); |
930 | GNUNET_assert (GNUNET_YES == | 918 | GNUNET_assert(GNUNET_YES == |
931 | GST_ats_is_known_no_session (ve->address)); | 919 | GST_ats_is_known_no_session(ve->address)); |
932 | } | 920 | } |
933 | return GNUNET_OK; | 921 | return GNUNET_OK; |
934 | } | 922 | } |
935 | 923 | ||
@@ -944,28 +932,28 @@ add_valid_address (void *cls, | |||
944 | * @param err_msg error message | 932 | * @param err_msg error message |
945 | */ | 933 | */ |
946 | static void | 934 | static void |
947 | process_peerinfo_hello (void *cls, | 935 | process_peerinfo_hello(void *cls, |
948 | const struct GNUNET_PeerIdentity *peer, | 936 | const struct GNUNET_PeerIdentity *peer, |
949 | const struct GNUNET_HELLO_Message *hello, | 937 | const struct GNUNET_HELLO_Message *hello, |
950 | const char *err_msg) | 938 | const char *err_msg) |
951 | { | 939 | { |
952 | GNUNET_assert (NULL != peer); | 940 | GNUNET_assert(NULL != peer); |
953 | if (NULL == hello) | 941 | if (NULL == hello) |
954 | return; | 942 | return; |
955 | if (0 == memcmp (&GST_my_identity, | 943 | if (0 == memcmp(&GST_my_identity, |
956 | peer, | 944 | peer, |
957 | sizeof (struct GNUNET_PeerIdentity))) | 945 | sizeof(struct GNUNET_PeerIdentity))) |
958 | { | 946 | { |
959 | /* Peerinfo returned own identity, skip validation */ | 947 | /* Peerinfo returned own identity, skip validation */ |
960 | return; | 948 | return; |
961 | } | 949 | } |
962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 950 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
963 | "Handling HELLO for peer `%s'\n", | 951 | "Handling HELLO for peer `%s'\n", |
964 | GNUNET_i2s (peer)); | 952 | GNUNET_i2s(peer)); |
965 | GNUNET_assert (NULL == | 953 | GNUNET_assert(NULL == |
966 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, | 954 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, |
967 | &add_valid_address, | 955 | &add_valid_address, |
968 | (void *) hello)); | 956 | (void *)hello)); |
969 | } | 957 | } |
970 | 958 | ||
971 | 959 | ||
@@ -975,7 +963,7 @@ process_peerinfo_hello (void *cls, | |||
975 | * @param max_fds maximum number of fds to use | 963 | * @param max_fds maximum number of fds to use |
976 | */ | 964 | */ |
977 | void | 965 | void |
978 | GST_validation_start (unsigned int max_fds) | 966 | GST_validation_start(unsigned int max_fds) |
979 | { | 967 | { |
980 | /** | 968 | /** |
981 | * Initialization for validation throttling | 969 | * Initialization for validation throttling |
@@ -993,19 +981,19 @@ GST_validation_start (unsigned int max_fds) | |||
993 | validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); | 981 | validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); |
994 | validations_fast_start_threshold = (max_fds / 2); | 982 | validations_fast_start_threshold = (max_fds / 2); |
995 | validations_running = 0; | 983 | validations_running = 0; |
996 | GNUNET_STATISTICS_set (GST_stats, | 984 | GNUNET_STATISTICS_set(GST_stats, |
997 | gettext_noop ("# validations running"), | 985 | gettext_noop("# validations running"), |
998 | validations_running, | 986 | validations_running, |
999 | GNUNET_NO); | 987 | GNUNET_NO); |
1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 988 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1001 | "Validation uses a fast start threshold of %u connections and a delay of %s\n", | 989 | "Validation uses a fast start threshold of %u connections and a delay of %s\n", |
1002 | validations_fast_start_threshold, | 990 | validations_fast_start_threshold, |
1003 | GNUNET_STRINGS_relative_time_to_string (validation_delay, | 991 | GNUNET_STRINGS_relative_time_to_string(validation_delay, |
1004 | GNUNET_YES)); | 992 | GNUNET_YES)); |
1005 | validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE, | 993 | validation_map = GNUNET_CONTAINER_multipeermap_create(VALIDATION_MAP_SIZE, |
1006 | GNUNET_NO); | 994 | GNUNET_NO); |
1007 | pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, | 995 | pnc = GNUNET_PEERINFO_notify(GST_cfg, GNUNET_YES, |
1008 | &process_peerinfo_hello, NULL); | 996 | &process_peerinfo_hello, NULL); |
1009 | } | 997 | } |
1010 | 998 | ||
1011 | 999 | ||
@@ -1013,14 +1001,14 @@ GST_validation_start (unsigned int max_fds) | |||
1013 | * Stop the validation subsystem. | 1001 | * Stop the validation subsystem. |
1014 | */ | 1002 | */ |
1015 | void | 1003 | void |
1016 | GST_validation_stop () | 1004 | GST_validation_stop() |
1017 | { | 1005 | { |
1018 | GNUNET_CONTAINER_multipeermap_iterate (validation_map, | 1006 | GNUNET_CONTAINER_multipeermap_iterate(validation_map, |
1019 | &cleanup_validation_entry, | 1007 | &cleanup_validation_entry, |
1020 | NULL); | 1008 | NULL); |
1021 | GNUNET_CONTAINER_multipeermap_destroy (validation_map); | 1009 | GNUNET_CONTAINER_multipeermap_destroy(validation_map); |
1022 | validation_map = NULL; | 1010 | validation_map = NULL; |
1023 | GNUNET_PEERINFO_notify_cancel (pnc); | 1011 | GNUNET_PEERINFO_notify_cancel(pnc); |
1024 | } | 1012 | } |
1025 | 1013 | ||
1026 | 1014 | ||
@@ -1036,41 +1024,41 @@ GST_validation_stop () | |||
1036 | * @param address target address | 1024 | * @param address target address |
1037 | */ | 1025 | */ |
1038 | static void | 1026 | static void |
1039 | multicast_pong (void *cls, | 1027 | multicast_pong(void *cls, |
1040 | struct GNUNET_TIME_Absolute valid_until, | 1028 | struct GNUNET_TIME_Absolute valid_until, |
1041 | struct GNUNET_TIME_Absolute validation_block, | 1029 | struct GNUNET_TIME_Absolute validation_block, |
1042 | const struct GNUNET_HELLO_Address *address) | 1030 | const struct GNUNET_HELLO_Address *address) |
1043 | { | 1031 | { |
1044 | struct TransportPongMessage *pong = cls; | 1032 | struct TransportPongMessage *pong = cls; |
1045 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 1033 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
1046 | struct GNUNET_ATS_Session *session; | 1034 | struct GNUNET_ATS_Session *session; |
1047 | 1035 | ||
1048 | papi = GST_plugins_find (address->transport_name); | 1036 | papi = GST_plugins_find(address->transport_name); |
1049 | if (NULL == papi) | 1037 | if (NULL == papi) |
1050 | { | 1038 | { |
1051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1039 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1052 | "Plugin %s not supported, cannot send PONG\n", | 1040 | "Plugin %s not supported, cannot send PONG\n", |
1053 | address->transport_name); | 1041 | address->transport_name); |
1054 | return; | 1042 | return; |
1055 | } | 1043 | } |
1056 | GNUNET_assert (NULL != papi->send); | 1044 | GNUNET_assert(NULL != papi->send); |
1057 | GNUNET_assert (NULL != papi->get_session); | 1045 | GNUNET_assert(NULL != papi->get_session); |
1058 | session = papi->get_session(papi->cls, address); | 1046 | session = papi->get_session(papi->cls, address); |
1059 | if (NULL == session) | 1047 | if (NULL == session) |
1060 | { | 1048 | { |
1061 | GNUNET_break (0); | 1049 | GNUNET_break(0); |
1062 | return; | 1050 | return; |
1063 | } | 1051 | } |
1064 | GST_ats_new_session (address, session); | 1052 | GST_ats_new_session(address, session); |
1065 | papi->send (papi->cls, session, | 1053 | papi->send(papi->cls, session, |
1066 | (const char *) pong, | 1054 | (const char *)pong, |
1067 | ntohs (pong->header.size), | 1055 | ntohs(pong->header.size), |
1068 | PONG_PRIORITY, | 1056 | PONG_PRIORITY, |
1069 | ACCEPTABLE_PING_DELAY, | 1057 | ACCEPTABLE_PING_DELAY, |
1070 | NULL, NULL); | 1058 | NULL, NULL); |
1071 | GST_neighbours_notify_data_sent (address, | 1059 | GST_neighbours_notify_data_sent(address, |
1072 | session, | 1060 | session, |
1073 | pong->header.size); | 1061 | pong->header.size); |
1074 | } | 1062 | } |
1075 | 1063 | ||
1076 | 1064 | ||
@@ -1084,10 +1072,10 @@ multicast_pong (void *cls, | |||
1084 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error | 1072 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error |
1085 | */ | 1073 | */ |
1086 | int | 1074 | int |
1087 | GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | 1075 | GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender, |
1088 | const struct GNUNET_MessageHeader *hdr, | 1076 | const struct GNUNET_MessageHeader *hdr, |
1089 | const struct GNUNET_HELLO_Address *sender_address, | 1077 | const struct GNUNET_HELLO_Address *sender_address, |
1090 | struct GNUNET_ATS_Session *session) | 1078 | struct GNUNET_ATS_Session *session) |
1091 | { | 1079 | { |
1092 | const struct TransportPingMessage *ping; | 1080 | const struct TransportPingMessage *ping; |
1093 | struct TransportPongMessage *pong; | 1081 | struct TransportPongMessage *pong; |
@@ -1104,32 +1092,32 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
1104 | struct GNUNET_HELLO_Address address; | 1092 | struct GNUNET_HELLO_Address address; |
1105 | 1093 | ||
1106 | if (0 == | 1094 | if (0 == |
1107 | memcmp (&GST_my_identity, | 1095 | memcmp(&GST_my_identity, |
1108 | sender, | 1096 | sender, |
1109 | sizeof (struct GNUNET_PeerIdentity))) | 1097 | sizeof(struct GNUNET_PeerIdentity))) |
1110 | return GNUNET_OK; /* our own, ignore! */ | 1098 | return GNUNET_OK; /* our own, ignore! */ |
1111 | if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) | 1099 | if (ntohs(hdr->size) < sizeof(struct TransportPingMessage)) |
1112 | { | 1100 | { |
1113 | GNUNET_break_op (0); | 1101 | GNUNET_break_op(0); |
1114 | return GNUNET_SYSERR; | 1102 | return GNUNET_SYSERR; |
1115 | } | 1103 | } |
1116 | ping = (const struct TransportPingMessage *) hdr; | 1104 | ping = (const struct TransportPingMessage *)hdr; |
1117 | if (0 != | 1105 | if (0 != |
1118 | memcmp (&ping->target, | 1106 | memcmp(&ping->target, |
1119 | &GST_my_identity, | 1107 | &GST_my_identity, |
1120 | sizeof (struct GNUNET_PeerIdentity))) | 1108 | sizeof(struct GNUNET_PeerIdentity))) |
1121 | { | 1109 | { |
1122 | GNUNET_STATISTICS_update (GST_stats, | 1110 | GNUNET_STATISTICS_update(GST_stats, |
1123 | gettext_noop | 1111 | gettext_noop |
1124 | ("# PING message for different peer received"), 1, | 1112 | ("# PING message for different peer received"), 1, |
1125 | GNUNET_NO); | 1113 | GNUNET_NO); |
1126 | return GNUNET_SYSERR; | 1114 | return GNUNET_SYSERR; |
1127 | } | 1115 | } |
1128 | GNUNET_STATISTICS_update (GST_stats, | 1116 | GNUNET_STATISTICS_update(GST_stats, |
1129 | gettext_noop ("# PING messages received"), 1, | 1117 | gettext_noop("# PING messages received"), 1, |
1130 | GNUNET_NO); | 1118 | GNUNET_NO); |
1131 | addr = (const char *) &ping[1]; | 1119 | addr = (const char *)&ping[1]; |
1132 | len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage); | 1120 | len_address = ntohs(hdr->size) - sizeof(struct TransportPingMessage); |
1133 | /* peer wants to confirm that this is one of our addresses, this is what is | 1121 | /* peer wants to confirm that this is one of our addresses, this is what is |
1134 | * used for address validation */ | 1122 | * used for address validation */ |
1135 | 1123 | ||
@@ -1137,198 +1125,198 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
1137 | sig_cache_exp = NULL; | 1125 | sig_cache_exp = NULL; |
1138 | papi = NULL; | 1126 | papi = NULL; |
1139 | if (len_address > 0) | 1127 | if (len_address > 0) |
1140 | { | ||
1141 | addrend = memchr (addr, '\0', len_address); | ||
1142 | if (NULL == addrend) | ||
1143 | { | 1128 | { |
1144 | GNUNET_break_op (0); | 1129 | addrend = memchr(addr, '\0', len_address); |
1145 | return GNUNET_SYSERR; | 1130 | if (NULL == addrend) |
1131 | { | ||
1132 | GNUNET_break_op(0); | ||
1133 | return GNUNET_SYSERR; | ||
1134 | } | ||
1135 | addrend++; | ||
1136 | len_plugin = strlen(addr) + 1; | ||
1137 | len_address -= len_plugin; | ||
1138 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
1139 | address.address = addrend; | ||
1140 | address.address_length = len_address; | ||
1141 | address.transport_name = addr; | ||
1142 | address.peer = GST_my_identity; | ||
1143 | |||
1144 | if (NULL == address.transport_name) | ||
1145 | { | ||
1146 | GNUNET_break(0); | ||
1147 | } | ||
1148 | |||
1149 | if (0 != strstr(address.transport_name, "_client")) | ||
1150 | { | ||
1151 | plugin_name = GNUNET_strdup(address.transport_name); | ||
1152 | pos = strstr(plugin_name, "_client"); | ||
1153 | GNUNET_assert(NULL != pos); | ||
1154 | GNUNET_snprintf(pos, strlen("_server") + 1, "%s", "_server"); | ||
1155 | } | ||
1156 | else | ||
1157 | plugin_name = GNUNET_strdup(address.transport_name); | ||
1158 | |||
1159 | if (NULL == (papi = GST_plugins_find(plugin_name))) | ||
1160 | { | ||
1161 | /* we don't have the plugin for this address */ | ||
1162 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1163 | _("Plugin `%s' not available, cannot confirm having this address\n"), | ||
1164 | plugin_name); | ||
1165 | GNUNET_free(plugin_name); | ||
1166 | return GNUNET_SYSERR; | ||
1167 | } | ||
1168 | GNUNET_free(plugin_name); | ||
1169 | if (GNUNET_OK != | ||
1170 | papi->check_address(papi->cls, | ||
1171 | addrend, | ||
1172 | len_address)) | ||
1173 | { | ||
1174 | GNUNET_STATISTICS_update(GST_stats, | ||
1175 | gettext_noop | ||
1176 | ("# failed address checks during validation"), 1, | ||
1177 | GNUNET_NO); | ||
1178 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1179 | _("Address `%s' is not one of my addresses, not confirming PING\n"), | ||
1180 | GST_plugins_a2s(&address)); | ||
1181 | return GNUNET_SYSERR; | ||
1182 | } | ||
1183 | else | ||
1184 | { | ||
1185 | GNUNET_STATISTICS_update(GST_stats, | ||
1186 | gettext_noop | ||
1187 | ("# successful address checks during validation"), 1, | ||
1188 | GNUNET_NO); | ||
1189 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1190 | "Address `%s' is one of my addresses, confirming PING\n", | ||
1191 | GST_plugins_a2s(&address)); | ||
1192 | } | ||
1193 | |||
1194 | if (GNUNET_YES != | ||
1195 | GST_hello_test_address(&address, | ||
1196 | &sig_cache, | ||
1197 | &sig_cache_exp)) | ||
1198 | { | ||
1199 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1200 | _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"), | ||
1201 | GNUNET_i2s(sender), | ||
1202 | GST_plugins_a2s(&address)); | ||
1203 | return GNUNET_SYSERR; | ||
1204 | } | ||
1146 | } | 1205 | } |
1147 | addrend++; | 1206 | else |
1148 | len_plugin = strlen (addr) + 1; | ||
1149 | len_address -= len_plugin; | ||
1150 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
1151 | address.address = addrend; | ||
1152 | address.address_length = len_address; | ||
1153 | address.transport_name = addr; | ||
1154 | address.peer = GST_my_identity; | ||
1155 | |||
1156 | if (NULL == address.transport_name) | ||
1157 | { | ||
1158 | GNUNET_break (0); | ||
1159 | } | ||
1160 | |||
1161 | if (0 != strstr (address.transport_name, "_client")) | ||
1162 | { | ||
1163 | plugin_name = GNUNET_strdup (address.transport_name); | ||
1164 | pos = strstr (plugin_name, "_client"); | ||
1165 | GNUNET_assert (NULL != pos); | ||
1166 | GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server"); | ||
1167 | } | ||
1168 | else | ||
1169 | plugin_name = GNUNET_strdup (address.transport_name); | ||
1170 | |||
1171 | if (NULL == (papi = GST_plugins_find (plugin_name))) | ||
1172 | { | ||
1173 | /* we don't have the plugin for this address */ | ||
1174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1175 | _("Plugin `%s' not available, cannot confirm having this address\n"), | ||
1176 | plugin_name); | ||
1177 | GNUNET_free (plugin_name); | ||
1178 | return GNUNET_SYSERR; | ||
1179 | } | ||
1180 | GNUNET_free (plugin_name); | ||
1181 | if (GNUNET_OK != | ||
1182 | papi->check_address (papi->cls, | ||
1183 | addrend, | ||
1184 | len_address)) | ||
1185 | { | ||
1186 | GNUNET_STATISTICS_update (GST_stats, | ||
1187 | gettext_noop | ||
1188 | ("# failed address checks during validation"), 1, | ||
1189 | GNUNET_NO); | ||
1190 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1191 | _("Address `%s' is not one of my addresses, not confirming PING\n"), | ||
1192 | GST_plugins_a2s (&address)); | ||
1193 | return GNUNET_SYSERR; | ||
1194 | } | ||
1195 | else | ||
1196 | { | 1207 | { |
1197 | GNUNET_STATISTICS_update (GST_stats, | 1208 | addrend = NULL; /* make gcc happy */ |
1198 | gettext_noop | 1209 | len_plugin = 0; |
1199 | ("# successful address checks during validation"), 1, | 1210 | static struct GNUNET_CRYPTO_EddsaSignature no_address_signature; |
1200 | GNUNET_NO); | 1211 | static struct GNUNET_TIME_Absolute no_address_signature_expiration; |
1201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1202 | "Address `%s' is one of my addresses, confirming PING\n", | ||
1203 | GST_plugins_a2s (&address)); | ||
1204 | } | ||
1205 | 1212 | ||
1206 | if (GNUNET_YES != | 1213 | sig_cache = &no_address_signature; |
1207 | GST_hello_test_address (&address, | 1214 | sig_cache_exp = &no_address_signature_expiration; |
1208 | &sig_cache, | ||
1209 | &sig_cache_exp)) | ||
1210 | { | ||
1211 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1212 | _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"), | ||
1213 | GNUNET_i2s (sender), | ||
1214 | GST_plugins_a2s (&address)); | ||
1215 | return GNUNET_SYSERR; | ||
1216 | } | 1215 | } |
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | addrend = NULL; /* make gcc happy */ | ||
1221 | len_plugin = 0; | ||
1222 | static struct GNUNET_CRYPTO_EddsaSignature no_address_signature; | ||
1223 | static struct GNUNET_TIME_Absolute no_address_signature_expiration; | ||
1224 | 1216 | ||
1225 | sig_cache = &no_address_signature; | 1217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1226 | sig_cache_exp = &no_address_signature_expiration; | 1218 | "I am `%s', sending PONG to peer `%s'\n", |
1227 | } | 1219 | GNUNET_i2s_full(&GST_my_identity), |
1228 | 1220 | GNUNET_i2s(sender)); | |
1229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1230 | "I am `%s', sending PONG to peer `%s'\n", | ||
1231 | GNUNET_i2s_full (&GST_my_identity), | ||
1232 | GNUNET_i2s (sender)); | ||
1233 | 1221 | ||
1234 | /* message with structure: | 1222 | /* message with structure: |
1235 | * [TransportPongMessage][Transport name][Address] */ | 1223 | * [TransportPongMessage][Transport name][Address] */ |
1236 | 1224 | ||
1237 | pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin); | 1225 | pong = GNUNET_malloc(sizeof(struct TransportPongMessage) + len_address + len_plugin); |
1238 | pong->header.size = | 1226 | pong->header.size = |
1239 | htons (sizeof (struct TransportPongMessage) + len_address + len_plugin); | 1227 | htons(sizeof(struct TransportPongMessage) + len_address + len_plugin); |
1240 | pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); | 1228 | pong->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); |
1241 | pong->purpose.size = | 1229 | pong->purpose.size = |
1242 | htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 1230 | htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + |
1243 | sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 1231 | sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + |
1244 | len_address + len_plugin); | 1232 | len_address + len_plugin); |
1245 | pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); | 1233 | pong->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); |
1246 | GNUNET_memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge)); | 1234 | GNUNET_memcpy(&pong->challenge, &ping->challenge, sizeof(ping->challenge)); |
1247 | pong->addrlen = htonl (len_address + len_plugin); | 1235 | pong->addrlen = htonl(len_address + len_plugin); |
1248 | GNUNET_memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */ | 1236 | GNUNET_memcpy(&pong[1], addr, len_plugin); /* Copy transport plugin */ |
1249 | if (len_address > 0) | 1237 | if (len_address > 0) |
1250 | { | 1238 | { |
1251 | GNUNET_assert (NULL != addrend); | 1239 | GNUNET_assert(NULL != addrend); |
1252 | GNUNET_memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address); | 1240 | GNUNET_memcpy(&((char *)&pong[1])[len_plugin], addrend, len_address); |
1253 | } | 1241 | } |
1254 | if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us < | 1242 | if (GNUNET_TIME_absolute_get_remaining(*sig_cache_exp).rel_value_us < |
1255 | PONG_SIGNATURE_LIFETIME.rel_value_us / 4) | 1243 | PONG_SIGNATURE_LIFETIME.rel_value_us / 4) |
1256 | { | ||
1257 | /* create / update cached sig */ | ||
1258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1259 | "Creating PONG signature to indicate ownership.\n"); | ||
1260 | *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); | ||
1261 | pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); | ||
1262 | if (GNUNET_OK != | ||
1263 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose, | ||
1264 | sig_cache)) | ||
1265 | { | 1244 | { |
1266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1245 | /* create / update cached sig */ |
1267 | _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender)); | 1246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1247 | "Creating PONG signature to indicate ownership.\n"); | ||
1248 | *sig_cache_exp = GNUNET_TIME_relative_to_absolute(PONG_SIGNATURE_LIFETIME); | ||
1249 | pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp); | ||
1250 | if (GNUNET_OK != | ||
1251 | GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, &pong->purpose, | ||
1252 | sig_cache)) | ||
1253 | { | ||
1254 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1255 | _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s(sender)); | ||
1256 | } | ||
1268 | } | 1257 | } |
1269 | } | ||
1270 | else | 1258 | else |
1271 | { | 1259 | { |
1272 | pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); | 1260 | pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp); |
1273 | } | 1261 | } |
1274 | pong->signature = *sig_cache; | 1262 | pong->signature = *sig_cache; |
1275 | 1263 | ||
1276 | GNUNET_assert (NULL != sender_address); | 1264 | GNUNET_assert(NULL != sender_address); |
1277 | 1265 | ||
1278 | /* first see if the session we got this PING from can be used to transmit | 1266 | /* first see if the session we got this PING from can be used to transmit |
1279 | * a response reliably */ | 1267 | * a response reliably */ |
1280 | if (NULL == papi) | 1268 | if (NULL == papi) |
1281 | { | ||
1282 | ret = -1; | ||
1283 | } | ||
1284 | else | ||
1285 | { | ||
1286 | GNUNET_assert (NULL != papi->send); | ||
1287 | GNUNET_assert (NULL != papi->get_session); | ||
1288 | if (NULL == session) | ||
1289 | { | 1269 | { |
1290 | session = papi->get_session (papi->cls, sender_address); | ||
1291 | } | ||
1292 | if (NULL == session) | ||
1293 | { | ||
1294 | GNUNET_break (0); | ||
1295 | ret = -1; | 1270 | ret = -1; |
1296 | } | 1271 | } |
1297 | else | 1272 | else |
1298 | { | 1273 | { |
1299 | ret = papi->send (papi->cls, session, | 1274 | GNUNET_assert(NULL != papi->send); |
1300 | (const char *) pong, | 1275 | GNUNET_assert(NULL != papi->get_session); |
1301 | ntohs (pong->header.size), | 1276 | if (NULL == session) |
1302 | PONG_PRIORITY, ACCEPTABLE_PING_DELAY, | 1277 | { |
1303 | NULL, NULL); | 1278 | session = papi->get_session(papi->cls, sender_address); |
1304 | if (-1 != ret) | 1279 | } |
1305 | GST_neighbours_notify_data_sent (sender_address, | 1280 | if (NULL == session) |
1306 | session, | 1281 | { |
1307 | pong->header.size); | 1282 | GNUNET_break(0); |
1283 | ret = -1; | ||
1284 | } | ||
1285 | else | ||
1286 | { | ||
1287 | ret = papi->send(papi->cls, session, | ||
1288 | (const char *)pong, | ||
1289 | ntohs(pong->header.size), | ||
1290 | PONG_PRIORITY, ACCEPTABLE_PING_DELAY, | ||
1291 | NULL, NULL); | ||
1292 | if (-1 != ret) | ||
1293 | GST_neighbours_notify_data_sent(sender_address, | ||
1294 | session, | ||
1295 | pong->header.size); | ||
1296 | } | ||
1308 | } | 1297 | } |
1309 | } | ||
1310 | if (-1 != ret) | 1298 | if (-1 != ret) |
1311 | { | 1299 | { |
1312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1300 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1313 | "Transmitted PONG to `%s' via reliable mechanism\n", | 1301 | "Transmitted PONG to `%s' via reliable mechanism\n", |
1314 | GNUNET_i2s (sender)); | 1302 | GNUNET_i2s(sender)); |
1315 | /* done! */ | 1303 | /* done! */ |
1316 | GNUNET_STATISTICS_update (GST_stats, | 1304 | GNUNET_STATISTICS_update(GST_stats, |
1317 | gettext_noop | 1305 | gettext_noop |
1318 | ("# PONGs unicast via reliable transport"), 1, | 1306 | ("# PONGs unicast via reliable transport"), 1, |
1319 | GNUNET_NO); | 1307 | GNUNET_NO); |
1320 | GNUNET_free (pong); | 1308 | GNUNET_free(pong); |
1321 | return GNUNET_OK; | 1309 | return GNUNET_OK; |
1322 | } | 1310 | } |
1323 | 1311 | ||
1324 | /* no reliable method found, try transmission via all known addresses */ | 1312 | /* no reliable method found, try transmission via all known addresses */ |
1325 | GNUNET_STATISTICS_update (GST_stats, | 1313 | GNUNET_STATISTICS_update(GST_stats, |
1326 | gettext_noop | 1314 | gettext_noop |
1327 | ("# PONGs multicast to all available addresses"), 1, | 1315 | ("# PONGs multicast to all available addresses"), 1, |
1328 | GNUNET_NO); | 1316 | GNUNET_NO); |
1329 | GST_validation_get_addresses (sender, | 1317 | GST_validation_get_addresses(sender, |
1330 | &multicast_pong, pong); | 1318 | &multicast_pong, pong); |
1331 | GNUNET_free (pong); | 1319 | GNUNET_free(pong); |
1332 | return GNUNET_OK; | 1320 | return GNUNET_OK; |
1333 | } | 1321 | } |
1334 | 1322 | ||
@@ -1339,36 +1327,36 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
1339 | * @param address address we should try to validate | 1327 | * @param address address we should try to validate |
1340 | */ | 1328 | */ |
1341 | void | 1329 | void |
1342 | GST_validation_handle_address (const struct GNUNET_HELLO_Address *address) | 1330 | GST_validation_handle_address(const struct GNUNET_HELLO_Address *address) |
1343 | { | 1331 | { |
1344 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 1332 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
1345 | struct ValidationEntry *ve; | 1333 | struct ValidationEntry *ve; |
1346 | 1334 | ||
1347 | papi = GST_plugins_find (address->transport_name); | 1335 | papi = GST_plugins_find(address->transport_name); |
1348 | if (NULL == papi) | 1336 | if (NULL == papi) |
1349 | { | 1337 | { |
1350 | /* This plugin is currently unvailable ... ignore */ | 1338 | /* This plugin is currently unvailable ... ignore */ |
1351 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1339 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1352 | "No plugin available for %s\n", | 1340 | "No plugin available for %s\n", |
1353 | address->transport_name); | 1341 | address->transport_name); |
1354 | return; | 1342 | return; |
1355 | } | 1343 | } |
1356 | ve = find_validation_entry (address); | 1344 | ve = find_validation_entry(address); |
1357 | if (NULL == ve->revalidation_task) | 1345 | if (NULL == ve->revalidation_task) |
1358 | { | 1346 | { |
1359 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1347 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1360 | "Validation process started for fresh address `%s' of %s\n", | 1348 | "Validation process started for fresh address `%s' of %s\n", |
1361 | GST_plugins_a2s (ve->address), | 1349 | GST_plugins_a2s(ve->address), |
1362 | GNUNET_i2s (&ve->address->peer)); | 1350 | GNUNET_i2s(&ve->address->peer)); |
1363 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | 1351 | ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve); |
1364 | } | 1352 | } |
1365 | else | 1353 | else |
1366 | { | 1354 | { |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1355 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1368 | "Validation already running for address `%s' of %s\n", | 1356 | "Validation already running for address `%s' of %s\n", |
1369 | GST_plugins_a2s (ve->address), | 1357 | GST_plugins_a2s(ve->address), |
1370 | GNUNET_i2s (&ve->address->peer)); | 1358 | GNUNET_i2s(&ve->address->peer)); |
1371 | } | 1359 | } |
1372 | } | 1360 | } |
1373 | 1361 | ||
1374 | 1362 | ||
@@ -1382,17 +1370,17 @@ GST_validation_handle_address (const struct GNUNET_HELLO_Address *address) | |||
1382 | * @return #GNUNET_OK (keep the address) | 1370 | * @return #GNUNET_OK (keep the address) |
1383 | */ | 1371 | */ |
1384 | static int | 1372 | static int |
1385 | validate_address_iterator (void *cls, | 1373 | validate_address_iterator(void *cls, |
1386 | const struct GNUNET_HELLO_Address *address, | 1374 | const struct GNUNET_HELLO_Address *address, |
1387 | struct GNUNET_TIME_Absolute expiration) | 1375 | struct GNUNET_TIME_Absolute expiration) |
1388 | { | 1376 | { |
1389 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 1377 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) |
1390 | { | 1378 | { |
1391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1392 | "Skipping expired address from HELLO\n"); | 1380 | "Skipping expired address from HELLO\n"); |
1393 | return GNUNET_OK; /* expired */ | 1381 | return GNUNET_OK; /* expired */ |
1394 | } | 1382 | } |
1395 | GST_validation_handle_address (address); | 1383 | GST_validation_handle_address(address); |
1396 | return GNUNET_OK; | 1384 | return GNUNET_OK; |
1397 | } | 1385 | } |
1398 | 1386 | ||
@@ -1407,19 +1395,19 @@ validate_address_iterator (void *cls, | |||
1407 | * end of the iteration. | 1395 | * end of the iteration. |
1408 | */ | 1396 | */ |
1409 | static ssize_t | 1397 | static ssize_t |
1410 | add_valid_peer_address (void *cls, | 1398 | add_valid_peer_address(void *cls, |
1411 | size_t max, | 1399 | size_t max, |
1412 | void *buf) | 1400 | void *buf) |
1413 | { | 1401 | { |
1414 | struct ValidationEntry *ve = cls; | 1402 | struct ValidationEntry *ve = cls; |
1415 | 1403 | ||
1416 | if (GNUNET_YES == ve->copied) | 1404 | if (GNUNET_YES == ve->copied) |
1417 | return GNUNET_SYSERR; /* Done */ | 1405 | return GNUNET_SYSERR; /* Done */ |
1418 | ve->copied = GNUNET_YES; | 1406 | ve->copied = GNUNET_YES; |
1419 | return GNUNET_HELLO_add_address (ve->address, | 1407 | return GNUNET_HELLO_add_address(ve->address, |
1420 | ve->valid_until, | 1408 | ve->valid_until, |
1421 | buf, | 1409 | buf, |
1422 | max); | 1410 | max); |
1423 | } | 1411 | } |
1424 | 1412 | ||
1425 | 1413 | ||
@@ -1432,8 +1420,8 @@ add_valid_peer_address (void *cls, | |||
1432 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error | 1420 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error |
1433 | */ | 1421 | */ |
1434 | int | 1422 | int |
1435 | GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | 1423 | GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender, |
1436 | const struct GNUNET_MessageHeader *hdr) | 1424 | const struct GNUNET_MessageHeader *hdr) |
1437 | { | 1425 | { |
1438 | const struct TransportPongMessage *pong; | 1426 | const struct TransportPongMessage *pong; |
1439 | struct ValidationEntry *ve; | 1427 | struct ValidationEntry *ve; |
@@ -1448,197 +1436,197 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1448 | int do_verify; | 1436 | int do_verify; |
1449 | 1437 | ||
1450 | if (0 == | 1438 | if (0 == |
1451 | memcmp (&GST_my_identity, | 1439 | memcmp(&GST_my_identity, |
1452 | sender, | 1440 | sender, |
1453 | sizeof (struct GNUNET_PeerIdentity))) | 1441 | sizeof(struct GNUNET_PeerIdentity))) |
1454 | return GNUNET_OK; /* our own, ignore! */ | 1442 | return GNUNET_OK; /* our own, ignore! */ |
1455 | 1443 | ||
1456 | if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) | 1444 | if (ntohs(hdr->size) < sizeof(struct TransportPongMessage)) |
1457 | { | 1445 | { |
1458 | GNUNET_break_op (0); | 1446 | GNUNET_break_op(0); |
1459 | return GNUNET_SYSERR; | 1447 | return GNUNET_SYSERR; |
1460 | } | 1448 | } |
1461 | GNUNET_STATISTICS_update (GST_stats, | 1449 | GNUNET_STATISTICS_update(GST_stats, |
1462 | gettext_noop ("# PONG messages received"), 1, | 1450 | gettext_noop("# PONG messages received"), 1, |
1463 | GNUNET_NO); | 1451 | GNUNET_NO); |
1464 | 1452 | ||
1465 | /* message with structure: | 1453 | /* message with structure: |
1466 | * [TransportPongMessage][Transport name][Address] */ | 1454 | * [TransportPongMessage][Transport name][Address] */ |
1467 | 1455 | ||
1468 | pong = (const struct TransportPongMessage *) hdr; | 1456 | pong = (const struct TransportPongMessage *)hdr; |
1469 | tname = (const char *) &pong[1]; | 1457 | tname = (const char *)&pong[1]; |
1470 | size = ntohs (hdr->size) - sizeof (struct TransportPongMessage); | 1458 | size = ntohs(hdr->size) - sizeof(struct TransportPongMessage); |
1471 | addr = memchr (tname, '\0', size); | 1459 | addr = memchr(tname, '\0', size); |
1472 | if (NULL == addr) | 1460 | if (NULL == addr) |
1473 | { | 1461 | { |
1474 | GNUNET_break_op (0); | 1462 | GNUNET_break_op(0); |
1475 | return GNUNET_SYSERR; | 1463 | return GNUNET_SYSERR; |
1476 | } | 1464 | } |
1477 | addr++; | 1465 | addr++; |
1478 | slen = strlen (tname) + 1; | 1466 | slen = strlen(tname) + 1; |
1479 | addrlen = size - slen; | 1467 | addrlen = size - slen; |
1480 | 1468 | ||
1481 | if (NULL == GST_plugins_find (tname)) | 1469 | if (NULL == GST_plugins_find(tname)) |
1482 | { | 1470 | { |
1483 | /* we got the PONG, but the transport plugin specified in it | 1471 | /* we got the PONG, but the transport plugin specified in it |
1484 | is not supported by this peer, so this cannot be a good | 1472 | is not supported by this peer, so this cannot be a good |
1485 | PONG for us. */ | 1473 | PONG for us. */ |
1486 | GNUNET_break_op (0); | 1474 | GNUNET_break_op(0); |
1487 | return GNUNET_OK; | 1475 | return GNUNET_OK; |
1488 | } | 1476 | } |
1489 | 1477 | ||
1490 | address.peer = *sender; | 1478 | address.peer = *sender; |
1491 | address.address = addr; | 1479 | address.address = addr; |
1492 | address.address_length = addrlen; | 1480 | address.address_length = addrlen; |
1493 | address.transport_name = tname; | 1481 | address.transport_name = tname; |
1494 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | 1482 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; |
1495 | ve = find_validation_entry (&address); | 1483 | ve = find_validation_entry(&address); |
1496 | if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) | 1484 | if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) |
1497 | { | 1485 | { |
1498 | GNUNET_STATISTICS_update (GST_stats, | 1486 | GNUNET_STATISTICS_update(GST_stats, |
1499 | gettext_noop | 1487 | gettext_noop |
1500 | ("# PONGs dropped, no matching pending validation"), | 1488 | ("# PONGs dropped, no matching pending validation"), |
1501 | 1, GNUNET_NO); | 1489 | 1, GNUNET_NO); |
1502 | return GNUNET_OK; | 1490 | return GNUNET_OK; |
1503 | } | 1491 | } |
1504 | /* now check that PONG is well-formed */ | 1492 | /* now check that PONG is well-formed */ |
1505 | if (0 != memcmp (&ve->address->peer, | 1493 | if (0 != memcmp(&ve->address->peer, |
1506 | sender, | 1494 | sender, |
1507 | sizeof (struct GNUNET_PeerIdentity))) | 1495 | sizeof(struct GNUNET_PeerIdentity))) |
1508 | { | 1496 | { |
1509 | GNUNET_break_op (0); | 1497 | GNUNET_break_op(0); |
1510 | return GNUNET_SYSERR; | 1498 | return GNUNET_SYSERR; |
1511 | } | 1499 | } |
1512 | if (0 == | 1500 | if (0 == |
1513 | GNUNET_TIME_absolute_get_remaining | 1501 | GNUNET_TIME_absolute_get_remaining |
1514 | (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us) | 1502 | (GNUNET_TIME_absolute_ntoh(pong->expiration)).rel_value_us) |
1515 | { | 1503 | { |
1516 | GNUNET_STATISTICS_update (GST_stats, | 1504 | GNUNET_STATISTICS_update(GST_stats, |
1517 | gettext_noop | 1505 | gettext_noop |
1518 | ("# PONGs dropped, signature expired"), 1, | 1506 | ("# PONGs dropped, signature expired"), 1, |
1519 | GNUNET_NO); | 1507 | GNUNET_NO); |
1520 | return GNUNET_SYSERR; | 1508 | return GNUNET_SYSERR; |
1521 | } | 1509 | } |
1522 | 1510 | ||
1523 | sig_res = GNUNET_SYSERR; | 1511 | sig_res = GNUNET_SYSERR; |
1524 | do_verify = GNUNET_YES; | 1512 | do_verify = GNUNET_YES; |
1525 | if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us) | 1513 | if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us) |
1526 | { | ||
1527 | /* We have a cached and valid signature for this peer, | ||
1528 | * try to compare instead of verify */ | ||
1529 | if (0 == memcmp (&ve->pong_sig_cache, | ||
1530 | &pong->signature, | ||
1531 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))) | ||
1532 | { | 1514 | { |
1533 | /* signatures are identical, we can skip verification */ | 1515 | /* We have a cached and valid signature for this peer, |
1534 | sig_res = GNUNET_OK; | 1516 | * try to compare instead of verify */ |
1535 | do_verify = GNUNET_NO; | 1517 | if (0 == memcmp(&ve->pong_sig_cache, |
1518 | &pong->signature, | ||
1519 | sizeof(struct GNUNET_CRYPTO_EddsaSignature))) | ||
1520 | { | ||
1521 | /* signatures are identical, we can skip verification */ | ||
1522 | sig_res = GNUNET_OK; | ||
1523 | do_verify = GNUNET_NO; | ||
1524 | } | ||
1525 | else | ||
1526 | { | ||
1527 | sig_res = GNUNET_SYSERR; | ||
1528 | /* signatures do not match, we have to verify */ | ||
1529 | } | ||
1536 | } | 1530 | } |
1537 | else | ||
1538 | { | ||
1539 | sig_res = GNUNET_SYSERR; | ||
1540 | /* signatures do not match, we have to verify */ | ||
1541 | } | ||
1542 | } | ||
1543 | 1531 | ||
1544 | if (GNUNET_YES == do_verify) | 1532 | if (GNUNET_YES == do_verify) |
1545 | { | ||
1546 | /* Do expensive verification */ | ||
1547 | sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | ||
1548 | &pong->purpose, | ||
1549 | &pong->signature, | ||
1550 | &ve->address->peer.public_key); | ||
1551 | if (sig_res == GNUNET_SYSERR) | ||
1552 | { | 1533 | { |
1553 | GNUNET_break_op (0); | 1534 | /* Do expensive verification */ |
1554 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1535 | sig_res = GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
1555 | "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n", | 1536 | &pong->purpose, |
1556 | tname, | 1537 | &pong->signature, |
1557 | GST_plugins_a2s (ve->address), | 1538 | &ve->address->peer.public_key); |
1558 | GNUNET_i2s (sender)); | 1539 | if (sig_res == GNUNET_SYSERR) |
1540 | { | ||
1541 | GNUNET_break_op(0); | ||
1542 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1543 | "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n", | ||
1544 | tname, | ||
1545 | GST_plugins_a2s(ve->address), | ||
1546 | GNUNET_i2s(sender)); | ||
1547 | } | ||
1559 | } | 1548 | } |
1560 | } | ||
1561 | if (sig_res == GNUNET_SYSERR) | 1549 | if (sig_res == GNUNET_SYSERR) |
1562 | { | 1550 | { |
1563 | GNUNET_break_op (0); | 1551 | GNUNET_break_op(0); |
1564 | return GNUNET_SYSERR; | 1552 | return GNUNET_SYSERR; |
1565 | } | 1553 | } |
1566 | 1554 | ||
1567 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1555 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1568 | "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", | 1556 | "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", |
1569 | GNUNET_i2s (sender), | 1557 | GNUNET_i2s(sender), |
1570 | tname, | 1558 | tname, |
1571 | GST_plugins_a2s (ve->address)); | 1559 | GST_plugins_a2s(ve->address)); |
1572 | GNUNET_STATISTICS_update (GST_stats, | 1560 | GNUNET_STATISTICS_update(GST_stats, |
1573 | gettext_noop ("# validations succeeded"), | 1561 | gettext_noop("# validations succeeded"), |
1574 | 1, | 1562 | 1, |
1575 | GNUNET_NO); | 1563 | GNUNET_NO); |
1576 | /* validity achieved, remember it! */ | 1564 | /* validity achieved, remember it! */ |
1577 | ve->expecting_pong = GNUNET_NO; | 1565 | ve->expecting_pong = GNUNET_NO; |
1578 | ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); | 1566 | ve->valid_until = GNUNET_TIME_relative_to_absolute(HELLO_ADDRESS_EXPIRATION); |
1579 | ve->pong_sig_cache = pong->signature; | 1567 | ve->pong_sig_cache = pong->signature; |
1580 | ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration); | 1568 | ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh(pong->expiration); |
1581 | ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); | 1569 | ve->latency = GNUNET_TIME_absolute_get_duration(ve->send_time); |
1582 | { | 1570 | { |
1583 | if (GNUNET_YES == ve->known_to_ats) | 1571 | if (GNUNET_YES == ve->known_to_ats) |
1584 | { | 1572 | { |
1585 | GNUNET_assert (GNUNET_YES == | 1573 | GNUNET_assert(GNUNET_YES == |
1586 | GST_ats_is_known_no_session (ve->address)); | 1574 | GST_ats_is_known_no_session(ve->address)); |
1587 | GST_ats_update_delay (ve->address, | 1575 | GST_ats_update_delay(ve->address, |
1588 | GNUNET_TIME_relative_divide (ve->latency, 2)); | 1576 | GNUNET_TIME_relative_divide(ve->latency, 2)); |
1589 | } | 1577 | } |
1590 | else | 1578 | else |
1591 | { | 1579 | { |
1592 | struct GNUNET_ATS_Properties prop; | 1580 | struct GNUNET_ATS_Properties prop; |
1593 | 1581 | ||
1594 | memset (&prop, 0, sizeof (prop)); | 1582 | memset(&prop, 0, sizeof(prop)); |
1595 | GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); | 1583 | GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network); |
1596 | prop.scope = ve->network; | 1584 | prop.scope = ve->network; |
1597 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); | 1585 | prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2); |
1598 | GNUNET_assert (GNUNET_NO == | 1586 | GNUNET_assert(GNUNET_NO == |
1599 | GST_ats_is_known_no_session (ve->address)); | 1587 | GST_ats_is_known_no_session(ve->address)); |
1600 | ve->known_to_ats = GNUNET_YES; | 1588 | ve->known_to_ats = GNUNET_YES; |
1601 | GST_ats_add_address (ve->address, &prop); | 1589 | GST_ats_add_address(ve->address, &prop); |
1602 | GNUNET_assert (GNUNET_YES == | 1590 | GNUNET_assert(GNUNET_YES == |
1603 | GST_ats_is_known_no_session (ve->address)); | 1591 | GST_ats_is_known_no_session(ve->address)); |
1604 | } | 1592 | } |
1605 | } | 1593 | } |
1606 | if (validations_running > 0) | 1594 | if (validations_running > 0) |
1607 | { | 1595 | { |
1608 | validations_running--; | 1596 | validations_running--; |
1609 | GNUNET_STATISTICS_set (GST_stats, | 1597 | GNUNET_STATISTICS_set(GST_stats, |
1610 | gettext_noop ("# validations running"), | 1598 | gettext_noop("# validations running"), |
1611 | validations_running, | 1599 | validations_running, |
1612 | GNUNET_NO); | 1600 | GNUNET_NO); |
1613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1601 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1614 | "Validation finished, %u validation processes running\n", | 1602 | "Validation finished, %u validation processes running\n", |
1615 | validations_running); | 1603 | validations_running); |
1616 | } | 1604 | } |
1617 | else | 1605 | else |
1618 | { | 1606 | { |
1619 | GNUNET_break (0); | 1607 | GNUNET_break(0); |
1620 | } | 1608 | } |
1621 | 1609 | ||
1622 | /* Notify about new validity */ | 1610 | /* Notify about new validity */ |
1623 | validation_entry_changed (ve, | 1611 | validation_entry_changed(ve, |
1624 | GNUNET_TRANSPORT_VS_UPDATE); | 1612 | GNUNET_TRANSPORT_VS_UPDATE); |
1625 | 1613 | ||
1626 | /* build HELLO to store in PEERINFO */ | 1614 | /* build HELLO to store in PEERINFO */ |
1627 | GNUNET_STATISTICS_update (GST_stats, | 1615 | GNUNET_STATISTICS_update(GST_stats, |
1628 | gettext_noop ("# HELLOs given to peerinfo"), | 1616 | gettext_noop("# HELLOs given to peerinfo"), |
1629 | 1, | 1617 | 1, |
1630 | GNUNET_NO); | 1618 | GNUNET_NO); |
1631 | ve->copied = GNUNET_NO; | 1619 | ve->copied = GNUNET_NO; |
1632 | hello = GNUNET_HELLO_create (&ve->address->peer.public_key, | 1620 | hello = GNUNET_HELLO_create(&ve->address->peer.public_key, |
1633 | &add_valid_peer_address, | 1621 | &add_valid_peer_address, |
1634 | ve, | 1622 | ve, |
1635 | GNUNET_NO); | 1623 | GNUNET_NO); |
1636 | GNUNET_break (NULL != | 1624 | GNUNET_break(NULL != |
1637 | GNUNET_PEERINFO_add_peer (GST_peerinfo, | 1625 | GNUNET_PEERINFO_add_peer(GST_peerinfo, |
1638 | hello, | 1626 | hello, |
1639 | NULL, | 1627 | NULL, |
1640 | NULL)); | 1628 | NULL)); |
1641 | GNUNET_free (hello); | 1629 | GNUNET_free(hello); |
1642 | return GNUNET_OK; | 1630 | return GNUNET_OK; |
1643 | } | 1631 | } |
1644 | 1632 | ||
@@ -1651,42 +1639,42 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1651 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error | 1639 | * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error |
1652 | */ | 1640 | */ |
1653 | int | 1641 | int |
1654 | GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) | 1642 | GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello) |
1655 | { | 1643 | { |
1656 | const struct GNUNET_HELLO_Message *hm = | 1644 | const struct GNUNET_HELLO_Message *hm = |
1657 | (const struct GNUNET_HELLO_Message *) hello; | 1645 | (const struct GNUNET_HELLO_Message *)hello; |
1658 | struct GNUNET_PeerIdentity pid; | 1646 | struct GNUNET_PeerIdentity pid; |
1659 | int friend; | 1647 | int friend; |
1660 | 1648 | ||
1661 | friend = GNUNET_HELLO_is_friend_only (hm); | 1649 | friend = GNUNET_HELLO_is_friend_only(hm); |
1662 | if ( ( (GNUNET_YES != friend) && | 1650 | if (((GNUNET_YES != friend) && |
1663 | (GNUNET_NO != friend) ) || | 1651 | (GNUNET_NO != friend)) || |
1664 | (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) ) | 1652 | (GNUNET_OK != GNUNET_HELLO_get_id(hm, &pid))) |
1665 | { | 1653 | { |
1666 | /* malformed HELLO */ | 1654 | /* malformed HELLO */ |
1667 | GNUNET_break_op (0); | 1655 | GNUNET_break_op(0); |
1668 | return GNUNET_SYSERR; | 1656 | return GNUNET_SYSERR; |
1669 | } | 1657 | } |
1670 | if (0 == | 1658 | if (0 == |
1671 | memcmp (&GST_my_identity, | 1659 | memcmp(&GST_my_identity, |
1672 | &pid, | 1660 | &pid, |
1673 | sizeof (struct GNUNET_PeerIdentity))) | 1661 | sizeof(struct GNUNET_PeerIdentity))) |
1674 | { | 1662 | { |
1675 | /* got our own HELLO, how boring */ | 1663 | /* got our own HELLO, how boring */ |
1676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1664 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1677 | "Validation received our own HELLO (%s), ignoring\n", | 1665 | "Validation received our own HELLO (%s), ignoring\n", |
1678 | GNUNET_i2s (&pid)); | 1666 | GNUNET_i2s(&pid)); |
1679 | return GNUNET_OK; | 1667 | return GNUNET_OK; |
1680 | } | 1668 | } |
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1669 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1682 | "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", | 1670 | "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", |
1683 | GNUNET_i2s (&pid), | 1671 | GNUNET_i2s(&pid), |
1684 | ntohs (hello->size)); | 1672 | ntohs(hello->size)); |
1685 | GNUNET_assert (NULL == | 1673 | GNUNET_assert(NULL == |
1686 | GNUNET_HELLO_iterate_addresses (hm, | 1674 | GNUNET_HELLO_iterate_addresses(hm, |
1687 | GNUNET_NO, | 1675 | GNUNET_NO, |
1688 | &validate_address_iterator, | 1676 | &validate_address_iterator, |
1689 | NULL)); | 1677 | NULL)); |
1690 | return GNUNET_OK; | 1678 | return GNUNET_OK; |
1691 | } | 1679 | } |
1692 | 1680 | ||
@@ -1694,8 +1682,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) | |||
1694 | /** | 1682 | /** |
1695 | * Closure for #iterate_addresses(). | 1683 | * Closure for #iterate_addresses(). |
1696 | */ | 1684 | */ |
1697 | struct IteratorContext | 1685 | struct IteratorContext { |
1698 | { | ||
1699 | /** | 1686 | /** |
1700 | * Function to call on each address. | 1687 | * Function to call on each address. |
1701 | */ | 1688 | */ |
@@ -1705,7 +1692,6 @@ struct IteratorContext | |||
1705 | * Closure for @e cb. | 1692 | * Closure for @e cb. |
1706 | */ | 1693 | */ |
1707 | void *cb_cls; | 1694 | void *cb_cls; |
1708 | |||
1709 | }; | 1695 | }; |
1710 | 1696 | ||
1711 | 1697 | ||
@@ -1718,17 +1704,17 @@ struct IteratorContext | |||
1718 | * @return #GNUNET_OK (continue to iterate) | 1704 | * @return #GNUNET_OK (continue to iterate) |
1719 | */ | 1705 | */ |
1720 | static int | 1706 | static int |
1721 | iterate_addresses (void *cls, | 1707 | iterate_addresses(void *cls, |
1722 | const struct GNUNET_PeerIdentity *key, | 1708 | const struct GNUNET_PeerIdentity *key, |
1723 | void *value) | 1709 | void *value) |
1724 | { | 1710 | { |
1725 | struct IteratorContext *ic = cls; | 1711 | struct IteratorContext *ic = cls; |
1726 | struct ValidationEntry *ve = value; | 1712 | struct ValidationEntry *ve = value; |
1727 | 1713 | ||
1728 | ic->cb (ic->cb_cls, | 1714 | ic->cb(ic->cb_cls, |
1729 | ve->valid_until, | 1715 | ve->valid_until, |
1730 | ve->revalidation_block, | 1716 | ve->revalidation_block, |
1731 | ve->address); | 1717 | ve->address); |
1732 | return GNUNET_OK; | 1718 | return GNUNET_OK; |
1733 | } | 1719 | } |
1734 | 1720 | ||
@@ -1742,17 +1728,17 @@ iterate_addresses (void *cls, | |||
1742 | * @param cb_cls closure for @a cb | 1728 | * @param cb_cls closure for @a cb |
1743 | */ | 1729 | */ |
1744 | void | 1730 | void |
1745 | GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, | 1731 | GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target, |
1746 | GST_ValidationAddressCallback cb, | 1732 | GST_ValidationAddressCallback cb, |
1747 | void *cb_cls) | 1733 | void *cb_cls) |
1748 | { | 1734 | { |
1749 | struct IteratorContext ic; | 1735 | struct IteratorContext ic; |
1750 | 1736 | ||
1751 | ic.cb = cb; | 1737 | ic.cb = cb; |
1752 | ic.cb_cls = cb_cls; | 1738 | ic.cb_cls = cb_cls; |
1753 | GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 1739 | GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, |
1754 | target, | 1740 | target, |
1755 | &iterate_addresses, &ic); | 1741 | &iterate_addresses, &ic); |
1756 | } | 1742 | } |
1757 | 1743 | ||
1758 | 1744 | ||
@@ -1766,37 +1752,37 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, | |||
1766 | * #GNUNET_NO if we are no longer using the address for a connection | 1752 | * #GNUNET_NO if we are no longer using the address for a connection |
1767 | */ | 1753 | */ |
1768 | void | 1754 | void |
1769 | GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, | 1755 | GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, |
1770 | int in_use) | 1756 | int in_use) |
1771 | { | 1757 | { |
1772 | struct ValidationEntry *ve; | 1758 | struct ValidationEntry *ve; |
1773 | 1759 | ||
1774 | if (GNUNET_HELLO_address_check_option (address, | 1760 | if (GNUNET_HELLO_address_check_option(address, |
1775 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 1761 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
1776 | return; /* ignore inbound for validation */ | 1762 | return; /* ignore inbound for validation */ |
1777 | if (NULL == GST_plugins_find (address->transport_name)) | 1763 | if (NULL == GST_plugins_find(address->transport_name)) |
1778 | { | 1764 | { |
1779 | /* How can we use an address for which we don't have the plugin? */ | 1765 | /* How can we use an address for which we don't have the plugin? */ |
1780 | GNUNET_break (0); | 1766 | GNUNET_break(0); |
1781 | return; | 1767 | return; |
1782 | } | 1768 | } |
1783 | ve = find_validation_entry (address); | 1769 | ve = find_validation_entry(address); |
1784 | if (NULL == ve) | 1770 | if (NULL == ve) |
1785 | { | 1771 | { |
1786 | GNUNET_break (0); | 1772 | GNUNET_break(0); |
1787 | return; | 1773 | return; |
1788 | } | 1774 | } |
1789 | if (in_use == ve->in_use) | 1775 | if (in_use == ve->in_use) |
1790 | return; | 1776 | return; |
1791 | ve->in_use = in_use; | 1777 | ve->in_use = in_use; |
1792 | if (GNUNET_YES == in_use) | 1778 | if (GNUNET_YES == in_use) |
1793 | { | 1779 | { |
1794 | /* from now on, higher frequeny, so reschedule now */ | 1780 | /* from now on, higher frequeny, so reschedule now */ |
1795 | if (NULL != ve->revalidation_task) | 1781 | if (NULL != ve->revalidation_task) |
1796 | GNUNET_SCHEDULER_cancel (ve->revalidation_task); | 1782 | GNUNET_SCHEDULER_cancel(ve->revalidation_task); |
1797 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, | 1783 | ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, |
1798 | ve); | 1784 | ve); |
1799 | } | 1785 | } |
1800 | } | 1786 | } |
1801 | 1787 | ||
1802 | 1788 | ||