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 * Context of currently active requests to peerinfo
283 * for validation of HELLOs.
285 struct CheckHelloValidatedContext
289 * This is a doubly-linked list.
291 struct CheckHelloValidatedContext *next;
294 * This is a doubly-linked list.
296 struct CheckHelloValidatedContext *prev;
299 * Hello that we are validating.
301 const struct GNUNET_HELLO_Message *hello;
307 * Head of linked list of HELLOs awaiting validation.
309 static struct CheckHelloValidatedContext *chvc_head;
312 * Tail of linked list of HELLOs awaiting validation
314 static struct CheckHelloValidatedContext *chvc_tail;
317 * Map of PeerIdentities to 'struct ValidationEntry*'s (addresses
318 * of the given peer that we are currently validating, have validated
319 * or are blocked from re-validation for a while).
321 static struct GNUNET_CONTAINER_MultiPeerMap *validation_map;
324 * Context for peerinfo iteration.
326 static struct GNUNET_PEERINFO_NotifyContext *pnc;
329 * Minimum delay between to validations
331 static struct GNUNET_TIME_Relative validation_delay;
334 * Number of validations running; any PING that was not yet
335 * matched by a PONG and for which we have not yet hit the
336 * timeout is considered a running 'validation'.
338 static unsigned int validations_running;
341 * Validition fast start threshold
343 static unsigned int validations_fast_start_threshold;
346 * When is next validation allowed
348 static struct GNUNET_TIME_Absolute validation_next;
352 * Context for the validation entry match function.
354 struct ValidationEntryMatchContext
357 * Where to store the result?
359 struct ValidationEntry *ve;
362 * Address we're interested in.
364 const struct GNUNET_HELLO_Address *address;
370 * Iterate over validation entries until a matching one is found.
372 * @param cls the `struct ValidationEntryMatchContext *`
373 * @param key peer identity (unused)
374 * @param value a `struct ValidationEntry *` to match
375 * @return #GNUNET_YES if the entry does not match,
376 * #GNUNET_NO if the entry does match
379 validation_entry_match (void *cls,
380 const struct GNUNET_PeerIdentity *key,
383 struct ValidationEntryMatchContext *vemc = cls;
384 struct ValidationEntry *ve = value;
386 if (0 == GNUNET_HELLO_address_cmp (ve->address,
397 * A validation entry changed. Update the state and notify
400 * @param ve validation entry that changed
401 * @param state new state
404 validation_entry_changed (struct ValidationEntry *ve,
405 enum GNUNET_TRANSPORT_ValidationState state)
408 GST_clients_broadcast_validation_notification (&ve->address->peer,
418 * Iterate over validation entries and free them.
420 * @param cls (unused)
421 * @param key peer identity (unused)
422 * @param value a `struct ValidationEntry *` to clean up
423 * @return #GNUNET_YES (continue to iterate)
426 cleanup_validation_entry (void *cls,
427 const struct GNUNET_PeerIdentity *key,
430 struct ValidationEntry *ve = value;
432 ve->next_validation = GNUNET_TIME_UNIT_ZERO_ABS;
433 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
435 /* Notify about deleted entry */
436 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_REMOVE);
440 GST_blacklist_test_cancel (ve->bc);
443 GNUNET_break (GNUNET_OK ==
444 GNUNET_CONTAINER_multipeermap_remove (validation_map,
447 if (GNUNET_YES == ve->known_to_ats)
449 GST_ats_expire_address (ve->address);
450 ve->known_to_ats = GNUNET_NO;
452 GNUNET_HELLO_address_free (ve->address);
453 if (NULL != ve->timeout_task)
455 GNUNET_SCHEDULER_cancel (ve->timeout_task);
456 ve->timeout_task = NULL;
458 if (NULL != ve->revalidation_task)
460 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
461 ve->revalidation_task = NULL;
463 if ( (GNUNET_YES == ve->expecting_pong) &&
464 (validations_running > 0) )
466 validations_running --;
467 GNUNET_STATISTICS_set (GST_stats,
468 gettext_noop ("# validations running"),
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Validation finished, %u validation processes running\n",
473 validations_running);
481 * Address validation cleanup task. Assesses if the record is no
482 * longer valid and then possibly triggers its removal.
484 * @param cls the `struct ValidationEntry`
485 * @param tc scheduler context (unused)
488 timeout_hello_validation (void *cls,
489 const struct GNUNET_SCHEDULER_TaskContext *tc)
491 struct ValidationEntry *ve = cls;
492 struct GNUNET_TIME_Absolute max;
493 struct GNUNET_TIME_Relative left;
495 ve->timeout_task = NULL;
496 max = GNUNET_TIME_absolute_max (ve->valid_until,
497 ve->revalidation_block);
498 left = GNUNET_TIME_absolute_get_remaining (max);
499 if (left.rel_value_us > 0)
501 /* should wait a bit longer */
503 GNUNET_SCHEDULER_add_delayed (left, &timeout_hello_validation, ve);
506 GNUNET_STATISTICS_update (GST_stats,
507 gettext_noop ("# address records discarded"), 1,
509 cleanup_validation_entry (NULL, &ve->address->peer, ve);
514 * Function called with the result from blacklisting.
515 * Send a PING to the other peer if a communication is allowed.
517 * @param cls our `struct ValidationEntry`
518 * @param pid identity of the other peer
519 * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not
522 transmit_ping_if_allowed (void *cls,
523 const struct GNUNET_PeerIdentity *pid,
526 struct ValidationEntry *ve = cls;
527 struct TransportPingMessage ping;
528 struct GNUNET_TRANSPORT_PluginFunctions *papi;
529 struct GNUNET_TIME_Absolute next;
530 const struct GNUNET_MessageHeader *hello;
531 enum GNUNET_ATS_Network_Type network;
538 if (GNUNET_NO == result)
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
541 "Blacklist denies to send PING to `%s' `%s' `%s'\n",
543 GST_plugins_a2s (ve->address),
544 ve->address->transport_name);
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
549 "Transmitting plain PING to `%s' `%s' `%s'\n",
551 GST_plugins_a2s (ve->address),
552 ve->address->transport_name);
554 slen = strlen (ve->address->transport_name) + 1;
555 hello = GST_hello_get ();
556 hsize = ntohs (hello->size);
558 sizeof (struct TransportPingMessage) + ve->address->address_length +
562 htons (sizeof (struct TransportPingMessage) +
563 ve->address->address_length + slen);
564 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
565 ping.challenge = htonl (ve->challenge);
568 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
573 sizeof (struct TransportPingMessage) + ve->address->address_length +
577 char message_buf[tsize];
579 /* build message with structure:
580 * [HELLO][TransportPingMessage][Transport name][Address] */
581 memcpy (message_buf, hello, hsize);
582 memcpy (&message_buf[hsize],
584 sizeof (struct TransportPingMessage));
585 memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
586 ve->address->transport_name,
588 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
589 ve->address->address,
590 ve->address->address_length);
591 papi = GST_plugins_find (ve->address->transport_name);
595 GNUNET_STATISTICS_update (GST_stats,
596 gettext_noop ("# validations not attempted (no plugin)"),
602 GNUNET_assert (NULL != papi->send);
603 struct Session *session = papi->get_session (papi->cls,
608 ret = papi->send (papi->cls, session,
611 ACCEPTABLE_PING_DELAY,
613 network = papi->get_network (papi->cls, session);
614 if (GNUNET_ATS_NET_UNSPECIFIED == network)
616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 "Could not obtain a valid network for `%s' `%s'\n",
619 GST_plugins_a2s (ve->address));
622 GST_neighbours_notify_data_sent (ve->address, session, tsize);
626 /* Could not get a valid session */
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 "Could not get a valid session for `%s' `%s'\n",
630 GST_plugins_a2s (ve->address));
637 next = GNUNET_TIME_relative_to_absolute (validation_delay);
638 validation_next = GNUNET_TIME_absolute_max (next,
640 ve->send_time = GNUNET_TIME_absolute_get ();
641 GNUNET_STATISTICS_update (GST_stats,
642 gettext_noop ("# PINGs for address validation sent"),
645 ve->network = network;
646 ve->expecting_pong = GNUNET_YES;
647 validations_running++;
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "Validation started, %u validation processes running\n",
650 validations_running);
651 GNUNET_STATISTICS_set (GST_stats,
652 gettext_noop ("# validations running"),
655 /* Notify about PING sent */
656 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
662 * Do address validation again to keep address valid.
664 * @param cls the `struct ValidationEntry`
665 * @param tc scheduler context (unused)
668 revalidate_address (void *cls,
669 const struct GNUNET_SCHEDULER_TaskContext *tc)
671 struct ValidationEntry *ve = cls;
672 struct GNUNET_TIME_Relative canonical_delay;
673 struct GNUNET_TIME_Relative delay;
674 struct GNUNET_TIME_Relative blocked_for;
675 struct GST_BlacklistCheck *bc;
678 ve->revalidation_task = NULL;
679 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
680 /* Considering current connectivity situation, what is the maximum
681 block period permitted? */
682 if (GNUNET_YES == ve->in_use)
683 canonical_delay = CONNECTED_PING_FREQUENCY;
684 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0)
685 canonical_delay = VALIDATED_PING_FREQUENCY;
687 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
688 /* Use delay that is MIN of original delay and possibly adjusted
689 new maximum delay (which may be lower); the real delay
690 is originally randomized between "canonical_delay" and "2 * canonical_delay",
691 so continue to permit that window for the operation. */
692 delay = GNUNET_TIME_relative_min (delay,
693 GNUNET_TIME_relative_multiply (canonical_delay,
695 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
696 if (delay.rel_value_us > 0)
698 /* should wait a bit longer */
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Waiting for %s longer before validating address `%s'\n",
701 GNUNET_STRINGS_relative_time_to_string (delay,
703 GST_plugins_a2s (ve->address));
704 ve->revalidation_task =
705 GNUNET_SCHEDULER_add_delayed (delay,
706 &revalidate_address, ve);
707 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
710 /* check if globally we have too many active validations at a
711 too high rate, if so, delay ours */
712 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next);
713 if ( (validations_running > validations_fast_start_threshold) &&
714 (blocked_for.rel_value_us > 0) )
716 /* Validations are blocked, have to wait for blocked_for time */
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
718 "Validations blocked for another %s, delaying validating address `%s'\n",
719 GNUNET_STRINGS_relative_time_to_string (blocked_for,
721 GST_plugins_a2s (ve->address));
722 ve->revalidation_task =
723 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
724 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for);
728 /* We are good to go; remember to not go again for `canonical_delay` time;
729 add up to `canonical_delay` to randomize start time */
730 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
731 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
733 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
734 canonical_delay.rel_value_us);
736 delay = GNUNET_TIME_relative_add (canonical_delay,
737 GNUNET_TIME_relative_multiply
738 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay));
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 "Validating now, next scheduled for %s, now validating address `%s'\n",
742 GNUNET_STRINGS_relative_time_to_string (blocked_for,
744 GST_plugins_a2s (ve->address));
745 ve->revalidation_task =
746 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
747 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay);
749 /* start PINGing by checking blacklist */
750 GNUNET_STATISTICS_update (GST_stats,
751 gettext_noop ("# address revalidations started"), 1,
753 bc = GST_blacklist_test_allowed (&ve->address->peer,
754 ve->address->transport_name,
755 &transmit_ping_if_allowed, ve);
757 ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already
763 * Find a ValidationEntry entry for the given neighbour that matches
764 * the given address and transport. If none exists, create one (but
765 * without starting any validation).
767 * @param address address to find
768 * @return validation entry matching the given specifications, NULL
769 * if we don't have an existing entry and no public key was given
771 static struct ValidationEntry *
772 find_validation_entry (const struct GNUNET_HELLO_Address *address)
774 struct ValidationEntryMatchContext vemc;
775 struct ValidationEntry *ve;
778 vemc.address = address;
779 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
781 &validation_entry_match, &vemc);
782 if (NULL != (ve = vemc.ve))
784 ve = GNUNET_new (struct ValidationEntry);
785 ve->in_use = GNUNET_SYSERR; /* not defined */
786 ve->address = GNUNET_HELLO_address_copy (address);
787 ve->pong_sig_valid_until = GNUNET_TIME_absolute_get_zero_();
788 memset (&ve->pong_sig_cache, '\0', sizeof (struct GNUNET_CRYPTO_EddsaSignature));
789 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
791 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
793 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
794 &timeout_hello_validation, ve);
795 GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer,
797 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
798 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW);
804 * Iterator which adds the given address to the set of validated
807 * @param cls original HELLO message
808 * @param address the address
809 * @param expiration expiration time
810 * @return #GNUNET_OK (keep the address)
813 add_valid_address (void *cls,
814 const struct GNUNET_HELLO_Address *address,
815 struct GNUNET_TIME_Absolute expiration)
817 const struct GNUNET_HELLO_Message *hello = cls;
818 struct ValidationEntry *ve;
819 struct GNUNET_PeerIdentity pid;
820 struct GNUNET_ATS_Information ats;
822 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
823 return GNUNET_OK; /* expired */
824 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
827 return GNUNET_OK; /* invalid HELLO !? */
829 if (0 == memcmp (&GST_my_identity,
831 sizeof (struct GNUNET_PeerIdentity)))
833 /* Peerinfo returned own identity, skip validation */
836 if (NULL == GST_plugins_find (address->transport_name))
838 /* might have been valid in the past, but we don't have that
839 plugin loaded right now */
843 ve = find_validation_entry (address);
844 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
846 if (NULL == ve->revalidation_task)
848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
849 "Starting revalidations for valid address `%s'\n",
850 GST_plugins_a2s (ve->address));
851 ve->next_validation = GNUNET_TIME_absolute_get();
852 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
854 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
856 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
857 ats.value = htonl (ve->network);
858 if (GNUNET_YES != ve->known_to_ats)
860 ve->known_to_ats = GNUNET_YES;
861 GST_ats_add_address (address, NULL, &ats, 1);
868 * Function called for any HELLO known to PEERINFO.
871 * @param peer id of the peer, NULL for last call
872 * @param hello hello message for the peer (can be NULL)
873 * @param err_msg error message
876 process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
877 const struct GNUNET_HELLO_Message *hello,
880 GNUNET_assert (NULL != peer);
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
884 "Handling HELLO for peer `%s'\n",
886 GNUNET_assert (NULL ==
887 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
894 * Start the validation subsystem.
896 * @param max_fds maximum number of fds to use
899 GST_validation_start (unsigned int max_fds)
902 * Initialization for validation throttling
904 * We have a maximum number max_fds of connections we can use for validation
905 * We monitor the number of validations in parallel and start to throttle it
906 * when doing to many validations in parallel:
907 * if (running validations < (max_fds / 2))
908 * - "fast start": run validation immediately
909 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
910 * (300 sec / ~150 == ~2 sec.) between two validations
913 validation_next = GNUNET_TIME_absolute_get();
914 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
915 validations_fast_start_threshold = (max_fds / 2);
916 validations_running = 0;
917 GNUNET_STATISTICS_set (GST_stats,
918 gettext_noop ("# validations running"),
921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
922 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
923 validations_fast_start_threshold,
924 GNUNET_STRINGS_relative_time_to_string (validation_delay,
926 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
928 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
929 &process_peerinfo_hello, NULL);
934 * Stop the validation subsystem.
937 GST_validation_stop ()
939 struct CheckHelloValidatedContext *chvc;
941 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
942 &cleanup_validation_entry, NULL);
943 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
944 validation_map = NULL;
945 while (NULL != (chvc = chvc_head))
947 GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
950 GNUNET_PEERINFO_notify_cancel (pnc);
955 * Send the given PONG to the given address.
957 * @param cls the PONG message
958 * @param valid_until is ZERO if we never validated the address,
959 * otherwise a time up to when we consider it (or was) valid
960 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
961 * is ZERO if the address is considered valid (no validation needed)
962 * otherwise a time in the future if we're currently denying re-validation
963 * @param address target address
966 multicast_pong (void *cls,
967 struct GNUNET_TIME_Absolute valid_until,
968 struct GNUNET_TIME_Absolute validation_block,
969 const struct GNUNET_HELLO_Address *address)
971 struct TransportPongMessage *pong = cls;
972 struct GNUNET_TRANSPORT_PluginFunctions *papi;
973 struct Session *session;
975 papi = GST_plugins_find (address->transport_name);
979 GNUNET_assert (NULL != papi->send);
980 GNUNET_assert (NULL != papi->get_session);
981 session = papi->get_session(papi->cls, address);
987 GST_ats_new_session (address, session);
988 papi->send (papi->cls, session,
990 ntohs (pong->header.size),
992 ACCEPTABLE_PING_DELAY,
994 GST_neighbours_notify_data_sent (address,
1002 * We've received a PING. If appropriate, generate a PONG.
1004 * @param sender peer sending the PING
1005 * @param hdr the PING
1006 * @param sender_address the sender address as we got it
1007 * @param session session we got the PING from
1008 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1011 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1012 const struct GNUNET_MessageHeader *hdr,
1013 const struct GNUNET_HELLO_Address *sender_address,
1014 struct Session *session)
1016 const struct TransportPingMessage *ping;
1017 struct TransportPongMessage *pong;
1018 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1019 struct GNUNET_CRYPTO_EddsaSignature *sig_cache;
1020 struct GNUNET_TIME_Absolute *sig_cache_exp;
1022 const char *addrend;
1028 int buggy = GNUNET_NO;
1029 struct GNUNET_HELLO_Address address;
1031 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
1033 GNUNET_break_op (0);
1034 return GNUNET_SYSERR;
1036 ping = (const struct TransportPingMessage *) hdr;
1038 memcmp (&ping->target, &GST_my_identity,
1039 sizeof (struct GNUNET_PeerIdentity)))
1041 GNUNET_STATISTICS_update (GST_stats,
1043 ("# PING message for different peer received"), 1,
1045 return GNUNET_SYSERR;
1047 GNUNET_STATISTICS_update (GST_stats,
1048 gettext_noop ("# PING messages received"), 1,
1050 addr = (const char *) &ping[1];
1051 len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
1052 /* peer wants to confirm that this is one of our addresses, this is what is
1053 * used for address validation */
1056 sig_cache_exp = NULL;
1058 if (len_address > 0)
1060 addrend = memchr (addr, '\0', len_address);
1061 if (NULL == addrend)
1063 GNUNET_break_op (0);
1064 return GNUNET_SYSERR;
1067 len_plugin = strlen (addr) + 1;
1068 len_address -= len_plugin;
1069 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1070 address.address = addrend;
1071 address.address_length = len_address;
1072 address.transport_name = addr;
1073 address.peer = GST_my_identity;
1075 if (NULL == address.transport_name)
1080 if (0 != strstr (address.transport_name, "_client"))
1082 plugin_name = GNUNET_strdup (address.transport_name);
1083 pos = strstr (plugin_name, "_client");
1084 GNUNET_assert (NULL != pos);
1085 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1088 plugin_name = GNUNET_strdup (address.transport_name);
1090 if (NULL == (papi = GST_plugins_find (plugin_name)))
1092 /* we don't have the plugin for this address */
1093 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1094 _("Plugin `%s' not available, cannot confirm having this address\n"),
1096 GNUNET_free (plugin_name);
1097 return GNUNET_SYSERR;
1099 GNUNET_free (plugin_name);
1100 if (GNUNET_OK != papi->check_address (papi->cls, addrend, len_address))
1102 GNUNET_STATISTICS_update (GST_stats,
1104 ("# failed address checks during validation"), 1,
1106 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1107 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1108 GST_plugins_a2s (&address));
1109 return GNUNET_SYSERR;
1113 GNUNET_STATISTICS_update (GST_stats,
1115 ("# successful address checks during validation"), 1,
1117 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1118 "Address `%s' is one of my addresses, confirming PING\n",
1119 GST_plugins_a2s (&address));
1122 if (GNUNET_YES != GST_hello_test_address (&address, &sig_cache, &sig_cache_exp))
1124 if (GNUNET_NO == buggy)
1126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1127 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1128 GNUNET_i2s (sender),
1129 GST_plugins_a2s (&address));
1130 return GNUNET_SYSERR;
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1135 _("Received a PING message with validation bug from `%s'\n"),
1136 GNUNET_i2s (sender));
1142 addrend = NULL; /* make gcc happy */
1144 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1145 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1147 sig_cache = &no_address_signature;
1148 sig_cache_exp = &no_address_signature_expiration;
1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1152 "I am `%s', sending PONG to peer `%s'\n",
1153 GNUNET_i2s_full (&GST_my_identity),
1154 GNUNET_i2s (sender));
1156 /* message with structure:
1157 * [TransportPongMessage][Transport name][Address] */
1159 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1161 htons (sizeof (struct TransportPongMessage) + len_address + len_plugin);
1162 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1163 pong->purpose.size =
1164 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1165 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1166 len_address + len_plugin);
1167 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1168 memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
1169 pong->addrlen = htonl (len_address + len_plugin);
1170 memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */
1171 if (len_address > 0)
1173 GNUNET_assert (NULL != addrend);
1174 memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address);
1176 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1177 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1179 /* create / update cached sig */
1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1181 "Creating PONG signature to indicate ownership.\n");
1182 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
1183 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1185 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1189 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender));
1194 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1196 pong->signature = *sig_cache;
1198 GNUNET_assert (sender_address != NULL);
1200 /* first see if the session we got this PING from can be used to transmit
1201 * a response reliably */
1208 GNUNET_assert (NULL != papi->send);
1209 GNUNET_assert (NULL != papi->get_session);
1210 if (NULL == session)
1212 session = papi->get_session (papi->cls, sender_address);
1214 if (NULL == session)
1221 ret = papi->send (papi->cls, session,
1222 (const char *) pong,
1223 ntohs (pong->header.size),
1224 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1227 GST_neighbours_notify_data_sent (sender_address,
1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235 "Transmitted PONG to `%s' via reliable mechanism\n",
1236 GNUNET_i2s (sender));
1238 GNUNET_STATISTICS_update (GST_stats,
1240 ("# PONGs unicast via reliable transport"), 1,
1246 /* no reliable method found, try transmission via all known addresses */
1247 GNUNET_STATISTICS_update (GST_stats,
1249 ("# PONGs multicast to all available addresses"), 1,
1251 GST_validation_get_addresses (sender,
1252 &multicast_pong, pong);
1259 * Iterator callback to go over all addresses and try to validate them
1260 * (unless blocked or already validated).
1263 * @param address the address
1264 * @param expiration expiration time
1265 * @return #GNUNET_OK (keep the address)
1268 validate_address_iterator (void *cls,
1269 const struct GNUNET_HELLO_Address *address,
1270 struct GNUNET_TIME_Absolute expiration)
1272 struct GNUNET_TRANSPORT_PluginFunctions * papi;
1273 struct ValidationEntry *ve;
1275 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1278 "Skipping expired address from HELLO\n");
1279 return GNUNET_OK; /* expired */
1281 papi = GST_plugins_find (address->transport_name);
1284 /* This plugin is currently unvailable ... ignore */
1287 ve = find_validation_entry (address);
1288 if (NULL == ve->revalidation_task)
1290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1291 "Validation process started for fresh address `%s'\n",
1292 GST_plugins_a2s (ve->address));
1293 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1300 * Add the validated peer address to the HELLO.
1302 * @param cls the `struct ValidationEntry *` with the validated address
1303 * @param max space in @a buf
1304 * @param buf where to add the address
1305 * @return number of bytes written, #GNUNET_SYSERR to signal the
1306 * end of the iteration.
1309 add_valid_peer_address (void *cls,
1313 struct ValidationEntry *ve = cls;
1315 if (GNUNET_YES == ve->copied)
1316 return GNUNET_SYSERR; /* Done */
1317 ve->copied = GNUNET_YES;
1318 return GNUNET_HELLO_add_address (ve->address, ve->valid_until, buf, max);
1323 * We've received a PONG. Check if it matches a pending PING and
1324 * mark the respective address as confirmed.
1326 * @param sender peer sending the PONG
1327 * @param hdr the PONG
1328 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1331 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1332 const struct GNUNET_MessageHeader *hdr)
1334 const struct TransportPongMessage *pong;
1335 struct ValidationEntry *ve;
1341 struct GNUNET_HELLO_Message *hello;
1342 struct GNUNET_HELLO_Address address;
1346 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1348 GNUNET_break_op (0);
1349 return GNUNET_SYSERR;
1351 GNUNET_STATISTICS_update (GST_stats,
1352 gettext_noop ("# PONG messages received"), 1,
1355 /* message with structure:
1356 * [TransportPongMessage][Transport name][Address] */
1358 pong = (const struct TransportPongMessage *) hdr;
1359 tname = (const char *) &pong[1];
1360 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1361 addr = memchr (tname, '\0', size);
1364 GNUNET_break_op (0);
1365 return GNUNET_SYSERR;
1368 slen = strlen (tname) + 1;
1369 addrlen = size - slen;
1370 address.peer = *sender;
1371 address.address = addr;
1372 address.address_length = addrlen;
1373 address.transport_name = tname;
1374 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1375 ve = find_validation_entry (&address);
1376 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1378 GNUNET_STATISTICS_update (GST_stats,
1380 ("# PONGs dropped, no matching pending validation"),
1384 /* now check that PONG is well-formed */
1385 if (0 != memcmp (&ve->address->peer,
1387 sizeof (struct GNUNET_PeerIdentity)))
1389 GNUNET_break_op (0);
1390 return GNUNET_SYSERR;
1393 GNUNET_TIME_absolute_get_remaining
1394 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us)
1396 GNUNET_STATISTICS_update (GST_stats,
1398 ("# PONGs dropped, signature expired"), 1,
1400 return GNUNET_SYSERR;
1403 sig_res = GNUNET_SYSERR;
1404 do_verify = GNUNET_YES;
1405 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
1407 /* We have a cached and valid signature for this peer,
1408 * try to compare instead of verify */
1409 if (0 == memcmp (&ve->pong_sig_cache, &pong->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1411 /* signatures are identical, we can skip verification */
1412 sig_res = GNUNET_OK;
1413 do_verify = GNUNET_NO;
1417 sig_res = GNUNET_SYSERR;
1418 /* signatures do not match, we have to verify */
1422 if (GNUNET_YES == do_verify)
1424 /* Do expensive verification */
1425 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1426 &pong->purpose, &pong->signature,
1427 &ve->address->peer.public_key);
1428 if (sig_res == GNUNET_SYSERR)
1430 GNUNET_break_op (0);
1431 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1432 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1434 GST_plugins_a2s (ve->address),
1435 GNUNET_i2s (sender));
1438 if (sig_res == GNUNET_SYSERR)
1440 GNUNET_break_op (0);
1441 return GNUNET_SYSERR;
1444 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1445 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1446 GNUNET_i2s (sender),
1448 GST_plugins_a2s (ve->address));
1449 GNUNET_STATISTICS_update (GST_stats,
1450 gettext_noop ("# validations succeeded"),
1453 /* validity achieved, remember it! */
1454 ve->expecting_pong = GNUNET_NO;
1455 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1456 ve->pong_sig_cache = pong->signature;
1457 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1458 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1460 struct GNUNET_ATS_Information ats[2];
1462 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
1463 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
1464 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1465 ats[1].value = htonl ((uint32_t) ve->network);
1466 if (GNUNET_YES == ve->known_to_ats)
1468 GST_ats_update_metrics (ve->address, NULL, ats, 2);
1472 ve->known_to_ats = GNUNET_YES;
1473 GST_ats_add_address (ve->address, NULL, ats, 2);
1476 if (validations_running > 0)
1478 validations_running --;
1479 GNUNET_STATISTICS_set (GST_stats,
1480 gettext_noop ("# validations running"),
1481 validations_running,
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1484 "Validation finished, %u validation processes running\n",
1485 validations_running);
1492 /* Notify about new validity */
1493 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
1495 /* build HELLO to store in PEERINFO */
1496 ve->copied = GNUNET_NO;
1497 hello = GNUNET_HELLO_create (&ve->address->peer.public_key,
1498 &add_valid_peer_address, ve,
1500 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1501 GNUNET_free (hello);
1507 * We've received a HELLO, check which addresses are new and trigger
1510 * @param hello the HELLO we received
1511 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1514 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1516 const struct GNUNET_HELLO_Message *hm =
1517 (const struct GNUNET_HELLO_Message *) hello;
1518 struct GNUNET_PeerIdentity pid;
1519 struct GNUNET_HELLO_Message *h;
1522 friend = GNUNET_HELLO_is_friend_only (hm);
1523 if ( ( (GNUNET_YES != friend) &&
1524 (GNUNET_NO != friend) ) ||
1525 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) )
1527 /* malformed HELLO */
1528 GNUNET_break_op (0);
1529 return GNUNET_SYSERR;
1532 memcmp (&GST_my_identity,
1534 sizeof (struct GNUNET_PeerIdentity)))
1536 /* Add peer identity without addresses to peerinfo service */
1537 h = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, friend);
1538 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1539 _("Validation received new %s message for peer `%s' with size %u\n"),
1542 ntohs (hello->size));
1543 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1546 _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",
1550 GNUNET_assert (NULL ==
1551 GNUNET_HELLO_iterate_addresses (hm,
1553 &validate_address_iterator,
1560 * Closure for #iterate_addresses().
1562 struct IteratorContext
1565 * Function to call on each address.
1567 GST_ValidationAddressCallback cb;
1570 * Closure for @e cb.
1578 * Call the callback in the closure for each validation entry.
1580 * @param cls the `struct IteratorContext`
1581 * @param key the peer's identity
1582 * @param value the `struct ValidationEntry`
1583 * @return #GNUNET_OK (continue to iterate)
1586 iterate_addresses (void *cls,
1587 const struct GNUNET_PeerIdentity *key,
1590 struct IteratorContext *ic = cls;
1591 struct ValidationEntry *ve = value;
1595 ve->revalidation_block,
1602 * Call the given function for each address for the given target.
1603 * Can either give a snapshot (synchronous API) or be continuous.
1605 * @param target peer information is requested for
1606 * @param cb function to call; will not be called after this function returns
1607 * @param cb_cls closure for @a cb
1610 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1611 GST_ValidationAddressCallback cb,
1614 struct IteratorContext ic;
1618 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1620 &iterate_addresses, &ic);
1625 * Update if we are using an address for a connection actively right now.
1626 * Based on this, the validation module will measure latency for the
1627 * address more or less often.
1629 * @param address the address
1630 * @param session the session
1631 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1632 * #GNUNET_NO if we are no longer using the address for a connection
1635 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1636 struct Session *session,
1639 struct ValidationEntry *ve;
1641 if (GNUNET_HELLO_address_check_option (address,
1642 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1643 return; /* ignore inbound for validation */
1644 if (NULL != address)
1645 ve = find_validation_entry (address);
1647 ve = NULL; /* FIXME: lookup based on session... */
1650 /* this can happen for inbound connections (sender_address_len == 0); */
1653 if (ve->in_use == in_use)
1655 if (GNUNET_YES == in_use)
1657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1658 "Error setting address in use for peer `%s' `%s' to USED\n",
1659 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1661 if (GNUNET_NO == in_use)
1663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1664 "Error setting address in use for peer `%s' `%s' to NOT_USED\n",
1665 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1669 GNUNET_break (ve->in_use != in_use); /* should be different... */
1670 ve->in_use = in_use;
1671 if (in_use == GNUNET_YES)
1673 /* from now on, higher frequeny, so reschedule now */
1674 if (NULL != ve->revalidation_task)
1675 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1676 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1682 * Query validation about the latest observed latency on a given
1685 * @param address the address
1686 * @param session session
1687 * @return observed latency of the address, FOREVER if the address was
1688 * never successfully validated
1690 struct GNUNET_TIME_Relative
1691 GST_validation_get_address_latency (const struct GNUNET_HELLO_Address *address,
1692 struct Session *session)
1694 struct ValidationEntry *ve;
1696 if (NULL == address)
1698 GNUNET_break (0); // FIXME: support having latency only with session...
1699 return GNUNET_TIME_UNIT_FOREVER_REL;
1701 ve = find_validation_entry (address);
1703 return GNUNET_TIME_UNIT_FOREVER_REL;
1708 * Closure for the validation_entries_iterate function.
1710 struct ValidationIteratorContext
1713 * Function to call on each validation entry
1715 GST_ValidationChangedCallback cb;
1718 * Closure for @e cb.
1725 * Function called on each entry in the validation map.
1726 * Passes the information from the validation entry to
1727 * the callback given in the closure.
1729 * @param cls the `struct ValidationIteratorContext`
1730 * @param key peer this is about
1731 * @param value the `struct ValidationEntry`
1732 * @return #GNUNET_OK (continue to iterate)
1735 validation_entries_iterate (void *cls,
1736 const struct GNUNET_PeerIdentity *key,
1739 struct ValidationIteratorContext *ic = cls;
1740 struct ValidationEntry *ve = value;
1742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1743 "Notifying about validation entry for peer `%s' address `%s' \n",
1744 GNUNET_i2s (&ve->address->peer),
1745 GST_plugins_a2s (ve->address));
1750 ve->next_validation,
1757 * Iterate over all iteration entries
1759 * @param cb function to call
1760 * @param cb_cls closure for cb
1763 GST_validation_iterate (GST_ValidationChangedCallback cb,
1766 struct ValidationIteratorContext ic;
1768 if (NULL == validation_map)
1769 return; /* can happen during shutdown */
1772 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1773 &validation_entries_iterate,
1777 /* end of file gnunet-service-transport_validation.c */