diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
commit | a983a0267109b1b6a8e16e476e2f2956a8771b94 (patch) | |
tree | 79bcae73cdb7b87b4f55d4396e79baea76ef53a6 /src/transport/gnunet-service-transport_validation.c | |
parent | a3f8ef5b89dc44fc3acfb8f081a502f3409e4224 (diff) | |
download | gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.tar.gz gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.zip |
refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 203 |
1 files changed, 82 insertions, 121 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index afc35a3a6..9b93c7508 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -175,15 +175,9 @@ struct ValidationEntry | |||
175 | { | 175 | { |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Name of the transport. | 178 | * The address. |
179 | */ | 179 | */ |
180 | char *transport_name; | 180 | struct GNUNET_HELLO_Address *address; |
181 | |||
182 | /** | ||
183 | * The address, actually a pointer to the end | ||
184 | * of this struct. Do not free! | ||
185 | */ | ||
186 | const void *addr; | ||
187 | 181 | ||
188 | /** | 182 | /** |
189 | * Handle to the blacklist check (if we're currently in it). | 183 | * Handle to the blacklist check (if we're currently in it). |
@@ -196,7 +190,7 @@ struct ValidationEntry | |||
196 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | 190 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; |
197 | 191 | ||
198 | /** | 192 | /** |
199 | * The identity of the peer. | 193 | * The identity of the peer. FIXME: duplicated (also in 'address') |
200 | */ | 194 | */ |
201 | struct GNUNET_PeerIdentity pid; | 195 | struct GNUNET_PeerIdentity pid; |
202 | 196 | ||
@@ -241,11 +235,6 @@ struct ValidationEntry | |||
241 | uint32_t challenge; | 235 | uint32_t challenge; |
242 | 236 | ||
243 | /** | 237 | /** |
244 | * Length of addr. | ||
245 | */ | ||
246 | size_t addrlen; | ||
247 | |||
248 | /** | ||
249 | * When passing the address in 'add_valid_peer_address', did we | 238 | * When passing the address in 'add_valid_peer_address', did we |
250 | * copy the address to the HELLO yet? | 239 | * copy the address to the HELLO yet? |
251 | */ | 240 | */ |
@@ -318,19 +307,10 @@ struct ValidationEntryMatchContext | |||
318 | struct ValidationEntry *ve; | 307 | struct ValidationEntry *ve; |
319 | 308 | ||
320 | /** | 309 | /** |
321 | * Transport name we're looking for. | ||
322 | */ | ||
323 | const char *transport_name; | ||
324 | |||
325 | /** | ||
326 | * Address we're interested in. | 310 | * Address we're interested in. |
327 | */ | 311 | */ |
328 | const char *addr; | 312 | const struct GNUNET_HELLO_Address *address; |
329 | 313 | ||
330 | /** | ||
331 | * Number of bytes in 'addr'. | ||
332 | */ | ||
333 | size_t addrlen; | ||
334 | }; | 314 | }; |
335 | 315 | ||
336 | 316 | ||
@@ -349,9 +329,9 @@ validation_entry_match (void *cls, const GNUNET_HashCode * key, void *value) | |||
349 | struct ValidationEntryMatchContext *vemc = cls; | 329 | struct ValidationEntryMatchContext *vemc = cls; |
350 | struct ValidationEntry *ve = value; | 330 | struct ValidationEntry *ve = value; |
351 | 331 | ||
352 | if ((ve->addrlen == vemc->addrlen) && | 332 | if (0 == |
353 | (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) && | 333 | GNUNET_HELLO_address_cmp (ve->address, |
354 | (0 == strcmp (ve->transport_name, vemc->transport_name))) | 334 | vemc->address)) |
355 | { | 335 | { |
356 | vemc->ve = ve; | 336 | vemc->ve = ve; |
357 | return GNUNET_NO; | 337 | return GNUNET_NO; |
@@ -381,7 +361,7 @@ cleanup_validation_entry (void *cls, const GNUNET_HashCode * key, void *value) | |||
381 | GNUNET_break (GNUNET_OK == | 361 | GNUNET_break (GNUNET_OK == |
382 | GNUNET_CONTAINER_multihashmap_remove (validation_map, | 362 | GNUNET_CONTAINER_multihashmap_remove (validation_map, |
383 | &ve->pid.hashPubKey, ve)); | 363 | &ve->pid.hashPubKey, ve)); |
384 | GNUNET_free (ve->transport_name); | 364 | GNUNET_HELLO_address_free (ve->address); |
385 | if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) | 365 | if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) |
386 | { | 366 | { |
387 | GNUNET_SCHEDULER_cancel (ve->timeout_task); | 367 | GNUNET_SCHEDULER_cancel (ve->timeout_task); |
@@ -454,16 +434,15 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, | |||
454 | 434 | ||
455 | ve->bc = NULL; | 435 | ve->bc = NULL; |
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n", | 436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n", |
457 | GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, | 437 | GNUNET_i2s (pid), GST_plugins_a2s (ve->address)); |
458 | ve->addrlen)); | ||
459 | 438 | ||
460 | slen = strlen (ve->transport_name) + 1; | 439 | slen = strlen (ve->address->transport_name) + 1; |
461 | hello = GST_hello_get (); | 440 | hello = GST_hello_get (); |
462 | hsize = ntohs (hello->size); | 441 | hsize = ntohs (hello->size); |
463 | tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize; | 442 | tsize = sizeof (struct TransportPingMessage) + ve->address->address_length + slen + hsize; |
464 | 443 | ||
465 | ping.header.size = | 444 | ping.header.size = |
466 | htons (sizeof (struct TransportPingMessage) + ve->addrlen + slen); | 445 | htons (sizeof (struct TransportPingMessage) + ve->address->address_length + slen); |
467 | ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); | 446 | ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); |
468 | ping.challenge = htonl (ve->challenge); | 447 | ping.challenge = htonl (ve->challenge); |
469 | ping.target = *pid; | 448 | ping.target = *pid; |
@@ -476,7 +455,7 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, | |||
476 | "HELLO", "PING", (unsigned int) tsize); | 455 | "HELLO", "PING", (unsigned int) tsize); |
477 | /* message too big (!?), get rid of HELLO */ | 456 | /* message too big (!?), get rid of HELLO */ |
478 | hsize = 0; | 457 | hsize = 0; |
479 | tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize; | 458 | tsize = sizeof (struct TransportPingMessage) + ve->address->address_length + slen + hsize; |
480 | } | 459 | } |
481 | { | 460 | { |
482 | char message_buf[tsize]; | 461 | char message_buf[tsize]; |
@@ -486,10 +465,10 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, | |||
486 | memcpy (message_buf, hello, hsize); | 465 | memcpy (message_buf, hello, hsize); |
487 | memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage)); | 466 | memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage)); |
488 | memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize], | 467 | memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize], |
489 | ve->transport_name, slen); | 468 | ve->address->transport_name, slen); |
490 | memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], | 469 | memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], |
491 | ve->addr, ve->addrlen); | 470 | ve->address, ve->address->address_length); |
492 | papi = GST_plugins_find (ve->transport_name); | 471 | papi = GST_plugins_find (ve->address->transport_name); |
493 | if (papi == NULL) | 472 | if (papi == NULL) |
494 | ret = -1; | 473 | ret = -1; |
495 | else | 474 | else |
@@ -498,7 +477,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, | |||
498 | ret = | 477 | ret = |
499 | papi->send (papi->cls, pid, message_buf, tsize, PING_PRIORITY, | 478 | papi->send (papi->cls, pid, message_buf, tsize, PING_PRIORITY, |
500 | ACCEPTABLE_PING_DELAY, NULL /* no session */ , | 479 | ACCEPTABLE_PING_DELAY, NULL /* no session */ , |
501 | ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL); | 480 | ve->address->address, ve->address->address_length, |
481 | GNUNET_YES, NULL, NULL); | ||
502 | } | 482 | } |
503 | } | 483 | } |
504 | if (-1 != ret) | 484 | if (-1 != ret) |
@@ -566,7 +546,8 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
566 | GNUNET_STATISTICS_update (GST_stats, | 546 | GNUNET_STATISTICS_update (GST_stats, |
567 | gettext_noop ("# address revalidations started"), 1, | 547 | gettext_noop ("# address revalidations started"), 1, |
568 | GNUNET_NO); | 548 | GNUNET_NO); |
569 | bc = GST_blacklist_test_allowed (&ve->pid, ve->transport_name, &transmit_ping_if_allowed, ve); | 549 | bc = GST_blacklist_test_allowed (&ve->pid, ve->address->transport_name, |
550 | &transmit_ping_if_allowed, ve); | ||
570 | if (NULL != bc) | 551 | if (NULL != bc) |
571 | ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already | 552 | ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already |
572 | called... */ | 553 | called... */ |
@@ -579,45 +560,36 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
579 | * without starting any validation). | 560 | * without starting any validation). |
580 | * | 561 | * |
581 | * @param public_key public key of the peer, NULL for unknown | 562 | * @param public_key public key of the peer, NULL for unknown |
582 | * @param neighbour which peer we care about | 563 | * @param address address to find |
583 | * @param tname name of the transport plugin | ||
584 | * @param addr binary address | ||
585 | * @param addrlen length of addr | ||
586 | * @return validation entry matching the given specifications, NULL | 564 | * @return validation entry matching the given specifications, NULL |
587 | * if we don't have an existing entry and no public key was given | 565 | * if we don't have an existing entry and no public key was given |
588 | */ | 566 | */ |
589 | static struct ValidationEntry * | 567 | static struct ValidationEntry * |
590 | find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 568 | find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
591 | *public_key, const struct GNUNET_PeerIdentity *neighbour, | 569 | *public_key, const struct GNUNET_HELLO_Address *address) |
592 | const char *tname, const char *addr, size_t addrlen) | ||
593 | { | 570 | { |
594 | struct ValidationEntryMatchContext vemc; | 571 | struct ValidationEntryMatchContext vemc; |
595 | struct ValidationEntry *ve; | 572 | struct ValidationEntry *ve; |
596 | 573 | ||
597 | vemc.ve = NULL; | 574 | vemc.ve = NULL; |
598 | vemc.transport_name = tname; | 575 | vemc.address = address; |
599 | vemc.addr = addr; | ||
600 | vemc.addrlen = addrlen; | ||
601 | GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, | 576 | GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, |
602 | &neighbour->hashPubKey, | 577 | &address->peer.hashPubKey, |
603 | &validation_entry_match, &vemc); | 578 | &validation_entry_match, &vemc); |
604 | if (NULL != (ve = vemc.ve)) | 579 | if (NULL != (ve = vemc.ve)) |
605 | return ve; | 580 | return ve; |
606 | if (public_key == NULL) | 581 | if (public_key == NULL) |
607 | return NULL; | 582 | return NULL; |
608 | ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen); | 583 | ve = GNUNET_malloc (sizeof (struct ValidationEntry)); |
609 | ve->transport_name = GNUNET_strdup (tname); | 584 | ve->address = GNUNET_HELLO_address_copy (address); |
610 | ve->addr = (void *) &ve[1]; | ||
611 | ve->public_key = *public_key; | 585 | ve->public_key = *public_key; |
612 | ve->pid = *neighbour; | 586 | ve->pid = address->peer; |
613 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; | 587 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; |
614 | ve->challenge = | 588 | ve->challenge = |
615 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 589 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
616 | ve->timeout_task = GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, | 590 | ve->timeout_task = GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, |
617 | &timeout_hello_validation, ve); | 591 | &timeout_hello_validation, ve); |
618 | memcpy (&ve[1], addr, addrlen); | 592 | GNUNET_CONTAINER_multihashmap_put (validation_map, &address->peer.hashPubKey, ve, |
619 | ve->addrlen = addrlen; | ||
620 | GNUNET_CONTAINER_multihashmap_put (validation_map, &neighbour->hashPubKey, ve, | ||
621 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 593 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
622 | return ve; | 594 | return ve; |
623 | } | 595 | } |
@@ -628,16 +600,14 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | |||
628 | * addresses. | 600 | * addresses. |
629 | * | 601 | * |
630 | * @param cls original HELLO message | 602 | * @param cls original HELLO message |
631 | * @param tname name of the transport | 603 | * @param address the address |
632 | * @param expiration expiration time | 604 | * @param expiration expiration time |
633 | * @param addr the address | ||
634 | * @param addrlen length of the address | ||
635 | * @return GNUNET_OK (keep the address) | 605 | * @return GNUNET_OK (keep the address) |
636 | */ | 606 | */ |
637 | static int | 607 | static int |
638 | add_valid_address (void *cls, const char *tname, | 608 | add_valid_address (void *cls, |
639 | struct GNUNET_TIME_Absolute expiration, const void *addr, | 609 | const struct GNUNET_HELLO_Address *address, |
640 | uint16_t addrlen) | 610 | struct GNUNET_TIME_Absolute expiration) |
641 | { | 611 | { |
642 | const struct GNUNET_HELLO_Message *hello = cls; | 612 | const struct GNUNET_HELLO_Message *hello = cls; |
643 | struct ValidationEntry *ve; | 613 | struct ValidationEntry *ve; |
@@ -652,11 +622,11 @@ add_valid_address (void *cls, const char *tname, | |||
652 | GNUNET_break (0); | 622 | GNUNET_break (0); |
653 | return GNUNET_OK; /* invalid HELLO !? */ | 623 | return GNUNET_OK; /* invalid HELLO !? */ |
654 | } | 624 | } |
655 | ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); | 625 | ve = find_validation_entry (&public_key, address); |
656 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); | 626 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); |
657 | if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) | 627 | if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) |
658 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | 628 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); |
659 | GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, addrlen, NULL, NULL, | 629 | GNUNET_ATS_address_update (GST_ats, address, NULL, NULL, |
660 | 0); | 630 | 0); |
661 | return GNUNET_OK; | 631 | return GNUNET_OK; |
662 | } | 632 | } |
@@ -728,29 +698,27 @@ GST_validation_stop () | |||
728 | * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) | 698 | * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) |
729 | * is ZERO if the address is considered valid (no validation needed) | 699 | * is ZERO if the address is considered valid (no validation needed) |
730 | * otherwise a time in the future if we're currently denying re-validation | 700 | * otherwise a time in the future if we're currently denying re-validation |
731 | * @param plugin_name name of the plugin | 701 | * @param adress target address |
732 | * @param plugin_address binary address | ||
733 | * @param plugin_address_len length of address | ||
734 | */ | 702 | */ |
735 | static void | 703 | static void |
736 | multicast_pong (void *cls, | 704 | multicast_pong (void *cls, |
737 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 705 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
738 | *public_key, const struct GNUNET_PeerIdentity *target, | 706 | *public_key, |
739 | struct GNUNET_TIME_Absolute valid_until, | 707 | struct GNUNET_TIME_Absolute valid_until, |
740 | struct GNUNET_TIME_Absolute validation_block, | 708 | struct GNUNET_TIME_Absolute validation_block, |
741 | const char *plugin_name, const void *plugin_address, | 709 | const struct GNUNET_HELLO_Address *address) |
742 | size_t plugin_address_len) | ||
743 | { | 710 | { |
744 | struct TransportPongMessage *pong = cls; | 711 | struct TransportPongMessage *pong = cls; |
745 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 712 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
746 | 713 | ||
747 | papi = GST_plugins_find (plugin_name); | 714 | papi = GST_plugins_find (address->transport_name); |
748 | if (papi == NULL) | 715 | if (papi == NULL) |
749 | return; | 716 | return; |
750 | (void) papi->send (papi->cls, target, (const char *) pong, | 717 | (void) papi->send (papi->cls, &address->peer, (const char *) pong, |
751 | ntohs (pong->header.size), PONG_PRIORITY, | 718 | ntohs (pong->header.size), PONG_PRIORITY, |
752 | ACCEPTABLE_PING_DELAY, NULL, plugin_address, | 719 | ACCEPTABLE_PING_DELAY, NULL, |
753 | plugin_address_len, GNUNET_YES, NULL, NULL); | 720 | address->address, |
721 | address->address_length, GNUNET_YES, NULL, NULL); | ||
754 | } | 722 | } |
755 | 723 | ||
756 | 724 | ||
@@ -759,18 +727,14 @@ multicast_pong (void *cls, | |||
759 | * | 727 | * |
760 | * @param sender peer sending the PING | 728 | * @param sender peer sending the PING |
761 | * @param hdr the PING | 729 | * @param hdr the PING |
730 | * @param sender_address the sender address as we got it | ||
762 | * @param session session we got the PING from | 731 | * @param session session we got the PING from |
763 | * @param plugin_name name of plugin that received the PING | ||
764 | * @param sender_address address of the sender as known to the plugin, NULL | ||
765 | * if we did not initiate the connection | ||
766 | * @param sender_address_len number of bytes in sender_address | ||
767 | */ | 732 | */ |
768 | void | 733 | void |
769 | GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | 734 | GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, |
770 | const struct GNUNET_MessageHeader *hdr, | 735 | const struct GNUNET_MessageHeader *hdr, |
771 | const char *plugin_name, struct Session *session, | 736 | const struct GNUNET_HELLO_Address *sender_address, |
772 | const void *sender_address, | 737 | struct Session *session) |
773 | size_t sender_address_len) | ||
774 | { | 738 | { |
775 | const struct TransportPingMessage *ping; | 739 | const struct TransportPingMessage *ping; |
776 | struct TransportPongMessage *pong; | 740 | struct TransportPongMessage *pong; |
@@ -782,6 +746,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
782 | size_t alen; | 746 | size_t alen; |
783 | size_t slen; | 747 | size_t slen; |
784 | ssize_t ret; | 748 | ssize_t ret; |
749 | struct GNUNET_HELLO_Address address; | ||
785 | 750 | ||
786 | if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) | 751 | if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) |
787 | { | 752 | { |
@@ -821,15 +786,18 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
821 | addrend++; | 786 | addrend++; |
822 | slen = strlen (addr) + 1; | 787 | slen = strlen (addr) + 1; |
823 | alen -= slen; | 788 | alen -= slen; |
824 | 789 | address.address = addrend; | |
790 | address.address_length = alen; | ||
791 | address.transport_name = addr; | ||
792 | address.peer = *sender; | ||
825 | if (GNUNET_YES != | 793 | if (GNUNET_YES != |
826 | GST_hello_test_address (addr, addrend, alen, &sig_cache, | 794 | GST_hello_test_address (&address, &sig_cache, |
827 | &sig_cache_exp)) | 795 | &sig_cache_exp)) |
828 | { | 796 | { |
829 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 797 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
830 | _ | 798 | _ |
831 | ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), | 799 | ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), |
832 | GST_plugins_a2s (addr, addrend, alen)); | 800 | GST_plugins_a2s (&address)); |
833 | return; | 801 | return; |
834 | } | 802 | } |
835 | } | 803 | } |
@@ -879,15 +847,17 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
879 | 847 | ||
880 | /* first see if the session we got this PING from can be used to transmit | 848 | /* first see if the session we got this PING from can be used to transmit |
881 | * a response reliably */ | 849 | * a response reliably */ |
882 | papi = GST_plugins_find (plugin_name); | 850 | papi = GST_plugins_find (sender_address->transport_name); |
883 | if (papi == NULL) | 851 | if (papi == NULL) |
884 | ret = -1; | 852 | ret = -1; |
885 | else | 853 | else |
886 | ret = | 854 | ret = |
887 | papi->send (papi->cls, sender, (const char *) pong, | 855 | papi->send (papi->cls, sender, (const char *) pong, |
888 | ntohs (pong->header.size), PONG_PRIORITY, | 856 | ntohs (pong->header.size), PONG_PRIORITY, |
889 | ACCEPTABLE_PING_DELAY, session, sender_address, | 857 | ACCEPTABLE_PING_DELAY, session, |
890 | sender_address_len, GNUNET_SYSERR, NULL, NULL); | 858 | sender_address->address, |
859 | sender_address->address_length, | ||
860 | GNUNET_SYSERR, NULL, NULL); | ||
891 | if (ret != -1) | 861 | if (ret != -1) |
892 | { | 862 | { |
893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -934,24 +904,21 @@ struct ValidateAddressContext | |||
934 | * (unless blocked or already validated). | 904 | * (unless blocked or already validated). |
935 | * | 905 | * |
936 | * @param cls pointer to a 'struct ValidateAddressContext' | 906 | * @param cls pointer to a 'struct ValidateAddressContext' |
937 | * @param tname name of the transport | 907 | * @param address the address |
938 | * @param expiration expiration time | 908 | * @param expiration expiration time |
939 | * @param addr the address | ||
940 | * @param addrlen length of the address | ||
941 | * @return GNUNET_OK (keep the address) | 909 | * @return GNUNET_OK (keep the address) |
942 | */ | 910 | */ |
943 | static int | 911 | static int |
944 | validate_address_iterator (void *cls, const char *tname, | 912 | validate_address_iterator (void *cls, |
945 | struct GNUNET_TIME_Absolute expiration, const void *addr, | 913 | const struct GNUNET_HELLO_Address *address, |
946 | uint16_t addrlen) | 914 | struct GNUNET_TIME_Absolute expiration) |
947 | { | 915 | { |
948 | const struct ValidateAddressContext *vac = cls; | 916 | const struct ValidateAddressContext *vac = cls; |
949 | const struct GNUNET_PeerIdentity *pid = &vac->pid; | ||
950 | struct ValidationEntry *ve; | 917 | struct ValidationEntry *ve; |
951 | 918 | ||
952 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) | 919 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) |
953 | return GNUNET_OK; /* expired */ | 920 | return GNUNET_OK; /* expired */ |
954 | ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen); | 921 | ve = find_validation_entry (&vac->public_key, address); |
955 | if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) | 922 | if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) |
956 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, | 923 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, |
957 | ve); | 924 | ve); |
@@ -976,8 +943,8 @@ add_valid_peer_address (void *cls, size_t max, void *buf) | |||
976 | if (GNUNET_YES == ve->copied) | 943 | if (GNUNET_YES == ve->copied) |
977 | return 0; /* terminate */ | 944 | return 0; /* terminate */ |
978 | ve->copied = GNUNET_YES; | 945 | ve->copied = GNUNET_YES; |
979 | return GNUNET_HELLO_add_address (ve->transport_name, ve->valid_until, | 946 | return GNUNET_HELLO_add_address (ve->address, ve->valid_until, |
980 | ve->addr, ve->addrlen, buf, max); | 947 | buf, max); |
981 | } | 948 | } |
982 | 949 | ||
983 | 950 | ||
@@ -1000,6 +967,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1000 | size_t slen; | 967 | size_t slen; |
1001 | size_t size; | 968 | size_t size; |
1002 | struct GNUNET_HELLO_Message *hello; | 969 | struct GNUNET_HELLO_Message *hello; |
970 | struct GNUNET_HELLO_Address address; | ||
1003 | 971 | ||
1004 | if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) | 972 | if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) |
1005 | { | 973 | { |
@@ -1022,8 +990,11 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1022 | addr++; | 990 | addr++; |
1023 | slen = strlen (tname) + 1; | 991 | slen = strlen (tname) + 1; |
1024 | addrlen = size - slen; | 992 | addrlen = size - slen; |
1025 | 993 | address.peer = *sender; | |
1026 | ve = find_validation_entry (NULL, sender, tname, addr, addrlen); | 994 | address.address = addr; |
995 | address.address_length = addrlen; | ||
996 | address.transport_name = tname; | ||
997 | ve = find_validation_entry (NULL, &address); | ||
1027 | if (NULL == ve) | 998 | if (NULL == ve) |
1028 | { | 999 | { |
1029 | GNUNET_STATISTICS_update (GST_stats, | 1000 | GNUNET_STATISTICS_update (GST_stats, |
@@ -1071,8 +1042,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1071 | 1042 | ||
1072 | ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | 1043 | ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); |
1073 | ats.value = htonl ((uint32_t) ve->latency.rel_value); | 1044 | ats.value = htonl ((uint32_t) ve->latency.rel_value); |
1074 | GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->transport_name, ve->addr, | 1045 | GNUNET_ATS_address_update (GST_ats, ve->address, NULL, &ats, 1); |
1075 | ve->addrlen, NULL, &ats, 1); | ||
1076 | } | 1046 | } |
1077 | /* build HELLO to store in PEERINFO */ | 1047 | /* build HELLO to store in PEERINFO */ |
1078 | ve->copied = GNUNET_NO; | 1048 | ve->copied = GNUNET_NO; |
@@ -1153,8 +1123,8 @@ iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value) | |||
1153 | struct IteratorContext *ic = cls; | 1123 | struct IteratorContext *ic = cls; |
1154 | struct ValidationEntry *ve = value; | 1124 | struct ValidationEntry *ve = value; |
1155 | 1125 | ||
1156 | ic->cb (ic->cb_cls, &ve->public_key, &ve->pid, ve->valid_until, | 1126 | ic->cb (ic->cb_cls, &ve->public_key, ve->valid_until, |
1157 | ve->revalidation_block, ve->transport_name, ve->addr, ve->addrlen); | 1127 | ve->revalidation_block, ve->address); |
1158 | return GNUNET_OK; | 1128 | return GNUNET_OK; |
1159 | } | 1129 | } |
1160 | 1130 | ||
@@ -1186,25 +1156,20 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, | |||
1186 | * Based on this, the validation module will measure latency for the | 1156 | * Based on this, the validation module will measure latency for the |
1187 | * address more or less often. | 1157 | * address more or less often. |
1188 | * | 1158 | * |
1189 | * @param sender peer | 1159 | * @param sender peer FIXME: redundant! |
1190 | * @param plugin_name name of plugin | 1160 | * @param address the address |
1191 | * @param session session | ||
1192 | * @param sender_address address of the sender as known to the plugin, NULL | ||
1193 | * if we did not initiate the connection | ||
1194 | * @param sender_address_len number of bytes in sender_address | ||
1195 | * @param in_use GNUNET_YES if we are now using the address for a connection, | 1161 | * @param in_use GNUNET_YES if we are now using the address for a connection, |
1196 | * GNUNET_NO if we are no longer using the address for a connection | 1162 | * GNUNET_NO if we are no longer using the address for a connection |
1197 | */ | 1163 | */ |
1198 | void | 1164 | void |
1199 | GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, | 1165 | GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, |
1200 | const char *plugin_name, struct Session *session, | 1166 | const struct GNUNET_HELLO_Address *address, |
1201 | const void *sender_address, | 1167 | struct Session *session, |
1202 | size_t sender_address_len, | ||
1203 | int in_use) | 1168 | int in_use) |
1204 | { | 1169 | { |
1205 | struct ValidationEntry *ve; | 1170 | struct ValidationEntry *ve; |
1206 | 1171 | ||
1207 | ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len); | 1172 | ve = find_validation_entry (NULL, address); |
1208 | if (NULL == ve) | 1173 | if (NULL == ve) |
1209 | { | 1174 | { |
1210 | /* FIXME: this can happen for inbound connections (sender_address_len == 0); | 1175 | /* FIXME: this can happen for inbound connections (sender_address_len == 0); |
@@ -1231,23 +1196,19 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, | |||
1231 | * address. | 1196 | * address. |
1232 | * | 1197 | * |
1233 | * @param sender peer | 1198 | * @param sender peer |
1234 | * @param plugin_name name of plugin | 1199 | * @param address the address |
1235 | * @param session session | 1200 | * @param session session |
1236 | * @param sender_address address of the sender as known to the plugin, NULL | ||
1237 | * if we did not initiate the connection | ||
1238 | * @param sender_address_len number of bytes in sender_address | ||
1239 | * @return observed latency of the address, FOREVER if the address was | 1201 | * @return observed latency of the address, FOREVER if the address was |
1240 | * never successfully validated | 1202 | * never successfully validated |
1241 | */ | 1203 | */ |
1242 | struct GNUNET_TIME_Relative | 1204 | struct GNUNET_TIME_Relative |
1243 | GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, | 1205 | GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, |
1244 | const char *plugin_name, struct Session *session, | 1206 | const struct GNUNET_HELLO_Address *address, |
1245 | const void *sender_address, | 1207 | struct Session *session) |
1246 | size_t sender_address_len) | ||
1247 | { | 1208 | { |
1248 | struct ValidationEntry *ve; | 1209 | struct ValidationEntry *ve; |
1249 | 1210 | ||
1250 | ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len); | 1211 | ve = find_validation_entry (NULL, address); |
1251 | if (NULL == ve) | 1212 | if (NULL == ve) |
1252 | return GNUNET_TIME_UNIT_FOREVER_REL; | 1213 | return GNUNET_TIME_UNIT_FOREVER_REL; |
1253 | return ve->latency; | 1214 | return ve->latency; |