diff options
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r-- | src/dht/test_dht_topo.c | 634 |
1 files changed, 0 insertions, 634 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c deleted file mode 100644 index 4830ba629..000000000 --- a/src/dht/test_dht_topo.c +++ /dev/null | |||
@@ -1,634 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file dht/test_dht_topo.c | ||
22 | * @author Christian Grothoff | ||
23 | * @brief Test for the dht service: store and retrieve in various topologies. | ||
24 | * Each peer stores a value from the DHT and then each peer tries to get each | ||
25 | * value from each other peer. | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_dht_service.h" | ||
30 | #include "dht_test_lib.h" | ||
31 | |||
32 | /** | ||
33 | * How long until we give up on fetching the data? | ||
34 | */ | ||
35 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
36 | 120) | ||
37 | |||
38 | /** | ||
39 | * How frequently do we execute the PUTs? | ||
40 | */ | ||
41 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
42 | 5) | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Information we keep for each GET operation. | ||
47 | */ | ||
48 | struct GetOperation | ||
49 | { | ||
50 | /** | ||
51 | * DLL. | ||
52 | */ | ||
53 | struct GetOperation *next; | ||
54 | |||
55 | /** | ||
56 | * DLL. | ||
57 | */ | ||
58 | struct GetOperation *prev; | ||
59 | |||
60 | /** | ||
61 | * Operation to fetch @a me. | ||
62 | */ | ||
63 | struct GNUNET_TESTBED_Operation *to; | ||
64 | |||
65 | /** | ||
66 | * Handle for the operation. | ||
67 | */ | ||
68 | struct GNUNET_DHT_GetHandle *get; | ||
69 | |||
70 | /** | ||
71 | * DHT used by this operation. | ||
72 | */ | ||
73 | struct GNUNET_DHT_Handle *dht; | ||
74 | |||
75 | /** | ||
76 | * Key we are looking up. | ||
77 | */ | ||
78 | struct GNUNET_HashCode key; | ||
79 | |||
80 | /** | ||
81 | * At which peer is this operation being performed? | ||
82 | */ | ||
83 | struct GNUNET_PeerIdentity me; | ||
84 | }; | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Result of the test. | ||
89 | */ | ||
90 | static int ok; | ||
91 | |||
92 | /** | ||
93 | * Task to do DHT_puts | ||
94 | */ | ||
95 | static struct GNUNET_SCHEDULER_Task *put_task; | ||
96 | |||
97 | /** | ||
98 | * Task to do DHT_gets | ||
99 | */ | ||
100 | static struct GNUNET_SCHEDULER_Task *get_task; | ||
101 | |||
102 | /** | ||
103 | * Task to time out / regular shutdown. | ||
104 | */ | ||
105 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
106 | |||
107 | /** | ||
108 | * Head of list of active GET operations. | ||
109 | */ | ||
110 | static struct GetOperation *get_head; | ||
111 | |||
112 | /** | ||
113 | * Tail of list of active GET operations. | ||
114 | */ | ||
115 | static struct GetOperation *get_tail; | ||
116 | |||
117 | /** | ||
118 | * Array of the testbed's peers. | ||
119 | */ | ||
120 | static struct GNUNET_TESTBED_Peer **my_peers; | ||
121 | |||
122 | /** | ||
123 | * Number of peers to run. | ||
124 | */ | ||
125 | static unsigned int NUM_PEERS; | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Statistics we print out. | ||
130 | */ | ||
131 | static struct | ||
132 | { | ||
133 | const char *subsystem; | ||
134 | const char *name; | ||
135 | unsigned long long total; | ||
136 | } stats[] = { | ||
137 | { "core", "# bytes decrypted", 0 }, | ||
138 | { "core", "# bytes encrypted", 0 }, | ||
139 | { "core", "# type maps received", 0 }, | ||
140 | { "core", "# session keys confirmed via PONG", 0 }, | ||
141 | { "core", "# peers connected", 0 }, | ||
142 | { "core", "# key exchanges initiated", 0 }, | ||
143 | { "core", "# send requests dropped (disconnected)", 0 }, | ||
144 | { "core", "# transmissions delayed due to corking", 0 }, | ||
145 | { "core", "# messages discarded (expired prior to transmission)", 0 }, | ||
146 | { "core", "# messages discarded (disconnected)", 0 }, | ||
147 | { "core", "# discarded CORE_SEND requests", 0 }, | ||
148 | { "core", "# discarded lower priority CORE_SEND requests", 0 }, | ||
149 | { "transport", "# bytes received via TCP", 0 }, | ||
150 | { "transport", "# bytes transmitted via TCP", 0 }, | ||
151 | { "dht", "# PUT messages queued for transmission", 0 }, | ||
152 | { "dht", "# P2P PUT requests received", 0 }, | ||
153 | { "dht", "# GET messages queued for transmission", 0 }, | ||
154 | { "dht", "# P2P GET requests received", 0 }, | ||
155 | { "dht", "# RESULT messages queued for transmission", 0 }, | ||
156 | { "dht", "# P2P RESULTS received", 0 }, | ||
157 | { "dht", "# Queued messages discarded (peer disconnected)", 0 }, | ||
158 | { "dht", "# Peers excluded from routing due to Bloomfilter", 0 }, | ||
159 | { "dht", "# Peer selection failed", 0 }, | ||
160 | { "dht", "# FIND PEER requests ignored due to Bloomfilter", 0 }, | ||
161 | { "dht", "# FIND PEER requests ignored due to lack of HELLO", 0 }, | ||
162 | { "dht", "# P2P FIND PEER requests processed", 0 }, | ||
163 | { "dht", "# P2P GET requests ONLY routed", 0 }, | ||
164 | { "dht", "# Preference updates given to core", 0 }, | ||
165 | { "dht", "# REPLIES ignored for CLIENTS (no match)", 0 }, | ||
166 | { "dht", "# GET requests from clients injected", 0 }, | ||
167 | { "dht", "# GET requests received from clients", 0 }, | ||
168 | { "dht", "# GET STOP requests received from clients", 0 }, | ||
169 | { "dht", "# ITEMS stored in datacache", 0 }, | ||
170 | { "dht", "# Good RESULTS found in datacache", 0 }, | ||
171 | { "dht", "# GET requests given to datacache", 0 }, | ||
172 | { NULL, NULL, 0 } | ||
173 | }; | ||
174 | |||
175 | |||
176 | static struct GNUNET_DHT_TEST_Context * | ||
177 | stop_ops (void) | ||
178 | { | ||
179 | struct GetOperation *get_op; | ||
180 | struct GNUNET_DHT_TEST_Context *ctx = NULL; | ||
181 | |||
182 | if (NULL != timeout_task) | ||
183 | { | ||
184 | ctx = GNUNET_SCHEDULER_cancel (timeout_task); | ||
185 | timeout_task = NULL; | ||
186 | } | ||
187 | if (NULL != put_task) | ||
188 | { | ||
189 | GNUNET_SCHEDULER_cancel (put_task); | ||
190 | put_task = NULL; | ||
191 | } | ||
192 | if (NULL != get_task) | ||
193 | { | ||
194 | GNUNET_SCHEDULER_cancel (get_task); | ||
195 | get_task = NULL; | ||
196 | } | ||
197 | while (NULL != (get_op = get_tail)) | ||
198 | { | ||
199 | if (NULL != get_op->to) | ||
200 | { | ||
201 | GNUNET_TESTBED_operation_done (get_op->to); | ||
202 | get_op->to = NULL; | ||
203 | } | ||
204 | if (NULL != get_op->get) | ||
205 | { | ||
206 | GNUNET_DHT_get_stop (get_op->get); | ||
207 | get_op->get = NULL; | ||
208 | } | ||
209 | GNUNET_CONTAINER_DLL_remove (get_head, | ||
210 | get_tail, | ||
211 | get_op); | ||
212 | GNUNET_free (get_op); | ||
213 | } | ||
214 | return ctx; | ||
215 | } | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Function called once we're done processing stats. | ||
220 | * | ||
221 | * @param cls the test context | ||
222 | * @param op the stats operation | ||
223 | * @param emsg error message on failure | ||
224 | */ | ||
225 | static void | ||
226 | stats_finished (void *cls, | ||
227 | struct GNUNET_TESTBED_Operation *op, | ||
228 | const char *emsg) | ||
229 | { | ||
230 | struct GNUNET_DHT_TEST_Context *ctx = cls; | ||
231 | |||
232 | if (NULL != op) | ||
233 | GNUNET_TESTBED_operation_done (op); | ||
234 | if (NULL != emsg) | ||
235 | { | ||
236 | fprintf (stderr, | ||
237 | _ ("Gathering statistics failed: %s\n"), | ||
238 | emsg); | ||
239 | GNUNET_SCHEDULER_cancel (put_task); | ||
240 | GNUNET_DHT_TEST_cleanup (ctx); | ||
241 | return; | ||
242 | } | ||
243 | for (unsigned int i = 0; NULL != stats[i].name; i++) | ||
244 | fprintf (stderr, | ||
245 | "%6s/%60s = %12llu\n", | ||
246 | stats[i].subsystem, | ||
247 | stats[i].name, | ||
248 | stats[i].total); | ||
249 | GNUNET_DHT_TEST_cleanup (ctx); | ||
250 | GNUNET_SCHEDULER_shutdown (); | ||
251 | } | ||
252 | |||
253 | |||
254 | /** | ||
255 | * Function called to process statistic values from all peers. | ||
256 | * | ||
257 | * @param cls closure | ||
258 | * @param peer the peer the statistic belong to | ||
259 | * @param subsystem name of subsystem that created the statistic | ||
260 | * @param name the name of the datum | ||
261 | * @param value the current value | ||
262 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
263 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
264 | */ | ||
265 | static enum GNUNET_GenericReturnValue | ||
266 | handle_stats (void *cls, | ||
267 | const struct GNUNET_TESTBED_Peer *peer, | ||
268 | const char *subsystem, | ||
269 | const char *name, | ||
270 | uint64_t value, | ||
271 | int is_persistent) | ||
272 | { | ||
273 | for (unsigned int i = 0; NULL != stats[i].name; i++) | ||
274 | if ((0 == strcasecmp (subsystem, | ||
275 | stats[i].subsystem)) && | ||
276 | (0 == strcasecmp (name, | ||
277 | stats[i].name))) | ||
278 | stats[i].total += value; | ||
279 | return GNUNET_OK; | ||
280 | } | ||
281 | |||
282 | |||
283 | /** | ||
284 | * Task run on shutdown to clean up. Terminates active get operations | ||
285 | * and shuts down the testbed. | ||
286 | * | ||
287 | * @param cls the 'struct GNUNET_DHT_TestContext' | ||
288 | */ | ||
289 | static void | ||
290 | shutdown_task (void *cls) | ||
291 | { | ||
292 | struct GNUNET_DHT_TEST_Context *ctx; | ||
293 | |||
294 | (void) cls; | ||
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
296 | "Performing shutdown\n"); | ||
297 | ctx = stop_ops (); | ||
298 | if (NULL != ctx) | ||
299 | GNUNET_DHT_TEST_cleanup (ctx); | ||
300 | } | ||
301 | |||
302 | |||
303 | /** | ||
304 | * Task run on timeout to clean up. Terminates active get operations | ||
305 | * and shuts down the testbed. | ||
306 | * | ||
307 | * @param cls the `struct GNUNET_DHT_TestContext` | ||
308 | */ | ||
309 | static void | ||
310 | timeout_cb (void *cls) | ||
311 | { | ||
312 | struct GNUNET_DHT_TEST_Context *ctx = cls; | ||
313 | |||
314 | timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, | ||
315 | &timeout_cb, | ||
316 | ctx); | ||
317 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
318 | "Timeout\n"); | ||
319 | GNUNET_SCHEDULER_shutdown (); | ||
320 | } | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Iterator called on each result obtained for a DHT | ||
325 | * operation that expects a reply | ||
326 | * | ||
327 | * @param cls closure with our 'struct GetOperation' | ||
328 | * @param exp when will this value expire | ||
329 | * @param query query hash | ||
330 | * @param get_path peers on reply path (or NULL if not recorded) | ||
331 | * @param get_path_length number of entries in @a get_path | ||
332 | * @param put_path peers on the PUT path (or NULL if not recorded) | ||
333 | * @param put_path_length number of entries in @a put_path | ||
334 | * @param type type of the result | ||
335 | * @param size number of bytes in @a data | ||
336 | * @param data pointer to the result data | ||
337 | */ | ||
338 | static void | ||
339 | dht_get_handler (void *cls, | ||
340 | struct GNUNET_TIME_Absolute exp, | ||
341 | const struct GNUNET_HashCode *query, | ||
342 | const struct GNUNET_DHT_PathElement *get_path, | ||
343 | unsigned int get_path_length, | ||
344 | const struct GNUNET_DHT_PathElement *put_path, | ||
345 | unsigned int put_path_length, | ||
346 | enum GNUNET_BLOCK_Type type, | ||
347 | size_t size, | ||
348 | const void *data) | ||
349 | { | ||
350 | struct GetOperation *get_op = cls; | ||
351 | struct GNUNET_HashCode want; | ||
352 | struct GNUNET_DHT_TEST_Context *ctx; | ||
353 | |||
354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
355 | "GET HANDLER called on PID %s\n", | ||
356 | GNUNET_i2s (&get_op->me)); | ||
357 | if (sizeof(struct GNUNET_HashCode) != size) | ||
358 | { | ||
359 | GNUNET_break (0); | ||
360 | return; | ||
361 | } | ||
362 | if (0 != GNUNET_memcmp (query, | ||
363 | &get_op->key)) | ||
364 | { | ||
365 | /* exact search should only yield exact results */ | ||
366 | GNUNET_break (0); | ||
367 | return; | ||
368 | } | ||
369 | GNUNET_CRYPTO_hash (query, | ||
370 | sizeof(*query), | ||
371 | &want); | ||
372 | if (0 != memcmp (&want, | ||
373 | data, | ||
374 | sizeof(want))) | ||
375 | { | ||
376 | GNUNET_break (0); | ||
377 | return; | ||
378 | } | ||
379 | if (0 != | ||
380 | GNUNET_DHT_verify_path (data, | ||
381 | size, | ||
382 | exp, | ||
383 | put_path, | ||
384 | put_path_length, | ||
385 | get_path, | ||
386 | get_path_length, | ||
387 | &get_op->me)) | ||
388 | { | ||
389 | GNUNET_break (0); | ||
390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
391 | "Path signature (%u/%u) verification failed for peer %s!\n", | ||
392 | get_path_length, | ||
393 | put_path_length, | ||
394 | GNUNET_i2s (&get_op->me)); | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
399 | "Get successful\n"); | ||
400 | ok--; | ||
401 | } | ||
402 | GNUNET_DHT_get_stop (get_op->get); | ||
403 | GNUNET_CONTAINER_DLL_remove (get_head, | ||
404 | get_tail, | ||
405 | get_op); | ||
406 | GNUNET_free (get_op); | ||
407 | if (NULL != get_head) | ||
408 | return; | ||
409 | /* all DHT GET operations successful; get stats! */ | ||
410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
411 | "All DHT operations successful. Obtaining stats!\n"); | ||
412 | ctx = stop_ops (); | ||
413 | GNUNET_assert (NULL != ctx); | ||
414 | (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, | ||
415 | my_peers, | ||
416 | NULL, NULL, | ||
417 | &handle_stats, | ||
418 | &stats_finished, | ||
419 | ctx); | ||
420 | } | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Task to put the id of each peer into the DHT. | ||
425 | * | ||
426 | * @param cls array with NUM_PEERS DHT handles | ||
427 | * @param tc Task context | ||
428 | */ | ||
429 | static void | ||
430 | do_puts (void *cls) | ||
431 | { | ||
432 | struct GNUNET_DHT_Handle **hs = cls; | ||
433 | struct GNUNET_HashCode key; | ||
434 | struct GNUNET_HashCode value; | ||
435 | |||
436 | put_task = NULL; | ||
437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
438 | "Putting %u values into DHT\n", | ||
439 | NUM_PEERS); | ||
440 | for (unsigned int i = 0; i < NUM_PEERS; i++) | ||
441 | { | ||
442 | GNUNET_CRYPTO_hash (&i, | ||
443 | sizeof(i), | ||
444 | &key); | ||
445 | GNUNET_CRYPTO_hash (&key, | ||
446 | sizeof(key), | ||
447 | &value); | ||
448 | GNUNET_DHT_put (hs[i], | ||
449 | &key, | ||
450 | 10U, | ||
451 | GNUNET_DHT_RO_RECORD_ROUTE | ||
452 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
453 | GNUNET_BLOCK_TYPE_TEST, | ||
454 | sizeof(value), | ||
455 | &value, | ||
456 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
457 | NULL, | ||
458 | NULL); | ||
459 | } | ||
460 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, | ||
461 | &do_puts, | ||
462 | hs); | ||
463 | } | ||
464 | |||
465 | |||
466 | /** | ||
467 | * Callback to be called when the requested peer information is available | ||
468 | * The peer information in the callback is valid until the operation 'op' is canceled. | ||
469 | * | ||
470 | * @param cls a `struct GetOperation *` | ||
471 | * @param op the operation this callback corresponds to | ||
472 | * @param pinfo the result; will be NULL if the operation has failed | ||
473 | * @param emsg error message if the operation has failed; will be NULL if the | ||
474 | * operation is successful | ||
475 | */ | ||
476 | static void | ||
477 | pid_cb (void *cls, | ||
478 | struct GNUNET_TESTBED_Operation *op, | ||
479 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
480 | const char *emsg) | ||
481 | { | ||
482 | struct GetOperation *get_op = cls; | ||
483 | |||
484 | if (NULL != emsg) | ||
485 | { | ||
486 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
487 | "Testbed failure: %s\n", | ||
488 | emsg); | ||
489 | GNUNET_TESTBED_operation_done (get_op->to); | ||
490 | get_op->to = NULL; | ||
491 | GNUNET_SCHEDULER_shutdown (); | ||
492 | return; | ||
493 | } | ||
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "Testbed provided PID %s\n", | ||
496 | GNUNET_i2s (pinfo->result.id)); | ||
497 | get_op->me = *pinfo->result.id; | ||
498 | GNUNET_TESTBED_operation_done (get_op->to); | ||
499 | get_op->to = NULL; | ||
500 | get_op->get = GNUNET_DHT_get_start (get_op->dht, | ||
501 | GNUNET_BLOCK_TYPE_TEST, | ||
502 | &get_op->key, | ||
503 | 4U, /* replication level */ | ||
504 | GNUNET_DHT_RO_RECORD_ROUTE | ||
505 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
506 | NULL, /* xquery */ | ||
507 | 0, /* xquery bits */ | ||
508 | &dht_get_handler, | ||
509 | get_op); | ||
510 | } | ||
511 | |||
512 | |||
513 | /** | ||
514 | * Start GET operations. | ||
515 | */ | ||
516 | static void | ||
517 | start_get (void *cls) | ||
518 | { | ||
519 | struct GNUNET_DHT_Handle **dhts = cls; | ||
520 | |||
521 | get_task = NULL; | ||
522 | for (unsigned int i = 0; i < NUM_PEERS; i++) | ||
523 | { | ||
524 | struct GNUNET_HashCode key; | ||
525 | |||
526 | GNUNET_CRYPTO_hash (&i, | ||
527 | sizeof(i), | ||
528 | &key); | ||
529 | for (unsigned int j = 0; j < NUM_PEERS; j++) | ||
530 | { | ||
531 | struct GetOperation *get_op; | ||
532 | |||
533 | get_op = GNUNET_new (struct GetOperation); | ||
534 | ok++; | ||
535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
536 | "Starting GET %p\n", | ||
537 | get_op); | ||
538 | get_op->key = key; | ||
539 | get_op->dht = dhts[j]; | ||
540 | get_op->to = GNUNET_TESTBED_peer_get_information (my_peers[j], | ||
541 | GNUNET_TESTBED_PIT_IDENTITY, | ||
542 | &pid_cb, | ||
543 | get_op); | ||
544 | GNUNET_CONTAINER_DLL_insert (get_head, | ||
545 | get_tail, | ||
546 | get_op); | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | |||
551 | |||
552 | /** | ||
553 | * Main function of the test. | ||
554 | * | ||
555 | * @param cls closure (NULL) | ||
556 | * @param ctx argument to give to #GNUNET_DHT_TEST_cleanup on test end | ||
557 | * @param num_peers number of @a peers that are running | ||
558 | * @param peers array of peers | ||
559 | * @param dhts handle to each of the DHTs of the peers | ||
560 | */ | ||
561 | static void | ||
562 | run (void *cls, | ||
563 | struct GNUNET_DHT_TEST_Context *ctx, | ||
564 | unsigned int num_peers, | ||
565 | struct GNUNET_TESTBED_Peer **peers, | ||
566 | struct GNUNET_DHT_Handle **dhts) | ||
567 | { | ||
568 | GNUNET_assert (NUM_PEERS == num_peers); | ||
569 | my_peers = peers; | ||
570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
571 | "Peers setup, starting test\n"); | ||
572 | put_task = GNUNET_SCHEDULER_add_now (&do_puts, | ||
573 | dhts); | ||
574 | get_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
575 | &start_get, | ||
576 | dhts); | ||
577 | timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, | ||
578 | &timeout_cb, | ||
579 | ctx); | ||
580 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
581 | ctx); | ||
582 | } | ||
583 | |||
584 | |||
585 | /** | ||
586 | * Main: start test | ||
587 | */ | ||
588 | int | ||
589 | main (int xargc, char *xargv[]) | ||
590 | { | ||
591 | const char *cfg_filename; | ||
592 | const char *test_name; | ||
593 | |||
594 | unsetenv ("XDG_DATA_HOME"); | ||
595 | unsetenv ("XDG_CONFIG_HOME"); | ||
596 | unsetenv ("XDG_CACHE_HOME"); | ||
597 | if (NULL != strstr (xargv[0], "test_dht_2dtorus")) | ||
598 | { | ||
599 | cfg_filename = "test_dht_2dtorus.conf"; | ||
600 | test_name = "test-dht-2dtorus"; | ||
601 | NUM_PEERS = 16; | ||
602 | } | ||
603 | else if (NULL != strstr (xargv[0], "test_dht_line")) | ||
604 | { | ||
605 | cfg_filename = "test_dht_line.conf"; | ||
606 | test_name = "test-dht-line"; | ||
607 | NUM_PEERS = 5; | ||
608 | } | ||
609 | else if (NULL != strstr (xargv[0], "test_dht_twopeer")) | ||
610 | { | ||
611 | cfg_filename = "test_dht_line.conf"; | ||
612 | test_name = "test-dht-twopeer"; | ||
613 | NUM_PEERS = 2; | ||
614 | } | ||
615 | else if (NULL != strstr (xargv[0], "test_dht_multipeer")) | ||
616 | { | ||
617 | cfg_filename = "test_dht_multipeer.conf"; | ||
618 | test_name = "test-dht-multipeer"; | ||
619 | NUM_PEERS = 10; | ||
620 | } | ||
621 | else | ||
622 | { | ||
623 | GNUNET_break (0); | ||
624 | return 1; | ||
625 | } | ||
626 | GNUNET_DHT_TEST_run (test_name, | ||
627 | cfg_filename, | ||
628 | NUM_PEERS, | ||
629 | &run, NULL); | ||
630 | return ok; | ||
631 | } | ||
632 | |||
633 | |||
634 | /* end of test_dht_topo.c */ | ||