diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-15 17:18:11 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-15 17:18:11 +0000 |
commit | 2368c95a00afc72a8f03ab67bca1ff41328eecdf (patch) | |
tree | 3bcbc29808d7e91c85ca60ac5c998374b458862e /src/transport/gnunet-service-transport_validation.c | |
parent | b0144a11f14f33ab010fd7cf8c61bdd361f20fd3 (diff) | |
download | gnunet-2368c95a00afc72a8f03ab67bca1ff41328eecdf.tar.gz gnunet-2368c95a00afc72a8f03ab67bca1ff41328eecdf.zip |
transport validation monitoring API (not yet complete) + CLI
+ fix for crash in transport/plugin_transport_udp.c
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 07ed2eeca..e18412588 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -218,6 +218,11 @@ struct ValidationEntry | |||
218 | struct GNUNET_TIME_Absolute send_time; | 218 | struct GNUNET_TIME_Absolute send_time; |
219 | 219 | ||
220 | /** | 220 | /** |
221 | * At what time do we send the next validation request (PING)? | ||
222 | */ | ||
223 | struct GNUNET_TIME_Absolute next_validation; | ||
224 | |||
225 | /** | ||
221 | * Until when is this address valid? | 226 | * Until when is this address valid? |
222 | * ZERO if it is not currently considered valid. | 227 | * ZERO if it is not currently considered valid. |
223 | */ | 228 | */ |
@@ -244,6 +249,10 @@ struct ValidationEntry | |||
244 | struct GNUNET_TIME_Relative latency; | 249 | struct GNUNET_TIME_Relative latency; |
245 | 250 | ||
246 | /** | 251 | /** |
252 | * Current state of this validation entry | ||
253 | */ | ||
254 | enum GNUNET_TRANSPORT_ValidationState state; | ||
255 | /** | ||
247 | * Challenge number we used. | 256 | * Challenge number we used. |
248 | */ | 257 | */ |
249 | uint32_t challenge; | 258 | uint32_t challenge; |
@@ -336,6 +345,9 @@ static unsigned int validations_fast_start_threshold; | |||
336 | */ | 345 | */ |
337 | static struct GNUNET_TIME_Absolute validation_next; | 346 | static struct GNUNET_TIME_Absolute validation_next; |
338 | 347 | ||
348 | static GST_ValidationChangedCallback validation_entry_changed_cb; | ||
349 | static void *validation_entry_changed_cb_cls; | ||
350 | |||
339 | /** | 351 | /** |
340 | * Context for the validation entry match function. | 352 | * Context for the validation entry match function. |
341 | */ | 353 | */ |
@@ -377,6 +389,24 @@ validation_entry_match (void *cls, const struct GNUNET_PeerIdentity * key, void | |||
377 | return GNUNET_YES; | 389 | return GNUNET_YES; |
378 | } | 390 | } |
379 | 391 | ||
392 | static void | ||
393 | validation_entry_changed (struct ValidationEntry *ve, enum GNUNET_TRANSPORT_ValidationState state) | ||
394 | { | ||
395 | char *t_sent = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->send_time)); | ||
396 | char *t_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->valid_until)); | ||
397 | char *t_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->next_validation)); | ||
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation entry changed for peer `%s' address `%s':\n\tSent: %s\n\tValid: %s\n\tNext: %s\n", | ||
399 | GNUNET_i2s(&ve->pid), GST_plugins_a2s(ve->address), | ||
400 | t_sent, t_valid, t_next); | ||
401 | ve->state = state; | ||
402 | |||
403 | GNUNET_free (t_sent); | ||
404 | GNUNET_free (t_valid); | ||
405 | GNUNET_free (t_next); | ||
406 | validation_entry_changed_cb (validation_entry_changed_cb_cls, &ve->pid, | ||
407 | ve->address, ve->send_time, ve->valid_until, ve->next_validation, state); | ||
408 | } | ||
409 | |||
380 | 410 | ||
381 | /** | 411 | /** |
382 | * Iterate over validation entries and free them. | 412 | * Iterate over validation entries and free them. |
@@ -391,6 +421,12 @@ cleanup_validation_entry (void *cls, const struct GNUNET_PeerIdentity * key, voi | |||
391 | { | 421 | { |
392 | struct ValidationEntry *ve = value; | 422 | struct ValidationEntry *ve = value; |
393 | 423 | ||
424 | ve->next_validation = GNUNET_TIME_absolute_get_zero_(); | ||
425 | ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; | ||
426 | |||
427 | /* Notify about deleted entry */ | ||
428 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_REMOVE); | ||
429 | |||
394 | if (NULL != ve->bc) | 430 | if (NULL != ve->bc) |
395 | { | 431 | { |
396 | GST_blacklist_test_cancel (ve->bc); | 432 | GST_blacklist_test_cancel (ve->bc); |
@@ -586,6 +622,8 @@ transmit_ping_if_allowed (void *cls, | |||
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
587 | "Validation started, %u validation processes running\n", | 623 | "Validation started, %u validation processes running\n", |
588 | validations_running); | 624 | validations_running); |
625 | /* Notify about PING sent */ | ||
626 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE); | ||
589 | } | 627 | } |
590 | } | 628 | } |
591 | 629 | ||
@@ -631,6 +669,7 @@ revalidate_address (void *cls, | |||
631 | GST_plugins_a2s (ve->address)); | 669 | GST_plugins_a2s (ve->address)); |
632 | ve->revalidation_task = | 670 | ve->revalidation_task = |
633 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); | 671 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); |
672 | ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | ||
634 | return; | 673 | return; |
635 | } | 674 | } |
636 | blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); | 675 | blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); |
@@ -645,6 +684,7 @@ revalidate_address (void *cls, | |||
645 | GST_plugins_a2s (ve->address)); | 684 | GST_plugins_a2s (ve->address)); |
646 | ve->revalidation_task = | 685 | ve->revalidation_task = |
647 | GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve); | 686 | GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve); |
687 | ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), blocked_for); | ||
648 | return; | 688 | return; |
649 | } | 689 | } |
650 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); | 690 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); |
@@ -675,6 +715,7 @@ revalidate_address (void *cls, | |||
675 | GST_plugins_a2s (ve->address)); | 715 | GST_plugins_a2s (ve->address)); |
676 | ve->revalidation_task = | 716 | ve->revalidation_task = |
677 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); | 717 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); |
718 | ve->next_validation = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | ||
678 | 719 | ||
679 | /* start PINGing by checking blacklist */ | 720 | /* start PINGing by checking blacklist */ |
680 | GNUNET_STATISTICS_update (GST_stats, | 721 | GNUNET_STATISTICS_update (GST_stats, |
@@ -730,6 +771,7 @@ find_validation_entry (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | |||
730 | GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer, | 771 | GNUNET_CONTAINER_multipeermap_put (validation_map, &address->peer, |
731 | ve, | 772 | ve, |
732 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 773 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
774 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW); | ||
733 | ve->expecting_pong = GNUNET_NO; | 775 | ve->expecting_pong = GNUNET_NO; |
734 | return ve; | 776 | return ve; |
735 | } | 777 | } |
@@ -779,8 +821,10 @@ add_valid_address (void *cls, | |||
779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
780 | "Starting revalidations for valid address `%s'\n", | 822 | "Starting revalidations for valid address `%s'\n", |
781 | GST_plugins_a2s (ve->address)); | 823 | GST_plugins_a2s (ve->address)); |
824 | ve->next_validation = GNUNET_TIME_absolute_get(); | ||
782 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | 825 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); |
783 | } | 826 | } |
827 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE); | ||
784 | 828 | ||
785 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 829 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
786 | ats.value = htonl (ve->network); | 830 | ats.value = htonl (ve->network); |
@@ -822,7 +866,7 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
822 | * @param max_fds maximum number of fds to use | 866 | * @param max_fds maximum number of fds to use |
823 | */ | 867 | */ |
824 | void | 868 | void |
825 | GST_validation_start (unsigned int max_fds) | 869 | GST_validation_start (GST_ValidationChangedCallback cb, void *cb_cls, unsigned int max_fds) |
826 | { | 870 | { |
827 | /** | 871 | /** |
828 | * Initialization for validation throttling | 872 | * Initialization for validation throttling |
@@ -840,6 +884,8 @@ GST_validation_start (unsigned int max_fds) | |||
840 | validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); | 884 | validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); |
841 | validations_fast_start_threshold = (max_fds / 2); | 885 | validations_fast_start_threshold = (max_fds / 2); |
842 | validations_running = 0; | 886 | validations_running = 0; |
887 | validation_entry_changed_cb = cb; | ||
888 | validation_entry_changed_cb_cls = cb_cls; | ||
843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ", | 889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ", |
844 | validations_fast_start_threshold, | 890 | validations_fast_start_threshold, |
845 | GNUNET_STRINGS_relative_time_to_string (validation_delay, | 891 | GNUNET_STRINGS_relative_time_to_string (validation_delay, |
@@ -1396,6 +1442,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1396 | GNUNET_break (0); | 1442 | GNUNET_break (0); |
1397 | } | 1443 | } |
1398 | 1444 | ||
1445 | /* Notify about new validity */ | ||
1446 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE); | ||
1447 | |||
1399 | /* build HELLO to store in PEERINFO */ | 1448 | /* build HELLO to store in PEERINFO */ |
1400 | ve->copied = GNUNET_NO; | 1449 | ve->copied = GNUNET_NO; |
1401 | hello = GNUNET_HELLO_create (&ve->public_key, | 1450 | hello = GNUNET_HELLO_create (&ve->public_key, |
@@ -1600,5 +1649,54 @@ GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, | |||
1600 | return ve->latency; | 1649 | return ve->latency; |
1601 | } | 1650 | } |
1602 | 1651 | ||
1652 | /** | ||
1653 | * Closure for the validation_entries_iterate function. | ||
1654 | */ | ||
1655 | struct ValidationIteratorContext | ||
1656 | { | ||
1657 | /** | ||
1658 | * Function to call on each validation entry | ||
1659 | */ | ||
1660 | GST_ValidationChangedCallback cb; | ||
1661 | |||
1662 | /** | ||
1663 | * Closure for 'cb'. | ||
1664 | */ | ||
1665 | void *cb_cls; | ||
1666 | }; | ||
1667 | |||
1668 | static int | ||
1669 | validation_entries_iterate (void *cls, | ||
1670 | const struct GNUNET_PeerIdentity *key, | ||
1671 | void *value) | ||
1672 | { | ||
1673 | struct ValidationIteratorContext *ic = cls; | ||
1674 | struct ValidationEntry *ve = value; | ||
1675 | |||
1676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Notifying about validation entry for peer `%s' address `%s' \n", | ||
1677 | GNUNET_i2s (&ve->pid), GST_plugins_a2s (ve->address)); | ||
1678 | ic->cb (ic->cb_cls, &ve->pid, ve->address, ve->send_time, | ||
1679 | ve->valid_until, ve->next_validation, ve->state); | ||
1680 | |||
1681 | return GNUNET_OK; | ||
1682 | } | ||
1683 | |||
1684 | /** | ||
1685 | * Iterate over all iteration entries | ||
1686 | * | ||
1687 | * @param cb function to call | ||
1688 | * @param cb_cls closure for cb | ||
1689 | */ | ||
1690 | void | ||
1691 | GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls) | ||
1692 | { | ||
1693 | struct ValidationIteratorContext ic; | ||
1694 | |||
1695 | if (NULL == validation_map) | ||
1696 | return; /* can happen during shutdown */ | ||
1697 | ic.cb = cb; | ||
1698 | ic.cb_cls = cb_cls; | ||
1699 | GNUNET_CONTAINER_multipeermap_iterate (validation_map, &validation_entries_iterate, &ic); | ||
1700 | } | ||
1603 | 1701 | ||
1604 | /* end of file gnunet-service-transport_validation.c */ | 1702 | /* end of file gnunet-service-transport_validation.c */ |