rps.conf is generated from rps.conf.in
[oweals/gnunet.git] / src / util / test_peer.c
index 45633119cf84a2b2df2842c8f158b2b52fe3a8ce..d16c66a27da4a706cdba1c3aea8b316c8b1293af 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file util/test_peer.c
 */
 /**
  * @file util/test_peer.c
  */
 
 #include "platform.h"
  */
 
 #include "platform.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_peer_lib.h"
+#include "gnunet_util_lib.h"
+#include <gcrypt.h>
 
 #define NUMBER_OF_PEERS 10
 
 
 #define NUMBER_OF_PEERS 10
 
-#define DEBUG GNUNET_NO
-
 /**
 /**
- * A list of Peer ID's to play with 
+ * A list of Peer ID's to play with
  */
 static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
 
  */
 static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
 
@@ -43,13 +41,13 @@ generatePeerIdList ()
   int i;
 
   for (i = 0; i < NUMBER_OF_PEERS; i++)
   int i;
 
   for (i = 0; i < NUMBER_OF_PEERS; i++)
-    {
-      GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
-                                       &pidArr[i].hashPubKey);
-#if DEBUG
-      printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
-#endif
-    }
+  {
+    gcry_randomize (&pidArr[i],
+                    sizeof (struct GNUNET_PeerIdentity),
+                    GCRY_STRONG_RANDOM);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
+  }
 }
 
 
 }
 
 
@@ -65,27 +63,25 @@ check ()
   GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
   /* Insert Peers into PeerEntry table and hashmap */
   for (i = 0; i < NUMBER_OF_PEERS; i++)
   GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
   /* Insert Peers into PeerEntry table and hashmap */
   for (i = 0; i < NUMBER_OF_PEERS; i++)
+  {
+    pid = GNUNET_PEER_intern (&pidArr[i]);
+    if (pid != (i + 1))
     {
     {
-      pid = GNUNET_PEER_intern (&pidArr[i]);
-      if (pid != (i + 1))
-       {
-         fprintf (stderr,
-                  "Unexpected Peer ID returned by intern function \n");
-         return 1;
-       }
+      FPRINTF (stderr, "%s",  "Unexpected Peer ID returned by intern function\n");
+      return 1;
     }
     }
+  }
 
   /* Referencing the first 3 peers once again */
   for (i = 0; i < 3; i++)
 
   /* Referencing the first 3 peers once again */
   for (i = 0; i < 3; i++)
+  {
+    pid = GNUNET_PEER_intern (&pidArr[i]);
+    if (pid != (i + 1))
     {
     {
-      pid = GNUNET_PEER_intern (&pidArr[i]);
-      if (pid != (i + 1))
-       {
-         fprintf (stderr,
-                  "Unexpected Peer ID returned by intern function \n");
-         return 1;
-       }
+      FPRINTF (stderr, "%s",  "Unexpected Peer ID returned by intern function\n");
+      return 1;
     }
     }
+  }
 
   /* Dereferencing the first 3 peers once [decrementing their reference count] */
   GNUNET_PEER_decrement_rcs (ids, 3);
 
   /* Dereferencing the first 3 peers once [decrementing their reference count] */
   GNUNET_PEER_decrement_rcs (ids, 3);
@@ -101,10 +97,10 @@ check ()
   GNUNET_PEER_resolve (1, &res);
   GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res)));
 
   GNUNET_PEER_resolve (1, &res);
   GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res)));
 
-  /* 
-   * Attempt to convert pid = 0 (which is reserved) 
+  /*
+   * Attempt to convert pid = 0 (which is reserved)
    * into a peer identity object, the peer identity memory
    * into a peer identity object, the peer identity memory
-   * is expected to be set to zero 
+   * is expected to be set to zero
    */
   memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
   GNUNET_log_skip (1, GNUNET_YES);
    */
   memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
   GNUNET_log_skip (1, GNUNET_YES);
@@ -126,14 +122,15 @@ check ()
 int
 main ()
 {
 int
 main ()
 {
-  int i;
+  unsigned int i;
+
   GNUNET_log_setup ("test-peer", "ERROR", NULL);
   for (i = 0; i < 1; i++)
   GNUNET_log_setup ("test-peer", "ERROR", NULL);
   for (i = 0; i < 1; i++)
-    {
-      generatePeerIdList ();
-      if (0 != check ())
-       return 1;
-    }
+  {
+    generatePeerIdList ();
+    if (0 != check ())
+      return 1;
+  }
   return 0;
 }
 
   return 0;
 }