ats_ril: fix: set address only active if address request for peer active
[oweals/gnunet.git] / src / ats / gnunet-service-ats-solver_mlp.c
index 299639de8d7ff38b5ca898b1751417cc8afbaec7..f921c1b1f952534f70922ea638684d1fef2dab47 100644 (file)
@@ -935,7 +935,6 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp)
   }
 }
 
-
 /**
  * Propagates the results when MLP problem was solved
  *
@@ -991,13 +990,16 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
     if (GNUNET_NO == address->active)
     {
             /* Address was not used before, enabling address */
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
-            address->active = GNUNET_YES;
-            address->assigned_bw_in.value__ = htonl (mlp_bw_in);
-            mlpi->b_in.value__ = htonl(mlp_bw_in);
-            address->assigned_bw_out.value__ = htonl (mlp_bw_out);
-            mlpi->b_out.value__ = htonl(mlp_bw_out);
-            mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n",
+          (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
+      address->active = GNUNET_YES;
+      address->assigned_bw_in.value__ = htonl (mlp_bw_in);
+      mlpi->b_in.value__ = htonl(mlp_bw_in);
+      address->assigned_bw_out.value__ = htonl (mlp_bw_out);
+      mlpi->b_out.value__ = htonl(mlp_bw_out);
+      if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
+        mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+      return GNUNET_OK;
     }
     else if (GNUNET_YES == address->active)
     {
@@ -1011,11 +1013,13 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
           mlpi->b_in.value__ = htonl(mlp_bw_in);
           address->assigned_bw_out.value__ = htonl (mlp_bw_out);
           mlpi->b_out.value__ = htonl(mlp_bw_out);
-          mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+          if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
+            mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+          return GNUNET_OK;
       }
     }
     else
-            GNUNET_break (0);
+      GNUNET_break (0);
   }
   else if (GLP_NO == mlp_use)
   {
@@ -1026,6 +1030,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
       /* Address was not used before, nothing to do */
       LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n",
           (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out);
+      return GNUNET_OK;
     }
     else if (GNUNET_YES == address->active)
     {
@@ -1039,6 +1044,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
       address->assigned_bw_out = BANDWIDTH_ZERO;
       mlpi->b_out.value__ = htonl(mlp_bw_out);
       //mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+      return GNUNET_OK;
     }
     else
       GNUNET_break (0);
@@ -1049,8 +1055,6 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
   return GNUNET_OK;
 }
 
-
-
 /**
  * Solves the MLP problem
  *
@@ -1144,7 +1148,9 @@ GAS_mlp_solve_problem (void *solver)
 
   /* Propagate result*/
   if ((GNUNET_OK == res_lp) && (GNUNET_OK == res_mip))
+  {
     GNUNET_CONTAINER_multihashmap_iterate (mlp->addresses, &mlp_propagate_results, mlp);
+  }
 
   struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get();
   if (GNUNET_YES == mlp->write_mip_mps)
@@ -1589,7 +1595,11 @@ GAS_mlp_get_preferred_address (void *solver,
       if ((GNUNET_YES == mlp->mlp_auto_solve)&&
           (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(mlp->addresses,
               &peer->hashPubKey)))
+      {
+        mlp->exclude_peer = peer;
         GAS_mlp_solve_problem (mlp);
+        mlp->exclude_peer = NULL;
+      }
   }
   /* Get prefered address */
   res = NULL;