diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 6 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 10 | ||||
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 105 |
3 files changed, 67 insertions, 54 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 865a20a03..ddcff962b 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -762,6 +762,8 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
762 | if (existing_address == NULL ) | 762 | if (existing_address == NULL ) |
763 | { | 763 | { |
764 | /* Add a new address */ | 764 | /* Add a new address */ |
765 | new_address->t_added = GNUNET_TIME_absolute_get(); | ||
766 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); | ||
765 | GNUNET_assert( | 767 | GNUNET_assert( |
766 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses, | 768 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses, |
767 | peer, | 769 | peer, |
@@ -816,6 +818,8 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
816 | GNUNET_i2s (peer), existing_address, session_id, | 818 | GNUNET_i2s (peer), existing_address, session_id, |
817 | GNUNET_ATS_print_network_type (addr_net)); | 819 | GNUNET_ATS_print_network_type (addr_net)); |
818 | /* We have an address without an session, update this address */ | 820 | /* We have an address without an session, update this address */ |
821 | existing_address->t_added = GNUNET_TIME_absolute_get(); | ||
822 | existing_address->t_last_activity = GNUNET_TIME_absolute_get(); | ||
819 | atsi_delta = NULL; | 823 | atsi_delta = NULL; |
820 | atsi_delta_count = 0; | 824 | atsi_delta_count = 0; |
821 | if (GNUNET_YES | 825 | if (GNUNET_YES |
@@ -914,6 +918,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
914 | "ADDRESS UPDATE", GNUNET_i2s (peer), aa); | 918 | "ADDRESS UPDATE", GNUNET_i2s (peer), aa); |
915 | 919 | ||
916 | /* Update address */ | 920 | /* Update address */ |
921 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | ||
917 | if (session_id != aa->session_id) | 922 | if (session_id != aa->session_id) |
918 | { | 923 | { |
919 | /* Session changed */ | 924 | /* Session changed */ |
@@ -1166,6 +1171,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1166 | 1171 | ||
1167 | /* Tell solver about update */ | 1172 | /* Tell solver about update */ |
1168 | ea->used = in_use; | 1173 | ea->used = in_use; |
1174 | ea->t_last_activity = GNUNET_TIME_absolute_get(); | ||
1169 | handle->env.sf.s_address_update_inuse (handle->solver, ea, ea->used); | 1175 | handle->env.sf.s_address_update_inuse (handle->solver, ea, ea->used); |
1170 | return GNUNET_OK; | 1176 | return GNUNET_OK; |
1171 | } | 1177 | } |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 887eeee81..8b7a58d52 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -363,6 +363,16 @@ struct ATS_Address | |||
363 | struct GNUNET_TIME_Absolute blocked_until; | 363 | struct GNUNET_TIME_Absolute blocked_until; |
364 | 364 | ||
365 | /** | 365 | /** |
366 | * Time when address had last activity (update, in uses) | ||
367 | */ | ||
368 | struct GNUNET_TIME_Absolute t_last_activity; | ||
369 | |||
370 | /** | ||
371 | * Time when address was added | ||
372 | */ | ||
373 | struct GNUNET_TIME_Absolute t_added; | ||
374 | |||
375 | /** | ||
366 | * Is this the active address for this peer? | 376 | * Is this the active address for this peer? |
367 | */ | 377 | */ |
368 | int active; | 378 | int active; |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 271dcdf8f..82a41d39f 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -714,14 +714,16 @@ find_best_address_it (void *cls, | |||
714 | const struct GNUNET_PeerIdentity *key, | 714 | const struct GNUNET_PeerIdentity *key, |
715 | void *value) | 715 | void *value) |
716 | { | 716 | { |
717 | struct FindBestAddressCtx *fba_ctx = (struct FindBestAddressCtx *) cls; | 717 | struct FindBestAddressCtx *ctx = (struct FindBestAddressCtx *) cls; |
718 | struct ATS_Address *current = (struct ATS_Address *) value; | 718 | struct ATS_Address *current = (struct ATS_Address *) value; |
719 | struct ATS_Address *current_best = (struct ATS_Address *) value; | ||
719 | struct GNUNET_TIME_Absolute now; | 720 | struct GNUNET_TIME_Absolute now; |
720 | struct AddressSolverInformation *asi; | 721 | struct AddressSolverInformation *asi; |
721 | const double *norm_prop_cur; | 722 | const double *norm_prop_cur; |
722 | const double *norm_prop_prev; | 723 | const double *norm_prop_best; |
723 | int index; | 724 | int index; |
724 | 725 | ||
726 | current_best = NULL; | ||
725 | asi = current->solver_information; | 727 | asi = current->solver_information; |
726 | now = GNUNET_TIME_absolute_get (); | 728 | now = GNUNET_TIME_absolute_get (); |
727 | 729 | ||
@@ -736,76 +738,71 @@ find_best_address_it (void *cls, | |||
736 | } | 738 | } |
737 | if (GNUNET_NO == is_bandwidth_available_in_network (asi->network)) | 739 | if (GNUNET_NO == is_bandwidth_available_in_network (asi->network)) |
738 | return GNUNET_OK; /* There's no bandwidth available in this network */ | 740 | return GNUNET_OK; /* There's no bandwidth available in this network */ |
739 | if (NULL != fba_ctx->best) | 741 | |
742 | if (NULL != ctx->best) | ||
740 | { | 743 | { |
741 | GNUNET_assert(NULL != fba_ctx->best->plugin); | 744 | /* Compare current addresses with denominated 'best' address */ |
742 | GNUNET_assert(NULL != current->plugin); | 745 | |
743 | if (0 == strcmp (fba_ctx->best->plugin, current->plugin)) | 746 | current_best = ctx->best; |
747 | if ((0 != ctx->best->addr_len) && (0 == current->addr_len)) | ||
744 | { | 748 | { |
745 | if ((0 != fba_ctx->best->addr_len) && (0 == current->addr_len)) | 749 | /* saved address was an outbound address, but we have an inbound address */ |
746 | { | 750 | current_best = current; |
747 | /* saved address was an outbound address, but we have an inbound address */ | 751 | goto end; |
748 | fba_ctx->best = current; | 752 | } |
749 | return GNUNET_OK; | 753 | if (ctx->best->t_last_activity.abs_value_us < current->t_last_activity.abs_value_us) |
750 | } | 754 | { |
751 | if (0 == fba_ctx->best->addr_len) | 755 | /* Current address is newer */ |
752 | { | 756 | current_best = current; |
753 | /* saved address was an inbound address, so do not overwrite */ | 757 | } |
754 | return GNUNET_OK; | 758 | if (ctx->best->t_added.abs_value_us < current->t_added.abs_value_us) |
755 | } | 759 | { |
760 | /* Current address is newer */ | ||
761 | current_best = current; | ||
762 | goto end; | ||
756 | } | 763 | } |
757 | } | 764 | } |
758 | if (NULL == fba_ctx->best) | 765 | if (NULL == ctx->best) |
759 | { | 766 | { |
760 | fba_ctx->best = current; | 767 | /* We do not have a 'best' address so take this address */ |
761 | return GNUNET_OK; | 768 | current_best = current; |
769 | goto end; | ||
762 | } | 770 | } |
763 | if ((ntohl (fba_ctx->best->assigned_bw_in.value__) == 0) | 771 | |
764 | && (ntohl (current->assigned_bw_in.value__) > 0)) | 772 | if ( (ntohl (ctx->best->assigned_bw_in.value__) == 0) && |
773 | (ntohl (current->assigned_bw_in.value__) > 0) ) | ||
765 | { | 774 | { |
766 | /* stick to existing connection */ | 775 | /* stick to existing connection */ |
767 | fba_ctx->best = current; | 776 | current_best = current; |
768 | return GNUNET_OK; | ||
769 | } | 777 | } |
770 | 778 | ||
771 | norm_prop_cur = fba_ctx->s->get_properties (fba_ctx->s->get_properties_cls, | 779 | /* Now compare ATS information */ |
780 | norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls, | ||
772 | (const struct ATS_Address *) current); | 781 | (const struct ATS_Address *) current); |
773 | norm_prop_prev = fba_ctx->s->get_properties (fba_ctx->s->get_properties_cls, | 782 | norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls, |
774 | (const struct ATS_Address *) fba_ctx->best); | 783 | (const struct ATS_Address *) ctx->best); |
775 | /* | 784 | |
776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s previous %.2f current %.2f\n", | ||
777 | "DISTANCE", norm_prop_cur[1], norm_prop_cur[1]); | ||
778 | */ | ||
779 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); | 785 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); |
780 | if (GNUNET_SYSERR == index) | 786 | if (GNUNET_SYSERR != index) |
781 | { | ||
782 | GNUNET_break(0); | ||
783 | return GNUNET_OK; | ||
784 | } | ||
785 | if (norm_prop_cur[index] < norm_prop_prev[index]) | ||
786 | { | 787 | { |
787 | /* user shorter distance */ | 788 | /* user shorter distance */ |
788 | fba_ctx->best = current; | 789 | if (norm_prop_cur[index] < norm_prop_best[index]) |
789 | return GNUNET_OK; | 790 | current_best = current; |
791 | else | ||
792 | current_best = ctx->best; | ||
790 | } | 793 | } |
791 | /* | 794 | |
792 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s previous %.2f current %.2f\n", | ||
793 | "DELAY", norm_prop_cur[1], norm_prop_cur[1]); | ||
794 | */ | ||
795 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); | 795 | index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); |
796 | if (GNUNET_SYSERR == index) | 796 | if (GNUNET_SYSERR != index) |
797 | { | 797 | { |
798 | GNUNET_break(0); | 798 | /* User connection with less delay */ |
799 | return GNUNET_OK; | 799 | if (norm_prop_cur[index] < norm_prop_best[index]) |
800 | } | 800 | current_best = current; |
801 | if (norm_prop_cur[index] < norm_prop_prev[index]) | 801 | else |
802 | { | 802 | current_best = ctx->best; |
803 | /* user shorter delay */ | ||
804 | fba_ctx->best = current; | ||
805 | return GNUNET_OK; | ||
806 | } | 803 | } |
807 | 804 | end: | |
808 | /* don't care */ | 805 | ctx->best = current_best; |
809 | return GNUNET_OK; | 806 | return GNUNET_OK; |
810 | } | 807 | } |
811 | 808 | ||