2 This file is part of GNUnet.
3 (C) 2010-2014 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_clients.h"
28 #include "gnunet-service-transport_validation.h"
29 #include "gnunet-service-transport_plugins.h"
30 #include "gnunet-service-transport_hello.h"
31 #include "gnunet-service-transport_blacklist.h"
32 #include "gnunet-service-transport_neighbours.h"
33 #include "gnunet-service-transport.h"
34 #include "gnunet_hello_lib.h"
35 #include "gnunet_ats_service.h"
36 #include "gnunet_peerinfo_service.h"
37 #include "gnunet_signatures.h"
41 * How long is a PONG signature valid? We'll recycle a signature until
42 * 1/4 of this time is remaining. PONGs should expire so that if our
43 * external addresses change an adversary cannot replay them indefinitely.
44 * OTOH, we don't want to spend too much time generating PONG signatures,
45 * so they must have some lifetime to reduce our CPU usage.
47 #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
50 * After how long do we expire an address in a HELLO that we just
51 * validated? This value is also used for our own addresses when we
54 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
57 * How often do we allow PINGing an address that we have not yet
58 * validated? This also determines how long we track an address that
59 * we cannot validate (because after this time we can destroy the
62 #define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
65 * How often do we PING an address that we have successfully validated
66 * in the past but are not actively using? Should be (significantly)
67 * smaller than HELLO_ADDRESS_EXPIRATION.
69 #define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
72 * How often do we PING an address that we are currently using?
74 #define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
77 * How much delay is acceptable for sending the PING or PONG?
79 #define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
82 * Size of the validation map hashmap.
84 #define VALIDATION_MAP_SIZE 256
87 * Priority to use for PINGs
89 #define PING_PRIORITY 2
92 * Priority to use for PONGs
94 #define PONG_PRIORITY 4
97 GNUNET_NETWORK_STRUCT_BEGIN
100 * Message used to ask a peer to validate receipt (to check an address
101 * from a HELLO). Followed by the address we are trying to validate,
102 * or an empty address if we are just sending a PING to confirm that a
103 * connection which the receiver (of the PING) initiated is still valid.
105 struct TransportPingMessage
109 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PING
111 struct GNUNET_MessageHeader header;
114 * Challenge code (to ensure fresh reply).
116 uint32_t challenge GNUNET_PACKED;
119 * Who is the intended recipient?
121 struct GNUNET_PeerIdentity target;
127 * Message used to validate a HELLO. The challenge is included in the
128 * confirmation to make matching of replies to requests possible. The
129 * signature signs our public key, an expiration time and our address.<p>
131 * This message is followed by our transport address that the PING tried
132 * to confirm (if we liked it). The address can be empty (zero bytes)
133 * if the PING had not address either (and we received the request via
134 * a connection that we initiated).
136 struct TransportPongMessage
140 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
142 struct GNUNET_MessageHeader header;
145 * Challenge code from PING (showing freshness). Not part of what
146 * is signed so that we can re-use signatures.
148 uint32_t challenge GNUNET_PACKED;
153 struct GNUNET_CRYPTO_EddsaSignature signature;
156 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
157 * plausible address for the signing peer.
159 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
162 * When does this signature expire?
164 struct GNUNET_TIME_AbsoluteNBO expiration;
167 * Size of address appended to this message (part of what is
168 * being signed, hence not redundant).
170 uint32_t addrlen GNUNET_PACKED;
173 GNUNET_NETWORK_STRUCT_END
176 * Information about an address under validation
178 struct ValidationEntry
184 struct GNUNET_HELLO_Address *address;
187 * Handle to the blacklist check (if we're currently in it).
189 struct GST_BlacklistCheck *bc;
192 * Public key of the peer.
194 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
197 * The identity of the peer. FIXME: duplicated (also in 'address')
199 struct GNUNET_PeerIdentity pid;
202 * Cached PONG signature
204 struct GNUNET_CRYPTO_EddsaSignature pong_sig_cache;
207 * ID of task that will clean up this entry if nothing happens.
209 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
212 * ID of task that will trigger address revalidation.
214 GNUNET_SCHEDULER_TaskIdentifier revalidation_task;
217 * At what time did we send the latest validation request (PING)?
219 struct GNUNET_TIME_Absolute send_time;
222 * At what time do we send the next validation request (PING)?
224 struct GNUNET_TIME_Absolute next_validation;
227 * Until when is this address valid?
228 * ZERO if it is not currently considered valid.
230 struct GNUNET_TIME_Absolute valid_until;
233 * Until when is the cached PONG signature valid?
234 * ZERO if it is not currently considered valid.
236 struct GNUNET_TIME_Absolute pong_sig_valid_until;
239 * How long until we can try to validate this address again?
240 * FOREVER if the address is for an unsupported plugin (from PEERINFO)
241 * ZERO if the address is considered valid (no validation needed)
242 * otherwise a time in the future if we're currently denying re-validation
244 struct GNUNET_TIME_Absolute revalidation_block;
247 * Last observed latency for this address (round-trip), delay between
248 * last PING sent and PONG received; FOREVER if we never got a PONG.
250 struct GNUNET_TIME_Relative latency;
253 * Current state of this validation entry
255 enum GNUNET_TRANSPORT_ValidationState state;
257 * Challenge number we used.
262 * When passing the address in 'add_valid_peer_address', did we
263 * copy the address to the HELLO yet?
268 * Are we currently using this address for a connection?
273 * Are we expecting a PONG message for this validation entry?
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
336 static unsigned int validations_running;
339 * Validition fast start threshold
341 static unsigned int validations_fast_start_threshold;
344 * When is next validation allowed
346 static struct GNUNET_TIME_Absolute validation_next;
350 * Context for the validation entry match function.
352 struct ValidationEntryMatchContext
355 * Where to store the result?
357 struct ValidationEntry *ve;
360 * Address we're interested in.
362 const struct GNUNET_HELLO_Address *address;
368 * Iterate over validation entries until a matching one is found.
370 * @param cls the `struct ValidationEntryMatchContext *`
371 * @param key peer identity (unused)
372 * @param value a `struct ValidationEntry *` to match
373 * @return #GNUNET_YES if the entry does not match,
374 * #GNUNET_NO if the entry does match
377 validation_entry_match (void *cls,
378 const struct GNUNET_PeerIdentity *key,
381 struct ValidationEntryMatchContext *vemc = cls;
382 struct ValidationEntry *ve = value;
384 if (0 == GNUNET_HELLO_address_cmp (ve->address, vemc->address))
394 * A validation entry changed. Update the state and notify
397 * @param ve validation entry that changed
398 * @param state new state
401 validation_entry_changed (struct ValidationEntry *ve,
402 enum GNUNET_TRANSPORT_ValidationState state)
405 GST_clients_broadcast_validation_notification (&ve->pid,
415 * Iterate over validation entries and free them.
417 * @param cls (unused)
418 * @param key peer identity (unused)
419 * @param value a `struct ValidationEntry *` to clean up
420 * @return #GNUNET_YES (continue to iterate)
423 cleanup_validation_entry (void *cls,
424 const struct GNUNET_PeerIdentity *key,
427 struct ValidationEntry *ve = value;
429 ve->next_validation = GNUNET_TIME_absolute_get_zero_();
430 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
432 /* Notify about deleted entry */
433 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_REMOVE);
437 GST_blacklist_test_cancel (ve->bc);
440 GNUNET_break (GNUNET_OK ==
441 GNUNET_CONTAINER_multipeermap_remove (validation_map,
443 GNUNET_HELLO_address_free (ve->address);
444 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
446 GNUNET_SCHEDULER_cancel (ve->timeout_task);
447 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
449 if (GNUNET_SCHEDULER_NO_TASK != ve->revalidation_task)
451 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
452 ve->revalidation_task = GNUNET_SCHEDULER_NO_TASK;
454 if ((GNUNET_YES == ve->expecting_pong) &&
455 (validations_running > 0))
457 validations_running --;
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "Validation finished, %u validation processes running\n",
460 validations_running);
468 * Address validation cleanup task. Assesses if the record is no
469 * longer valid and then possibly triggers its removal.
471 * @param cls the 'struct ValidationEntry'
472 * @param tc scheduler context (unused)
475 timeout_hello_validation (void *cls,
476 const struct GNUNET_SCHEDULER_TaskContext *tc)
478 struct ValidationEntry *ve = cls;
479 struct GNUNET_TIME_Absolute max;
480 struct GNUNET_TIME_Relative left;
482 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
483 max = GNUNET_TIME_absolute_max (ve->valid_until, ve->revalidation_block);
484 left = GNUNET_TIME_absolute_get_remaining (max);
485 if (left.rel_value_us > 0)
487 /* should wait a bit longer */
489 GNUNET_SCHEDULER_add_delayed (left, &timeout_hello_validation, ve);
492 GNUNET_STATISTICS_update (GST_stats,
493 gettext_noop ("# address records discarded"), 1,
495 cleanup_validation_entry (NULL, &ve->pid, ve);
500 * Function called with the result from blacklisting.
501 * Send a PING to the other peer if a communication is allowed.
503 * @param cls our 'struct ValidationEntry'
504 * @param pid identity of the other peer
505 * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not
508 transmit_ping_if_allowed (void *cls,
509 const struct GNUNET_PeerIdentity *pid,
512 struct ValidationEntry *ve = cls;
513 struct TransportPingMessage ping;
514 struct GNUNET_TRANSPORT_PluginFunctions *papi;
515 struct GNUNET_TIME_Absolute next;
516 const struct GNUNET_MessageHeader *hello;
517 enum GNUNET_ATS_Network_Type network;
524 if (GNUNET_NO == result)
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Blacklist denies to send PING to `%s' `%s' `%s'\n",
529 GST_plugins_a2s (ve->address),
530 ve->address->transport_name);
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
535 "Transmitting plain PING to `%s' `%s' `%s'\n",
537 GST_plugins_a2s (ve->address),
538 ve->address->transport_name);
540 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
542 if (next.abs_value_us > validation_next.abs_value_us)
543 validation_next = next; /* We're going to send a PING so delay next validation */
545 slen = strlen (ve->address->transport_name) + 1;
546 hello = GST_hello_get ();
547 hsize = ntohs (hello->size);
549 sizeof (struct TransportPingMessage) + ve->address->address_length +
553 htons (sizeof (struct TransportPingMessage) +
554 ve->address->address_length + slen);
555 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
556 ping.challenge = htonl (ve->challenge);
559 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
561 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
563 ("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"),
564 "HELLO", "PING", (unsigned int) tsize);
565 /* message too big (!?), get rid of HELLO */
568 sizeof (struct TransportPingMessage) + ve->address->address_length +
572 char message_buf[tsize];
574 /* build message with structure:
575 * [HELLO][TransportPingMessage][Transport name][Address] */
576 memcpy (message_buf, hello, hsize);
577 memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage));
578 memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
579 ve->address->transport_name, slen);
580 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
581 ve->address->address, ve->address->address_length);
582 papi = GST_plugins_find (ve->address->transport_name);
587 GNUNET_assert (NULL != papi->send);
588 GNUNET_assert (NULL != papi->get_session);
589 struct Session * session = papi->get_session(papi->cls, ve->address);
593 ret = papi->send (papi->cls, session,
595 PING_PRIORITY, ACCEPTABLE_PING_DELAY,
597 network = papi->get_network (papi->cls, session);
598 if (GNUNET_ATS_NET_UNSPECIFIED == network)
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "Could not obtain a valid network for `%s' `%s'\n",
603 GST_plugins_a2s (ve->address));
606 GST_neighbours_notify_data_sent (pid, ve->address, session, tsize);
610 /* Could not get a valid session */
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
612 "Could not get a valid session for `%s' `%s'\n",
614 GST_plugins_a2s (ve->address));
621 ve->send_time = GNUNET_TIME_absolute_get ();
622 GNUNET_STATISTICS_update (GST_stats,
624 ("# PING without HELLO messages sent"), 1,
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 /* Notify about PING sent */
634 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
640 * Do address validation again to keep address valid.
642 * @param cls the 'struct ValidationEntry'
643 * @param tc scheduler context (unused)
646 revalidate_address (void *cls,
647 const struct GNUNET_SCHEDULER_TaskContext *tc)
649 struct ValidationEntry *ve = cls;
650 struct GNUNET_TIME_Relative canonical_delay;
651 struct GNUNET_TIME_Relative delay;
652 struct GNUNET_TIME_Relative blocked_for;
653 struct GST_BlacklistCheck *bc;
656 ve->revalidation_task = GNUNET_SCHEDULER_NO_TASK;
657 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block);
658 /* How long until we can possibly permit the next PING? */
661 GNUNET_YES) ? CONNECTED_PING_FREQUENCY
662 : ((GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us >
663 0) ? VALIDATED_PING_FREQUENCY : UNVALIDATED_PING_KEEPALIVE);
664 if (delay.rel_value_us > canonical_delay.rel_value_us * 2)
666 /* situation changed, recalculate delay */
667 delay = canonical_delay;
668 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
670 if (delay.rel_value_us > 0)
672 /* should wait a bit longer */
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "Waiting for %s longer before validating address `%s'\n",
675 GNUNET_STRINGS_relative_time_to_string (delay,
677 GST_plugins_a2s (ve->address));
678 ve->revalidation_task =
679 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
680 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
683 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next);
684 if ((validations_running > validations_fast_start_threshold) &&
685 (blocked_for.rel_value_us > 0))
687 /* Validations are blocked, have to wait for blocked_for time */
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "Validations blocked for another %s, delaying validating address `%s'\n",
690 GNUNET_STRINGS_relative_time_to_string (blocked_for,
692 GST_plugins_a2s (ve->address));
693 ve->revalidation_task =
694 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
695 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), blocked_for);
698 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay);
700 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
702 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
703 canonical_delay.rel_value_us);
705 /* Debug code for mantis 0002726 */
706 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
707 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, rdelay).rel_value_us)
710 delay = canonical_delay;
714 delay = GNUNET_TIME_relative_add (canonical_delay,
715 GNUNET_TIME_relative_multiply
716 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay));
718 /* End debug code for mantis 0002726*/
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
720 "Validating now, next scheduled for %s, now validating address `%s'\n",
721 GNUNET_STRINGS_relative_time_to_string (blocked_for,
723 GST_plugins_a2s (ve->address));
724 ve->revalidation_task =
725 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
726 ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
728 /* start PINGing by checking blacklist */
729 GNUNET_STATISTICS_update (GST_stats,
730 gettext_noop ("# address revalidations started"), 1,
732 bc = GST_blacklist_test_allowed (&ve->pid, ve->address->transport_name,
733 &transmit_ping_if_allowed, ve);
735 ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already
741 * Find a ValidationEntry entry for the given neighbour that matches
742 * the given address and transport. If none exists, create one (but
743 * without starting any validation).
745 * @param public_key public key of the peer, NULL for unknown
746 * @param address address to find
747 * @return validation entry matching the given specifications, NULL
748 * if we don't have an existing entry and no public key was given
750 static struct ValidationEntry *
751 find_validation_entry (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
752 const struct GNUNET_HELLO_Address *address)
754 struct ValidationEntryMatchContext vemc;
755 struct ValidationEntry *ve;
758 vemc.address = address;
759 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
761 &validation_entry_match, &vemc);
762 if (NULL != (ve = vemc.ve))
764 if (public_key == NULL)
766 ve = GNUNET_new (struct ValidationEntry);
767 ve->in_use = GNUNET_SYSERR; /* not defined */
768 ve->address = GNUNET_HELLO_address_copy (address);
769 ve->public_key = *public_key;
770 ve->pid = address->peer;
771 ve->pong_sig_valid_until = GNUNET_TIME_absolute_get_zero_();
772 memset (&ve->pong_sig_cache, '\0', sizeof (struct GNUNET_CRYPTO_EddsaSignature));
773 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
775 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
777 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE,
778 &timeout_hello_validation, ve);
779 GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer,
781 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
782 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW);
783 ve->expecting_pong = GNUNET_NO;
789 * Iterator which adds the given address to the set of validated
792 * @param cls original HELLO message
793 * @param address the address
794 * @param expiration expiration time
795 * @return #GNUNET_OK (keep the address)
798 add_valid_address (void *cls,
799 const struct GNUNET_HELLO_Address *address,
800 struct GNUNET_TIME_Absolute expiration)
802 const struct GNUNET_HELLO_Message *hello = cls;
803 struct ValidationEntry *ve;
804 struct GNUNET_PeerIdentity pid;
805 struct GNUNET_ATS_Information ats;
806 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
808 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
809 return GNUNET_OK; /* expired */
810 if ((GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) ||
811 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
814 return GNUNET_OK; /* invalid HELLO !? */
816 if (0 == memcmp (&GST_my_identity,
818 sizeof (struct GNUNET_PeerIdentity)))
820 /* Peerinfo returned own identity, skip validation */
824 ve = find_validation_entry (&public_key, address);
825 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
827 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
830 "Starting revalidations for valid address `%s'\n",
831 GST_plugins_a2s (ve->address));
832 ve->next_validation = GNUNET_TIME_absolute_get();
833 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
835 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
837 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
838 ats.value = htonl (ve->network);
839 GNUNET_ATS_address_add (GST_ats, address, NULL, &ats, 1);
846 * Function called for any HELLO known to PEERINFO.
849 * @param peer id of the peer, NULL for last call
850 * @param hello hello message for the peer (can be NULL)
851 * @param err_msg error message
854 process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
855 const struct GNUNET_HELLO_Message *hello,
858 GNUNET_assert (NULL != peer);
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
862 "Handling HELLO for peer `%s'\n",
864 GNUNET_assert (NULL ==
865 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
872 * Start the validation subsystem.
874 * @param max_fds maximum number of fds to use
877 GST_validation_start (unsigned int max_fds)
880 * Initialization for validation throttling
882 * We have a maximum number max_fds of connections we can use for validation
883 * We monitor the number of validations in parallel and start to throttle it
884 * when doing to many validations in parallel:
885 * if (running validations < (max_fds / 2))
886 * - "fast start": run validation immediately
887 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
888 * (300 sec / ~150 == ~2 sec.) between two validations
891 validation_next = GNUNET_TIME_absolute_get();
892 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
893 validations_fast_start_threshold = (max_fds / 2);
894 validations_running = 0;
895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
896 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
897 validations_fast_start_threshold,
898 GNUNET_STRINGS_relative_time_to_string (validation_delay,
900 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
902 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
903 &process_peerinfo_hello, NULL);
908 * Stop the validation subsystem.
911 GST_validation_stop ()
913 struct CheckHelloValidatedContext *chvc;
915 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
916 &cleanup_validation_entry, NULL);
917 GNUNET_CONTAINER_multipeermap_destroy (validation_map);
918 validation_map = NULL;
919 while (NULL != (chvc = chvc_head))
921 GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
924 GNUNET_PEERINFO_notify_cancel (pnc);
929 * Send the given PONG to the given address.
931 * @param cls the PONG message
932 * @param public_key public key for the peer, never NULL
933 * @param valid_until is ZERO if we never validated the address,
934 * otherwise a time up to when we consider it (or was) valid
935 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
936 * is ZERO if the address is considered valid (no validation needed)
937 * otherwise a time in the future if we're currently denying re-validation
938 * @param address target address
941 multicast_pong (void *cls,
942 const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
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 papi->send (papi->cls, session,
965 ntohs (pong->header.size),
967 ACCEPTABLE_PING_DELAY,
969 GST_neighbours_notify_data_sent (&address->peer,
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 alen = 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;
1036 addrend = memchr (addr, '\0', alen);
1037 if (NULL == addrend)
1039 GNUNET_break_op (0);
1040 return GNUNET_SYSERR;
1043 slen = strlen (addr) + 1;
1045 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1046 address.address = addrend;
1047 address.address_length = alen;
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, alen))
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) + alen + slen);
1137 htons (sizeof (struct TransportPongMessage) + alen + slen);
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) +
1143 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1144 memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge));
1145 pong->addrlen = htonl (alen + slen);
1146 memcpy (&pong[1], addr, slen); /* Copy transport plugin */
1149 GNUNET_assert (NULL != addrend);
1150 memcpy (&((char *) &pong[1])[slen], addrend, alen);
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 */
1182 GNUNET_assert (papi->send != NULL);
1183 GNUNET_assert (papi->get_session != NULL);
1185 if (session == NULL)
1187 session = papi->get_session (papi->cls, sender_address);
1189 if (session == NULL)
1196 ret = papi->send (papi->cls, session,
1197 (const char *) pong, ntohs (pong->header.size),
1198 PONG_PRIORITY, ACCEPTABLE_PING_DELAY,
1201 GST_neighbours_notify_data_sent (sender,
1202 sender_address, session,
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "Transmitted PONG to `%s' via reliable mechanism\n",
1210 GNUNET_i2s (sender));
1212 GNUNET_STATISTICS_update (GST_stats,
1214 ("# PONGs unicast via reliable transport"), 1,
1220 /* no reliable method found, try transmission via all known addresses */
1221 GNUNET_STATISTICS_update (GST_stats,
1223 ("# PONGs multicast to all available addresses"), 1,
1225 GST_validation_get_addresses (sender,
1226 &multicast_pong, pong);
1233 * Context for the #validate_address_iterator() function
1235 struct ValidateAddressContext
1238 * Hash of the public key of the peer whose address is being validated.
1240 struct GNUNET_PeerIdentity pid;
1243 * Public key of the peer whose address is being validated.
1245 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
1251 * Iterator callback to go over all addresses and try to validate them
1252 * (unless blocked or already validated).
1254 * @param cls pointer to a `struct ValidateAddressContext *`
1255 * @param address the address
1256 * @param expiration expiration time
1257 * @return #GNUNET_OK (keep the address)
1260 validate_address_iterator (void *cls,
1261 const struct GNUNET_HELLO_Address *address,
1262 struct GNUNET_TIME_Absolute expiration)
1264 const struct ValidateAddressContext *vac = cls;
1265 struct ValidationEntry *ve;
1267 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1270 "Skipping expired address from HELLO\n");
1271 return GNUNET_OK; /* expired */
1273 ve = find_validation_entry (&vac->public_key, address);
1274 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
1276 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1277 "Validation process started for fresh address `%s'\n",
1278 GST_plugins_a2s (ve->address));
1279 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1286 * Add the validated peer address to the HELLO.
1288 * @param cls the `struct ValidationEntry *` with the validated address
1289 * @param max space in @a buf
1290 * @param buf where to add the address
1291 * @return number of bytes written, #GNUNET_SYSERR to signal the
1292 * end of the iteration.
1295 add_valid_peer_address (void *cls,
1299 struct ValidationEntry *ve = cls;
1301 if (GNUNET_YES == ve->copied)
1302 return GNUNET_SYSERR; /* Done */
1303 ve->copied = GNUNET_YES;
1304 return GNUNET_HELLO_add_address (ve->address, ve->valid_until, buf, max);
1309 * We've received a PONG. Check if it matches a pending PING and
1310 * mark the respective address as confirmed.
1312 * @param sender peer sending the PONG
1313 * @param hdr the PONG
1314 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1317 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1318 const struct GNUNET_MessageHeader *hdr)
1320 const struct TransportPongMessage *pong;
1321 struct ValidationEntry *ve;
1327 struct GNUNET_HELLO_Message *hello;
1328 struct GNUNET_HELLO_Address address;
1332 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
1334 GNUNET_break_op (0);
1335 return GNUNET_SYSERR;
1337 GNUNET_STATISTICS_update (GST_stats,
1338 gettext_noop ("# PONG messages received"), 1,
1341 /* message with structure:
1342 * [TransportPongMessage][Transport name][Address] */
1344 pong = (const struct TransportPongMessage *) hdr;
1345 tname = (const char *) &pong[1];
1346 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1347 addr = memchr (tname, '\0', size);
1350 GNUNET_break_op (0);
1351 return GNUNET_SYSERR;
1354 slen = strlen (tname) + 1;
1355 addrlen = size - slen;
1356 address.peer = *sender;
1357 address.address = addr;
1358 address.address_length = addrlen;
1359 address.transport_name = tname;
1360 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1361 ve = find_validation_entry (NULL, &address);
1362 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1364 GNUNET_STATISTICS_update (GST_stats,
1366 ("# PONGs dropped, no matching pending validation"),
1370 /* now check that PONG is well-formed */
1371 if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity)))
1373 GNUNET_break_op (0);
1374 return GNUNET_SYSERR;
1376 if (GNUNET_TIME_absolute_get_remaining
1377 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us == 0)
1379 GNUNET_STATISTICS_update (GST_stats,
1381 ("# PONGs dropped, signature expired"), 1,
1383 return GNUNET_SYSERR;
1386 sig_res = GNUNET_SYSERR;
1387 do_verify = GNUNET_YES;
1388 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
1390 /* We have a cached and valid signature for this peer,
1391 * try to compare instead of verify */
1392 if (0 == memcmp (&ve->pong_sig_cache, &pong->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1394 /* signatures are identical, we can skip verification */
1395 sig_res = GNUNET_OK;
1396 do_verify = GNUNET_NO;
1400 sig_res = GNUNET_SYSERR;
1401 /* signatures do not match, we have to verify */
1405 if (GNUNET_YES == do_verify)
1407 /* Do expensive verification */
1408 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1409 &pong->purpose, &pong->signature,
1411 if (sig_res == GNUNET_SYSERR)
1413 GNUNET_break_op (0);
1414 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1415 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n",
1417 GST_plugins_a2s (ve->address),
1418 GNUNET_i2s (sender));
1421 if (sig_res == GNUNET_SYSERR)
1423 GNUNET_break_op (0);
1424 return GNUNET_SYSERR;
1427 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1428 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1429 GNUNET_i2s (sender),
1431 GST_plugins_a2s (ve->address));
1432 /* validity achieved, remember it! */
1433 ve->expecting_pong = GNUNET_NO;
1434 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1435 ve->pong_sig_cache = pong->signature;
1436 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
1437 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
1439 struct GNUNET_ATS_Information ats[2];
1441 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
1442 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
1443 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1444 ats[1].value = htonl ((uint32_t) ve->network);
1445 GNUNET_ATS_address_add (GST_ats, ve->address, NULL, ats, 2);
1447 if (validations_running > 0)
1449 validations_running --;
1450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1451 "Validation finished, %u validation processes running\n",
1452 validations_running);
1459 /* Notify about new validity */
1460 validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE);
1462 /* build HELLO to store in PEERINFO */
1463 ve->copied = GNUNET_NO;
1464 hello = GNUNET_HELLO_create (&ve->public_key,
1465 &add_valid_peer_address, ve,
1467 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1468 GNUNET_free (hello);
1474 * We've received a HELLO, check which addresses are new and trigger
1477 * @param hello the HELLO we received
1478 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1481 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1483 const struct GNUNET_HELLO_Message *hm =
1484 (const struct GNUNET_HELLO_Message *) hello;
1485 struct ValidateAddressContext vac;
1486 struct GNUNET_HELLO_Message *h;
1489 friend = GNUNET_HELLO_is_friend_only (hm);
1490 if ( ( (GNUNET_YES != friend) &&
1491 (GNUNET_NO != friend) ) ||
1492 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1493 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
1495 /* malformed HELLO */
1496 GNUNET_break_op (0);
1497 return GNUNET_SYSERR;
1500 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
1502 /* Add peer identity without addresses to peerinfo service */
1503 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL, friend);
1504 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1505 _("Validation received new %s message for peer `%s' with size %u\n"),
1507 GNUNET_i2s (&vac.pid),
1508 ntohs (hello->size));
1509 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
1511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1512 _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",
1513 GNUNET_i2s (&vac.pid));
1516 GNUNET_assert (NULL ==
1517 GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO,
1518 &validate_address_iterator,
1525 * Closure for #iterate_addresses().
1527 struct IteratorContext
1530 * Function to call on each address.
1532 GST_ValidationAddressCallback cb;
1535 * Closure for @e cb.
1543 * Call the callback in the closure for each validation entry.
1545 * @param cls the `struct IteratorContext`
1546 * @param key the peer's identity
1547 * @param value the `struct ValidationEntry`
1548 * @return #GNUNET_OK (continue to iterate)
1551 iterate_addresses (void *cls,
1552 const struct GNUNET_PeerIdentity *key,
1555 struct IteratorContext *ic = cls;
1556 struct ValidationEntry *ve = value;
1558 ic->cb (ic->cb_cls, &ve->public_key, ve->valid_until, ve->revalidation_block,
1565 * Call the given function for each address for the given target.
1566 * Can either give a snapshot (synchronous API) or be continuous.
1568 * @param target peer information is requested for
1569 * @param cb function to call; will not be called after this function returns
1570 * @param cb_cls closure for @a cb
1573 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1574 GST_ValidationAddressCallback cb, void *cb_cls)
1576 struct IteratorContext ic;
1580 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
1582 &iterate_addresses, &ic);
1587 * Update if we are using an address for a connection actively right now.
1588 * Based on this, the validation module will measure latency for the
1589 * address more or less often.
1591 * @param address the address
1592 * @param session the session
1593 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1594 * #GNUNET_NO if we are no longer using the address for a connection
1597 GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address,
1598 struct Session *session,
1601 struct ValidationEntry *ve;
1603 if (NULL != address)
1604 ve = find_validation_entry (NULL, address);
1606 ve = NULL; /* FIXME: lookup based on session... */
1609 /* this can happen for inbound connections (sender_address_len == 0); */
1612 if (ve->in_use == in_use)
1615 if (GNUNET_YES == in_use)
1617 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1618 "Error setting address in use for peer `%s' `%s' to USED\n",
1619 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1621 if (GNUNET_NO == in_use)
1623 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1624 "Error setting address in use for peer `%s' `%s' to NOT_USED\n",
1625 GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
1629 GNUNET_break (ve->in_use != in_use); /* should be different... */
1630 ve->in_use = in_use;
1631 if (in_use == GNUNET_YES)
1633 /* from now on, higher frequeny, so reschedule now */
1634 GNUNET_SCHEDULER_cancel (ve->revalidation_task);
1635 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1641 * Query validation about the latest observed latency on a given
1644 * @param sender peer
1645 * @param address the address
1646 * @param session session
1647 * @return observed latency of the address, FOREVER if the address was
1648 * never successfully validated
1650 struct GNUNET_TIME_Relative
1651 GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
1652 const struct GNUNET_HELLO_Address *address,
1653 struct Session *session)
1655 struct ValidationEntry *ve;
1657 if (NULL == address)
1659 GNUNET_break (0); // FIXME: support having latency only with session...
1660 return GNUNET_TIME_UNIT_FOREVER_REL;
1662 ve = find_validation_entry (NULL, address);
1664 return GNUNET_TIME_UNIT_FOREVER_REL;
1669 * Closure for the validation_entries_iterate function.
1671 struct ValidationIteratorContext
1674 * Function to call on each validation entry
1676 GST_ValidationChangedCallback cb;
1679 * Closure for @e cb.
1686 validation_entries_iterate (void *cls,
1687 const struct GNUNET_PeerIdentity *key,
1690 struct ValidationIteratorContext *ic = cls;
1691 struct ValidationEntry *ve = value;
1693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Notifying about validation entry for peer `%s' address `%s' \n",
1694 GNUNET_i2s (&ve->pid), GST_plugins_a2s (ve->address));
1695 ic->cb (ic->cb_cls, &ve->pid, ve->address, ve->send_time,
1696 ve->valid_until, ve->next_validation, ve->state);
1702 * Iterate over all iteration entries
1704 * @param cb function to call
1705 * @param cb_cls closure for cb
1708 GST_validation_iterate (GST_ValidationChangedCallback cb,
1711 struct ValidationIteratorContext ic;
1713 if (NULL == validation_map)
1714 return; /* can happen during shutdown */
1717 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1718 &validation_entries_iterate,
1722 /* end of file gnunet-service-transport_validation.c */