summaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_proportional.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-18 16:31:43 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-18 16:31:43 +0000
commit397b5c300a1c0ea3521191c69a325f6d9166ebb0 (patch)
tree4fbe80dde2cb52d4c96a423ff14228dcb4458418 /src/ats/plugin_ats_proportional.c
parenta4ae4a97527fc6532aa9b7a0f20d1a2f5d7b73ba (diff)
downloadgnunet-397b5c300a1c0ea3521191c69a325f6d9166ebb0.tar.gz
gnunet-397b5c300a1c0ea3521191c69a325f6d9166ebb0.zip
idea: try to prefer 'newer' addresses to improve mobility issues
adding time of add and time of last activity information, to allow to choose 'newer' address
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r--src/ats/plugin_ats_proportional.c105
1 files changed, 51 insertions, 54 deletions
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 804end:
808 /* don't care */ 805 ctx->best = current_best;
809 return GNUNET_OK; 806 return GNUNET_OK;
810} 807}
811 808