diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-05 21:10:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-05 21:10:48 +0000 |
commit | 4989f1f56b69db11da245ec92a981f1ee4c67a0b (patch) | |
tree | ea535511c830e3550fe36db3feb1336399cfccdd /src/consensus/gnunet-consensus-profiler.c | |
parent | f4dd1ae2a22c3a3e53be15494649730ca46d544c (diff) | |
download | gnunet-4989f1f56b69db11da245ec92a981f1ee4c67a0b.tar.gz gnunet-4989f1f56b69db11da245ec92a981f1ee4c67a0b.zip |
-fixing indentation/doxygen/style issues and some memory leaks in gnunet-consensus-profiler
Diffstat (limited to 'src/consensus/gnunet-consensus-profiler.c')
-rw-r--r-- | src/consensus/gnunet-consensus-profiler.c | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c index bade332b5..6b01f9d8e 100644 --- a/src/consensus/gnunet-consensus-profiler.c +++ b/src/consensus/gnunet-consensus-profiler.c | |||
@@ -65,18 +65,20 @@ static int verbose; | |||
65 | * @param event information about the event | 65 | * @param event information about the event |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | controller_cb(void *cls, | 68 | controller_cb (void *cls, |
69 | const struct GNUNET_TESTBED_EventInformation *event) | 69 | const struct GNUNET_TESTBED_EventInformation *event) |
70 | { | 70 | { |
71 | GNUNET_assert (0); | 71 | GNUNET_assert (0); |
72 | } | 72 | } |
73 | 73 | ||
74 | |||
74 | static void | 75 | static void |
75 | destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx) | 76 | destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx) |
76 | { | 77 | { |
77 | struct GNUNET_CONSENSUS_Handle *consensus; | 78 | struct GNUNET_CONSENSUS_Handle *consensus = cls; |
78 | consensus = cls; | 79 | |
79 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying consensus\n"); | 80 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
81 | "destroying consensus\n"); | ||
80 | GNUNET_CONSENSUS_destroy (consensus); | 82 | GNUNET_CONSENSUS_destroy (consensus); |
81 | peers_done++; | 83 | peers_done++; |
82 | if (peers_done == num_peers) | 84 | if (peers_done == num_peers) |
@@ -85,7 +87,10 @@ destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx) | |||
85 | for (i = 0; i < num_peers; i++) | 87 | for (i = 0; i < num_peers; i++) |
86 | GNUNET_TESTBED_operation_done (testbed_operations[i]); | 88 | GNUNET_TESTBED_operation_done (testbed_operations[i]); |
87 | for (i = 0; i < num_peers; i++) | 89 | for (i = 0; i < num_peers; i++) |
88 | printf ("P%u got %u of %u elements\n", i, results_for_peer[i], num_values); | 90 | printf ("P%u got %u of %u elements\n", |
91 | i, | ||
92 | results_for_peer[i], | ||
93 | num_values); | ||
89 | GNUNET_SCHEDULER_shutdown (); | 94 | GNUNET_SCHEDULER_shutdown (); |
90 | } | 95 | } |
91 | } | 96 | } |
@@ -95,13 +100,17 @@ destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx) | |||
95 | * Called when a conclusion was successful. | 100 | * Called when a conclusion was successful. |
96 | * | 101 | * |
97 | * @param cls closure, the consensus handle | 102 | * @param cls closure, the consensus handle |
98 | * @return GNUNET_YES if more consensus groups should be offered, GNUNET_NO if not | 103 | * @return #GNUNET_YES if more consensus groups should be offered, |
104 | * #GNUNET_NO if not | ||
99 | */ | 105 | */ |
100 | static void | 106 | static void |
101 | conclude_cb (void *cls) | 107 | conclude_cb (void *cls) |
102 | { | 108 | { |
103 | struct GNUNET_CONSENSUS_Handle **chp = cls; | 109 | struct GNUNET_CONSENSUS_Handle **chp = cls; |
104 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "consensus %d done\n", chp - consensus_handles); | 110 | |
111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
112 | "consensus %d done\n", | ||
113 | chp - consensus_handles); | ||
105 | GNUNET_SCHEDULER_add_now (destroy, *chp); | 114 | GNUNET_SCHEDULER_add_now (destroy, *chp); |
106 | } | 115 | } |
107 | 116 | ||
@@ -134,34 +143,37 @@ static void | |||
134 | do_consensus () | 143 | do_consensus () |
135 | { | 144 | { |
136 | int unique_indices[replication]; | 145 | int unique_indices[replication]; |
137 | int i; | 146 | unsigned int i; |
138 | 147 | ||
139 | for (i = 0; i < num_values; i++) | 148 | for (i = 0; i < num_values; i++) |
140 | { | 149 | { |
141 | int j; | 150 | unsigned int j; |
142 | struct GNUNET_HashCode *val; | 151 | struct GNUNET_HashCode val; |
143 | struct GNUNET_SET_Element *element; | 152 | struct GNUNET_SET_Element element; |
144 | generate_indices(unique_indices); | ||
145 | |||
146 | val = GNUNET_malloc (sizeof *val); | ||
147 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, val); | ||
148 | 153 | ||
149 | element = GNUNET_malloc (sizeof *element); | 154 | generate_indices (unique_indices); |
150 | element->data = val; | 155 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val); |
151 | element->size = sizeof *val; | ||
152 | 156 | ||
157 | element.data = &val; | ||
158 | element.size = sizeof (val); | ||
153 | for (j = 0; j < replication; j++) | 159 | for (j = 0; j < replication; j++) |
154 | { | 160 | { |
155 | int cid; | 161 | int cid; |
162 | |||
156 | cid = unique_indices[j]; | 163 | cid = unique_indices[j]; |
157 | GNUNET_CONSENSUS_insert (consensus_handles[cid], element, NULL, NULL); | 164 | GNUNET_CONSENSUS_insert (consensus_handles[cid], |
165 | &element, | ||
166 | NULL, NULL); | ||
158 | } | 167 | } |
159 | } | 168 | } |
160 | 169 | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "all elements inserted, calling conclude\n"); | 170 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
171 | "all elements inserted, calling conclude\n"); | ||
162 | 172 | ||
163 | for (i = 0; i < num_peers; i++) | 173 | for (i = 0; i < num_peers; i++) |
164 | GNUNET_CONSENSUS_conclude (consensus_handles[i], conclude_timeout, conclude_cb, &consensus_handles[i]); | 174 | GNUNET_CONSENSUS_conclude (consensus_handles[i], |
175 | conclude_timeout, | ||
176 | conclude_cb, &consensus_handles[i]); | ||
165 | } | 177 | } |
166 | 178 | ||
167 | 179 | ||
@@ -183,13 +195,16 @@ connect_complete (void *cls, | |||
183 | 195 | ||
184 | if (NULL != emsg) | 196 | if (NULL != emsg) |
185 | { | 197 | { |
186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "testbed connect emsg: %s\n", emsg); | 198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
199 | "testbed connect emsg: %s\n", | ||
200 | emsg); | ||
187 | GNUNET_assert (0); | 201 | GNUNET_assert (0); |
188 | } | 202 | } |
189 | 203 | ||
190 | num_connected_handles++; | 204 | num_connected_handles++; |
191 | 205 | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connect complete\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
207 | "connect complete\n"); | ||
193 | 208 | ||
194 | if (num_connected_handles == num_peers) | 209 | if (num_connected_handles == num_peers) |
195 | { | 210 | { |
@@ -213,7 +228,9 @@ new_element_cb (void *cls, | |||
213 | 228 | ||
214 | if (GNUNET_YES == verbose) | 229 | if (GNUNET_YES == verbose) |
215 | { | 230 | { |
216 | printf ("P%d received %s\n", idx, GNUNET_h2s ((struct GNUNET_HashCode *) element->data)); | 231 | printf ("P%d received %s\n", |
232 | idx, | ||
233 | GNUNET_h2s ((struct GNUNET_HashCode *) element->data)); | ||
217 | } | 234 | } |
218 | } | 235 | } |
219 | 236 | ||
@@ -236,8 +253,13 @@ connect_adapter (void *cls, | |||
236 | struct GNUNET_CONSENSUS_Handle *consensus; | 253 | struct GNUNET_CONSENSUS_Handle *consensus; |
237 | chp = (struct GNUNET_CONSENSUS_Handle **) cls; | 254 | chp = (struct GNUNET_CONSENSUS_Handle **) cls; |
238 | 255 | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connect adapter, %d peers\n", num_peers); | 256 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
240 | consensus = GNUNET_CONSENSUS_create (cfg, num_peers, peer_ids, &session_id, new_element_cb, chp); | 257 | "connect adapter, %d peers\n", |
258 | num_peers); | ||
259 | consensus = GNUNET_CONSENSUS_create (cfg, | ||
260 | num_peers, peer_ids, | ||
261 | &session_id, | ||
262 | &new_element_cb, chp); | ||
241 | *chp = (struct GNUNET_CONSENSUS_Handle *) consensus; | 263 | *chp = (struct GNUNET_CONSENSUS_Handle *) consensus; |
242 | return consensus; | 264 | return consensus; |
243 | } | 265 | } |
@@ -340,6 +362,7 @@ test_master (void *cls, | |||
340 | &peer_ids[i]); | 362 | &peer_ids[i]); |
341 | } | 363 | } |
342 | 364 | ||
365 | |||
343 | static void | 366 | static void |
344 | run (void *cls, char *const *args, const char *cfgfile, | 367 | run (void *cls, char *const *args, const char *cfgfile, |
345 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 368 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -350,8 +373,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
350 | 373 | ||
351 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology)) | 374 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology)) |
352 | { | 375 | { |
353 | fprintf (stderr, "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, " | 376 | fprintf (stderr, |
354 | "seems like you passed the wrong configuration file\n"); | 377 | "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, " |
378 | "seems like you passed the wrong configuration file\n"); | ||
355 | return; | 379 | return; |
356 | } | 380 | } |
357 | 381 | ||
@@ -360,8 +384,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
360 | 384 | ||
361 | if (0 == topology_cmp_result) | 385 | if (0 == topology_cmp_result) |
362 | { | 386 | { |
363 | fprintf (stderr, "'OVERLAY_TOPOLOGY' set to 'NONE', " | 387 | fprintf (stderr, |
364 | "seems like you passed the wrong configuration file\n"); | 388 | "'OVERLAY_TOPOLOGY' set to 'NONE', " |
389 | "seems like you passed the wrong configuration file\n"); | ||
365 | return; | 390 | return; |
366 | } | 391 | } |
367 | 392 | ||
@@ -371,7 +396,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
371 | return; | 396 | return; |
372 | } | 397 | } |
373 | 398 | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running gnunet-consensus\n"); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
400 | "running gnunet-consensus\n"); | ||
375 | 401 | ||
376 | GNUNET_CRYPTO_hash (session_str, strlen(session_str), &session_id); | 402 | GNUNET_CRYPTO_hash (session_str, strlen(session_str), &session_id); |
377 | 403 | ||
@@ -408,7 +434,7 @@ main (int argc, char **argv) | |||
408 | GNUNET_GETOPT_OPTION_END | 434 | GNUNET_GETOPT_OPTION_END |
409 | }; | 435 | }; |
410 | conclude_timeout = GNUNET_TIME_UNIT_SECONDS; | 436 | conclude_timeout = GNUNET_TIME_UNIT_SECONDS; |
411 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus", | 437 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus-profiler", |
412 | "help", | 438 | "help", |
413 | options, &run, NULL, GNUNET_YES); | 439 | options, &run, NULL, GNUNET_YES); |
414 | return 0; | 440 | return 0; |