test_fs_namespace_list_updateable.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2005-2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file fs/test_fs_namespace_list_updateable.c
  19. * @brief Test for fs_namespace_list_updateable.c
  20. * @author Christian Grothoff
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_testing_lib.h"
  25. #include "gnunet_fs_service.h"
  26. static struct GNUNET_FS_Handle *fs;
  27. static int err;
  28. static struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
  29. static struct GNUNET_CONTAINER_MetaData *meta;
  30. static struct GNUNET_FS_Uri *uri_this;
  31. static struct GNUNET_FS_Uri *uri_next;
  32. static struct GNUNET_FS_BlockOptions bo;
  33. static void *
  34. progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
  35. {
  36. return NULL;
  37. }
  38. static void
  39. do_shutdown ()
  40. {
  41. if (uri_this != NULL)
  42. GNUNET_FS_uri_destroy (uri_this);
  43. if (uri_next != NULL)
  44. GNUNET_FS_uri_destroy (uri_next);
  45. if (ns != NULL)
  46. GNUNET_free (ns);
  47. if (meta != NULL)
  48. GNUNET_CONTAINER_meta_data_destroy (meta);
  49. }
  50. static void
  51. check_next (void *cls, const char *last_id,
  52. const struct GNUNET_FS_Uri *last_uri,
  53. const struct GNUNET_CONTAINER_MetaData *last_meta,
  54. const char *next_id)
  55. {
  56. GNUNET_break (0 == strcmp (last_id, "next"));
  57. GNUNET_break (0 == strcmp (next_id, "future"));
  58. err -= 4;
  59. }
  60. static void
  61. check_this_next (void *cls, const char *last_id,
  62. const struct GNUNET_FS_Uri *last_uri,
  63. const struct GNUNET_CONTAINER_MetaData *last_meta,
  64. const char *next_id)
  65. {
  66. GNUNET_break (0 == strcmp (last_id, "this"));
  67. GNUNET_break (0 == strcmp (next_id, "next"));
  68. err -= 2;
  69. err += 4;
  70. GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL);
  71. }
  72. static void
  73. sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
  74. {
  75. GNUNET_assert (NULL == emsg);
  76. err += 2;
  77. GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL);
  78. }
  79. static void
  80. check_this (void *cls, const char *last_id,
  81. const struct GNUNET_FS_Uri *last_uri,
  82. const struct GNUNET_CONTAINER_MetaData *last_meta,
  83. const char *next_id)
  84. {
  85. GNUNET_break (0 == strcmp (last_id, "this"));
  86. GNUNET_break (0 == strcmp (next_id, "next"));
  87. err -= 1;
  88. }
  89. static void
  90. sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
  91. {
  92. GNUNET_assert (NULL == emsg);
  93. err = 1;
  94. GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL);
  95. GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
  96. GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
  97. }
  98. static void
  99. testNamespace ()
  100. {
  101. ns = GNUNET_CRYPTO_ecdsa_key_create ();
  102. GNUNET_assert (NULL != ns);
  103. bo.content_priority = 1;
  104. bo.anonymity_level = 1;
  105. bo.replication_level = 0;
  106. bo.expiration_time =
  107. GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
  108. meta = GNUNET_CONTAINER_meta_data_create ();
  109. uri_this =
  110. GNUNET_FS_uri_parse
  111. ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
  112. NULL);
  113. uri_next =
  114. GNUNET_FS_uri_parse
  115. ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
  116. NULL);
  117. GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
  118. GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
  119. }
  120. static void
  121. run (void *cls,
  122. const struct GNUNET_CONFIGURATION_Handle *cfg,
  123. struct GNUNET_TESTING_Peer *peer)
  124. {
  125. fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
  126. GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
  127. testNamespace ();
  128. }
  129. int
  130. main (int argc, char *argv[])
  131. {
  132. if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable",
  133. "test_fs_namespace_data.conf",
  134. &run, NULL))
  135. return 1;
  136. do_shutdown ();
  137. return err;
  138. }
  139. /* end of test_fs_namespace_list_updateable.c */