src: for every AGPL3.0 file, add SPDX identifier.
[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      SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21 /**
22  * @file fs/test_fs_namespace_list_updateable.c
23  * @brief Test for fs_namespace_list_updateable.c
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_lib.h"
29 #include "gnunet_fs_service.h"
30
31
32 static struct GNUNET_FS_Handle *fs;
33
34 static int err;
35
36 static struct GNUNET_CRYPTO_EcdsaPrivateKey *ns;
37
38 static struct GNUNET_CONTAINER_MetaData *meta;
39
40 static struct GNUNET_FS_Uri *uri_this;
41
42 static struct GNUNET_FS_Uri *uri_next;
43
44 static struct GNUNET_FS_BlockOptions bo;
45
46
47 static void *
48 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
49 {
50   return NULL;
51 }
52
53
54 static void
55 do_shutdown ()
56 {
57   if (uri_this != NULL)
58     GNUNET_FS_uri_destroy (uri_this);
59   if (uri_next != NULL)
60     GNUNET_FS_uri_destroy (uri_next);
61   if (ns != NULL)
62     GNUNET_free (ns);
63   if (meta != NULL)
64     GNUNET_CONTAINER_meta_data_destroy (meta);
65 }
66
67
68 static void
69 check_next (void *cls, const char *last_id,
70             const struct GNUNET_FS_Uri *last_uri,
71             const struct GNUNET_CONTAINER_MetaData *last_meta,
72             const char *next_id)
73 {
74   GNUNET_break (0 == strcmp (last_id, "next"));
75   GNUNET_break (0 == strcmp (next_id, "future"));
76   err -= 4;
77 }
78
79
80 static void
81 check_this_next (void *cls, const char *last_id,
82                  const struct GNUNET_FS_Uri *last_uri,
83                  const struct GNUNET_CONTAINER_MetaData *last_meta,
84                  const char *next_id)
85 {
86   GNUNET_break (0 == strcmp (last_id, "this"));
87   GNUNET_break (0 == strcmp (next_id, "next"));
88   err -= 2;
89   err += 4;
90   GNUNET_FS_namespace_list_updateable (fs, ns, next_id, &check_next, NULL);
91 }
92
93
94 static void
95 sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
96 {
97   GNUNET_assert (NULL == emsg);
98   err += 2;
99   GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this_next, NULL);
100 }
101
102
103 static void
104 check_this (void *cls, const char *last_id,
105             const struct GNUNET_FS_Uri *last_uri,
106             const struct GNUNET_CONTAINER_MetaData *last_meta,
107             const char *next_id)
108 {
109   GNUNET_break (0 == strcmp (last_id, "this"));
110   GNUNET_break (0 == strcmp (next_id, "next"));
111   err -= 1;
112 }
113
114
115 static void
116 sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
117 {
118   GNUNET_assert (NULL == emsg);
119   err = 1;
120   GNUNET_FS_namespace_list_updateable (fs, ns, NULL, &check_this, NULL);
121   GNUNET_FS_publish_sks (fs, ns, "next", "future", meta, uri_next, &bo,
122                          GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_next, NULL);
123
124 }
125
126
127 static void
128 testNamespace ()
129 {
130   ns = GNUNET_CRYPTO_ecdsa_key_create ();
131   GNUNET_assert (NULL != ns);
132   bo.content_priority = 1;
133   bo.anonymity_level = 1;
134   bo.replication_level = 0;
135   bo.expiration_time =
136       GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
137   meta = GNUNET_CONTAINER_meta_data_create ();
138
139   uri_this =
140       GNUNET_FS_uri_parse
141       ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
142        NULL);
143   uri_next =
144       GNUNET_FS_uri_parse
145       ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43",
146        NULL);
147   GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri_this, &bo,
148                          GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont_this, NULL);
149 }
150
151
152 static void
153 run (void *cls,
154      const struct GNUNET_CONFIGURATION_Handle *cfg,
155      struct GNUNET_TESTING_Peer *peer)
156 {
157   fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
158                         GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
159   testNamespace ();
160 }
161
162
163 int
164 main (int argc, char *argv[])
165 {
166   if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable",
167                                     "test_fs_namespace_data.conf",
168                                     &run, NULL))
169     return 1;
170   do_shutdown ();
171   return err;
172 }
173
174
175 /* end of test_fs_namespace_list_updateable.c */