summaryrefslogtreecommitdiff
path: root/src/dht/test_dht_topo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r--src/dht/test_dht_topo.c417
1 files changed, 211 insertions, 206 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index 32d99152d..d92095cc6 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -32,18 +32,21 @@
32/** 32/**
33 * How long until we give up on fetching the data? 33 * How long until we give up on fetching the data?
34 */ 34 */
35#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 35#define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
36 120)
36 37
37/** 38/**
38 * How frequently do we execute the PUTs? 39 * How frequently do we execute the PUTs?
39 */ 40 */
40#define PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 41#define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
42 5)
41 43
42 44
43/** 45/**
44 * Information we keep for each GET operation. 46 * Information we keep for each GET operation.
45 */ 47 */
46struct GetOperation { 48struct GetOperation
49{
47 /** 50 /**
48 * DLL. 51 * DLL.
49 */ 52 */
@@ -105,7 +108,8 @@ static unsigned int NUM_PEERS;
105/** 108/**
106 * Statistics we print out. 109 * Statistics we print out.
107 */ 110 */
108static struct { 111static struct
112{
109 const char *subsystem; 113 const char *subsystem;
110 const char *name; 114 const char *name;
111 unsigned long long total; 115 unsigned long long total;
@@ -150,34 +154,34 @@ static struct {
150 154
151 155
152static struct GNUNET_DHT_TEST_Context * 156static struct GNUNET_DHT_TEST_Context *
153stop_ops() 157stop_ops ()
154{ 158{
155 struct GetOperation *get_op; 159 struct GetOperation *get_op;
156 struct GNUNET_DHT_TEST_Context *ctx = NULL; 160 struct GNUNET_DHT_TEST_Context *ctx = NULL;
157 161
158 if (NULL != timeout_task) 162 if (NULL != timeout_task)
159 { 163 {
160 ctx = GNUNET_SCHEDULER_cancel(timeout_task); 164 ctx = GNUNET_SCHEDULER_cancel (timeout_task);
161 timeout_task = NULL; 165 timeout_task = NULL;
162 } 166 }
163 if (NULL != put_task) 167 if (NULL != put_task)
164 { 168 {
165 GNUNET_SCHEDULER_cancel(put_task); 169 GNUNET_SCHEDULER_cancel (put_task);
166 put_task = NULL; 170 put_task = NULL;
167 } 171 }
168 if (NULL != get_task) 172 if (NULL != get_task)
169 { 173 {
170 GNUNET_SCHEDULER_cancel(get_task); 174 GNUNET_SCHEDULER_cancel (get_task);
171 get_task = NULL; 175 get_task = NULL;
172 } 176 }
173 while (NULL != (get_op = get_tail)) 177 while (NULL != (get_op = get_tail))
174 { 178 {
175 GNUNET_DHT_get_stop(get_op->get); 179 GNUNET_DHT_get_stop (get_op->get);
176 GNUNET_CONTAINER_DLL_remove(get_head, 180 GNUNET_CONTAINER_DLL_remove (get_head,
177 get_tail, 181 get_tail,
178 get_op); 182 get_op);
179 GNUNET_free(get_op); 183 GNUNET_free (get_op);
180 } 184 }
181 return ctx; 185 return ctx;
182} 186}
183 187
@@ -190,32 +194,32 @@ stop_ops()
190 * @param emsg error message on failure 194 * @param emsg error message on failure
191 */ 195 */
192static void 196static void
193stats_finished(void *cls, 197stats_finished (void *cls,
194 struct GNUNET_TESTBED_Operation *op, 198 struct GNUNET_TESTBED_Operation *op,
195 const char *emsg) 199 const char *emsg)
196{ 200{
197 struct GNUNET_DHT_TEST_Context *ctx = cls; 201 struct GNUNET_DHT_TEST_Context *ctx = cls;
198 unsigned int i; 202 unsigned int i;
199 203
200 if (NULL != op) 204 if (NULL != op)
201 GNUNET_TESTBED_operation_done(op); 205 GNUNET_TESTBED_operation_done (op);
202 if (NULL != emsg) 206 if (NULL != emsg)
203 { 207 {
204 fprintf(stderr, 208 fprintf (stderr,
205 _("Gathering statistics failed: %s\n"), 209 _ ("Gathering statistics failed: %s\n"),
206 emsg); 210 emsg);
207 GNUNET_SCHEDULER_cancel(put_task); 211 GNUNET_SCHEDULER_cancel (put_task);
208 GNUNET_DHT_TEST_cleanup(ctx); 212 GNUNET_DHT_TEST_cleanup (ctx);
209 return; 213 return;
210 } 214 }
211 for (i = 0; NULL != stats[i].name; i++) 215 for (i = 0; NULL != stats[i].name; i++)
212 fprintf(stderr, 216 fprintf (stderr,
213 "%6s/%60s = %12llu\n", 217 "%6s/%60s = %12llu\n",
214 stats[i].subsystem, 218 stats[i].subsystem,
215 stats[i].name, 219 stats[i].name,
216 stats[i].total); 220 stats[i].total);
217 GNUNET_DHT_TEST_cleanup(ctx); 221 GNUNET_DHT_TEST_cleanup (ctx);
218 GNUNET_SCHEDULER_shutdown(); 222 GNUNET_SCHEDULER_shutdown ();
219} 223}
220 224
221 225
@@ -231,20 +235,20 @@ stats_finished(void *cls,
231 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 235 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
232 */ 236 */
233static int 237static int
234handle_stats(void *cls, 238handle_stats (void *cls,
235 const struct GNUNET_TESTBED_Peer *peer, 239 const struct GNUNET_TESTBED_Peer *peer,
236 const char *subsystem, 240 const char *subsystem,
237 const char *name, 241 const char *name,
238 uint64_t value, 242 uint64_t value,
239 int is_persistent) 243 int is_persistent)
240{ 244{
241 unsigned int i; 245 unsigned int i;
242 246
243 for (i = 0; NULL != stats[i].name; i++) 247 for (i = 0; NULL != stats[i].name; i++)
244 if ((0 == strcasecmp(subsystem, 248 if ((0 == strcasecmp (subsystem,
245 stats[i].subsystem)) && 249 stats[i].subsystem)) &&
246 (0 == strcasecmp(name, 250 (0 == strcasecmp (name,
247 stats[i].name))) 251 stats[i].name)))
248 stats[i].total += value; 252 stats[i].total += value;
249 return GNUNET_OK; 253 return GNUNET_OK;
250} 254}
@@ -257,9 +261,9 @@ handle_stats(void *cls,
257 * @param cls the 'struct GNUNET_DHT_TestContext' 261 * @param cls the 'struct GNUNET_DHT_TestContext'
258 */ 262 */
259static void 263static void
260shutdown_task(void *cls) 264shutdown_task (void *cls)
261{ 265{
262 (void)stop_ops(); 266 (void) stop_ops ();
263} 267}
264 268
265 269
@@ -270,12 +274,12 @@ shutdown_task(void *cls)
270 * @param cls the `struct GNUNET_DHT_TestContext` 274 * @param cls the `struct GNUNET_DHT_TestContext`
271 */ 275 */
272static void 276static void
273timeout_cb(void *cls) 277timeout_cb (void *cls)
274{ 278{
275 timeout_task = NULL; 279 timeout_task = NULL;
276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
277 "Timeout\n"); 281 "Timeout\n");
278 GNUNET_SCHEDULER_shutdown(); 282 GNUNET_SCHEDULER_shutdown ();
279} 283}
280 284
281 285
@@ -295,75 +299,75 @@ timeout_cb(void *cls)
295 * @param data pointer to the result data 299 * @param data pointer to the result data
296 */ 300 */
297static void 301static void
298dht_get_handler(void *cls, 302dht_get_handler (void *cls,
299 struct GNUNET_TIME_Absolute exp, 303 struct GNUNET_TIME_Absolute exp,
300 const struct GNUNET_HashCode *key, 304 const struct GNUNET_HashCode *key,
301 const struct GNUNET_PeerIdentity *get_path, 305 const struct GNUNET_PeerIdentity *get_path,
302 unsigned int get_path_length, 306 unsigned int get_path_length,
303 const struct GNUNET_PeerIdentity *put_path, 307 const struct GNUNET_PeerIdentity *put_path,
304 unsigned int put_path_length, 308 unsigned int put_path_length,
305 enum GNUNET_BLOCK_Type type, 309 enum GNUNET_BLOCK_Type type,
306 size_t size, 310 size_t size,
307 const void *data) 311 const void *data)
308{ 312{
309 struct GetOperation *get_op = cls; 313 struct GetOperation *get_op = cls;
310 struct GNUNET_HashCode want; 314 struct GNUNET_HashCode want;
311 struct GNUNET_DHT_TEST_Context *ctx; 315 struct GNUNET_DHT_TEST_Context *ctx;
312 316
313 if (sizeof(struct GNUNET_HashCode) != size) 317 if (sizeof(struct GNUNET_HashCode) != size)
314 { 318 {
315 GNUNET_break(0); 319 GNUNET_break (0);
316 return; 320 return;
317 } 321 }
318 GNUNET_CRYPTO_hash(key, 322 GNUNET_CRYPTO_hash (key,
319 sizeof(*key), 323 sizeof(*key),
320 &want); 324 &want);
321 if (0 != memcmp(&want, 325 if (0 != memcmp (&want,
322 data, 326 data,
323 sizeof(want))) 327 sizeof(want)))
324 { 328 {
325 GNUNET_break(0); 329 GNUNET_break (0);
326 return; 330 return;
327 } 331 }
328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "Get successful\n"); 333 "Get successful\n");
330#if 0 334#if 0
331 { 335 {
332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "PATH: (get %u, put %u)\n", 337 "PATH: (get %u, put %u)\n",
334 get_path_length, 338 get_path_length,
335 put_path_length); 339 put_path_length);
336 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 " LOCAL\n"); 341 " LOCAL\n");
338 for (int i = get_path_length - 1; i >= 0; i--) 342 for (int i = get_path_length - 1; i >= 0; i--)
339 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 " %s\n", 344 " %s\n",
341 GNUNET_i2s(&get_path[i])); 345 GNUNET_i2s (&get_path[i]));
342 for (int i = put_path_length - 1; i >= 0; i--) 346 for (int i = put_path_length - 1; i >= 0; i--)
343 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 " %s\n", 348 " %s\n",
345 GNUNET_i2s(&put_path[i])); 349 GNUNET_i2s (&put_path[i]));
346 } 350 }
347#endif 351#endif
348 GNUNET_DHT_get_stop(get_op->get); 352 GNUNET_DHT_get_stop (get_op->get);
349 GNUNET_CONTAINER_DLL_remove(get_head, 353 GNUNET_CONTAINER_DLL_remove (get_head,
350 get_tail, 354 get_tail,
351 get_op); 355 get_op);
352 GNUNET_free(get_op); 356 GNUNET_free (get_op);
353 if (NULL != get_head) 357 if (NULL != get_head)
354 return; 358 return;
355 /* all DHT GET operations successful; get stats! */ 359 /* all DHT GET operations successful; get stats! */
356 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 360 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
357 "All DHT operations successful. Obtaining stats!\n"); 361 "All DHT operations successful. Obtaining stats!\n");
358 ok = 0; 362 ok = 0;
359 ctx = stop_ops(); 363 ctx = stop_ops ();
360 GNUNET_assert(NULL != ctx); 364 GNUNET_assert (NULL != ctx);
361 (void)GNUNET_TESTBED_get_statistics(NUM_PEERS, 365 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS,
362 my_peers, 366 my_peers,
363 NULL, NULL, 367 NULL, NULL,
364 &handle_stats, 368 &handle_stats,
365 &stats_finished, 369 &stats_finished,
366 ctx); 370 ctx);
367} 371}
368 372
369 373
@@ -374,38 +378,38 @@ dht_get_handler(void *cls,
374 * @param tc Task context 378 * @param tc Task context
375 */ 379 */
376static void 380static void
377do_puts(void *cls) 381do_puts (void *cls)
378{ 382{
379 struct GNUNET_DHT_Handle **hs = cls; 383 struct GNUNET_DHT_Handle **hs = cls;
380 struct GNUNET_HashCode key; 384 struct GNUNET_HashCode key;
381 struct GNUNET_HashCode value; 385 struct GNUNET_HashCode value;
382 386
383 put_task = NULL; 387 put_task = NULL;
384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385 "Putting values into DHT\n"); 389 "Putting values into DHT\n");
386 for (unsigned int i = 0; i < NUM_PEERS; i++) 390 for (unsigned int i = 0; i < NUM_PEERS; i++)
387 { 391 {
388 GNUNET_CRYPTO_hash(&i, 392 GNUNET_CRYPTO_hash (&i,
389 sizeof(i), 393 sizeof(i),
390 &key); 394 &key);
391 GNUNET_CRYPTO_hash(&key, 395 GNUNET_CRYPTO_hash (&key,
392 sizeof(key), 396 sizeof(key),
393 &value); 397 &value);
394 GNUNET_DHT_put(hs[i], 398 GNUNET_DHT_put (hs[i],
395 &key, 399 &key,
396 10U, 400 10U,
397 GNUNET_DHT_RO_RECORD_ROUTE | 401 GNUNET_DHT_RO_RECORD_ROUTE
398 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 402 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
399 GNUNET_BLOCK_TYPE_TEST, 403 GNUNET_BLOCK_TYPE_TEST,
400 sizeof(value), 404 sizeof(value),
401 &value, 405 &value,
402 GNUNET_TIME_UNIT_FOREVER_ABS, 406 GNUNET_TIME_UNIT_FOREVER_ABS,
403 NULL, 407 NULL,
404 NULL); 408 NULL);
405 } 409 }
406 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, 410 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY,
407 &do_puts, 411 &do_puts,
408 hs); 412 hs);
409} 413}
410 414
411 415
@@ -413,7 +417,7 @@ do_puts(void *cls)
413 * Start GET operations. 417 * Start GET operations.
414 */ 418 */
415static void 419static void
416start_get(void *cls) 420start_get (void *cls)
417{ 421{
418 struct GNUNET_DHT_Handle **dhts = cls; 422 struct GNUNET_DHT_Handle **dhts = cls;
419 unsigned int i; 423 unsigned int i;
@@ -423,25 +427,26 @@ start_get(void *cls)
423 427
424 get_task = NULL; 428 get_task = NULL;
425 for (i = 0; i < NUM_PEERS; i++) 429 for (i = 0; i < NUM_PEERS; i++)
430 {
431 GNUNET_CRYPTO_hash (&i, sizeof(i), &key);
432 for (j = 0; j < NUM_PEERS; j++)
426 { 433 {
427 GNUNET_CRYPTO_hash(&i, sizeof(i), &key); 434 get_op = GNUNET_new (struct GetOperation);
428 for (j = 0; j < NUM_PEERS; j++) 435 GNUNET_CONTAINER_DLL_insert (get_head,
429 { 436 get_tail,
430 get_op = GNUNET_new(struct GetOperation); 437 get_op);
431 GNUNET_CONTAINER_DLL_insert(get_head, 438 get_op->get = GNUNET_DHT_get_start (dhts[j],
432 get_tail, 439 GNUNET_BLOCK_TYPE_TEST, /* type */
433 get_op); 440 &key, /*key to search */
434 get_op->get = GNUNET_DHT_get_start(dhts[j], 441 4U, /* replication level */
435 GNUNET_BLOCK_TYPE_TEST, /* type */ 442 GNUNET_DHT_RO_RECORD_ROUTE
436 &key, /*key to search */ 443 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
437 4U, /* replication level */ 444 NULL, /* xquery */
438 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 445 0, /* xquery bits */
439 NULL, /* xquery */ 446 &dht_get_handler,
440 0, /* xquery bits */ 447 get_op);
441 &dht_get_handler,
442 get_op);
443 }
444 } 448 }
449 }
445} 450}
446 451
447 452
@@ -455,26 +460,26 @@ start_get(void *cls)
455 * @param dhts handle to each of the DHTs of the peers 460 * @param dhts handle to each of the DHTs of the peers
456 */ 461 */
457static void 462static void
458run(void *cls, 463run (void *cls,
459 struct GNUNET_DHT_TEST_Context *ctx, 464 struct GNUNET_DHT_TEST_Context *ctx,
460 unsigned int num_peers, 465 unsigned int num_peers,
461 struct GNUNET_TESTBED_Peer **peers, 466 struct GNUNET_TESTBED_Peer **peers,
462 struct GNUNET_DHT_Handle **dhts) 467 struct GNUNET_DHT_Handle **dhts)
463{ 468{
464 GNUNET_assert(NUM_PEERS == num_peers); 469 GNUNET_assert (NUM_PEERS == num_peers);
465 my_peers = peers; 470 my_peers = peers;
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Peers setup, starting test\n"); 472 "Peers setup, starting test\n");
468 put_task = GNUNET_SCHEDULER_add_now(&do_puts, 473 put_task = GNUNET_SCHEDULER_add_now (&do_puts,
469 dhts); 474 dhts);
470 get_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 475 get_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
471 &start_get, 476 &start_get,
472 dhts); 477 dhts);
473 timeout_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, 478 timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
474 &timeout_cb, 479 &timeout_cb,
475 ctx); 480 ctx);
476 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 481 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
477 ctx); 482 ctx);
478} 483}
479 484
480 485
@@ -482,44 +487,44 @@ run(void *cls,
482 * Main: start test 487 * Main: start test
483 */ 488 */
484int 489int
485main(int xargc, char *xargv[]) 490main (int xargc, char *xargv[])
486{ 491{
487 const char *cfg_filename; 492 const char *cfg_filename;
488 const char *test_name; 493 const char *test_name;
489 494
490 if (NULL != strstr(xargv[0], "test_dht_2dtorus")) 495 if (NULL != strstr (xargv[0], "test_dht_2dtorus"))
491 { 496 {
492 cfg_filename = "test_dht_2dtorus.conf"; 497 cfg_filename = "test_dht_2dtorus.conf";
493 test_name = "test-dht-2dtorus"; 498 test_name = "test-dht-2dtorus";
494 NUM_PEERS = 16; 499 NUM_PEERS = 16;
495 } 500 }
496 else if (NULL != strstr(xargv[0], "test_dht_line")) 501 else if (NULL != strstr (xargv[0], "test_dht_line"))
497 { 502 {
498 cfg_filename = "test_dht_line.conf"; 503 cfg_filename = "test_dht_line.conf";
499 test_name = "test-dht-line"; 504 test_name = "test-dht-line";
500 NUM_PEERS = 5; 505 NUM_PEERS = 5;
501 } 506 }
502 else if (NULL != strstr(xargv[0], "test_dht_twopeer")) 507 else if (NULL != strstr (xargv[0], "test_dht_twopeer"))
503 { 508 {
504 cfg_filename = "test_dht_line.conf"; 509 cfg_filename = "test_dht_line.conf";
505 test_name = "test-dht-twopeer"; 510 test_name = "test-dht-twopeer";
506 NUM_PEERS = 2; 511 NUM_PEERS = 2;
507 } 512 }
508 else if (NULL != strstr(xargv[0], "test_dht_multipeer")) 513 else if (NULL != strstr (xargv[0], "test_dht_multipeer"))
509 { 514 {
510 cfg_filename = "test_dht_multipeer.conf"; 515 cfg_filename = "test_dht_multipeer.conf";
511 test_name = "test-dht-multipeer"; 516 test_name = "test-dht-multipeer";
512 NUM_PEERS = 10; 517 NUM_PEERS = 10;
513 } 518 }
514 else 519 else
515 { 520 {
516 GNUNET_break(0); 521 GNUNET_break (0);
517 return 1; 522 return 1;
518 } 523 }
519 GNUNET_DHT_TEST_run(test_name, 524 GNUNET_DHT_TEST_run (test_name,
520 cfg_filename, 525 cfg_filename,
521 NUM_PEERS, 526 NUM_PEERS,
522 &run, NULL); 527 &run, NULL);
523 return ok; 528 return ok;
524} 529}
525 530