aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_namespace.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/fs_namespace.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/fs_namespace.c')
-rw-r--r--src/fs/fs_namespace.c1063
1 files changed, 478 insertions, 585 deletions
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index cd0bfc415..e8dd56ef4 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -46,16 +46,13 @@ get_namespace_directory (struct GNUNET_FS_Handle *h)
46 46
47 if (GNUNET_OK != 47 if (GNUNET_OK !=
48 GNUNET_CONFIGURATION_get_value_filename (h->cfg, 48 GNUNET_CONFIGURATION_get_value_filename (h->cfg,
49 "FS", 49 "FS", "IDENTITY_DIR", &dn))
50 "IDENTITY_DIR", 50 {
51 &dn)) 51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
52 { 52 _("Configuration fails to specify `%s' in section `%s'\n"),
53 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 53 "IDENTITY_DIR", "fs");
54 _("Configuration fails to specify `%s' in section `%s'\n"), 54 return NULL;
55 "IDENTITY_DIR", 55 }
56 "fs");
57 return NULL;
58 }
59 return dn; 56 return dn;
60} 57}
61 58
@@ -75,21 +72,14 @@ get_update_information_directory (struct GNUNET_FS_Namespace *ns)
75 72
76 if (GNUNET_OK != 73 if (GNUNET_OK !=
77 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg, 74 GNUNET_CONFIGURATION_get_value_filename (ns->h->cfg,
78 "FS", 75 "FS", "UPDATE_DIR", &dn))
79 "UPDATE_DIR", 76 {
80 &dn)) 77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
81 { 78 _("Configuration fails to specify `%s' in section `%s'\n"),
82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 79 "UPDATE_DIR", "fs");
83 _("Configuration fails to specify `%s' in section `%s'\n"), 80 return NULL;
84 "UPDATE_DIR", 81 }
85 "fs"); 82 GNUNET_asprintf (&ret, "%s%s%s", dn, DIR_SEPARATOR_STR, ns->name);
86 return NULL;
87 }
88 GNUNET_asprintf (&ret,
89 "%s%s%s",
90 dn,
91 DIR_SEPARATOR_STR,
92 ns->name);
93 GNUNET_free (dn); 83 GNUNET_free (dn);
94 return ret; 84 return ret;
95} 85}
@@ -103,7 +93,7 @@ get_update_information_directory (struct GNUNET_FS_Namespace *ns)
103static void 93static void
104write_update_information_graph (struct GNUNET_FS_Namespace *ns) 94write_update_information_graph (struct GNUNET_FS_Namespace *ns)
105{ 95{
106 char * fn; 96 char *fn;
107 struct GNUNET_BIO_WriteHandle *wh; 97 struct GNUNET_BIO_WriteHandle *wh;
108 unsigned int i; 98 unsigned int i;
109 struct NamespaceUpdateNode *n; 99 struct NamespaceUpdateNode *n;
@@ -112,39 +102,35 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
112 fn = get_update_information_directory (ns); 102 fn = get_update_information_directory (ns);
113 wh = GNUNET_BIO_write_open (fn); 103 wh = GNUNET_BIO_write_open (fn);
114 if (wh == NULL) 104 if (wh == NULL)
115 { 105 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 _("Failed to open `%s' for writing: %s\n"), 107 _("Failed to open `%s' for writing: %s\n"), STRERROR (errno));
118 STRERROR (errno)); 108 GNUNET_free (fn);
119 GNUNET_free (fn); 109 return;
120 return; 110 }
121 } 111 if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, ns->update_node_count))
122 if (GNUNET_OK !=
123 GNUNET_BIO_write_int32 (wh, ns->update_node_count))
124 goto END; 112 goto END;
125 for (i=0;i<ns->update_node_count;i++) 113 for (i = 0; i < ns->update_node_count; i++)
114 {
115 n = ns->update_nodes[i];
116 uris = GNUNET_FS_uri_to_string (n->uri);
117 if ((GNUNET_OK !=
118 GNUNET_BIO_write_string (wh, n->id)) ||
119 (GNUNET_OK !=
120 GNUNET_BIO_write_meta_data (wh, n->md)) ||
121 (GNUNET_OK !=
122 GNUNET_BIO_write_string (wh, n->update)) ||
123 (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)))
126 { 124 {
127 n = ns->update_nodes[i];
128 uris = GNUNET_FS_uri_to_string (n->uri);
129 if ( (GNUNET_OK !=
130 GNUNET_BIO_write_string (wh, n->id)) ||
131 (GNUNET_OK !=
132 GNUNET_BIO_write_meta_data (wh, n->md)) ||
133 (GNUNET_OK !=
134 GNUNET_BIO_write_string (wh, n->update)) ||
135 (GNUNET_OK !=
136 GNUNET_BIO_write_string (wh, uris)) )
137 {
138 GNUNET_free (uris);
139 break;
140 }
141 GNUNET_free (uris); 125 GNUNET_free (uris);
126 break;
142 } 127 }
143 END: 128 GNUNET_free (uris);
129 }
130END:
144 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 131 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
146 _("Failed to write `%s': %s\n"), 133 _("Failed to write `%s': %s\n"), STRERROR (errno));
147 STRERROR (errno));
148 GNUNET_free (fn); 134 GNUNET_free (fn);
149} 135}
150 136
@@ -157,89 +143,85 @@ write_update_information_graph (struct GNUNET_FS_Namespace *ns)
157static void 143static void
158read_update_information_graph (struct GNUNET_FS_Namespace *ns) 144read_update_information_graph (struct GNUNET_FS_Namespace *ns)
159{ 145{
160 char * fn; 146 char *fn;
161 struct GNUNET_BIO_ReadHandle *rh; 147 struct GNUNET_BIO_ReadHandle *rh;
162 unsigned int i; 148 unsigned int i;
163 struct NamespaceUpdateNode *n; 149 struct NamespaceUpdateNode *n;
164 char *uris; 150 char *uris;
165 uint32_t count; 151 uint32_t count;
166 char *emsg; 152 char *emsg;
167 153
168 fn = get_update_information_directory (ns); 154 fn = get_update_information_directory (ns);
169 if (GNUNET_YES != 155 if (GNUNET_YES != GNUNET_DISK_file_test (fn))
170 GNUNET_DISK_file_test (fn)) 156 {
171 { 157 GNUNET_free (fn);
172 GNUNET_free (fn); 158 return;
173 return; 159 }
174 }
175 rh = GNUNET_BIO_read_open (fn); 160 rh = GNUNET_BIO_read_open (fn);
176 if (rh == NULL) 161 if (rh == NULL)
177 { 162 {
178 GNUNET_free (fn); 163 GNUNET_free (fn);
179 return; 164 return;
180 } 165 }
181 if (GNUNET_OK != 166 if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count))
182 GNUNET_BIO_read_int32 (rh, &count)) 167 {
183 { 168 GNUNET_break (0);
184 GNUNET_break (0); 169 goto END;
185 goto END; 170 }
186 }
187 if (count > 1024 * 1024) 171 if (count > 1024 * 1024)
188 { 172 {
189 GNUNET_break (0); 173 GNUNET_break (0);
190 goto END; 174 goto END;
191 } 175 }
192 if (count == 0) 176 if (count == 0)
177 {
178 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
179 GNUNET_free (fn);
180 return;
181 }
182 ns->update_nodes =
183 GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode *));
184
185 for (i = 0; i < count; i++)
186 {
187 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
188 if ((GNUNET_OK !=
189 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
190 (GNUNET_OK !=
191 GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
192 (GNUNET_OK !=
193 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
194 (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
193 { 195 {
194 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 196 GNUNET_break (0);
195 GNUNET_free (fn); 197 GNUNET_free_non_null (n->id);
196 return; 198 GNUNET_free_non_null (n->update);
199 if (n->md != NULL)
200 GNUNET_CONTAINER_meta_data_destroy (n->md);
201 GNUNET_free (n);
202 break;
197 } 203 }
198 ns->update_nodes = GNUNET_malloc (count * sizeof (struct NamespaceUpdateNode*)); 204 n->uri = GNUNET_FS_uri_parse (uris, &emsg);
199 205 GNUNET_free (uris);
200 for (i=0;i<count;i++) 206 if (n->uri == NULL)
201 { 207 {
202 n = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 208 GNUNET_break (0);
203 if ( (GNUNET_OK != 209 GNUNET_free (emsg);
204 GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || 210 GNUNET_free (n->id);
205 (GNUNET_OK != 211 GNUNET_free_non_null (n->update);
206 GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || 212 GNUNET_CONTAINER_meta_data_destroy (n->md);
207 (GNUNET_OK != 213 GNUNET_free (n);
208 GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || 214 break;
209 (GNUNET_OK !=
210 GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)) )
211 {
212 GNUNET_break (0);
213 GNUNET_free_non_null (n->id);
214 GNUNET_free_non_null (n->update);
215 if (n->md != NULL)
216 GNUNET_CONTAINER_meta_data_destroy (n->md);
217 GNUNET_free (n);
218 break;
219 }
220 n->uri = GNUNET_FS_uri_parse (uris, &emsg);
221 GNUNET_free (uris);
222 if (n->uri == NULL)
223 {
224 GNUNET_break (0);
225 GNUNET_free (emsg);
226 GNUNET_free (n->id);
227 GNUNET_free_non_null (n->update);
228 GNUNET_CONTAINER_meta_data_destroy (n->md);
229 GNUNET_free (n);
230 break;
231 }
232 ns->update_nodes[i] = n;
233 } 215 }
216 ns->update_nodes[i] = n;
217 }
234 ns->update_node_count = i; 218 ns->update_node_count = i;
235 END: 219END:
236 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 220 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
237 { 221 {
238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write `%s': %s\n"), emsg);
239 _("Failed to write `%s': %s\n"), 223 GNUNET_free (emsg);
240 emsg); 224 }
241 GNUNET_free (emsg);
242 }
243 GNUNET_free (fn); 225 GNUNET_free (fn);
244} 226}
245 227
@@ -266,7 +248,7 @@ struct AdvertisementContext
266 248
267 /** 249 /**
268 * Our KSK URI. 250 * Our KSK URI.
269 */ 251 */
270 struct GNUNET_FS_Uri *ksk_uri; 252 struct GNUNET_FS_Uri *ksk_uri;
271 253
272 /** 254 /**
@@ -291,7 +273,7 @@ struct AdvertisementContext
291 273
292 /** 274 /**
293 * Number of bytes of plaintext. 275 * Number of bytes of plaintext.
294 */ 276 */
295 size_t pt_size; 277 size_t pt_size;
296 278
297 /** 279 /**
@@ -308,13 +290,11 @@ struct AdvertisementContext
308 * @param tc scheduler context 290 * @param tc scheduler context
309 */ 291 */
310static void 292static void
311do_disconnect (void *cls, 293do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
312 const struct GNUNET_SCHEDULER_TaskContext *tc)
313{ 294{
314 struct GNUNET_DATASTORE_Handle *dsh = cls; 295 struct GNUNET_DATASTORE_Handle *dsh = cls;
315 296
316 GNUNET_DATASTORE_disconnect (dsh, 297 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
317 GNUNET_NO);
318} 298}
319 299
320 300
@@ -327,9 +307,7 @@ do_disconnect (void *cls,
327 * @param msg NULL on success, otherwise an error message 307 * @param msg NULL on success, otherwise an error message
328 */ 308 */
329static void 309static void
330advertisement_cont (void *cls, 310advertisement_cont (void *cls, int success, const char *msg)
331 int success,
332 const char *msg)
333{ 311{
334 struct AdvertisementContext *ac = cls; 312 struct AdvertisementContext *ac = cls;
335 const char *keyword; 313 const char *keyword;
@@ -338,81 +316,75 @@ advertisement_cont (void *cls,
338 struct GNUNET_CRYPTO_AesSessionKey skey; 316 struct GNUNET_CRYPTO_AesSessionKey skey;
339 struct GNUNET_CRYPTO_AesInitializationVector iv; 317 struct GNUNET_CRYPTO_AesInitializationVector iv;
340 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 318 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
341 319
342 if (GNUNET_OK != success) 320 if (GNUNET_OK != success)
321 {
322 /* error! */
323 GNUNET_SCHEDULER_add_continuation (&do_disconnect,
324 ac->dsh,
325 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
326 if (msg == NULL)
343 { 327 {
344 /* error! */ 328 GNUNET_break (0);
345 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 329 msg = _("Unknown error");
346 ac->dsh,
347 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
348 if (msg == NULL)
349 {
350 GNUNET_break (0);
351 msg = _("Unknown error");
352 }
353 if (ac->cont != NULL)
354 ac->cont (ac->cont_cls, NULL, msg);
355 GNUNET_FS_uri_destroy (ac->ksk_uri);
356 GNUNET_free (ac->pt);
357 GNUNET_free (ac->nb);
358 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
359 GNUNET_free (ac);
360 return;
361 } 330 }
331 if (ac->cont != NULL)
332 ac->cont (ac->cont_cls, NULL, msg);
333 GNUNET_FS_uri_destroy (ac->ksk_uri);
334 GNUNET_free (ac->pt);
335 GNUNET_free (ac->nb);
336 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
337 GNUNET_free (ac);
338 return;
339 }
362 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount) 340 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
363 { 341 {
364 /* done! */ 342 /* done! */
365 GNUNET_SCHEDULER_add_continuation (&do_disconnect, 343 GNUNET_SCHEDULER_add_continuation (&do_disconnect,
366 ac->dsh, 344 ac->dsh,
367 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 345 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
368 if (ac->cont != NULL) 346 if (ac->cont != NULL)
369 ac->cont (ac->cont_cls, ac->ksk_uri, NULL); 347 ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
370 GNUNET_FS_uri_destroy (ac->ksk_uri); 348 GNUNET_FS_uri_destroy (ac->ksk_uri);
371 GNUNET_free (ac->pt); 349 GNUNET_free (ac->pt);
372 GNUNET_free (ac->nb); 350 GNUNET_free (ac->nb);
373 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO); 351 GNUNET_FS_namespace_delete (ac->ns, GNUNET_NO);
374 GNUNET_free (ac); 352 GNUNET_free (ac);
375 return; 353 return;
376 } 354 }
377 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++]; 355 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++];
378 /* first character of keyword indicates if it is 356 /* first character of keyword indicates if it is
379 mandatory or not -- ignore for hashing */ 357 * mandatory or not -- ignore for hashing */
380 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 358 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
381 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 359 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
382 GNUNET_CRYPTO_aes_encrypt (ac->pt, 360 GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]);
383 ac->pt_size, 361 GNUNET_break (GNUNET_OK ==
384 &skey, 362 GNUNET_CRYPTO_rsa_sign (ac->ns->key,
385 &iv, 363 &ac->nb->ns_purpose,
386 &ac->nb[1]); 364 &ac->nb->ns_signature));
387 GNUNET_break (GNUNET_OK ==
388 GNUNET_CRYPTO_rsa_sign (ac->ns->key,
389 &ac->nb->ns_purpose,
390 &ac->nb->ns_signature));
391 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 365 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
392 GNUNET_assert (pk != NULL); 366 GNUNET_assert (pk != NULL);
393 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace); 367 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace);
394 GNUNET_CRYPTO_hash (&ac->nb->keyspace, 368 GNUNET_CRYPTO_hash (&ac->nb->keyspace,
395 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 369 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
396 &query); 370 &query);
397 GNUNET_break (GNUNET_OK == 371 GNUNET_break (GNUNET_OK ==
398 GNUNET_CRYPTO_rsa_sign (pk, 372 GNUNET_CRYPTO_rsa_sign (pk,
399 &ac->nb->ksk_purpose, 373 &ac->nb->ksk_purpose,
400 &ac->nb->ksk_signature)); 374 &ac->nb->ksk_signature));
401 GNUNET_CRYPTO_rsa_key_free (pk); 375 GNUNET_CRYPTO_rsa_key_free (pk);
402 GNUNET_DATASTORE_put (ac->dsh, 376 GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ ,
403 0 /* no reservation */, 377 &query,
404 &query, 378 ac->pt_size + sizeof (struct NBlock),
405 ac->pt_size + sizeof (struct NBlock), 379 ac->nb,
406 ac->nb, 380 GNUNET_BLOCK_TYPE_FS_NBLOCK,
407 GNUNET_BLOCK_TYPE_FS_NBLOCK, 381 ac->bo.content_priority,
408 ac->bo.content_priority, 382 ac->bo.anonymity_level,
409 ac->bo.anonymity_level, 383 ac->bo.replication_level,
410 ac->bo.replication_level, 384 ac->bo.expiration_time,
411 ac->bo.expiration_time, 385 -2, 1,
412 -2, 1, 386 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
413 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 387 &advertisement_cont, ac);
414 &advertisement_cont,
415 ac);
416} 388}
417 389
418 390
@@ -430,13 +402,13 @@ advertisement_cont (void *cls,
430 */ 402 */
431void 403void
432GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h, 404GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
433 struct GNUNET_FS_Uri *ksk_uri, 405 struct GNUNET_FS_Uri *ksk_uri,
434 struct GNUNET_FS_Namespace *namespace, 406 struct GNUNET_FS_Namespace *namespace,
435 const struct GNUNET_CONTAINER_MetaData *meta, 407 const struct GNUNET_CONTAINER_MetaData *meta,
436 const struct GNUNET_FS_BlockOptions *bo, 408 const struct GNUNET_FS_BlockOptions *bo,
437 const char *rootEntry, 409 const char *rootEntry,
438 GNUNET_FS_PublishContinuation cont, 410 GNUNET_FS_PublishContinuation cont,
439 void *cont_cls) 411 void *cont_cls)
440{ 412{
441 size_t reslen; 413 size_t reslen;
442 size_t size; 414 size_t size;
@@ -450,50 +422,52 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
450 /* create advertisements */ 422 /* create advertisements */
451 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); 423 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
452 if (-1 == mdsize) 424 if (-1 == mdsize)
453 { 425 {
454 cont (cont_cls, NULL, _("Failed to serialize meta data")); 426 cont (cont_cls, NULL, _("Failed to serialize meta data"));
455 return; 427 return;
456 } 428 }
457 reslen = strlen (rootEntry) + 1; 429 reslen = strlen (rootEntry) + 1;
458 size = mdsize + sizeof (struct NBlock) + reslen; 430 size = mdsize + sizeof (struct NBlock) + reslen;
459 if (size > MAX_NBLOCK_SIZE) 431 if (size > MAX_NBLOCK_SIZE)
460 { 432 {
461 size = MAX_NBLOCK_SIZE; 433 size = MAX_NBLOCK_SIZE;
462 mdsize = size - sizeof (struct NBlock) - reslen; 434 mdsize = size - sizeof (struct NBlock) - reslen;
463 } 435 }
464 436
465 pt = GNUNET_malloc (mdsize + reslen); 437 pt = GNUNET_malloc (mdsize + reslen);
466 memcpy (pt, rootEntry, reslen); 438 memcpy (pt, rootEntry, reslen);
467 mdst = &pt[reslen]; 439 mdst = &pt[reslen];
468 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta, 440 mdsize = GNUNET_CONTAINER_meta_data_serialize (meta,
469 &mdst, 441 &mdst,
470 mdsize, 442 mdsize,
471 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 443 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
472 if (mdsize == -1) 444 if (mdsize == -1)
473 { 445 {
474 GNUNET_break (0); 446 GNUNET_break (0);
475 GNUNET_free (pt); 447 GNUNET_free (pt);
476 cont (cont_cls, NULL, _("Failed to serialize meta data")); 448 cont (cont_cls, NULL, _("Failed to serialize meta data"));
477 return; 449 return;
478 } 450 }
479 size = mdsize + sizeof (struct NBlock) + reslen; 451 size = mdsize + sizeof (struct NBlock) + reslen;
480 nb = GNUNET_malloc (size); 452 nb = GNUNET_malloc (size);
481 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, 453 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &nb->subspace);
482 &nb->subspace); 454 nb->ns_purpose.size = htonl (mdsize + reslen +
483 nb->ns_purpose.size = htonl (mdsize + reslen + 455 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
484 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 456 +
485 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 457 sizeof (struct
458 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
486 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK); 459 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
487 nb->ksk_purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); 460 nb->ksk_purpose.size =
461 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
488 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG); 462 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG);
489 dsh = GNUNET_DATASTORE_connect (h->cfg); 463 dsh = GNUNET_DATASTORE_connect (h->cfg);
490 if (NULL == dsh) 464 if (NULL == dsh)
491 { 465 {
492 GNUNET_free (nb); 466 GNUNET_free (nb);
493 GNUNET_free (pt); 467 GNUNET_free (pt);
494 cont (cont_cls, NULL, _("Failed to connect to datastore service")); 468 cont (cont_cls, NULL, _("Failed to connect to datastore service"));
495 return; 469 return;
496 } 470 }
497 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext)); 471 ctx = GNUNET_malloc (sizeof (struct AdvertisementContext));
498 ctx->cont = cont; 472 ctx->cont = cont;
499 ctx->cont_cls = cont_cls; 473 ctx->cont_cls = cont_cls;
@@ -518,33 +492,28 @@ GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
518 * @return handle to the namespace, NULL on error 492 * @return handle to the namespace, NULL on error
519 */ 493 */
520struct GNUNET_FS_Namespace * 494struct GNUNET_FS_Namespace *
521GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, 495GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name)
522 const char *name)
523{ 496{
524 char *dn; 497 char *dn;
525 char *fn; 498 char *fn;
526 struct GNUNET_FS_Namespace *ret; 499 struct GNUNET_FS_Namespace *ret;
527 500
528 dn = get_namespace_directory (h); 501 dn = get_namespace_directory (h);
529 GNUNET_asprintf (&fn, 502 GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name);
530 "%s%s%s",
531 dn,
532 DIR_SEPARATOR_STR,
533 name);
534 GNUNET_free (dn); 503 GNUNET_free (dn);
535 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); 504 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
536 ret->h = h; 505 ret->h = h;
537 ret->rc = 1; 506 ret->rc = 1;
538 ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn); 507 ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
539 if (ret->key == NULL) 508 if (ret->key == NULL)
540 { 509 {
541 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
542 _("Failed to create or read private key for namespace `%s'\n"), 511 _("Failed to create or read private key for namespace `%s'\n"),
543 name); 512 name);
544 GNUNET_free (ret); 513 GNUNET_free (ret);
545 GNUNET_free (fn); 514 GNUNET_free (fn);
546 return NULL; 515 return NULL;
547 } 516 }
548 ret->name = GNUNET_strdup (name); 517 ret->name = GNUNET_strdup (name);
549 ret->filename = fn; 518 ret->filename = fn;
550 return ret; 519 return ret;
@@ -562,42 +531,39 @@ GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
562 * 531 *
563 * @return GNUNET_OK on success, GNUNET_SYSERR on error 532 * @return GNUNET_OK on success, GNUNET_SYSERR on error
564 */ 533 */
565int 534int
566GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, 535GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze)
567 int freeze)
568{ 536{
569 unsigned int i; 537 unsigned int i;
570 struct NamespaceUpdateNode *nsn; 538 struct NamespaceUpdateNode *nsn;
571 539
572 namespace->rc--; 540 namespace->rc--;
573 if (freeze) 541 if (freeze)
574 { 542 {
575 if (0 != UNLINK (namespace->filename)) 543 if (0 != UNLINK (namespace->filename))
576 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 544 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
577 "unlink", 545 "unlink", namespace->filename);
578 namespace->filename); 546 }
579 }
580 if (0 == namespace->rc) 547 if (0 == namespace->rc)
548 {
549 GNUNET_CRYPTO_rsa_key_free (namespace->key);
550 GNUNET_free (namespace->filename);
551 GNUNET_free (namespace->name);
552 for (i = 0; i < namespace->update_node_count; i++)
581 { 553 {
582 GNUNET_CRYPTO_rsa_key_free (namespace->key); 554 nsn = namespace->update_nodes[i];
583 GNUNET_free (namespace->filename); 555 GNUNET_CONTAINER_meta_data_destroy (nsn->md);
584 GNUNET_free (namespace->name); 556 GNUNET_FS_uri_destroy (nsn->uri);
585 for (i=0;i<namespace->update_node_count;i++) 557 GNUNET_free (nsn->id);
586 { 558 GNUNET_free (nsn->update);
587 nsn = namespace->update_nodes[i]; 559 GNUNET_free (nsn);
588 GNUNET_CONTAINER_meta_data_destroy (nsn->md);
589 GNUNET_FS_uri_destroy (nsn->uri);
590 GNUNET_free (nsn->id);
591 GNUNET_free (nsn->update);
592 GNUNET_free (nsn);
593 }
594 GNUNET_array_grow (namespace->update_nodes,
595 namespace->update_node_count,
596 0);
597 if (namespace->update_map != NULL)
598 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
599 GNUNET_free (namespace);
600 } 560 }
561 GNUNET_array_grow (namespace->update_nodes,
562 namespace->update_node_count, 0);
563 if (namespace->update_map != NULL)
564 GNUNET_CONTAINER_multihashmap_destroy (namespace->update_map);
565 GNUNET_free (namespace);
566 }
601 return GNUNET_OK; 567 return GNUNET_OK;
602} 568}
603 569
@@ -630,8 +596,7 @@ struct ProcessNamespaceContext
630 * GNUNET_SYSERR to abort iteration with error! 596 * GNUNET_SYSERR to abort iteration with error!
631 */ 597 */
632static int 598static int
633process_namespace (void *cls, 599process_namespace (void *cls, const char *filename)
634 const char *filename)
635{ 600{
636 struct ProcessNamespaceContext *pnc = cls; 601 struct ProcessNamespaceContext *pnc = cls;
637 struct GNUNET_CRYPTO_RsaPrivateKey *key; 602 struct GNUNET_CRYPTO_RsaPrivateKey *key;
@@ -642,25 +607,22 @@ process_namespace (void *cls,
642 607
643 key = GNUNET_CRYPTO_rsa_key_create_from_file (filename); 608 key = GNUNET_CRYPTO_rsa_key_create_from_file (filename);
644 if (key == NULL) 609 if (key == NULL)
645 { 610 {
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 _("Failed to read namespace private key file `%s', deleting it!\n"), 612 _
648 filename); 613 ("Failed to read namespace private key file `%s', deleting it!\n"),
649 if (0 != UNLINK (filename)) 614 filename);
650 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 615 if (0 != UNLINK (filename))
651 "unlink", 616 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
652 filename); 617 return GNUNET_OK;
653 return GNUNET_OK; 618 }
654 }
655 GNUNET_CRYPTO_rsa_key_get_public (key, &pk); 619 GNUNET_CRYPTO_rsa_key_get_public (key, &pk);
656 GNUNET_CRYPTO_rsa_key_free (key); 620 GNUNET_CRYPTO_rsa_key_free (key);
657 GNUNET_CRYPTO_hash (&pk, sizeof(pk), &id); 621 GNUNET_CRYPTO_hash (&pk, sizeof (pk), &id);
658 name = filename; 622 name = filename;
659 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR))) 623 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR)))
660 name = t + 1; 624 name = t + 1;
661 pnc->cb (pnc->cb_cls, 625 pnc->cb (pnc->cb_cls, name, &id);
662 name,
663 &id);
664 return GNUNET_OK; 626 return GNUNET_OK;
665} 627}
666 628
@@ -674,22 +636,19 @@ process_namespace (void *cls,
674 * @param cb function to call on each known namespace 636 * @param cb function to call on each known namespace
675 * @param cb_cls closure for cb 637 * @param cb_cls closure for cb
676 */ 638 */
677void 639void
678GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h, 640GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
679 GNUNET_FS_NamespaceInfoProcessor cb, 641 GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls)
680 void *cb_cls)
681{ 642{
682 char *dn; 643 char *dn;
683 struct ProcessNamespaceContext ctx; 644 struct ProcessNamespaceContext ctx;
684 645
685 dn = get_namespace_directory (h); 646 dn = get_namespace_directory (h);
686 if (dn == NULL) 647 if (dn == NULL)
687 return; 648 return;
688 ctx.cb = cb; 649 ctx.cb = cb;
689 ctx.cb_cls = cb_cls; 650 ctx.cb_cls = cb_cls;
690 GNUNET_DISK_directory_scan (dn, 651 GNUNET_DISK_directory_scan (dn, &process_namespace, &ctx);
691 &process_namespace,
692 &ctx);
693 GNUNET_free (dn); 652 GNUNET_free (dn);
694} 653}
695 654
@@ -730,7 +689,7 @@ struct PublishSksContext
730 689
731 /** 690 /**
732 * Closure for cont. 691 * Closure for cont.
733 */ 692 */
734 void *cont_cls; 693 void *cont_cls;
735 694
736}; 695};
@@ -745,66 +704,56 @@ struct PublishSksContext
745 * @param msg error message (or NULL) 704 * @param msg error message (or NULL)
746 */ 705 */
747static void 706static void
748sb_put_cont (void *cls, 707sb_put_cont (void *cls, int success, const char *msg)
749 int success,
750 const char *msg)
751{ 708{
752 struct PublishSksContext *psc = cls; 709 struct PublishSksContext *psc = cls;
753 GNUNET_HashCode hc; 710 GNUNET_HashCode hc;
754 711
755 if (NULL != psc->dsh) 712 if (NULL != psc->dsh)
756 { 713 {
757 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); 714 GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO);
758 psc->dsh = NULL; 715 psc->dsh = NULL;
759 } 716 }
760 if (GNUNET_OK != success) 717 if (GNUNET_OK != success)
761 { 718 {
762 if (psc->cont != NULL) 719 if (psc->cont != NULL)
763 psc->cont (psc->cont_cls, 720 psc->cont (psc->cont_cls, NULL, msg);
764 NULL, 721 }
765 msg);
766 }
767 else 722 else
723 {
724 if (psc->nsn != NULL)
768 { 725 {
769 if (psc->nsn != NULL) 726 /* FIXME: this can be done much more
770 { 727 * efficiently by simply appending to the
771 /* FIXME: this can be done much more 728 * file and overwriting the 4-byte header */
772 efficiently by simply appending to the 729 if (psc->namespace->update_nodes == NULL)
773 file and overwriting the 4-byte header */ 730 read_update_information_graph (psc->namespace);
774 if (psc->namespace->update_nodes == NULL) 731 GNUNET_array_append (psc->namespace->update_nodes,
775 read_update_information_graph (psc->namespace); 732 psc->namespace->update_node_count, psc->nsn);
776 GNUNET_array_append (psc->namespace->update_nodes, 733 if (psc->namespace->update_map != NULL)
777 psc->namespace->update_node_count, 734 {
778 psc->nsn); 735 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc);
779 if (psc->namespace->update_map != NULL) 736 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map,
780 { 737 &hc,
781 GNUNET_CRYPTO_hash (psc->nsn->id, 738 psc->nsn,
782 strlen (psc->nsn->id), 739 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
783 &hc); 740 }
784 GNUNET_CONTAINER_multihashmap_put (psc->namespace->update_map, 741 psc->nsn = NULL;
785 &hc, 742 write_update_information_graph (psc->namespace);
786 psc->nsn,
787 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
788 }
789 psc->nsn = NULL;
790 write_update_information_graph (psc->namespace);
791 }
792 if (psc->cont != NULL)
793 psc->cont (psc->cont_cls,
794 psc->uri,
795 NULL);
796 } 743 }
797 GNUNET_FS_namespace_delete (psc->namespace, 744 if (psc->cont != NULL)
798 GNUNET_NO); 745 psc->cont (psc->cont_cls, psc->uri, NULL);
746 }
747 GNUNET_FS_namespace_delete (psc->namespace, GNUNET_NO);
799 GNUNET_FS_uri_destroy (psc->uri); 748 GNUNET_FS_uri_destroy (psc->uri);
800 if (psc->nsn != NULL) 749 if (psc->nsn != NULL)
801 { 750 {
802 GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md); 751 GNUNET_CONTAINER_meta_data_destroy (psc->nsn->md);
803 GNUNET_FS_uri_destroy (psc->nsn->uri); 752 GNUNET_FS_uri_destroy (psc->nsn->uri);
804 GNUNET_free (psc->nsn->id); 753 GNUNET_free (psc->nsn->id);
805 GNUNET_free (psc->nsn->update); 754 GNUNET_free (psc->nsn->update);
806 GNUNET_free (psc->nsn); 755 GNUNET_free (psc->nsn);
807 } 756 }
808 GNUNET_free (psc); 757 GNUNET_free (psc);
809} 758}
810 759
@@ -825,15 +774,14 @@ sb_put_cont (void *cls,
825 */ 774 */
826void 775void
827GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, 776GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
828 struct GNUNET_FS_Namespace *namespace, 777 struct GNUNET_FS_Namespace *namespace,
829 const char *identifier, 778 const char *identifier,
830 const char *update, 779 const char *update,
831 const struct GNUNET_CONTAINER_MetaData *meta, 780 const struct GNUNET_CONTAINER_MetaData *meta,
832 const struct GNUNET_FS_Uri *uri, 781 const struct GNUNET_FS_Uri *uri,
833 const struct GNUNET_FS_BlockOptions *bo, 782 const struct GNUNET_FS_BlockOptions *bo,
834 enum GNUNET_FS_PublishOptions options, 783 enum GNUNET_FS_PublishOptions options,
835 GNUNET_FS_PublishContinuation cont, 784 GNUNET_FS_PublishContinuation cont, void *cont_cls)
836 void *cont_cls)
837{ 785{
838 struct PublishSksContext *psc; 786 struct PublishSksContext *psc;
839 struct GNUNET_CRYPTO_AesSessionKey sk; 787 struct GNUNET_CRYPTO_AesSessionKey sk;
@@ -849,9 +797,9 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
849 struct SBlock *sb_enc; 797 struct SBlock *sb_enc;
850 char *dest; 798 char *dest;
851 struct GNUNET_CONTAINER_MetaData *mmeta; 799 struct GNUNET_CONTAINER_MetaData *mmeta;
852 GNUNET_HashCode key; /* hash of thisId = key */ 800 GNUNET_HashCode key; /* hash of thisId = key */
853 GNUNET_HashCode id; /* hash of hc = identifier */ 801 GNUNET_HashCode id; /* hash of hc = identifier */
854 GNUNET_HashCode query; /* id ^ nsid = DB query */ 802 GNUNET_HashCode query; /* id ^ nsid = DB query */
855 803
856 if (NULL == meta) 804 if (NULL == meta)
857 mmeta = GNUNET_CONTAINER_meta_data_create (); 805 mmeta = GNUNET_CONTAINER_meta_data_create ();
@@ -867,10 +815,10 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
867 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta); 815 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
868 size = sizeof (struct SBlock) + slen + nidlen + mdsize; 816 size = sizeof (struct SBlock) + slen + nidlen + mdsize;
869 if (size > MAX_SBLOCK_SIZE) 817 if (size > MAX_SBLOCK_SIZE)
870 { 818 {
871 size = MAX_SBLOCK_SIZE; 819 size = MAX_SBLOCK_SIZE;
872 mdsize = size - (sizeof (struct SBlock) + slen + nidlen); 820 mdsize = size - (sizeof (struct SBlock) + slen + nidlen);
873 } 821 }
874 sb = GNUNET_malloc (sizeof (struct SBlock) + size); 822 sb = GNUNET_malloc (sizeof (struct SBlock) + size);
875 dest = (char *) &sb[1]; 823 dest = (char *) &sb[1];
876 if (update != NULL) 824 if (update != NULL)
@@ -882,19 +830,17 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
882 GNUNET_free (uris); 830 GNUNET_free (uris);
883 dest += slen; 831 dest += slen;
884 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta, 832 mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta,
885 &dest, 833 &dest,
886 mdsize, 834 mdsize,
887 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 835 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
888 GNUNET_CONTAINER_meta_data_destroy (mmeta); 836 GNUNET_CONTAINER_meta_data_destroy (mmeta);
889 if (mdsize == -1) 837 if (mdsize == -1)
890 { 838 {
891 GNUNET_break (0); 839 GNUNET_break (0);
892 GNUNET_free (sb); 840 GNUNET_free (sb);
893 cont (cont_cls, 841 cont (cont_cls, NULL, _("Internal error."));
894 NULL, 842 return;
895 _("Internal error.")); 843 }
896 return;
897 }
898 size = sizeof (struct SBlock) + mdsize + slen + nidlen; 844 size = sizeof (struct SBlock) + mdsize + slen + nidlen;
899 sb_enc = GNUNET_malloc (size); 845 sb_enc = GNUNET_malloc (size);
900 GNUNET_CRYPTO_hash (identifier, idlen, &key); 846 GNUNET_CRYPTO_hash (identifier, idlen, &key);
@@ -903,76 +849,64 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
903 sks_uri->type = sks; 849 sks_uri->type = sks;
904 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace); 850 GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace);
905 GNUNET_CRYPTO_hash (&sb_enc->subspace, 851 GNUNET_CRYPTO_hash (&sb_enc->subspace,
906 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 852 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
907 &sks_uri->data.sks.namespace); 853 &sks_uri->data.sks.namespace);
908 sks_uri->data.sks.identifier = GNUNET_strdup (identifier); 854 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
909 GNUNET_CRYPTO_hash_xor (&id, 855 GNUNET_CRYPTO_hash_xor (&id,
910 &sks_uri->data.sks.namespace, 856 &sks_uri->data.sks.namespace, &sb_enc->identifier);
911 &sb_enc->identifier);
912 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); 857 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
913 GNUNET_CRYPTO_aes_encrypt (&sb[1], 858 GNUNET_CRYPTO_aes_encrypt (&sb[1],
914 size - sizeof (struct SBlock), 859 size - sizeof (struct SBlock),
915 &sk, 860 &sk, &iv, &sb_enc[1]);
916 &iv,
917 &sb_enc[1]);
918 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); 861 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK);
919 sb_enc->purpose.size = htonl(slen + mdsize + nidlen 862 sb_enc->purpose.size = htonl (slen + mdsize + nidlen
920 + sizeof(struct SBlock) 863 + sizeof (struct SBlock)
921 - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 864 - sizeof (struct GNUNET_CRYPTO_RsaSignature));
922 GNUNET_assert (GNUNET_OK == 865 GNUNET_assert (GNUNET_OK ==
923 GNUNET_CRYPTO_rsa_sign (namespace->key, 866 GNUNET_CRYPTO_rsa_sign (namespace->key,
924 &sb_enc->purpose, 867 &sb_enc->purpose, &sb_enc->signature));
925 &sb_enc->signature)); 868 psc = GNUNET_malloc (sizeof (struct PublishSksContext));
926 psc = GNUNET_malloc (sizeof(struct PublishSksContext));
927 psc->uri = sks_uri; 869 psc->uri = sks_uri;
928 psc->cont = cont; 870 psc->cont = cont;
929 psc->namespace = namespace; 871 psc->namespace = namespace;
930 namespace->rc++; 872 namespace->rc++;
931 psc->cont_cls = cont_cls; 873 psc->cont_cls = cont_cls;
932 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 874 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
933 { 875 {
934 GNUNET_free (sb_enc); 876 GNUNET_free (sb_enc);
935 GNUNET_free (sb); 877 GNUNET_free (sb);
936 sb_put_cont (psc, 878 sb_put_cont (psc, GNUNET_OK, NULL);
937 GNUNET_OK, 879 return;
938 NULL); 880 }
939 return;
940 }
941 psc->dsh = GNUNET_DATASTORE_connect (h->cfg); 881 psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
942 if (NULL == psc->dsh) 882 if (NULL == psc->dsh)
943 { 883 {
944 GNUNET_free (sb_enc); 884 GNUNET_free (sb_enc);
945 GNUNET_free (sb); 885 GNUNET_free (sb);
946 sb_put_cont (psc, 886 sb_put_cont (psc, GNUNET_NO, _("Failed to connect to datastore."));
947 GNUNET_NO, 887 return;
948 _("Failed to connect to datastore.")); 888 }
949 return; 889 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace, &id, &query);
950 }
951 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace,
952 &id,
953 &query);
954 if (NULL != update) 890 if (NULL != update)
955 { 891 {
956 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 892 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
957 psc->nsn->id = GNUNET_strdup (identifier); 893 psc->nsn->id = GNUNET_strdup (identifier);
958 psc->nsn->update = GNUNET_strdup (update); 894 psc->nsn->update = GNUNET_strdup (update);
959 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); 895 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
960 psc->nsn->uri = GNUNET_FS_uri_dup (uri); 896 psc->nsn->uri = GNUNET_FS_uri_dup (uri);
961 } 897 }
962 GNUNET_DATASTORE_put (psc->dsh, 898 GNUNET_DATASTORE_put (psc->dsh,
963 0, 899 0,
964 &sb_enc->identifier, 900 &sb_enc->identifier,
965 size, 901 size,
966 sb_enc, 902 sb_enc,
967 GNUNET_BLOCK_TYPE_FS_SBLOCK, 903 GNUNET_BLOCK_TYPE_FS_SBLOCK,
968 bo->content_priority, 904 bo->content_priority,
969 bo->anonymity_level, 905 bo->anonymity_level,
970 bo->replication_level, 906 bo->replication_level,
971 bo->expiration_time, 907 bo->expiration_time,
972 -2, 1, 908 -2, 1,
973 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 909 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc);
974 &sb_put_cont,
975 psc);
976 GNUNET_free (sb); 910 GNUNET_free (sb);
977 GNUNET_free (sb_enc); 911 GNUNET_free (sb_enc);
978} 912}
@@ -981,7 +915,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
981/** 915/**
982 * Closure for 'process_update_node'. 916 * Closure for 'process_update_node'.
983 */ 917 */
984struct ProcessUpdateClosure 918struct ProcessUpdateClosure
985{ 919{
986 /** 920 /**
987 * Function to call for each node. 921 * Function to call for each node.
@@ -1006,18 +940,12 @@ struct ProcessUpdateClosure
1006 * GNUNET_NO if not. 940 * GNUNET_NO if not.
1007 */ 941 */
1008static int 942static int
1009process_update_node (void *cls, 943process_update_node (void *cls, const GNUNET_HashCode * key, void *value)
1010 const GNUNET_HashCode * key,
1011 void *value)
1012{ 944{
1013 struct ProcessUpdateClosure *pc = cls; 945 struct ProcessUpdateClosure *pc = cls;
1014 struct NamespaceUpdateNode *nsn = value; 946 struct NamespaceUpdateNode *nsn = value;
1015 947
1016 pc->ip (pc->ip_cls, 948 pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
1017 nsn->id,
1018 nsn->uri,
1019 nsn->md,
1020 nsn->update);
1021 return GNUNET_YES; 949 return GNUNET_YES;
1022} 950}
1023 951
@@ -1025,7 +953,7 @@ process_update_node (void *cls,
1025/** 953/**
1026 * Closure for 'find_trees'. 954 * Closure for 'find_trees'.
1027 */ 955 */
1028struct FindTreeClosure 956struct FindTreeClosure
1029{ 957{
1030 /** 958 /**
1031 * Namespace we are operating on. 959 * Namespace we are operating on.
@@ -1075,42 +1003,36 @@ struct FindTreeClosure
1075 * GNUNET_NO if not. 1003 * GNUNET_NO if not.
1076 */ 1004 */
1077static int 1005static int
1078find_trees (void *cls, 1006find_trees (void *cls, const GNUNET_HashCode * key, void *value)
1079 const GNUNET_HashCode * key,
1080 void *value)
1081{ 1007{
1082 struct FindTreeClosure *fc = cls; 1008 struct FindTreeClosure *fc = cls;
1083 struct NamespaceUpdateNode *nsn = value; 1009 struct NamespaceUpdateNode *nsn = value;
1084 GNUNET_HashCode hc; 1010 GNUNET_HashCode hc;
1085 1011
1086 if (nsn->nug == fc->nug) 1012 if (nsn->nug == fc->nug)
1087 { 1013 {
1088 if (nsn->tree_id == UINT_MAX) 1014 if (nsn->tree_id == UINT_MAX)
1089 return GNUNET_YES; /* circular */ 1015 return GNUNET_YES; /* circular */
1090 GNUNET_assert (nsn->tree_id < fc->tree_array_size); 1016 GNUNET_assert (nsn->tree_id < fc->tree_array_size);
1091 if (fc->tree_array[nsn->tree_id] != nsn) 1017 if (fc->tree_array[nsn->tree_id] != nsn)
1092 return GNUNET_YES; /* part of "another" (directed) TREE, 1018 return GNUNET_YES; /* part of "another" (directed) TREE,
1093 and not root of it, end trace */ 1019 * and not root of it, end trace */
1094 if (nsn->tree_id == fc->id) 1020 if (nsn->tree_id == fc->id)
1095 return GNUNET_YES; /* that's our own root (can this be?) */ 1021 return GNUNET_YES; /* that's our own root (can this be?) */
1096 /* merge existing TREE, we have a root for both */ 1022 /* merge existing TREE, we have a root for both */
1097 fc->tree_array[nsn->tree_id] = NULL; 1023 fc->tree_array[nsn->tree_id] = NULL;
1098 if (fc->id == UINT_MAX) 1024 if (fc->id == UINT_MAX)
1099 fc->id = nsn->tree_id; /* take over ID */ 1025 fc->id = nsn->tree_id; /* take over ID */
1100 } 1026 }
1101 else 1027 else
1102 { 1028 {
1103 nsn->nug = fc->nug; 1029 nsn->nug = fc->nug;
1104 nsn->tree_id = UINT_MAX; /* mark as undef */ 1030 nsn->tree_id = UINT_MAX; /* mark as undef */
1105 /* trace */ 1031 /* trace */
1106 GNUNET_CRYPTO_hash (nsn->update, 1032 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
1107 strlen (nsn->update), 1033 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map,
1108 &hc); 1034 &hc, &find_trees, fc);
1109 GNUNET_CONTAINER_multihashmap_get_multiple (fc->namespace->update_map, 1035 }
1110 &hc,
1111 &find_trees,
1112 fc);
1113 }
1114 return GNUNET_YES; 1036 return GNUNET_YES;
1115} 1037}
1116 1038
@@ -1139,9 +1061,9 @@ find_trees (void *cls,
1139 */ 1061 */
1140void 1062void
1141GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace, 1063GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1142 const char *next_id, 1064 const char *next_id,
1143 GNUNET_FS_IdentifierProcessor ip, 1065 GNUNET_FS_IdentifierProcessor ip,
1144 void *ip_cls) 1066 void *ip_cls)
1145{ 1067{
1146 unsigned int i; 1068 unsigned int i;
1147 unsigned int nug; 1069 unsigned int nug;
@@ -1153,154 +1075,125 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1153 if (namespace->update_nodes == NULL) 1075 if (namespace->update_nodes == NULL)
1154 read_update_information_graph (namespace); 1076 read_update_information_graph (namespace);
1155 if (namespace->update_nodes == NULL) 1077 if (namespace->update_nodes == NULL)
1156 { 1078 {
1157#if DEBUG_NAMESPACE 1079#if DEBUG_NAMESPACE
1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1159 "No updateable nodes found for ID `%s'\n", 1081 "No updateable nodes found for ID `%s'\n", next_id);
1160 next_id);
1161#endif 1082#endif
1162 return; /* no nodes */ 1083 return; /* no nodes */
1163 } 1084 }
1164 if (namespace->update_map == NULL) 1085 if (namespace->update_map == NULL)
1086 {
1087 /* need to construct */
1088 namespace->update_map =
1089 GNUNET_CONTAINER_multihashmap_create (2 +
1090 3 * namespace->update_node_count /
1091 4);
1092 for (i = 0; i < namespace->update_node_count; i++)
1165 { 1093 {
1166 /* need to construct */ 1094 nsn = namespace->update_nodes[i];
1167 namespace->update_map = GNUNET_CONTAINER_multihashmap_create (2 + 3 * namespace->update_node_count / 4); 1095 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1168 for (i=0;i<namespace->update_node_count;i++) 1096 GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
1169 { 1097 &hc,
1170 nsn = namespace->update_nodes[i]; 1098 nsn,
1171 GNUNET_CRYPTO_hash (nsn->id, 1099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1172 strlen (nsn->id),
1173 &hc);
1174 GNUNET_CONTAINER_multihashmap_put (namespace->update_map,
1175 &hc,
1176 nsn,
1177 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1178 }
1179 } 1100 }
1101 }
1180 if (next_id != NULL) 1102 if (next_id != NULL)
1181 { 1103 {
1182 GNUNET_CRYPTO_hash (next_id, 1104 GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
1183 strlen (next_id), 1105 pc.ip = ip;
1184 &hc); 1106 pc.ip_cls = ip_cls;
1185 pc.ip = ip; 1107 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1186 pc.ip_cls = ip_cls; 1108 &hc, &process_update_node, &pc);
1187 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1109 return;
1188 &hc, 1110 }
1189 &process_update_node,
1190 &pc);
1191 return;
1192 }
1193#if DEBUG_NAMESPACE 1111#if DEBUG_NAMESPACE
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Calculating TREEs to find roots of update trees\n"); 1113 "Calculating TREEs to find roots of update trees\n");
1196#endif 1114#endif
1197 /* Find heads of TREEs in update graph */ 1115 /* Find heads of TREEs in update graph */
1198 nug = ++namespace->nug_gen; 1116 nug = ++namespace->nug_gen;
1199 fc.tree_array = NULL; 1117 fc.tree_array = NULL;
1200 fc.tree_array_size = 0; 1118 fc.tree_array_size = 0;
1201 1119
1202 for (i=0;i<namespace->update_node_count;i++) 1120 for (i = 0; i < namespace->update_node_count; i++)
1121 {
1122 nsn = namespace->update_nodes[i];
1123 if (nsn->nug == nug)
1203 { 1124 {
1204 nsn = namespace->update_nodes[i];
1205 if (nsn->nug == nug)
1206 {
1207#if DEBUG_NAMESPACE 1125#if DEBUG_NAMESPACE
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "TREE of node `%s' is %u\n", 1127 "TREE of node `%s' is %u\n", nsn->id, nsn->nug);
1210 nsn->id,
1211 nsn->nug);
1212#endif 1128#endif
1213 continue; /* already placed in TREE */ 1129 continue; /* already placed in TREE */
1214 } 1130 }
1215 GNUNET_CRYPTO_hash (nsn->update, 1131 GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
1216 strlen (nsn->update), 1132 nsn->nug = nug;
1217 &hc); 1133 fc.id = UINT_MAX;
1218 nsn->nug = nug; 1134 fc.nug = nug;
1219 fc.id = UINT_MAX; 1135 fc.namespace = namespace;
1136 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1137 &hc, &find_trees, &fc);
1138 if (fc.id == UINT_MAX)
1139 {
1140 /* start new TREE */
1141 for (fc.id = 0; fc.id < fc.tree_array_size; fc.id++)
1142 {
1143 if (fc.tree_array[fc.id] == NULL)
1144 {
1145 fc.tree_array[fc.id] = nsn;
1146 nsn->tree_id = fc.id;
1147 break;
1148 }
1149 }
1150 if (fc.id == fc.tree_array_size)
1151 {
1152 GNUNET_array_append (fc.tree_array, fc.tree_array_size, nsn);
1153 nsn->tree_id = fc.id;
1154 }
1155#if DEBUG_NAMESPACE
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1157 "Starting new TREE %u with node `%s'\n",
1158 nsn->tree_id, nsn->id);
1159#endif
1160 /* put all nodes with same identifier into this TREE */
1161 GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
1162 fc.id = nsn->tree_id;
1220 fc.nug = nug; 1163 fc.nug = nug;
1221 fc.namespace = namespace; 1164 fc.namespace = namespace;
1222 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map, 1165 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1223 &hc, 1166 &hc, &find_trees, &fc);
1224 &find_trees, 1167 }
1225 &fc); 1168 else
1226 if (fc.id == UINT_MAX) 1169 {
1227 { 1170 /* make head of TREE "id" */
1228 /* start new TREE */ 1171 fc.tree_array[fc.id] = nsn;
1229 for (fc.id=0;fc.id<fc.tree_array_size;fc.id++) 1172 nsn->tree_id = fc.id;
1230 { 1173 }
1231 if (fc.tree_array[fc.id] == NULL)
1232 {
1233 fc.tree_array[fc.id] = nsn;
1234 nsn->tree_id = fc.id;
1235 break;
1236 }
1237 }
1238 if (fc.id == fc.tree_array_size)
1239 {
1240 GNUNET_array_append (fc.tree_array,
1241 fc.tree_array_size,
1242 nsn);
1243 nsn->tree_id = fc.id;
1244 }
1245#if DEBUG_NAMESPACE
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "Starting new TREE %u with node `%s'\n",
1248 nsn->tree_id,
1249 nsn->id);
1250#endif
1251 /* put all nodes with same identifier into this TREE */
1252 GNUNET_CRYPTO_hash (nsn->id,
1253 strlen (nsn->id),
1254 &hc);
1255 fc.id = nsn->tree_id;
1256 fc.nug = nug;
1257 fc.namespace = namespace;
1258 GNUNET_CONTAINER_multihashmap_get_multiple (namespace->update_map,
1259 &hc,
1260 &find_trees,
1261 &fc);
1262 }
1263 else
1264 {
1265 /* make head of TREE "id" */
1266 fc.tree_array[fc.id] = nsn;
1267 nsn->tree_id = fc.id;
1268 }
1269#if DEBUG_NAMESPACE 1174#if DEBUG_NAMESPACE
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1271 "TREE of node `%s' is %u\n", 1176 "TREE of node `%s' is %u\n", nsn->id, fc.id);
1272 nsn->id,
1273 fc.id);
1274#endif 1177#endif
1275 } 1178 }
1276 for (i=0;i<fc.tree_array_size;i++) 1179 for (i = 0; i < fc.tree_array_size; i++)
1180 {
1181 nsn = fc.tree_array[i];
1182 if (NULL != nsn)
1277 { 1183 {
1278 nsn = fc.tree_array[i];
1279 if (NULL != nsn)
1280 {
1281#if DEBUG_NAMESPACE 1184#if DEBUG_NAMESPACE
1282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1283 "Root of TREE %u is node `%s'\n", 1186 "Root of TREE %u is node `%s'\n", i, nsn->id);
1284 i,
1285 nsn->id);
1286#endif 1187#endif
1287 1188
1288 ip (ip_cls, 1189 ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
1289 nsn->id,
1290 nsn->uri,
1291 nsn->md,
1292 nsn->update);
1293 }
1294 } 1190 }
1295 GNUNET_array_grow (fc.tree_array, 1191 }
1296 fc.tree_array_size, 1192 GNUNET_array_grow (fc.tree_array, fc.tree_array_size, 0);
1297 0);
1298#if DEBUG_NAMESPACE 1193#if DEBUG_NAMESPACE
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done processing TREEs\n");
1300 "Done processing TREEs\n");
1301#endif 1195#endif
1302} 1196}
1303 1197
1304 1198
1305/* end of fs_namespace.c */ 1199/* end of fs_namespace.c */
1306