diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-02 14:07:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-02 14:07:27 +0000 |
commit | b9c16e59778a0ba63ab677faf081c8023df08eb5 (patch) | |
tree | 440dd5e780cb0554b59a41a385b41fe86ecf6afe /src/dht/test_dht_api.c | |
parent | 3b54e87cfe8f36ce11af703bae138a3a0a828e8a (diff) | |
download | gnunet-b9c16e59778a0ba63ab677faf081c8023df08eb5.tar.gz gnunet-b9c16e59778a0ba63ab677faf081c8023df08eb5.zip |
make first test compile
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r-- | src/dht/test_dht_api.c | 77 |
1 files changed, 52 insertions, 25 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 4b5728811..f0b330d3a 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -151,7 +151,7 @@ end_badly () | |||
151 | #endif | 151 | #endif |
152 | 152 | ||
153 | if ((retry_context.peer_ctx != NULL) && (retry_context.peer_ctx->find_peer_handle != NULL)) | 153 | if ((retry_context.peer_ctx != NULL) && (retry_context.peer_ctx->find_peer_handle != NULL)) |
154 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle, NULL, NULL); | 154 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); |
155 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) | 155 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) |
156 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); | 156 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); |
157 | GNUNET_DHT_disconnect (p1.dht_handle); | 157 | GNUNET_DHT_disconnect (p1.dht_handle); |
@@ -160,6 +160,8 @@ end_badly () | |||
160 | return; | 160 | return; |
161 | } | 161 | } |
162 | 162 | ||
163 | #if HAVE_MALICIOUS | ||
164 | |||
163 | /** | 165 | /** |
164 | * Signature of the main function of a task. | 166 | * Signature of the main function of a task. |
165 | * | 167 | * |
@@ -204,7 +206,8 @@ void test_set_peer_malicious_put (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
204 | * @param cls closure | 206 | * @param cls closure |
205 | * @param tc context information (why was this task triggered now) | 207 | * @param tc context information (why was this task triggered now) |
206 | */ | 208 | */ |
207 | void test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 209 | static void |
210 | test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
208 | { | 211 | { |
209 | struct PeerContext *peer = cls; | 212 | struct PeerContext *peer = cls; |
210 | 213 | ||
@@ -216,6 +219,8 @@ void test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskC | |||
216 | 219 | ||
217 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500, &test_set_peer_malicious_put, &p1); | 220 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500, &test_set_peer_malicious_put, &p1); |
218 | } | 221 | } |
222 | #endif | ||
223 | |||
219 | 224 | ||
220 | /** | 225 | /** |
221 | * Signature of the main function of a task. | 226 | * Signature of the main function of a task. |
@@ -234,9 +239,15 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
234 | 239 | ||
235 | GNUNET_assert (peer->dht_handle != NULL); | 240 | GNUNET_assert (peer->dht_handle != NULL); |
236 | 241 | ||
237 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &test_set_peer_malicious_get, &p1); | 242 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); |
238 | 243 | ||
239 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1); | 244 | #if HAVE_MALICIOUS |
245 | GNUNET_SCHEDULER_add_now (sched, | ||
246 | &test_set_peer_malicious_get, &p1); | ||
247 | #else | ||
248 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), | ||
249 | &end, &p1); | ||
250 | #endif | ||
240 | 251 | ||
241 | } | 252 | } |
242 | 253 | ||
@@ -304,9 +315,11 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
305 | "test_find_peer timed out, retrying!\n"); | 316 | "test_find_peer timed out, retrying!\n"); |
306 | retry_ctx->next_timeout = GNUNET_TIME_relative_multiply(retry_ctx->next_timeout, 2); | 317 | retry_ctx->next_timeout = GNUNET_TIME_relative_multiply(retry_ctx->next_timeout, 2); |
307 | retry_ctx->peer_ctx->find_peer_handle = | 318 | retry_ctx->peer_ctx->find_peer_handle |
308 | GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, retry_ctx->next_timeout, 0, &hash, | 319 | = GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, |
309 | &test_find_peer_processor, retry_ctx, NULL, NULL); | 320 | retry_ctx->next_timeout, &hash, |
321 | GNUNET_DHT_RO_NONE, | ||
322 | &test_find_peer_processor, retry_ctx); | ||
310 | } | 323 | } |
311 | else | 324 | else |
312 | { | 325 | { |
@@ -336,10 +349,11 @@ retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
336 | memset (&hash, 42, sizeof (GNUNET_HashCode)); | 349 | memset (&hash, 42, sizeof (GNUNET_HashCode)); |
337 | 350 | ||
338 | if (retry_ctx->peer_ctx->find_peer_handle != NULL) | 351 | if (retry_ctx->peer_ctx->find_peer_handle != NULL) |
339 | GNUNET_DHT_find_peer_stop(retry_ctx->peer_ctx->find_peer_handle, &retry_find_peer, retry_ctx); | 352 | { |
340 | else | 353 | GNUNET_DHT_find_peer_stop(retry_ctx->peer_ctx->find_peer_handle); |
341 | GNUNET_SCHEDULER_add_now (sched, &retry_find_peer, retry_ctx); | 354 | retry_ctx->peer_ctx->find_peer_handle = NULL; |
342 | 355 | } | |
356 | GNUNET_SCHEDULER_add_now (sched, &retry_find_peer, retry_ctx); | ||
343 | } | 357 | } |
344 | 358 | ||
345 | /** | 359 | /** |
@@ -362,9 +376,11 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
362 | retry_context.next_timeout = BASE_TIMEOUT; | 376 | retry_context.next_timeout = BASE_TIMEOUT; |
363 | retry_context.peer_ctx = peer; | 377 | retry_context.peer_ctx = peer; |
364 | 378 | ||
365 | peer->find_peer_handle = | 379 | peer->find_peer_handle |
366 | GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, 1, &hash, | 380 | = GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, |
367 | &test_find_peer_processor, &retry_context, NULL, NULL); | 381 | &hash, |
382 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
383 | &test_find_peer_processor, &retry_context); | ||
368 | 384 | ||
369 | if (peer->find_peer_handle == NULL) | 385 | if (peer->find_peer_handle == NULL) |
370 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 386 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); |
@@ -386,20 +402,21 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); | 402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); |
387 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 403 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
388 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | 404 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); |
389 | |||
390 | GNUNET_assert (peer->dht_handle != NULL); | 405 | GNUNET_assert (peer->dht_handle != NULL); |
391 | 406 | GNUNET_DHT_get_stop (peer->get_handle); | |
392 | GNUNET_DHT_get_stop (peer->get_handle, &test_find_peer, &p1); | 407 | GNUNET_SCHEDULER_add_now(sched, |
393 | 408 | &test_find_peer, | |
394 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | 409 | &p1); |
395 | |||
396 | } | 410 | } |
397 | 411 | ||
398 | void | 412 | void |
399 | test_get_iterator (void *cls, | 413 | test_get_iterator (void *cls, |
400 | struct GNUNET_TIME_Absolute exp, | 414 | struct GNUNET_TIME_Absolute exp, |
401 | const GNUNET_HashCode * key, | 415 | const GNUNET_HashCode * key, |
402 | uint32_t type, uint32_t size, const void *data) | 416 | const struct GNUNET_PeerIdentity * const *get_path, |
417 | const struct GNUNET_PeerIdentity * const *put_path, | ||
418 | enum GNUNET_BLOCK_Type type, | ||
419 | uint32_t size, const void *data) | ||
403 | { | 420 | { |
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
405 | "test_get_iterator called (we got a result), stopping get request!\n"); | 422 | "test_get_iterator called (we got a result), stopping get request!\n"); |
@@ -426,8 +443,14 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
426 | GNUNET_assert (peer->dht_handle != NULL); | 443 | GNUNET_assert (peer->dht_handle != NULL); |
427 | 444 | ||
428 | peer->get_handle = | 445 | peer->get_handle = |
429 | GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, 49, &hash, | 446 | GNUNET_DHT_get_start (peer->dht_handle, |
430 | &test_get_iterator, NULL, NULL, NULL); | 447 | TOTAL_TIMEOUT, |
448 | 49 /* fixme: use test type */, | ||
449 | &hash, | ||
450 | GNUNET_DHT_RO_NONE, | ||
451 | NULL, 0, | ||
452 | NULL, 0, | ||
453 | &test_get_iterator, NULL); | ||
431 | 454 | ||
432 | if (peer->get_handle == NULL) | 455 | if (peer->get_handle == NULL) |
433 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 456 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); |
@@ -454,8 +477,12 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
454 | 477 | ||
455 | GNUNET_assert (peer->dht_handle != NULL); | 478 | GNUNET_assert (peer->dht_handle != NULL); |
456 | 479 | ||
457 | GNUNET_DHT_put (peer->dht_handle, &hash, 49, data_size, data, | 480 | GNUNET_DHT_put (peer->dht_handle, &hash, |
458 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), TOTAL_TIMEOUT, | 481 | GNUNET_DHT_RO_NONE, |
482 | 49 /* fixme: use test type */, | ||
483 | data_size, data, | ||
484 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), | ||
485 | TOTAL_TIMEOUT, | ||
459 | &test_get, &p1); | 486 | &test_get, &p1); |
460 | GNUNET_free(data); | 487 | GNUNET_free(data); |
461 | } | 488 | } |