testcase with one peer is passing
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 28 Apr 2010 06:47:51 +0000 (06:47 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 28 Apr 2010 06:47:51 +0000 (06:47 +0000)
src/hostlist/test_gnunet_daemon_hostlist_learning.c

index 64fd062dc18700e92590302902d92478b753c436..cd22226f141dc8ca2bc775dfdca1886868150b66 100644 (file)
@@ -30,7 +30,7 @@
 #include "gnunet_resolver_service.h"
 #include "gnunet_statistics_service.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 
 #define START_ARM GNUNET_YES
 #define MAX_URL_LEN 1000
 #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 static int timeout;
-static int adv_arrived;
 static int adv_sent;
-static int learned_hostlist_saved;
-static int learned_hostlist_downloaded;
+
+static int adv_arrived_p1;
+static int learned_hostlist_saved_p1;
+static int learned_hostlist_downloaded_p1;
+
+static int adv_arrived_p2;
+static int learned_hostlist_saved_p2;
+static int learned_hostlist_downloaded_p2;
 
 static char * current_adv_uri;
 
@@ -139,11 +144,12 @@ static void shutdown_testcase()
     GNUNET_TRANSPORT_disconnect (learn_peer.th);
     learn_peer.th = NULL;
   }
+  /*
   if (learn_peer2.th != NULL)
   {
     GNUNET_TRANSPORT_disconnect (learn_peer2.th);
     learn_peer2.th = NULL;
-  }
+  }*/
   if (adv_peer.core != NULL)
   {
     GNUNET_CORE_disconnect (adv_peer.core);
@@ -154,19 +160,20 @@ static void shutdown_testcase()
     GNUNET_CORE_disconnect (learn_peer.core);
     learn_peer.core = NULL;
   }
+  /*
   if (learn_peer2.core != NULL)
   {
     GNUNET_CORE_disconnect (learn_peer2.core);
     learn_peer2.core = NULL;
-  }
+  }*/
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asking ARM to stop core services\n");
   learn_peer.arm = GNUNET_ARM_connect (learn_peer.cfg, sched, NULL);
   GNUNET_ARM_stop_service (learn_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS,
                            &stop_cb, &learn_peer);
-  learn_peer2.arm = GNUNET_ARM_connect (learn_peer2.cfg, sched, NULL);
+  /* learn_peer2.arm = GNUNET_ARM_connect (learn_peer2.cfg, sched, NULL);
   GNUNET_ARM_stop_service (learn_peer2.arm, "core", GNUNET_TIME_UNIT_SECONDS,
-                           &stop_cb, &learn_peer2);
+                           &stop_cb, &learn_peer2);*/
   adv_peer.arm = GNUNET_ARM_connect (adv_peer.cfg, sched, NULL);
   GNUNET_ARM_stop_service (adv_peer.arm, "core", GNUNET_TIME_UNIT_SECONDS,
                            &stop_cb, &adv_peer);
@@ -194,13 +201,22 @@ process_downloads (void *cls,
               uint64_t value,
               int is_persistent)
 {
-  if ( (value == 2) && (learned_hostlist_downloaded == GNUNET_NO) )
+
+
+  if ( ((struct PeerContext *) cls == &learn_peer) && (value == 2) && (learned_hostlist_downloaded_p1 == GNUNET_NO) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _("Client has successfully downloaded advertised URI \n"));
-    learned_hostlist_downloaded = GNUNET_YES;
+                _("Peer1 has successfully downloaded advertised URI \n"));
+    learned_hostlist_downloaded_p1 = GNUNET_YES;
   }
-  if ( GNUNET_NO != learned_hostlist_downloaded )
+  /*
+  if ( ((struct PeerContext *) cls == &learn_peer2) && (value == 2) && (learned_hostlist_downloaded_p2 == GNUNET_NO) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _("Peer2 has successfully downloaded advertised URI \n"));
+    learned_hostlist_downloaded_p2 = GNUNET_YES;
+  }*/
+  if ( (GNUNET_NO != learned_hostlist_downloaded_p1) /*&& (GNUNET_NO != learned_hostlist_downloaded_p2)*/ )
     shutdown_testcase();
   return GNUNET_OK;
 }
@@ -212,12 +228,19 @@ process_uris_recv (void *cls,
               uint64_t value,
               int is_persistent)
 {
-  if ( (value == 1) && (learned_hostlist_saved == GNUNET_NO))
+  if ( ((struct PeerContext *) cls == &learn_peer) && (value == 1) && (learned_hostlist_saved_p1 == GNUNET_NO))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                _("Client has successfully saved advertised URI \n"));
-    learned_hostlist_saved = GNUNET_YES;
+                _("Peer1 has successfully saved advertised URI \n"));
+    learned_hostlist_saved_p1 = GNUNET_YES;
   }
+  /*
+  if ( ((struct PeerContext *) cls == &learn_peer2) && (value == 1) && (learned_hostlist_saved_p2 == GNUNET_NO))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _("Peer2 has successfully saved advertised URI \n"));
+    learned_hostlist_saved_p2 = GNUNET_YES;
+  }*/
   return GNUNET_OK;
 }
 
@@ -228,7 +251,7 @@ process_adv_sent (void *cls,
               uint64_t value,
               int is_persistent)
 {
-  if ( (value == 1) && (adv_sent == GNUNET_NO))
+  if ( (value >= 1) && (adv_sent == GNUNET_NO))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 _("Server has successfully sent advertisement\n"));
@@ -254,15 +277,30 @@ check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                          GNUNET_TIME_UNIT_MINUTES,
                          NULL,
                          &process_downloads,
-                         NULL);
+                         &learn_peer);
+  /*GNUNET_STATISTICS_get (learn_peer2.stats,
+                         "hostlist",
+                         stat,
+                         GNUNET_TIME_UNIT_MINUTES,
+                         NULL,
+                         &process_downloads,
+                         &learn_peer2);*/
   GNUNET_free (stat);
+
   GNUNET_STATISTICS_get (learn_peer.stats,
                          "hostlist",
                          gettext_noop("# advertised hostlist URIs"),
                          GNUNET_TIME_UNIT_MINUTES,
                          NULL,
                          &process_uris_recv,
-                         NULL);
+                         &learn_peer);
+  /*GNUNET_STATISTICS_get (learn_peer2.stats,
+                         "hostlist",
+                         gettext_noop("# advertised hostlist URIs"),
+                         GNUNET_TIME_UNIT_MINUTES,
+                         NULL,
+                         &process_uris_recv,
+                         &learn_peer2);*/
   GNUNET_STATISTICS_get (adv_peer.stats,
                          "hostlist",
                          gettext_noop("# hostlist advertisements send"),
@@ -325,7 +363,8 @@ static int ad_arrive_handler (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri);
-    adv_arrived = GNUNET_YES;
+    adv_arrived_p1 = GNUNET_YES;
+    adv_arrived_p2 = GNUNET_YES;
   }
   else
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -415,9 +454,16 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   timeout = GNUNET_NO;
-  adv_arrived = GNUNET_NO;
   adv_sent =GNUNET_NO;
-  learned_hostlist_downloaded = GNUNET_NO;
+
+  adv_arrived_p1 = GNUNET_NO;
+  learned_hostlist_downloaded_p1 = GNUNET_NO;
+  learned_hostlist_saved_p1 = GNUNET_NO;
+
+  /*adv_arrived_p2 = GNUNET_NO;
+  learned_hostlist_downloaded_p2 = GNUNET_NO;
+  learned_hostlist_saved_p2 = GNUNET_NO;*/
+
   sched = s;
   timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
                                                TIMEOUT,
@@ -430,7 +476,7 @@ run (void *cls,
 
   setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
   setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
-  setup_learn_peer (&learn_peer2, "test_learning_learn_peer2.conf");
+  // setup_learn_peer (&learn_peer2, "test_learning_learn_peer2.conf");
 
 }
 
@@ -462,24 +508,44 @@ check ()
                 "Testcase could not set up two communicating peers, timeout\n");
     failed = GNUNET_YES;
   }
-  if (adv_arrived == GNUNET_NO)
+  if (adv_arrived_p1 == GNUNET_NO)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Learning peer did not recieve advertisement from server\n");
+                "Peer1: Learning peer did not recieve advertisement from server\n");
     failed = GNUNET_YES;
   }
-  if ( learned_hostlist_saved == GNUNET_NO )
+  if ( learned_hostlist_saved_p1 == GNUNET_NO )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Advertised hostlist was not saved in datastore\n");
+                  "Peer1: Advertised hostlist was not saved in datastore\n");
       failed = GNUNET_YES;
     }
-  if (learned_hostlist_downloaded == GNUNET_NO)
+  if (learned_hostlist_downloaded_p1 == GNUNET_NO)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Advertised hostlist could not be downloaded from server\n");
+                "Peer1: Advertised hostlist could not be downloaded from server\n");
     failed = GNUNET_YES;
   }
+  /*
+  if (adv_arrived_p2 == GNUNET_NO)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Peer2: Learning peer did not recieve advertisement from server\n");
+    failed = GNUNET_YES;
+  }
+  if ( learned_hostlist_saved_p2 == GNUNET_NO )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Peer2: Advertised hostlist was not saved in datastore\n");
+      failed = GNUNET_YES;
+    }
+  if (learned_hostlist_downloaded_p2 == GNUNET_NO)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Peer2: Advertised hostlist could not be downloaded from server\n");
+    failed = GNUNET_YES;
+  }*/
+
   if (adv_sent == GNUNET_NO)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,