diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-11-05 18:21:50 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-11-05 18:21:50 +0000 |
commit | 75a33a1499cf60ea4364c9aa673816629a6c1413 (patch) | |
tree | 0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/dht/test_dht_twopeer_put_get.c | |
parent | 7217c601ad30760872823193d62307e7a335d226 (diff) | |
download | gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip |
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/dht/test_dht_twopeer_put_get.c')
-rw-r--r-- | src/dht/test_dht_twopeer_put_get.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index b57faeb83..0f61f4930 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c | |||
@@ -80,10 +80,6 @@ static struct GNUNET_TESTING_PeerGroup *pg; | |||
80 | */ | 80 | */ |
81 | struct GNUNET_DHT_GetHandle *global_get_handle; | 81 | struct GNUNET_DHT_GetHandle *global_get_handle; |
82 | 82 | ||
83 | /** | ||
84 | * Global scheduler, used for all GNUNET_SCHEDULER_* functions. | ||
85 | */ | ||
86 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
87 | 83 | ||
88 | /** | 84 | /** |
89 | * Total number of peers to run, set based on config file. | 85 | * Total number of peers to run, set based on config file. |
@@ -190,7 +186,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
190 | GNUNET_DHT_get_stop(global_get_handle); | 186 | GNUNET_DHT_get_stop(global_get_handle); |
191 | global_get_handle = NULL; | 187 | global_get_handle = NULL; |
192 | } | 188 | } |
193 | GNUNET_SCHEDULER_add_now(sched, &end_badly_cont, NULL); | 189 | GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL); |
194 | ok = 1; | 190 | ok = 1; |
195 | } | 191 | } |
196 | 192 | ||
@@ -221,15 +217,15 @@ void get_result_iterator (void *cls, | |||
221 | if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data)))) | 217 | if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data)))) |
222 | { | 218 | { |
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n"); | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n"); |
224 | GNUNET_SCHEDULER_cancel(sched, die_task); | 220 | GNUNET_SCHEDULER_cancel(die_task); |
225 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "key or data mismatch in get response!\n"); | 221 | GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); |
226 | return; | 222 | return; |
227 | } | 223 | } |
228 | 224 | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); |
230 | GNUNET_SCHEDULER_cancel(sched, die_task); | 226 | GNUNET_SCHEDULER_cancel(die_task); |
231 | GNUNET_DHT_get_stop(global_get_handle); | 227 | GNUNET_DHT_get_stop(global_get_handle); |
232 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | 228 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
233 | } | 229 | } |
234 | 230 | ||
235 | /** | 231 | /** |
@@ -256,10 +252,10 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
256 | static void | 252 | static void |
257 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 253 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
258 | { | 254 | { |
259 | GNUNET_SCHEDULER_cancel (sched, die_task); | 255 | GNUNET_SCHEDULER_cancel (die_task); |
260 | die_task = GNUNET_SCHEDULER_add_delayed (sched, GET_TIMEOUT, | 256 | die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, |
261 | &end_badly, "waiting for get response (data not found)"); | 257 | &end_badly, "waiting for get response (data not found)"); |
262 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); | 258 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); |
263 | } | 259 | } |
264 | 260 | ||
265 | /** | 261 | /** |
@@ -331,17 +327,16 @@ topology_callback (void *cls, | |||
331 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", | 327 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", |
332 | total_connections); | 328 | total_connections); |
333 | #endif | 329 | #endif |
334 | GNUNET_SCHEDULER_cancel (sched, die_task); | 330 | GNUNET_SCHEDULER_cancel (die_task); |
335 | die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, | 331 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
336 | &end_badly, "from test gets"); | 332 | &end_badly, "from test gets"); |
337 | 333 | ||
338 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); | 334 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); |
339 | } | 335 | } |
340 | else if (total_connections + failed_connections == expected_connections) | 336 | else if (total_connections + failed_connections == expected_connections) |
341 | { | 337 | { |
342 | GNUNET_SCHEDULER_cancel (sched, die_task); | 338 | GNUNET_SCHEDULER_cancel (die_task); |
343 | die_task = GNUNET_SCHEDULER_add_now (sched, | 339 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); |
344 | &end_badly, "from topology_callback (too many failed connections)"); | ||
345 | } | 340 | } |
346 | } | 341 | } |
347 | 342 | ||
@@ -375,21 +370,21 @@ peers_started_callback (void *cls, | |||
375 | if (peers_left == num_peers) | 370 | if (peers_left == num_peers) |
376 | { | 371 | { |
377 | memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer id */ | 372 | memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer id */ |
378 | peer1dht = GNUNET_DHT_connect(sched, cfg, 100); /* Connect to the first peers DHT service */ | 373 | peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT service */ |
379 | if (peer1dht == NULL) /* If DHT connect failed */ | 374 | if (peer1dht == NULL) /* If DHT connect failed */ |
380 | { | 375 | { |
381 | GNUNET_SCHEDULER_cancel (sched, die_task); | 376 | GNUNET_SCHEDULER_cancel (die_task); |
382 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); | 377 | GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); |
383 | } | 378 | } |
384 | } | 379 | } |
385 | else /* This is the second peer started */ | 380 | else /* This is the second peer started */ |
386 | { | 381 | { |
387 | memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for first peer... */ | 382 | memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for first peer... */ |
388 | peer2dht = GNUNET_DHT_connect(sched, cfg, 100); | 383 | peer2dht = GNUNET_DHT_connect(cfg, 100); |
389 | if (peer2dht == NULL) | 384 | if (peer2dht == NULL) |
390 | { | 385 | { |
391 | GNUNET_SCHEDULER_cancel (sched, die_task); | 386 | GNUNET_SCHEDULER_cancel (die_task); |
392 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); | 387 | GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); |
393 | } | 388 | } |
394 | } | 389 | } |
395 | 390 | ||
@@ -411,14 +406,12 @@ peers_started_callback (void *cls, | |||
411 | } | 406 | } |
412 | 407 | ||
413 | /* Cancel current timeout fail task */ | 408 | /* Cancel current timeout fail task */ |
414 | GNUNET_SCHEDULER_cancel (sched, die_task); | 409 | GNUNET_SCHEDULER_cancel (die_task); |
415 | if (expected_connections == GNUNET_SYSERR) /* Some error happened */ | 410 | if (expected_connections == GNUNET_SYSERR) /* Some error happened */ |
416 | die_task = GNUNET_SCHEDULER_add_now (sched, | 411 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); |
417 | &end_badly, "from connect topology (bad return)"); | ||
418 | 412 | ||
419 | /* Schedule timeout on failure task */ | 413 | /* Schedule timeout on failure task */ |
420 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 414 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
421 | TIMEOUT, | ||
422 | &end_badly, "from connect topology (timeout)"); | 415 | &end_badly, "from connect topology (timeout)"); |
423 | ok = 0; | 416 | ok = 0; |
424 | } | 417 | } |
@@ -426,11 +419,9 @@ peers_started_callback (void *cls, | |||
426 | 419 | ||
427 | static void | 420 | static void |
428 | run (void *cls, | 421 | run (void *cls, |
429 | struct GNUNET_SCHEDULER_Handle *s, | ||
430 | char *const *args, | 422 | char *const *args, |
431 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 423 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
432 | { | 424 | { |
433 | sched = s; | ||
434 | 425 | ||
435 | /* Get path from configuration file */ | 426 | /* Get path from configuration file */ |
436 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 427 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) |
@@ -449,13 +440,12 @@ run (void *cls, | |||
449 | peers_left = num_peers; | 440 | peers_left = num_peers; |
450 | 441 | ||
451 | /* Set up a task to end testing if peer start fails */ | 442 | /* Set up a task to end testing if peer start fails */ |
452 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 443 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
453 | TIMEOUT, | ||
454 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); | 444 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); |
455 | 445 | ||
456 | /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ | 446 | /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ |
457 | /* Read the API documentation for other parameters! */ | 447 | /* Read the API documentation for other parameters! */ |
458 | pg = GNUNET_TESTING_daemons_start (sched, cfg, | 448 | pg = GNUNET_TESTING_daemons_start (cfg, |
459 | num_peers, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, | 449 | num_peers, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, |
460 | &topology_callback, NULL, NULL); | 450 | &topology_callback, NULL, NULL); |
461 | 451 | ||