diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 16:43:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 16:43:41 +0000 |
commit | ef5b7049c8ac74924c4ee24e566802e1fc05addd (patch) | |
tree | 0e00089628e99ea304a06be291ae4885845ecb34 /src | |
parent | 03cece829b042e5a829a633e2e790ab83ac9308e (diff) | |
download | gnunet-ef5b7049c8ac74924c4ee24e566802e1fc05addd.tar.gz gnunet-ef5b7049c8ac74924c4ee24e566802e1fc05addd.zip |
clean up find_quality_property_index and get_active_address_it
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index e29e352c5..f233ca4df 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -638,17 +638,22 @@ struct FindBestAddressCtx | |||
638 | 638 | ||
639 | 639 | ||
640 | /** | 640 | /** |
641 | * Find index of a ATS property type in the array. | 641 | * Find index of a ATS property type in the quality properties array. |
642 | * | ||
643 | * @param type ATS property type | ||
644 | * @return index in the quality array, #GNUNET_SYSERR if the type | ||
645 | * was not a quality property | ||
642 | */ | 646 | */ |
643 | static int | 647 | static int |
644 | find_property_index (uint32_t type) | 648 | find_quality_property_index (enum GNUNET_ATS_Property type) |
645 | { | 649 | { |
646 | int existing_types[] = GNUNET_ATS_QualityProperties; | 650 | enum GNUNET_ATS_Property existing_types[] = GNUNET_ATS_QualityProperties; |
647 | int c; | 651 | unsigned int c; |
648 | 652 | ||
649 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) | 653 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) |
650 | if (existing_types[c] == type) | 654 | if (existing_types[c] == type) |
651 | return c; | 655 | return c; |
656 | GNUNET_break (0); | ||
652 | return GNUNET_SYSERR; | 657 | return GNUNET_SYSERR; |
653 | } | 658 | } |
654 | 659 | ||
@@ -723,10 +728,10 @@ find_best_address_it (void *cls, | |||
723 | } | 728 | } |
724 | 729 | ||
725 | /* Now compare ATS information */ | 730 | /* Now compare ATS information */ |
726 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); | 731 | index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); |
727 | cur_distance = current->atsin[index].norm; | 732 | cur_distance = current->atsin[index].norm; |
728 | best_distance = ctx->best->atsin[index].norm; | 733 | best_distance = ctx->best->atsin[index].norm; |
729 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); | 734 | index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DELAY); |
730 | cur_delay = current->atsin[index].norm; | 735 | cur_delay = current->atsin[index].norm; |
731 | best_delay = ctx->best->atsin[index].norm; | 736 | best_delay = ctx->best->atsin[index].norm; |
732 | 737 | ||
@@ -802,7 +807,8 @@ get_best_address (struct GAS_PROPORTIONAL_Handle *s, | |||
802 | 807 | ||
803 | 808 | ||
804 | /** | 809 | /** |
805 | * Hashmap Iterator to find current active address for peer | 810 | * Address map iterator to find current active address for peer. |
811 | * Asserts that only one address is active per peer. | ||
806 | * | 812 | * |
807 | * @param cls last active address | 813 | * @param cls last active address |
808 | * @param key peer's key | 814 | * @param key peer's key |
@@ -815,27 +821,12 @@ get_active_address_it (void *cls, | |||
815 | void *value) | 821 | void *value) |
816 | { | 822 | { |
817 | struct ATS_Address **dest = cls; | 823 | struct ATS_Address **dest = cls; |
818 | struct ATS_Address *aa = (struct ATS_Address *) value; | 824 | struct ATS_Address *aa = value; |
819 | |||
820 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
821 | "Checking address %p\n", aa); | ||
822 | 825 | ||
823 | if (GNUNET_YES == aa->active) | 826 | if (GNUNET_YES != aa->active) |
824 | { | 827 | return GNUNET_OK; |
825 | LOG (GNUNET_ERROR_TYPE_INFO, | 828 | GNUNET_assert (NULL == (*dest)); |
826 | "Address %p is active\n", aa); | 829 | (*dest) = aa; |
827 | if (NULL != (*dest)) | ||
828 | { | ||
829 | /* should never happen */ | ||
830 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
831 | "Multiple active addresses for peer `%s'\n", | ||
832 | GNUNET_i2s (&aa->peer)); | ||
833 | GNUNET_break(0); | ||
834 | return GNUNET_NO; | ||
835 | } | ||
836 | (*dest) = aa; | ||
837 | |||
838 | } | ||
839 | return GNUNET_OK; | 830 | return GNUNET_OK; |
840 | } | 831 | } |
841 | 832 | ||