gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7344 - GNUnet/src/applications/dht/tools


From: gnunet
Subject: [GNUnet-SVN] r7344 - GNUnet/src/applications/dht/tools
Date: Fri, 27 Jun 2008 12:26:55 -0600 (MDT)

Author: grothoff
Date: 2008-06-27 12:26:55 -0600 (Fri, 27 Jun 2008)
New Revision: 7344

Modified:
   GNUnet/src/applications/dht/tools/dht_api.c
   GNUnet/src/applications/dht/tools/dht_multipeer_test.c
   GNUnet/src/applications/dht/tools/dht_twopeer_test.c
Log:
fix

Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2008-06-27 18:24:22 UTC (rev 
7343)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2008-06-27 18:26:55 UTC (rev 
7344)
@@ -47,12 +47,21 @@
       reply = NULL;
       if (GNUNET_OK != GNUNET_client_connection_read (info->sock, &reply))
        {
+         /* FIXME: we need to handle this better,
+            if we were not aborted, we need to try
+            to reconnect! -- this assertion failure
+            is more like a warning to the end-user/developer
+            that the code is not yet perfect... */
          GNUNET_GE_BREAK(NULL, info->aborted != GNUNET_NO);        
          break;
        }
       if ((sizeof (CS_dht_request_put_MESSAGE) > ntohs (reply->size)) ||
           (GNUNET_CS_PROTO_DHT_REQUEST_PUT != ntohs (reply->type)))
         {
+         fprintf(stderr,
+                 "Received message of type %u and size %u\n",
+                 ntohs(reply->type),
+                 ntohs(reply->size));
           GNUNET_GE_BREAK (NULL, 0);
           GNUNET_free (reply);
           break;                /*  invalid reply */

Modified: GNUnet/src/applications/dht/tools/dht_multipeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_multipeer_test.c      2008-06-27 
18:24:22 UTC (rev 7343)
+++ GNUnet/src/applications/dht/tools/dht_multipeer_test.c      2008-06-27 
18:26:55 UTC (rev 7344)
@@ -222,7 +222,7 @@
   printf ("Found %u out of %u attempts.\n", found, NUM_PEERS * NUM_PEERS);
   if (found < NUM_PEERS * NUM_PEERS / 2)
     {
-      printf ("Not enough results (not even 50%), marking test as failed!\n");
+      printf ("Not enough results (not even 50%%), marking test as failed!\n");
       ret = 1;
     }
 FAILURE:

Modified: GNUnet/src/applications/dht/tools/dht_twopeer_test.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_twopeer_test.c        2008-06-27 
18:24:22 UTC (rev 7343)
+++ GNUnet/src/applications/dht/tools/dht_twopeer_test.c        2008-06-27 
18:26:55 UTC (rev 7344)
@@ -33,9 +33,9 @@
 #include "gnunet_util.h"
 #include "dht_api.h"
 
-
 #define START_PEERS 1
 
+#define NUM_ROUNDS 100
 
 static int ok;
 static int peer1count;
@@ -67,9 +67,7 @@
   if ((8 != size) ||
       (0 != memcmp (expect, data, size)) ||
       (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
-    {
-      return GNUNET_SYSERR;
-    }
+    return GNUNET_SYSERR;    
   peer1count--;
   return GNUNET_OK;
 }
@@ -88,10 +86,8 @@
   memset (expect, (*i), sizeof (expect));
   if ((8 != size) ||
       (0 != memcmp (expect, data, size)) ||
-      (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))
-    {
-      return GNUNET_SYSERR;
-    }
+      (type != GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING))    
+    return GNUNET_SYSERR;    
   peer2count--;
   return GNUNET_OK;
 }
@@ -115,7 +111,10 @@
   struct GNUNET_GC_Configuration *cfg;
   struct GNUNET_DHT_Context *ctx_peer1;
   struct GNUNET_DHT_Context *ctx_peer2;
+  struct GNUNET_ClientServerConnection *sock;
   int left;
+  int k;
+  int want;
 
   ectx = NULL;
   cfg = GNUNET_GC_create ();
@@ -144,12 +143,11 @@
     }
 
   /* wait for DHT's to find each other! */
-  ctx_peer1 =
-    GNUNET_DHT_context_create (cfg, ectx, &result_callback_peer1, NULL);
   left = 50;                    /* how many iterations should we wait? */
+  sock = GNUNET_client_connection_create (NULL, cfg);
   printf ("Waiting for peers to DHT-connect (1->2)");
   while (GNUNET_OK ==
-         GNUNET_STATS_get_statistics (NULL, ctx_peer1->sock, &waitForConnect,
+         GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect,
                                       NULL))
     {
       printf (".");
@@ -162,12 +160,15 @@
   printf (left > 0 ? " OK!\n" : "?\n");
   if (ok == 0)
     {
+      GNUNET_client_connection_destroy (sock);
       GNUNET_TESTING_stop_daemons (peers);
       fprintf (stderr, "Peers' DHTs failed to DHT-connect!\n");
       GNUNET_GC_free (cfg);
-      GNUNET_DHT_context_destroy (ctx_peer1);
       return -1;
     }
+  GNUNET_client_connection_destroy (sock);
+  ctx_peer1 =
+    GNUNET_DHT_context_create (cfg, ectx, &result_callback_peer1, &want);
 
   /* switch to peer2 */
   GNUNET_GC_set_configuration_value_string (cfg,
@@ -176,12 +177,11 @@
                                             "localhost:12087");
   /* verify that peer2 also sees the other DHT! */
   ok = 0;
-  ctx_peer2 =
-    GNUNET_DHT_context_create (cfg, ectx, &result_callback_peer2, NULL);
   left = 50;                    /* how many iterations should we wait? */
   printf ("Waiting for peers to DHT-connect (2->1)");
+  sock = GNUNET_client_connection_create (NULL, cfg);
   while (GNUNET_OK ==
-         GNUNET_STATS_get_statistics (NULL, ctx_peer2->sock, &waitForConnect,
+         GNUNET_STATS_get_statistics (NULL, sock, &waitForConnect,
                                       NULL))
     {
       printf (".");
@@ -194,13 +194,16 @@
   printf (left > 0 ? " OK!\n" : "?\n");
   if (ok == 0)
     {
+      GNUNET_client_connection_destroy (sock);
       GNUNET_TESTING_stop_daemons (peers);
       fprintf (stderr, "Peers' DHTs failed to DHT-connect!\n");
       GNUNET_GC_free (cfg);
       GNUNET_DHT_context_destroy (ctx_peer1);
-      GNUNET_DHT_context_destroy (ctx_peer2);
       return -1;
     }
+  GNUNET_client_connection_destroy (sock);
+  ctx_peer2 =
+    GNUNET_DHT_context_create (cfg, ectx, &result_callback_peer2, &want);
 
 
   /* actual test code */
@@ -209,7 +212,7 @@
                                             ectx,
                                             "NETWORK", "HOST",
                                             "localhost:2087");
-  GNUNET_hash ("key 1", 4, &key);
+  GNUNET_hash ("key 1", 5, &key);
   value = GNUNET_malloc (8);
   memset (value, 'A', 8);
   CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
@@ -217,7 +220,7 @@
                                       &key,
                                       GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                       8, value));
-  GNUNET_hash ("key 2", 3, &key);
+  GNUNET_hash ("key 2", 5, &key);
   value = GNUNET_malloc (8);
   memset (value, 'B', 8);
   CHECK (GNUNET_OK == GNUNET_DHT_put (cfg,
@@ -225,43 +228,59 @@
                                       &key,
                                       GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                       8, value));
-  GNUNET_hash ("key 1", 4, &key);
+  GNUNET_hash ("key 1", 5, &key);
   peer2count = 10;
   printf ("Getting key 1 from peer 2 (stored at peer 1)");
+  want = 'A';
   CHECK (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer2,
                                            
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                            &key));  
-  while (peer2count > 0);
+  for (k = 0; k < NUM_ROUNDS; k++)
+    {
+      if (0 == (k %10))
+       printf (".");
+      fflush (stdout);
+      GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS);
+      if (peer2count < 10)
+       break;
+    }  
   CHECK (GNUNET_OK == GNUNET_DHT_get_stop (ctx_peer2,
                                           
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                           &key));  
-  printf (peer2count > 0 ? " OK!\n" : "?\n");
+  printf (peer2count < 10 ? " OK!\n" : "?\n");
+  CHECK (peer2count < 10);
 
-  CHECK (peer2count > 0);
-
   printf ("Getting key 2 from peer 1 (stored at peer 2)");
+  GNUNET_hash ("key 2", 5, &key);
   peer1count = 10;
+  want = 'B';
   CHECK (GNUNET_OK == GNUNET_DHT_get_start (ctx_peer1,
                                            
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                            &key));
-
-  while (peer1count > 0);
-  printf (peer1count > 0 ? " OK!\n" : "?\n");
-  CHECK (peer1count > 0);
-
+  for (k = 0; k < NUM_ROUNDS; k++)
+    {
+      if (0 == (k %10))
+       printf (".");
+      fflush (stdout);
+      GNUNET_thread_sleep(50 * GNUNET_CRON_MILLISECONDS);
+      if (peer2count < 10)
+       break;
+    }
   CHECK (GNUNET_OK == GNUNET_DHT_get_stop (ctx_peer1,
                                           
GNUNET_ECRS_BLOCKTYPE_DHT_STRING2STRING,
                                           &key));
+  printf (peer1count < 10 ? " OK!\n" : "?\n");
+  CHECK (peer1count < 10);
 
   /* end of actual test code */
 
 FAILURE:
+  GNUNET_DHT_context_destroy (ctx_peer1);
+  GNUNET_DHT_context_destroy (ctx_peer2);
 #if START_PEERS
   GNUNET_TESTING_stop_daemons (peers);
 #endif
   GNUNET_GC_free (cfg);
-  GNUNET_DHT_context_destroy (ctx_peer1);
-  GNUNET_DHT_context_destroy (ctx_peer2);
   return ret;
 }
 





reply via email to

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