testbed_test.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <unistd.h>
  2. #include <gnunet/platform.h>
  3. #include <gnunet/gnunet_util_lib.h>
  4. #include <gnunet/gnunet_testbed_service.h>
  5. #include <gnunet/gnunet_dht_service.h>
  6. #define NUM_PEERS 20
  7. static struct GNUNET_TESTBED_Operation *dht_op;
  8. static struct GNUNET_DHT_Handle *dht_handle;
  9. struct MyContext
  10. {
  11. int ht_len;
  12. } ctxt;
  13. static int result;
  14. static void
  15. shutdown_task (void *cls)
  16. {
  17. if (NULL != dht_op)
  18. {
  19. GNUNET_TESTBED_operation_done (dht_op);
  20. dht_op = NULL;
  21. dht_handle = NULL;
  22. }
  23. result = GNUNET_OK;
  24. }
  25. static void
  26. service_connect_comp (void *cls,
  27. struct GNUNET_TESTBED_Operation *op,
  28. void *ca_result,
  29. const char *emsg)
  30. {
  31. GNUNET_assert (op == dht_op);
  32. dht_handle = ca_result;
  33. // Do work here...
  34. GNUNET_SCHEDULER_shutdown ();
  35. }
  36. static void *
  37. dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
  38. {
  39. struct MyContext *ctxt = cls;
  40. dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len);
  41. return dht_handle;
  42. }
  43. static void
  44. dht_da (void *cls, void *op_result)
  45. {
  46. struct MyContext *ctxt = cls;
  47. GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
  48. dht_handle = NULL;
  49. }
  50. static void
  51. test_master (void *cls,
  52. struct GNUNET_TESTBED_RunHandle *h,
  53. unsigned int num_peers,
  54. struct GNUNET_TESTBED_Peer **peers,
  55. unsigned int links_succeeded,
  56. unsigned int links_failed)
  57. {
  58. ctxt.ht_len = 10;
  59. dht_op = GNUNET_TESTBED_service_connect
  60. (NULL, peers[0], "dht",
  61. &service_connect_comp, NULL,
  62. &dht_ca, &dht_da, &ctxt);
  63. GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
  64. }
  65. int
  66. main (int argc, char **argv)
  67. {
  68. int ret;
  69. result = GNUNET_SYSERR;
  70. ret = GNUNET_TESTBED_test_run
  71. ("awesome-test", "template.conf",
  72. NUM_PEERS, 0LL,
  73. NULL, NULL, &test_master, NULL);
  74. if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
  75. return 1;
  76. return 0;
  77. }