gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r16732 - gnunet/src/ats
Date: Thu, 8 Sep 2011 18:02:03 +0200

Author: wachs
Date: 2011-09-08 18:02:02 +0200 (Thu, 08 Sep 2011)
New Revision: 16732

Modified:
   gnunet/src/ats/ats_api.c
Log:
merging ats arrays
is working but needs an additional testcase


Modified: gnunet/src/ats/ats_api.c
===================================================================
--- gnunet/src/ats/ats_api.c    2011-09-08 08:39:26 UTC (rev 16731)
+++ gnunet/src/ats/ats_api.c    2011-09-08 16:02:02 UTC (rev 16732)
@@ -486,7 +486,11 @@
   struct AllocationRecord *arnew = usc->arnew;
   struct AllocationRecord *arold = value;
   int change;
+  int c_old;
+  int c_new;
+  int found;
 
+
 #if DEBUG_ATS
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
                    "Updating session for peer `%s' plugin `%s'\n",
@@ -514,8 +518,53 @@
       arold->connected = GNUNET_YES;
       change = GNUNET_YES;
     }
-    // FIXME: merge ats arrays of (arold, arnew);
 
+    /* Update existing value */
+    c_new = 0;
+    while (c_new < arnew->ats_count)
+    {
+      c_old = 0;
+      found = GNUNET_NO;
+      while (c_old < arold->ats_count)
+      {
+        if (arold->ats[c_old].type == arnew->ats[c_new].type)
+        {
+#if DEBUG_ATS
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                      "Found type %u, old value=%u new value=%u\n",
+                      ntohl (arold->ats[c_old].type),
+                      ntohl (arold->ats[c_old].value),
+                      ntohl (arnew->ats[c_new].value));
+#endif
+          arold->ats[c_old].value = arnew->ats[c_new].value;
+          found = GNUNET_YES;
+        }
+        c_old++;
+      }
+      /* Add new value */
+      if (found == GNUNET_NO)
+      {
+#if DEBUG_ATS
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Added new value type %u, old value=%u new value=%u\n",
+                    ntohl (arnew->ats[c_new].type),
+                    ntohl (arnew->ats[c_new].value));
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n",
+                    arold->ats_count);
+#endif
+        GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1);
+        arold->ats[arold->ats_count - 1].type = arnew->ats[c_new].type;
+        arold->ats[arold->ats_count - 1].value = arnew->ats[c_new].value;
+        arold->ats[arold->ats_count].type = htonl (0);
+        arold->ats[arold->ats_count].value = htonl (0);
+#if DEBUG_ATS
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n",
+                    arold->ats_count);
+#endif
+      }
+      c_new++;
+    }
+
     if (GNUNET_YES == change)
       update_bandwidth_assignment (usc->atc, arold);
     return GNUNET_NO;




reply via email to

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