ats related changes
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 6 Jul 2011 15:48:30 +0000 (15:48 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 6 Jul 2011 15:48:30 +0000 (15:48 +0000)
src/transport/Makefile.am
src/transport/gnunet-service-transport.c
src/transport/transport.h

index 867749cafccdc0ae8bba57b390af314b3d5645db..96c25b15ec20f96f84b6c4176ebd7d8b58092283 100644 (file)
@@ -234,6 +234,7 @@ endif
 
 check_PROGRAMS = \
  test_transport_ats \
+ test_transport_ats_multiple_peers \
  $(TRANSPORT_BENCHMARKS) \
  test_transport_api_tcp \
  test_transport_api_tcp_nat \
@@ -266,6 +267,7 @@ check_PROGRAMS = \
 if ENABLE_TEST_RUN
 TESTS = \
  test_transport_ats \
+ test_transport_ats_multiple_peers \
  perf_transport_ats \
  test_transport_api_tcp \
  test_transport_api_tcp_nat \
@@ -297,8 +299,17 @@ TESTS = \
 endif
 
 test_transport_ats_SOURCES = \
- test_transport_ats.c
+ test_transport_ats.c transport_ats.c
 test_transport_ats_LDADD = -lm \
+ $(top_builddir)/src/transport/libgnunettransportnew.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(GN_GLPK)
+
+test_transport_ats_multiple_peers_SOURCES = \
+ test_transport_ats_multiple_peers.c
+test_transport_ats_multiple_peers_LDADD = -lm \
  $(top_builddir)/src/transport/libgnunettransportnew.la \
  $(top_builddir)/src/statistics/libgnunetstatistics.la \
  $(top_builddir)/src/testing/libgnunettesting.la \
index 249ad51049236afe68e134734c025bb770f8e579..a8b2dcaeb299aa49302d09e6731922f673eee967 100644 (file)
@@ -927,7 +927,7 @@ static int shutdown_in_progress;
 /**
  * Handle for ats information
  */
-static struct ATS_info *ats;
+static struct ATS_Handle *ats;
 
 /**
  * The peer specified by the given neighbour has timed-out or a plugin
@@ -973,33 +973,34 @@ find_neighbour (const struct GNUNET_PeerIdentity *key)
 
 static int update_addr_value (struct ForeignAddressList *fal, uint32_t value , int ats_index)
 {
-       int c;
-       int set = GNUNET_NO;
-       for (c=0; c<available_quality_metrics; c++)
-       {
-         if (ats_index == qm[c].atis_index)
-         {
-                 fal->quality[c].values[0] = fal->quality[c].values[1];
-                 fal->quality[c].values[1] = fal->quality[c].values[2];
-                 fal->quality[c].values[2] = value;
-                 set = GNUNET_YES;
-                 ats->stat.modified_quality = GNUNET_YES;
-         }
-       }
-       if (set == GNUNET_NO)
-       {
-         for (c=0; c<available_ressources; c++)
-         {
-                 if (ats_index == ressources[c].atis_index)
-                 {
-                         fal->ressources[c].c = value;
-                         set = GNUNET_YES;
-                         ats->stat.modified_resources = GNUNET_YES;
-                 }
-         }
-       }
-
-       return set;
+  int c;
+  int set = GNUNET_NO;
+  for (c=0; c<available_quality_metrics; c++)
+  {
+    if (ats_index == qm[c].atis_index)
+    {
+      fal->quality[c].values[0] = fal->quality[c].values[1];
+      fal->quality[c].values[1] = fal->quality[c].values[2];
+      fal->quality[c].values[2] = value;
+      set = GNUNET_YES;
+      if (ats != NULL)
+        ats->stat.modified_quality = GNUNET_YES;
+    }
+  }
+  if (set == GNUNET_NO)
+  {
+    for (c=0; c<available_ressources; c++)
+    {
+      if (ats_index == ressources[c].atis_index)
+      {
+        fal->ressources[c].c = value;
+        set = GNUNET_YES;
+        if (ats != NULL)
+          ats->stat.modified_resources = GNUNET_YES;
+      }
+    }
+  }
+  return set;
 }
 
 static int
@@ -2436,7 +2437,8 @@ plugin_env_session_end  (void *cls,
       return; 
     }
   GNUNET_free (pos);
-  ats->stat.recreate_problem = GNUNET_YES;
+  if (ats != NULL)
+    ats->stat.recreate_problem = GNUNET_YES;
   if (nl->received_pong == GNUNET_NO)
     {
       GNUNET_STATISTICS_update (stats,
@@ -2598,7 +2600,7 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
 
   /* notify ats about connecting peer */
   /* notify ats about connecting peer */
-  if (shutdown_in_progress == GNUNET_NO)
+  if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
   {
     ats->stat.recreate_problem = GNUNET_YES;
     ats_calculate_bandwidth_distribution (ats, stats, neighbours);
@@ -2647,7 +2649,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
   memcpy (&dim.peer, peer, sizeof (struct GNUNET_PeerIdentity));
 
   /* notify ats about connecting peer */
-  if (shutdown_in_progress == GNUNET_NO)
+  if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
   {
     ats->stat.recreate_problem = GNUNET_YES;
     ats_calculate_bandwidth_distribution (ats, stats, neighbours);
@@ -4843,7 +4845,8 @@ disconnect_neighbour (struct NeighbourList *n, int check)
          GNUNET_free(peer_pos->quality);
          peer_pos->ressources = NULL;
          GNUNET_free(peer_pos);
-         ats->stat.recreate_problem = GNUNET_YES;
+         if (ats != NULL)
+           ats->stat.recreate_problem = GNUNET_YES;
         }
       GNUNET_free (rpos);
     }
@@ -5316,19 +5319,19 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
        uint32_t value =  ntohl(*((uint32_t *) &message[1]));
        //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: %i \n", value);
        /* Force ressource and quality update */
-       if (value == 4)
+       if ((value == 4) && (ats != NULL))
          {
            ats->stat.modified_resources = GNUNET_YES;
            ats->stat.modified_quality = GNUNET_YES;
          }
        /* Force cost update */
-       if (value == 3)
+       if ((value == 3) && (ats != NULL))
          ats->stat.modified_resources = GNUNET_YES;
        /* Force quality update */
-       if (value == 2)
+       if ((value == 2) && (ats != NULL))
          ats->stat.modified_quality = GNUNET_YES;
        /* Force full rebuild */
-       if (value == 1)
+       if ((value == 1) && (ats != NULL))
          ats->stat.recreate_problem = GNUNET_YES;
       }
     
@@ -6002,7 +6005,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_CONTAINER_multihashmap_destroy (validation_map);
   validation_map = NULL;
 
-  ats_shutdown (ats);
+  if (ats != NULL)
+    ats_shutdown (ats);
 
   /* free 'chvc' data structure */
   while (NULL != (chvc = chvc_head))
@@ -6050,7 +6054,7 @@ static void
 schedule_ats (void *cls,
                          const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct ATS_info *ats = (struct ATS_info *) cls;
+  struct ATS_Handle *ats = (struct ATS_Handle *) cls;
   if (ats==NULL)
     return;
 
@@ -6204,8 +6208,9 @@ run (void *cls,
     refresh_hello ();
 
   ats = ats_init (cfg);
-  GNUNET_assert (ats != NULL);
-  ats->ats_task = GNUNET_SCHEDULER_add_now (&schedule_ats, ats);
+  if (ats != NULL)
+    ats->ats_task = GNUNET_SCHEDULER_add_now (&schedule_ats, ats);
+
 
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
index 0e4fba73150f9ecfcdbd5f7db692c4fe449f6a07..73ebe682092579a44e340ee1a3c253e8f57cf2ad 100644 (file)
 #include "gnunet_time_lib.h"
 #include "gnunet_transport_service.h"
 
-/* Minimum time between to calculations*/
-#define ATS_MIN_INTERVAL  GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
-#define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
-#define ATS_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
-#define ATS_MAX_ITERATIONS INT_MAX
-
 #define DEBUG_TRANSPORT 3
 
 #define DEBUG_TRANSPORT_TIMEOUT GNUNET_NO