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