gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r25284 - gnunet/src/ats
Date: Thu, 6 Dec 2012 10:42:24 +0100

Author: wachs
Date: 2012-12-06 10:42:23 +0100 (Thu, 06 Dec 2012)
New Revision: 25284

Modified:
   gnunet/src/ats/test_ats_api_scheduling_add_address.c
   gnunet/src/ats/test_ats_api_scheduling_destroy_address.c
Log:
changes


Modified: gnunet/src/ats/test_ats_api_scheduling_add_address.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_add_address.c        2012-12-06 
09:22:46 UTC (rev 25283)
+++ gnunet/src/ats/test_ats_api_scheduling_add_address.c        2012-12-06 
09:42:23 UTC (rev 25284)
@@ -104,8 +104,6 @@
                     const struct GNUNET_ATS_Information *atsi,
                     uint32_t ats_count)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 
GNUNET_i2s_full(&address->peer));
-
   if (0 != memcmp (&address->peer, &p.id, sizeof (struct GNUNET_PeerIdentity)))
   {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer 
id'\n");

Modified: gnunet/src/ats/test_ats_api_scheduling_destroy_address.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_destroy_address.c    2012-12-06 
09:22:46 UTC (rev 25283)
+++ gnunet/src/ats/test_ats_api_scheduling_destroy_address.c    2012-12-06 
09:42:23 UTC (rev 25284)
@@ -32,17 +32,17 @@
 
 static GNUNET_SCHEDULER_TaskIdentifier die_task;
 
+static GNUNET_SCHEDULER_TaskIdentifier wait_task;
+
+#define WAIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 
5)
+
+
 /**
  * Scheduling handle
  */
 static struct GNUNET_ATS_SchedulingHandle *sched_ats;
 
 /**
- * Performance handle
- */
-static struct GNUNET_ATS_PerformanceHandle *perf_ats;
-
-/**
  * Return value
  */
 static int ret;
@@ -57,7 +57,12 @@
  */
 static struct PeerContext p;
 
+/**
+ * HELLO address
+ */
+struct GNUNET_HELLO_Address hello_address;
 
+
 static void
 create_test_address (struct Test_Address *dest, char * plugin, void *session, 
void *addr, size_t addrlen)
 {
@@ -84,8 +89,6 @@
 
   if (sched_ats != NULL)
     GNUNET_ATS_scheduling_done (sched_ats);
-  if (perf_ats != NULL)
-    GNUNET_ATS_performance_done (perf_ats);
   free_test_address (&test_addr);
   ret = GNUNET_SYSERR;
 }
@@ -95,6 +98,7 @@
 end ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+  wait_task = GNUNET_SCHEDULER_NO_TASK;
   if (die_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel (die_task);
@@ -103,44 +107,72 @@
   free_test_address (&test_addr);
   GNUNET_ATS_scheduling_done (sched_ats);
   sched_ats = NULL;
-  GNUNET_ATS_performance_done (perf_ats);
-  perf_ats = NULL;
 }
 
-void address_callback (void *cls,
-                      const struct
-                      GNUNET_HELLO_Address *
-                      address,
-                      struct
-                      GNUNET_BANDWIDTH_Value32NBO
-                      bandwidth_out,
-                      struct
-                      GNUNET_BANDWIDTH_Value32NBO
-                      bandwidth_in,
-                      const struct
-                      GNUNET_ATS_Information *
-                      ats, uint32_t ats_count)
+static void
+address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
+                    struct Session *session,
+                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+                    const struct GNUNET_ATS_Information *atsi,
+                    uint32_t ats_count)
 {
-  static int counter = 0;
-  if (NULL != address)
+  static int stage = 0;
+  int res = 0;
+
+  if (0 ==stage)
   {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received callback for peer `%s'\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Received suggestion for 
peer `%s'\n",
+                GNUNET_i2s(&address->peer));
+
+    if (0 != memcmp (&address->peer, &p.id, sizeof (struct 
GNUNET_PeerIdentity)))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer 
id'\n");
+        res = 1;
+    }
+    else if (0 != strcmp (address->transport_name, test_addr.plugin))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid 
plugin'\n");
+        res = 1;
+    }
+    else if (address->address_length != test_addr.addr_len)
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address 
length'\n");
+        res = 1;
+    }
+    else if (0 != memcmp (address->address, test_addr.plugin, 
address->address_length))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid 
address'\n");
+        res = 1;
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for correct address 
`%s'\n",
                   GNUNET_i2s (&address->peer));
-      counter ++;
-      return;
+      res = 0;
+    }
+    GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id);
+    if (1 == res)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for invalid address 
`%s'\n",
+                  GNUNET_i2s (&address->peer));
+      GNUNET_SCHEDULER_add_now (&end, NULL);
+      ret = 1;
+    }
+    stage ++;
+    ret = 0;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying address for `%s'\n",
+                GNUNET_i2s (&address->peer));
+    /* Destroying address */
+    GNUNET_ATS_address_destroyed (sched_ats, &hello_address, 
test_addr.session);
+    /* Request address */
+    GNUNET_ATS_suggest_address (sched_ats, &p.id);
+    wait_task = GNUNET_SCHEDULER_add_delayed (WAIT_TIMEOUT, &end, NULL);
+    return;
   }
-  if (counter > 0)
-  {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %u unexpected addresses 
callbacks\n", counter);
-      ret = counter;
-  }
-  else
-  {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received no unexpected addresses 
callbacks\n", counter);
-      ret = 0;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last callback, shutdown\n");
-  GNUNET_SCHEDULER_add_now (&end, NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Unexpected address 
suggestion\n");
+  ret = 1;
+
 }
 
 
@@ -149,11 +181,10 @@
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  struct GNUNET_HELLO_Address hello_address;
   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
 
   /* Connect to ATS scheduling */
-  sched_ats = GNUNET_ATS_scheduling_init (cfg, NULL, NULL);
+  sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
   if (sched_ats == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS 
scheduling!\n");
@@ -162,16 +193,6 @@
     return;
   }
 
-  /* Connect to ATS performance */
-  perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL);
-  if (perf_ats == NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS 
performance!\n");
-    ret = 1;
-    end ();
-    return;
-  }
-
   /* Set up peer */
   if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID, 
&p.id.hashPubKey))
   {
@@ -192,11 +213,8 @@
   hello_address.address_length = test_addr.addr_len;
   GNUNET_ATS_address_add (sched_ats, &hello_address, test_addr.session, NULL, 
0);
 
-  /* Destroying address */
-  GNUNET_ATS_address_destroyed (sched_ats, &hello_address, test_addr.session);
-
-  /* Get list of addresses, expect 0 addresses only NULL callback */
-  GNUNET_ATS_performance_list_addresses (perf_ats, &p.id, GNUNET_YES, 
address_callback, NULL);
+  /* Request address */
+  GNUNET_ATS_suggest_address (sched_ats, &p.id);
 }
 
 




reply via email to

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