gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r31543 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r31543 - gnunet/src/ats
Date: Wed, 18 Dec 2013 17:31:43 +0100

Author: wachs
Date: 2013-12-18 17:31:43 +0100 (Wed, 18 Dec 2013)
New Revision: 31543

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses.h
   gnunet/src/ats/plugin_ats_proportional.c
Log:
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


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2013-12-18 16:24:35 UTC 
(rev 31542)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2013-12-18 16:31:43 UTC 
(rev 31543)
@@ -762,6 +762,8 @@
   if (existing_address == NULL )
   {
     /* Add a new address */
+    new_address->t_added = GNUNET_TIME_absolute_get();
+    new_address->t_last_activity = GNUNET_TIME_absolute_get();
     GNUNET_assert(
         GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses,
                                                        peer,
@@ -816,6 +818,8 @@
       GNUNET_i2s (peer), existing_address, session_id,
       GNUNET_ATS_print_network_type (addr_net));
   /* We have an address without an session, update this address */
+  existing_address->t_added = GNUNET_TIME_absolute_get();
+  existing_address->t_last_activity = GNUNET_TIME_absolute_get();
   atsi_delta = NULL;
   atsi_delta_count = 0;
   if (GNUNET_YES
@@ -914,6 +918,7 @@
       "ADDRESS UPDATE", GNUNET_i2s (peer), aa);
 
   /* Update address */
+  aa->t_last_activity = GNUNET_TIME_absolute_get();
   if (session_id != aa->session_id)
   {
     /* Session changed */
@@ -1166,6 +1171,7 @@
 
   /* Tell solver about update */
   ea->used = in_use;
+  ea->t_last_activity = GNUNET_TIME_absolute_get();
   handle->env.sf.s_address_update_inuse (handle->solver, ea, ea->used);
   return GNUNET_OK;
 }

Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h       2013-12-18 16:24:35 UTC 
(rev 31542)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h       2013-12-18 16:31:43 UTC 
(rev 31543)
@@ -363,6 +363,16 @@
   struct GNUNET_TIME_Absolute blocked_until;
 
   /**
+   * Time when address had last activity (update, in uses)
+   */
+  struct GNUNET_TIME_Absolute t_last_activity;
+
+  /**
+   * Time when address was added
+   */
+  struct GNUNET_TIME_Absolute t_added;
+
+  /**
    * Is this the active address for this peer?
    */
   int active;

Modified: gnunet/src/ats/plugin_ats_proportional.c
===================================================================
--- gnunet/src/ats/plugin_ats_proportional.c    2013-12-18 16:24:35 UTC (rev 
31542)
+++ gnunet/src/ats/plugin_ats_proportional.c    2013-12-18 16:31:43 UTC (rev 
31543)
@@ -714,14 +714,16 @@
                      const struct GNUNET_PeerIdentity *key,
                      void *value)
 {
-  struct FindBestAddressCtx *fba_ctx = (struct FindBestAddressCtx *) cls;
+  struct FindBestAddressCtx *ctx = (struct FindBestAddressCtx *) cls;
   struct ATS_Address *current = (struct ATS_Address *) value;
+  struct ATS_Address *current_best = (struct ATS_Address *) value;
   struct GNUNET_TIME_Absolute now;
   struct AddressSolverInformation *asi;
   const double *norm_prop_cur;
-  const double *norm_prop_prev;
+  const double *norm_prop_best;
   int index;
 
+  current_best = NULL;
   asi = current->solver_information;
   now = GNUNET_TIME_absolute_get ();
 
@@ -736,76 +738,71 @@
   }
   if (GNUNET_NO == is_bandwidth_available_in_network (asi->network))
     return GNUNET_OK; /* There's no bandwidth available in this network */
-  if (NULL != fba_ctx->best)
+
+  if (NULL != ctx->best)
   {
-    GNUNET_assert(NULL != fba_ctx->best->plugin);
-    GNUNET_assert(NULL != current->plugin);
-    if (0 == strcmp (fba_ctx->best->plugin, current->plugin))
+    /* Compare current addresses with denominated 'best' address */
+
+    current_best = ctx->best;
+    if ((0 != ctx->best->addr_len) && (0 == current->addr_len))
     {
-      if ((0 != fba_ctx->best->addr_len) && (0 == current->addr_len))
-      {
-        /* saved address was an outbound address, but we have an inbound 
address */
-        fba_ctx->best = current;
-        return GNUNET_OK;
-      }
-      if (0 == fba_ctx->best->addr_len)
-      {
-        /* saved address was an inbound address, so do not overwrite */
-        return GNUNET_OK;
-      }
+      /* saved address was an outbound address, but we have an inbound address 
*/
+      current_best = current;
+      goto end;
     }
+    if (ctx->best->t_last_activity.abs_value_us < 
current->t_last_activity.abs_value_us)
+    {
+      /* Current address is newer */
+      current_best = current;
+    }
+    if (ctx->best->t_added.abs_value_us < current->t_added.abs_value_us)
+    {
+      /* Current address is newer */
+      current_best = current;
+      goto end;
+    }
   }
-  if (NULL == fba_ctx->best)
+  if (NULL == ctx->best)
   {
-    fba_ctx->best = current;
-    return GNUNET_OK;
+    /* We do not have a 'best' address so take this address */
+    current_best = current;
+    goto end;
   }
-  if ((ntohl (fba_ctx->best->assigned_bw_in.value__) == 0)
-      && (ntohl (current->assigned_bw_in.value__) > 0))
+
+  if ( (ntohl (ctx->best->assigned_bw_in.value__) == 0) &&
+       (ntohl (current->assigned_bw_in.value__) > 0) )
   {
     /* stick to existing connection */
-    fba_ctx->best = current;
-    return GNUNET_OK;
+    current_best = current;
   }
 
-  norm_prop_cur = fba_ctx->s->get_properties (fba_ctx->s->get_properties_cls,
+  /* Now compare ATS information */
+  norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls,
       (const struct ATS_Address *) current);
-  norm_prop_prev = fba_ctx->s->get_properties (fba_ctx->s->get_properties_cls,
-      (const struct ATS_Address *) fba_ctx->best);
-  /*
-   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s previous %.2f current %.2f\n",
-   "DISTANCE", norm_prop_cur[1], norm_prop_cur[1]);
-   */
+  norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls,
+      (const struct ATS_Address *) ctx->best);
+
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  if (GNUNET_SYSERR == index)
+  if (GNUNET_SYSERR != index)
   {
-    GNUNET_break(0);
-    return GNUNET_OK;
-  }
-  if (norm_prop_cur[index] < norm_prop_prev[index])
-  {
     /* user shorter distance */
-    fba_ctx->best = current;
-    return GNUNET_OK;
+    if (norm_prop_cur[index] < norm_prop_best[index])
+      current_best = current;
+    else
+      current_best = ctx->best;
   }
-  /*
-   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s previous %.2f current %.2f\n",
-   "DELAY", norm_prop_cur[1], norm_prop_cur[1]);
-   */
+
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
-  if (GNUNET_SYSERR == index)
+  if (GNUNET_SYSERR != index)
   {
-    GNUNET_break(0);
-    return GNUNET_OK;
+    /* User connection with less delay */
+    if (norm_prop_cur[index] < norm_prop_best[index])
+      current_best = current;
+    else
+      current_best = ctx->best;
   }
-  if (norm_prop_cur[index] < norm_prop_prev[index])
-  {
-    /* user shorter delay */
-    fba_ctx->best = current;
-    return GNUNET_OK;
-  }
-
-  /* don't care */
+end:
+  ctx->best = current_best;
   return GNUNET_OK;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]