2 This file is part of GNUnet.
3 (C) 2010,2011 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_validation.h"
28 #include "gnunet-service-transport_plugins.h"
29 #include "gnunet-service-transport_hello.h"
30 #include "gnunet-service-transport.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_ats_service.h"
33 #include "gnunet_peerinfo_service.h"
34 #include "gnunet_signatures.h"
36 // TODO: observe latency between PING/PONG and give information to ATS!
39 * How long is a PONG signature valid? We'll recycle a signature until
40 * 1/4 of this time is remaining. PONGs should expire so that if our
41 * external addresses change an adversary cannot replay them indefinitely.
42 * OTOH, we don't want to spend too much time generating PONG signatures,
43 * so they must have some lifetime to reduce our CPU usage.
45 #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
48 * After how long do we expire an address in a HELLO that we just
49 * validated? This value is also used for our own addresses when we
52 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
55 * How long before an existing address expires should we again try to
56 * validate it? Must be (significantly) smaller than
57 * HELLO_ADDRESS_EXPIRATION.
59 #define HELLO_REVALIDATION_START_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
62 * Size of the validation map hashmap.
64 #define VALIDATION_MAP_SIZE 256
67 * Priority to use for PINGs
69 #define PING_PRIORITY 2
72 * Priority to use for PONGs
74 #define PONG_PRIORITY 4
78 * Message used to ask a peer to validate receipt (to check an address
79 * from a HELLO). Followed by the address we are trying to validate,
80 * or an empty address if we are just sending a PING to confirm that a
81 * connection which the receiver (of the PING) initiated is still valid.
83 struct TransportPingMessage
87 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PING
89 struct GNUNET_MessageHeader header;
92 * Challenge code (to ensure fresh reply).
94 uint32_t challenge GNUNET_PACKED;
97 * Who is the intended recipient?
99 struct GNUNET_PeerIdentity target;
105 * Message used to validate a HELLO. The challenge is included in the
106 * confirmation to make matching of replies to requests possible. The
107 * signature signs our public key, an expiration time and our address.<p>
109 * This message is followed by our transport address that the PING tried
110 * to confirm (if we liked it). The address can be empty (zero bytes)
111 * if the PING had not address either (and we received the request via
112 * a connection that we initiated).
114 struct TransportPongMessage
118 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
120 struct GNUNET_MessageHeader header;
123 * Challenge code from PING (showing freshness). Not part of what
124 * is signed so that we can re-use signatures.
126 uint32_t challenge GNUNET_PACKED;
131 struct GNUNET_CRYPTO_RsaSignature signature;
134 * What are we signing and why? Two possible reason codes can be here:
135 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
136 * plausible address for this peer (pid is set to identity of signer); or
137 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING to confirm that this is
138 * an address we used to connect to the peer with the given pid.
140 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
143 * When does this signature expire?
145 struct GNUNET_TIME_AbsoluteNBO expiration;
148 * Either the identity of the peer Who signed this message, or the
149 * identity of the peer that we're connected to using the given
150 * address (depending on purpose.type).
152 struct GNUNET_PeerIdentity pid;
155 * Size of address appended to this message (part of what is
156 * being signed, hence not redundant).
158 uint32_t addrlen GNUNET_PACKED;
164 * Information about an address under validation
166 struct ValidationEntry
170 * Name of the transport.
172 char *transport_name;
175 * The address, actually a pointer to the end
176 * of this struct. Do not free!
181 * Public key of the peer.
183 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
186 * The identity of the peer.
188 struct GNUNET_PeerIdentity pid;
191 * ID of task that will clean up this entry if nothing happens.
193 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
196 * At what time did we send the latest validation request?
198 struct GNUNET_TIME_Absolute send_time;
201 * Until when is this address valid?
202 * ZERO if it is not currently considered valid.
204 struct GNUNET_TIME_Absolute valid_until;
207 * How long until we can try to validate this address again?
208 * FOREVER if the address is for an unsupported plugin (from PEERINFO)
209 * ZERO if the address is considered valid (no validation needed)
210 * otherwise a time in the future if we're currently denying re-validation
212 struct GNUNET_TIME_Absolute validation_block;
215 * Challenge number we used.
228 * Context of currently active requests to peerinfo
229 * for validation of HELLOs.
231 struct CheckHelloValidatedContext
235 * This is a doubly-linked list.
237 struct CheckHelloValidatedContext *next;
240 * This is a doubly-linked list.
242 struct CheckHelloValidatedContext *prev;
245 * Hello that we are validating.
247 const struct GNUNET_HELLO_Message *hello;
253 * Head of linked list of HELLOs awaiting validation.
255 static struct CheckHelloValidatedContext *chvc_head;
258 * Tail of linked list of HELLOs awaiting validation
260 static struct CheckHelloValidatedContext *chvc_tail;
263 * Map of PeerIdentities to 'struct ValidationEntry*'s (addresses
264 * of the given peer that we are currently validating, have validated
265 * or are blocked from re-validation for a while).
267 static struct GNUNET_CONTAINER_MultiHashMap *validation_map;
270 * Context for peerinfo iteration.
272 static struct GNUNET_PEERINFO_NotifyContext *pnc;
276 * Context for the validation entry match function.
278 struct ValidationEntryMatchContext
281 * Where to store the result?
283 struct ValidationEntry *ve;
286 * Transport name we're looking for.
288 const char *transport_name;
291 * Address we're interested in.
296 * Number of bytes in 'addr'.
303 * Iterate over validation entries until a matching one is found.
305 * @param cls the 'struct ValidationEntryMatchContext'
306 * @param key peer identity (unused)
307 * @param value a 'struct ValidationEntry' to match
308 * @return GNUNET_YES if the entry does not match,
309 * GNUNET_NO if the entry does match
312 validation_entry_match (void *cls,
313 const GNUNET_HashCode *key,
316 struct ValidationEntryMatchContext *vemc = cls;
317 struct ValidationEntry *ve = value;
319 if ( (ve->addrlen == vemc->addrlen) &&
320 (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) &&
321 (0 == strcmp (ve->transport_name, vemc->transport_name)) )
331 * Find a ValidationEntry entry for the given neighbour that matches
332 * the given address and transport. If none exists, create one (but
333 * without starting any validation).
335 * @param public_key public key of the peer, NULL for unknown
336 * @param neighbour which peer we care about
337 * @param tname name of the transport plugin
338 * @param session session to look for, NULL for 'any'; otherwise
339 * can be used for the service to "learn" this session ID
341 * @param addr binary address
342 * @param addrlen length of addr
343 * @return validation entry matching the given specifications, NULL
344 * if we don't have an existing entry and no public key was given
346 static struct ValidationEntry *
347 find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
348 const struct GNUNET_PeerIdentity *neighbour,
353 struct ValidationEntryMatchContext vemc;
354 struct ValidationEntry *ve;
357 vemc.transport_name = tname;
359 vemc.addrlen = addrlen;
360 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
361 &neighbour->hashPubKey,
362 &validation_entry_match,
364 if (NULL != (ve = vemc.ve))
366 if (public_key == NULL)
368 ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
369 ve->transport_name = GNUNET_strdup (tname);
370 ve->addr = (void*) &ve[1];
371 ve->public_key = *public_key;
372 ve->pid = *neighbour;
373 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
375 memcpy (&ve[1], addr, addrlen);
376 ve->addrlen = addrlen;
377 GNUNET_CONTAINER_multihashmap_put (validation_map,
378 &neighbour->hashPubKey,
380 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
386 * Iterator which adds the given address to the set of validated
389 * @param cls original HELLO message
390 * @param tname name of the transport
391 * @param expiration expiration time
392 * @param addr the address
393 * @param addrlen length of the address
394 * @return GNUNET_OK (keep the address)
397 add_valid_address (void *cls,
399 struct GNUNET_TIME_Absolute expiration,
403 const struct GNUNET_HELLO_Message *hello = cls;
404 struct ValidationEntry *ve;
405 struct GNUNET_PeerIdentity pid;
406 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
408 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
409 return GNUNET_OK; /* expired */
411 GNUNET_HELLO_get_id (hello, &pid)) ||
413 GNUNET_HELLO_get_key (hello, &public_key)) )
416 return GNUNET_OK; /* invalid HELLO !? */
418 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
419 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
421 GNUNET_ATS_address_update (GST_ats,
435 * Function called for any HELLO known to PEERINFO.
438 * @param peer id of the peer, NULL for last call
439 * @param hello hello message for the peer (can be NULL)
440 * @param error message
443 process_peerinfo_hello (void *cls,
444 const struct GNUNET_PeerIdentity *peer,
445 const struct GNUNET_HELLO_Message *hello,
448 GNUNET_assert (NULL != peer);
451 GNUNET_assert (NULL ==
452 GNUNET_HELLO_iterate_addresses (hello,
460 * Start the validation subsystem.
463 GST_validation_start ()
465 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
466 pnc = GNUNET_PEERINFO_notify (GST_cfg,
467 &process_peerinfo_hello,
473 * Iterate over validation entries and free them.
475 * @param cls (unused)
476 * @param key peer identity (unused)
477 * @param value a 'struct ValidationEntry' to clean up
478 * @return GNUNET_YES (continue to iterate)
481 cleanup_validation_entry (void *cls,
482 const GNUNET_HashCode *key,
485 struct ValidationEntry *ve = value;
487 GNUNET_free (ve->transport_name);
488 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
490 GNUNET_SCHEDULER_cancel (ve->timeout_task);
491 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
499 * Stop the validation subsystem.
502 GST_validation_stop ()
504 struct CheckHelloValidatedContext *chvc;
506 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
507 &cleanup_validation_entry,
509 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
510 validation_map = NULL;
511 while (NULL != (chvc = chvc_head))
513 GNUNET_CONTAINER_DLL_remove (chvc_head,
518 GNUNET_PEERINFO_notify_cancel (pnc);
523 * Address validation cleanup task (record no longer needed).
525 * @param cls the 'struct ValidationEntry'
526 * @param tc scheduler context (unused)
529 timeout_hello_validation (void *cls,
530 const struct GNUNET_SCHEDULER_TaskContext *tc)
532 struct ValidationEntry *va = cls;
534 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
535 GNUNET_STATISTICS_update (GST_stats,
536 gettext_noop ("# address records discarded"),
539 GNUNET_break (GNUNET_OK ==
540 GNUNET_CONTAINER_multihashmap_remove (validation_map,
543 GNUNET_free (va->transport_name);
549 * Send the given PONG to the given address.
551 * @param cls the PONG message
552 * @param public_key public key for the peer, never NULL
553 * @param target peer this change is about, never NULL
554 * @param valid_until is ZERO if we never validated the address,
555 * otherwise a time up to when we consider it (or was) valid
556 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
557 * is ZERO if the address is considered valid (no validation needed)
558 * otherwise a time in the future if we're currently denying re-validation
559 * @param plugin_name name of the plugin
560 * @param plugin_address binary address
561 * @param plugin_address_len length of address
564 multicast_pong (void *cls,
565 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
566 const struct GNUNET_PeerIdentity *target,
567 struct GNUNET_TIME_Absolute valid_until,
568 struct GNUNET_TIME_Absolute validation_block,
569 const char *plugin_name,
570 const void *plugin_address,
571 size_t plugin_address_len)
573 struct TransportPongMessage *pong = cls;
574 struct GNUNET_TRANSPORT_PluginFunctions *papi;
576 papi = GST_plugins_find (plugin_name);
579 (void) papi->send (papi->cls,
582 ntohs (pong->header.size),
584 HELLO_REVALIDATION_START_TIME,
594 * We've received a PING. If appropriate, generate a PONG.
596 * @param sender peer sending the PING
597 * @param hdr the PING
598 * @param session session we got the PING from
599 * @param plugin_name name of plugin that received the PING
600 * @param sender_address address of the sender as known to the plugin, NULL
601 * if we did not initiate the connection
602 * @param sender_address_len number of bytes in sender_address
605 GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
606 const struct GNUNET_MessageHeader *hdr,
607 const char *plugin_name,
608 struct Session *session,
609 const void *sender_address,
610 size_t sender_address_len)
613 const struct TransportPingMessage *ping;
614 struct TransportPongMessage *pong;
615 struct GNUNET_TRANSPORT_PluginFunctions *papi;
616 struct GNUNET_CRYPTO_RsaSignature *sig_cache;
617 struct GNUNET_TIME_Absolute *sig_cache_exp;
624 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
629 ping = (const struct TransportPingMessage *) hdr;
630 if (0 != memcmp (&ping->target,
632 sizeof (struct GNUNET_PeerIdentity)))
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
639 "Processing `%s' from `%s'\n",
641 (sender_address != NULL)
642 ? GST_plugin_a2s (plugin_name,
647 GNUNET_STATISTICS_update (GST_stats,
648 gettext_noop ("# PING messages received"),
651 addr = (const char*) &ping[1];
652 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
653 /* peer wants to confirm that this is one of our addresses, this is what is
654 used for address validation */
656 addrend = memchr (addr, '\0', alen);
667 GST_hello_test_address (addr,
673 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
674 _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
675 GST_plugins_a2s (addr,
681 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
682 pong->header.size = htons (sizeof (struct TransportPongMessage) + alen + slen);
683 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
685 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
687 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
688 sizeof (struct GNUNET_PeerIdentity) + alen + slen);
689 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
690 pong->challenge = ping->challenge;
691 pong->addrlen = htonl(alen + slen);
692 pong->pid = GST_my_identity;
693 memcpy (&pong[1], addr, slen);
694 memcpy (&((char*)&pong[1])[slen], addrend, alen);
695 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
697 /* create / update cached sig */
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Creating PONG signature to indicate ownership.\n");
702 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
703 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
704 GNUNET_assert (GNUNET_OK ==
705 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
711 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
713 pong->signature = *sig_cache;
715 /* first see if the session we got this PING from can be used to transmit
716 a response reliably */
717 papi = GST_plugins_find (plugin_name);
721 ret = papi->send (papi->cls,
724 ntohs (pong->header.size),
726 HELLO_REVALIDATION_START_TIME,
734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
735 "Transmitted PONG to `%s' via reliable mechanism\n",
736 GNUNET_i2s (sender));
738 GNUNET_STATISTICS_update (GST_stats,
739 gettext_noop ("# PONGs unicast via reliable transport"),
746 /* no reliable method found, try transmission via all known addresses */
747 GNUNET_STATISTICS_update (GST_stats,
748 gettext_noop ("# PONGs multicast to all available addresses"),
751 GST_validation_get_addresses (sender,
759 * Context for the 'validate_address' function
761 struct ValidateAddressContext
764 * Hash of the public key of the peer whose address is being validated.
766 struct GNUNET_PeerIdentity pid;
769 * Public key of the peer whose address is being validated.
771 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
776 * Iterator callback to go over all addresses and try to validate them
777 * (unless blocked or already validated).
779 * @param cls pointer to a 'struct ValidateAddressContext'
780 * @param tname name of the transport
781 * @param expiration expiration time
782 * @param addr the address
783 * @param addrlen length of the address
784 * @return GNUNET_OK (keep the address)
787 validate_address (void *cls,
789 struct GNUNET_TIME_Absolute expiration,
793 const struct ValidateAddressContext *vac = cls;
794 const struct GNUNET_PeerIdentity *pid = &vac->pid;
795 struct ValidationEntry *ve;
796 struct TransportPingMessage ping;
797 struct GNUNET_TRANSPORT_PluginFunctions *papi;
798 const struct GNUNET_MessageHeader *hello;
804 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
805 return GNUNET_OK; /* expired */
806 ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen);
807 if (GNUNET_TIME_absolute_get_remaining (ve->validation_block).rel_value > 0)
808 return GNUNET_OK; /* blocked */
809 if ( (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) &&
810 (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0) )
811 return GNUNET_OK; /* revalidation task already scheduled & still valid */
812 ve->validation_block = GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME);
813 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
814 GNUNET_SCHEDULER_cancel (ve->timeout_task);
815 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_REVALIDATION_START_TIME,
816 &timeout_hello_validation,
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
819 "Transmitting plain PING to `%s'\n",
821 ping.header.size = htons(sizeof(struct TransportPingMessage));
822 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
823 ping.challenge = htonl(ve->challenge);
826 slen = strlen(ve->transport_name) + 1;
827 hello = GST_hello_get ();
828 hsize = ntohs (hello->size);
829 tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize;
830 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
832 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
833 _("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"),
836 (unsigned int) tsize);
837 /* message too big (!?), get rid of HELLO */
839 tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize;
842 char message_buf[tsize];
844 memcpy(message_buf, hello, hsize);
845 memcpy(&message_buf[hsize], &ping, sizeof (struct TransportPingMessage));
846 memcpy(&message_buf[sizeof (struct TransportPingMessage) + hsize],
849 memcpy(&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
852 papi = GST_plugins_find (ve->transport_name);
856 ret = papi->send (papi->cls,
861 HELLO_REVALIDATION_START_TIME,
862 NULL /* no session */,
870 ve->send_time = GNUNET_TIME_absolute_get ();
871 GNUNET_STATISTICS_update (GST_stats,
872 gettext_noop ("# PING without HELLO messages sent"),
881 * Do address validation again to keep address valid.
883 * @param cls the 'struct ValidationEntry'
884 * @param tc scheduler context (unused)
887 revalidate_address (void *cls,
888 const struct GNUNET_SCHEDULER_TaskContext *tc)
890 struct ValidationEntry *ve = cls;
891 struct GNUNET_TIME_Relative delay;
892 struct ValidateAddressContext vac;
894 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
895 delay = GNUNET_TIME_absolute_get_remaining (ve->validation_block);
896 if (delay.rel_value > 0)
898 /* should wait a bit longer */
899 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
904 GNUNET_STATISTICS_update (GST_stats,
905 gettext_noop ("# address revalidations started"),
909 vac.public_key = ve->public_key;
910 validate_address (&vac,
914 (uint16_t) ve->addrlen);
919 * Add the validated peer address to the HELLO.
921 * @param cls the 'struct ValidationEntry' with the validated address
922 * @param max space in buf
923 * @param buf where to add the address
926 add_valid_peer_address (void *cls,
930 struct ValidationEntry *ve = cls;
932 return GNUNET_HELLO_add_address (ve->transport_name,
942 * We've received a PONG. Check if it matches a pending PING and
943 * mark the respective address as confirmed.
945 * @param sender peer sending the PONG
946 * @param hdr the PONG
947 * @param plugin_name name of plugin that received the PONG
948 * @param sender_address address of the sender as known to the plugin, NULL
949 * if we did not initiate the connection
950 * @param sender_address_len number of bytes in sender_address
953 GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
954 const struct GNUNET_MessageHeader *hdr,
955 const char *plugin_name,
956 const void *sender_address,
957 size_t sender_address_len)
959 const struct TransportPongMessage *pong;
960 struct ValidationEntry *ve;
966 struct GNUNET_TIME_Relative delay;
967 struct GNUNET_HELLO_Message *hello;
969 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
974 GNUNET_STATISTICS_update (GST_stats,
975 gettext_noop ("# PONG messages received"),
978 pong = (const struct TransportPongMessage *) hdr;
979 if (0 != memcmp (&pong->pid,
981 sizeof (struct GNUNET_PeerIdentity)))
987 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
988 "Processing `%s' from `%s'\n",
990 (sender_address != NULL)
991 ? GST_plugin_a2s (plugin_name,
996 addr = (const char*) &pong[1];
997 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
998 addrend = memchr (addr, '\0', alen);
1001 GNUNET_break_op (0);
1005 slen = strlen(addr);
1007 ve = find_validation_entry (NULL,
1014 GNUNET_STATISTICS_update (GST_stats,
1015 gettext_noop ("# PONGs dropped, no matching pending validation"),
1020 /* now check that PONG is well-formed */
1021 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
1023 GNUNET_STATISTICS_update (GST_stats,
1024 gettext_noop ("# PONGs dropped, signature expired"),
1030 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1035 GNUNET_break_op (0);
1039 /* validity achieved, remember it! */
1040 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1041 GNUNET_ATS_address_update (GST_ats,
1049 NULL, 0); /* FIXME: compute and add latency here... */
1051 /* build HELLO to store in PEERINFO */
1052 hello = GNUNET_HELLO_create (&ve->public_key,
1053 &add_valid_peer_address,
1055 GNUNET_PEERINFO_add_peer (GST_peerinfo,
1057 GNUNET_free (hello);
1059 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
1060 GNUNET_SCHEDULER_cancel (ve->timeout_task);
1062 /* randomly delay by up to 1h to avoid synchronous validations */
1063 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1065 delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME,
1066 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1068 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
1069 &revalidate_address,
1075 * We've received a HELLO, check which addresses are new and trigger
1078 * @param hello the HELLO we received
1081 GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1083 const struct GNUNET_HELLO_Message* hm = (const struct GNUNET_HELLO_Message*) hello;
1084 struct ValidateAddressContext vac;
1087 GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1089 GNUNET_HELLO_get_key (hm, &vac.public_key)) )
1091 /* malformed HELLO */
1095 GNUNET_assert (NULL ==
1096 GNUNET_HELLO_iterate_addresses (hm,
1104 * Closure for 'iterate_addresses'
1106 struct IteratorContext
1109 * Function to call on each address.
1111 GST_ValidationAddressCallback cb;
1122 * Call the callback in the closure for each validation entry.
1124 * @param cls the 'struct GST_ValidationIteratorContext'
1125 * @param key the peer's identity
1126 * @param value the 'struct ValidationEntry'
1127 * @return GNUNET_OK (continue to iterate)
1130 iterate_addresses (void *cls,
1131 const GNUNET_HashCode *key,
1134 struct IteratorContext *ic = cls;
1135 struct ValidationEntry *ve = value;
1141 ve->validation_block,
1150 * Call the given function for each address for the given target.
1151 * Can either give a snapshot (synchronous API) or be continuous.
1153 * @param target peer information is requested for
1154 * @param snapshot_only GNUNET_YES to iterate over addresses once, GNUNET_NO to
1155 * continue to give information about addresses as it evolves
1156 * @param cb function to call; will not be called after this function returns
1157 * if snapshot_only is GNUNET_YES
1158 * @param cb_cls closure for 'cb'
1159 * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES
1162 GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1163 GST_ValidationAddressCallback cb,
1166 struct IteratorContext ic;
1170 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
1171 &target->hashPubKey,
1177 /* end of file gnunet-service-transport_validation.c */