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.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.c')
-rw-r--r-- | src/dht/test_dht_twopeer.c | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c index 06807f82a..6f3d5060d 100644 --- a/src/dht/test_dht_twopeer.c +++ b/src/dht/test_dht_twopeer.c | |||
@@ -62,8 +62,6 @@ static unsigned long long peers_left; | |||
62 | 62 | ||
63 | static struct GNUNET_TESTING_PeerGroup *pg; | 63 | static struct GNUNET_TESTING_PeerGroup *pg; |
64 | 64 | ||
65 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
66 | |||
67 | static unsigned long long num_peers; | 65 | static unsigned long long num_peers; |
68 | 66 | ||
69 | static unsigned int total_gets; | 67 | static unsigned int total_gets; |
@@ -124,21 +122,21 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
124 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 122 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
125 | 123 | ||
126 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) | 124 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) |
127 | GNUNET_SCHEDULER_cancel(sched, curr_get_ctx.retry_task); | 125 | GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task); |
128 | } | 126 | } |
129 | 127 | ||
130 | static void | 128 | static void |
131 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 129 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
132 | { | 130 | { |
133 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) | 131 | if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK) |
134 | GNUNET_SCHEDULER_cancel(sched, curr_get_ctx.retry_task); | 132 | GNUNET_SCHEDULER_cancel(curr_get_ctx.retry_task); |
135 | 133 | ||
136 | if (curr_get_ctx.get_handle != NULL) | 134 | if (curr_get_ctx.get_handle != NULL) |
137 | { | 135 | { |
138 | GNUNET_DHT_get_stop(curr_get_ctx.get_handle); | 136 | GNUNET_DHT_get_stop(curr_get_ctx.get_handle); |
139 | } | 137 | } |
140 | 138 | ||
141 | GNUNET_SCHEDULER_add_now (sched, &end_badly_cont, NULL); | 139 | GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL); |
142 | ok = 1; | 140 | ok = 1; |
143 | } | 141 | } |
144 | 142 | ||
@@ -171,14 +169,14 @@ void get_result_iterator (void *cls, | |||
171 | if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode))) | 169 | if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode))) |
172 | { | 170 | { |
173 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key returned is not the same key as was searched for!\n"); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key returned is not the same key as was searched for!\n"); |
174 | GNUNET_SCHEDULER_cancel(sched, die_task); | 172 | GNUNET_SCHEDULER_cancel(die_task); |
175 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "key mismatch in get response!\n"); | 173 | GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n"); |
176 | return; | 174 | return; |
177 | } | 175 | } |
178 | 176 | ||
179 | if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK) | 177 | if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK) |
180 | { | 178 | { |
181 | GNUNET_SCHEDULER_cancel(sched, get_context->retry_task); | 179 | GNUNET_SCHEDULER_cancel(get_context->retry_task); |
182 | get_context->retry_task = GNUNET_SCHEDULER_NO_TASK; | 180 | get_context->retry_task = GNUNET_SCHEDULER_NO_TASK; |
183 | } | 181 | } |
184 | 182 | ||
@@ -188,14 +186,14 @@ void get_result_iterator (void *cls, | |||
188 | get_context->dht_handle = peer2dht; | 186 | get_context->dht_handle = peer2dht; |
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request response!\n"); | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request response!\n"); |
190 | GNUNET_DHT_get_stop(get_context->get_handle); | 188 | GNUNET_DHT_get_stop(get_context->get_handle); |
191 | GNUNET_SCHEDULER_add_now (sched, &do_get, get_context); | 189 | GNUNET_SCHEDULER_add_now (&do_get, get_context); |
192 | } | 190 | } |
193 | else | 191 | else |
194 | { | 192 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request response!\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request response!\n"); |
196 | GNUNET_SCHEDULER_cancel(sched, die_task); | 194 | GNUNET_SCHEDULER_cancel(die_task); |
197 | GNUNET_DHT_get_stop(get_context->get_handle); | 195 | GNUNET_DHT_get_stop(get_context->get_handle); |
198 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | 196 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
199 | } | 197 | } |
200 | 198 | ||
201 | } | 199 | } |
@@ -213,14 +211,13 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
213 | else | 211 | else |
214 | { | 212 | { |
215 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Too many attempts failed, ending test!\n", get_context->get_attempts); | 213 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Too many attempts failed, ending test!\n", get_context->get_attempts); |
216 | GNUNET_SCHEDULER_cancel(sched, die_task); | 214 | GNUNET_SCHEDULER_cancel(die_task); |
217 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "key mismatch in get response!\n"); | 215 | GNUNET_SCHEDULER_add_now(&end_badly, "key mismatch in get response!\n"); |
218 | return; | 216 | return; |
219 | } | 217 | } |
220 | get_context->get_attempts++; | 218 | get_context->get_attempts++; |
221 | get_context->retry_task = GNUNET_SCHEDULER_add_delayed(sched, | 219 | get_context->retry_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), |
222 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | 220 | &stop_retry_get, get_context); |
223 | &stop_retry_get, get_context); | ||
224 | get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, | 221 | get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, |
225 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), | 222 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
226 | 0 /* fixme: use real type */, &get_context->peer->hashPubKey, | 223 | 0 /* fixme: use real type */, &get_context->peer->hashPubKey, |
@@ -238,7 +235,7 @@ stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
238 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, canceling request!\n", get_context->get_attempts); | 235 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Get attempt %u failed, canceling request!\n", get_context->get_attempts); |
239 | GNUNET_DHT_get_stop(get_context->get_handle); | 236 | GNUNET_DHT_get_stop(get_context->get_handle); |
240 | get_context->get_handle = NULL; | 237 | get_context->get_handle = NULL; |
241 | GNUNET_SCHEDULER_add_now(sched, &get_stop_finished, get_context); | 238 | GNUNET_SCHEDULER_add_now(&get_stop_finished, get_context); |
242 | } | 239 | } |
243 | 240 | ||
244 | static void | 241 | static void |
@@ -246,8 +243,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
246 | { | 243 | { |
247 | struct PeerGetContext *get_context = cls; | 244 | struct PeerGetContext *get_context = cls; |
248 | 245 | ||
249 | get_context->retry_task = GNUNET_SCHEDULER_add_delayed(sched, | 246 | get_context->retry_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), |
250 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
251 | &stop_retry_get, get_context); | 247 | &stop_retry_get, get_context); |
252 | 248 | ||
253 | get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, | 249 | get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, |
@@ -299,20 +295,19 @@ topology_callback (void *cls, | |||
299 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", | 295 | "Created %d total connections, which is our target number! Starting next phase of testing.\n", |
300 | total_connections); | 296 | total_connections); |
301 | #endif | 297 | #endif |
302 | GNUNET_SCHEDULER_cancel (sched, die_task); | 298 | GNUNET_SCHEDULER_cancel (die_task); |
303 | die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, | 299 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
304 | &end_badly, "from test gets"); | 300 | &end_badly, "from test gets"); |
305 | 301 | ||
306 | curr_get_ctx.dht_handle = peer1dht; | 302 | curr_get_ctx.dht_handle = peer1dht; |
307 | curr_get_ctx.peer = &peer2id; | 303 | curr_get_ctx.peer = &peer2id; |
308 | //GNUNET_SCHEDULER_add_now (sched, &do_get, &curr_get_ctx); | 304 | //GNUNET_SCHEDULER_add_now (&do_get, &curr_get_ctx); |
309 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get, &curr_get_ctx); | 305 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get, &curr_get_ctx); |
310 | } | 306 | } |
311 | else if (total_connections + failed_connections == expected_connections) | 307 | else if (total_connections + failed_connections == expected_connections) |
312 | { | 308 | { |
313 | GNUNET_SCHEDULER_cancel (sched, die_task); | 309 | GNUNET_SCHEDULER_cancel (die_task); |
314 | die_task = GNUNET_SCHEDULER_add_now (sched, | 310 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); |
315 | &end_badly, "from topology_callback (too many failed connections)"); | ||
316 | } | 311 | } |
317 | } | 312 | } |
318 | 313 | ||
@@ -323,14 +318,12 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
323 | if ((pg != NULL) && (peers_left == 0)) | 318 | if ((pg != NULL) && (peers_left == 0)) |
324 | expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0, NULL, NULL); | 319 | expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0, NULL, NULL); |
325 | 320 | ||
326 | GNUNET_SCHEDULER_cancel (sched, die_task); | 321 | GNUNET_SCHEDULER_cancel (die_task); |
327 | if (expected_connections == GNUNET_SYSERR) | 322 | if (expected_connections == GNUNET_SYSERR) |
328 | die_task = GNUNET_SCHEDULER_add_now (sched, | 323 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); |
329 | &end_badly, "from connect topology (bad return)"); | ||
330 | 324 | ||
331 | 325 | ||
332 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 326 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
333 | TIMEOUT, | ||
334 | &end_badly, "from connect topology (timeout)"); | 327 | &end_badly, "from connect topology (timeout)"); |
335 | } | 328 | } |
336 | 329 | ||
@@ -350,21 +343,21 @@ peers_started_callback (void *cls, | |||
350 | if (peers_left == num_peers) | 343 | if (peers_left == num_peers) |
351 | { | 344 | { |
352 | memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); | 345 | memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); |
353 | peer1dht = GNUNET_DHT_connect(sched, cfg, 100); | 346 | peer1dht = GNUNET_DHT_connect(cfg, 100); |
354 | if (peer1dht == NULL) | 347 | if (peer1dht == NULL) |
355 | { | 348 | { |
356 | GNUNET_SCHEDULER_cancel (sched, die_task); | 349 | GNUNET_SCHEDULER_cancel (die_task); |
357 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); | 350 | GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); |
358 | } | 351 | } |
359 | } | 352 | } |
360 | else | 353 | else |
361 | { | 354 | { |
362 | memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); | 355 | memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); |
363 | peer2dht = GNUNET_DHT_connect(sched, cfg, 100); | 356 | peer2dht = GNUNET_DHT_connect(cfg, 100); |
364 | if (peer2dht == NULL) | 357 | if (peer2dht == NULL) |
365 | { | 358 | { |
366 | GNUNET_SCHEDULER_cancel (sched, die_task); | 359 | GNUNET_SCHEDULER_cancel (die_task); |
367 | GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n"); | 360 | GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); |
368 | } | 361 | } |
369 | } | 362 | } |
370 | 363 | ||
@@ -378,25 +371,22 @@ peers_started_callback (void *cls, | |||
378 | "All %d daemons started, now connecting peers!\n", | 371 | "All %d daemons started, now connecting peers!\n", |
379 | num_peers); | 372 | num_peers); |
380 | #endif | 373 | #endif |
381 | GNUNET_SCHEDULER_cancel (sched, die_task); | 374 | GNUNET_SCHEDULER_cancel (die_task); |
382 | /* Set up task in case topology creation doesn't finish | 375 | /* Set up task in case topology creation doesn't finish |
383 | * within a reasonable amount of time */ | 376 | * within a reasonable amount of time */ |
384 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 377 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
385 | TIMEOUT, | ||
386 | &end_badly, "from peers_started_callback"); | 378 | &end_badly, "from peers_started_callback"); |
387 | 379 | ||
388 | GNUNET_SCHEDULER_add_now(sched, &connect_topology, NULL); | 380 | GNUNET_SCHEDULER_add_now(&connect_topology, NULL); |
389 | ok = 0; | 381 | ok = 0; |
390 | } | 382 | } |
391 | } | 383 | } |
392 | 384 | ||
393 | static void | 385 | static void |
394 | run (void *cls, | 386 | run (void *cls, |
395 | struct GNUNET_SCHEDULER_Handle *s, | ||
396 | char *const *args, | 387 | char *const *args, |
397 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 388 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
398 | { | 389 | { |
399 | sched = s; | ||
400 | 390 | ||
401 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 391 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) |
402 | { | 392 | { |
@@ -413,11 +403,10 @@ run (void *cls, | |||
413 | total_gets = num_peers; | 403 | total_gets = num_peers; |
414 | gets_succeeded = 0; | 404 | gets_succeeded = 0; |
415 | /* Set up a task to end testing if peer start fails */ | 405 | /* Set up a task to end testing if peer start fails */ |
416 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 406 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
417 | TIMEOUT, | ||
418 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); | 407 | &end_badly, "didn't start all daemons in reasonable amount of time!!!"); |
419 | 408 | ||
420 | pg = GNUNET_TESTING_daemons_start (sched, cfg, | 409 | pg = GNUNET_TESTING_daemons_start (cfg, |
421 | num_peers, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, | 410 | num_peers, TIMEOUT, NULL, NULL, &peers_started_callback, NULL, |
422 | &topology_callback, NULL, NULL); | 411 | &topology_callback, NULL, NULL); |
423 | 412 | ||