diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-04 16:51:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-04 16:51:45 +0000 |
commit | 4a24e01d19cdad1e6c1bcd72b1919e18c90e0ba0 (patch) | |
tree | 432157b54e505b2c915a5207e74f3c2909989118 /src/revocation/test_revocation.c | |
parent | 42eda11ebcf7a40181bb74804f5ffb4c52bb1e14 (diff) | |
download | gnunet-4a24e01d19cdad1e6c1bcd72b1919e18c90e0ba0.tar.gz gnunet-4a24e01d19cdad1e6c1bcd72b1919e18c90e0ba0.zip |
-indentation, logging fixes
Diffstat (limited to 'src/revocation/test_revocation.c')
-rw-r--r-- | src/revocation/test_revocation.c | 137 |
1 files changed, 97 insertions, 40 deletions
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index c1278c650..d9e7a669a 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -55,8 +55,10 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
55 | */ | 55 | */ |
56 | static int ok; | 56 | static int ok; |
57 | 57 | ||
58 | |||
58 | static void | 59 | static void |
59 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 60 | do_shutdown (void *cls, |
61 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
60 | { | 62 | { |
61 | int c; | 63 | int c; |
62 | 64 | ||
@@ -99,6 +101,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
99 | ok = 0; | 101 | ok = 0; |
100 | } | 102 | } |
101 | 103 | ||
104 | |||
102 | static void | 105 | static void |
103 | do_shutdown_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 106 | do_shutdown_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
104 | { | 107 | { |
@@ -129,26 +132,31 @@ identity_disconnect_adapter (void *cls, void *op_result) | |||
129 | me->idh = NULL; | 132 | me->idh = NULL; |
130 | } | 133 | } |
131 | 134 | ||
135 | |||
132 | static void | 136 | static void |
133 | check_revocation (); | 137 | check_revocation (); |
134 | 138 | ||
139 | |||
135 | static void | 140 | static void |
136 | revocation_remote_cb (void *cls, int is_valid) | 141 | revocation_remote_cb (void *cls, int is_valid) |
137 | { | 142 | { |
138 | static int repeat = 0; | 143 | static int repeat = 0; |
139 | if (GNUNET_NO == is_valid) | 144 | if (GNUNET_NO == is_valid) |
140 | { | 145 | { |
141 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); | 146 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
147 | "Local revocation successful\n"); | ||
142 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL ); | 148 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL ); |
143 | } | 149 | } |
144 | else if (repeat < 10) | 150 | else if (repeat < 10) |
145 | { | 151 | { |
146 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &check_revocation, | 152 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
147 | NULL ); | 153 | &check_revocation, |
154 | NULL ); | ||
148 | } | 155 | } |
149 | else | 156 | else |
150 | { | 157 | { |
151 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Flooding of revocation failed\n"); | 158 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
159 | "Flooding of revocation failed\n"); | ||
152 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 160 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
153 | { | 161 | { |
154 | GNUNET_SCHEDULER_cancel (die_task); | 162 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -159,28 +167,35 @@ revocation_remote_cb (void *cls, int is_valid) | |||
159 | repeat++; | 167 | repeat++; |
160 | } | 168 | } |
161 | 169 | ||
170 | |||
162 | static void | 171 | static void |
163 | check_revocation () | 172 | check_revocation () |
164 | { | 173 | { |
165 | GNUNET_REVOCATION_query (testpeers[0].cfg, &testpeers[1].pubkey, | 174 | GNUNET_REVOCATION_query (testpeers[0].cfg, |
166 | &revocation_remote_cb, NULL ); | 175 | &testpeers[1].pubkey, |
176 | &revocation_remote_cb, NULL); | ||
167 | } | 177 | } |
168 | 178 | ||
179 | |||
169 | static void | 180 | static void |
170 | revocation_cb (void *cls, int is_valid) | 181 | revocation_cb (void *cls, int is_valid) |
171 | { | 182 | { |
172 | testpeers[1].revok_handle = NULL; | 183 | testpeers[1].revok_handle = NULL; |
173 | if (GNUNET_NO == is_valid) | 184 | if (GNUNET_NO == is_valid) |
174 | { | 185 | { |
175 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); | 186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
187 | "Revocation successful\n"); | ||
176 | check_revocation (); | 188 | check_revocation (); |
177 | } | 189 | } |
178 | } | 190 | } |
179 | 191 | ||
192 | |||
180 | static void | 193 | static void |
181 | ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | 194 | ego_cb (void *cls, |
195 | const struct GNUNET_IDENTITY_Ego *ego) | ||
182 | { | 196 | { |
183 | static int completed = 0; | 197 | static int completed = 0; |
198 | |||
184 | if ((NULL != ego) && (cls == &testpeers[0])) | 199 | if ((NULL != ego) && (cls == &testpeers[0])) |
185 | { | 200 | { |
186 | testpeers[0].ego_lookup = NULL; | 201 | testpeers[0].ego_lookup = NULL; |
@@ -195,32 +210,41 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) | |||
195 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); | 210 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); |
196 | GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); | 211 | GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); |
197 | 212 | ||
198 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); | 213 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
214 | "Calculating proof of work...\n"); | ||
199 | testpeers[1].pow = 0; | 215 | testpeers[1].pow = 0; |
200 | int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, | 216 | int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, |
201 | testpeers[1].pow, 5); | 217 | testpeers[1].pow, 5); |
202 | while (GNUNET_OK != res) | 218 | while (GNUNET_OK != res) |
203 | { | 219 | { |
204 | testpeers[1].pow++; | 220 | testpeers[1].pow++; |
205 | res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, | 221 | res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, |
206 | 5); | 222 | testpeers[1].pow, |
223 | 5); | ||
207 | } | 224 | } |
208 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done calculating proof of work\n"); | 225 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
226 | "Done calculating proof of work\n"); | ||
209 | completed++; | 227 | completed++; |
210 | } | 228 | } |
211 | if (2 == completed) | 229 | if (2 == completed) |
212 | { | 230 | { |
213 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); | 231 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
232 | "Egos retrieved\n"); | ||
214 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, | 233 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, |
215 | &testpeers[1].pubkey, &testpeers[1].sig, testpeers[1].pow, | 234 | &testpeers[1].pubkey, |
216 | revocation_cb, NULL ); | 235 | &testpeers[1].sig, |
236 | testpeers[1].pow, | ||
237 | revocation_cb, NULL); | ||
217 | } | 238 | } |
218 | } | 239 | } |
219 | 240 | ||
220 | void | 241 | |
221 | identity_create_cb (void *cls, const char *emsg) | 242 | static void |
243 | identity_create_cb (void *cls, | ||
244 | const char *emsg) | ||
222 | { | 245 | { |
223 | static int completed = 0; | 246 | static int completed = 0; |
247 | |||
224 | if ((NULL == emsg) && (cls == &testpeers[0])) | 248 | if ((NULL == emsg) && (cls == &testpeers[0])) |
225 | { | 249 | { |
226 | testpeers[0].create_id_op = NULL; | 250 | testpeers[0].create_id_op = NULL; |
@@ -233,23 +257,32 @@ identity_create_cb (void *cls, const char *emsg) | |||
233 | } | 257 | } |
234 | if (2 == completed) | 258 | if (2 == completed) |
235 | { | 259 | { |
236 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Identities created\n"); | 260 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
261 | "Identities created\n"); | ||
237 | testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, | 262 | testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, |
238 | "client", ego_cb, &testpeers[0]); | 263 | "client", |
264 | ego_cb, | ||
265 | &testpeers[0]); | ||
239 | testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, | 266 | testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, |
240 | "toberevoked", ego_cb, &testpeers[1]); | 267 | "toberevoked", |
268 | ego_cb, | ||
269 | &testpeers[1]); | ||
241 | } | 270 | } |
242 | } | 271 | } |
243 | 272 | ||
273 | |||
244 | static void | 274 | static void |
245 | identity_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 275 | identity_completion_cb (void *cls, |
246 | void *ca_result, const char *emsg) | 276 | struct GNUNET_TESTBED_Operation *op, |
277 | void *ca_result, | ||
278 | const char *emsg) | ||
247 | { | 279 | { |
248 | static int completed = 0; | 280 | static int completed = 0; |
249 | completed++; | 281 | completed++; |
250 | if (NUM_TEST_PEERS == completed) | 282 | if (NUM_TEST_PEERS == completed) |
251 | { | 283 | { |
252 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to identity\n"); | 284 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
285 | "Connected to identity\n"); | ||
253 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, | 286 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, |
254 | "client", identity_create_cb, &testpeers[0]); | 287 | "client", identity_create_cb, &testpeers[0]); |
255 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, | 288 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, |
@@ -257,13 +290,18 @@ identity_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
257 | } | 290 | } |
258 | } | 291 | } |
259 | 292 | ||
260 | void static connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | 293 | |
294 | static void | ||
295 | connect_cb (void *cls, | ||
296 | const struct GNUNET_PeerIdentity *peer) | ||
261 | { | 297 | { |
262 | static int connects = 0; | 298 | static int connects = 0; |
299 | |||
263 | connects++; | 300 | connects++; |
264 | if (4 == connects) | 301 | if (4 == connects) |
265 | { | 302 | { |
266 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "All peers connected ...\n"); | 303 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
304 | "All peers connected ...\n"); | ||
267 | 305 | ||
268 | /* Connect to identity service */ | 306 | /* Connect to identity service */ |
269 | testpeers[0].identity_op = GNUNET_TESTBED_service_connect (NULL, | 307 | testpeers[0].identity_op = GNUNET_TESTBED_service_connect (NULL, |
@@ -279,14 +317,17 @@ void static connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
279 | 317 | ||
280 | 318 | ||
281 | static void | 319 | static void |
282 | core_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 320 | core_completion_cb (void *cls, |
283 | void *ca_result, const char *emsg) | 321 | struct GNUNET_TESTBED_Operation *op, |
322 | void *ca_result, | ||
323 | const char *emsg) | ||
284 | { | 324 | { |
285 | static int completed = 0; | 325 | static int completed = 0; |
286 | completed++; | 326 | completed++; |
287 | if (NUM_TEST_PEERS == completed) | 327 | if (NUM_TEST_PEERS == completed) |
288 | { | 328 | { |
289 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); | 329 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
330 | "Connected to CORE\n"); | ||
290 | } | 331 | } |
291 | } | 332 | } |
292 | 333 | ||
@@ -297,39 +338,52 @@ core_connect_adapter (void *cls, | |||
297 | { | 338 | { |
298 | struct TestPeer *me = cls; | 339 | struct TestPeer *me = cls; |
299 | me->cfg = cfg; | 340 | me->cfg = cfg; |
300 | me->ch = GNUNET_CORE_connect (cfg, me, NULL, &connect_cb, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | 341 | me->ch = GNUNET_CORE_connect (cfg, me, NULL, |
342 | &connect_cb, NULL, | ||
343 | NULL, GNUNET_NO, | ||
344 | NULL, GNUNET_NO, NULL); | ||
301 | if (NULL == me->ch) | 345 | if (NULL == me->ch) |
302 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); | 346 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
347 | "Failed to create CORE handle \n"); | ||
303 | return me->ch; | 348 | return me->ch; |
304 | } | 349 | } |
305 | 350 | ||
306 | 351 | ||
307 | static void | 352 | static void |
308 | core_disconnect_adapter (void *cls, void *op_result) | 353 | core_disconnect_adapter (void *cls, |
354 | void *op_result) | ||
309 | { | 355 | { |
310 | struct TestPeer *me = cls; | 356 | struct TestPeer *me = cls; |
311 | GNUNET_CORE_disconnect (me->ch); | 357 | GNUNET_CORE_disconnect (me->ch); |
312 | me->ch = NULL; | 358 | me->ch = NULL; |
313 | } | 359 | } |
314 | 360 | ||
361 | |||
315 | static void | 362 | static void |
316 | test_connection (void *cls, struct GNUNET_TESTBED_RunHandle *h, | 363 | test_connection (void *cls, |
317 | unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, | 364 | struct GNUNET_TESTBED_RunHandle *h, |
318 | unsigned int links_succeeded, unsigned int links_failed) | 365 | unsigned int num_peers, |
366 | struct GNUNET_TESTBED_Peer **peers, | ||
367 | unsigned int links_succeeded, | ||
368 | unsigned int links_failed) | ||
319 | { | 369 | { |
320 | int c; | 370 | int c; |
321 | 371 | ||
322 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 372 | die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
323 | &do_shutdown_badly, NULL ); | 373 | &do_shutdown_badly, NULL); |
324 | if (NUM_TEST_PEERS != num_peers) | 374 | if (NUM_TEST_PEERS != num_peers) |
325 | { | 375 | { |
326 | ok = 1; | 376 | ok = 1; |
327 | fprintf (stderr, "Only %u out of 2 peers were started ...\n", num_peers); | 377 | fprintf (stderr, |
378 | "Only %u out of %u peers were started ...\n", | ||
379 | num_peers, | ||
380 | NUM_TEST_PEERS); | ||
328 | } | 381 | } |
329 | 382 | ||
330 | if (0 == links_failed) | 383 | if (0 == links_failed) |
331 | { | 384 | { |
332 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testbed connected peers\n"); | 385 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
386 | "Testbed connected peers\n"); | ||
333 | for (c = 0; c < num_peers; c++) | 387 | for (c = 0; c < num_peers; c++) |
334 | { | 388 | { |
335 | testpeers[c].p = peers[c]; | 389 | testpeers[c].p = peers[c]; |
@@ -342,13 +396,16 @@ test_connection (void *cls, struct GNUNET_TESTBED_RunHandle *h, | |||
342 | } | 396 | } |
343 | } | 397 | } |
344 | 398 | ||
399 | |||
345 | int | 400 | int |
346 | main (int argc, char *argv[]) | 401 | main (int argc, char *argv[]) |
347 | { | 402 | { |
348 | ok = 1; | 403 | ok = 1; |
349 | /* Connecting initial topology */ | 404 | /* Connecting initial topology */ |
350 | (void) GNUNET_TESTBED_test_run ("test-revocation", "test_revocation.conf", | 405 | (void) GNUNET_TESTBED_test_run ("test-revocation", |
351 | NUM_TEST_PEERS, 0, NULL, NULL, &test_connection, NULL ); | 406 | "test_revocation.conf", |
407 | NUM_TEST_PEERS, 0, NULL, NULL, | ||
408 | &test_connection, NULL ); | ||
352 | return ok; | 409 | return ok; |
353 | } | 410 | } |
354 | 411 | ||