test_fs_namespace_list_updateable.c 4.9 KB

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