gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16077 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r16077 - gnunet/src/transport
Date: Mon, 18 Jul 2011 10:19:35 +0200

Author: wachs
Date: 2011-07-18 10:19:35 +0200 (Mon, 18 Jul 2011)
New Revision: 16077

Modified:
   gnunet/src/transport/test_transport_ats.c
Log:
preliminary commit to prevent more conflicts


Modified: gnunet/src/transport/test_transport_ats.c
===================================================================
--- gnunet/src/transport/test_transport_ats.c   2011-07-18 08:18:37 UTC (rev 
16076)
+++ gnunet/src/transport/test_transport_ats.c   2011-07-18 08:19:35 UTC (rev 
16077)
@@ -22,49 +22,89 @@
  * @brief testcase for ats functionality without starting peers
  */
 #include "platform.h"
-#include "transport_ats.h"
+#include "gnunet_transport_ats.h"
 #include "gnunet_configuration_lib.h"
+#include "gnunet_crypto_lib.h"
 
 #define VERBOSE GNUNET_YES
 
-#if HAVE_LIBGLPK
-
-struct GNUNET_CONFIGURATION_Handle *cfg;
-
 static struct ATS_Handle * ats;
+static struct GNUNET_CONFIGURATION_Handle * cfg;
 
-static void 
-ats_result_cb ()
+void ats_result_cb ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
       "ATS Result callback\n");
 }
 
+struct TransportConfiguration
+{
+  int peers;
+  int mechanisms;
 
-static void 
-create_ats_information (struct ATS_peer **p, int * c_p,
-                       struct ATS_mechanism ** m, int * c_m)
+  struct ATS_peer * p_head;
+  struct ATS_peer * p_tail;
+
+  struct ATS_mechanism * m_head;
+  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)
+{
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
       "ATS needs addresses\n");
-  (*c_m) = 100;
-  (*c_p) = 10;
+
+ (*p) = tc->p_head;
+ (*c_p) = tc->mechanisms;
+ (*m) = tc->m_head;
+ (*c_m) = tc->mechanisms;
+
 }
 
-static int 
-run_ats ()
+int run_ats (void)
 {
   int ret = 0;
 
   ats_calculate_bandwidth_distribution(ats, NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Running ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED");
+              "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
   return ret;
 }
 
-static int 
-init_ats ()
+int init_ats (void)
 {
   int ret = 0;
 
@@ -74,26 +114,24 @@
   //GNUNET_assert (ats != NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Initializing ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED");
+              "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
   return ret;
 }
 
 
-static int 
-shutdown_ats ()
+int shutdown_ats (void)
 {
   int ret = 0;
 
-  //ats_delete_problem (ats);
-  //ats_shutdown (ats);
+  ats_delete_problem (ats);
+  ats_shutdown (ats);
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Shutdown ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED");
+              "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
   return ret;
 }
 
 /* To make compiler happy */
-static void 
-dummy()
+void dummy(void)
 {
   struct ATS_quality_metric * q = qm;
   q = NULL;
@@ -101,8 +139,64 @@
   r = NULL;
 }
 
-#endif
+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)
+{
+  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)
+{
+  struct TransportConfiguration * tc = cls;
+  /* Peer definition */
+  if (99 == strlen(section))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
+      GNUNET_HashCode h;
+      int res =GNUNET_CRYPTO_hash_from_string(section, &h);
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), 
res);
+      GNUNET_CONFIGURATION_iterate_section_values(cfg, section, 
iterate_peer_values, NULL);
+      tc->peers++;
+    }
+  if (10 == strlen(section))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
+      GNUNET_CONFIGURATION_iterate_section_values(cfg, section, 
iterate_mech_values, NULL);
+      tc->peers++;
+    }
+}
+
+void destroy_transport_configuration (char * filename)
+{
+  GNUNET_CONFIGURATION_destroy (cfg);
+
+}
+
+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);
+
+  return ret;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -116,28 +210,30 @@
 #endif
                     NULL);
 #if !HAVE_LIBGLPK
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "HAVE_LIBGLPK not set, exiting testcase\n");
 #endif
 
 #if !HAVE_LIBGLPK
   return ret;
-#else
+#endif
 
+  return 0;
 
-  cfg = GNUNET_CONFIGURATION_create();
-  GNUNET_CONFIGURATION_load(cfg, "test_transport_ats_1addr.conf");
+  tc = load_transport_configuration ("test.ats");
 
+  return ret;
+
   /* Testing */
   ats = NULL;
+
   ret += init_ats ();
   ret += run_ats ();
   ret += shutdown_ats ();
 
   /* Shutdown */
-  GNUNET_CONFIGURATION_destroy(cfg);
   return ret;
-#endif
+
 }
 
 /* end of test_transport_ats.c*/




reply via email to

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