test_fs_namespace_list_updateable.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2005, 2006, 2008, 2009 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_arm_service.h"
  25. #include "gnunet_fs_service.h"
  26. #define VERBOSE GNUNET_NO
  27. #define START_ARM GNUNET_YES
  28. static struct PeerContext p1;
  29. static struct GNUNET_FS_Handle *fs;
  30. static int err;
  31. static struct GNUNET_FS_Namespace *ns;
  32. static struct GNUNET_CONTAINER_MetaData *meta;
  33. static struct GNUNET_FS_Uri *uri_this;
  34. static struct GNUNET_FS_Uri *uri_next;
  35. static struct GNUNET_FS_BlockOptions bo;
  36. struct PeerContext
  37. {
  38. struct GNUNET_CONFIGURATION_Handle *cfg;
  39. #if START_ARM
  40. struct GNUNET_OS_Process *arm_proc;
  41. #endif
  42. };
  43. static void *
  44. progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
  45. {
  46. return NULL;
  47. }
  48. static void
  49. setup_peer (struct PeerContext *p, const char *cfgname)
  50. {
  51. p->cfg = GNUNET_CONFIGURATION_create ();
  52. #if START_ARM
  53. p->arm_proc =
  54. GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
  55. "gnunet-service-arm",
  56. #if VERBOSE
  57. "-L", "DEBUG",
  58. #endif
  59. "-c", cfgname, NULL);
  60. #endif
  61. GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
  62. }
  63. static void
  64. stop_arm (struct PeerContext *p)
  65. {
  66. #if START_ARM
  67. if (NULL != p->arm_proc)
  68. {
  69. if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
  70. GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
  71. if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
  72. GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
  73. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
  74. GNUNET_OS_process_get_pid (p->arm_proc));
  75. GNUNET_OS_process_close (p->arm_proc);
  76. p->arm_proc = NULL;
  77. }
  78. #endif
  79. if (uri_this != NULL)
  80. GNUNET_FS_uri_destroy (uri_this);
  81. if (uri_next != NULL)
  82. GNUNET_FS_uri_destroy (uri_next);
  83. if (ns != NULL)
  84. GNUNET_FS_namespace_delete (ns, GNUNET_NO);
  85. if (meta != NULL)
  86. GNUNET_CONTAINER_meta_data_destroy (meta);
  87. GNUNET_CONFIGURATION_destroy (p->cfg);
  88. }
  89. static void
  90. check_next (void *cls, const char *last_id,
  91. const struct GNUNET_FS_Uri *last_uri,
  92. const struct GNUNET_CONTAINER_MetaData *last_meta,
  93. const char *next_id)
  94. {
  95. GNUNET_break (0 == strcmp (last_id, "next"));
  96. GNUNET_break (0 == strcmp (next_id, "future"));
  97. err -= 4;
  98. }
  99. static void
  100. check_this_next (void *cls, const char *last_id,
  101. const struct GNUNET_FS_Uri *last_uri,
  102. const struct GNUNET_CONTAINER_MetaData *last_meta,
  103. const char *next_id)
  104. {
  105. GNUNET_break (0 == strcmp (last_id, "this"));
  106. GNUNET_break (0 == strcmp (next_id, "next"));
  107. err -= 2;
  108. err += 4;
  109. GNUNET_FS_namespace_list_updateable (ns, next_id, &check_next, NULL);
  110. }
  111. static void
  112. sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
  113. {
  114. GNUNET_assert (NULL == emsg);
  115. err += 2;
  116. GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this_next, NULL);
  117. }
  118. static void
  119. check_this (void *cls, const char *last_id,
  120. const struct GNUNET_FS_Uri *last_uri,
  121. const struct GNUNET_CONTAINER_MetaData *last_meta,
  122. const char *next_id)
  123. {
  124. GNUNET_break (0 == strcmp (last_id, "this"));
  125. GNUNET_break (0 == strcmp (next_id, "next"));
  126. err -= 1;
  127. }
  128. static void
  129. sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
  130. {
  131. GNUNET_assert (NULL == emsg);
  132. err = 1;
  133. GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL);
  134. GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
  135. GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
  136. }
  137. static void
  138. testNamespace ()
  139. {
  140. ns = GNUNET_FS_namespace_create (fs, "testNamespace");
  141. GNUNET_assert (NULL != ns);
  142. bo.content_priority = 1;
  143. bo.anonymity_level = 1;
  144. bo.replication_level = 0;
  145. bo.expiration_time =
  146. GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
  147. meta = GNUNET_CONTAINER_meta_data_create ();
  148. uri_this =
  149. GNUNET_FS_uri_parse
  150. ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
  151. NULL);
  152. uri_next =
  153. GNUNET_FS_uri_parse
  154. ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
  155. NULL);
  156. GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
  157. GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
  158. }
  159. static void
  160. run (void *cls, char *const *args, const char *cfgfile,
  161. const struct GNUNET_CONFIGURATION_Handle *cfg)
  162. {
  163. setup_peer (&p1, "test_fs_namespace_data.conf");
  164. fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
  165. GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
  166. testNamespace ();
  167. }
  168. int
  169. main (int argc, char *argv[])
  170. {
  171. char *const argvx[] = {
  172. "test-fs-namespace",
  173. "-c",
  174. "test_fs_namespace_data.conf",
  175. #if VERBOSE
  176. "-L", "DEBUG",
  177. #endif
  178. NULL
  179. };
  180. struct GNUNET_GETOPT_CommandLineOption options[] = {
  181. GNUNET_GETOPT_OPTION_END
  182. };
  183. GNUNET_log_setup ("test_fs_namespace_list_updateable",
  184. #if VERBOSE
  185. "DEBUG",
  186. #else
  187. "WARNING",
  188. #endif
  189. NULL);
  190. GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
  191. "test-fs-namespace", "nohelp", options, &run, NULL);
  192. stop_arm (&p1);
  193. GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
  194. return err;
  195. }
  196. /* end of test_fs_namespace_list_updateable.c */