2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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_blacklist.h"
29 #include "gnunet-service-transport_clients.h"
30 #include "gnunet-service-transport_hello.h"
31 #include "gnunet-service-transport_neighbours.h"
32 #include "gnunet-service-transport_plugins.h"
33 #include "gnunet-service-transport_validation.h"
34 #include "gnunet-service-transport.h"
35 #include "gnunet_hello_lib.h"
36 #include "gnunet_ats_service.h"
37 #include "gnunet_peerinfo_service.h"
38 #include "gnunet_signatures.h"
42 * How long is a PONG signature valid? We'll recycle a signature until
43 * 1/4 of this time is remaining. PONGs should expire so that if our
44 * external addresses change an adversary cannot replay them indefinitely.
45 * OTOH, we don't want to spend too much time generating PONG signatures,
46 * so they must have some lifetime to reduce our CPU usage.
48 #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
51 * After how long do we expire an address in a HELLO that we just
52 * validated? This value is also used for our own addresses when we
55 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
58 * How often do we allow PINGing an address that we have not yet
59 * validated? This also determines how long we track an address that
60 * we cannot validate (because after this time we can destroy the
63 #define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
66 * How often do we PING an address that we have successfully validated
67 * in the past but are not actively using? Should be (significantly)
68 * smaller than HELLO_ADDRESS_EXPIRATION.
70 #define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
73 * How often do we PING an address that we are currently using?
75 #define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
78 * How much delay is acceptable for sending the PING or PONG?
80 #define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
83 * Size of the validation map hashmap.
85 #define VALIDATION_MAP_SIZE 256
88 * Priority to use for PINGs
90 #define PING_PRIORITY 2
93 * Priority to use for PONGs
95 #define PONG_PRIORITY 4
98 GNUNET_NETWORK_STRUCT_BEGIN
101 * Message used to ask a peer to validate receipt (to check an address
102 * from a HELLO). Followed by the address we are trying to validate,
103 * or an empty address if we are just sending a PING to confirm that a
104 * connection which the receiver (of the PING) initiated is still valid.
106 struct TransportPingMessage
110 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING
112 struct GNUNET_MessageHeader header;
115 * Challenge code (to ensure fresh reply).
117 uint32_t challenge GNUNET_PACKED;
120 * Who is the intended recipient?
122 struct GNUNET_PeerIdentity target;
128 * Message used to validate a HELLO. The challenge is included in the
129 * confirmation to make matching of replies to requests possible. The
130 * signature signs our public key, an expiration time and our address.<p>
132 * This message is followed by our transport address that the PING tried
133 * to confirm (if we liked it). The address can be empty (zero bytes)
134 * if the PING had not address either (and we received the request via
135 * a connection that we initiated).
137 struct TransportPongMessage
141 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
143 struct GNUNET_MessageHeader header;
146 * Challenge code from PING (showing freshness). Not part of what
147 * is signed so that we can re-use signatures.
149 uint32_t challenge GNUNET_PACKED;
154 struct GNUNET_CRYPTO_EddsaSignature signature;
157 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
158 * plausible address for the signing peer.
160 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
163 * When does this signature expire?
165 struct GNUNET_TIME_AbsoluteNBO expiration;
168 * Size of address appended to this message (part of what is
169 * being signed, hence not redundant).
171 uint32_t addrlen GNUNET_PACKED;
174 GNUNET_NETWORK_STRUCT_END
177 * Information about an address under validation
179 struct ValidationEntry
185 struct GNUNET_HELLO_Address *address;
188 * Handle to the blacklist check (if we're currently in it).
190 struct GST_BlacklistCheck *bc;
193 * Cached PONG signature
195 struct GNUNET_CRYPTO_EddsaSignature pong_sig_cache;
198 * ID of task that will clean up this entry if nothing happens.
200 struct GNUNET_SCHEDULER_Task *timeout_task;
203 * ID of task that will trigger address revalidation.
205 struct GNUNET_SCHEDULER_Task *revalidation_task;
208 * At what time did we send the latest validation request (PING)?
210 struct GNUNET_TIME_Absolute send_time;
213 * At what time do we send the next validation request (PING)?
215 struct GNUNET_TIME_Absolute next_validation;
218 * Until when is this address valid?
219 * ZERO if it is not currently considered valid.
221 struct GNUNET_TIME_Absolute valid_until;
224 * Until when is the cached PONG signature valid?
225 * ZERO if it is not currently considered valid.
227 struct GNUNET_TIME_Absolute pong_sig_valid_until;
230 * How long until we can try to validate this address again?
231 * FOREVER if the address is for an unsupported plugin (from PEERINFO)
232 * ZERO if the address is considered valid (no validation needed)
233 * otherwise a time in the future if we're currently denying re-validation
235 struct GNUNET_TIME_Absolute revalidation_block;
238 * Last observed latency for this address (round-trip), delay between
239 * last PING sent and PONG received; FOREVER if we never got a PONG.
241 struct GNUNET_TIME_Relative latency;
244 * Current state of this validation entry
246 enum GNUNET_TRANSPORT_ValidationState state;
249 * Challenge number we used.
254 * When passing the address in #add_valid_peer_address(), did we
255 * copy the address to the HELLO yet?
260 * Are we currently using this address for a connection?
265 * Are we expecting a PONG message for this validation entry?
270 * Is this address known to ATS as valid right now?
275 * Which network type does our address belong to?
277 enum GNUNET_ATS_Network_Type network;
282 * Map of PeerIdentities to 'struct ValidationEntry*'s (addresses
283 * of the given peer that we are currently validating, have validated
284 * or are blocked from re-validation for a while).
286 static struct GNUNET_CONTAINER_MultiPeerMap *validation_map;
289 * Context for peerinfo iteration.
291 static struct GNUNET_PEERINFO_NotifyContext *pnc;
294 * Minimum delay between to validations
296 static struct GNUNET_TIME_Relative validation_delay;
299 * Number of validations running; any PING that was not yet
300 * matched by a PONG and for which we have not yet hit the
301 * timeout is considered a running 'validation'.
303 static unsigned int validations_running;
306 * Validition fast start threshold
308 static unsigned int validations_fast_start_threshold;
311 * When is next validation allowed
313 static struct GNUNET_TIME_Absolute validation_next;
317 * Context for the validation entry match function.
319 struct ValidationEntryMatchContext
322 * Where to store the result?
324 struct ValidationEntry *ve;
327 * Address we're interested in.
329 const struct GNUNET_HELLO_Address *address;
335 * Provide an update on the `validation_map` map size to statistics.
336 * This function should be called whenever the `validation_map`
340 publish_ve_stat_update ()
342 GNUNET_STATISTICS_set (GST_stats,
343 gettext_noop ("# Addresses in validation map"),
344 GNUNET_CONTAINER_multipeermap_size (validation_map),
350 * Iterate over validation entries until a matching one is found.
352 * @param cls the `struct ValidationEntryMatchContext *`
353 * @param key peer identity (unused)
354 * @param value a `struct ValidationEntry *` to match
355 * @return #GNUNET_YES if the entry does not match,
356 * #GNUNET_NO if the entry does match
359 validation_entry_match (void *cls,
360 const struct GNUNET_PeerIdentity *key,
363 struct ValidationEntryMatchContext *vemc = cls;
364 struct ValidationEntry *ve = value;
366 if (0 == GNUNET_HELLO_address_cmp (ve->address,
377 * A validation entry changed. Update the state and notify
380 * @param ve validation entry that changed
381 * @param state new state
384 validation_entry_changed (struct ValidationEntry *ve,
385 enum GNUNET_TRANSPORT_ValidationState state)
388 GST_clients_broadcast_validation_notification (&ve->address->peer,
398 * Iterate over validation entries and free them.
400 * @param cls (unused)
401 * @param key peer identity (unused)
402 * @param value a `struct ValidationEntry *` to clean up
403 * @return #GNUNET_YES (continue to iterate)
406 cleanup_validation_entry (void *cls,
407 const struct GNUNET_PeerIdentity *key,
410 struct ValidationEntry *ve = value;
412 ve->next_validation = GNUNET_TIME_UNIT_ZERO_ABS;
413 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
415 /* Notify about deleted entry */
416 validation_entry_changed (ve,
417 GNUNET_TRANSPORT_VS_REMOVE);
421 GST_blacklist_test_cancel (ve->bc);
424 GNUNET_break (GNUNET_OK ==
425 GNUNET_CONTAINER_multipeermap_remove (validation_map,
428 publish_ve_stat_update ();
429 if (GNUNET_YES == ve->known_to_ats)
431 GST_ats_expire_address (ve->address);
432 GNUNET_assert (GNUNET_NO ==
433 GST_ats_is_known_no_session (ve->address));
434 ve->known_to_ats = GNUNET_NO;
436 GNUNET_HELLO_address_free (ve->address);
437 if (NULL != ve->timeout_task)
439 GNUNET_SCHEDULER_cancel (ve->timeout_task);
440 ve->timeout_task = NULL;
442 if (NULL != ve->revalidation_task)
444 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
445 ve->revalidation_task = NULL;
447 if ( (GNUNET_YES == ve->expecting_pong) &&
448 (validations_running > 0) )
450 validations_running--;
451 GNUNET_STATISTICS_set (GST_stats,
452 gettext_noop ("# validations running"),
462 * Address validation cleanup task. Assesses if the record is no
463 * longer valid and then possibly triggers its removal.
465 * @param cls the `struct ValidationEntry`
466 * @param tc scheduler context (unused)
469 timeout_hello_validation (void *cls,
470 const struct GNUNET_SCHEDULER_TaskContext *tc)
472 struct ValidationEntry *ve = cls;
473 struct GNUNET_TIME_Absolute max;
474 struct GNUNET_TIME_Relative left;
476 ve->timeout_task = NULL;
477 /* For valid addresses, we want to wait until the expire;
478 for addresses under PING validation, we want to wait
479 until we give up on the PING */
480 max = GNUNET_TIME_absolute_max (ve->valid_until,
481 ve->revalidation_block);
482 left = GNUNET_TIME_absolute_get_remaining (max);
483 if (left.rel_value_us > 0)
485 /* We should wait a bit longer. This happens when
486 address lifetimes are extended due to successful
489 GNUNET_SCHEDULER_add_delayed (left,
490 &timeout_hello_validation,
494 GNUNET_STATISTICS_update (GST_stats,
495 gettext_noop ("# address records discarded (timeout)"),
498 cleanup_validation_entry (NULL,
505 * Function called with the result from blacklisting.
506 * Send a PING to the other peer if a communication is allowed.
508 * @param cls our `struct ValidationEntry`
509 * @param pid identity of the other peer
510 * @param address_null address associated with the request, always NULL
511 * @param session_null session associated with the request, always NULL
512 * @param result #GNUNET_OK if the connection is allowed,
514 * #GNUNET_SYSERR if operation was aborted
517 transmit_ping_if_allowed (void *cls,
518 const struct GNUNET_PeerIdentity *pid,
519 const struct GNUNET_HELLO_Address *address_null,
520 struct GNUNET_ATS_Session *session_null,
523 struct ValidationEntry *ve = cls;
524 struct TransportPingMessage ping;
525 struct GNUNET_TRANSPORT_PluginFunctions *papi;
526 struct GNUNET_TIME_Absolute next;
527 const struct GNUNET_MessageHeader *hello;
532 struct GNUNET_ATS_Session *session;
535 if (GNUNET_OK != result)
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Blacklist denies sending PING to `%s' `%s' `%s'\n",
540 GST_plugins_a2s (ve->address),
541 ve->address->transport_name);
542 GNUNET_STATISTICS_update (GST_stats,
543 gettext_noop ("# address records discarded (blacklist)"),
546 cleanup_validation_entry (NULL,
551 hello = GST_hello_get ();
552 GNUNET_assert (NULL != hello);
553 slen = strlen (ve->address->transport_name) + 1;
554 hsize = ntohs (hello->size);
555 tsize = sizeof (struct TransportPingMessage) +
556 ve->address->address_length + slen + hsize;
559 htons (sizeof (struct TransportPingMessage) +
560 ve->address->address_length + slen);
561 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
562 ping.challenge = htonl (ve->challenge);
565 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
570 sizeof (struct TransportPingMessage) + ve->address->address_length +
574 char message_buf[tsize] GNUNET_ALIGN;
579 memcpy (&message_buf[hsize],
581 sizeof (struct TransportPingMessage));
582 memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
583 ve->address->transport_name,
585 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
586 ve->address->address,
587 ve->address->address_length);
588 papi = GST_plugins_find (ve->address->transport_name);
589 GNUNET_assert (NULL != papi);
590 session = papi->get_session (papi->cls,
594 /* Could not get a valid session */
595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
596 "Failed to get session to send PING to `%s' at `%s'\n",
598 GST_plugins_a2s (ve->address));
602 ret = papi->send (papi->cls, session,
605 ACCEPTABLE_PING_DELAY,
609 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
610 "Failed to send PING to `%s' at `%s'\n",
612 GST_plugins_a2s (ve->address));
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Transmitted plain PING to `%s' `%s' `%s'\n",
618 GST_plugins_a2s (ve->address),
619 ve->address->transport_name);
620 ve->network = papi->get_network (papi->cls,
622 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
623 GST_neighbours_notify_data_sent (ve->address,
626 next = GNUNET_TIME_relative_to_absolute (validation_delay);
627 validation_next = GNUNET_TIME_absolute_max (next,
629 ve->send_time = GNUNET_TIME_absolute_get ();
630 GNUNET_STATISTICS_update (GST_stats,
631 gettext_noop ("# PINGs for address validation sent"),
634 ve->expecting_pong = GNUNET_YES;
635 validations_running++;
636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
637 "Validation started, %u validation processes running\n",
638 validations_running);
639 GNUNET_STATISTICS_set (GST_stats,
640 gettext_noop ("# validations running"),
643 /* Notify about PING sent */
644 validation_entry_changed (ve,
645 GNUNET_TRANSPORT_VS_UPDATE);
652 * Do address validation again to keep address valid.
654 * @param cls the `struct ValidationEntry`
655 * @param tc scheduler context (unused)
658 revalidate_address (void *cls,
659 const struct GNUNET_SCHEDULER_TaskContext *tc)
661 struct ValidationEntry *ve = cls;
662 struct GNUNET_TIME_Relative canonical_delay;
663 struct GNUNET_TIME_Relative delay;
664 struct GNUNET_TIME_Relative blocked_for;
665 struct GST_BlacklistCheck *bc;
668 ve->revalidation_task = NULL;
669 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
670 /* Considering current connectivity situation, what is the maximum
671 block period permitted? */
672 if (GNUNET_YES == ve->in_use)
673 canonical_delay = CONNECTED_PING_FREQUENCY;
674 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0)
675 canonical_delay = VALIDATED_PING_FREQUENCY;
677 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
678 /* Use delay that is MIN of original delay and possibly adjusted
679 new maximum delay (which may be lower); the real delay
680 is originally randomized between "canonical_delay" and "2 * canonical_delay",
681 so continue to permit that window for the operation. */
682 delay = GNUNET_TIME_relative_min (delay,
683 GNUNET_TIME_relative_multiply (canonical_delay,
685 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
686 if (delay.rel_value_us > 0)
688 /* should wait a bit longer */
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "Waiting for %s longer before (re)validating address `%s'\n",
691 GNUNET_STRINGS_relative_time_to_string (delay,
693 GST_plugins_a2s (ve->address));
694 ve->revalidation_task =
695 GNUNET_SCHEDULER_add_delayed (delay,
696 &revalidate_address, ve);
697 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
700 /* check if globally we have too many active validations at a
701 too high rate, if so, delay ours */
702 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next);
703 if ( (validations_running > validations_fast_start_threshold) &&
704 (blocked_for.rel_value_us > 0) )
706 /* Validations are blocked, have to wait for blocked_for time */
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "Validations blocked for another %s, delaying validating address `%s'\n",
709 GNUNET_STRINGS_relative_time_to_string (blocked_for,
711 GST_plugins_a2s (ve->address));
712 GNUNET_STATISTICS_update (GST_stats,
713 gettext_noop ("# validations delayed by global throttle"),
716 ve->revalidation_task =
717 GNUNET_SCHEDULER_add_delayed (blocked_for,
720 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
724 /* We are good to go; remember to not go again for `canonical_delay` time;
725 add up to `canonical_delay` to randomize start time */
726 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
727 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
729 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
730 canonical_delay.rel_value_us);
732 delay = GNUNET_TIME_relative_add (canonical_delay,
733 GNUNET_TIME_relative_multiply
734 (GNUNET_TIME_UNIT_MICROSECONDS,
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Validating now, next scheduled for %s, now validating address `%s'\n",
739 GNUNET_STRINGS_relative_time_to_string (blocked_for,
741 GST_plugins_a2s (ve->address));
742 ve->revalidation_task =
743 GNUNET_SCHEDULER_add_delayed (delay,
746 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
748 /* start PINGing by checking blacklist */
749 GNUNET_STATISTICS_update (GST_stats,
750 gettext_noop ("# address revalidations started"), 1,
752 bc = GST_blacklist_test_allowed (&ve->address->peer,
753 ve->address->transport_name,
754 &transmit_ping_if_allowed,
759 ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already
765 * Find a ValidationEntry entry for the given neighbour that matches
766 * the given address and transport. If none exists, create one (but
767 * without starting any validation).
769 * @param address address to find
770 * @return validation entry matching the given specifications, NULL
771 * if we don't have an existing entry and no public key was given
773 static struct ValidationEntry *
774 find_validation_entry (const struct GNUNET_HELLO_Address *address)
776 struct ValidationEntryMatchContext vemc;
777 struct ValidationEntry *ve;
780 vemc.address = address;
781 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
783 &validation_entry_match, &vemc);
784 if (NULL != (ve = vemc.ve))
786 GNUNET_assert (GNUNET_NO ==
787 GST_ats_is_known_no_session (address));
788 ve = GNUNET_new (struct ValidationEntry);
789 ve->in_use = GNUNET_SYSERR; /* not defined */
790 ve->address = GNUNET_HELLO_address_copy (address);
791 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
792 memset (&ve->pong_sig_cache,
794 sizeof (struct GNUNET_CRYPTO_EddsaSignature));
795 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
797 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
799 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
800 &timeout_hello_validation,
802 GNUNET_CONTAINER_multipeermap_put (validation_map,
805 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
806 publish_ve_stat_update ();
807 validation_entry_changed (ve,
808 GNUNET_TRANSPORT_VS_NEW);
814 * Iterator which adds the given address to the set of validated
817 * @param cls original HELLO message
818 * @param address the address
819 * @param expiration expiration time
820 * @return #GNUNET_OK (keep the address), could return
821 * #GNUNET_NO (delete address, but this is ignored);
822 * #GNUNET_SYSERR would abort iteration (but we always iterate all)
825 add_valid_address (void *cls,
826 const struct GNUNET_HELLO_Address *address,
827 struct GNUNET_TIME_Absolute expiration)
829 const struct GNUNET_HELLO_Message *hello = cls;
830 struct ValidationEntry *ve;
831 struct GNUNET_PeerIdentity pid;
832 struct GNUNET_ATS_Properties prop;
833 struct GNUNET_TRANSPORT_PluginFunctions *papi;
835 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
836 return GNUNET_OK; /* expired */
837 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
840 return GNUNET_OK; /* invalid HELLO !? */
842 if (NULL == (papi = GST_plugins_find (address->transport_name)))
844 /* might have been valid in the past, but we don't have that
845 plugin loaded right now */
849 papi->address_to_string (papi->cls,
851 address->address_length))
853 /* Why do we try to add an ill-formed address? */
855 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
856 "Address with %u bytes for plugin %s and peer %s is malformed\n",
857 (unsigned int) address->address_length,
858 address->transport_name,
863 ve = find_validation_entry (address);
864 ve->network = papi->get_network_for_address (papi->cls,
866 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
867 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
869 if (NULL == ve->revalidation_task)
871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
872 "Starting revalidations for valid address `%s'\n",
873 GST_plugins_a2s (ve->address));
874 ve->next_validation = GNUNET_TIME_absolute_get();
875 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
877 validation_entry_changed (ve,
878 GNUNET_TRANSPORT_VS_UPDATE);
879 memset (&prop, 0, sizeof (prop));
880 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
881 prop.scope = ve->network;
882 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
883 if (GNUNET_YES != ve->known_to_ats)
885 ve->known_to_ats = GNUNET_YES;
886 GST_ats_add_address (address, &prop);
887 GNUNET_assert (GNUNET_YES ==
888 GST_ats_is_known_no_session (ve->address));
895 * Function called for any HELLO known to PEERINFO.
897 * @param cls unused (NULL)
898 * @param peer id of the peer, NULL for last call (during iteration,
899 * as we are monitoring, this should never happen)
900 * @param hello hello message for the peer (can be NULL)
901 * @param err_msg error message
904 process_peerinfo_hello (void *cls,
905 const struct GNUNET_PeerIdentity *peer,
906 const struct GNUNET_HELLO_Message *hello,
909 GNUNET_assert (NULL != peer);
912 if (0 == memcmp (&GST_my_identity,
914 sizeof (struct GNUNET_PeerIdentity)))
916 /* Peerinfo returned own identity, skip validation */
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Handling HELLO for peer `%s'\n",
922 GNUNET_assert (NULL ==
923 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
930 * Start the validation subsystem.
932 * @param max_fds maximum number of fds to use
935 GST_validation_start (unsigned int max_fds)
938 * Initialization for validation throttling
940 * We have a maximum number max_fds of connections we can use for validation
941 * We monitor the number of validations in parallel and start to throttle it
942 * when doing to many validations in parallel:
943 * if (running validations < (max_fds / 2))
944 * - "fast start": run validation immediately
945 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
946 * (300 sec / ~150 == ~2 sec.) between two validations
949 validation_next = GNUNET_TIME_absolute_get();
950 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
951 validations_fast_start_threshold = (max_fds / 2);
952 validations_running = 0;
953 GNUNET_STATISTICS_set (GST_stats,
954 gettext_noop ("# validations running"),
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Validation uses a fast start threshold of %u connections and a delay of %s\n",
959 validations_fast_start_threshold,
960 GNUNET_STRINGS_relative_time_to_string (validation_delay,
962 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
964 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
965 &process_peerinfo_hello, NULL);
970 * Stop the validation subsystem.
973 GST_validation_stop ()
975 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
976 &cleanup_validation_entry,
978 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
979 validation_map = NULL;
980 GNUNET_PEERINFO_notify_cancel (pnc);
985 * Send the given PONG to the given address.
987 * @param cls the PONG message
988 * @param valid_until is ZERO if we never validated the address,
989 * otherwise a time up to when we consider it (or was) valid
990 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
991 * is ZERO if the address is considered valid (no validation needed)
992 * otherwise a time in the future if we're currently denying re-validation
993 * @param address target address
996 multicast_pong (void *cls,
997 struct GNUNET_TIME_Absolute valid_until,
998 struct GNUNET_TIME_Absolute validation_block,
999 const struct GNUNET_HELLO_Address *address)
1001 struct TransportPongMessage *pong = cls;
1002 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1003 struct GNUNET_ATS_Session *session;
1005 papi = GST_plugins_find (address->transport_name);
1008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1009 "Plugin %s not supported, cannot send PONG\n",
1010 address->transport_name);
1013 GNUNET_assert (NULL != papi->send);
1014 GNUNET_assert (NULL != papi->get_session);
1015 session = papi->get_session(papi->cls, address);
1016 if (NULL == session)
1021 GST_ats_new_session (address, session);
1022 papi->send (papi->cls, session,
1023 (const char *) pong,
1024 ntohs (pong->header.size),
1026 ACCEPTABLE_PING_DELAY,
1028 GST_neighbours_notify_data_sent (address,
1035 * We've received a PING. If appropriate, generate a PONG.
1037 * @param sender peer sending the PING
1038 * @param hdr the PING
1039 * @param sender_address the sender address as we got it
1040 * @param session session we got the PING from
1041 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1044 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1045 const struct GNUNET_MessageHeader *hdr,
1046 const struct GNUNET_HELLO_Address *sender_address,
1047 struct GNUNET_ATS_Session *session)
1049 const struct TransportPingMessage *ping;
1050 struct TransportPongMessage *pong;
1051 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1052 struct GNUNET_CRYPTO_EddsaSignature *sig_cache;
1053 struct GNUNET_TIME_Absolute *sig_cache_exp;
1055 const char *addrend;
1061 struct GNUNET_HELLO_Address address;
1064 memcmp (&GST_my_identity,
1066 sizeof (struct GNUNET_PeerIdentity)))
1067 return GNUNET_OK; /* our own, ignore! */
1068 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
1070 GNUNET_break_op (0);
1071 return GNUNET_SYSERR;
1073 ping = (const struct TransportPingMessage *) hdr;
1075 memcmp (&ping->target, &GST_my_identity,
1076 sizeof (struct GNUNET_PeerIdentity)))
1078 GNUNET_STATISTICS_update (GST_stats,
1080 ("# PING message for different peer received"), 1,
1082 return GNUNET_SYSERR;
1084 GNUNET_STATISTICS_update (GST_stats,
1085 gettext_noop ("# PING messages received"), 1,
1087 addr = (const char *) &ping[1];
1088 len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
1089 /* peer wants to confirm that this is one of our addresses, this is what is
1090 * used for address validation */
1093 sig_cache_exp = NULL;
1095 if (len_address > 0)
1097 addrend = memchr (addr, '\0', len_address);
1098 if (NULL == addrend)
1100 GNUNET_break_op (0);
1101 return GNUNET_SYSERR;
1104 len_plugin = strlen (addr) + 1;
1105 len_address -= len_plugin;
1106 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1107 address.address = addrend;
1108 address.address_length = len_address;
1109 address.transport_name = addr;
1110 address.peer = GST_my_identity;
1112 if (NULL == address.transport_name)
1117 if (0 != strstr (address.transport_name, "_client"))
1119 plugin_name = GNUNET_strdup (address.transport_name);
1120 pos = strstr (plugin_name, "_client");
1121 GNUNET_assert (NULL != pos);
1122 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1125 plugin_name = GNUNET_strdup (address.transport_name);
1127 if (NULL == (papi = GST_plugins_find (plugin_name)))
1129 /* we don't have the plugin for this address */
1130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1131 _("Plugin `%s' not available, cannot confirm having this address\n"),
1133 GNUNET_free (plugin_name);
1134 return GNUNET_SYSERR;
1136 GNUNET_free (plugin_name);
1138 papi->check_address (papi->cls,
1142 GNUNET_STATISTICS_update (GST_stats,
1144 ("# failed address checks during validation"), 1,
1146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1147 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1148 GST_plugins_a2s (&address));
1149 return GNUNET_SYSERR;
1153 GNUNET_STATISTICS_update (GST_stats,
1155 ("# successful address checks during validation"), 1,
1157 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1158 "Address `%s' is one of my addresses, confirming PING\n",
1159 GST_plugins_a2s (&address));
1163 GST_hello_test_address (&address,
1167 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1168 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1169 GNUNET_i2s (sender),
1170 GST_plugins_a2s (&address));
1171 return GNUNET_SYSERR;
1176 addrend = NULL; /* make gcc happy */
1178 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1179 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1181 sig_cache = &no_address_signature;
1182 sig_cache_exp = &no_address_signature_expiration;
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "I am `%s', sending PONG to peer `%s'\n",
1187 GNUNET_i2s_full (&GST_my_identity),
1188 GNUNET_i2s (sender));
1190 /* message with structure:
1191 * [TransportPongMessage][Transport name][Address] */
1193 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1195 htons (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1196 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1197 pong->purpose.size =
1198 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1199 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1200 len_address + len_plugin);
1201 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1202 memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
1203 pong->addrlen = htonl (len_address + len_plugin);
1204 memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */
1205 if (len_address > 0)
1207 GNUNET_assert (NULL != addrend);
1208 memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address);
1210 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1211 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1213 /* create / update cached sig */
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1215 "Creating PONG signature to indicate ownership.\n");
1216 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
1217 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1219 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1223 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender));
1228 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1230 pong->signature = *sig_cache;
1232 GNUNET_assert (NULL != sender_address);
1234 /* first see if the session we got this PING from can be used to transmit
1235 * a response reliably */
1242 GNUNET_assert (NULL != papi->send);
1243 GNUNET_assert (NULL != papi->get_session);
1244 if (NULL == session)
1246 session = papi->get_session (papi->cls, sender_address);
1248 if (NULL == session)
1255 ret = papi->send (papi->cls, session,
1256 (const char *) pong,
1257 ntohs (pong->header.size),
1258 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1261 GST_neighbours_notify_data_sent (sender_address,
1268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1269 "Transmitted PONG to `%s' via reliable mechanism\n",
1270 GNUNET_i2s (sender));
1272 GNUNET_STATISTICS_update (GST_stats,
1274 ("# PONGs unicast via reliable transport"), 1,
1280 /* no reliable method found, try transmission via all known addresses */
1281 GNUNET_STATISTICS_update (GST_stats,
1283 ("# PONGs multicast to all available addresses"), 1,
1285 GST_validation_get_addresses (sender,
1286 &multicast_pong, pong);
1293 * Validate an individual address.
1295 * @param address address we should try to validate
1298 GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1300 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1301 struct ValidationEntry *ve;
1303 papi = GST_plugins_find (address->transport_name);
1306 /* This plugin is currently unvailable ... ignore */
1309 ve = find_validation_entry (address);
1310 if (NULL == ve->revalidation_task)
1312 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1313 "Validation process started for fresh address `%s' of %s\n",
1314 GST_plugins_a2s (ve->address),
1315 GNUNET_i2s (&ve->address->peer));
1316 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1322 * Iterator callback to go over all addresses and try to validate them
1323 * (unless blocked or already validated).
1326 * @param address the address
1327 * @param expiration expiration time
1328 * @return #GNUNET_OK (keep the address)
1331 validate_address_iterator (void *cls,
1332 const struct GNUNET_HELLO_Address *address,
1333 struct GNUNET_TIME_Absolute expiration)
1335 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1338 "Skipping expired address from HELLO\n");
1339 return GNUNET_OK; /* expired */
1341 GST_validation_handle_address (address);
1347 * Add the validated peer address to the HELLO.
1349 * @param cls the `struct ValidationEntry *` with the validated address
1350 * @param max space in @a buf
1351 * @param buf where to add the address
1352 * @return number of bytes written, #GNUNET_SYSERR to signal the
1353 * end of the iteration.
1356 add_valid_peer_address (void *cls,
1360 struct ValidationEntry *ve = cls;
1362 if (GNUNET_YES == ve->copied)
1363 return GNUNET_SYSERR; /* Done */
1364 ve->copied = GNUNET_YES;
1365 return GNUNET_HELLO_add_address (ve->address,
1373 * We've received a PONG. Check if it matches a pending PING and
1374 * mark the respective address as confirmed.
1376 * @param sender peer sending the PONG
1377 * @param hdr the PONG
1378 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1381 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1382 const struct GNUNET_MessageHeader *hdr)
1384 const struct TransportPongMessage *pong;
1385 struct ValidationEntry *ve;
1391 struct GNUNET_HELLO_Message *hello;
1392 struct GNUNET_HELLO_Address address;
1397 memcmp (&GST_my_identity,
1399 sizeof (struct GNUNET_PeerIdentity)))
1400 return GNUNET_OK; /* our own, ignore! */
1402 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1404 GNUNET_break_op (0);
1405 return GNUNET_SYSERR;
1407 GNUNET_STATISTICS_update (GST_stats,
1408 gettext_noop ("# PONG messages received"), 1,
1411 /* message with structure:
1412 * [TransportPongMessage][Transport name][Address] */
1414 pong = (const struct TransportPongMessage *) hdr;
1415 tname = (const char *) &pong[1];
1416 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1417 addr = memchr (tname, '\0', size);
1420 GNUNET_break_op (0);
1421 return GNUNET_SYSERR;
1424 slen = strlen (tname) + 1;
1425 addrlen = size - slen;
1427 if (NULL == GST_plugins_find (tname))
1429 /* we got the PONG, but the transport plugin specified in it
1430 is not supported by this peer, so this cannot be a good
1432 GNUNET_break_op (0);
1436 address.peer = *sender;
1437 address.address = addr;
1438 address.address_length = addrlen;
1439 address.transport_name = tname;
1440 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1441 ve = find_validation_entry (&address);
1442 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1444 GNUNET_STATISTICS_update (GST_stats,
1446 ("# PONGs dropped, no matching pending validation"),
1450 /* now check that PONG is well-formed */
1451 if (0 != memcmp (&ve->address->peer,
1453 sizeof (struct GNUNET_PeerIdentity)))
1455 GNUNET_break_op (0);
1456 return GNUNET_SYSERR;
1459 GNUNET_TIME_absolute_get_remaining
1460 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us)
1462 GNUNET_STATISTICS_update (GST_stats,
1464 ("# PONGs dropped, signature expired"), 1,
1466 return GNUNET_SYSERR;
1469 sig_res = GNUNET_SYSERR;
1470 do_verify = GNUNET_YES;
1471 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
1473 /* We have a cached and valid signature for this peer,
1474 * try to compare instead of verify */
1475 if (0 == memcmp (&ve->pong_sig_cache,
1477 sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1479 /* signatures are identical, we can skip verification */
1480 sig_res = GNUNET_OK;
1481 do_verify = GNUNET_NO;
1485 sig_res = GNUNET_SYSERR;
1486 /* signatures do not match, we have to verify */
1490 if (GNUNET_YES == do_verify)
1492 /* Do expensive verification */
1493 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1496 &ve->address->peer.public_key);
1497 if (sig_res == GNUNET_SYSERR)
1499 GNUNET_break_op (0);
1500 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1501 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1503 GST_plugins_a2s (ve->address),
1504 GNUNET_i2s (sender));
1507 if (sig_res == GNUNET_SYSERR)
1509 GNUNET_break_op (0);
1510 return GNUNET_SYSERR;
1513 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1514 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1515 GNUNET_i2s (sender),
1517 GST_plugins_a2s (ve->address));
1518 GNUNET_STATISTICS_update (GST_stats,
1519 gettext_noop ("# validations succeeded"),
1522 /* validity achieved, remember it! */
1523 ve->expecting_pong = GNUNET_NO;
1524 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1525 ve->pong_sig_cache = pong->signature;
1526 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1527 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1529 if (GNUNET_YES == ve->known_to_ats)
1531 GNUNET_assert (GNUNET_YES ==
1532 GST_ats_is_known_no_session (ve->address));
1533 GST_ats_update_delay (ve->address,
1534 GNUNET_TIME_relative_divide (ve->latency, 2));
1538 struct GNUNET_ATS_Properties prop;
1540 memset (&prop, 0, sizeof (prop));
1541 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
1542 prop.scope = ve->network;
1543 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
1544 GNUNET_assert (GNUNET_NO ==
1545 GST_ats_is_known_no_session (ve->address));
1546 ve->known_to_ats = GNUNET_YES;
1547 GST_ats_add_address (ve->address, &prop);
1548 GNUNET_assert (GNUNET_YES ==
1549 GST_ats_is_known_no_session (ve->address));
1552 if (validations_running > 0)
1554 validations_running--;
1555 GNUNET_STATISTICS_set (GST_stats,
1556 gettext_noop ("# validations running"),
1557 validations_running,
1559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1560 "Validation finished, %u validation processes running\n",
1561 validations_running);
1568 /* Notify about new validity */
1569 validation_entry_changed (ve,
1570 GNUNET_TRANSPORT_VS_UPDATE);
1572 /* build HELLO to store in PEERINFO */
1573 ve->copied = GNUNET_NO;
1574 hello = GNUNET_HELLO_create (&ve->address->peer.public_key,
1575 &add_valid_peer_address,
1578 GNUNET_PEERINFO_add_peer (GST_peerinfo,
1582 GNUNET_free (hello);
1588 * We've received a HELLO, check which addresses are new and trigger
1591 * @param hello the HELLO we received
1592 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1595 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1597 const struct GNUNET_HELLO_Message *hm =
1598 (const struct GNUNET_HELLO_Message *) hello;
1599 struct GNUNET_PeerIdentity pid;
1602 friend = GNUNET_HELLO_is_friend_only (hm);
1603 if ( ( (GNUNET_YES != friend) &&
1604 (GNUNET_NO != friend) ) ||
1605 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) )
1607 /* malformed HELLO */
1608 GNUNET_break_op (0);
1609 return GNUNET_SYSERR;
1612 memcmp (&GST_my_identity,
1614 sizeof (struct GNUNET_PeerIdentity)))
1616 /* got our own HELLO, how boring */
1619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1620 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n",
1622 ntohs (hello->size));
1623 GNUNET_assert (NULL ==
1624 GNUNET_HELLO_iterate_addresses (hm,
1626 &validate_address_iterator,
1633 * Closure for #iterate_addresses().
1635 struct IteratorContext
1638 * Function to call on each address.
1640 GST_ValidationAddressCallback cb;
1643 * Closure for @e cb.
1651 * Call the callback in the closure for each validation entry.
1653 * @param cls the `struct IteratorContext`
1654 * @param key the peer's identity
1655 * @param value the `struct ValidationEntry`
1656 * @return #GNUNET_OK (continue to iterate)
1659 iterate_addresses (void *cls,
1660 const struct GNUNET_PeerIdentity *key,
1663 struct IteratorContext *ic = cls;
1664 struct ValidationEntry *ve = value;
1668 ve->revalidation_block,
1675 * Call the given function for each address for the given target.
1676 * Can either give a snapshot (synchronous API) or be continuous.
1678 * @param target peer information is requested for
1679 * @param cb function to call; will not be called after this function returns
1680 * @param cb_cls closure for @a cb
1683 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1684 GST_ValidationAddressCallback cb,
1687 struct IteratorContext ic;
1691 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1693 &iterate_addresses, &ic);
1698 * Update if we are using an address for a connection actively right now.
1699 * Based on this, the validation module will measure latency for the
1700 * address more or less often.
1702 * @param address the address that we are now using (or not)
1703 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1704 * #GNUNET_NO if we are no longer using the address for a connection
1707 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1710 struct ValidationEntry *ve;
1712 if (GNUNET_HELLO_address_check_option (address,
1713 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1714 return; /* ignore inbound for validation */
1715 if (NULL == GST_plugins_find (address->transport_name))
1717 /* How can we use an address for which we don't have the plugin? */
1721 ve = find_validation_entry (address);
1727 if (in_use == ve->in_use)
1729 ve->in_use = in_use;
1730 if (GNUNET_YES == in_use)
1732 /* from now on, higher frequeny, so reschedule now */
1733 if (NULL != ve->revalidation_task)
1734 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1735 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address,
1742 * Closure for the validation_entries_iterate function.
1744 struct ValidationIteratorContext
1747 * Function to call on each validation entry
1749 GST_ValidationChangedCallback cb;
1752 * Closure for @e cb.
1759 * Function called on each entry in the validation map.
1760 * Passes the information from the validation entry to
1761 * the callback given in the closure.
1763 * @param cls the `struct ValidationIteratorContext`
1764 * @param key peer this is about
1765 * @param value the `struct ValidationEntry`
1766 * @return #GNUNET_OK (continue to iterate)
1769 validation_entries_iterate (void *cls,
1770 const struct GNUNET_PeerIdentity *key,
1773 struct ValidationIteratorContext *ic = cls;
1774 struct ValidationEntry *ve = value;
1776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1777 "Notifying about validation entry for peer `%s' address `%s' \n",
1778 GNUNET_i2s (&ve->address->peer),
1779 GST_plugins_a2s (ve->address));
1784 ve->next_validation,
1791 * Iterate over all iteration entries
1793 * @param cb function to call
1794 * @param cb_cls closure for @a cb
1797 GST_validation_iterate (GST_ValidationChangedCallback cb,
1800 struct ValidationIteratorContext ic;
1802 if (NULL == validation_map)
1803 return; /* can happen during shutdown */
1806 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1807 &validation_entries_iterate,
1811 /* end of file gnunet-service-transport_validation.c */