- changes
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 11 Dec 2012 10:41:09 +0000 (10:41 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 11 Dec 2012 10:41:09 +0000 (10:41 +0000)
src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_addresses_simplistic.c
src/ats/test_ats_api_scheduling_update_address.c

index 56232d6e25ed68156a1a6d6fa36000c143100b21..b94a7165624726a85d3996ebb1efa54e6593662f 100644 (file)
@@ -210,6 +210,8 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src,
       res ++;
       break;
     case GNUNET_ATS_QUALITY_NET_DISTANCE:
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Old ATS type %u %u\n", dest->atsp_distance, ntohl (src[i].type));
       dest->atsp_distance = ntohl (src[i].value);
       res ++;
       break;
@@ -465,7 +467,6 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
                        plugin_name,
                        plugin_addr, plugin_addr_len,
                        session_id);
-  aa->solver_information = NULL;
   if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa)))
   {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -484,10 +485,12 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n",
                 GNUNET_i2s (peer), session_id, aa);
-    /* Tell solver about update */
+    /* Tell solver about new address */
     handle->s_add (handle->solver, handle->addresses, aa);
     return;
   }
+  GNUNET_free (aa->plugin);
+  GNUNET_free (aa);
 
   if (old->session_id != 0)
   {
@@ -510,9 +513,8 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
                 "While updating address: had %u ATS elements to add, could only add %u\n",
                 atsi_count, ats_res);
   }
-  GNUNET_free (aa->plugin);
-  GNUNET_free (aa);
-  handle->s_add (handle->solver, handle->addresses, old);
+
+  handle->s_update (handle->solver, handle->addresses, old);
 }
 
 
@@ -523,23 +525,18 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
                       const struct GNUNET_ATS_Information *atsi,
                       uint32_t atsi_count)
 {
-  struct ATS_Address *old;
+  struct ATS_Address *aa;
   uint32_t ats_res;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Received `%s' for peer `%s'\n",
-                "ADDRESS UPDATE",
-                GNUNET_i2s (peer));
-
   if (GNUNET_NO == handle->running)
     return;
 
   GNUNET_assert (NULL != handle->addresses);
 
   /* Get existing address */
-  old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len,
+  aa = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len,
                        session_id, atsi, atsi_count);
-  if (old == NULL)
+  if (aa == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n",
                 GNUNET_i2s (peer), plugin_name, session_id);
@@ -547,15 +544,23 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
     return;
   }
 
-  if (atsi_count != (ats_res = disassemble_ats_information (atsi, atsi_count, old)))
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Received `%s' for peer `%s' address \n",
+                "ADDRESS UPDATE",
+                GNUNET_i2s (peer), aa);
+
+  if (atsi_count != (ats_res = disassemble_ats_information (atsi, atsi_count, aa)))
   {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "While adding address: had %u ATS elements to add, could only add %u\n",
                 atsi_count, ats_res);
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+            "Updated %u ATS elements for address %p\n",
+            ats_res, aa);
 
   /* Tell solver about update */
-  handle->s_update (handle->solver, handle->addresses, old);
+  handle->s_update (handle->solver, handle->addresses, aa);
 }
 
 
index 5405e9af57ac078dd255066449ad9581997797f6..94d6f5536527101e114079e2270f7190a1f8cc20 100644 (file)
@@ -51,7 +51,7 @@
  * QUOTA_PER_ADDRESS = LAN_TOTAL_OUT / x
  *
  * Quotas are automatically recalculated and reported back when addresses are
- * added, updated or deleted and can be requested using "get_prefered_address".
+ * - requested
  *
  */
 
@@ -98,6 +98,11 @@ struct Network
    */
   unsigned int active_addresses;
 
+  /**
+   * Number of total addresses for this network
+   */
+  unsigned int total_addresses;
+
   struct AddressWrapper *head;
   struct AddressWrapper *tail;
 };
@@ -152,6 +157,7 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   for (c = 0; c < dest_length; c++)
   {
       cur = &s->network_entries[c];
+      cur->total_addresses = 0;
       cur->active_addresses = 0;
       cur->type = network[c];
       cur->total_quota_in = in_quota[c];
@@ -193,13 +199,26 @@ GAS_simplistic_done (void *solver)
   GNUNET_free (s);
 }
 
+/**
+ * Update the quotas for a network type
+ *
+ * @param network the network type to update
+ * @param address_except address excluded from notifcation, since we suggest
+ * this address
+ */
+
 static void
-update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, struct Network *net)
+update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s,
+                          struct Network *net,
+                          struct ATS_Address *address_except)
 {
   unsigned long long quota_in;
   unsigned long long quota_out;
   struct AddressWrapper *cur;
 
+  if (net->active_addresses == 0)
+    return; /* no addresses to update */
+
   quota_in = net->total_quota_in / net->active_addresses;
   quota_out = net->total_quota_out / net->active_addresses;
 
@@ -217,7 +236,7 @@ update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s, struct Network *net)
         cur->addr->assigned_bw_in.value__ = htonl (quota_in);
         cur->addr->assigned_bw_out.value__ = htonl (quota_out);
         /* Notify on change */
-        if (GNUNET_YES == cur->addr->active)
+        if ((GNUNET_YES == cur->addr->active) && (cur->addr != address_except))
           s->bw_changed (cur->addr);
       }
       cur = cur->next;
@@ -255,16 +274,13 @@ GAS_simplistic_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap *
   aw = GNUNET_malloc (sizeof (struct AddressWrapper));
   aw->addr = address;
   GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, aw);
-  cur->active_addresses ++;
+  cur->total_addresses ++;
   aw->addr->solver_information = cur;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
               "Adding new address for network type `%s' (now %u total)\n",
               cur->desc,
               cur->active_addresses);
-
-  /* Update quota for this network type */
-  update_quota_per_network (s, cur);
 }
 
 
@@ -477,12 +493,12 @@ GAS_simplistic_get_preferred_address (void *solver,
       prev->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); /* no bw assigned */
       s->bw_changed (prev); /* notify about bw change, REQUIERED? */
       net_cur->active_addresses --;
-      update_quota_per_network (s, net_prev);
+      update_quota_per_network (s, net_prev, NULL);
   }
 
   cur->active = GNUNET_YES;
   net_cur->active_addresses ++;
-  update_quota_per_network (s, net_cur);
+  update_quota_per_network (s, net_cur, cur);
 
   return cur;
 }
index 702fe3f9ac54d6f6d28a9e3c35bd4207fece9f91..2a0f35d611a9b01e540a775cfab9e904ac0d8a4c 100644 (file)
@@ -66,7 +66,7 @@ static void *test_session;
 /**
  * Test ats info
  */
-struct GNUNET_ATS_Information test_ats_info[2];
+struct GNUNET_ATS_Information test_ats_info[3];
 
 /**
  * Test ats count
@@ -236,9 +236,11 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
     /* Update address */
     /* Prepare ATS Information */
     test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
-    test_ats_info[0].value = htonl(GNUNET_ATS_NET_LAN);
+    test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
     test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
     test_ats_info[1].value = htonl(3);
+    test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+    test_ats_info[1].value = htonl(30);
     test_ats_count = 2;
 
     GNUNET_ATS_address_update (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count);
@@ -311,6 +313,8 @@ run (void *cls,
   test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
   test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
   test_ats_info[1].value = htonl(1);
+  test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+  test_ats_info[1].value = htonl(10);
   test_ats_count = 2;
 
   /* Adding address without session */