diff options
Diffstat (limited to 'src/fs/fs_publish_ksk.c')
-rw-r--r-- | src/fs/fs_publish_ksk.c | 255 |
1 files changed, 0 insertions, 255 deletions
diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c deleted file mode 100644 index 3981ad335..000000000 --- a/src/fs/fs_publish_ksk.c +++ /dev/null | |||
@@ -1,255 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2012, 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/fs_publish_ksk.c | ||
23 | * @brief publish a URI under a keyword in GNUnet | ||
24 | * @see https://gnunet.org/encoding and #2564 | ||
25 | * @author Krista Bennett | ||
26 | * @author Christian Grothoff | ||
27 | */ | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_constants.h" | ||
31 | #include "gnunet_signatures.h" | ||
32 | #include "gnunet_util_lib.h" | ||
33 | |||
34 | #include "gnunet_fs_service.h" | ||
35 | #include "fs_api.h" | ||
36 | #include "fs_tree.h" | ||
37 | #include "fs_publish_ublock.h" | ||
38 | |||
39 | /** | ||
40 | * Context for the KSK publication. | ||
41 | */ | ||
42 | struct GNUNET_FS_PublishKskContext | ||
43 | { | ||
44 | /** | ||
45 | * Keywords to use. | ||
46 | */ | ||
47 | struct GNUNET_FS_Uri *ksk_uri; | ||
48 | |||
49 | /** | ||
50 | * URI to publish. | ||
51 | */ | ||
52 | struct GNUNET_FS_Uri *uri; | ||
53 | |||
54 | /** | ||
55 | * Metadata to use. | ||
56 | */ | ||
57 | struct GNUNET_FS_MetaData *meta; | ||
58 | |||
59 | /** | ||
60 | * Global FS context. | ||
61 | */ | ||
62 | struct GNUNET_FS_Handle *h; | ||
63 | |||
64 | /** | ||
65 | * UBlock publishing operation that is active. | ||
66 | */ | ||
67 | struct GNUNET_FS_PublishUblockContext *uc; | ||
68 | |||
69 | /** | ||
70 | * Handle to the datastore, NULL if we are just simulating. | ||
71 | */ | ||
72 | struct GNUNET_DATASTORE_Handle *dsh; | ||
73 | |||
74 | /** | ||
75 | * Current task. | ||
76 | */ | ||
77 | struct GNUNET_SCHEDULER_Task *ksk_task; | ||
78 | |||
79 | /** | ||
80 | * Function to call once we're done. | ||
81 | */ | ||
82 | GNUNET_FS_PublishContinuation cont; | ||
83 | |||
84 | /** | ||
85 | * Closure for cont. | ||
86 | */ | ||
87 | void *cont_cls; | ||
88 | |||
89 | /** | ||
90 | * When should the KBlocks expire? | ||
91 | */ | ||
92 | struct GNUNET_FS_BlockOptions bo; | ||
93 | |||
94 | /** | ||
95 | * Options to use. | ||
96 | */ | ||
97 | enum GNUNET_FS_PublishOptions options; | ||
98 | |||
99 | /** | ||
100 | * Keyword that we are currently processing. | ||
101 | */ | ||
102 | unsigned int i; | ||
103 | }; | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Continuation of #GNUNET_FS_publish_ksk() that performs | ||
108 | * the actual publishing operation (iterating over all | ||
109 | * of the keywords). | ||
110 | * | ||
111 | * @param cls closure of type `struct PublishKskContext *` | ||
112 | */ | ||
113 | static void | ||
114 | publish_ksk_cont (void *cls); | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Function called by the datastore API with | ||
119 | * the result from the PUT request. | ||
120 | * | ||
121 | * @param cls closure of type `struct GNUNET_FS_PublishKskContext *` | ||
122 | * @param msg error message (or NULL) | ||
123 | */ | ||
124 | static void | ||
125 | kb_put_cont (void *cls, | ||
126 | const char *msg) | ||
127 | { | ||
128 | struct GNUNET_FS_PublishKskContext *pkc = cls; | ||
129 | |||
130 | pkc->uc = NULL; | ||
131 | if (NULL != msg) | ||
132 | { | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "KBlock PUT operation failed: %s\n", msg); | ||
135 | pkc->cont (pkc->cont_cls, NULL, msg); | ||
136 | GNUNET_FS_publish_ksk_cancel (pkc); | ||
137 | return; | ||
138 | } | ||
139 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); | ||
140 | } | ||
141 | |||
142 | |||
143 | static void | ||
144 | publish_ksk_cont (void *cls) | ||
145 | { | ||
146 | struct GNUNET_FS_PublishKskContext *pkc = cls; | ||
147 | const char *keyword; | ||
148 | |||
149 | pkc->ksk_task = NULL; | ||
150 | if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || | ||
151 | (NULL == pkc->dsh)) | ||
152 | { | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
154 | "KSK PUT operation complete\n"); | ||
155 | pkc->cont (pkc->cont_cls, pkc->ksk_uri, | ||
156 | NULL); | ||
157 | GNUNET_FS_publish_ksk_cancel (pkc); | ||
158 | return; | ||
159 | } | ||
160 | keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; | ||
161 | pkc->uc = GNUNET_FS_publish_ublock_ (pkc->h, | ||
162 | pkc->dsh, | ||
163 | keyword + 1 /* skip '+' */, | ||
164 | NULL, | ||
165 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (), | ||
166 | pkc->meta, | ||
167 | pkc->uri, | ||
168 | &pkc->bo, | ||
169 | pkc->options, | ||
170 | &kb_put_cont, pkc); | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Publish a CHK under various keywords on GNUnet. | ||
176 | * | ||
177 | * @param h handle to the file sharing subsystem | ||
178 | * @param ksk_uri keywords to use | ||
179 | * @param meta metadata to use | ||
180 | * @param uri URI to refer to in the KBlock | ||
181 | * @param bo per-block options | ||
182 | * @param options publication options | ||
183 | * @param cont continuation | ||
184 | * @param cont_cls closure for cont | ||
185 | * @return NULL on error ('cont' will still be called) | ||
186 | */ | ||
187 | struct GNUNET_FS_PublishKskContext * | ||
188 | GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, | ||
189 | const struct GNUNET_FS_Uri *ksk_uri, | ||
190 | const struct GNUNET_FS_MetaData *meta, | ||
191 | const struct GNUNET_FS_Uri *uri, | ||
192 | const struct GNUNET_FS_BlockOptions *bo, | ||
193 | enum GNUNET_FS_PublishOptions options, | ||
194 | GNUNET_FS_PublishContinuation cont, void *cont_cls) | ||
195 | { | ||
196 | struct GNUNET_FS_PublishKskContext *pkc; | ||
197 | |||
198 | GNUNET_assert (NULL != uri); | ||
199 | pkc = GNUNET_new (struct GNUNET_FS_PublishKskContext); | ||
200 | pkc->h = h; | ||
201 | pkc->bo = *bo; | ||
202 | pkc->options = options; | ||
203 | pkc->cont = cont; | ||
204 | pkc->cont_cls = cont_cls; | ||
205 | pkc->meta = GNUNET_FS_meta_data_duplicate (meta); | ||
206 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | ||
207 | { | ||
208 | pkc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
209 | if (NULL == pkc->dsh) | ||
210 | { | ||
211 | cont (cont_cls, | ||
212 | NULL, | ||
213 | _ ("Could not connect to datastore.")); | ||
214 | GNUNET_free (pkc); | ||
215 | return NULL; | ||
216 | } | ||
217 | } | ||
218 | pkc->uri = GNUNET_FS_uri_dup (uri); | ||
219 | pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); | ||
220 | pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); | ||
221 | return pkc; | ||
222 | } | ||
223 | |||
224 | |||
225 | /** | ||
226 | * Abort the KSK publishing operation. | ||
227 | * | ||
228 | * @param pkc context of the operation to abort. | ||
229 | */ | ||
230 | void | ||
231 | GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc) | ||
232 | { | ||
233 | if (NULL != pkc->ksk_task) | ||
234 | { | ||
235 | GNUNET_SCHEDULER_cancel (pkc->ksk_task); | ||
236 | pkc->ksk_task = NULL; | ||
237 | } | ||
238 | if (NULL != pkc->uc) | ||
239 | { | ||
240 | GNUNET_FS_publish_ublock_cancel_ (pkc->uc); | ||
241 | pkc->uc = NULL; | ||
242 | } | ||
243 | if (NULL != pkc->dsh) | ||
244 | { | ||
245 | GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); | ||
246 | pkc->dsh = NULL; | ||
247 | } | ||
248 | GNUNET_FS_meta_data_destroy (pkc->meta); | ||
249 | GNUNET_FS_uri_destroy (pkc->ksk_uri); | ||
250 | GNUNET_FS_uri_destroy (pkc->uri); | ||
251 | GNUNET_free (pkc); | ||
252 | } | ||
253 | |||
254 | |||
255 | /* end of fs_publish_ksk.c */ | ||