(no commit message)
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 14 Oct 2011 12:25:48 +0000 (12:25 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 14 Oct 2011 12:25:48 +0000 (12:25 +0000)
src/ats/gnunet-service-ats_addresses.c
src/ats/test_ats_api.conf
src/ats/test_ats_api_scheduling.c

index e7da7dca3079e1870209831dea5ec4f5c2516b2b..8a79889f3f0a7af89f63061e90bea0d997655d68 100644 (file)
@@ -26,7 +26,7 @@
  */
 #include "platform.h"
 #include "gnunet-service-ats_addresses.h"
-
+#include "gnunet-service-ats_scheduling.h"
 
 struct ATS_Address
 {
@@ -45,6 +45,10 @@ struct ATS_Address
   char * plugin;
 
   struct GNUNET_TRANSPORT_ATS_Information * ats;
+
+  struct GNUNET_BANDWIDTH_Value32NBO bw_in;
+
+  struct GNUNET_BANDWIDTH_Value32NBO bw_out;
 };
 
 
@@ -100,19 +104,27 @@ find_address (const struct GNUNET_PeerIdentity *peer,
 static void
 merge_ats (struct ATS_Address * dest, struct ATS_Address * source)
 {
+  /*
   int c_src = 0;
   int c_dest = 0;
   struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats;
   struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats;
 
+  int new_entries = dest->ats_count;
+
   for (c_dest = 0; c_dest < dest->ats_count; c_dest ++)
   {
     for (c_src = 0; c_src < source->ats_count; c_src ++)
     {
       if (a_src[c_src].type == a_dest[c_dest].type)
-        a_src[c_src].value = a_dest[c_dest].value;
+        new_entries--;
     }
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    "Have %u new entries\n",
+    new_entries);
+*/
 }
 
 void
@@ -128,14 +140,14 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
   struct ATS_Address * old;
 
   aa = GNUNET_malloc (sizeof (struct ATS_Address) +
-                    atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
-                    plugin_addr_len);
+                      plugin_addr_len);
+  aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+
   aa->peer = *peer;
   aa->addr_len = plugin_addr_len;
   aa->ats_count = atsi_count;
-  aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];
-  memcpy (&aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
-  aa->addr = &aa->ats[atsi_count];
+  memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+  aa->addr = &aa[1];
   memcpy (&aa->addr, plugin_addr, plugin_addr_len);
   aa->plugin = GNUNET_strdup (plugin_name);
   aa->session_client = session_client;
@@ -150,15 +162,16 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
                                                      aa,
                                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Added new address for peer `%s' \n",
-      GNUNET_i2s (peer));
+      "Added new address for peer `%s' %X\n",
+      GNUNET_i2s (peer), aa);
   }
   else
   {
     merge_ats (old, aa);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-      "Updated existing address for peer `%s' \n",
-      GNUNET_i2s (peer));
+      "Updated existing address for peer `%s' %X \n",
+      GNUNET_i2s (peer), old);
+    GNUNET_free (aa->ats);
     GNUNET_free (aa);
   }
 
@@ -192,6 +205,7 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
   GNUNET_break (GNUNET_YES ==
                GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res));
   GNUNET_free (res->plugin);
+  GNUNET_free_non_null (res->ats);
   GNUNET_free (res);
 
 }
@@ -200,8 +214,10 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
 void
 GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
 {
-
-
+  struct ATS_Address * aa = NULL;
+  aa = GNUNET_CONTAINER_multihashmap_get (addresses, &peer->hashPubKey);
+  if (aa != NULL)
+    GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, aa->addr_len, aa->session_client, aa->session_id, aa->ats, aa->ats_count, aa->bw_out, aa->bw_in);
 }
 
 
@@ -228,7 +244,10 @@ free_address_it (void *cls,
                 const GNUNET_HashCode * key,
                 void *value)
 {
-  struct ATS_Address * aa = cls;
+  struct ATS_Address * aa = value;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    "Freeing address for peer `%s' %X\n",
+    GNUNET_i2s (&aa->peer), aa);
   GNUNET_free (aa);
   return GNUNET_OK;
 }
index 8ee71a7e85b32cc2fe724c1faa6b6d52d519f90f..c2bb1942d298dfc26c4e27bd617e0911014114ae 100644 (file)
@@ -7,6 +7,7 @@ DEFAULTSERVICES = ats
 UNIXPATH = /tmp/test-ats-scheduling-arm.sock
 
 [ats]
+DEBUG = YES
 AUTOSTART = YES
 PORT = 12002
 HOSTNAME = localhost
index 68026e1965b1549a548f9f6669483f71c197f621..4ed68ba8792b39eea233e3786f7f4a2d7af0300f 100644 (file)
@@ -34,7 +34,7 @@
 #include "gnunet_ats_service.h"
 #include "ats.h"
 
-#define VERBOSE GNUNET_EXTRA_LOGGING
+#define VERBOSE GNUNET_YES
 
 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
 
@@ -46,6 +46,10 @@ static struct GNUNET_ATS_SchedulingHandle *ats;
 
 struct GNUNET_OS_Process * arm_proc;
 
+struct Address addr;
+struct PeerContext p;
+struct GNUNET_TRANSPORT_ATS_Information atsi[2];
+
 static int ret;
 
 struct Address
@@ -97,6 +101,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 end ()
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
   if (die_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel(die_task);
@@ -132,9 +137,26 @@ address_suggest_cb (void *cls,
                     uint32_t ats_count)
 
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address_suggest_cb `%s'\n", GNUNET_i2s (peer));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer));
+
+  GNUNET_assert (0 == memcmp (peer, &p.id, sizeof (struct GNUNET_PeerIdentity)));
+  GNUNET_assert (0 == strcmp (plugin_name, addr.plugin));
+  GNUNET_assert (plugin_addr_len == addr.addr_len);
+  GNUNET_assert (0 == memcmp (plugin_addr, addr.plugin, plugin_addr_len));
+  GNUNET_assert (addr.session == session);
+
+
+  /* TODO ats merge
+  GNUNET_assert (ats_count == 2);
+  GNUNET_assert (atsi[0].type == htons (1));
+  GNUNET_assert (atsi[0].type == htons (2));
+  GNUNET_assert (atsi[1].type == htons (2));
+  GNUNET_assert (atsi[1].type == htons (2));
+  */
+
+  ret = 0;
 
-  end ();
+  GNUNET_SCHEDULER_add_now(&end, NULL);
 }
 
 void
@@ -153,8 +175,6 @@ check (void *cls, char *const *args, const char *cfgfile,
        const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   ret = GNUNET_SYSERR;
-  struct Address addr;
-  struct PeerContext p;
 
   die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
   start_arm (cfgfile);
@@ -181,6 +201,20 @@ check (void *cls, char *const *args, const char *cfgfile,
 
   GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
 
+  atsi[0].type = htons (1);
+  atsi[0].type = htons (1);
+
+  GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 1);
+
+  atsi[0].type = htons (1);
+  atsi[0].type = htons (2);
+
+  atsi[1].type = htons (2);
+  atsi[1].type = htons (2);
+
+  GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 2);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p.id));
   GNUNET_ATS_suggest_address(ats, &p.id);
 }