2 This file is part of GNUnet.
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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, GNUNET_TRANSPORT_VS_REMOVE);
420 GST_blacklist_test_cancel (ve->bc);
423 GNUNET_break (GNUNET_OK ==
424 GNUNET_CONTAINER_multipeermap_remove (validation_map,
427 publish_ve_stat_update ();
428 if (GNUNET_YES == ve->known_to_ats)
430 GST_ats_expire_address (ve->address);
431 ve->known_to_ats = GNUNET_NO;
433 GNUNET_HELLO_address_free (ve->address);
434 if (NULL != ve->timeout_task)
436 GNUNET_SCHEDULER_cancel (ve->timeout_task);
437 ve->timeout_task = NULL;
439 if (NULL != ve->revalidation_task)
441 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
442 ve->revalidation_task = NULL;
444 if ( (GNUNET_YES == ve->expecting_pong) &&
445 (validations_running > 0) )
447 validations_running--;
448 GNUNET_STATISTICS_set (GST_stats,
449 gettext_noop ("# validations running"),
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Validation finished, %u validation processes running\n",
454 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 max = GNUNET_TIME_absolute_max (ve->valid_until,
478 ve->revalidation_block);
479 left = GNUNET_TIME_absolute_get_remaining (max);
480 if (left.rel_value_us > 0)
482 /* should wait a bit longer */
484 GNUNET_SCHEDULER_add_delayed (left, &timeout_hello_validation, ve);
487 GNUNET_STATISTICS_update (GST_stats,
488 gettext_noop ("# address records discarded"), 1,
490 cleanup_validation_entry (NULL, &ve->address->peer, ve);
495 * Function called with the result from blacklisting.
496 * Send a PING to the other peer if a communication is allowed.
498 * @param cls our `struct ValidationEntry`
499 * @param pid identity of the other peer
500 * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not
503 transmit_ping_if_allowed (void *cls,
504 const struct GNUNET_PeerIdentity *pid,
507 struct ValidationEntry *ve = cls;
508 struct TransportPingMessage ping;
509 struct GNUNET_TRANSPORT_PluginFunctions *papi;
510 struct GNUNET_TIME_Absolute next;
511 const struct GNUNET_MessageHeader *hello;
512 enum GNUNET_ATS_Network_Type network;
519 if (GNUNET_NO == result)
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Blacklist denies to send PING to `%s' `%s' `%s'\n",
524 GST_plugins_a2s (ve->address),
525 ve->address->transport_name);
526 cleanup_validation_entry (NULL, pid, ve);
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
531 "Transmitting plain PING to `%s' `%s' `%s'\n",
533 GST_plugins_a2s (ve->address),
534 ve->address->transport_name);
536 slen = strlen (ve->address->transport_name) + 1;
537 hello = GST_hello_get ();
538 hsize = ntohs (hello->size);
540 sizeof (struct TransportPingMessage) + ve->address->address_length +
544 htons (sizeof (struct TransportPingMessage) +
545 ve->address->address_length + slen);
546 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
547 ping.challenge = htonl (ve->challenge);
550 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
555 sizeof (struct TransportPingMessage) + ve->address->address_length +
559 char message_buf[tsize];
561 /* build message with structure:
562 * [HELLO][TransportPingMessage][Transport name][Address] */
563 memcpy (message_buf, hello, hsize);
564 memcpy (&message_buf[hsize],
566 sizeof (struct TransportPingMessage));
567 memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
568 ve->address->transport_name,
570 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
571 ve->address->address,
572 ve->address->address_length);
573 papi = GST_plugins_find (ve->address->transport_name);
577 GNUNET_STATISTICS_update (GST_stats,
578 gettext_noop ("# validations not attempted (no plugin)"),
584 GNUNET_assert (NULL != papi->send);
585 struct Session *session = papi->get_session (papi->cls,
590 ret = papi->send (papi->cls, session,
593 ACCEPTABLE_PING_DELAY,
595 network = papi->get_network (papi->cls, session);
596 if (GNUNET_ATS_NET_UNSPECIFIED == network)
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
599 "Could not obtain a valid network for `%s' `%s'\n",
601 GST_plugins_a2s (ve->address));
604 GST_neighbours_notify_data_sent (ve->address, session, tsize);
608 /* Could not get a valid session */
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
610 "Could not get a valid session for `%s' `%s'\n",
612 GST_plugins_a2s (ve->address));
619 next = GNUNET_TIME_relative_to_absolute (validation_delay);
620 validation_next = GNUNET_TIME_absolute_max (next,
622 ve->send_time = GNUNET_TIME_absolute_get ();
623 GNUNET_STATISTICS_update (GST_stats,
624 gettext_noop ("# PINGs for address validation sent"),
627 ve->network = network;
628 ve->expecting_pong = GNUNET_YES;
629 validations_running++;
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Validation started, %u validation processes running\n",
632 validations_running);
633 GNUNET_STATISTICS_set (GST_stats,
634 gettext_noop ("# validations running"),
637 /* Notify about PING sent */
638 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
644 * Do address validation again to keep address valid.
646 * @param cls the `struct ValidationEntry`
647 * @param tc scheduler context (unused)
650 revalidate_address (void *cls,
651 const struct GNUNET_SCHEDULER_TaskContext *tc)
653 struct ValidationEntry *ve = cls;
654 struct GNUNET_TIME_Relative canonical_delay;
655 struct GNUNET_TIME_Relative delay;
656 struct GNUNET_TIME_Relative blocked_for;
657 struct GST_BlacklistCheck *bc;
660 ve->revalidation_task = NULL;
661 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
662 /* Considering current connectivity situation, what is the maximum
663 block period permitted? */
664 if (GNUNET_YES == ve->in_use)
665 canonical_delay = CONNECTED_PING_FREQUENCY;
666 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0)
667 canonical_delay = VALIDATED_PING_FREQUENCY;
669 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
670 /* Use delay that is MIN of original delay and possibly adjusted
671 new maximum delay (which may be lower); the real delay
672 is originally randomized between "canonical_delay" and "2 * canonical_delay",
673 so continue to permit that window for the operation. */
674 delay = GNUNET_TIME_relative_min (delay,
675 GNUNET_TIME_relative_multiply (canonical_delay,
677 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
678 if (delay.rel_value_us > 0)
680 /* should wait a bit longer */
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
682 "Waiting for %s longer before validating address `%s'\n",
683 GNUNET_STRINGS_relative_time_to_string (delay,
685 GST_plugins_a2s (ve->address));
686 ve->revalidation_task =
687 GNUNET_SCHEDULER_add_delayed (delay,
688 &revalidate_address, ve);
689 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
692 /* check if globally we have too many active validations at a
693 too high rate, if so, delay ours */
694 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next);
695 if ( (validations_running > validations_fast_start_threshold) &&
696 (blocked_for.rel_value_us > 0) )
698 /* Validations are blocked, have to wait for blocked_for time */
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Validations blocked for another %s, delaying validating address `%s'\n",
701 GNUNET_STRINGS_relative_time_to_string (blocked_for,
703 GST_plugins_a2s (ve->address));
704 ve->revalidation_task =
705 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
706 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
710 /* We are good to go; remember to not go again for `canonical_delay` time;
711 add up to `canonical_delay` to randomize start time */
712 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
713 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
715 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
716 canonical_delay.rel_value_us);
718 delay = GNUNET_TIME_relative_add (canonical_delay,
719 GNUNET_TIME_relative_multiply
720 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay));
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Validating now, next scheduled for %s, now validating address `%s'\n",
724 GNUNET_STRINGS_relative_time_to_string (blocked_for,
726 GST_plugins_a2s (ve->address));
727 ve->revalidation_task =
728 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
729 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
731 /* start PINGing by checking blacklist */
732 GNUNET_STATISTICS_update (GST_stats,
733 gettext_noop ("# address revalidations started"), 1,
735 bc = GST_blacklist_test_allowed (&ve->address->peer,
736 ve->address->transport_name,
737 &transmit_ping_if_allowed, ve);
739 ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already
745 * Find a ValidationEntry entry for the given neighbour that matches
746 * the given address and transport. If none exists, create one (but
747 * without starting any validation).
749 * @param address address to find
750 * @return validation entry matching the given specifications, NULL
751 * if we don't have an existing entry and no public key was given
753 static struct ValidationEntry *
754 find_validation_entry (const struct GNUNET_HELLO_Address *address)
756 struct ValidationEntryMatchContext vemc;
757 struct ValidationEntry *ve;
760 vemc.address = address;
761 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
763 &validation_entry_match, &vemc);
764 if (NULL != (ve = vemc.ve))
766 ve = GNUNET_new (struct ValidationEntry);
767 ve->in_use = GNUNET_SYSERR; /* not defined */
768 ve->address = GNUNET_HELLO_address_copy (address);
769 ve->pong_sig_valid_until = GNUNET_TIME_absolute_get_zero_();
770 memset (&ve->pong_sig_cache, '\0', sizeof (struct GNUNET_CRYPTO_EddsaSignature));
771 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
773 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
775 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
776 &timeout_hello_validation, ve);
777 GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer,
779 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
780 publish_ve_stat_update ();
781 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW);
787 * Iterator which adds the given address to the set of validated
790 * @param cls original HELLO message
791 * @param address the address
792 * @param expiration expiration time
793 * @return #GNUNET_OK (keep the address)
796 add_valid_address (void *cls,
797 const struct GNUNET_HELLO_Address *address,
798 struct GNUNET_TIME_Absolute expiration)
800 const struct GNUNET_HELLO_Message *hello = cls;
801 struct ValidationEntry *ve;
802 struct GNUNET_PeerIdentity pid;
803 struct GNUNET_ATS_Information ats;
805 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
806 return GNUNET_OK; /* expired */
807 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
810 return GNUNET_OK; /* invalid HELLO !? */
812 if (0 == memcmp (&GST_my_identity,
814 sizeof (struct GNUNET_PeerIdentity)))
816 /* Peerinfo returned own identity, skip validation */
819 if (NULL == GST_plugins_find (address->transport_name))
821 /* might have been valid in the past, but we don't have that
822 plugin loaded right now */
826 ve = find_validation_entry (address);
827 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
829 if (NULL == ve->revalidation_task)
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
832 "Starting revalidations for valid address `%s'\n",
833 GST_plugins_a2s (ve->address));
834 ve->next_validation = GNUNET_TIME_absolute_get();
835 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
837 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
839 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
840 ats.value = htonl (ve->network);
841 if (GNUNET_YES != ve->known_to_ats)
843 ve->known_to_ats = GNUNET_YES;
844 GST_ats_add_address (address, NULL, &ats, 1);
851 * Function called for any HELLO known to PEERINFO.
854 * @param peer id of the peer, NULL for last call
855 * @param hello hello message for the peer (can be NULL)
856 * @param err_msg error message
859 process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
860 const struct GNUNET_HELLO_Message *hello,
863 GNUNET_assert (NULL != peer);
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
867 "Handling HELLO for peer `%s'\n",
869 GNUNET_assert (NULL ==
870 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
877 * Start the validation subsystem.
879 * @param max_fds maximum number of fds to use
882 GST_validation_start (unsigned int max_fds)
885 * Initialization for validation throttling
887 * We have a maximum number max_fds of connections we can use for validation
888 * We monitor the number of validations in parallel and start to throttle it
889 * when doing to many validations in parallel:
890 * if (running validations < (max_fds / 2))
891 * - "fast start": run validation immediately
892 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
893 * (300 sec / ~150 == ~2 sec.) between two validations
896 validation_next = GNUNET_TIME_absolute_get();
897 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
898 validations_fast_start_threshold = (max_fds / 2);
899 validations_running = 0;
900 GNUNET_STATISTICS_set (GST_stats,
901 gettext_noop ("# validations running"),
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
905 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
906 validations_fast_start_threshold,
907 GNUNET_STRINGS_relative_time_to_string (validation_delay,
909 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
911 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
912 &process_peerinfo_hello, NULL);
917 * Stop the validation subsystem.
920 GST_validation_stop ()
922 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
923 &cleanup_validation_entry, NULL);
924 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
925 validation_map = NULL;
926 GNUNET_PEERINFO_notify_cancel (pnc);
931 * Send the given PONG to the given address.
933 * @param cls the PONG message
934 * @param valid_until is ZERO if we never validated the address,
935 * otherwise a time up to when we consider it (or was) valid
936 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
937 * is ZERO if the address is considered valid (no validation needed)
938 * otherwise a time in the future if we're currently denying re-validation
939 * @param address target address
942 multicast_pong (void *cls,
943 struct GNUNET_TIME_Absolute valid_until,
944 struct GNUNET_TIME_Absolute validation_block,
945 const struct GNUNET_HELLO_Address *address)
947 struct TransportPongMessage *pong = cls;
948 struct GNUNET_TRANSPORT_PluginFunctions *papi;
949 struct Session *session;
951 papi = GST_plugins_find (address->transport_name);
955 GNUNET_assert (NULL != papi->send);
956 GNUNET_assert (NULL != papi->get_session);
957 session = papi->get_session(papi->cls, address);
963 GST_ats_new_session (address, session);
964 papi->send (papi->cls, session,
966 ntohs (pong->header.size),
968 ACCEPTABLE_PING_DELAY,
970 GST_neighbours_notify_data_sent (address,
978 * We've received a PING. If appropriate, generate a PONG.
980 * @param sender peer sending the PING
981 * @param hdr the PING
982 * @param sender_address the sender address as we got it
983 * @param session session we got the PING from
984 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
987 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
988 const struct GNUNET_MessageHeader *hdr,
989 const struct GNUNET_HELLO_Address *sender_address,
990 struct Session *session)
992 const struct TransportPingMessage *ping;
993 struct TransportPongMessage *pong;
994 struct GNUNET_TRANSPORT_PluginFunctions *papi;
995 struct GNUNET_CRYPTO_EddsaSignature *sig_cache;
996 struct GNUNET_TIME_Absolute *sig_cache_exp;
1004 int buggy = GNUNET_NO;
1005 struct GNUNET_HELLO_Address address;
1007 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
1009 GNUNET_break_op (0);
1010 return GNUNET_SYSERR;
1012 ping = (const struct TransportPingMessage *) hdr;
1014 memcmp (&ping->target, &GST_my_identity,
1015 sizeof (struct GNUNET_PeerIdentity)))
1017 GNUNET_STATISTICS_update (GST_stats,
1019 ("# PING message for different peer received"), 1,
1021 return GNUNET_SYSERR;
1023 GNUNET_STATISTICS_update (GST_stats,
1024 gettext_noop ("# PING messages received"), 1,
1026 addr = (const char *) &ping[1];
1027 len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
1028 /* peer wants to confirm that this is one of our addresses, this is what is
1029 * used for address validation */
1032 sig_cache_exp = NULL;
1034 if (len_address > 0)
1036 addrend = memchr (addr, '\0', len_address);
1037 if (NULL == addrend)
1039 GNUNET_break_op (0);
1040 return GNUNET_SYSERR;
1043 len_plugin = strlen (addr) + 1;
1044 len_address -= len_plugin;
1045 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1046 address.address = addrend;
1047 address.address_length = len_address;
1048 address.transport_name = addr;
1049 address.peer = GST_my_identity;
1051 if (NULL == address.transport_name)
1056 if (0 != strstr (address.transport_name, "_client"))
1058 plugin_name = GNUNET_strdup (address.transport_name);
1059 pos = strstr (plugin_name, "_client");
1060 GNUNET_assert (NULL != pos);
1061 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1064 plugin_name = GNUNET_strdup (address.transport_name);
1066 if (NULL == (papi = GST_plugins_find (plugin_name)))
1068 /* we don't have the plugin for this address */
1069 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1070 _("Plugin `%s' not available, cannot confirm having this address\n"),
1072 GNUNET_free (plugin_name);
1073 return GNUNET_SYSERR;
1075 GNUNET_free (plugin_name);
1076 if (GNUNET_OK != papi->check_address (papi->cls, addrend, len_address))
1078 GNUNET_STATISTICS_update (GST_stats,
1080 ("# failed address checks during validation"), 1,
1082 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1083 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1084 GST_plugins_a2s (&address));
1085 return GNUNET_SYSERR;
1089 GNUNET_STATISTICS_update (GST_stats,
1091 ("# successful address checks during validation"), 1,
1093 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1094 "Address `%s' is one of my addresses, confirming PING\n",
1095 GST_plugins_a2s (&address));
1098 if (GNUNET_YES != GST_hello_test_address (&address, &sig_cache, &sig_cache_exp))
1100 if (GNUNET_NO == buggy)
1102 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1103 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1104 GNUNET_i2s (sender),
1105 GST_plugins_a2s (&address));
1106 return GNUNET_SYSERR;
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 _("Received a PING message with validation bug from `%s'\n"),
1112 GNUNET_i2s (sender));
1118 addrend = NULL; /* make gcc happy */
1120 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1121 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1123 sig_cache = &no_address_signature;
1124 sig_cache_exp = &no_address_signature_expiration;
1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1128 "I am `%s', sending PONG to peer `%s'\n",
1129 GNUNET_i2s_full (&GST_my_identity),
1130 GNUNET_i2s (sender));
1132 /* message with structure:
1133 * [TransportPongMessage][Transport name][Address] */
1135 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1137 htons (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1138 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1139 pong->purpose.size =
1140 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1141 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1142 len_address + len_plugin);
1143 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1144 memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
1145 pong->addrlen = htonl (len_address + len_plugin);
1146 memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */
1147 if (len_address > 0)
1149 GNUNET_assert (NULL != addrend);
1150 memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address);
1152 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1153 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1155 /* create / update cached sig */
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Creating PONG signature to indicate ownership.\n");
1158 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
1159 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1161 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1165 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender));
1170 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1172 pong->signature = *sig_cache;
1174 GNUNET_assert (sender_address != NULL);
1176 /* first see if the session we got this PING from can be used to transmit
1177 * a response reliably */
1184 GNUNET_assert (NULL != papi->send);
1185 GNUNET_assert (NULL != papi->get_session);
1186 if (NULL == session)
1188 session = papi->get_session (papi->cls, sender_address);
1190 if (NULL == session)
1197 ret = papi->send (papi->cls, session,
1198 (const char *) pong,
1199 ntohs (pong->header.size),
1200 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1203 GST_neighbours_notify_data_sent (sender_address,
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "Transmitted PONG to `%s' via reliable mechanism\n",
1212 GNUNET_i2s (sender));
1214 GNUNET_STATISTICS_update (GST_stats,
1216 ("# PONGs unicast via reliable transport"), 1,
1222 /* no reliable method found, try transmission via all known addresses */
1223 GNUNET_STATISTICS_update (GST_stats,
1225 ("# PONGs multicast to all available addresses"), 1,
1227 GST_validation_get_addresses (sender,
1228 &multicast_pong, pong);
1235 * Iterator callback to go over all addresses and try to validate them
1236 * (unless blocked or already validated).
1239 * @param address the address
1240 * @param expiration expiration time
1241 * @return #GNUNET_OK (keep the address)
1244 validate_address_iterator (void *cls,
1245 const struct GNUNET_HELLO_Address *address,
1246 struct GNUNET_TIME_Absolute expiration)
1248 struct GNUNET_TRANSPORT_PluginFunctions * papi;
1249 struct ValidationEntry *ve;
1251 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1254 "Skipping expired address from HELLO\n");
1255 return GNUNET_OK; /* expired */
1257 papi = GST_plugins_find (address->transport_name);
1260 /* This plugin is currently unvailable ... ignore */
1263 ve = find_validation_entry (address);
1264 if (NULL == ve->revalidation_task)
1266 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1267 "Validation process started for fresh address `%s'\n",
1268 GST_plugins_a2s (ve->address));
1269 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1276 * Add the validated peer address to the HELLO.
1278 * @param cls the `struct ValidationEntry *` with the validated address
1279 * @param max space in @a buf
1280 * @param buf where to add the address
1281 * @return number of bytes written, #GNUNET_SYSERR to signal the
1282 * end of the iteration.
1285 add_valid_peer_address (void *cls,
1289 struct ValidationEntry *ve = cls;
1291 if (GNUNET_YES == ve->copied)
1292 return GNUNET_SYSERR; /* Done */
1293 ve->copied = GNUNET_YES;
1294 return GNUNET_HELLO_add_address (ve->address, ve->valid_until, buf, max);
1299 * We've received a PONG. Check if it matches a pending PING and
1300 * mark the respective address as confirmed.
1302 * @param sender peer sending the PONG
1303 * @param hdr the PONG
1304 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1307 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1308 const struct GNUNET_MessageHeader *hdr)
1310 const struct TransportPongMessage *pong;
1311 struct ValidationEntry *ve;
1317 struct GNUNET_HELLO_Message *hello;
1318 struct GNUNET_HELLO_Address address;
1322 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1324 GNUNET_break_op (0);
1325 return GNUNET_SYSERR;
1327 GNUNET_STATISTICS_update (GST_stats,
1328 gettext_noop ("# PONG messages received"), 1,
1331 /* message with structure:
1332 * [TransportPongMessage][Transport name][Address] */
1334 pong = (const struct TransportPongMessage *) hdr;
1335 tname = (const char *) &pong[1];
1336 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1337 addr = memchr (tname, '\0', size);
1340 GNUNET_break_op (0);
1341 return GNUNET_SYSERR;
1344 slen = strlen (tname) + 1;
1345 addrlen = size - slen;
1346 address.peer = *sender;
1347 address.address = addr;
1348 address.address_length = addrlen;
1349 address.transport_name = tname;
1350 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1351 ve = find_validation_entry (&address);
1352 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1354 GNUNET_STATISTICS_update (GST_stats,
1356 ("# PONGs dropped, no matching pending validation"),
1360 /* now check that PONG is well-formed */
1361 if (0 != memcmp (&ve->address->peer,
1363 sizeof (struct GNUNET_PeerIdentity)))
1365 GNUNET_break_op (0);
1366 return GNUNET_SYSERR;
1369 GNUNET_TIME_absolute_get_remaining
1370 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us)
1372 GNUNET_STATISTICS_update (GST_stats,
1374 ("# PONGs dropped, signature expired"), 1,
1376 return GNUNET_SYSERR;
1379 sig_res = GNUNET_SYSERR;
1380 do_verify = GNUNET_YES;
1381 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
1383 /* We have a cached and valid signature for this peer,
1384 * try to compare instead of verify */
1385 if (0 == memcmp (&ve->pong_sig_cache, &pong->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1387 /* signatures are identical, we can skip verification */
1388 sig_res = GNUNET_OK;
1389 do_verify = GNUNET_NO;
1393 sig_res = GNUNET_SYSERR;
1394 /* signatures do not match, we have to verify */
1398 if (GNUNET_YES == do_verify)
1400 /* Do expensive verification */
1401 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1402 &pong->purpose, &pong->signature,
1403 &ve->address->peer.public_key);
1404 if (sig_res == GNUNET_SYSERR)
1406 GNUNET_break_op (0);
1407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1408 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1410 GST_plugins_a2s (ve->address),
1411 GNUNET_i2s (sender));
1414 if (sig_res == GNUNET_SYSERR)
1416 GNUNET_break_op (0);
1417 return GNUNET_SYSERR;
1420 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1421 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1422 GNUNET_i2s (sender),
1424 GST_plugins_a2s (ve->address));
1425 GNUNET_STATISTICS_update (GST_stats,
1426 gettext_noop ("# validations succeeded"),
1429 /* validity achieved, remember it! */
1430 ve->expecting_pong = GNUNET_NO;
1431 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1432 ve->pong_sig_cache = pong->signature;
1433 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1434 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1436 struct GNUNET_ATS_Information ats[2];
1438 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
1439 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
1440 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1441 ats[1].value = htonl ((uint32_t) ve->network);
1442 if (GNUNET_YES == ve->known_to_ats)
1444 GST_ats_update_metrics (ve->address, NULL, ats, 2);
1448 ve->known_to_ats = GNUNET_YES;
1449 GST_ats_add_address (ve->address, NULL, ats, 2);
1452 if (validations_running > 0)
1454 validations_running--;
1455 GNUNET_STATISTICS_set (GST_stats,
1456 gettext_noop ("# validations running"),
1457 validations_running,
1459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1460 "Validation finished, %u validation processes running\n",
1461 validations_running);
1468 /* Notify about new validity */
1469 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
1471 /* build HELLO to store in PEERINFO */
1472 ve->copied = GNUNET_NO;
1473 hello = GNUNET_HELLO_create (&ve->address->peer.public_key,
1474 &add_valid_peer_address, ve,
1476 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1477 GNUNET_free (hello);
1483 * We've received a HELLO, check which addresses are new and trigger
1486 * @param hello the HELLO we received
1487 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1490 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1492 const struct GNUNET_HELLO_Message *hm =
1493 (const struct GNUNET_HELLO_Message *) hello;
1494 struct GNUNET_PeerIdentity pid;
1495 struct GNUNET_HELLO_Message *h;
1498 friend = GNUNET_HELLO_is_friend_only (hm);
1499 if ( ( (GNUNET_YES != friend) &&
1500 (GNUNET_NO != friend) ) ||
1501 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) )
1503 /* malformed HELLO */
1504 GNUNET_break_op (0);
1505 return GNUNET_SYSERR;
1508 memcmp (&GST_my_identity,
1510 sizeof (struct GNUNET_PeerIdentity)))
1512 /* Add peer identity without addresses to peerinfo service */
1513 h = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, friend);
1514 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1515 _("Validation received new %s message for peer `%s' with size %u\n"),
1518 ntohs (hello->size));
1519 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",
1526 GNUNET_assert (NULL ==
1527 GNUNET_HELLO_iterate_addresses (hm,
1529 &validate_address_iterator,
1536 * Closure for #iterate_addresses().
1538 struct IteratorContext
1541 * Function to call on each address.
1543 GST_ValidationAddressCallback cb;
1546 * Closure for @e cb.
1554 * Call the callback in the closure for each validation entry.
1556 * @param cls the `struct IteratorContext`
1557 * @param key the peer's identity
1558 * @param value the `struct ValidationEntry`
1559 * @return #GNUNET_OK (continue to iterate)
1562 iterate_addresses (void *cls,
1563 const struct GNUNET_PeerIdentity *key,
1566 struct IteratorContext *ic = cls;
1567 struct ValidationEntry *ve = value;
1571 ve->revalidation_block,
1578 * Call the given function for each address for the given target.
1579 * Can either give a snapshot (synchronous API) or be continuous.
1581 * @param target peer information is requested for
1582 * @param cb function to call; will not be called after this function returns
1583 * @param cb_cls closure for @a cb
1586 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1587 GST_ValidationAddressCallback cb,
1590 struct IteratorContext ic;
1594 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1596 &iterate_addresses, &ic);
1601 * Update if we are using an address for a connection actively right now.
1602 * Based on this, the validation module will measure latency for the
1603 * address more or less often.
1605 * @param address the address
1606 * @param session the session
1607 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1608 * #GNUNET_NO if we are no longer using the address for a connection
1611 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1612 struct Session *session,
1615 struct ValidationEntry *ve;
1617 if (GNUNET_HELLO_address_check_option (address,
1618 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1619 return; /* ignore inbound for validation */
1620 if (NULL != address)
1621 ve = find_validation_entry (address);
1623 ve = NULL; /* FIXME: lookup based on session... */
1626 /* this can happen for inbound connections (sender_address_len == 0); */
1629 if (ve->in_use == in_use)
1631 if (GNUNET_YES == in_use)
1633 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1634 "Error setting address in use for peer `%s' `%s' to USED\n",
1635 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1637 if (GNUNET_NO == in_use)
1639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1640 "Error setting address in use for peer `%s' `%s' to NOT_USED\n",
1641 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1645 GNUNET_break (ve->in_use != in_use); /* should be different... */
1646 ve->in_use = in_use;
1647 if (in_use == GNUNET_YES)
1649 /* from now on, higher frequeny, so reschedule now */
1650 if (NULL != ve->revalidation_task)
1651 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1652 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1658 * Query validation about the latest observed latency on a given
1661 * @param address the address
1662 * @param session session
1663 * @return observed latency of the address, FOREVER if the address was
1664 * never successfully validated
1666 struct GNUNET_TIME_Relative
1667 GST_validation_get_address_latency (const struct GNUNET_HELLO_Address *address,
1668 struct Session *session)
1670 struct ValidationEntry *ve;
1672 if (NULL == address)
1674 GNUNET_break (0); // FIXME: support having latency only with session...
1675 return GNUNET_TIME_UNIT_FOREVER_REL;
1677 ve = find_validation_entry (address);
1679 return GNUNET_TIME_UNIT_FOREVER_REL;
1684 * Closure for the validation_entries_iterate function.
1686 struct ValidationIteratorContext
1689 * Function to call on each validation entry
1691 GST_ValidationChangedCallback cb;
1694 * Closure for @e cb.
1701 * Function called on each entry in the validation map.
1702 * Passes the information from the validation entry to
1703 * the callback given in the closure.
1705 * @param cls the `struct ValidationIteratorContext`
1706 * @param key peer this is about
1707 * @param value the `struct ValidationEntry`
1708 * @return #GNUNET_OK (continue to iterate)
1711 validation_entries_iterate (void *cls,
1712 const struct GNUNET_PeerIdentity *key,
1715 struct ValidationIteratorContext *ic = cls;
1716 struct ValidationEntry *ve = value;
1718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1719 "Notifying about validation entry for peer `%s' address `%s' \n",
1720 GNUNET_i2s (&ve->address->peer),
1721 GST_plugins_a2s (ve->address));
1726 ve->next_validation,
1733 * Iterate over all iteration entries
1735 * @param cb function to call
1736 * @param cb_cls closure for cb
1739 GST_validation_iterate (GST_ValidationChangedCallback cb,
1742 struct ValidationIteratorContext ic;
1744 if (NULL == validation_map)
1745 return; /* can happen during shutdown */
1748 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1749 &validation_entries_iterate,
1753 /* end of file gnunet-service-transport_validation.c */