stuff
[oweals/gnunet.git] / src / transport / test_transport_ats.c
index c782b97d90d219299628908e2ba7c1072c3f1655..bf7bc0fe5ab43a5cb4986e5ed8c1b6e612bdfe45 100644 (file)
 #define VERBOSE GNUNET_YES
 
 static struct ATS_Handle * ats;
+
 static struct GNUNET_CONFIGURATION_Handle * cfg;
 
-void ats_result_cb ()
+static struct TransportConfiguration *tc;
+
+
+static void 
+ats_result_cb ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
       "ATS Result callback\n");
@@ -49,40 +54,11 @@ struct TransportConfiguration
   struct ATS_mechanism * m_tail;
 };
 
-struct TransportConfiguration *tc;
-
-/*
-void create_topology (int c_peers, int c_mechanisms)
-{
-  int c;
-  peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer));
-  for (c=0 ; c<c_peers; c++)
-    {
-      peers[c].f = 1.0 / c_peers;
-      GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &peers[c].peer.hashPubKey);
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s \n", GNUNET_i2s (&peers[c].peer));
-      peers[c].m_head = NULL;
-      peers[c].m_tail = NULL;
-    }
-  mechanisms = GNUNET_malloc ( c_mechanisms * sizeof (struct ATS_mechanism));
-  for (c=0 ; c<c_mechanisms; c++)
-    {
-       mechanisms[c].peer = &peers[c];
-    }
-}
-
-
-void delete_topology (void)
-{
-  GNUNET_free (peers);
-  GNUNET_free (mechanisms);
-}*/
-
-
-void create_ats_information (struct ATS_peer **p, int * c_p,
-                             struct ATS_mechanism ** m, int * c_m)
-{
 
+static void 
+create_ats_information (struct ATS_peer **p, int * c_p,
+                       struct ATS_mechanism ** m, int * c_m)
+{ 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
       "ATS needs addresses\n");
 
@@ -90,24 +66,24 @@ void create_ats_information (struct ATS_peer **p, int * c_p,
  (*c_p) = tc->mechanisms;
  (*m) = tc->m_head;
  (*c_m) = tc->mechanisms;
-
 }
 
-int run_ats (void)
+
+static
+int run_ats ()
 {
   int ret = 0;
-
-  ats_calculate_bandwidth_distribution(ats, NULL);
-
+  ats_calculate_bandwidth_distribution (ats);
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
   return ret;
 }
 
-int init_ats (void)
+
+static int
+init_ats ()
 {
   int ret = 0;
-
   ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
                 create_ats_information,
                 ats_result_cb);
@@ -119,10 +95,10 @@ int init_ats (void)
 }
 
 
-int shutdown_ats (void)
+static int 
+shutdown_ats ()
 {
   int ret = 0;
-
   ats_delete_problem (ats);
   ats_shutdown (ats);
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -130,37 +106,45 @@ int shutdown_ats (void)
   return ret;
 }
 
+
 /* To make compiler happy */
-void dummy(void)
+void 
+dummy()
 {
   struct ATS_quality_metric * q = qm;
   q = NULL;
   struct ATS_ressource * r = ressources;
   r = NULL;
+  q++; 
+  r++;
 }
 
-void iterate_peer_values (void *cls,
-                      const char *section,
-                      const char *option,
-                      const char *value)
+
+static void 
+iterate_peer_values (void *cls,
+                    const char *section,
+                    const char *option,
+                    const char *value)
 {
   if (strcmp (option, "f") == 0)
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "\t %s %s\n", option, value);
 }
 
-void iterate_mech_values (void *cls,
-                      const char *section,
-                      const char *option,
-                      const char *value)
+static void
+iterate_mech_values (void *cls,
+                    const char *section,
+                    const char *option,
+                    const char *value)
 {
   if (strcmp (option, "f") == 0)
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "\t %s %s\n", option, value);
 }
 
-void iterate_sections (void *cls,
-                        const char *section)
+static void 
+iterate_sections (void *cls,
+                 const char *section)
 {
   struct TransportConfiguration * tc = cls;
   /* Peer definition */
@@ -181,22 +165,22 @@ void iterate_sections (void *cls,
     }
 }
 
-void destroy_transport_configuration (char * filename)
-{
-  GNUNET_CONFIGURATION_destroy (cfg);
 
-}
-
-struct TransportConfiguration * load_transport_configuration (char * filename)
+static struct TransportConfiguration * 
+load_transport_configuration (char * filename)
 {
   struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
-  cfg = GNUNET_CONFIGURATION_create();
-  GNUNET_CONFIGURATION_load(cfg, filename);
-  GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret);
 
+  cfg = GNUNET_CONFIGURATION_create();
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CONFIGURATION_load(cfg, filename));
+  GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret);
+  GNUNET_CONFIGURATION_destroy (cfg);
+  cfg = NULL;
   return ret;
 }
 
+
 int
 main (int argc, char *argv[])
 {
@@ -209,29 +193,11 @@ main (int argc, char *argv[])
                     "INFO",
 #endif
                     NULL);
-#if !HAVE_LIBGLPK
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "HAVE_LIBGLPK not set, exiting testcase\n");
-#endif
-
-#if !HAVE_LIBGLPK
-  return ret;
-#endif
-
-  return 0;
-
-  tc = load_transport_configuration ("test.ats");
-
-  return ret;
-
-  /* Testing */
+  tc = load_transport_configuration ("test_transport_ats.data");
   ats = NULL;
-
   ret += init_ats ();
   ret += run_ats ();
   ret += shutdown_ats ();
-
-  /* Shutdown */
   return ret;
 
 }