gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r26730 - gnunet/src/ats
Date: Wed, 3 Apr 2013 11:24:29 +0200

Author: wachs
Date: 2013-04-03 11:24:29 +0200 (Wed, 03 Apr 2013)
New Revision: 26730

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses.h
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
   gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
   gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h
   gnunet/src/ats/perf_ats_mlp.c
   gnunet/src/ats/test_ats_api_scheduling_update_address.c
   gnunet/src/ats/test_ats_mlp.c
   gnunet/src/ats/test_ats_mlp_update.c
Log:
api change, fix and improvements


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2013-04-03 07:59:52 UTC 
(rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2013-04-03 09:24:29 UTC 
(rev 26730)
@@ -397,17 +397,21 @@
   change = GNUNET_NO;
   add_atsi_count = 0;
 
+  if (0 == ats_count)
+       return GNUNET_NO;
+
   if (NULL == dest->atsi)
   {
+               /* Create performance information */
                dest->atsi = GNUNET_malloc (ats_count * sizeof (struct 
GNUNET_ATS_Information));
                dest->atsi_count = ats_count;
                memcpy (dest->atsi, src, ats_count * sizeof (struct 
GNUNET_ATS_Information));
                return GNUNET_YES;
   }
 
-  /* Update existing performance information */
   for (c1 = 0; c1 < ats_count; c1++)
   {
+       /* Update existing performance information */
        found = GNUNET_NO;
        for (c2 = 0; c2 < dest->atsi_count; c2++)
        {
@@ -431,10 +435,14 @@
 
   if (add_atsi_count > 0)
   {
+               /* Extend ats performance information */
                tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) *
                                sizeof (sizeof (struct 
GNUNET_ATS_Information)));
                memcpy (tmp_atsi, dest->atsi, dest->atsi_count * sizeof (struct 
GNUNET_ATS_Information));
                memcpy (&tmp_atsi[dest->atsi_count], add_atsi, add_atsi_count * 
sizeof (struct GNUNET_ATS_Information));
+               GNUNET_free (dest->atsi);
+               dest->atsi = tmp_atsi;
+               dest->atsi_count = dest->atsi_count + add_atsi_count;
                        change = GNUNET_YES;
   }
 
@@ -673,8 +681,31 @@
   return ea;
 }
 
+/**
+ * Extract an ATS performance info from an address
+ *
+ * @param address the address
+ * @param type the type to extract in HBO
+ * @return the value in HBO or UINT32_MAX in HBO if value does not exist
+ */
+static int
+get_performance_info (struct ATS_Address *address, uint32_t type)
+{
+       int c1;
+       GNUNET_assert (NULL != address);
 
+       if ((NULL == address->atsi) || (0 == address->atsi_count))
+                       return UINT32_MAX;
 
+       for (c1 = 0; c1 < address->atsi_count; c1++)
+       {
+                       if (ntohl(address->atsi[c1].type) == type)
+                               return ntohl(address->atsi[c1].value);
+       }
+       return UINT32_MAX;
+}
+
+
 /**
  * Add a new address for a peer.
  *
@@ -697,7 +728,7 @@
 {
   struct ATS_Address *aa;
   struct ATS_Address *ea;
-  unsigned int ats_res;
+  uint32_t addr_net;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' for peer `%s'\n",
@@ -711,14 +742,8 @@
 
   aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
                        session_id);
+  disassemble_ats_information (atsi, atsi_count, 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);
-  }
-
   /* Get existing address or address with session == 0 */
   ea = find_equivalent_address (handle, peer, aa);
   if (ea == NULL)
@@ -730,8 +755,11 @@
                                                       
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);
+    addr_net = get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE);
+    if (UINT32_MAX == addr_net)
+       addr_net = GNUNET_ATS_NET_UNSPECIFIED;
     /* Tell solver about new address */
-    handle->s_add (handle->solver, handle->addresses, aa);
+    handle->s_add (handle->solver, handle->addresses, aa, addr_net);
     /* Notify performance clients about new address */
     GAS_performance_notify_all_clients (&aa->peer,
         aa->plugin,
@@ -742,7 +770,9 @@
         aa->assigned_bw_in);
     return;
   }
+
   GNUNET_free (aa->plugin);
+  GNUNET_free_non_null (aa->atsi);
   GNUNET_free (aa);
 
   if (ea->session_id != 0)

Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h       2013-04-03 07:59:52 UTC 
(rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h       2013-04-03 09:24:29 UTC 
(rev 26730)
@@ -408,17 +408,20 @@
                                          enum GNUNET_ATS_PreferenceKind kind,
                                          float score);
 
+
 /**
- * Add a single address to the solver
+ * Add a single address within a network to the solver
  *
  * @param solver the solver Handle
  * @param addresses the address hashmap containing all addresses
  * @param address the address to add
+ * @param network network type of this address
  */
 typedef void
 (*GAS_solver_address_add) (void *solver,
-                           struct GNUNET_CONTAINER_MultiHashMap * addresses,
-                           struct ATS_Address *address);
+                                                                               
                                struct GNUNET_CONTAINER_MultiHashMap *addresses,
+                                                                               
                                struct ATS_Address *address,
+                                                                               
                                uint32_t network);
 
 
 /**

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-04-03 07:59:52 UTC 
(rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-04-03 09:24:29 UTC 
(rev 26730)
@@ -1040,10 +1040,13 @@
  *
  * @param solver the solver Handle
  * @param addresses the address hashmap containing all addresses
- * @param address the address to add
+ * @param network network type of this address
  */
 void
-GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * 
addresses, struct ATS_Address *address)
+GAS_mlp_address_add (void *solver,
+                                                                               
struct GNUNET_CONTAINER_MultiHashMap *addresses,
+                                                                               
struct ATS_Address *address,
+                                                                               
uint32_t network)
 {
   struct GAS_MLP_Handle *mlp = solver;
   struct ATS_Peer *p;

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2013-04-03 07:59:52 UTC 
(rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2013-04-03 09:24:29 UTC 
(rev 26730)
@@ -363,14 +363,18 @@
 
 
 /**
- * Add a single address to the solve
+ * Add a single address within a network to the solver
  *
  * @param solver the solver Handle
  * @param addresses the address hashmap containing all addresses
  * @param address the address to add
+ * @param network network type of this address
  */
 void
-GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * 
addresses, struct ATS_Address *address);
+GAS_mlp_address_add (void *solver,
+                                                                               
struct GNUNET_CONTAINER_MultiHashMap *addresses,
+                                                                               
struct ATS_Address *address,
+                                                                               
uint32_t network);
 
 /**
  * Updates a single address in the MLP problem

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2013-04-03 
07:59:52 UTC (rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2013-04-03 
09:24:29 UTC (rev 26730)
@@ -791,31 +791,29 @@
 
 
 /**
- * Add a single address to the solve
+ * Add a single address within a network to the solver
  *
  * @param solver the solver Handle
  * @param addresses the address hashmap containing all addresses
  * @param address the address to add
+ * @param network network type of this address
  */
 void
-GAS_simplistic_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap 
* addresses, struct ATS_Address *address)
+GAS_simplistic_address_add (void *solver,
+                                                                               
                                struct GNUNET_CONTAINER_MultiHashMap *addresses,
+                                                                               
                                struct ATS_Address *address,
+                                                                               
                                uint32_t network)
 {
   struct GAS_SIMPLISTIC_Handle *s = solver;
   struct Network *net = NULL;
   struct AddressWrapper *aw = NULL;
-  uint32_t addr_net;
+  int c;
 
   GNUNET_assert (NULL != s);
-  int c;
-
-  addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
-  if (UINT32_MAX == addr_net)
-       addr_net = GNUNET_ATS_NET_UNSPECIFIED;
-
   for (c = 0; c < s->networks; c++)
   {
       net = &s->network_entries[c];
-      if (addr_net == net->type)
+      if (network == net->type)
           break;
   }
   if (NULL == net)
@@ -1008,7 +1006,7 @@
         address->solver_information = new_net;
 
         /* Add to new network and update*/
-        GAS_simplistic_address_add (solver, addresses, address);
+        GAS_simplistic_address_add (solver, addresses, address, value);
         if (GNUNET_YES == save_active)
         {
           /* check if bandwidth available in new network */

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h    2013-04-03 
07:59:52 UTC (rev 26729)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h    2013-04-03 
09:24:29 UTC (rev 26730)
@@ -80,14 +80,18 @@
 GAS_simplistic_done (void * solver);
 
 /**
- * Add a single address to the solve
+ * Add a single address within a network to the solver
  *
  * @param solver the solver Handle
  * @param addresses the address hashmap containing all addresses
  * @param address the address to add
+ * @param network network type of this address
  */
 void
-GAS_simplistic_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap 
* addresses, struct ATS_Address *address);
+GAS_simplistic_address_add (void *solver,
+                                                                               
                                struct GNUNET_CONTAINER_MultiHashMap *addresses,
+                                                                               
                                struct ATS_Address *address,
+                                                                               
                                uint32_t network);
 
 
 /**

Modified: gnunet/src/ats/perf_ats_mlp.c
===================================================================
--- gnunet/src/ats/perf_ats_mlp.c       2013-04-03 07:59:52 UTC (rev 26729)
+++ gnunet/src/ats/perf_ats_mlp.c       2013-04-03 09:24:29 UTC (rev 26730)
@@ -320,7 +320,7 @@
                        {
                                        cur_addr = perf_create_address(cp, ca);
                                        /* add address */
-                                       GAS_mlp_address_add (mlp, addresses, 
cur_addr);
+                                       GAS_mlp_address_add (mlp, addresses, 
cur_addr, GNUNET_ATS_NET_UNSPECIFIED);
                                        address_initial_update (mlp, addresses, 
cur_addr);
                                        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
"Adding address for peer %u address %u: \n", cp, ca);
                        }

Modified: gnunet/src/ats/test_ats_api_scheduling_update_address.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_update_address.c     2013-04-03 
07:59:52 UTC (rev 26729)
+++ gnunet/src/ats/test_ats_api_scheduling_update_address.c     2013-04-03 
09:24:29 UTC (rev 26730)
@@ -128,7 +128,8 @@
       return;
     }
 
-    if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, 
test_ats_count))
+    if ((ats_count != test_ats_count) ||
+               (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, 
test_ats_count)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect 
ats info \n");
       ret = 1;
@@ -141,10 +142,10 @@
     test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
     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;
+    test_ats_info[1].value = htonl(5);
+    test_ats_info[2].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+    test_ats_info[2].value = htonl(30);
+    test_ats_count = 3;
 
     GNUNET_ATS_address_update (sched_ats, &test_hello_address, test_session, 
test_ats_info, test_ats_count);
 
@@ -168,7 +169,8 @@
         ret = 1;
       }
 
-      if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, 
test_ats_count))
+      if ((ats_count != test_ats_count) ||
+               (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, 
test_ats_count)))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Callback with incorrect 
ats info \n");
         ret = 1;
@@ -214,8 +216,6 @@
   /* Prepare ATS Information */
   test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
   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;

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2013-04-03 07:59:52 UTC (rev 26729)
+++ gnunet/src/ats/test_ats_mlp.c       2013-04-03 09:24:29 UTC (rev 26730)
@@ -233,7 +233,7 @@
   GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
   /* Adding address 0 */
-  GAS_mlp_address_add (mlp, addresses, address[0]);
+  GAS_mlp_address_add (mlp, addresses, address[0], GNUNET_ATS_NET_UNSPECIFIED);
 
   /* Create address 1 */
   address[1] = create_address (&p[0], "test_plugin1", "test_addr1", 
strlen("test_addr1")+1, 0);
@@ -246,7 +246,7 @@
   GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
   /* Adding address 1*/
-  GAS_mlp_address_add (mlp, addresses, address[1]);
+  GAS_mlp_address_add (mlp, addresses, address[1], GNUNET_ATS_NET_UNSPECIFIED);
 
 
   /* Create address 3 */
@@ -260,7 +260,7 @@
   GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
   /* Adding address 3*/
-  GAS_mlp_address_add (mlp, addresses, address[2]);
+  GAS_mlp_address_add (mlp, addresses, address[2], GNUNET_ATS_NET_UNSPECIFIED);
 
 
   /* Updating address 0*/

Modified: gnunet/src/ats/test_ats_mlp_update.c
===================================================================
--- gnunet/src/ats/test_ats_mlp_update.c        2013-04-03 07:59:52 UTC (rev 
26729)
+++ gnunet/src/ats/test_ats_mlp_update.c        2013-04-03 09:24:29 UTC (rev 
26730)
@@ -220,7 +220,7 @@
   GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
                GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
   /* Adding address 0 */
-  GAS_mlp_address_add (mlp, addresses, address[0]);
+  GAS_mlp_address_add (mlp, addresses, address[0], GNUNET_ATS_NET_UNSPECIFIED);
 
   /* Retrieving preferred address for peer and wait for callback */
   GAS_mlp_get_preferred_address (mlp, addresses, &p[0]);




reply via email to

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