aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_peer.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-10 08:16:49 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-10 08:16:49 +0000
commit660c6da4fcbca6bd2cb15599dfe3c6d53b890c7f (patch)
treea4085d49c56bd9498cf5b40847a6aa29c31ac618 /src/util/test_peer.c
parent167aef74f57116be5a859d0c0568102943f54ab8 (diff)
downloadgnunet-660c6da4fcbca6bd2cb15599dfe3c6d53b890c7f.tar.gz
gnunet-660c6da4fcbca6bd2cb15599dfe3c6d53b890c7f.zip
indent
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r--src/util/test_peer.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 0f4a227d3..e2fd100fd 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -36,70 +36,80 @@
36static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS]; 36static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
37 37
38 38
39static void generatePeerIdList() 39static void
40generatePeerIdList ()
40{ 41{
41 int i; 42 int i;
42 43
43 for (i = 0; i < NUMBER_OF_PEERS; i++ ) { 44 for (i = 0; i < NUMBER_OF_PEERS; i++)
44 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &pidArr[i].hashPubKey); 45 {
46 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
47 &pidArr[i].hashPubKey);
45#ifdef DEBUG 48#ifdef DEBUG
46 printf ("Peer %d: %s\n", 49 printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
47 i,
48 GNUNET_i2s (&pidArr[i]));
49#endif 50#endif
50 } 51 }
51} 52}
52 53
53 54
54static int check() 55static int
56check ()
55{ 57{
56 int i; 58 int i;
57 GNUNET_PEER_Id pid; 59 GNUNET_PEER_Id pid;
58 60
59 /* Insert Peers into PeerEntry table and hashmap */ 61 /* Insert Peers into PeerEntry table and hashmap */
60 for (i=0; i < NUMBER_OF_PEERS; i++) { 62 for (i = 0; i < NUMBER_OF_PEERS; i++)
61 pid = GNUNET_PEER_intern(&pidArr[i]); 63 {
62 if ( pid != (i + 1)) { 64 pid = GNUNET_PEER_intern (&pidArr[i]);
63 fprintf(stderr, "Unexpected Peer ID returned by intern function \n"); 65 if (pid != (i + 1))
64 return 1; 66 {
67 fprintf (stderr,
68 "Unexpected Peer ID returned by intern function \n");
69 return 1;
70 }
65 } 71 }
66 } 72
67
68 /* Referencing the first 3 peers once again */ 73 /* Referencing the first 3 peers once again */
69 for (i = 0; i < 3; i++) { 74 for (i = 0; i < 3; i++)
70 pid = GNUNET_PEER_intern(&pidArr[i]); 75 {
71 if (pid != (i + 1)) { 76 pid = GNUNET_PEER_intern (&pidArr[i]);
72 fprintf(stderr, "Unexpcted Peer ID returned by intern function \n"); 77 if (pid != (i + 1))
73 return 1; 78 {
79 fprintf (stderr,
80 "Unexpcted Peer ID returned by intern function \n");
81 return 1;
82 }
74 } 83 }
75 } 84
76
77 /* Dereferencing the first 3 peers once [decrementing their reference count] */ 85 /* Dereferencing the first 3 peers once [decrementing their reference count] */
78 { 86 {
79 GNUNET_PEER_Id ids[] = {1, 2, 3}; 87 GNUNET_PEER_Id ids[] = { 1, 2, 3 };
80 GNUNET_PEER_decrement_rcs(ids, 3); 88 GNUNET_PEER_decrement_rcs (ids, 3);
81 } 89 }
82 90
83 /* re-referencing the first 3 peers using the change_rc function */ 91 /* re-referencing the first 3 peers using the change_rc function */
84 for (i = 0; i < 3; i++) { 92 for (i = 0; i < 3; i++)
85 GNUNET_PEER_change_rc(i, 1); 93 {
86 } 94 GNUNET_PEER_change_rc (i, 1);
87 95 }
96
88 /* Removing the second Peer from the PeerEntry hash map */ 97 /* Removing the second Peer from the PeerEntry hash map */
89 GNUNET_PEER_change_rc(2, -2); 98 GNUNET_PEER_change_rc (2, -2);
90 99
91 /* convert the pid of the first PeerEntry into that of the third */ 100 /* convert the pid of the first PeerEntry into that of the third */
92 GNUNET_PEER_resolve(1, &pidArr[3]); 101 GNUNET_PEER_resolve (1, &pidArr[3]);
93 102
94 return 0; 103 return 0;
95} 104}
96 105
97 106
98int main() 107int
108main ()
99{ 109{
100 GNUNET_log_setup ("test-peer", "ERROR", NULL); 110 GNUNET_log_setup ("test-peer", "ERROR", NULL);
101 generatePeerIdList(); 111 generatePeerIdList ();
102 return check(); 112 return check ();
103} 113}
104 114
105/* end of test_peer.c */ 115/* end of test_peer.c */