diff options
Diffstat (limited to 'src/fs/fs_namespace.c')
-rw-r--r-- | src/fs/fs_namespace.c | 663 |
1 files changed, 328 insertions, 335 deletions
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 11a137a09..b740eb2ba 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file fs/fs_namespace.c | 22 | * @file fs/fs_namespace.c |
@@ -37,8 +37,7 @@ | |||
37 | * Information about an (updateable) node in the | 37 | * Information about an (updateable) node in the |
38 | * namespace. | 38 | * namespace. |
39 | */ | 39 | */ |
40 | struct NamespaceUpdateNode | 40 | struct NamespaceUpdateNode { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Identifier for this node. | 42 | * Identifier for this node. |
44 | */ | 43 | */ |
@@ -75,9 +74,7 @@ struct NamespaceUpdateNode | |||
75 | /** | 74 | /** |
76 | * Handle to update information for a namespace. | 75 | * Handle to update information for a namespace. |
77 | */ | 76 | */ |
78 | struct GNUNET_FS_UpdateInformationGraph | 77 | struct GNUNET_FS_UpdateInformationGraph { |
79 | { | ||
80 | |||
81 | /** | 78 | /** |
82 | * Handle to the FS service context. | 79 | * Handle to the FS service context. |
83 | */ | 80 | */ |
@@ -125,7 +122,7 @@ struct GNUNET_FS_UpdateInformationGraph | |||
125 | * @return NULL on error, otherwise the name of the directory | 122 | * @return NULL on error, otherwise the name of the directory |
126 | */ | 123 | */ |
127 | static char * | 124 | static char * |
128 | get_update_information_directory ( | 125 | get_update_information_directory( |
129 | struct GNUNET_FS_Handle *h, | 126 | struct GNUNET_FS_Handle *h, |
130 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 127 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
131 | { | 128 | { |
@@ -136,20 +133,20 @@ get_update_information_directory ( | |||
136 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 133 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
137 | 134 | ||
138 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
139 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) | 136 | GNUNET_CONFIGURATION_get_value_filename(h->cfg, "FS", "UPDATE_DIR", &dn)) |
140 | { | 137 | { |
141 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); | 138 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); |
142 | return NULL; | 139 | return NULL; |
143 | } | 140 | } |
144 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); | 141 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &pub); |
145 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); | 142 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &hc); |
146 | GNUNET_CRYPTO_hash_to_enc (&hc, &enc); | 143 | GNUNET_CRYPTO_hash_to_enc(&hc, &enc); |
147 | GNUNET_asprintf (&ret, | 144 | GNUNET_asprintf(&ret, |
148 | "%s%s%s", | 145 | "%s%s%s", |
149 | dn, | 146 | dn, |
150 | DIR_SEPARATOR_STR, | 147 | DIR_SEPARATOR_STR, |
151 | (const char *) enc.encoding); | 148 | (const char *)enc.encoding); |
152 | GNUNET_free (dn); | 149 | GNUNET_free(dn); |
153 | return ret; | 150 | return ret; |
154 | } | 151 | } |
155 | 152 | ||
@@ -160,24 +157,24 @@ get_update_information_directory ( | |||
160 | * @param uig data structure to free | 157 | * @param uig data structure to free |
161 | */ | 158 | */ |
162 | static void | 159 | static void |
163 | free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | 160 | free_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) |
164 | { | 161 | { |
165 | unsigned int i; | 162 | unsigned int i; |
166 | struct NamespaceUpdateNode *nsn; | 163 | struct NamespaceUpdateNode *nsn; |
167 | 164 | ||
168 | for (i = 0; i < uig->update_node_count; i++) | 165 | for (i = 0; i < uig->update_node_count; i++) |
169 | { | 166 | { |
170 | nsn = uig->update_nodes[i]; | 167 | nsn = uig->update_nodes[i]; |
171 | GNUNET_CONTAINER_meta_data_destroy (nsn->md); | 168 | GNUNET_CONTAINER_meta_data_destroy(nsn->md); |
172 | GNUNET_FS_uri_destroy (nsn->uri); | 169 | GNUNET_FS_uri_destroy(nsn->uri); |
173 | GNUNET_free (nsn->id); | 170 | GNUNET_free(nsn->id); |
174 | GNUNET_free (nsn->update); | 171 | GNUNET_free(nsn->update); |
175 | GNUNET_free (nsn); | 172 | GNUNET_free(nsn); |
176 | } | 173 | } |
177 | GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); | 174 | GNUNET_array_grow(uig->update_nodes, uig->update_node_count, 0); |
178 | if (NULL != uig->update_map) | 175 | if (NULL != uig->update_map) |
179 | GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); | 176 | GNUNET_CONTAINER_multihashmap_destroy(uig->update_map); |
180 | GNUNET_free (uig); | 177 | GNUNET_free(uig); |
181 | } | 178 | } |
182 | 179 | ||
183 | 180 | ||
@@ -187,7 +184,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
187 | * @param uig update information graph to dump | 184 | * @param uig update information graph to dump |
188 | */ | 185 | */ |
189 | static void | 186 | static void |
190 | write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | 187 | write_update_information_graph(struct GNUNET_FS_UpdateInformationGraph *uig) |
191 | { | 188 | { |
192 | char *fn; | 189 | char *fn; |
193 | struct GNUNET_BIO_WriteHandle *wh; | 190 | struct GNUNET_BIO_WriteHandle *wh; |
@@ -195,40 +192,40 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
195 | struct NamespaceUpdateNode *n; | 192 | struct NamespaceUpdateNode *n; |
196 | char *uris; | 193 | char *uris; |
197 | 194 | ||
198 | fn = get_update_information_directory (uig->h, &uig->ns); | 195 | fn = get_update_information_directory(uig->h, &uig->ns); |
199 | wh = GNUNET_BIO_write_open (fn); | 196 | wh = GNUNET_BIO_write_open(fn); |
200 | if (NULL == wh) | 197 | if (NULL == wh) |
201 | { | 198 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 199 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
203 | _ ("Failed to open `%s' for writing: %s\n"), | 200 | _("Failed to open `%s' for writing: %s\n"), |
204 | fn, | 201 | fn, |
205 | strerror (errno)); | 202 | strerror(errno)); |
206 | GNUNET_free (fn); | 203 | GNUNET_free(fn); |
207 | return; | 204 | return; |
208 | } | 205 | } |
209 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count)) | 206 | if (GNUNET_OK != GNUNET_BIO_write_int32(wh, uig->update_node_count)) |
210 | goto END; | 207 | goto END; |
211 | for (i = 0; i < uig->update_node_count; i++) | 208 | for (i = 0; i < uig->update_node_count; i++) |
212 | { | ||
213 | n = uig->update_nodes[i]; | ||
214 | uris = GNUNET_FS_uri_to_string (n->uri); | ||
215 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) || | ||
216 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) || | ||
217 | (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) || | ||
218 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) | ||
219 | { | 209 | { |
220 | GNUNET_free (uris); | 210 | n = uig->update_nodes[i]; |
221 | break; | 211 | uris = GNUNET_FS_uri_to_string(n->uri); |
212 | if ((GNUNET_OK != GNUNET_BIO_write_string(wh, n->id)) || | ||
213 | (GNUNET_OK != GNUNET_BIO_write_meta_data(wh, n->md)) || | ||
214 | (GNUNET_OK != GNUNET_BIO_write_string(wh, n->update)) || | ||
215 | (GNUNET_OK != GNUNET_BIO_write_string(wh, uris))) | ||
216 | { | ||
217 | GNUNET_free(uris); | ||
218 | break; | ||
219 | } | ||
220 | GNUNET_free(uris); | ||
222 | } | 221 | } |
223 | GNUNET_free (uris); | ||
224 | } | ||
225 | END: | 222 | END: |
226 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 223 | if (GNUNET_OK != GNUNET_BIO_write_close(wh)) |
227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
228 | _ ("Failed to write `%s': %s\n"), | 225 | _("Failed to write `%s': %s\n"), |
229 | fn, | 226 | fn, |
230 | strerror (errno)); | 227 | strerror(errno)); |
231 | GNUNET_free (fn); | 228 | GNUNET_free(fn); |
232 | } | 229 | } |
233 | 230 | ||
234 | 231 | ||
@@ -240,8 +237,8 @@ END: | |||
240 | * @return update graph, never NULL | 237 | * @return update graph, never NULL |
241 | */ | 238 | */ |
242 | static struct GNUNET_FS_UpdateInformationGraph * | 239 | static struct GNUNET_FS_UpdateInformationGraph * |
243 | read_update_information_graph (struct GNUNET_FS_Handle *h, | 240 | read_update_information_graph(struct GNUNET_FS_Handle *h, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
245 | { | 242 | { |
246 | struct GNUNET_FS_UpdateInformationGraph *uig; | 243 | struct GNUNET_FS_UpdateInformationGraph *uig; |
247 | char *fn; | 244 | char *fn; |
@@ -252,79 +249,79 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
252 | uint32_t count; | 249 | uint32_t count; |
253 | char *emsg; | 250 | char *emsg; |
254 | 251 | ||
255 | uig = GNUNET_new (struct GNUNET_FS_UpdateInformationGraph); | 252 | uig = GNUNET_new(struct GNUNET_FS_UpdateInformationGraph); |
256 | uig->h = h; | 253 | uig->h = h; |
257 | uig->ns = *ns; | 254 | uig->ns = *ns; |
258 | fn = get_update_information_directory (h, ns); | 255 | fn = get_update_information_directory(h, ns); |
259 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) | 256 | if (GNUNET_YES != GNUNET_DISK_file_test(fn)) |
260 | { | 257 | { |
261 | GNUNET_free (fn); | 258 | GNUNET_free(fn); |
262 | return uig; | 259 | return uig; |
263 | } | 260 | } |
264 | rh = GNUNET_BIO_read_open (fn); | 261 | rh = GNUNET_BIO_read_open(fn); |
265 | if (NULL == rh) | 262 | if (NULL == rh) |
266 | { | 263 | { |
267 | GNUNET_free (fn); | 264 | GNUNET_free(fn); |
268 | return uig; | 265 | return uig; |
269 | } | 266 | } |
270 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count)) | 267 | if (GNUNET_OK != GNUNET_BIO_read_int32(rh, &count)) |
271 | { | 268 | { |
272 | GNUNET_break (0); | 269 | GNUNET_break(0); |
273 | goto END; | 270 | goto END; |
274 | } | 271 | } |
275 | if (count > 1024 * 1024) | 272 | if (count > 1024 * 1024) |
276 | { | 273 | { |
277 | GNUNET_break (0); | 274 | GNUNET_break(0); |
278 | goto END; | 275 | goto END; |
279 | } | 276 | } |
280 | if (0 == count) | 277 | if (0 == count) |
281 | goto END; | 278 | goto END; |
282 | uig->update_nodes = | 279 | uig->update_nodes = |
283 | GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *)); | 280 | GNUNET_malloc(count * sizeof(struct NamespaceUpdateNode *)); |
284 | 281 | ||
285 | for (i = 0; i < count; i++) | 282 | for (i = 0; i < count; i++) |
286 | { | ||
287 | n = GNUNET_new (struct NamespaceUpdateNode); | ||
288 | if ((GNUNET_OK != | ||
289 | GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || | ||
290 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | ||
291 | (GNUNET_OK != | ||
292 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || | ||
293 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) | ||
294 | { | 283 | { |
295 | GNUNET_break (0); | 284 | n = GNUNET_new(struct NamespaceUpdateNode); |
296 | GNUNET_free_non_null (n->id); | 285 | if ((GNUNET_OK != |
297 | GNUNET_free_non_null (n->update); | 286 | GNUNET_BIO_read_string(rh, "identifier", &n->id, 1024)) || |
298 | if (n->md != NULL) | 287 | (GNUNET_OK != GNUNET_BIO_read_meta_data(rh, "meta", &n->md)) || |
299 | GNUNET_CONTAINER_meta_data_destroy (n->md); | 288 | (GNUNET_OK != |
300 | GNUNET_free (n); | 289 | GNUNET_BIO_read_string(rh, "update-id", &n->update, 1024)) || |
301 | break; | 290 | (GNUNET_OK != GNUNET_BIO_read_string(rh, "uri", &uris, 1024 * 2))) |
302 | } | 291 | { |
303 | n->uri = GNUNET_FS_uri_parse (uris, &emsg); | 292 | GNUNET_break(0); |
304 | GNUNET_free (uris); | 293 | GNUNET_free_non_null(n->id); |
305 | if (n->uri == NULL) | 294 | GNUNET_free_non_null(n->update); |
306 | { | 295 | if (n->md != NULL) |
307 | GNUNET_break (0); | 296 | GNUNET_CONTAINER_meta_data_destroy(n->md); |
308 | GNUNET_free (emsg); | 297 | GNUNET_free(n); |
309 | GNUNET_free (n->id); | 298 | break; |
310 | GNUNET_free_non_null (n->update); | 299 | } |
311 | GNUNET_CONTAINER_meta_data_destroy (n->md); | 300 | n->uri = GNUNET_FS_uri_parse(uris, &emsg); |
312 | GNUNET_free (n); | 301 | GNUNET_free(uris); |
313 | break; | 302 | if (n->uri == NULL) |
303 | { | ||
304 | GNUNET_break(0); | ||
305 | GNUNET_free(emsg); | ||
306 | GNUNET_free(n->id); | ||
307 | GNUNET_free_non_null(n->update); | ||
308 | GNUNET_CONTAINER_meta_data_destroy(n->md); | ||
309 | GNUNET_free(n); | ||
310 | break; | ||
311 | } | ||
312 | uig->update_nodes[i] = n; | ||
314 | } | 313 | } |
315 | uig->update_nodes[i] = n; | ||
316 | } | ||
317 | uig->update_node_count = i; | 314 | uig->update_node_count = i; |
318 | END: | 315 | END: |
319 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 316 | if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg)) |
320 | { | 317 | { |
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 318 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
322 | _ ("Failed to read `%s': %s\n"), | 319 | _("Failed to read `%s': %s\n"), |
323 | fn, | 320 | fn, |
324 | emsg); | 321 | emsg); |
325 | GNUNET_free (emsg); | 322 | GNUNET_free(emsg); |
326 | } | 323 | } |
327 | GNUNET_free (fn); | 324 | GNUNET_free(fn); |
328 | return uig; | 325 | return uig; |
329 | } | 326 | } |
330 | 327 | ||
@@ -332,9 +329,7 @@ END: | |||
332 | /** | 329 | /** |
333 | * Context for the SKS publication. | 330 | * Context for the SKS publication. |
334 | */ | 331 | */ |
335 | struct GNUNET_FS_PublishSksContext | 332 | struct GNUNET_FS_PublishSksContext { |
336 | { | ||
337 | |||
338 | /** | 333 | /** |
339 | * URI of the new entry in the namespace. | 334 | * URI of the new entry in the namespace. |
340 | */ | 335 | */ |
@@ -386,33 +381,33 @@ struct GNUNET_FS_PublishSksContext | |||
386 | * @param msg error message (or NULL) | 381 | * @param msg error message (or NULL) |
387 | */ | 382 | */ |
388 | static void | 383 | static void |
389 | sks_publish_cont (void *cls, const char *msg) | 384 | sks_publish_cont(void *cls, const char *msg) |
390 | { | 385 | { |
391 | struct GNUNET_FS_PublishSksContext *psc = cls; | 386 | struct GNUNET_FS_PublishSksContext *psc = cls; |
392 | struct GNUNET_FS_UpdateInformationGraph *uig; | 387 | struct GNUNET_FS_UpdateInformationGraph *uig; |
393 | 388 | ||
394 | psc->uc = NULL; | 389 | psc->uc = NULL; |
395 | if (NULL != msg) | 390 | if (NULL != msg) |
396 | { | 391 | { |
397 | if (NULL != psc->cont) | 392 | if (NULL != psc->cont) |
398 | psc->cont (psc->cont_cls, NULL, msg); | 393 | psc->cont(psc->cont_cls, NULL, msg); |
399 | GNUNET_FS_publish_sks_cancel (psc); | 394 | GNUNET_FS_publish_sks_cancel(psc); |
400 | return; | 395 | return; |
401 | } | 396 | } |
402 | if (NULL != psc->nsn) | 397 | if (NULL != psc->nsn) |
403 | { | 398 | { |
404 | /* FIXME: this can be done much more | 399 | /* FIXME: this can be done much more |
405 | * efficiently by simply appending to the | 400 | * efficiently by simply appending to the |
406 | * file and overwriting the 4-byte header */ | 401 | * file and overwriting the 4-byte header */ |
407 | uig = read_update_information_graph (psc->h, &psc->ns); | 402 | uig = read_update_information_graph(psc->h, &psc->ns); |
408 | GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); | 403 | GNUNET_array_append(uig->update_nodes, uig->update_node_count, psc->nsn); |
409 | psc->nsn = NULL; | 404 | psc->nsn = NULL; |
410 | write_update_information_graph (uig); | 405 | write_update_information_graph(uig); |
411 | free_update_information_graph (uig); | 406 | free_update_information_graph(uig); |
412 | } | 407 | } |
413 | if (NULL != psc->cont) | 408 | if (NULL != psc->cont) |
414 | psc->cont (psc->cont_cls, psc->uri, NULL); | 409 | psc->cont(psc->cont_cls, psc->uri, NULL); |
415 | GNUNET_FS_publish_sks_cancel (psc); | 410 | GNUNET_FS_publish_sks_cancel(psc); |
416 | } | 411 | } |
417 | 412 | ||
418 | 413 | ||
@@ -432,59 +427,59 @@ sks_publish_cont (void *cls, const char *msg) | |||
432 | * @return NULL on error ('cont' will still be called) | 427 | * @return NULL on error ('cont' will still be called) |
433 | */ | 428 | */ |
434 | struct GNUNET_FS_PublishSksContext * | 429 | struct GNUNET_FS_PublishSksContext * |
435 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | 430 | GNUNET_FS_publish_sks(struct GNUNET_FS_Handle *h, |
436 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 431 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
437 | const char *identifier, | 432 | const char *identifier, |
438 | const char *update, | 433 | const char *update, |
439 | const struct GNUNET_CONTAINER_MetaData *meta, | 434 | const struct GNUNET_CONTAINER_MetaData *meta, |
440 | const struct GNUNET_FS_Uri *uri, | 435 | const struct GNUNET_FS_Uri *uri, |
441 | const struct GNUNET_FS_BlockOptions *bo, | 436 | const struct GNUNET_FS_BlockOptions *bo, |
442 | enum GNUNET_FS_PublishOptions options, | 437 | enum GNUNET_FS_PublishOptions options, |
443 | GNUNET_FS_PublishContinuation cont, | 438 | GNUNET_FS_PublishContinuation cont, |
444 | void *cont_cls) | 439 | void *cont_cls) |
445 | { | 440 | { |
446 | struct GNUNET_FS_PublishSksContext *psc; | 441 | struct GNUNET_FS_PublishSksContext *psc; |
447 | struct GNUNET_FS_Uri *sks_uri; | 442 | struct GNUNET_FS_Uri *sks_uri; |
448 | 443 | ||
449 | sks_uri = GNUNET_new (struct GNUNET_FS_Uri); | 444 | sks_uri = GNUNET_new(struct GNUNET_FS_Uri); |
450 | sks_uri->type = GNUNET_FS_URI_SKS; | 445 | sks_uri->type = GNUNET_FS_URI_SKS; |
451 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); | 446 | sks_uri->data.sks.identifier = GNUNET_strdup(identifier); |
452 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); | 447 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, &sks_uri->data.sks.ns); |
453 | 448 | ||
454 | psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); | 449 | psc = GNUNET_new(struct GNUNET_FS_PublishSksContext); |
455 | psc->h = h; | 450 | psc->h = h; |
456 | psc->uri = sks_uri; | 451 | psc->uri = sks_uri; |
457 | psc->cont = cont; | 452 | psc->cont = cont; |
458 | psc->cont_cls = cont_cls; | 453 | psc->cont_cls = cont_cls; |
459 | psc->ns = *ns; | 454 | psc->ns = *ns; |
460 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 455 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
461 | { | ||
462 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg); | ||
463 | if (NULL == psc->dsh) | ||
464 | { | 456 | { |
465 | sks_publish_cont (psc, _ ("Failed to connect to datastore.")); | 457 | psc->dsh = GNUNET_DATASTORE_connect(h->cfg); |
466 | return NULL; | 458 | if (NULL == psc->dsh) |
459 | { | ||
460 | sks_publish_cont(psc, _("Failed to connect to datastore.")); | ||
461 | return NULL; | ||
462 | } | ||
467 | } | 463 | } |
468 | } | ||
469 | if (NULL != update) | 464 | if (NULL != update) |
470 | { | 465 | { |
471 | psc->nsn = GNUNET_new (struct NamespaceUpdateNode); | 466 | psc->nsn = GNUNET_new(struct NamespaceUpdateNode); |
472 | psc->nsn->id = GNUNET_strdup (identifier); | 467 | psc->nsn->id = GNUNET_strdup(identifier); |
473 | psc->nsn->update = GNUNET_strdup (update); | 468 | psc->nsn->update = GNUNET_strdup(update); |
474 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); | 469 | psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate(meta); |
475 | psc->nsn->uri = GNUNET_FS_uri_dup (uri); | 470 | psc->nsn->uri = GNUNET_FS_uri_dup(uri); |
476 | } | 471 | } |
477 | psc->uc = GNUNET_FS_publish_ublock_ (h, | 472 | psc->uc = GNUNET_FS_publish_ublock_(h, |
478 | psc->dsh, | 473 | psc->dsh, |
479 | identifier, | 474 | identifier, |
480 | update, | 475 | update, |
481 | ns, | 476 | ns, |
482 | meta, | 477 | meta, |
483 | uri, | 478 | uri, |
484 | bo, | 479 | bo, |
485 | options, | 480 | options, |
486 | &sks_publish_cont, | 481 | &sks_publish_cont, |
487 | psc); | 482 | psc); |
488 | return psc; | 483 | return psc; |
489 | } | 484 | } |
490 | 485 | ||
@@ -495,36 +490,35 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | |||
495 | * @param psc context of the operation to abort. | 490 | * @param psc context of the operation to abort. |
496 | */ | 491 | */ |
497 | void | 492 | void |
498 | GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc) | 493 | GNUNET_FS_publish_sks_cancel(struct GNUNET_FS_PublishSksContext *psc) |
499 | { | 494 | { |
500 | if (NULL != psc->uc) | 495 | if (NULL != psc->uc) |
501 | { | 496 | { |
502 | GNUNET_FS_publish_ublock_cancel_ (psc->uc); | 497 | GNUNET_FS_publish_ublock_cancel_(psc->uc); |
503 | psc->uc = NULL; | 498 | psc->uc = NULL; |
504 | } | 499 | } |
505 | if (NULL != psc->dsh) | 500 | if (NULL != psc->dsh) |
506 | { | 501 | { |
507 | GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); | 502 | GNUNET_DATASTORE_disconnect(psc->dsh, GNUNET_NO); |
508 | psc->dsh = NULL; | 503 | psc->dsh = NULL; |
509 | } | 504 | } |
510 | GNUNET_FS_uri_destroy (psc->uri); | 505 | GNUNET_FS_uri_destroy(psc->uri); |
511 | if (NULL != psc->nsn) | 506 | if (NULL != psc->nsn) |
512 | { | 507 | { |
513 | GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); | 508 | GNUNET_CONTAINER_meta_data_destroy(psc->nsn->md); |
514 | GNUNET_FS_uri_destroy (psc->nsn->uri); | 509 | GNUNET_FS_uri_destroy(psc->nsn->uri); |
515 | GNUNET_free (psc->nsn->id); | 510 | GNUNET_free(psc->nsn->id); |
516 | GNUNET_free (psc->nsn->update); | 511 | GNUNET_free(psc->nsn->update); |
517 | GNUNET_free (psc->nsn); | 512 | GNUNET_free(psc->nsn); |
518 | } | 513 | } |
519 | GNUNET_free (psc); | 514 | GNUNET_free(psc); |
520 | } | 515 | } |
521 | 516 | ||
522 | 517 | ||
523 | /** | 518 | /** |
524 | * Closure for 'process_update_node'. | 519 | * Closure for 'process_update_node'. |
525 | */ | 520 | */ |
526 | struct ProcessUpdateClosure | 521 | struct ProcessUpdateClosure { |
527 | { | ||
528 | /** | 522 | /** |
529 | * Function to call for each node. | 523 | * Function to call for each node. |
530 | */ | 524 | */ |
@@ -548,12 +542,12 @@ struct ProcessUpdateClosure | |||
548 | * GNUNET_NO if not. | 542 | * GNUNET_NO if not. |
549 | */ | 543 | */ |
550 | static int | 544 | static int |
551 | process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) | 545 | process_update_node(void *cls, const struct GNUNET_HashCode *key, void *value) |
552 | { | 546 | { |
553 | struct ProcessUpdateClosure *pc = cls; | 547 | struct ProcessUpdateClosure *pc = cls; |
554 | struct NamespaceUpdateNode *nsn = value; | 548 | struct NamespaceUpdateNode *nsn = value; |
555 | 549 | ||
556 | pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 550 | pc->ip(pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
557 | return GNUNET_YES; | 551 | return GNUNET_YES; |
558 | } | 552 | } |
559 | 553 | ||
@@ -561,8 +555,7 @@ process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
561 | /** | 555 | /** |
562 | * Closure for 'find_trees'. | 556 | * Closure for 'find_trees'. |
563 | */ | 557 | */ |
564 | struct FindTreeClosure | 558 | struct FindTreeClosure { |
565 | { | ||
566 | /** | 559 | /** |
567 | * UIG we are operating on. | 560 | * UIG we are operating on. |
568 | */ | 561 | */ |
@@ -611,38 +604,38 @@ struct FindTreeClosure | |||
611 | * GNUNET_NO if not. | 604 | * GNUNET_NO if not. |
612 | */ | 605 | */ |
613 | static int | 606 | static int |
614 | find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) | 607 | find_trees(void *cls, const struct GNUNET_HashCode *key, void *value) |
615 | { | 608 | { |
616 | struct FindTreeClosure *fc = cls; | 609 | struct FindTreeClosure *fc = cls; |
617 | struct NamespaceUpdateNode *nsn = value; | 610 | struct NamespaceUpdateNode *nsn = value; |
618 | struct GNUNET_HashCode hc; | 611 | struct GNUNET_HashCode hc; |
619 | 612 | ||
620 | if (nsn->nug == fc->nug) | 613 | if (nsn->nug == fc->nug) |
621 | { | 614 | { |
622 | if (UINT_MAX == nsn->tree_id) | 615 | if (UINT_MAX == nsn->tree_id) |
623 | return GNUNET_YES; /* circular */ | 616 | return GNUNET_YES; /* circular */ |
624 | GNUNET_assert (nsn->tree_id < fc->tree_array_size); | 617 | GNUNET_assert(nsn->tree_id < fc->tree_array_size); |
625 | if (fc->tree_array[nsn->tree_id] != nsn) | 618 | if (fc->tree_array[nsn->tree_id] != nsn) |
626 | return GNUNET_YES; /* part of "another" (directed) TREE, | 619 | return GNUNET_YES; /* part of "another" (directed) TREE, |
627 | * and not root of it, end trace */ | 620 | * and not root of it, end trace */ |
628 | if (nsn->tree_id == fc->id) | 621 | if (nsn->tree_id == fc->id) |
629 | return GNUNET_YES; /* that's our own root (can this be?) */ | 622 | return GNUNET_YES; /* that's our own root (can this be?) */ |
630 | /* merge existing TREE, we have a root for both */ | 623 | /* merge existing TREE, we have a root for both */ |
631 | fc->tree_array[nsn->tree_id] = NULL; | 624 | fc->tree_array[nsn->tree_id] = NULL; |
632 | if (UINT_MAX == fc->id) | 625 | if (UINT_MAX == fc->id) |
633 | fc->id = nsn->tree_id; /* take over ID */ | 626 | fc->id = nsn->tree_id; /* take over ID */ |
634 | } | 627 | } |
635 | else | 628 | else |
636 | { | 629 | { |
637 | nsn->nug = fc->nug; | 630 | nsn->nug = fc->nug; |
638 | nsn->tree_id = UINT_MAX; /* mark as undef */ | 631 | nsn->tree_id = UINT_MAX; /* mark as undef */ |
639 | /* trace */ | 632 | /* trace */ |
640 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | 633 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); |
641 | GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, | 634 | GNUNET_CONTAINER_multihashmap_get_multiple(fc->uig->update_map, |
642 | &hc, | 635 | &hc, |
643 | &find_trees, | 636 | &find_trees, |
644 | fc); | 637 | fc); |
645 | } | 638 | } |
646 | return GNUNET_YES; | 639 | return GNUNET_YES; |
647 | } | 640 | } |
648 | 641 | ||
@@ -671,7 +664,7 @@ find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
671 | * @param ip_cls closure for ip | 664 | * @param ip_cls closure for ip |
672 | */ | 665 | */ |
673 | void | 666 | void |
674 | GNUNET_FS_namespace_list_updateable ( | 667 | GNUNET_FS_namespace_list_updateable( |
675 | struct GNUNET_FS_Handle *h, | 668 | struct GNUNET_FS_Handle *h, |
676 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 669 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
677 | const char *next_id, | 670 | const char *next_id, |
@@ -686,125 +679,125 @@ GNUNET_FS_namespace_list_updateable ( | |||
686 | struct FindTreeClosure fc; | 679 | struct FindTreeClosure fc; |
687 | struct GNUNET_FS_UpdateInformationGraph *uig; | 680 | struct GNUNET_FS_UpdateInformationGraph *uig; |
688 | 681 | ||
689 | uig = read_update_information_graph (h, ns); | 682 | uig = read_update_information_graph(h, ns); |
690 | if (NULL == uig->update_nodes) | 683 | if (NULL == uig->update_nodes) |
691 | { | 684 | { |
692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 685 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
693 | "No updateable nodes found for ID `%s'\n", | 686 | "No updateable nodes found for ID `%s'\n", |
694 | next_id); | 687 | next_id); |
695 | free_update_information_graph (uig); | 688 | free_update_information_graph(uig); |
696 | return; /* no nodes */ | 689 | return; /* no nodes */ |
697 | } | 690 | } |
698 | uig->update_map = | 691 | uig->update_map = |
699 | GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, | 692 | GNUNET_CONTAINER_multihashmap_create(2 + 3 * uig->update_node_count / 4, |
700 | GNUNET_NO); | 693 | GNUNET_NO); |
701 | for (i = 0; i < uig->update_node_count; i++) | 694 | for (i = 0; i < uig->update_node_count; i++) |
702 | { | 695 | { |
703 | nsn = uig->update_nodes[i]; | 696 | nsn = uig->update_nodes[i]; |
704 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | 697 | GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); |
705 | GNUNET_CONTAINER_multihashmap_put ( | 698 | GNUNET_CONTAINER_multihashmap_put( |
706 | uig->update_map, | 699 | uig->update_map, |
707 | &hc, | 700 | &hc, |
708 | nsn, | 701 | nsn, |
709 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 702 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
710 | } | 703 | } |
711 | if (NULL != next_id) | 704 | if (NULL != next_id) |
712 | { | 705 | { |
713 | GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); | 706 | GNUNET_CRYPTO_hash(next_id, strlen(next_id), &hc); |
714 | pc.ip = ip; | 707 | pc.ip = ip; |
715 | pc.ip_cls = ip_cls; | 708 | pc.ip_cls = ip_cls; |
716 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | 709 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, |
717 | &hc, | 710 | &hc, |
718 | &process_update_node, | 711 | &process_update_node, |
719 | &pc); | 712 | &pc); |
720 | free_update_information_graph (uig); | 713 | free_update_information_graph(uig); |
721 | return; | 714 | return; |
722 | } | 715 | } |
723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
724 | "Calculating TREEs to find roots of update trees\n"); | 717 | "Calculating TREEs to find roots of update trees\n"); |
725 | /* Find heads of TREEs in update graph */ | 718 | /* Find heads of TREEs in update graph */ |
726 | nug = ++uig->nug_gen; | 719 | nug = ++uig->nug_gen; |
727 | fc.tree_array = NULL; | 720 | fc.tree_array = NULL; |
728 | fc.tree_array_size = 0; | 721 | fc.tree_array_size = 0; |
729 | 722 | ||
730 | for (i = 0; i < uig->update_node_count; i++) | 723 | for (i = 0; i < uig->update_node_count; i++) |
731 | { | ||
732 | nsn = uig->update_nodes[i]; | ||
733 | if (nsn->nug == nug) | ||
734 | { | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
736 | "TREE of node `%s' is %u\n", | ||
737 | nsn->id, | ||
738 | nsn->nug); | ||
739 | continue; /* already placed in TREE */ | ||
740 | } | ||
741 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | ||
742 | nsn->nug = nug; | ||
743 | nsn->tree_id = UINT_MAX; | ||
744 | fc.id = UINT_MAX; | ||
745 | fc.nug = nug; | ||
746 | fc.uig = uig; | ||
747 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | ||
748 | &hc, | ||
749 | &find_trees, | ||
750 | &fc); | ||
751 | if (UINT_MAX == fc.id) | ||
752 | { | 724 | { |
753 | /* start new TREE */ | 725 | nsn = uig->update_nodes[i]; |
754 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) | 726 | if (nsn->nug == nug) |
755 | { | ||
756 | if (NULL == fc.tree_array[fc.id]) | ||
757 | { | 727 | { |
758 | fc.tree_array[fc.id] = nsn; | 728 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
759 | nsn->tree_id = fc.id; | 729 | "TREE of node `%s' is %u\n", |
760 | break; | 730 | nsn->id, |
731 | nsn->nug); | ||
732 | continue; /* already placed in TREE */ | ||
761 | } | 733 | } |
762 | } | 734 | GNUNET_CRYPTO_hash(nsn->update, strlen(nsn->update), &hc); |
763 | if (fc.id == fc.tree_array_size) | 735 | nsn->nug = nug; |
764 | { | 736 | nsn->tree_id = UINT_MAX; |
765 | GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn); | 737 | fc.id = UINT_MAX; |
766 | nsn->tree_id = fc.id; | ||
767 | } | ||
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
769 | "Starting new TREE %u with node `%s'\n", | ||
770 | nsn->tree_id, | ||
771 | nsn->id); | ||
772 | /* put all nodes with same identifier into this TREE */ | ||
773 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | ||
774 | fc.id = nsn->tree_id; | ||
775 | fc.nug = nug; | 738 | fc.nug = nug; |
776 | fc.uig = uig; | 739 | fc.uig = uig; |
777 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, | 740 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, |
778 | &hc, | 741 | &hc, |
779 | &find_trees, | 742 | &find_trees, |
780 | &fc); | 743 | &fc); |
781 | } | 744 | if (UINT_MAX == fc.id) |
782 | else | 745 | { |
783 | { | 746 | /* start new TREE */ |
784 | /* make head of TREE "id" */ | 747 | for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++) |
785 | fc.tree_array[fc.id] = nsn; | 748 | { |
786 | nsn->tree_id = fc.id; | 749 | if (NULL == fc.tree_array[fc.id]) |
750 | { | ||
751 | fc.tree_array[fc.id] = nsn; | ||
752 | nsn->tree_id = fc.id; | ||
753 | break; | ||
754 | } | ||
755 | } | ||
756 | if (fc.id == fc.tree_array_size) | ||
757 | { | ||
758 | GNUNET_array_append(fc.tree_array, fc.tree_array_size, nsn); | ||
759 | nsn->tree_id = fc.id; | ||
760 | } | ||
761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
762 | "Starting new TREE %u with node `%s'\n", | ||
763 | nsn->tree_id, | ||
764 | nsn->id); | ||
765 | /* put all nodes with same identifier into this TREE */ | ||
766 | GNUNET_CRYPTO_hash(nsn->id, strlen(nsn->id), &hc); | ||
767 | fc.id = nsn->tree_id; | ||
768 | fc.nug = nug; | ||
769 | fc.uig = uig; | ||
770 | GNUNET_CONTAINER_multihashmap_get_multiple(uig->update_map, | ||
771 | &hc, | ||
772 | &find_trees, | ||
773 | &fc); | ||
774 | } | ||
775 | else | ||
776 | { | ||
777 | /* make head of TREE "id" */ | ||
778 | fc.tree_array[fc.id] = nsn; | ||
779 | nsn->tree_id = fc.id; | ||
780 | } | ||
781 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
782 | "TREE of node `%s' is %u\n", | ||
783 | nsn->id, | ||
784 | fc.id); | ||
787 | } | 785 | } |
788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
789 | "TREE of node `%s' is %u\n", | ||
790 | nsn->id, | ||
791 | fc.id); | ||
792 | } | ||
793 | for (i = 0; i < fc.tree_array_size; i++) | 786 | for (i = 0; i < fc.tree_array_size; i++) |
794 | { | ||
795 | nsn = fc.tree_array[i]; | ||
796 | if (NULL != nsn) | ||
797 | { | 787 | { |
798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | nsn = fc.tree_array[i]; |
799 | "Root of TREE %u is node `%s'\n", | 789 | if (NULL != nsn) |
800 | i, | 790 | { |
801 | nsn->id); | 791 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
802 | ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 792 | "Root of TREE %u is node `%s'\n", |
793 | i, | ||
794 | nsn->id); | ||
795 | ip(ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | ||
796 | } | ||
803 | } | 797 | } |
804 | } | 798 | GNUNET_array_grow(fc.tree_array, fc.tree_array_size, 0); |
805 | GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0); | 799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n"); | 800 | free_update_information_graph(uig); |
807 | free_update_information_graph (uig); | ||
808 | } | 801 | } |
809 | 802 | ||
810 | 803 | ||