diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-09 22:40:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-09 22:40:03 +0000 |
commit | efa495524a5be052ee67793e4bcf600ba05e149c (patch) | |
tree | 2925c3218cf298600e5c5d247abed0c73d18e3de /src/util/test_peer.c | |
parent | c193ad71b2ba954bc414c568566ef0d02ba73f98 (diff) | |
download | gnunet-efa495524a5be052ee67793e4bcf600ba05e149c.tar.gz gnunet-efa495524a5be052ee67793e4bcf600ba05e149c.zip |
code clean up
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r-- | src/util/test_peer.c | 116 |
1 files changed, 52 insertions, 64 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c index 63610e420..0f4a227d3 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c | |||
@@ -30,88 +30,76 @@ | |||
30 | #define NUMBER_OF_PEERS 10 | 30 | #define NUMBER_OF_PEERS 10 |
31 | /*#define DEBUG*/ | 31 | /*#define DEBUG*/ |
32 | 32 | ||
33 | /* Global Variables */ | 33 | /** |
34 | static struct GNUNET_PeerIdentity** pidArr; /* A list of Peer ID's to play with */ | 34 | * A list of Peer ID's to play with |
35 | */ | ||
36 | static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS]; | ||
35 | 37 | ||
36 | 38 | ||
37 | static void generatePeerIdList() | 39 | static void generatePeerIdList() |
38 | { | 40 | { |
39 | int i; /* Loop Index */ | 41 | int i; |
40 | |||
41 | pidArr = GNUNET_malloc(NUMBER_OF_PEERS * sizeof(struct GNUNET_PeerIdentity*)); | ||
42 | for (i = 0; i < NUMBER_OF_PEERS; i++ ) { | ||
43 | pidArr[i] = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | ||
44 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &(pidArr[i]->hashPubKey)); | ||
45 | 42 | ||
43 | for (i = 0; i < NUMBER_OF_PEERS; i++ ) { | ||
44 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &pidArr[i].hashPubKey); | ||
46 | #ifdef DEBUG | 45 | #ifdef DEBUG |
47 | { | 46 | printf ("Peer %d: %s\n", |
48 | struct GNUNET_CRYPTO_HashAsciiEncoded hashAsciiEncoded; | 47 | i, |
49 | GNUNET_CRYPTO_hash_to_enc(&(pidArr[i]->hashPubKey), &hashAsciiEncoded); | 48 | GNUNET_i2s (&pidArr[i])); |
50 | printf ("I'm Peer: %s\n", (char*) &hashAsciiEncoded); | ||
51 | } | ||
52 | #endif | 49 | #endif |
53 | } | 50 | } |
54 | } | 51 | } |
55 | 52 | ||
56 | static void destroyPeerIdList() | ||
57 | { | ||
58 | int i; | ||
59 | for (i = 0; i < NUMBER_OF_PEERS; i++) { | ||
60 | GNUNET_free(pidArr[i]); | ||
61 | } | ||
62 | GNUNET_free(pidArr); | ||
63 | } | ||
64 | 53 | ||
65 | static int check() | 54 | static int check() |
66 | { | 55 | { |
67 | int i = 0; | 56 | int i; |
68 | GNUNET_PEER_Id pid; | 57 | GNUNET_PEER_Id pid; |
69 | |||
70 | /* Insert Peers into PeerEntry table and hashmap */ | ||
71 | for (; i < NUMBER_OF_PEERS; i++) { | ||
72 | pid = GNUNET_PEER_intern(pidArr[i]); | ||
73 | if ( pid != (i + 1)) { | ||
74 | fprintf(stderr, "Unexpected Peer ID returned by intern function \n"); | ||
75 | return 1; | ||
76 | } | ||
77 | } | ||
78 | 58 | ||
79 | /* Referencing the first 3 peers once again */ | 59 | /* Insert Peers into PeerEntry table and hashmap */ |
80 | for (i = 0; i < 3; i++) { | 60 | for (i=0; i < NUMBER_OF_PEERS; i++) { |
81 | pid = GNUNET_PEER_intern(pidArr[i]); | 61 | pid = GNUNET_PEER_intern(&pidArr[i]); |
82 | if (pid != (i + 1)) { | 62 | if ( pid != (i + 1)) { |
83 | fprintf(stderr, "Unexpcted Peer ID returned by intern function \n"); | 63 | fprintf(stderr, "Unexpected Peer ID returned by intern function \n"); |
84 | return 1; | 64 | return 1; |
85 | } | 65 | } |
86 | } | 66 | } |
87 | 67 | ||
88 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ | 68 | /* Referencing the first 3 peers once again */ |
89 | { | 69 | for (i = 0; i < 3; i++) { |
90 | GNUNET_PEER_Id ids[] = {1, 2, 3}; | 70 | pid = GNUNET_PEER_intern(&pidArr[i]); |
91 | GNUNET_PEER_decrement_rcs(ids, 3); | 71 | if (pid != (i + 1)) { |
92 | } | 72 | fprintf(stderr, "Unexpcted Peer ID returned by intern function \n"); |
73 | return 1; | ||
74 | } | ||
75 | } | ||
93 | 76 | ||
94 | /* re-referencing the first 3 peers using the change_rc function */ | 77 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ |
95 | for (i = 0; i < 3; i++) { | 78 | { |
96 | GNUNET_PEER_change_rc(i, 1); | 79 | GNUNET_PEER_Id ids[] = {1, 2, 3}; |
97 | } | 80 | GNUNET_PEER_decrement_rcs(ids, 3); |
81 | } | ||
82 | |||
83 | /* re-referencing the first 3 peers using the change_rc function */ | ||
84 | for (i = 0; i < 3; i++) { | ||
85 | GNUNET_PEER_change_rc(i, 1); | ||
86 | } | ||
87 | |||
88 | /* Removing the second Peer from the PeerEntry hash map */ | ||
89 | GNUNET_PEER_change_rc(2, -2); | ||
90 | |||
91 | /* convert the pid of the first PeerEntry into that of the third */ | ||
92 | GNUNET_PEER_resolve(1, &pidArr[3]); | ||
98 | 93 | ||
99 | /* Removing the second Peer from the PeerEntry hash map */ | 94 | return 0; |
100 | GNUNET_PEER_change_rc(2, -2); | ||
101 | |||
102 | /* convert the pid of the first PeerEntry into that of the third */ | ||
103 | GNUNET_PEER_resolve(1, pidArr[3]); | ||
104 | |||
105 | return 0; | ||
106 | } | 95 | } |
107 | 96 | ||
97 | |||
108 | int main() | 98 | int main() |
109 | { | 99 | { |
110 | int ret; | 100 | GNUNET_log_setup ("test-peer", "ERROR", NULL); |
111 | GNUNET_log_setup ("test-peer", "ERROR", NULL); | 101 | generatePeerIdList(); |
112 | generatePeerIdList(); | 102 | return check(); |
113 | ret = check(); | ||
114 | destroyPeerIdList(); | ||
115 | |||
116 | return ret; | ||
117 | } | 103 | } |
104 | |||
105 | /* end of test_peer.c */ | ||