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