X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Ftest_peer.c;h=fa4d31b8db3bd2e319eabd683c2e918b3bdc8a95;hb=72c8645af31896829b674b575c5375706f362a30;hp=5e3e97ac476374744655d9a617ab6dbd5a2e7b63;hpb=38b29592cf2e8b816cab68579e07e2477153f739;p=oweals%2Fgnunet.git diff --git a/src/util/test_peer.c b/src/util/test_peer.c index 5e3e97ac4..fa4d31b8d 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c @@ -29,10 +29,8 @@ #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]; @@ -43,13 +41,12 @@ generatePeerIdList () 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 - } + { + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &pidArr[i].hashPubKey); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); + } } @@ -65,27 +62,25 @@ check () 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++) + { + 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); @@ -101,10 +96,10 @@ check () 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 - * 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); @@ -126,14 +121,15 @@ check () int main () { - int i; + unsigned int 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; }