gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r25254 - gnunet/src/ats
Date: Wed, 5 Dec 2012 15:06:58 +0100

Author: wachs
Date: 2012-12-05 15:06:58 +0100 (Wed, 05 Dec 2012)
New Revision: 25254

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_mlp.c
   gnunet/src/ats/test_ats_mlp_averaging.c
Log:
commit required ... things can be broken

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2012-12-05 13:56:23 UTC 
(rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2012-12-05 14:06:58 UTC 
(rev 25254)
@@ -36,8 +36,9 @@
 #endif
 #include "gnunet-service-ats_addresses_simplistic.h"
 
-#define ATS_BLOCKING_DELTA 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
 
+#define BIG_M_VALUE (UINT32_MAX) /10
+#define BIG_M_STRING "unlimited"
 
 /**
  * Available ressource assignment modes
@@ -760,95 +761,6 @@
 }
 
 
-/**
- * Find a "good" address to use for a peer.  If we already have an existing
- * address, we stick to it.  Otherwise, we pick by lowest distance and then
- * by lowest latency.
- *
- * @param cls the 'struct ATS_Address**' where we store the result
- * @param key unused
- * @param value another 'struct ATS_Address*' to consider using
- * @return GNUNET_OK (continue to iterate)
- */
-static int
-find_address_it (void *cls, const struct GNUNET_HashCode * key, void *value)
-{
-  struct ATS_Address **ap = cls;
-  struct ATS_Address *aa = (struct ATS_Address *) value;
-  struct ATS_Address *ab = *ap;
-  struct GNUNET_TIME_Absolute now;
-
-  now = GNUNET_TIME_absolute_get();
-
-  if (aa->blocked_until.abs_value == GNUNET_TIME_absolute_max (now, 
aa->blocked_until).abs_value)
-  {
-    /* This address is blocked for suggestion */
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Address %p blocked for suggestion for %llu ms \n",
-                aa,
-                GNUNET_TIME_absolute_get_difference(now, 
aa->blocked_until).rel_value);
-    return GNUNET_OK;
-  }
-
-  aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval, 
ATS_BLOCKING_DELTA);
-  aa->blocked_until = GNUNET_TIME_absolute_add (now, aa->block_interval);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Address %p ready for suggestion, block interval now %llu \n", 
aa, aa->block_interval);
-
-  /* FIXME this is a hack */
-
-
-  if (NULL != ab)
-  {
-    if ((0 == strcmp (ab->plugin, "tcp")) &&
-        (0 == strcmp (aa->plugin, "tcp")))
-    {
-      if ((0 != ab->addr_len) &&
-          (0 == aa->addr_len))
-      {
-        /* saved address was an outbound address, but we have an inbound 
address */
-        *ap = aa;
-        return GNUNET_OK;
-      }
-      if (0 == ab->addr_len)
-      {
-        /* saved address was an inbound address, so do not overwrite */
-        return GNUNET_OK;
-      }
-    }
-  }
-  /* FIXME end of hack */
-
-  if (NULL == ab)
-  {
-    *ap = aa;
-    return GNUNET_OK;
-  }
-  if ((ntohl (ab->assigned_bw_in.value__) == 0) &&
-      (ntohl (aa->assigned_bw_in.value__) > 0))
-  {
-    /* stick to existing connection */
-    *ap = aa;
-    return GNUNET_OK;
-  }
-  if (ab->atsp_distance > aa->atsp_distance)
-  {
-    /* user shorter distance */
-    *ap = aa;
-    return GNUNET_OK;
-  }
-  if (ab->atsp_latency.rel_value > aa->atsp_latency.rel_value)
-  {
-    /* user lower latency */
-    *ap = aa;
-    return GNUNET_OK;
-  }
-  /* don't care */
-  return GNUNET_OK;
-}
-
-
 int
 GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer,
                       const char *plugin_name, const void *plugin_addr,
@@ -938,46 +850,7 @@
 }
 
 
-static void 
-request_address_simple (const struct GNUNET_PeerIdentity *peer)
-{
-  struct ATS_Address *aa;
-  aa = NULL;
 
-  /* Get address with: stick to current address, lower distance, lower latency 
*/
-  GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, 
&peer->hashPubKey,
-                                              &find_address_it, &aa);
-  if (aa == NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
-                "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
-    return;
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
-              "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer));
-
-  if (aa->active == GNUNET_NO)
-  {
-    aa->active = GNUNET_YES;
-    handle->active_addr_count++;
-    if (handle->ats_mode == MODE_SIMPLISTIC)
-    {
-      recalculate_assigned_bw ();
-    }
-  }
-  else
-  {
-    /* just to be sure... */
-    GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
-                                                aa->addr_len, aa->session_id,
-                                                aa->ats, aa->ats_count,
-                                                aa->assigned_bw_out,
-                                                aa->assigned_bw_in);
-  }
-}
-
-
 /**
  * Cancel address suggestions for a peer
  *
@@ -1013,6 +886,9 @@
 GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
 {
   struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head;
+  struct ATS_Address *aa;
+  struct GNUNET_ATS_Information *ats;
+  unsigned int ats_count;
 
   if (GNUNET_NO == handle->running)
     return;
@@ -1028,14 +904,25 @@
       cur->id = (*peer);
       GNUNET_CONTAINER_DLL_insert (handle->r_head, handle->r_tail, cur);
   }
-  if (handle->ats_mode == MODE_SIMPLISTIC)
-  {
-    request_address_simple (peer);
-  }
-  if (handle->ats_mode == MODE_MLP)
-  {
-    request_address_mlp(peer);
-  }
+
+  aa = handle->s_get (handle->solver, handle->addresses, peer);
+  if (NULL == aa)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s 
(peer));
+
+  ats_count = assemble_ats_information (aa, &ats);
+  GAS_scheduling_transmit_address_suggestion (peer,
+                                              aa->plugin,
+                                              aa->addr, aa->addr_len,
+                                              aa->session_id,
+                                              ats, ats_count,
+                                              aa->assigned_bw_out,
+                                              aa->assigned_bw_in);
+  GNUNET_free (ats);
+
 }
 
 
@@ -1045,7 +932,8 @@
   struct ATS_Address *aa = value;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Resetting interval for peer `%s' address %p from %llu to 0\n", 
GNUNET_i2s (&aa->peer), aa, aa->block_interval);
+              "Resetting interval for peer `%s' address %p from %llu to 0\n",
+              GNUNET_i2s (&aa->peer), aa, aa->block_interval);
 
   aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS;
   aa->block_interval = GNUNET_TIME_UNIT_ZERO;
@@ -1075,8 +963,89 @@
   handle->s_pref (handle->solver, peer, kind, score);
 }
 
+static unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long 
*out_dest, unsigned long long *in_dest, int dest_length)
+{
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  char * entry_in = NULL;
+  char * entry_out = NULL;
+  char * quota_out_str;
+  char * quota_in_str;
+  int c;
 
+  for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+  {
+    in_dest[c] = 0;
+    out_dest[c] = 0;
+    switch (quotas[c]) {
+      case GNUNET_ATS_NET_UNSPECIFIED:
+        entry_out = "UNSPECIFIED_QUOTA_OUT";
+        entry_in = "UNSPECIFIED_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LOOPBACK:
+        entry_out = "LOOPBACK_QUOTA_OUT";
+        entry_in = "LOOPBACK_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LAN:
+        entry_out = "LAN_QUOTA_OUT";
+        entry_in = "LAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WAN:
+        entry_out = "WAN_QUOTA_OUT";
+        entry_in = "WAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WLAN:
+        entry_out = "WLAN_QUOTA_OUT";
+        entry_in = "WLAN_QUOTA_IN";
+        break;
+      default:
+        break;
+    }
 
+    if ((entry_in == NULL) || (entry_out == NULL))
+      continue;
+
+    /* quota out */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_out, &quota_out_str))
+    {
+      if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 
&out_dest[c])))
+        out_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_out_str);
+      quota_out_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+      out_dest[c] = UINT32_MAX;
+    else
+      out_dest[c] = UINT32_MAX;
+
+    /* quota in */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_in, &quota_in_str))
+    {
+      if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, 
&in_dest[c])))
+        in_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_in_str);
+      quota_in_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+    {
+      in_dest[c] = UINT32_MAX;
+    }
+    else
+    {
+        in_dest[c] = UINT32_MAX;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", 
entry_in, in_dest[c], entry_out, out_dest[c]);
+
+  }
+  return GNUNET_ATS_NetworkTypeCount;
+}
+
+
+
 /**
  * Initialize address subsystem.
  *
@@ -1088,8 +1057,10 @@
                     const struct GNUNET_STATISTICS_Handle *stats)
 {
   struct GAS_Addresses_Handle *ah;
-  char *quota_wan_in_str;
-  char *quota_wan_out_str;
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  unsigned long long  quotas_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
+  int quota_count;
   char *mode_str;
   int c;
 
@@ -1097,31 +1068,6 @@
   handle = ah;
   handle->running = GNUNET_NO;
 
-  /* Initialize the system with configuration values */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
"WAN_QUOTA_IN", &quota_wan_in_str))
-  {
-    if (0 == strcmp(quota_wan_in_str, "unlimited") ||
-        (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes 
(quota_wan_in_str, &ah->wan_quota_in)))
-      ah->wan_quota_in = (UINT32_MAX) /10;
-
-    GNUNET_free (quota_wan_in_str);
-    quota_wan_in_str = NULL;
-  }
-  else
-      ah->wan_quota_in = (UINT32_MAX) /10;
-
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
"WAN_QUOTA_OUT", &quota_wan_out_str))
-  {
-    if (0 == strcmp(quota_wan_out_str, "unlimited") ||
-        (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes 
(quota_wan_out_str, &ah->wan_quota_out)))
-      ah->wan_quota_out = (UINT32_MAX) /10;
-
-    GNUNET_free (quota_wan_out_str);
-    quota_wan_out_str = NULL;
-  }
-  else
-    ah->wan_quota_out = (UINT32_MAX) /10;
-
   /* Initialize the addresses database */
   ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
   GNUNET_assert (NULL != ah->addresses);
@@ -1196,10 +1142,12 @@
   GNUNET_assert (NULL != ah->s_del);
   GNUNET_assert (NULL != ah->s_done);
 
-  ah->solver = ah->s_init (cfg, stats);
+  quota_count = load_quotas(cfg, quotas_in, quotas_out, 
GNUNET_ATS_NetworkTypeCount);
+
+  ah->solver = ah->s_init (cfg, stats, quotas, quotas_in, quotas_out, 
quota_count);
   if (NULL == ah->solver)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n");
     GNUNET_free (ah);
     return NULL;
   }

Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h       2012-12-05 13:56:23 UTC 
(rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h       2012-12-05 14:06:58 UTC 
(rev 25254)
@@ -32,6 +32,9 @@
 #include "gnunet_statistics_service.h"
 #include "ats.h"
 
+#define ATS_BLOCKING_DELTA 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
+
+
 struct ATS_Address
 {
   struct ATS_Address *next;
@@ -98,7 +101,11 @@
 
 typedef void *
  (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                     const struct GNUNET_STATISTICS_Handle *stats);
+                     const struct GNUNET_STATISTICS_Handle *stats,
+                     int *network,
+                     unsigned long long *out_dest,
+                     unsigned long long *in_dest,
+                     int dest_length);
 
 typedef void
 (*GAS_solver_address_change_preference) (void *solver,
@@ -117,7 +124,7 @@
                               struct ATS_Address *address);
 
 
-typedef struct ATS_PreferedAddress *
+typedef struct ATS_Address *
 (*GAS_solver_get_preferred_address) (void *solver,
                                      struct GNUNET_CONTAINER_MultiHashMap 
*addresses,
                                      const struct GNUNET_PeerIdentity *peer);

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-12-05 13:56:23 UTC 
(rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-12-05 14:06:58 UTC 
(rev 25254)
@@ -31,6 +31,8 @@
 #include "gnunet_statistics_service.h"
 #include "glpk.h"
 
+#define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__)
+
 #define WRITE_MLP GNUNET_NO
 #define DEBUG_ATS GNUNET_NO
 #define VERBOSE_GLPK GNUNET_NO
@@ -1074,7 +1076,9 @@
  */
 void *
 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-              const struct GNUNET_STATISTICS_Handle *stats)
+              const struct GNUNET_STATISTICS_Handle *stats,
+              int *network,
+              unsigned long long *out_dest, unsigned long long *in_dest, int 
dest_length)
 {
   struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
 
@@ -1708,15 +1712,12 @@
  * @param peer the peer
  * @return suggested address
  */
-struct ATS_PreferedAddress *
+struct ATS_Address *
 GAS_mlp_get_preferred_address (void *solver,
                                struct GNUNET_CONTAINER_MultiHashMap * 
addresses,
                                const struct GNUNET_PeerIdentity *peer)
 {
-  struct ATS_PreferedAddress * aa = GNUNET_malloc (sizeof (struct 
ATS_PreferedAddress));
-  aa->address = NULL;
-  aa->bandwidth_in = 0;
-  aa->bandwidth_out = 0;
+  struct ATS_Address * aa = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n", 
GNUNET_i2s (peer));
   GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, 
mlp_get_preferred_address_it, aa);
   return aa;

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-12-05 13:56:23 UTC 
(rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-12-05 14:06:58 UTC 
(rev 25254)
@@ -319,7 +319,9 @@
  */
 void *
 GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-              const struct GNUNET_STATISTICS_Handle *stats);
+              const struct GNUNET_STATISTICS_Handle *stats,
+              int *network,
+              unsigned long long *out_dest, unsigned long long *in_dest, int 
dest_length);
 
 
 /**
@@ -381,7 +383,7 @@
  * @param peer the peer
  * @return suggested address
  */
-struct ATS_PreferedAddress *
+struct ATS_Address *
 GAS_mlp_get_preferred_address (void *solver,
                                struct GNUNET_CONTAINER_MultiHashMap * 
addresses,
                                const struct GNUNET_PeerIdentity *peer);

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2012-12-05 
13:56:23 UTC (rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2012-12-05 
14:06:58 UTC (rev 25254)
@@ -29,13 +29,17 @@
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet_statistics_service.h"
 
+#define LOG(kind,...) GNUNET_log_from (kind, "ats-simplistic",__VA_ARGS__)
 
 /**
  * A handle for the simplistic solver
  */
 struct GAS_SIMPLISTIC_Handle
 {
-
+  unsigned int active_addresses;
+  int *quota_net;
+  unsigned long long *quota_in;
+  unsigned long long *quota_out;
 };
 
 
@@ -48,9 +52,23 @@
  */
 void *
 GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                     const struct GNUNET_STATISTICS_Handle *stats)
+                     const struct GNUNET_STATISTICS_Handle *stats,
+                     int *network,
+                     unsigned long long *out_dest,
+                     unsigned long long *in_dest,
+                     int dest_length)
 {
   struct GAS_SIMPLISTIC_Handle *solver = GNUNET_malloc (sizeof (struct 
GAS_SIMPLISTIC_Handle));
+
+  solver->quota_net = GNUNET_malloc (dest_length * sizeof (int));
+  memcpy (solver->quota_net, network, dest_length * sizeof (int));
+
+  solver->quota_in  = GNUNET_malloc (dest_length * sizeof (unsigned long 
long));
+  memcpy (solver->quota_in, out_dest, dest_length * sizeof (int));
+
+  solver->quota_out = GNUNET_malloc (dest_length * sizeof (unsigned long 
long));
+  memcpy (solver->quota_out, out_dest, dest_length * sizeof (unsigned long 
long));
+
   return solver;
 }
 
@@ -63,8 +81,12 @@
 void
 GAS_simplistic_done (void *solver)
 {
-  GNUNET_assert (solver != NULL);
-  GNUNET_free (solver);
+  struct GAS_SIMPLISTIC_Handle *s = solver;
+  GNUNET_assert (s != NULL);
+  GNUNET_free (s->quota_net);
+  GNUNET_free (s->quota_in);
+  GNUNET_free (s->quota_out);
+  GNUNET_free (s);
 }
 
 /**
@@ -95,19 +117,161 @@
 }
 
 
+
 /**
+ * Find a "good" address to use for a peer.  If we already have an existing
+ * address, we stick to it.  Otherwise, we pick by lowest distance and then
+ * by lowest latency.
+ *
+ * @param cls the 'struct ATS_Address**' where we store the result
+ * @param key unused
+ * @param value another 'struct ATS_Address*' to consider using
+ * @return GNUNET_OK (continue to iterate)
+ */
+static int
+find_address_it (void *cls, const struct GNUNET_HashCode * key, void *value)
+{
+  struct ATS_Address **previous_p = cls;
+  struct ATS_Address *current = (struct ATS_Address *) value;
+  struct ATS_Address *previous = *previous_p;
+  struct GNUNET_TIME_Absolute now;
+
+  now = GNUNET_TIME_absolute_get();
+
+  if (current->blocked_until.abs_value == GNUNET_TIME_absolute_max (now, 
current->blocked_until).abs_value)
+  {
+    /* This address is blocked for suggestion */
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+                "Address %p blocked for suggestion for %llu ms \n",
+                current,
+                GNUNET_TIME_absolute_get_difference(now, 
current->blocked_until).rel_value);
+    return GNUNET_OK;
+  }
+
+  current->block_interval = GNUNET_TIME_relative_add (current->block_interval, 
ATS_BLOCKING_DELTA);
+  current->blocked_until = GNUNET_TIME_absolute_add (now, 
current->block_interval);
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Address %p ready for suggestion, block interval now %llu \n",
+       current, current->block_interval);
+
+  if (NULL != previous)
+  {
+    if ((0 == strcmp (previous->plugin, "tcp")) &&
+        (0 == strcmp (current->plugin, "tcp")))
+    {
+      if ((0 != previous->addr_len) &&
+          (0 == current->addr_len))
+      {
+        /* saved address was an outbound address, but we have an inbound 
address */
+        *previous_p = current;
+        return GNUNET_OK;
+      }
+      if (0 == previous->addr_len)
+      {
+        /* saved address was an inbound address, so do not overwrite */
+        return GNUNET_OK;
+      }
+    }
+  }
+
+  if (NULL == previous)
+  {
+    *previous_p = current;
+    return GNUNET_OK;
+  }
+  if ((ntohl (previous->assigned_bw_in.value__) == 0) &&
+      (ntohl (current->assigned_bw_in.value__) > 0))
+  {
+    /* stick to existing connection */
+    *previous_p = current;
+    return GNUNET_OK;
+  }
+  if (previous->atsp_distance > current->atsp_distance)
+  {
+    /* user shorter distance */
+    *previous_p = current;
+    return GNUNET_OK;
+  }
+  if (previous->atsp_latency.rel_value > current->atsp_latency.rel_value)
+  {
+    /* user lower latency */
+    *previous_p = current;
+    return GNUNET_OK;
+  }
+  /* don't care */
+  return GNUNET_OK;
+}
+
+static int
+update_bw_simple_it (void *cls, const struct GNUNET_HashCode * key, void 
*value)
+{
+  struct GAS_SIMPLISTIC_Handle *s = cls;
+  struct ATS_Address *aa = value;
+
+  if (GNUNET_YES != aa->active)
+    return GNUNET_OK;
+  GNUNET_assert (s->active_addresses > 0);
+
+
+  /* Simple method */
+
+  aa->assigned_bw_in.value__ = htonl (UINT32_MAX / s->active_addresses);
+  aa->assigned_bw_out.value__ = htonl (UINT32_MAX / s->active_addresses);
+
+  //send_bw_notification (aa);
+
+  return GNUNET_OK;
+}
+
+/**
+ * Some (significant) input changed, recalculate bandwidth assignment
+ * for all peers.
+ */
+static void
+recalculate_assigned_bw (void *solver,
+                         struct GNUNET_CONTAINER_MultiHashMap * addresses)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Recalculating bandwidth for all active connections\n");
+  GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, 
solver);
+}
+
+
+
+/**
  * Get the prefered address for a specific peer
  *
  * @param solver the solver handle
  * @param addresses the address hashmap containing all addresses
  * @param peer the identity of the peer
  */
-struct ATS_PreferedAddress *
+struct ATS_Address *
 GAS_simplistic_get_preferred_address (void *solver,
                                struct GNUNET_CONTAINER_MultiHashMap * 
addresses,
                                const struct GNUNET_PeerIdentity *peer)
 {
-  return NULL;
+  struct GAS_SIMPLISTIC_Handle *s = solver;
+  struct ATS_Address *aa;
+
+  GNUNET_assert (s != NULL);
+  aa = NULL;
+  /* Get address with: stick to current address, lower distance, lower latency 
*/
+  GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+                                              &find_address_it, &aa);
+  if (NULL == aa)
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Cannot suggest address for peer `%s'\n", 
GNUNET_i2s (peer));
+  else
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Suggesting address %p for peer `%s'\n", aa, 
GNUNET_i2s (peer));
+
+  if (GNUNET_NO == aa->active)
+  {
+    aa->active = GNUNET_YES;
+    s->active_addresses++;
+    recalculate_assigned_bw (s, addresses);
+  }
+
+  return aa;
 }
 
 

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h    2012-12-05 
13:56:23 UTC (rev 25253)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h    2012-12-05 
14:06:58 UTC (rev 25254)
@@ -38,7 +38,9 @@
  */
 void *
 GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                     const struct GNUNET_STATISTICS_Handle *stats);
+    const struct GNUNET_STATISTICS_Handle *stats,
+    int *network,
+    unsigned long long *out_dest, unsigned long long *in_dest, int 
dest_length);
 
 /**
  * Shutdown the simplistic problem solving component
@@ -78,7 +80,7 @@
  * @param addresses the address hashmap containing all addresses
  * @param peer the identity of the peer
  */
-struct ATS_PreferedAddress *
+struct ATS_Address *
 GAS_simplistic_get_preferred_address (void *solver,
                                struct GNUNET_CONTAINER_MultiHashMap * 
addresses,
                                const struct GNUNET_PeerIdentity *peer);

Modified: gnunet/src/ats/perf_ats_mlp.c
===================================================================
--- gnunet/src/ats/perf_ats_mlp.c       2012-12-05 13:56:23 UTC (rev 25253)
+++ gnunet/src/ats/perf_ats_mlp.c       2012-12-05 14:06:58 UTC (rev 25254)
@@ -175,7 +175,88 @@
 
 }
 
+static unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long 
*out_dest, unsigned long long *in_dest, int dest_length)
+{
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  char * entry_in = NULL;
+  char * entry_out = NULL;
+  char * quota_out_str;
+  char * quota_in_str;
+  int c;
 
+  for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+  {
+    in_dest[c] = 0;
+    out_dest[c] = 0;
+    switch (quotas[c]) {
+      case GNUNET_ATS_NET_UNSPECIFIED:
+        entry_out = "UNSPECIFIED_QUOTA_OUT";
+        entry_in = "UNSPECIFIED_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LOOPBACK:
+        entry_out = "LOOPBACK_QUOTA_OUT";
+        entry_in = "LOOPBACK_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LAN:
+        entry_out = "LAN_QUOTA_OUT";
+        entry_in = "LAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WAN:
+        entry_out = "WAN_QUOTA_OUT";
+        entry_in = "WAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WLAN:
+        entry_out = "WLAN_QUOTA_OUT";
+        entry_in = "WLAN_QUOTA_IN";
+        break;
+      default:
+        break;
+    }
+
+    if ((entry_in == NULL) || (entry_out == NULL))
+      continue;
+
+    /* quota out */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_out, &quota_out_str))
+    {
+      if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 
&out_dest[c])))
+        out_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_out_str);
+      quota_out_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+      out_dest[c] = UINT32_MAX;
+    else
+      out_dest[c] = UINT32_MAX;
+
+    /* quota in */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_in, &quota_in_str))
+    {
+      if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, 
&in_dest[c])))
+        in_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_in_str);
+      quota_in_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+    {
+      in_dest[c] = UINT32_MAX;
+    }
+    else
+    {
+        in_dest[c] = UINT32_MAX;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loaded quota: %s %u, %s %u\n", 
entry_in, in_dest[c], entry_out, out_dest[c]);
+
+  }
+  return GNUNET_ATS_NetworkTypeCount;
+}
+
+
 static void
 check (void *cls, char *const *args, const char *cfgfile,
        const  struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -186,6 +267,10 @@
   int update = GNUNET_NO;
   int range = GNUNET_NO;
   int res;
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  unsigned long long  quotas_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
+  int quota_count;
 
 #if !HAVE_LIBGLPK
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
@@ -195,7 +280,8 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses 
per peer\n", peers, addresses);
 
-  mlp = GAS_mlp_init (cfg, NULL);
+  quota_count = load_quotas(cfg, quotas_in, quotas_out, 
GNUNET_ATS_NetworkTypeCount);
+  mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count);
   if (NULL == mlp)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n");

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2012-12-05 13:56:23 UTC (rev 25253)
+++ gnunet/src/ats/test_ats_mlp.c       2012-12-05 14:06:58 UTC (rev 25254)
@@ -61,6 +61,90 @@
   ats->value = value;
 }
 
+
+unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long 
*out_dest, unsigned long long *in_dest, int dest_length)
+{
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  char * entry_in = NULL;
+  char * entry_out = NULL;
+  char * quota_out_str;
+  char * quota_in_str;
+  int c;
+
+  for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+  {
+    in_dest[c] = 0;
+    out_dest[c] = 0;
+    switch (quotas[c]) {
+      case GNUNET_ATS_NET_UNSPECIFIED:
+        entry_out = "UNSPECIFIED_QUOTA_OUT";
+        entry_in = "UNSPECIFIED_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LOOPBACK:
+        entry_out = "LOOPBACK_QUOTA_OUT";
+        entry_in = "LOOPBACK_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LAN:
+        entry_out = "LAN_QUOTA_OUT";
+        entry_in = "LAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WAN:
+        entry_out = "WAN_QUOTA_OUT";
+        entry_in = "WAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WLAN:
+        entry_out = "WLAN_QUOTA_OUT";
+        entry_in = "WLAN_QUOTA_IN";
+        break;
+      default:
+        break;
+    }
+
+    if ((entry_in == NULL) || (entry_out == NULL))
+      continue;
+
+    /* quota out */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_out, &quota_out_str))
+    {
+      if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 
&out_dest[c])))
+        out_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_out_str);
+      quota_out_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+      out_dest[c] = UINT32_MAX;
+    else
+      out_dest[c] = UINT32_MAX;
+
+    /* quota in */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_in, &quota_in_str))
+    {
+      if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, 
&in_dest[c])))
+        in_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_in_str);
+      quota_in_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+    {
+      in_dest[c] = UINT32_MAX;
+    }
+    else
+    {
+        in_dest[c] = UINT32_MAX;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loaded quota: %s %u, %s %u\n", 
entry_in, in_dest[c], entry_out, out_dest[c]);
+
+  }
+  return GNUNET_ATS_NetworkTypeCount;
+}
+
+
+
 static void
 check (void *cls, char *const *args, const char *cfgfile,
        const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -71,14 +155,19 @@
   return;
 #endif
   struct ATS_Address addr[10];
-  struct ATS_PreferedAddress *res[10];
+  struct ATS_Address *res[10];
   struct GAS_MLP_SolutionContext ctx;
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  unsigned long long  quotas_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
+  int quota_count;
 
   stats = GNUNET_STATISTICS_create("ats", cfg);
 
   addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
 
-  mlp = GAS_mlp_init (cfg, NULL);
+  quota_count = load_quotas(cfg, quotas_in, quotas_out, 
GNUNET_ATS_NetworkTypeCount);
+  mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count);
   mlp->auto_solve = GNUNET_NO;
 
   struct GNUNET_PeerIdentity p[10];
@@ -143,9 +232,9 @@
   GNUNET_assert (GNUNET_OK == ctx.mlp_result);
 
   res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' outbound 
bandwidth: %u Bps\n",res[0]->address->plugin, res[0]->bandwidth_out);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' outbound 
bandwidth: %u Bps\n",res[0]->plugin, res[0]->assigned_bw_out);
   res[1] = GAS_mlp_get_preferred_address(mlp, addresses, &p[1]);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' outbound 
bandwidth: %u Bps\n",res[1]->address->plugin, res[1]->bandwidth_out);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' outbound 
bandwidth: %u Bps\n",res[1]->plugin, res[1]->assigned_bw_out);
 
   /* Delete an address */
   GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, 
&addr[0]);

Modified: gnunet/src/ats/test_ats_mlp_averaging.c
===================================================================
--- gnunet/src/ats/test_ats_mlp_averaging.c     2012-12-05 13:56:23 UTC (rev 
25253)
+++ gnunet/src/ats/test_ats_mlp_averaging.c     2012-12-05 14:06:58 UTC (rev 
25254)
@@ -61,6 +61,87 @@
   ats->value = value;
 }
 
+static unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long 
*out_dest, unsigned long long *in_dest, int dest_length)
+{
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  char * entry_in = NULL;
+  char * entry_out = NULL;
+  char * quota_out_str;
+  char * quota_in_str;
+  int c;
+
+  for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+  {
+    in_dest[c] = 0;
+    out_dest[c] = 0;
+    switch (quotas[c]) {
+      case GNUNET_ATS_NET_UNSPECIFIED:
+        entry_out = "UNSPECIFIED_QUOTA_OUT";
+        entry_in = "UNSPECIFIED_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LOOPBACK:
+        entry_out = "LOOPBACK_QUOTA_OUT";
+        entry_in = "LOOPBACK_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LAN:
+        entry_out = "LAN_QUOTA_OUT";
+        entry_in = "LAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WAN:
+        entry_out = "WAN_QUOTA_OUT";
+        entry_in = "WAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WLAN:
+        entry_out = "WLAN_QUOTA_OUT";
+        entry_in = "WLAN_QUOTA_IN";
+        break;
+      default:
+        break;
+    }
+
+    if ((entry_in == NULL) || (entry_out == NULL))
+      continue;
+
+    /* quota out */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_out, &quota_out_str))
+    {
+      if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, 
&out_dest[c])))
+        out_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_out_str);
+      quota_out_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+      out_dest[c] = UINT32_MAX;
+    else
+      out_dest[c] = UINT32_MAX;
+
+    /* quota in */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_in, &quota_in_str))
+    {
+      if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
+          (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, 
&in_dest[c])))
+        in_dest[c] = UINT32_MAX;
+
+      GNUNET_free (quota_in_str);
+      quota_in_str = NULL;
+    }
+    else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
+    {
+      in_dest[c] = UINT32_MAX;
+    }
+    else
+    {
+        in_dest[c] = UINT32_MAX;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loaded quota: %s %u, %s %u\n", 
entry_in, in_dest[c], entry_out, out_dest[c]);
+
+  }
+  return GNUNET_ATS_NetworkTypeCount;
+}
+
 static void
 check (void *cls, char *const *args, const char *cfgfile,
        const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -72,6 +153,10 @@
 #endif
   struct ATS_Address addr[10];
   struct ATS_PreferedAddress *res[10];
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  unsigned long long  quotas_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
+  int quota_count;
   // struct MLP_information *mlpi;
   struct GAS_MLP_SolutionContext ctx;
 
@@ -79,7 +164,8 @@
 
   addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
 
-  mlp = GAS_mlp_init (cfg, NULL);
+  quota_count = load_quotas(cfg, quotas_in, quotas_out, 
GNUNET_ATS_NetworkTypeCount);
+  mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count);
   mlp->auto_solve = GNUNET_NO;
 
   struct GNUNET_PeerIdentity p[10];




reply via email to

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