2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file transport/gnunet-service-transport_validation.c
23 * @brief address validation subsystem
24 * @author Christian Grothoff
27 #include "gnunet-service-transport_ats.h"
28 #include "gnunet-service-transport_hello.h"
29 #include "gnunet-service-transport_neighbours.h"
30 #include "gnunet-service-transport_plugins.h"
31 #include "gnunet-service-transport_validation.h"
32 #include "gnunet-service-transport.h"
33 #include "gnunet_hello_lib.h"
34 #include "gnunet_ats_service.h"
35 #include "gnunet_peerinfo_service.h"
36 #include "gnunet_signatures.h"
39 * Current state of a validation process.
41 * FIXME: what state is used to indicate that a validation
42 * was successful? If that is clarified/determined, "UGH" in
43 * ~gnunetpeerinfogtk.c:1103 should be resolved.
45 enum GNUNET_TRANSPORT_ValidationState
50 * Used for final callback indicating operation done
52 GNUNET_TRANSPORT_VS_NONE,
55 * Fresh validation entry
57 * Entry was just created, no validation process was executed
59 GNUNET_TRANSPORT_VS_NEW,
62 * Updated validation entry
64 * This is an update for an existing validation entry
66 GNUNET_TRANSPORT_VS_UPDATE,
69 * Timeout for validation entry
71 * A timeout occured during the validation process
73 GNUNET_TRANSPORT_VS_TIMEOUT,
76 * Validation entry is removed
78 * The validation entry is getting removed due to a failed validation
80 GNUNET_TRANSPORT_VS_REMOVE
87 * How long is a PONG signature valid? We'll recycle a signature until
88 * 1/4 of this time is remaining. PONGs should expire so that if our
89 * external addresses change an adversary cannot replay them indefinitely.
90 * 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.
93 #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
96 * 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
100 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
103 * How often do we allow PINGing an address that we have not yet
104 * validated? This also determines how long we track an address that
105 * we cannot validate (because after this time we can destroy the
106 * validation record).
108 #define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
111 * How often do we PING an address that we have successfully validated
112 * in the past but are not actively using? Should be (significantly)
113 * smaller than HELLO_ADDRESS_EXPIRATION.
115 #define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
118 * How often do we PING an address that we are currently using?
120 #define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
123 * How much delay is acceptable for sending the PING or PONG?
125 #define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
128 * Size of the validation map hashmap.
130 #define VALIDATION_MAP_SIZE 256
133 * Priority to use for PINGs
135 #define PING_PRIORITY 2
138 * Priority to use for PONGs
140 #define PONG_PRIORITY 4
143 GNUNET_NETWORK_STRUCT_BEGIN
146 * Message used to ask a peer to validate receipt (to check an address
147 * from a HELLO). Followed by the address we are trying to validate,
148 * 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.
151 struct TransportPingMessage
155 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING
157 struct GNUNET_MessageHeader header;
160 * Challenge code (to ensure fresh reply).
162 uint32_t challenge GNUNET_PACKED;
165 * Who is the intended recipient?
167 struct GNUNET_PeerIdentity target;
173 * Message used to validate a HELLO. The challenge is included in the
174 * confirmation to make matching of replies to requests possible. The
175 * signature signs our public key, an expiration time and our address.<p>
177 * This message is followed by our transport address that the PING tried
178 * to confirm (if we liked it). The address can be empty (zero bytes)
179 * if the PING had not address either (and we received the request via
180 * a connection that we initiated).
182 struct TransportPongMessage
186 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
188 struct GNUNET_MessageHeader header;
191 * Challenge code from PING (showing freshness). Not part of what
192 * is signed so that we can re-use signatures.
194 uint32_t challenge GNUNET_PACKED;
199 struct GNUNET_CRYPTO_EddsaSignature signature;
202 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
203 * plausible address for the signing peer.
205 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
208 * When does this signature expire?
210 struct GNUNET_TIME_AbsoluteNBO expiration;
213 * Size of address appended to this message (part of what is
214 * being signed, hence not redundant).
216 uint32_t addrlen GNUNET_PACKED;
219 GNUNET_NETWORK_STRUCT_END
222 * Information about an address under validation
224 struct ValidationEntry
230 struct GNUNET_HELLO_Address *address;
233 * Handle to the blacklist check (if we're currently in it).
235 struct GST_BlacklistCheck *bc;
238 * Cached PONG signature
240 struct GNUNET_CRYPTO_EddsaSignature pong_sig_cache;
243 * ID of task that will clean up this entry if nothing happens.
245 struct GNUNET_SCHEDULER_Task *timeout_task;
248 * ID of task that will trigger address revalidation.
250 struct GNUNET_SCHEDULER_Task *revalidation_task;
253 * At what time did we send the latest validation request (PING)?
255 struct GNUNET_TIME_Absolute send_time;
258 * At what time do we send the next validation request (PING)?
260 struct GNUNET_TIME_Absolute next_validation;
263 * Until when is this address valid?
264 * ZERO if it is not currently considered valid.
266 struct GNUNET_TIME_Absolute valid_until;
269 * Until when is the cached PONG signature valid?
270 * ZERO if it is not currently considered valid.
272 struct GNUNET_TIME_Absolute pong_sig_valid_until;
275 * How long until we can try to validate this address again?
276 * FOREVER if the address is for an unsupported plugin (from PEERINFO)
277 * ZERO if the address is considered valid (no validation needed)
278 * otherwise a time in the future if we're currently denying re-validation
280 struct GNUNET_TIME_Absolute revalidation_block;
283 * Last observed latency for this address (round-trip), delay between
284 * last PING sent and PONG received; FOREVER if we never got a PONG.
286 struct GNUNET_TIME_Relative latency;
289 * Current state of this validation entry
291 enum GNUNET_TRANSPORT_ValidationState state;
294 * Challenge number we used.
299 * When passing the address in #add_valid_peer_address(), did we
300 * copy the address to the HELLO yet?
305 * Are we currently using this address for a connection?
310 * Are we expecting a PONG message for this validation entry?
315 * Is this address known to ATS as valid right now?
320 * Which network type does our address belong to?
322 enum GNUNET_NetworkType network;
327 * Map of PeerIdentities to 'struct ValidationEntry*'s (addresses
328 * of the given peer that we are currently validating, have validated
329 * or are blocked from re-validation for a while).
331 static struct GNUNET_CONTAINER_MultiPeerMap *validation_map;
334 * Context for peerinfo iteration.
336 static struct GNUNET_PEERINFO_NotifyContext *pnc;
339 * Minimum delay between to validations
341 static struct GNUNET_TIME_Relative validation_delay;
344 * Number of validations running; any PING that was not yet
345 * matched by a PONG and for which we have not yet hit the
346 * timeout is considered a running 'validation'.
348 static unsigned int validations_running;
351 * Validition fast start threshold
353 static unsigned int validations_fast_start_threshold;
356 * When is next validation allowed
358 static struct GNUNET_TIME_Absolute validation_next;
362 * Context for the validation entry match function.
364 struct ValidationEntryMatchContext
367 * Where to store the result?
369 struct ValidationEntry *ve;
372 * Address we're interested in.
374 const struct GNUNET_HELLO_Address *address;
380 * Provide an update on the `validation_map` map size to statistics.
381 * This function should be called whenever the `validation_map`
385 publish_ve_stat_update ()
387 GNUNET_STATISTICS_set (GST_stats,
388 gettext_noop ("# Addresses in validation map"),
389 GNUNET_CONTAINER_multipeermap_size (validation_map),
395 * Iterate over validation entries until a matching one is found.
397 * @param cls the `struct ValidationEntryMatchContext *`
398 * @param key peer identity (unused)
399 * @param value a `struct ValidationEntry *` to match
400 * @return #GNUNET_YES if the entry does not match,
401 * #GNUNET_NO if the entry does match
404 validation_entry_match (void *cls,
405 const struct GNUNET_PeerIdentity *key,
408 struct ValidationEntryMatchContext *vemc = cls;
409 struct ValidationEntry *ve = value;
411 if (0 == GNUNET_HELLO_address_cmp (ve->address,
422 * A validation entry changed. Update the state and notify
425 * @param ve validation entry that changed
426 * @param state new state
429 validation_entry_changed (struct ValidationEntry *ve,
430 enum GNUNET_TRANSPORT_ValidationState state)
437 * Iterate over validation entries and free them.
439 * @param cls (unused)
440 * @param key peer identity (unused)
441 * @param value a `struct ValidationEntry *` to clean up
442 * @return #GNUNET_YES (continue to iterate)
445 cleanup_validation_entry (void *cls,
446 const struct GNUNET_PeerIdentity *key,
449 struct ValidationEntry *ve = value;
451 ve->next_validation = GNUNET_TIME_UNIT_ZERO_ABS;
452 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
454 /* Notify about deleted entry */
455 validation_entry_changed (ve,
456 GNUNET_TRANSPORT_VS_REMOVE);
460 GST_blacklist_test_cancel (ve->bc);
463 GNUNET_break (GNUNET_OK ==
464 GNUNET_CONTAINER_multipeermap_remove (validation_map,
467 publish_ve_stat_update ();
468 if (GNUNET_YES == ve->known_to_ats)
470 GST_ats_expire_address (ve->address);
471 GNUNET_assert (GNUNET_NO ==
472 GST_ats_is_known_no_session (ve->address));
473 ve->known_to_ats = GNUNET_NO;
475 GNUNET_HELLO_address_free (ve->address);
476 if (NULL != ve->timeout_task)
478 GNUNET_SCHEDULER_cancel (ve->timeout_task);
479 ve->timeout_task = NULL;
481 if (NULL != ve->revalidation_task)
483 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
484 ve->revalidation_task = NULL;
486 if ( (GNUNET_YES == ve->expecting_pong) &&
487 (validations_running > 0) )
489 validations_running--;
490 GNUNET_STATISTICS_set (GST_stats,
491 gettext_noop ("# validations running"),
501 * Address validation cleanup task. Assesses if the record is no
502 * longer valid and then possibly triggers its removal.
504 * @param cls the `struct ValidationEntry`
507 timeout_hello_validation (void *cls)
509 struct ValidationEntry *ve = cls;
510 struct GNUNET_TIME_Absolute max;
511 struct GNUNET_TIME_Relative left;
513 ve->timeout_task = NULL;
514 /* For valid addresses, we want to wait until the expire;
515 for addresses under PING validation, we want to wait
516 until we give up on the PING */
517 max = GNUNET_TIME_absolute_max (ve->valid_until,
518 ve->revalidation_block);
519 left = GNUNET_TIME_absolute_get_remaining (max);
520 if (left.rel_value_us > 0)
522 /* We should wait a bit longer. This happens when
523 address lifetimes are extended due to successful
526 GNUNET_SCHEDULER_add_delayed (left,
527 &timeout_hello_validation,
531 GNUNET_STATISTICS_update (GST_stats,
532 gettext_noop ("# address records discarded (timeout)"),
535 cleanup_validation_entry (NULL,
542 * Function called with the result from blacklisting.
543 * Send a PING to the other peer if a communication is allowed.
545 * @param cls our `struct ValidationEntry`
546 * @param pid identity of the other peer
547 * @param address_null address associated with the request, always NULL
548 * @param session_null session associated with the request, always NULL
549 * @param result #GNUNET_OK if the connection is allowed,
551 * #GNUNET_SYSERR if operation was aborted
554 transmit_ping_if_allowed (void *cls,
555 const struct GNUNET_PeerIdentity *pid,
556 const struct GNUNET_HELLO_Address *address_null,
557 struct GNUNET_ATS_Session *session_null,
560 struct ValidationEntry *ve = cls;
561 struct TransportPingMessage ping;
562 struct GNUNET_TRANSPORT_PluginFunctions *papi;
563 struct GNUNET_TIME_Absolute next;
564 const struct GNUNET_MessageHeader *hello;
569 struct GNUNET_ATS_Session *session;
572 if (GNUNET_OK != result)
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
575 "Blacklist denies sending PING to `%s' `%s' `%s'\n",
577 GST_plugins_a2s (ve->address),
578 ve->address->transport_name);
579 GNUNET_STATISTICS_update (GST_stats,
580 gettext_noop ("# address records discarded (blacklist)"),
583 cleanup_validation_entry (NULL,
588 hello = GST_hello_get ();
589 GNUNET_assert (NULL != hello);
590 slen = strlen (ve->address->transport_name) + 1;
591 hsize = ntohs (hello->size);
592 tsize = sizeof (struct TransportPingMessage) +
593 ve->address->address_length + slen + hsize;
596 htons (sizeof (struct TransportPingMessage) +
597 ve->address->address_length + slen);
598 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
599 ping.challenge = htonl (ve->challenge);
602 if (tsize >= GNUNET_MAX_MESSAGE_SIZE)
607 sizeof (struct TransportPingMessage) + ve->address->address_length +
611 char message_buf[tsize] GNUNET_ALIGN;
613 GNUNET_memcpy (message_buf,
616 GNUNET_memcpy (&message_buf[hsize],
618 sizeof (struct TransportPingMessage));
619 GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
620 ve->address->transport_name,
622 GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
623 ve->address->address,
624 ve->address->address_length);
625 papi = GST_plugins_find (ve->address->transport_name);
626 GNUNET_assert (NULL != papi);
627 session = papi->get_session (papi->cls,
631 /* Could not get a valid session */
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
633 "Failed to get session to send PING to `%s' at `%s'\n",
635 GST_plugins_a2s (ve->address));
639 ret = papi->send (papi->cls, session,
642 ACCEPTABLE_PING_DELAY,
646 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
647 "Failed to send PING to `%s' at `%s'\n",
649 GST_plugins_a2s (ve->address));
652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
653 "Transmitted plain PING to `%s' `%s' `%s'\n",
655 GST_plugins_a2s (ve->address),
656 ve->address->transport_name);
657 ve->network = papi->get_network (papi->cls,
659 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
660 GST_neighbours_notify_data_sent (ve->address,
663 next = GNUNET_TIME_relative_to_absolute (validation_delay);
664 validation_next = GNUNET_TIME_absolute_max (next,
666 ve->send_time = GNUNET_TIME_absolute_get ();
667 GNUNET_STATISTICS_update (GST_stats,
668 gettext_noop ("# PINGs for address validation sent"),
671 ve->expecting_pong = GNUNET_YES;
672 validations_running++;
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "Validation started, %u validation processes running\n",
675 validations_running);
676 GNUNET_STATISTICS_set (GST_stats,
677 gettext_noop ("# validations running"),
680 /* Notify about PING sent */
681 validation_entry_changed (ve,
682 GNUNET_TRANSPORT_VS_UPDATE);
689 * Do address validation again to keep address valid.
691 * @param cls the `struct ValidationEntry`
694 revalidate_address (void *cls)
696 struct ValidationEntry *ve = cls;
697 struct GNUNET_TIME_Relative canonical_delay;
698 struct GNUNET_TIME_Relative delay;
699 struct GNUNET_TIME_Relative blocked_for;
700 struct GST_BlacklistCheck *bc;
703 ve->revalidation_task = NULL;
704 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
705 /* Considering current connectivity situation, what is the maximum
706 block period permitted? */
707 if (GNUNET_YES == ve->in_use)
708 canonical_delay = CONNECTED_PING_FREQUENCY;
709 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0)
710 canonical_delay = VALIDATED_PING_FREQUENCY;
712 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
713 /* Use delay that is MIN of original delay and possibly adjusted
714 new maximum delay (which may be lower); the real delay
715 is originally randomized between "canonical_delay" and "2 * canonical_delay",
716 so continue to permit that window for the operation. */
717 delay = GNUNET_TIME_relative_min (delay,
718 GNUNET_TIME_relative_multiply (canonical_delay,
720 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
721 if (delay.rel_value_us > 0)
723 /* should wait a bit longer */
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
725 "Waiting for %s longer before (re)validating address `%s'\n",
726 GNUNET_STRINGS_relative_time_to_string (delay,
728 GST_plugins_a2s (ve->address));
729 ve->revalidation_task =
730 GNUNET_SCHEDULER_add_delayed (delay,
731 &revalidate_address, ve);
732 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
735 /* check if globally we have too many active validations at a
736 too high rate, if so, delay ours */
737 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next);
738 if ( (validations_running > validations_fast_start_threshold) &&
739 (blocked_for.rel_value_us > 0) )
741 /* Validations are blocked, have to wait for blocked_for time */
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "Validations blocked for another %s, delaying validating address `%s'\n",
744 GNUNET_STRINGS_relative_time_to_string (blocked_for,
746 GST_plugins_a2s (ve->address));
747 GNUNET_STATISTICS_update (GST_stats,
748 gettext_noop ("# validations delayed by global throttle"),
751 ve->revalidation_task =
752 GNUNET_SCHEDULER_add_delayed (blocked_for,
755 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
759 /* We are good to go; remember to not go again for `canonical_delay` time;
760 add up to `canonical_delay` to randomize start time */
761 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
762 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
764 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
765 canonical_delay.rel_value_us);
767 delay = GNUNET_TIME_relative_add (canonical_delay,
768 GNUNET_TIME_relative_multiply
769 (GNUNET_TIME_UNIT_MICROSECONDS,
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
773 "Validating now, next scheduled for %s, now validating address `%s'\n",
774 GNUNET_STRINGS_relative_time_to_string (blocked_for,
776 GST_plugins_a2s (ve->address));
777 ve->revalidation_task =
778 GNUNET_SCHEDULER_add_delayed (delay,
781 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
783 /* start PINGing by checking blacklist */
784 GNUNET_STATISTICS_update (GST_stats,
785 gettext_noop ("# address revalidations started"), 1,
789 GST_blacklist_test_cancel (ve->bc);
792 bc = GST_blacklist_test_allowed (&ve->address->peer,
793 ve->address->transport_name,
794 &transmit_ping_if_allowed,
800 /* 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.
809 * Find a ValidationEntry entry for the given neighbour that matches
810 * the given address and transport. If none exists, create one (but
811 * without starting any validation).
813 * @param address address to find
814 * @return validation entry matching the given specifications, NULL
815 * if we don't have an existing entry and no public key was given
817 static struct ValidationEntry *
818 find_validation_entry (const struct GNUNET_HELLO_Address *address)
820 struct ValidationEntryMatchContext vemc;
821 struct ValidationEntry *ve;
824 vemc.address = address;
825 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
827 &validation_entry_match, &vemc);
828 if (NULL != (ve = vemc.ve))
830 GNUNET_assert (GNUNET_NO ==
831 GST_ats_is_known_no_session (address));
832 ve = GNUNET_new (struct ValidationEntry);
833 ve->in_use = GNUNET_SYSERR; /* not defined */
834 ve->address = GNUNET_HELLO_address_copy (address);
835 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
836 memset (&ve->pong_sig_cache,
838 sizeof (struct GNUNET_CRYPTO_EddsaSignature));
839 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
841 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
843 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
844 &timeout_hello_validation,
846 GNUNET_CONTAINER_multipeermap_put (validation_map,
849 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
850 publish_ve_stat_update ();
851 validation_entry_changed (ve,
852 GNUNET_TRANSPORT_VS_NEW);
858 * Iterator which adds the given address to the set of validated
861 * @param cls original HELLO message
862 * @param address the address
863 * @param expiration expiration time
864 * @return #GNUNET_OK (keep the address), could return
865 * #GNUNET_NO (delete address, but this is ignored);
866 * #GNUNET_SYSERR would abort iteration (but we always iterate all)
869 add_valid_address (void *cls,
870 const struct GNUNET_HELLO_Address *address,
871 struct GNUNET_TIME_Absolute expiration)
873 const struct GNUNET_HELLO_Message *hello = cls;
874 struct ValidationEntry *ve;
875 struct GNUNET_PeerIdentity pid;
876 struct GNUNET_ATS_Properties prop;
877 struct GNUNET_TRANSPORT_PluginFunctions *papi;
879 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
880 return GNUNET_OK; /* expired */
881 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
884 return GNUNET_OK; /* invalid HELLO !? */
886 if (NULL == (papi = GST_plugins_find (address->transport_name)))
888 /* might have been valid in the past, but we don't have that
889 plugin loaded right now */
893 papi->address_to_string (papi->cls,
895 address->address_length))
897 /* Why do we try to add an ill-formed address? */
899 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
900 "Address with %u bytes for plugin %s and peer %s is malformed\n",
901 (unsigned int) address->address_length,
902 address->transport_name,
907 ve = find_validation_entry (address);
908 ve->network = papi->get_network_for_address (papi->cls,
910 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
911 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
913 if (NULL == ve->revalidation_task)
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Starting revalidations for valid address `%s'\n",
917 GST_plugins_a2s (ve->address));
918 ve->next_validation = GNUNET_TIME_absolute_get();
919 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
921 validation_entry_changed (ve,
922 GNUNET_TRANSPORT_VS_UPDATE);
923 memset (&prop, 0, sizeof (prop));
924 prop.scope = ve->network;
925 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
926 if (GNUNET_YES != ve->known_to_ats)
928 ve->known_to_ats = GNUNET_YES;
929 GST_ats_add_address (address, &prop);
930 GNUNET_assert (GNUNET_YES ==
931 GST_ats_is_known_no_session (ve->address));
938 * Function called for any HELLO known to PEERINFO.
940 * @param cls unused (NULL)
941 * @param peer id of the peer, NULL for last call (during iteration,
942 * as we are monitoring, this should never happen)
943 * @param hello hello message for the peer (can be NULL)
944 * @param err_msg error message
947 process_peerinfo_hello (void *cls,
948 const struct GNUNET_PeerIdentity *peer,
949 const struct GNUNET_HELLO_Message *hello,
952 GNUNET_assert (NULL != peer);
955 if (0 == memcmp (&GST_my_identity,
957 sizeof (struct GNUNET_PeerIdentity)))
959 /* Peerinfo returned own identity, skip validation */
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Handling HELLO for peer `%s'\n",
965 GNUNET_assert (NULL ==
966 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
973 * Start the validation subsystem.
975 * @param max_fds maximum number of fds to use
978 GST_validation_start (unsigned int max_fds)
981 * Initialization for validation throttling
983 * We have a maximum number max_fds of connections we can use for validation
984 * We monitor the number of validations in parallel and start to throttle it
985 * when doing to many validations in parallel:
986 * if (running validations < (max_fds / 2))
987 * - "fast start": run validation immediately
988 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
989 * (300 sec / ~150 == ~2 sec.) between two validations
992 validation_next = GNUNET_TIME_absolute_get();
993 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
994 validations_fast_start_threshold = (max_fds / 2);
995 validations_running = 0;
996 GNUNET_STATISTICS_set (GST_stats,
997 gettext_noop ("# validations running"),
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1001 "Validation uses a fast start threshold of %u connections and a delay of %s\n",
1002 validations_fast_start_threshold,
1003 GNUNET_STRINGS_relative_time_to_string (validation_delay,
1005 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
1007 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
1008 &process_peerinfo_hello, NULL);
1013 * Stop the validation subsystem.
1016 GST_validation_stop ()
1018 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1019 &cleanup_validation_entry,
1021 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
1022 validation_map = NULL;
1023 GNUNET_PEERINFO_notify_cancel (pnc);
1028 * Send the given PONG to the given address.
1030 * @param cls the PONG message
1031 * @param valid_until is ZERO if we never validated the address,
1032 * otherwise a time up to when we consider it (or was) valid
1033 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
1034 * is ZERO if the address is considered valid (no validation needed)
1035 * otherwise a time in the future if we're currently denying re-validation
1036 * @param address target address
1039 multicast_pong (void *cls,
1040 struct GNUNET_TIME_Absolute valid_until,
1041 struct GNUNET_TIME_Absolute validation_block,
1042 const struct GNUNET_HELLO_Address *address)
1044 struct TransportPongMessage *pong = cls;
1045 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1046 struct GNUNET_ATS_Session *session;
1048 papi = GST_plugins_find (address->transport_name);
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1052 "Plugin %s not supported, cannot send PONG\n",
1053 address->transport_name);
1056 GNUNET_assert (NULL != papi->send);
1057 GNUNET_assert (NULL != papi->get_session);
1058 session = papi->get_session(papi->cls, address);
1059 if (NULL == session)
1064 GST_ats_new_session (address, session);
1065 papi->send (papi->cls, session,
1066 (const char *) pong,
1067 ntohs (pong->header.size),
1069 ACCEPTABLE_PING_DELAY,
1071 GST_neighbours_notify_data_sent (address,
1078 * We've received a PING. If appropriate, generate a PONG.
1080 * @param sender peer sending the PING
1081 * @param hdr the PING
1082 * @param sender_address the sender address as we got it
1083 * @param session session we got the PING from
1084 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1087 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1088 const struct GNUNET_MessageHeader *hdr,
1089 const struct GNUNET_HELLO_Address *sender_address,
1090 struct GNUNET_ATS_Session *session)
1092 const struct TransportPingMessage *ping;
1093 struct TransportPongMessage *pong;
1094 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1095 struct GNUNET_CRYPTO_EddsaSignature *sig_cache;
1096 struct GNUNET_TIME_Absolute *sig_cache_exp;
1098 const char *addrend;
1104 struct GNUNET_HELLO_Address address;
1107 memcmp (&GST_my_identity,
1109 sizeof (struct GNUNET_PeerIdentity)))
1110 return GNUNET_OK; /* our own, ignore! */
1111 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
1113 GNUNET_break_op (0);
1114 return GNUNET_SYSERR;
1116 ping = (const struct TransportPingMessage *) hdr;
1118 memcmp (&ping->target,
1120 sizeof (struct GNUNET_PeerIdentity)))
1122 GNUNET_STATISTICS_update (GST_stats,
1124 ("# PING message for different peer received"), 1,
1126 return GNUNET_SYSERR;
1128 GNUNET_STATISTICS_update (GST_stats,
1129 gettext_noop ("# PING messages received"), 1,
1131 addr = (const char *) &ping[1];
1132 len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
1133 /* peer wants to confirm that this is one of our addresses, this is what is
1134 * used for address validation */
1137 sig_cache_exp = NULL;
1139 if (len_address > 0)
1141 addrend = memchr (addr, '\0', len_address);
1142 if (NULL == addrend)
1144 GNUNET_break_op (0);
1145 return GNUNET_SYSERR;
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;
1156 if (NULL == address.transport_name)
1161 if (0 != strstr (address.transport_name, "_client"))
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");
1169 plugin_name = GNUNET_strdup (address.transport_name);
1171 if (NULL == (papi = GST_plugins_find (plugin_name)))
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"),
1177 GNUNET_free (plugin_name);
1178 return GNUNET_SYSERR;
1180 GNUNET_free (plugin_name);
1182 papi->check_address (papi->cls,
1186 GNUNET_STATISTICS_update (GST_stats,
1188 ("# failed address checks during validation"), 1,
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;
1197 GNUNET_STATISTICS_update (GST_stats,
1199 ("# successful address checks during validation"), 1,
1201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1202 "Address `%s' is one of my addresses, confirming PING\n",
1203 GST_plugins_a2s (&address));
1207 GST_hello_test_address (&address,
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;
1220 addrend = NULL; /* make gcc happy */
1222 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1223 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1225 sig_cache = &no_address_signature;
1226 sig_cache_exp = &no_address_signature_expiration;
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));
1234 /* message with structure:
1235 * [TransportPongMessage][Transport name][Address] */
1237 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1239 htons (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1240 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1241 pong->purpose.size =
1242 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1243 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1244 len_address + len_plugin);
1245 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1246 GNUNET_memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
1247 pong->addrlen = htonl (len_address + len_plugin);
1248 GNUNET_memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */
1249 if (len_address > 0)
1251 GNUNET_assert (NULL != addrend);
1252 GNUNET_memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address);
1254 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1255 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
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);
1263 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1267 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender));
1272 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1274 pong->signature = *sig_cache;
1276 GNUNET_assert (NULL != sender_address);
1278 /* first see if the session we got this PING from can be used to transmit
1279 * a response reliably */
1286 GNUNET_assert (NULL != papi->send);
1287 GNUNET_assert (NULL != papi->get_session);
1288 if (NULL == session)
1290 session = papi->get_session (papi->cls, sender_address);
1292 if (NULL == session)
1299 ret = papi->send (papi->cls, session,
1300 (const char *) pong,
1301 ntohs (pong->header.size),
1302 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1305 GST_neighbours_notify_data_sent (sender_address,
1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1313 "Transmitted PONG to `%s' via reliable mechanism\n",
1314 GNUNET_i2s (sender));
1316 GNUNET_STATISTICS_update (GST_stats,
1318 ("# PONGs unicast via reliable transport"), 1,
1324 /* no reliable method found, try transmission via all known addresses */
1325 GNUNET_STATISTICS_update (GST_stats,
1327 ("# PONGs multicast to all available addresses"), 1,
1329 GST_validation_get_addresses (sender,
1330 &multicast_pong, pong);
1337 * Validate an individual address.
1339 * @param address address we should try to validate
1342 GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1344 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1345 struct ValidationEntry *ve;
1347 papi = GST_plugins_find (address->transport_name);
1350 /* This plugin is currently unvailable ... ignore */
1351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1352 "No plugin available for %s\n",
1353 address->transport_name);
1356 ve = find_validation_entry (address);
1357 if (NULL == ve->revalidation_task)
1359 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1360 "Validation process started for fresh address `%s' of %s\n",
1361 GST_plugins_a2s (ve->address),
1362 GNUNET_i2s (&ve->address->peer));
1363 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1367 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1368 "Validation already running for address `%s' of %s\n",
1369 GST_plugins_a2s (ve->address),
1370 GNUNET_i2s (&ve->address->peer));
1376 * Iterator callback to go over all addresses and try to validate them
1377 * (unless blocked or already validated).
1380 * @param address the address
1381 * @param expiration expiration time
1382 * @return #GNUNET_OK (keep the address)
1385 validate_address_iterator (void *cls,
1386 const struct GNUNET_HELLO_Address *address,
1387 struct GNUNET_TIME_Absolute expiration)
1389 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1392 "Skipping expired address from HELLO\n");
1393 return GNUNET_OK; /* expired */
1395 GST_validation_handle_address (address);
1401 * Add the validated peer address to the HELLO.
1403 * @param cls the `struct ValidationEntry *` with the validated address
1404 * @param max space in @a buf
1405 * @param buf where to add the address
1406 * @return number of bytes written, #GNUNET_SYSERR to signal the
1407 * end of the iteration.
1410 add_valid_peer_address (void *cls,
1414 struct ValidationEntry *ve = cls;
1416 if (GNUNET_YES == ve->copied)
1417 return GNUNET_SYSERR; /* Done */
1418 ve->copied = GNUNET_YES;
1419 return GNUNET_HELLO_add_address (ve->address,
1427 * We've received a PONG. Check if it matches a pending PING and
1428 * mark the respective address as confirmed.
1430 * @param sender peer sending the PONG
1431 * @param hdr the PONG
1432 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1435 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1436 const struct GNUNET_MessageHeader *hdr)
1438 const struct TransportPongMessage *pong;
1439 struct ValidationEntry *ve;
1445 struct GNUNET_HELLO_Message *hello;
1446 struct GNUNET_HELLO_Address address;
1451 memcmp (&GST_my_identity,
1453 sizeof (struct GNUNET_PeerIdentity)))
1454 return GNUNET_OK; /* our own, ignore! */
1456 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1458 GNUNET_break_op (0);
1459 return GNUNET_SYSERR;
1461 GNUNET_STATISTICS_update (GST_stats,
1462 gettext_noop ("# PONG messages received"), 1,
1465 /* message with structure:
1466 * [TransportPongMessage][Transport name][Address] */
1468 pong = (const struct TransportPongMessage *) hdr;
1469 tname = (const char *) &pong[1];
1470 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1471 addr = memchr (tname, '\0', size);
1474 GNUNET_break_op (0);
1475 return GNUNET_SYSERR;
1478 slen = strlen (tname) + 1;
1479 addrlen = size - slen;
1481 if (NULL == GST_plugins_find (tname))
1483 /* we got the PONG, but the transport plugin specified in it
1484 is not supported by this peer, so this cannot be a good
1486 GNUNET_break_op (0);
1490 address.peer = *sender;
1491 address.address = addr;
1492 address.address_length = addrlen;
1493 address.transport_name = tname;
1494 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1495 ve = find_validation_entry (&address);
1496 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1498 GNUNET_STATISTICS_update (GST_stats,
1500 ("# PONGs dropped, no matching pending validation"),
1504 /* now check that PONG is well-formed */
1505 if (0 != memcmp (&ve->address->peer,
1507 sizeof (struct GNUNET_PeerIdentity)))
1509 GNUNET_break_op (0);
1510 return GNUNET_SYSERR;
1513 GNUNET_TIME_absolute_get_remaining
1514 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us)
1516 GNUNET_STATISTICS_update (GST_stats,
1518 ("# PONGs dropped, signature expired"), 1,
1520 return GNUNET_SYSERR;
1523 sig_res = GNUNET_SYSERR;
1524 do_verify = GNUNET_YES;
1525 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
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,
1531 sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1533 /* signatures are identical, we can skip verification */
1534 sig_res = GNUNET_OK;
1535 do_verify = GNUNET_NO;
1539 sig_res = GNUNET_SYSERR;
1540 /* signatures do not match, we have to verify */
1544 if (GNUNET_YES == do_verify)
1546 /* Do expensive verification */
1547 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1550 &ve->address->peer.public_key);
1551 if (sig_res == GNUNET_SYSERR)
1553 GNUNET_break_op (0);
1554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1555 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1557 GST_plugins_a2s (ve->address),
1558 GNUNET_i2s (sender));
1561 if (sig_res == GNUNET_SYSERR)
1563 GNUNET_break_op (0);
1564 return GNUNET_SYSERR;
1567 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1568 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1569 GNUNET_i2s (sender),
1571 GST_plugins_a2s (ve->address));
1572 GNUNET_STATISTICS_update (GST_stats,
1573 gettext_noop ("# validations succeeded"),
1576 /* validity achieved, remember it! */
1577 ve->expecting_pong = GNUNET_NO;
1578 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1579 ve->pong_sig_cache = pong->signature;
1580 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1581 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1583 if (GNUNET_YES == ve->known_to_ats)
1585 GNUNET_assert (GNUNET_YES ==
1586 GST_ats_is_known_no_session (ve->address));
1587 GST_ats_update_delay (ve->address,
1588 GNUNET_TIME_relative_divide (ve->latency, 2));
1592 struct GNUNET_ATS_Properties prop;
1594 memset (&prop, 0, sizeof (prop));
1595 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network);
1596 prop.scope = ve->network;
1597 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
1598 GNUNET_assert (GNUNET_NO ==
1599 GST_ats_is_known_no_session (ve->address));
1600 ve->known_to_ats = GNUNET_YES;
1601 GST_ats_add_address (ve->address, &prop);
1602 GNUNET_assert (GNUNET_YES ==
1603 GST_ats_is_known_no_session (ve->address));
1606 if (validations_running > 0)
1608 validations_running--;
1609 GNUNET_STATISTICS_set (GST_stats,
1610 gettext_noop ("# validations running"),
1611 validations_running,
1613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1614 "Validation finished, %u validation processes running\n",
1615 validations_running);
1622 /* Notify about new validity */
1623 validation_entry_changed (ve,
1624 GNUNET_TRANSPORT_VS_UPDATE);
1626 /* build HELLO to store in PEERINFO */
1627 GNUNET_STATISTICS_update (GST_stats,
1628 gettext_noop ("# HELLOs given to peerinfo"),
1631 ve->copied = GNUNET_NO;
1632 hello = GNUNET_HELLO_create (&ve->address->peer.public_key,
1633 &add_valid_peer_address,
1636 GNUNET_break (NULL !=
1637 GNUNET_PEERINFO_add_peer (GST_peerinfo,
1641 GNUNET_free (hello);
1647 * We've received a HELLO, check which addresses are new and trigger
1650 * @param hello the HELLO we received
1651 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1654 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1656 const struct GNUNET_HELLO_Message *hm =
1657 (const struct GNUNET_HELLO_Message *) hello;
1658 struct GNUNET_PeerIdentity pid;
1661 friend = GNUNET_HELLO_is_friend_only (hm);
1662 if ( ( (GNUNET_YES != friend) &&
1663 (GNUNET_NO != friend) ) ||
1664 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) )
1666 /* malformed HELLO */
1667 GNUNET_break_op (0);
1668 return GNUNET_SYSERR;
1671 memcmp (&GST_my_identity,
1673 sizeof (struct GNUNET_PeerIdentity)))
1675 /* got our own HELLO, how boring */
1676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1677 "Validation received our own HELLO (%s), ignoring\n",
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n",
1684 ntohs (hello->size));
1685 GNUNET_assert (NULL ==
1686 GNUNET_HELLO_iterate_addresses (hm,
1688 &validate_address_iterator,
1695 * Closure for #iterate_addresses().
1697 struct IteratorContext
1700 * Function to call on each address.
1702 GST_ValidationAddressCallback cb;
1705 * Closure for @e cb.
1713 * Call the callback in the closure for each validation entry.
1715 * @param cls the `struct IteratorContext`
1716 * @param key the peer's identity
1717 * @param value the `struct ValidationEntry`
1718 * @return #GNUNET_OK (continue to iterate)
1721 iterate_addresses (void *cls,
1722 const struct GNUNET_PeerIdentity *key,
1725 struct IteratorContext *ic = cls;
1726 struct ValidationEntry *ve = value;
1730 ve->revalidation_block,
1737 * Call the given function for each address for the given target.
1738 * Can either give a snapshot (synchronous API) or be continuous.
1740 * @param target peer information is requested for
1741 * @param cb function to call; will not be called after this function returns
1742 * @param cb_cls closure for @a cb
1745 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1746 GST_ValidationAddressCallback cb,
1749 struct IteratorContext ic;
1753 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1755 &iterate_addresses, &ic);
1760 * Update if we are using an address for a connection actively right now.
1761 * Based on this, the validation module will measure latency for the
1762 * address more or less often.
1764 * @param address the address that we are now using (or not)
1765 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1766 * #GNUNET_NO if we are no longer using the address for a connection
1769 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1772 struct ValidationEntry *ve;
1774 if (GNUNET_HELLO_address_check_option (address,
1775 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1776 return; /* ignore inbound for validation */
1777 if (NULL == GST_plugins_find (address->transport_name))
1779 /* How can we use an address for which we don't have the plugin? */
1783 ve = find_validation_entry (address);
1789 if (in_use == ve->in_use)
1791 ve->in_use = in_use;
1792 if (GNUNET_YES == in_use)
1794 /* from now on, higher frequeny, so reschedule now */
1795 if (NULL != ve->revalidation_task)
1796 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1797 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address,
1803 /* end of file gnunet-service-transport_validation.c */