gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r25383 - gnunet/src/ats
Date: Tue, 11 Dec 2012 11:41:09 +0100

Author: wachs
Date: 2012-12-11 11:41:09 +0100 (Tue, 11 Dec 2012)
New Revision: 25383

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
   gnunet/src/ats/test_ats_api_scheduling_update_address.c
Log:
- changes


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2012-12-11 10:08:48 UTC 
(rev 25382)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2012-12-11 10:41:09 UTC 
(rev 25383)
@@ -210,6 +210,8 @@
       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 @@
                        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 @@
                                                       
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 @@
                 "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 @@
                       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 @@
     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);
 }
 
 

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2012-12-11 
10:08:48 UTC (rev 25382)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2012-12-11 
10:41:09 UTC (rev 25383)
@@ -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 @@
    */
   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 @@
   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 @@
   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 @@
         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 @@
   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 @@
       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;
 }

Modified: gnunet/src/ats/test_ats_api_scheduling_update_address.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_update_address.c     2012-12-11 
10:08:48 UTC (rev 25382)
+++ gnunet/src/ats/test_ats_api_scheduling_update_address.c     2012-12-11 
10:41:09 UTC (rev 25383)
@@ -66,7 +66,7 @@
 /**
  * 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 @@
     /* 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 @@
   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 */




reply via email to

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