paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / fs / test_fs_namespace_list_updateable.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2005-2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file fs/test_fs_namespace_list_updateable.c
21  * @brief Test for fs_namespace_list_updateable.c
22  * @author Christian Grothoff
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include "gnunet_testing_lib.h"
27 #include "gnunet_fs_service.h"
28
29
30 static struct GNUNET_FS_Handle *fs;
31
32 static int err;
33
34 static struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
35
36 static struct GNUNET_CONTAINER_MetaData *meta;
37
38 static struct GNUNET_FS_Uri *uri_this;
39
40 static struct GNUNET_FS_Uri *uri_next;
41
42 static struct GNUNET_FS_BlockOptions bo;
43
44
45 static void *
46 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
47 {
48   return NULL;
49 }
50
51
52 static void
53 do_shutdown ()
54 {
55   if (uri_this != NULL)
56     GNUNET_FS_uri_destroy (uri_this);
57   if (uri_next != NULL)
58     GNUNET_FS_uri_destroy (uri_next);
59   if (ns != NULL)
60     GNUNET_free (ns);
61   if (meta != NULL)
62     GNUNET_CONTAINER_meta_data_destroy (meta);
63 }
64
65
66 static void
67 check_next (void *cls, const char *last_id,
68             const struct GNUNET_FS_Uri *last_uri,
69             const struct GNUNET_CONTAINER_MetaData *last_meta,
70             const char *next_id)
71 {
72   GNUNET_break (0 == strcmp (last_id, "next"));
73   GNUNET_break (0 == strcmp (next_id, "future"));
74   err -= 4;
75 }
76
77
78 static void
79 check_this_next (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 -= 2;
87   err += 4;
88   GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL);
89 }
90
91
92 static void
93 sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
94 {
95   GNUNET_assert (NULL == emsg);
96   err += 2;
97   GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL);
98 }
99
100
101 static void
102 check_this (void *cls, const char *last_id,
103             const struct GNUNET_FS_Uri *last_uri,
104             const struct GNUNET_CONTAINER_MetaData *last_meta,
105             const char *next_id)
106 {
107   GNUNET_break (0 == strcmp (last_id, "this"));
108   GNUNET_break (0 == strcmp (next_id, "next"));
109   err -= 1;
110 }
111
112
113 static void
114 sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
115 {
116   GNUNET_assert (NULL == emsg);
117   err = 1;
118   GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL);
119   GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
120                          GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
121
122 }
123
124
125 static void
126 testNamespace ()
127 {
128   ns = GNUNET_CRYPTO_ecdsa_key_create ();
129   GNUNET_assert (NULL != ns);
130   bo.content_priority = 1;
131   bo.anonymity_level = 1;
132   bo.replication_level = 0;
133   bo.expiration_time =
134       GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
135   meta = GNUNET_CONTAINER_meta_data_create ();
136
137   uri_this =
138       GNUNET_FS_uri_parse
139       ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
140        NULL);
141   uri_next =
142       GNUNET_FS_uri_parse
143       ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
144        NULL);
145   GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
146                          GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
147 }
148
149
150 static void
151 run (void *cls,
152      const struct GNUNET_CONFIGURATION_Handle *cfg,
153      struct GNUNET_TESTING_Peer *peer)
154 {
155   fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
156                         GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
157   testNamespace ();
158 }
159
160
161 int
162 main (int argc, char *argv[])
163 {
164   if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable",
165                                     "test_fs_namespace_data.conf",
166                                     &run, NULL))
167     return 1;
168   do_shutdown ();
169   return err;
170 }
171
172
173 /* end of test_fs_namespace_list_updateable.c */