aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fs/Makefile.am1
-rw-r--r--src/fs/fs.h15
-rw-r--r--src/fs/fs_api.h18
-rw-r--r--src/fs/fs_namespace.c288
-rw-r--r--src/fs/fs_namespace_advertise.c363
-rw-r--r--src/fs/fs_publish_ksk.c89
-rw-r--r--src/fs/fs_search.c249
-rw-r--r--src/fs/fs_unindex.c84
-rw-r--r--src/fs/fs_uri.c71
-rw-r--r--src/fs/gnunet-pseudonym.c41
-rw-r--r--src/fs/gnunet-service-fs.c4
-rw-r--r--src/fs/gnunet-service-fs.h6
-rw-r--r--src/fs/gnunet-service-fs_cp.c18
-rw-r--r--src/fs/gnunet-service-fs_lc.c12
-rw-r--r--src/fs/gnunet-service-fs_pr.c36
-rw-r--r--src/fs/gnunet-service-fs_pr.h8
-rw-r--r--src/fs/gnunet-service-fs_put.c4
-rw-r--r--src/fs/plugin_block_fs.c181
-rw-r--r--src/fs/test_fs_namespace.c182
-rw-r--r--src/fs/test_fs_uri.c23
-rw-r--r--src/include/block_fs.h98
-rw-r--r--src/include/gnunet_block_lib.h102
-rw-r--r--src/include/gnunet_fs_service.h121
-rw-r--r--src/include/gnunet_pseudonym_lib.h271
-rw-r--r--src/include/gnunet_signatures.h12
-rw-r--r--src/util/pseudonym.c669
-rw-r--r--src/util/strings.c5
-rw-r--r--src/util/test_pseudonym.c109
28 files changed, 1299 insertions, 1781 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 84c0a61d9..54267c57c 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -38,7 +38,6 @@ libgnunetfs_la_SOURCES = \
38 fs_publish_ksk.c \ 38 fs_publish_ksk.c \
39 fs_misc.c \ 39 fs_misc.c \
40 fs_namespace.c \ 40 fs_namespace.c \
41 fs_namespace_advertise.c \
42 fs_search.c \ 41 fs_search.c \
43 fs_sharetree.c \ 42 fs_sharetree.c \
44 fs_tree.c fs_tree.h \ 43 fs_tree.c fs_tree.h \
diff --git a/src/fs/fs.h b/src/fs/fs.h
index ffd448d2b..9a987303b 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -240,26 +240,21 @@ struct SearchMessage
240 * nevertheless, we should probably not use it for a DHT-lookup 240 * nevertheless, we should probably not use it for a DHT-lookup
241 * or similar blunt actions in order to avoid exposing ourselves). 241 * or similar blunt actions in order to avoid exposing ourselves).
242 * <p> 242 * <p>
243 * If the request is for an SBLOCK, this is the identity of the 243 * Otherwise, "target" must be all zeros.
244 * pseudonym to which the SBLOCK belongs.
245 * <p>
246 * If the request is for a KBLOCK, "target" must be all zeros.
247 */ 244 */
248 struct GNUNET_HashCode target; 245 struct GNUNET_HashCode target;
249 246
250 /** 247 /**
251 * Hash of the keyword (aka query) for KBLOCKs; Hash of 248 * Hash of the public key for UBLOCKs; Hash of
252 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query) 249 * the CHK-encoded block for DBLOCKS and IBLOCKS.
253 * and hash of the identifier XORed with the target for
254 * SBLOCKS (aka query).
255 */ 250 */
256 struct GNUNET_HashCode query; 251 struct GNUNET_HashCode query;
257 252
258 /* this is followed by the hash codes of already-known 253 /* this is followed by the hash codes of already-known
259 * results (which should hence be excluded from what 254 * results (which should hence be excluded from what
260 * the service returns); naturally, this only applies 255 * the service returns); naturally, this only applies
261 * to queries that can have multiple results, such as 256 * to queries that can have multiple results (UBLOCKS).
262 * those for KBLOCKS (KSK) and SBLOCKS (SKS) */ 257 */
263}; 258};
264 259
265 260
diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h
index 61a568fa0..b2744237e 100644
--- a/src/fs/fs_api.h
+++ b/src/fs/fs_api.h
@@ -204,9 +204,9 @@ struct GNUNET_FS_Uri
204 struct 204 struct
205 { 205 {
206 /** 206 /**
207 * Hash of the public key for the namespace. 207 * Identifier of the namespace.
208 */ 208 */
209 struct GNUNET_HashCode ns; 209 struct GNUNET_PseudonymIdentifier ns;
210 210
211 /** 211 /**
212 * Human-readable identifier chosen for this 212 * Human-readable identifier chosen for this
@@ -1390,14 +1390,14 @@ struct GNUNET_FS_UnindexContext
1390 struct GNUNET_DATASTORE_QueueEntry *dqe; 1390 struct GNUNET_DATASTORE_QueueEntry *dqe;
1391 1391
1392 /** 1392 /**
1393 * Current key for decrypting KBLocks from 'get_key' operation. 1393 * Current key for decrypting UBLocks from 'get_key' operation.
1394 */ 1394 */
1395 struct GNUNET_HashCode key; 1395 struct GNUNET_HashCode ukey;
1396 1396
1397 /** 1397 /**
1398 * Current query of 'get_key' operation. 1398 * Current query of 'get_key' operation.
1399 */ 1399 */
1400 struct GNUNET_HashCode query; 1400 struct GNUNET_HashCode uquery;
1401 1401
1402 /** 1402 /**
1403 * First content UID, 0 for none. 1403 * First content UID, 0 for none.
@@ -1449,15 +1449,15 @@ struct GNUNET_FS_UnindexContext
1449struct SearchRequestEntry 1449struct SearchRequestEntry
1450{ 1450{
1451 /** 1451 /**
1452 * Hash of the original keyword, also known as the 1452 * Hash of the original keyword, used to derive the
1453 * key (for decrypting the KBlock). 1453 * key (for decrypting the KBlock).
1454 */ 1454 */
1455 struct GNUNET_HashCode key; 1455 struct GNUNET_HashCode ukey;
1456 1456
1457 /** 1457 /**
1458 * Hash of the public key, also known as the query. 1458 * Hash of the public key, also known as the query.
1459 */ 1459 */
1460 struct GNUNET_HashCode query; 1460 struct GNUNET_HashCode uquery;
1461 1461
1462 /** 1462 /**
1463 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that 1463 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
@@ -2008,7 +2008,7 @@ struct GNUNET_FS_Namespace
2008 /** 2008 /**
2009 * Private key for the namespace. 2009 * Private key for the namespace.
2010 */ 2010 */
2011 struct GNUNET_CRYPTO_RsaPrivateKey *key; 2011 struct GNUNET_PseudonymHandle *key;
2012 2012
2013 /** 2013 /**
2014 * Hash map mapping identifiers of update nodes 2014 * Hash map mapping identifiers of update nodes
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c
index 3cc3ca299..87ddb667f 100644
--- a/src/fs/fs_namespace.c
+++ b/src/fs/fs_namespace.c
@@ -32,49 +32,6 @@
32 32
33 33
34/** 34/**
35 * Maximum legal size for an sblock.
36 */
37#define MAX_SBLOCK_SIZE (60 * 1024)
38
39
40/**
41 * Context for creating a namespace asynchronously.
42 */
43struct GNUNET_FS_NamespaceCreationContext
44{
45 /**
46 * Context for asynchronous key creation.
47 */
48 struct GNUNET_CRYPTO_RsaKeyGenerationContext *keycreator;
49
50 /**
51 * Name of the file to store key in / read key from.
52 */
53 char *filename;
54
55 /**
56 * Name of the namespace.
57 */
58 char *name;
59
60 /**
61 * Global fs handle
62 */
63 struct GNUNET_FS_Handle *h;
64
65 /**
66 * Function to call when generation ends (successfully or not)
67 */
68 GNUNET_FS_NamespaceCreationCallback cont;
69
70 /**
71 * Client value to pass to continuation function.
72 */
73 void *cont_cls;
74};
75
76
77/**
78 * Return the name of the directory in which we store 35 * Return the name of the directory in which we store
79 * our local namespaces (or rather, their public keys). 36 * our local namespaces (or rather, their public keys).
80 * 37 *
@@ -288,7 +245,7 @@ GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name)
288 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); 245 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
289 ret->h = h; 246 ret->h = h;
290 ret->rc = 1; 247 ret->rc = 1;
291 ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn); 248 ret->key = GNUNET_PSEUDONYM_create (fn);
292 if (NULL == ret->key) 249 if (NULL == ret->key)
293 { 250 {
294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -332,7 +289,7 @@ GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name)
332 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); 289 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
333 ret->h = h; 290 ret->h = h;
334 ret->rc = 1; 291 ret->rc = 1;
335 ret->key = GNUNET_CRYPTO_rsa_key_create_from_existing_file (fn); 292 ret->key = GNUNET_PSEUDONYM_create_from_existing_file (fn);
336 if (NULL == ret->key) 293 if (NULL == ret->key)
337 { 294 {
338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -348,118 +305,6 @@ GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name)
348 305
349 306
350/** 307/**
351 * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_start'.
352 *
353 * @param cls closure
354 * @param pk NULL on error, otherwise the private key (which must be free'd by the callee)
355 * @param emsg NULL on success, otherwise an error message
356 */
357static void
358ns_key_created (void *cls, struct GNUNET_CRYPTO_RsaPrivateKey *pk,
359 const char *emsg)
360{
361 struct GNUNET_FS_NamespaceCreationContext *ncc = cls;
362
363 ncc->keycreator = NULL;
364
365 if (pk)
366 {
367 struct GNUNET_FS_Namespace *ret;
368 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
369 ret->rc = 1;
370 ret->key = pk;
371 ret->h = ncc->h;
372 ret->name = ncc->name;
373 ret->filename = ncc->filename;
374 ncc->cont (ncc->cont_cls, ret, NULL);
375 }
376 else
377 {
378 GNUNET_free (ncc->filename);
379 GNUNET_free (ncc->name);
380 ncc->cont (ncc->cont_cls, NULL, emsg);
381 }
382 GNUNET_free (ncc);
383}
384
385
386/**
387 * Create a namespace with the given name.
388 * If one already exists, the continuation will be called with a handle to
389 * the existing namespace.
390 * Otherwise creates a new namespace.
391 *
392 * @param h handle to the file sharing subsystem
393 * @param name name to use for the namespace
394 * @return namespace creation context, NULL on error (i.e. invalid filename)
395 */
396struct GNUNET_FS_NamespaceCreationContext *
397GNUNET_FS_namespace_create_start (struct GNUNET_FS_Handle *h, const char *name,
398 GNUNET_FS_NamespaceCreationCallback cont, void *cont_cls)
399{
400 char *dn;
401 char *fn;
402 struct GNUNET_FS_NamespaceCreationContext *ret;
403
404 dn = get_namespace_directory (h);
405 if (NULL == dn)
406 {
407 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
408 _("Can't determine where namespace directory is\n"));
409 return NULL;
410 }
411 GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name);
412 GNUNET_free (dn);
413
414 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_NamespaceCreationContext));
415 ret->filename = fn;
416 ret->h = h;
417 ret->name = GNUNET_strdup (name);
418 ret->cont = cont;
419 ret->cont_cls = cont_cls;
420
421 ret->keycreator = GNUNET_CRYPTO_rsa_key_create_start (fn,
422 ns_key_created, ret);
423
424 if (NULL == ret->keycreator)
425 {
426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
427 _("Failed to start creating or reading private key for namespace `%s'\n"),
428 name);
429 GNUNET_free (fn);
430 GNUNET_free (ret->name);
431 GNUNET_free (ret);
432 return NULL;
433 }
434 return ret;
435}
436
437
438/**
439 * Abort namespace creation.
440 *
441 * @param ncc namespace creation context to abort
442 */
443void
444GNUNET_FS_namespace_create_stop (struct GNUNET_FS_NamespaceCreationContext *ncc)
445{
446 if (NULL != ncc->keycreator)
447 {
448 GNUNET_CRYPTO_rsa_key_create_stop (ncc->keycreator);
449 ncc->keycreator = NULL;
450 }
451 if (NULL != ncc->filename)
452 {
453 if (0 != UNLINK (ncc->filename))
454 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", ncc->filename);
455 GNUNET_free (ncc->filename);
456 }
457 GNUNET_free_non_null (ncc->name);
458 GNUNET_free (ncc);
459}
460
461
462/**
463 * Rename a local namespace. 308 * Rename a local namespace.
464 * 309 *
465 * @param h handle to the file sharing subsystem 310 * @param h handle to the file sharing subsystem
@@ -468,7 +313,9 @@ GNUNET_FS_namespace_create_stop (struct GNUNET_FS_NamespaceCreationContext *ncc)
468 * @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details) 313 * @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details)
469 */ 314 */
470int 315int
471GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name, const char *new_name) 316GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h,
317 const char *old_name,
318 const char *new_name)
472{ 319{
473 char *dn; 320 char *dn;
474 char *fn_old; 321 char *fn_old;
@@ -496,6 +343,7 @@ GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name, co
496 return GNUNET_SYSERR; 343 return GNUNET_SYSERR;
497} 344}
498 345
346
499/** 347/**
500 * Duplicate a namespace handle. 348 * Duplicate a namespace handle.
501 * 349 *
@@ -536,7 +384,7 @@ GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze)
536 } 384 }
537 if (0 != ns->rc) 385 if (0 != ns->rc)
538 return GNUNET_OK; 386 return GNUNET_OK;
539 GNUNET_CRYPTO_rsa_key_free (ns->key); 387 GNUNET_PSEUDONYM_destroy (ns->key);
540 GNUNET_free (ns->filename); 388 GNUNET_free (ns->filename);
541 GNUNET_free (ns->name); 389 GNUNET_free (ns->name);
542 for (i = 0; i < ns->update_node_count; i++) 390 for (i = 0; i < ns->update_node_count; i++)
@@ -584,12 +432,12 @@ struct ProcessNamespaceContext
584 * GNUNET_SYSERR on failure (contents of id remain intact) 432 * GNUNET_SYSERR on failure (contents of id remain intact)
585 */ 433 */
586int 434int
587GNUNET_FS_namespace_get_public_key_hash (struct GNUNET_FS_Namespace *ns, 435GNUNET_FS_namespace_get_public_identifier (struct GNUNET_FS_Namespace *ns,
588 struct GNUNET_HashCode *id) 436 struct GNUNET_PseudonymIdentifier *id)
589{ 437{
590 if ((NULL == ns) || (NULL == id)) 438 if ((NULL == ns) || (NULL == id))
591 return GNUNET_SYSERR; 439 return GNUNET_SYSERR;
592 GNUNET_CRYPTO_rsa_get_public_key_hash (ns->key, id); 440 GNUNET_PSEUDONYM_get_identifier (ns->key, id);
593 return GNUNET_OK; 441 return GNUNET_OK;
594} 442}
595 443
@@ -607,13 +455,12 @@ static int
607process_namespace (void *cls, const char *filename) 455process_namespace (void *cls, const char *filename)
608{ 456{
609 struct ProcessNamespaceContext *pnc = cls; 457 struct ProcessNamespaceContext *pnc = cls;
610 struct GNUNET_CRYPTO_RsaPrivateKey *key; 458 struct GNUNET_PseudonymHandle *ph;
611 struct GNUNET_HashCode id; 459 struct GNUNET_PseudonymIdentifier id;
612 const char *name; 460 const char *name;
613 const char *t; 461 const char *t;
614 462
615 key = GNUNET_CRYPTO_rsa_key_create_from_file (filename); 463 if (NULL == (ph = GNUNET_PSEUDONYM_create (filename)))
616 if (NULL == key)
617 { 464 {
618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 465 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
619 _ 466 _
@@ -623,8 +470,8 @@ process_namespace (void *cls, const char *filename)
623 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); 470 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
624 return GNUNET_OK; 471 return GNUNET_OK;
625 } 472 }
626 GNUNET_CRYPTO_rsa_get_public_key_hash (key, &id); 473 GNUNET_PSEUDONYM_get_identifier (ph, &id);
627 GNUNET_CRYPTO_rsa_key_free (key); 474 GNUNET_PSEUDONYM_destroy (ph);
628 name = filename; 475 name = filename;
629 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR))) 476 while (NULL != (t = strstr (name, DIR_SEPARATOR_STR)))
630 name = t + 1; 477 name = t + 1;
@@ -705,7 +552,7 @@ struct GNUNET_FS_PublishSksContext
705 552
706/** 553/**
707 * Function called by the datastore API with 554 * Function called by the datastore API with
708 * the result from the PUT (SBlock) request. 555 * the result from the PUT (UBlock) request.
709 * 556 *
710 * @param cls closure of type "struct GNUNET_FS_PublishSksContext*" 557 * @param cls closure of type "struct GNUNET_FS_PublishSksContext*"
711 * @param success GNUNET_OK on success 558 * @param success GNUNET_OK on success
@@ -737,7 +584,7 @@ sb_put_cont (void *cls, int success,
737 read_update_information_graph (psc->ns); 584 read_update_information_graph (psc->ns);
738 GNUNET_array_append (psc->ns->update_nodes, 585 GNUNET_array_append (psc->ns->update_nodes,
739 psc->ns->update_node_count, psc->nsn); 586 psc->ns->update_node_count, psc->nsn);
740 if (psc->ns->update_map != NULL) 587 if (NULL != psc->ns->update_map)
741 { 588 {
742 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc); 589 GNUNET_CRYPTO_hash (psc->nsn->id, strlen (psc->nsn->id), &hc);
743 GNUNET_CONTAINER_multihashmap_put (psc->ns->update_map, &hc, 590 GNUNET_CONTAINER_multihashmap_put (psc->ns->update_map, &hc,
@@ -788,13 +635,15 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
788 size_t nidlen; 635 size_t nidlen;
789 size_t idlen; 636 size_t idlen;
790 ssize_t mdsize; 637 ssize_t mdsize;
791 struct SBlock *sb; 638 struct UBlock *ub;
792 struct SBlock *sb_enc; 639 struct UBlock *ub_enc;
793 char *dest; 640 char *dest;
794 struct GNUNET_CONTAINER_MetaData *mmeta; 641 struct GNUNET_CONTAINER_MetaData *mmeta;
795 struct GNUNET_HashCode key; /* hash of thisId = key */ 642 struct GNUNET_HashCode id_hash; /* hash of thisId */
796 struct GNUNET_HashCode id; /* hash of hc = identifier */ 643 struct GNUNET_HashCode ns_hash; /* hash of namespace public key */
797 struct GNUNET_HashCode query; /* id ^ nsid = DB query */ 644 struct GNUNET_HashCode key; /* id_hash ^ ns_hash, for AES key */
645 struct GNUNET_HashCode signing_key; /* H(key) = input for public key */
646 struct GNUNET_HashCode query; /* H(verification_key) = query */
798 647
799 idlen = strlen (identifier); 648 idlen = strlen (identifier);
800 if (NULL != update) 649 if (NULL != update)
@@ -803,11 +652,11 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
803 nidlen = 1; 652 nidlen = 1;
804 uris = GNUNET_FS_uri_to_string (uri); 653 uris = GNUNET_FS_uri_to_string (uri);
805 slen = strlen (uris) + 1; 654 slen = strlen (uris) + 1;
806 if ( (slen >= MAX_SBLOCK_SIZE - sizeof (struct SBlock)) || 655 if ( (slen >= MAX_UBLOCK_SIZE - sizeof (struct UBlock)) ||
807 (nidlen >= MAX_SBLOCK_SIZE - sizeof (struct SBlock) - slen) ) 656 (nidlen >= MAX_UBLOCK_SIZE - sizeof (struct UBlock) - slen) )
808 { 657 {
809 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
810 _("Identifiers or URI too long to create SBlock")); 659 _("Identifiers or URI too long to create UBlock"));
811 GNUNET_free (uris); 660 GNUNET_free (uris);
812 return NULL; 661 return NULL;
813 } 662 }
@@ -816,15 +665,15 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
816 else 665 else
817 mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); 666 mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
818 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta); 667 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta);
819 size = sizeof (struct SBlock) + slen + nidlen + mdsize; 668 size = sizeof (struct UBlock) + slen + nidlen + mdsize;
820 if ( (size > MAX_SBLOCK_SIZE) || 669 if ( (size > MAX_UBLOCK_SIZE) ||
821 (size < sizeof (struct SBlock) + slen + nidlen) ) 670 (size < sizeof (struct UBlock) + slen + nidlen) )
822 { 671 {
823 size = MAX_SBLOCK_SIZE; 672 size = MAX_UBLOCK_SIZE;
824 mdsize = MAX_SBLOCK_SIZE - (sizeof (struct SBlock) + slen + nidlen); 673 mdsize = MAX_UBLOCK_SIZE - (sizeof (struct UBlock) + slen + nidlen);
825 } 674 }
826 sb = GNUNET_malloc (sizeof (struct SBlock) + size); 675 ub = GNUNET_malloc (sizeof (struct UBlock) + size);
827 dest = (char *) &sb[1]; 676 dest = (char *) &ub[1];
828 if (NULL != update) 677 if (NULL != update)
829 memcpy (dest, update, nidlen); 678 memcpy (dest, update, nidlen);
830 else 679 else
@@ -840,34 +689,44 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
840 if (-1 == mdsize) 689 if (-1 == mdsize)
841 { 690 {
842 GNUNET_break (0); 691 GNUNET_break (0);
843 GNUNET_free (sb); 692 GNUNET_free (ub);
844 if (NULL != cont) 693 if (NULL != cont)
845 cont (cont_cls, NULL, _("Internal error.")); 694 cont (cont_cls, NULL, _("Internal error."));
846 return NULL; 695 return NULL;
847 } 696 }
848 size = sizeof (struct SBlock) + mdsize + slen + nidlen;
849 sb_enc = GNUNET_malloc (size);
850 GNUNET_CRYPTO_hash (identifier, idlen, &key);
851 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &id);
852 sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 697 sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
853 sks_uri->type = GNUNET_FS_URI_SKS; 698 sks_uri->type = GNUNET_FS_URI_SKS;
854 GNUNET_CRYPTO_rsa_key_get_public (ns->key, &sb_enc->subspace);
855 GNUNET_CRYPTO_hash (&sb_enc->subspace,
856 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
857 &sks_uri->data.sks.ns);
858 sks_uri->data.sks.identifier = GNUNET_strdup (identifier); 699 sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
859 GNUNET_CRYPTO_hash_xor (&id, &sks_uri->data.sks.ns, 700 GNUNET_FS_namespace_get_public_identifier (ns,
860 &sb_enc->identifier); 701 &sks_uri->data.sks.ns);
702
703 size = sizeof (struct UBlock) + mdsize + slen + nidlen;
704 ub_enc = GNUNET_malloc (size);
705 GNUNET_CRYPTO_hash (identifier, idlen, &id_hash);
706 GNUNET_CRYPTO_hash (&sks_uri->data.sks.ns,
707 sizeof (sks_uri->data.sks.ns), &ns_hash);
708 GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
861 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); 709 GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
862 GNUNET_CRYPTO_aes_encrypt (&sb[1], size - sizeof (struct SBlock), &sk, &iv, 710 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &signing_key);
863 &sb_enc[1]); 711
864 sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); 712 GNUNET_CRYPTO_aes_encrypt (&ub[1],
865 sb_enc->purpose.size = 713 size - sizeof (struct UBlock),
866 htonl (slen + mdsize + nidlen + sizeof (struct SBlock) - 714 &sk, &iv,
867 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 715 &ub_enc[1]);
868 GNUNET_assert (GNUNET_OK == 716 ub_enc->purpose.size = htonl (nidlen + slen + mdsize + sizeof (struct UBlock)
869 GNUNET_CRYPTO_rsa_sign (ns->key, &sb_enc->purpose, 717 - sizeof (struct GNUNET_PseudonymSignature));
870 &sb_enc->signature)); 718 ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK);
719 GNUNET_PSEUDONYM_sign (ns->key,
720 &ub_enc->purpose,
721 NULL,
722 &signing_key,
723 &ub_enc->signature);
724 GNUNET_PSEUDONYM_derive_verification_key (&sks_uri->data.sks.ns,
725 &signing_key,
726 &ub_enc->verification_key);
727 GNUNET_CRYPTO_hash (&ub_enc->verification_key,
728 sizeof (ub_enc->verification_key),
729 &query);
871 psc = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishSksContext)); 730 psc = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishSksContext));
872 psc->uri = sks_uri; 731 psc->uri = sks_uri;
873 psc->cont = cont; 732 psc->cont = cont;
@@ -875,20 +734,20 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
875 psc->cont_cls = cont_cls; 734 psc->cont_cls = cont_cls;
876 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 735 if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
877 { 736 {
878 GNUNET_free (sb_enc); 737 GNUNET_free (ub_enc);
879 GNUNET_free (sb); 738 GNUNET_free (ub);
880 sb_put_cont (psc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); 739 sb_put_cont (psc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
881 return NULL; 740 return NULL;
882 } 741 }
883 psc->dsh = GNUNET_DATASTORE_connect (h->cfg); 742 psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
884 if (NULL == psc->dsh) 743 if (NULL == psc->dsh)
885 { 744 {
886 GNUNET_free (sb_enc); 745 GNUNET_free (ub_enc);
887 GNUNET_free (sb); 746 GNUNET_free (ub);
888 sb_put_cont (psc, GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, _("Failed to connect to datastore.")); 747 sb_put_cont (psc, GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, _("Failed to connect to datastore."));
889 return NULL; 748 return NULL;
890 } 749 }
891 GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.ns, &id, &query); 750
892 if (NULL != update) 751 if (NULL != update)
893 { 752 {
894 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode)); 753 psc->nsn = GNUNET_malloc (sizeof (struct NamespaceUpdateNode));
@@ -897,13 +756,14 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
897 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta); 756 psc->nsn->md = GNUNET_CONTAINER_meta_data_duplicate (meta);
898 psc->nsn->uri = GNUNET_FS_uri_dup (uri); 757 psc->nsn->uri = GNUNET_FS_uri_dup (uri);
899 } 758 }
900 psc->dqe = GNUNET_DATASTORE_put (psc->dsh, 0, &sb_enc->identifier, size, sb_enc, 759
901 GNUNET_BLOCK_TYPE_FS_SBLOCK, bo->content_priority, 760 psc->dqe = GNUNET_DATASTORE_put (psc->dsh, 0, &query, size, ub_enc,
761 GNUNET_BLOCK_TYPE_FS_UBLOCK, bo->content_priority,
902 bo->anonymity_level, bo->replication_level, 762 bo->anonymity_level, bo->replication_level,
903 bo->expiration_time, -2, 1, 763 bo->expiration_time, -2, 1,
904 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc); 764 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &sb_put_cont, psc);
905 GNUNET_free (sb); 765 GNUNET_free (ub);
906 GNUNET_free (sb_enc); 766 GNUNET_free (ub_enc);
907 return psc; 767 return psc;
908} 768}
909 769
diff --git a/src/fs/fs_namespace_advertise.c b/src/fs/fs_namespace_advertise.c
deleted file mode 100644
index 554f61657..000000000
--- a/src/fs/fs_namespace_advertise.c
+++ /dev/null
@@ -1,363 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file fs/fs_namespace_advertise.c
23 * @brief advertise namespaces (creating NBlocks)
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_constants.h"
28#include "gnunet_signatures.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_fs_service.h"
31#include "fs_api.h"
32
33
34/**
35 * Maximum legal size for an nblock.
36 */
37#define MAX_NBLOCK_SIZE (60 * 1024)
38
39
40/**
41 * Context for advertising a namespace.
42 */
43struct GNUNET_FS_AdvertisementContext
44{
45 /**
46 * Function to call with the result.
47 */
48 GNUNET_FS_PublishContinuation cont;
49
50 /**
51 * Closure for cont.
52 */
53 void *cont_cls;
54
55 /**
56 * Datastore handle.
57 */
58 struct GNUNET_DATASTORE_Handle *dsh;
59
60 /**
61 * Our KSK URI.
62 */
63 struct GNUNET_FS_Uri *ksk_uri;
64
65 /**
66 * Plaintext.
67 */
68 char *pt;
69
70 /**
71 * NBlock to sign and store.
72 */
73 struct NBlock *nb;
74
75 /**
76 * The namespace.
77 */
78 struct GNUNET_FS_Namespace *ns;
79
80 /**
81 * Current datastore queue entry for advertising.
82 */
83 struct GNUNET_DATASTORE_QueueEntry *dqe;
84
85 /**
86 * Block options.
87 */
88 struct GNUNET_FS_BlockOptions bo;
89
90 /**
91 * Number of bytes of plaintext.
92 */
93 size_t pt_size;
94
95 /**
96 * Current keyword offset.
97 */
98 unsigned int pos;
99};
100
101
102// FIXME: I see no good reason why this should need to be done
103// in a new task (anymore). Integrate with 'cancel' function below?
104/**
105 * Disconnect from the datastore.
106 *
107 * @param cls datastore handle
108 * @param tc scheduler context
109 */
110static void
111do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
112{
113 struct GNUNET_DATASTORE_Handle *dsh = cls;
114
115 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
116}
117
118
119/**
120 * Continuation called to notify client about result of the
121 * operation.
122 *
123 * @param cls closure (our struct GNUNET_FS_AdvertismentContext)
124 * @param success GNUNET_SYSERR on failure
125 * @param min_expiration minimum expiration time required for content to be stored
126 * @param msg NULL on success, otherwise an error message
127 */
128static void
129advertisement_cont (void *cls, int success,
130 struct GNUNET_TIME_Absolute min_expiration,
131 const char *msg)
132{
133 struct GNUNET_FS_AdvertisementContext *ac = cls;
134 const char *keyword;
135 struct GNUNET_HashCode key;
136 struct GNUNET_HashCode query;
137 struct GNUNET_CRYPTO_AesSessionKey skey;
138 struct GNUNET_CRYPTO_AesInitializationVector iv;
139 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
140
141 ac->dqe = NULL;
142 if (GNUNET_SYSERR == success)
143 {
144 /* error! */
145 (void) GNUNET_SCHEDULER_add_now (&do_disconnect, ac->dsh);
146 ac->dsh = NULL;
147 if (msg == NULL)
148 {
149 GNUNET_break (0);
150 msg = _("Unknown error");
151 }
152 if (ac->cont != NULL)
153 {
154 ac->cont (ac->cont_cls, NULL, msg);
155 ac->cont = NULL;
156 }
157 GNUNET_FS_namespace_advertise_cancel (ac);
158 return;
159 }
160 if (ac->pos == ac->ksk_uri->data.ksk.keywordCount)
161 {
162 /* done! */
163 (void) GNUNET_SCHEDULER_add_now (&do_disconnect, ac->dsh);
164 ac->dsh = NULL;
165 if (ac->cont != NULL)
166 {
167 ac->cont (ac->cont_cls, ac->ksk_uri, NULL);
168 ac->cont = NULL;
169 }
170 GNUNET_FS_namespace_advertise_cancel (ac);
171 return;
172 }
173 keyword = ac->ksk_uri->data.ksk.keywords[ac->pos++];
174 /* first character of keyword indicates if it is
175 * mandatory or not -- ignore for hashing */
176 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
177 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
178 GNUNET_CRYPTO_aes_encrypt (ac->pt, ac->pt_size, &skey, &iv, &ac->nb[1]);
179 GNUNET_break (GNUNET_OK ==
180 GNUNET_CRYPTO_rsa_sign (ac->ns->key, &ac->nb->ns_purpose,
181 &ac->nb->ns_signature));
182 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key);
183 GNUNET_assert (pk != NULL);
184 GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace);
185 GNUNET_CRYPTO_hash (&ac->nb->keyspace,
186 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
187 &query);
188 GNUNET_break (GNUNET_OK ==
189 GNUNET_CRYPTO_rsa_sign (pk, &ac->nb->ksk_purpose,
190 &ac->nb->ksk_signature));
191 GNUNET_CRYPTO_rsa_key_free (pk);
192 ac->dqe = GNUNET_DATASTORE_put (ac->dsh, 0 /* no reservation */ ,
193 &query, ac->pt_size + sizeof (struct NBlock), ac->nb,
194 GNUNET_BLOCK_TYPE_FS_NBLOCK, ac->bo.content_priority,
195 ac->bo.anonymity_level, ac->bo.replication_level,
196 ac->bo.expiration_time, -2, 1,
197 GNUNET_CONSTANTS_SERVICE_TIMEOUT, &advertisement_cont,
198 ac);
199}
200
201
202/**
203 * Create an SKS uri that points to the root entry of the namespace,
204 * then insert that SKS uri into metadata.
205 *
206 * @param ns handle for the namespace that should be advertised
207 * @param meta meta-data into which namespace advertisement should be inserted
208 * @param rootEntry name of the root of the namespace (use NULL to use default)
209 * @return GNUNET_OK on success, GNUNET_SYSERR on error
210 */
211int
212GNUNET_FS_namespace_insert_advertisement_into_metadata (
213 struct GNUNET_FS_Namespace *ns, struct GNUNET_CONTAINER_MetaData *meta,
214 const char *rootEntry)
215{
216 struct GNUNET_FS_Uri *sks_uri;
217 char *emsg;
218 char *sks_uri_string;
219 int md_insert;
220
221 if (NULL == rootEntry)
222 rootEntry = "/";
223
224 emsg = NULL;
225 sks_uri = GNUNET_FS_uri_sks_create (ns, rootEntry, &emsg);
226 GNUNET_free_non_null (emsg);
227 if (NULL == sks_uri)
228 return GNUNET_SYSERR;
229
230 sks_uri_string = GNUNET_FS_uri_to_string (sks_uri);
231 GNUNET_FS_uri_destroy (sks_uri);
232 if (NULL == sks_uri_string)
233 return GNUNET_SYSERR;
234
235 md_insert = GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>",
236 EXTRACTOR_METATYPE_URI, EXTRACTOR_METAFORMAT_UTF8,
237 "text/plain", sks_uri_string, strlen (sks_uri_string) + 1);
238 GNUNET_free (sks_uri_string);
239 return md_insert;
240}
241
242/**
243 * Publish an advertismement for a namespace.
244 *
245 * @param h handle to the file sharing subsystem
246 * @param ksk_uri keywords to use for advertisment
247 * @param ns handle for the namespace that should be advertised
248 * @param meta meta-data for the namespace advertisement
249 * @param bo block options
250 * @param rootEntry name of the root of the namespace
251 * @param cont continuation
252 * @param cont_cls closure for cont
253 * @return NULL on error ('cont' is still called)
254 */
255struct GNUNET_FS_AdvertisementContext *
256GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
257 struct GNUNET_FS_Uri *ksk_uri,
258 struct GNUNET_FS_Namespace *ns,
259 const struct GNUNET_CONTAINER_MetaData *meta,
260 const struct GNUNET_FS_BlockOptions *bo,
261 const char *rootEntry,
262 GNUNET_FS_PublishContinuation cont,
263 void *cont_cls)
264{
265 size_t reslen;
266 size_t size;
267 ssize_t mdsize;
268 struct NBlock *nb;
269 char *mdst;
270 struct GNUNET_DATASTORE_Handle *dsh;
271 struct GNUNET_FS_AdvertisementContext *ctx;
272 char *pt;
273
274 /* create advertisements */
275 mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
276 if (-1 == mdsize)
277 {
278 cont (cont_cls, NULL, _("Failed to serialize meta data"));
279 return NULL;
280 }
281 reslen = strlen (rootEntry) + 1;
282 size = mdsize + sizeof (struct NBlock) + reslen;
283 if (size > MAX_NBLOCK_SIZE)
284 {
285 size = MAX_NBLOCK_SIZE;
286 mdsize = size - sizeof (struct NBlock) - reslen;
287 }
288
289 pt = GNUNET_malloc (mdsize + reslen);
290 memcpy (pt, rootEntry, reslen);
291 mdst = &pt[reslen];
292 mdsize =
293 GNUNET_CONTAINER_meta_data_serialize (meta, &mdst, mdsize,
294 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
295 if (-1 == mdsize)
296 {
297 GNUNET_break (0);
298 GNUNET_free (pt);
299 cont (cont_cls, NULL, _("Failed to serialize meta data"));
300 return NULL;
301 }
302 size = mdsize + sizeof (struct NBlock) + reslen;
303 nb = GNUNET_malloc (size);
304 GNUNET_CRYPTO_rsa_key_get_public (ns->key, &nb->subspace);
305 nb->ns_purpose.size =
306 htonl (mdsize + reslen +
307 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
308 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
309 nb->ns_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK);
310 nb->ksk_purpose.size =
311 htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
312 nb->ksk_purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG);
313 dsh = GNUNET_DATASTORE_connect (h->cfg);
314 if (NULL == dsh)
315 {
316 GNUNET_free (nb);
317 GNUNET_free (pt);
318 cont (cont_cls, NULL, _("Failed to connect to datastore service"));
319 return NULL;
320 }
321 ctx = GNUNET_malloc (sizeof (struct GNUNET_FS_AdvertisementContext));
322 ctx->cont = cont;
323 ctx->cont_cls = cont_cls;
324 ctx->dsh = dsh;
325 ctx->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
326 ctx->nb = nb;
327 ctx->pt = pt;
328 ctx->pt_size = mdsize + reslen;
329 ctx->ns = ns;
330 ctx->ns->rc++;
331 ctx->bo = *bo;
332 advertisement_cont (ctx, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
333 return ctx;
334}
335
336
337/**
338 * Abort the namespace advertisement operation.
339 *
340 * @param ac context of the operation to abort.
341 */
342void
343GNUNET_FS_namespace_advertise_cancel (struct GNUNET_FS_AdvertisementContext *ac)
344{
345 if (NULL != ac->dqe)
346 {
347 GNUNET_DATASTORE_cancel (ac->dqe);
348 ac->dqe = NULL;
349 }
350 if (NULL != ac->dsh)
351 {
352 GNUNET_DATASTORE_disconnect (ac->dsh, GNUNET_NO);
353 ac->dsh = NULL;
354 }
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}
361
362
363/* end of fs_namespace_advertise.c */
diff --git a/src/fs/fs_publish_ksk.c b/src/fs/fs_publish_ksk.c
index 5511fb93d..bbbbdc1d6 100644
--- a/src/fs/fs_publish_ksk.c
+++ b/src/fs/fs_publish_ksk.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010, 2012 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2010, 2012, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file fs/fs_publish_ksk.c 22 * @file fs/fs_publish_ksk.c
23 * @brief publish a URI under a keyword in GNUnet 23 * @brief publish a URI under a keyword in GNUnet
24 * @see https://gnunet.org/encoding 24 * @see https://gnunet.org/encoding and #2564
25 * @author Krista Bennett 25 * @author Krista Bennett
26 * @author Christian Grothoff 26 * @author Christian Grothoff
27 */ 27 */
@@ -36,12 +36,6 @@
36 36
37 37
38/** 38/**
39 * Maximum legal size for a kblock.
40 */
41#define MAX_KBLOCK_SIZE (60 * 1024)
42
43
44/**
45 * Context for the KSK publication. 39 * Context for the KSK publication.
46 */ 40 */
47struct GNUNET_FS_PublishKskContext 41struct GNUNET_FS_PublishKskContext
@@ -62,13 +56,13 @@ struct GNUNET_FS_PublishKskContext
62 * (in plaintext), has "mdsize+slen" more 56 * (in plaintext), has "mdsize+slen" more
63 * bytes than the struct would suggest. 57 * bytes than the struct would suggest.
64 */ 58 */
65 struct KBlock *kb; 59 struct UBlock *ub;
66 60
67 /** 61 /**
68 * Buffer of the same size as "kb" for 62 * Buffer of the same size as "kb" for
69 * the encrypted version. 63 * the encrypted version.
70 */ 64 */
71 struct KBlock *cpy; 65 struct UBlock *cpy;
72 66
73 /** 67 /**
74 * Handle to the datastore, NULL if we are just 68 * Handle to the datastore, NULL if we are just
@@ -173,10 +167,13 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 struct GNUNET_FS_PublishKskContext *pkc = cls; 167 struct GNUNET_FS_PublishKskContext *pkc = cls;
174 const char *keyword; 168 const char *keyword;
175 struct GNUNET_HashCode key; 169 struct GNUNET_HashCode key;
170 struct GNUNET_HashCode seed;
171 struct GNUNET_HashCode signing_key;
176 struct GNUNET_HashCode query; 172 struct GNUNET_HashCode query;
177 struct GNUNET_CRYPTO_AesSessionKey skey; 173 struct GNUNET_CRYPTO_AesSessionKey skey;
178 struct GNUNET_CRYPTO_AesInitializationVector iv; 174 struct GNUNET_CRYPTO_AesInitializationVector iv;
179 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 175 struct GNUNET_PseudonymHandle *ph;
176 struct GNUNET_PseudonymIdentifier pseudonym;
180 177
181 pkc->ksk_task = GNUNET_SCHEDULER_NO_TASK; 178 pkc->ksk_task = GNUNET_SCHEDULER_NO_TASK;
182 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh)) 179 if ((pkc->i == pkc->ksk_uri->data.ksk.keywordCount) || (NULL == pkc->dsh))
@@ -186,29 +183,43 @@ publish_ksk_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
186 GNUNET_FS_publish_ksk_cancel (pkc); 183 GNUNET_FS_publish_ksk_cancel (pkc);
187 return; 184 return;
188 } 185 }
186 /* derive signing seed from plaintext */
187 GNUNET_CRYPTO_hash (&pkc->ub[1],
188 1 + pkc->slen + pkc->mdsize,
189 &seed);
189 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++]; 190 keyword = pkc->ksk_uri->data.ksk.keywords[pkc->i++];
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n", 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing under keyword `%s'\n",
191 &keyword[1]); 192 &keyword[1]);
192 /* first character of keyword indicates if it is 193 /* first character of keyword indicates if it is
193 * mandatory or not -- ignore for hashing */ 194 * mandatory or not -- ignore for hashing */
194 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key); 195 GNUNET_CRYPTO_hash (&keyword[1], strlen (&keyword[1]), &key);
195 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 196 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
196 GNUNET_CRYPTO_aes_encrypt (&pkc->kb[1], pkc->slen + pkc->mdsize, &skey, &iv, 197 GNUNET_CRYPTO_aes_encrypt (&pkc->ub[1],
198 1 + pkc->slen + pkc->mdsize,
199 &skey, &iv,
197 &pkc->cpy[1]); 200 &pkc->cpy[1]);
198 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); 201 ph = GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle ();
199 GNUNET_assert (NULL != pk); 202 GNUNET_CRYPTO_hash (&key, sizeof (key), &signing_key);
200 GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace); 203 pkc->cpy->purpose.size = htonl (1 + pkc->slen + pkc->mdsize + sizeof (struct UBlock)
201 GNUNET_CRYPTO_hash (&pkc->cpy->keyspace, 204 - sizeof (struct GNUNET_PseudonymSignature));
202 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 205 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK);
203 &query); 206 GNUNET_PSEUDONYM_sign (ph,
204 GNUNET_assert (GNUNET_OK == 207 &pkc->cpy->purpose,
205 GNUNET_CRYPTO_rsa_sign (pk, &pkc->cpy->purpose, 208 &seed,
206 &pkc->cpy->signature)); 209 &signing_key,
207 GNUNET_CRYPTO_rsa_key_free (pk); 210 &pkc->cpy->signature);
211 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym);
212 GNUNET_PSEUDONYM_derive_verification_key (&pseudonym,
213 &signing_key,
214 &pkc->cpy->verification_key);
215 GNUNET_CRYPTO_hash (&pkc->cpy->verification_key,
216 sizeof (pkc->cpy->verification_key),
217 &query);
218 GNUNET_PSEUDONYM_destroy (ph);
208 pkc->qre = 219 pkc->qre =
209 GNUNET_DATASTORE_put (pkc->dsh, 0, &query, 220 GNUNET_DATASTORE_put (pkc->dsh, 0, &query,
210 pkc->mdsize + sizeof (struct KBlock) + pkc->slen, 221 1 + pkc->slen + pkc->mdsize + sizeof (struct UBlock),
211 pkc->cpy, GNUNET_BLOCK_TYPE_FS_KBLOCK, 222 pkc->cpy, GNUNET_BLOCK_TYPE_FS_UBLOCK,
212 pkc->bo.content_priority, pkc->bo.anonymity_level, 223 pkc->bo.content_priority, pkc->bo.anonymity_level,
213 pkc->bo.replication_level, pkc->bo.expiration_time, 224 pkc->bo.replication_level, pkc->bo.expiration_time,
214 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT, 225 -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT,
@@ -267,14 +278,15 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
267 GNUNET_assert (pkc->mdsize >= 0); 278 GNUNET_assert (pkc->mdsize >= 0);
268 uris = GNUNET_FS_uri_to_string (uri); 279 uris = GNUNET_FS_uri_to_string (uri);
269 pkc->slen = strlen (uris) + 1; 280 pkc->slen = strlen (uris) + 1;
270 size = pkc->mdsize + sizeof (struct KBlock) + pkc->slen; 281 size = pkc->mdsize + sizeof (struct UBlock) + pkc->slen + 1;
271 if (size > MAX_KBLOCK_SIZE) 282 if (size > MAX_UBLOCK_SIZE)
272 { 283 {
273 size = MAX_KBLOCK_SIZE; 284 size = MAX_UBLOCK_SIZE;
274 pkc->mdsize = size - sizeof (struct KBlock) - pkc->slen; 285 pkc->mdsize = size - sizeof (struct UBlock) - pkc->slen + 1;
275 } 286 }
276 pkc->kb = GNUNET_malloc (size); 287 pkc->ub = GNUNET_malloc (size);
277 kbe = (char *) &pkc->kb[1]; 288 kbe = (char *) &pkc->ub[1];
289 kbe++; /* leave one '\0' for the update identifier */
278 memcpy (kbe, uris, pkc->slen); 290 memcpy (kbe, uris, pkc->slen);
279 GNUNET_free (uris); 291 GNUNET_free (uris);
280 sptr = &kbe[pkc->slen]; 292 sptr = &kbe[pkc->slen];
@@ -285,8 +297,8 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
285 if (-1 == pkc->mdsize) 297 if (-1 == pkc->mdsize)
286 { 298 {
287 GNUNET_break (0); 299 GNUNET_break (0);
288 GNUNET_free (pkc->kb); 300 GNUNET_free (pkc->ub);
289 if (pkc->dsh != NULL) 301 if (NULL != pkc->dsh)
290 { 302 {
291 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO); 303 GNUNET_DATASTORE_disconnect (pkc->dsh, GNUNET_NO);
292 pkc->dsh = NULL; 304 pkc->dsh = NULL;
@@ -295,14 +307,13 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
295 cont (cont_cls, NULL, _("Internal error.")); 307 cont (cont_cls, NULL, _("Internal error."));
296 return NULL; 308 return NULL;
297 } 309 }
298 size = sizeof (struct KBlock) + pkc->slen + pkc->mdsize; 310 size = sizeof (struct UBlock) + pkc->slen + pkc->mdsize + 1;
299 311
300 pkc->cpy = GNUNET_malloc (size); 312 pkc->cpy = GNUNET_malloc (size);
301 pkc->cpy->purpose.size = 313 pkc->cpy->purpose.size =
302 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 314 htonl (sizeof (struct GNUNET_PseudonymSignaturePurpose) +
303 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 315 pkc->mdsize + pkc->slen + 1);
304 pkc->mdsize + pkc->slen); 316 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK);
305 pkc->cpy->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
306 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri); 317 pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
307 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc); 318 pkc->ksk_task = GNUNET_SCHEDULER_add_now (&publish_ksk_cont, pkc);
308 return pkc; 319 return pkc;
@@ -333,7 +344,7 @@ GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc)
333 pkc->dsh = NULL; 344 pkc->dsh = NULL;
334 } 345 }
335 GNUNET_free (pkc->cpy); 346 GNUNET_free (pkc->cpy);
336 GNUNET_free (pkc->kb); 347 GNUNET_free (pkc->ub);
337 GNUNET_FS_uri_destroy (pkc->ksk_uri); 348 GNUNET_FS_uri_destroy (pkc->ksk_uri);
338 GNUNET_free (pkc); 349 GNUNET_free (pkc);
339} 350}
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index fc05498cc..eaf26f73f 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001-2006, 2008-2012 Christian Grothoff (and other contributing authors) 3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -22,7 +22,6 @@
22 * @brief Helper functions for searching. 22 * @brief Helper functions for searching.
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25
26#include "platform.h" 25#include "platform.h"
27#include "gnunet_constants.h" 26#include "gnunet_constants.h"
28#include "gnunet_fs_service.h" 27#include "gnunet_fs_service.h"
@@ -575,22 +574,22 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
575 574
576 575
577/** 576/**
578 * Decrypt a block using a 'keyword' as the passphrase. Given the 577 * Decrypt a ublock using a 'keyword' as the passphrase. Given the
579 * KSK public key derived from the keyword, this function looks up 578 * KSK public key derived from the keyword, this function looks up
580 * the original keyword in the search context and decrypts the 579 * the original keyword in the search context and decrypts the
581 * given ciphertext block. 580 * given ciphertext block.
582 * 581 *
583 * @param sc search context with the keywords 582 * @param sc search context with the keywords
584 * @param public_key public key to use to lookup the keyword 583 * @param verification_key public key to use to lookup the keyword
585 * @param edata encrypted data 584 * @param edata encrypted data
586 * @param edata_size number of bytes in 'edata' (and 'data') 585 * @param edata_size number of bytes in 'edata' (and 'data')
587 * @param data where to store the plaintext 586 * @param data where to store the plaintext
588 * @return keyword index on success, GNUNET_SYSERR on error (no such 587 * @return keyword index on success, GNUNET_SYSERR on error (no such
589 * keyword, internal error) 588 * keyword, internal error)
590 */ 589 */
591static int 590static int
592decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, 591decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
593 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 592 const struct GNUNET_PseudonymIdentifier *verification_key,
594 const void *edata, 593 const void *edata,
595 size_t edata_size, 594 size_t edata_size,
596 char *data) 595 char *data)
@@ -600,12 +599,12 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
600 struct GNUNET_CRYPTO_AesInitializationVector iv; 599 struct GNUNET_CRYPTO_AesInitializationVector iv;
601 int i; 600 int i;
602 601
603 GNUNET_CRYPTO_hash (public_key, 602 GNUNET_CRYPTO_hash (verification_key,
604 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 603 sizeof (struct GNUNET_PseudonymIdentifier),
605 &q); 604 &q);
606 /* find key */ 605 /* find key */
607 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 606 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
608 if (0 == memcmp (&q, &sc->requests[i].query, sizeof (struct GNUNET_HashCode))) 607 if (0 == memcmp (&q, &sc->requests[i].uquery, sizeof (struct GNUNET_HashCode)))
609 break; 608 break;
610 if (i == sc->uri->data.ksk.keywordCount) 609 if (i == sc->uri->data.ksk.keywordCount)
611 { 610 {
@@ -614,7 +613,7 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
614 return GNUNET_SYSERR; 613 return GNUNET_SYSERR;
615 } 614 }
616 /* decrypt */ 615 /* decrypt */
617 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 616 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].ukey, &skey, &iv);
618 if (-1 == 617 if (-1 ==
619 GNUNET_CRYPTO_aes_decrypt (edata, edata_size, &skey, 618 GNUNET_CRYPTO_aes_decrypt (edata, edata_size, &skey,
620 &iv, data)) 619 &iv, data))
@@ -627,18 +626,20 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
627 626
628 627
629/** 628/**
630 * Process a keyword-search result. 629 * Process a keyword search result. The actual type of block is
630 * a UBlock; we know it is a keyword search result because that's
631 * what we were searching for.
631 * 632 *
632 * @param sc our search context 633 * @param sc our search context
633 * @param kb the kblock 634 * @param ub the ublock with the keyword search result
634 * @param size size of kb 635 * @param size size of nb
635 */ 636 */
636static void 637static void
637process_kblock (struct GNUNET_FS_SearchContext *sc, const struct KBlock *kb, 638process_kblock (struct GNUNET_FS_SearchContext *sc, const struct UBlock *ub,
638 size_t size) 639 size_t size)
639{ 640{
640 size_t j; 641 size_t j;
641 char pt[size - sizeof (struct KBlock)]; 642 char pt[size - sizeof (struct UBlock)];
642 const char *eos; 643 const char *eos;
643 struct GNUNET_CONTAINER_MetaData *meta; 644 struct GNUNET_CONTAINER_MetaData *meta;
644 struct GNUNET_FS_Uri *uri; 645 struct GNUNET_FS_Uri *uri;
@@ -646,75 +647,22 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, const struct KBlock *kb,
646 int i; 647 int i;
647 648
648 if (-1 == (i = decrypt_block_with_keyword (sc, 649 if (-1 == (i = decrypt_block_with_keyword (sc,
649 &kb->keyspace, 650 &ub->verification_key,
650 &kb[1], 651 &ub[1],
651 size - sizeof (struct KBlock), 652 size - sizeof (struct UBlock),
652 pt))) 653 pt)))
653 return; 654 return;
654 /* parse */ 655 /* parse; pt[0] is just '\0', so we skip over that */
655 eos = memchr (pt, 0, sizeof (pt)); 656 eos = memchr (&pt[1], '\0', sizeof (pt) - 1);
656 if (NULL == eos) 657 if (NULL == eos)
657 { 658 {
658 GNUNET_break_op (0); 659 GNUNET_break_op (0);
659 return; 660 return;
660 } 661 }
661 j = eos - pt + 1; 662 if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg)))
662 if (sizeof (pt) == j)
663 meta = GNUNET_CONTAINER_meta_data_create ();
664 else
665 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
666 if (NULL == meta)
667 { 663 {
668 GNUNET_break_op (0); /* kblock malformed */ 664 GNUNET_break_op (0); /* ublock malformed */
669 return; 665 GNUNET_free_non_null (emsg);
670 }
671 uri = GNUNET_FS_uri_parse (pt, &emsg);
672 if (NULL == uri)
673 {
674 GNUNET_break_op (0); /* kblock malformed */
675 GNUNET_free_non_null (emsg);
676 GNUNET_CONTAINER_meta_data_destroy (meta);
677 return;
678 }
679 /* process */
680 process_ksk_result (sc, &sc->requests[i], uri, meta);
681
682 /* clean up */
683 GNUNET_CONTAINER_meta_data_destroy (meta);
684 GNUNET_FS_uri_destroy (uri);
685}
686
687
688/**
689 * Process a keyword-search result with a namespace advertisment.
690 *
691 * @param sc our search context
692 * @param nb the nblock
693 * @param size size of nb
694 */
695static void
696process_nblock (struct GNUNET_FS_SearchContext *sc, const struct NBlock *nb,
697 size_t size)
698{
699 size_t j;
700 char pt[size - sizeof (struct NBlock)];
701 const char *eos;
702 struct GNUNET_CONTAINER_MetaData *meta;
703 struct GNUNET_FS_Uri *uri;
704 char *uris;
705 int i;
706
707 if (-1 == (i = decrypt_block_with_keyword (sc,
708 &nb->keyspace,
709 &nb[1],
710 size - sizeof (struct NBlock),
711 pt)))
712 return;
713 /* parse */
714 eos = memchr (pt, 0, sizeof (pt));
715 if (NULL == eos)
716 {
717 GNUNET_break_op (0);
718 return; 666 return;
719 } 667 }
720 j = eos - pt + 1; 668 j = eos - pt + 1;
@@ -724,23 +672,10 @@ process_nblock (struct GNUNET_FS_SearchContext *sc, const struct NBlock *nb,
724 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j); 672 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
725 if (NULL == meta) 673 if (NULL == meta)
726 { 674 {
727 GNUNET_break_op (0); /* nblock malformed */ 675 GNUNET_break_op (0); /* ublock malformed */
676 GNUNET_FS_uri_destroy (uri);
728 return; 677 return;
729 } 678 }
730
731 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
732 uri->type = GNUNET_FS_URI_SKS;
733 uri->data.sks.identifier = GNUNET_strdup (pt);
734 GNUNET_CRYPTO_hash (&nb->subspace,
735 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
736 &uri->data.sks.ns);
737 uris = GNUNET_FS_uri_to_string (uri);
738 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_URI,
739 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
740 uris, strlen (uris) + 1);
741 GNUNET_free (uris);
742 GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.ns, meta);
743 /* process */
744 process_ksk_result (sc, &sc->requests[i], uri, meta); 679 process_ksk_result (sc, &sc->requests[i], uri, meta);
745 680
746 /* clean up */ 681 /* clean up */
@@ -750,17 +685,20 @@ process_nblock (struct GNUNET_FS_SearchContext *sc, const struct NBlock *nb,
750 685
751 686
752/** 687/**
753 * Process a namespace-search result. 688 * Process a namespace-search result. The actual type of block is
689 * a UBlock; we know it is a namespace search result because that's
690 * what we were searching for.
754 * 691 *
755 * @param sc our search context 692 * @param sc our search context
756 * @param sb the sblock 693 * @param ub the ublock with a namespace result
757 * @param size size of sb 694 * @param size size of sb
758 */ 695 */
759static void 696static void
760process_sblock (struct GNUNET_FS_SearchContext *sc, const struct SBlock *sb, 697process_sblock (struct GNUNET_FS_SearchContext *sc,
698 const struct UBlock *ub,
761 size_t size) 699 size_t size)
762{ 700{
763 size_t len = size - sizeof (struct SBlock); 701 size_t len = size - sizeof (struct UBlock);
764 char pt[len]; 702 char pt[len];
765 struct GNUNET_CRYPTO_AesSessionKey skey; 703 struct GNUNET_CRYPTO_AesSessionKey skey;
766 struct GNUNET_CRYPTO_AesInitializationVector iv; 704 struct GNUNET_CRYPTO_AesInitializationVector iv;
@@ -771,36 +709,39 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, const struct SBlock *sb,
771 size_t off; 709 size_t off;
772 char *emsg; 710 char *emsg;
773 struct GNUNET_HashCode key; 711 struct GNUNET_HashCode key;
712 struct GNUNET_HashCode id_hash;
713 struct GNUNET_HashCode ns_hash;
774 char *identifier; 714 char *identifier;
775 715
776 /* decrypt */ 716 /* decrypt */
777 identifier = sc->uri->data.sks.identifier; 717 identifier = sc->uri->data.sks.identifier;
778 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key); 718 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash);
719 GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns,
720 sizeof (sc->uri->data.sks.ns), &ns_hash);
721 GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
779 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); 722 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
780 if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], len, &skey, &iv, pt)) 723 if (-1 == GNUNET_CRYPTO_aes_decrypt (&ub[1], len, &skey, &iv, pt))
781 { 724 {
782 GNUNET_break (0); 725 GNUNET_break (0);
783 return; 726 return;
784 } 727 }
785 /* parse */ 728 /* parse */
786 off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris); 729 if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris)))
787 if (0 == off)
788 { 730 {
789 GNUNET_break_op (0); /* sblock malformed */ 731 GNUNET_break_op (0); /* ublock malformed */
790 return; 732 return;
791 } 733 }
792 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off); 734 if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off)))
793 if (meta == NULL)
794 { 735 {
795 GNUNET_break_op (0); /* sblock malformed */ 736 GNUNET_break_op (0); /* ublock malformed */
796 return; 737 return;
797 } 738 }
798 uri = GNUNET_FS_uri_parse (uris, &emsg); 739 if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg)))
799 if (NULL == uri)
800 { 740 {
801 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse URI `%s': %s\n", uris, 741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
802 emsg); 742 _("Failed to parse URI `%s': %s\n"),
803 GNUNET_break_op (0); /* sblock malformed */ 743 uris, emsg);
744 GNUNET_break_op (0); /* ublock malformed */
804 GNUNET_free_non_null (emsg); 745 GNUNET_free_non_null (emsg);
805 GNUNET_CONTAINER_meta_data_destroy (meta); 746 GNUNET_CONTAINER_meta_data_destroy (meta);
806 return; 747 return;
@@ -836,44 +777,11 @@ process_result (struct GNUNET_FS_SearchContext *sc, enum GNUNET_BLOCK_Type type,
836 } 777 }
837 switch (type) 778 switch (type)
838 { 779 {
839 case GNUNET_BLOCK_TYPE_FS_KBLOCK: 780 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
840 if (!GNUNET_FS_uri_test_ksk (sc->uri)) 781 if (GNUNET_FS_URI_SKS == sc->uri->type)
841 { 782 process_sblock (sc, data, size);
842 GNUNET_break (0); 783 else
843 return; 784 process_kblock (sc, data, size);
844 }
845 if (sizeof (struct KBlock) > size)
846 {
847 GNUNET_break_op (0);
848 return;
849 }
850 process_kblock (sc, data, size);
851 break;
852 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
853 if (!GNUNET_FS_uri_test_sks (sc->uri))
854 {
855 GNUNET_break (0);
856 return;
857 }
858 if (sizeof (struct SBlock) > size)
859 {
860 GNUNET_break_op (0);
861 return;
862 }
863 process_sblock (sc, data, size);
864 break;
865 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
866 if (!GNUNET_FS_uri_test_ksk (sc->uri))
867 {
868 GNUNET_break (0);
869 return;
870 }
871 if (sizeof (struct NBlock) > size)
872 {
873 GNUNET_break_op (0);
874 return;
875 }
876 process_nblock (sc, data, size);
877 break; 785 break;
878 case GNUNET_BLOCK_TYPE_ANY: 786 case GNUNET_BLOCK_TYPE_ANY:
879 GNUNET_break (0); 787 GNUNET_break (0);
@@ -1054,7 +962,10 @@ transmit_search_request (void *cls, size_t size, void *buf)
1054 struct SearchMessage *sm; 962 struct SearchMessage *sm;
1055 const char *identifier; 963 const char *identifier;
1056 struct GNUNET_HashCode key; 964 struct GNUNET_HashCode key;
1057 struct GNUNET_HashCode idh; 965 struct GNUNET_HashCode signing_key;
966 struct GNUNET_HashCode ns_hash;
967 struct GNUNET_HashCode id_hash;
968 struct GNUNET_PseudonymIdentifier verification_key;
1058 unsigned int sqms; 969 unsigned int sqms;
1059 uint32_t options; 970 uint32_t options;
1060 971
@@ -1090,10 +1001,10 @@ transmit_search_request (void *cls, size_t size, void *buf)
1090 /* now build message */ 1001 /* now build message */
1091 msize += sizeof (struct GNUNET_HashCode) * mbc.put_cnt; 1002 msize += sizeof (struct GNUNET_HashCode) * mbc.put_cnt;
1092 sm->header.size = htons (msize); 1003 sm->header.size = htons (msize);
1093 sm->type = htonl (GNUNET_BLOCK_TYPE_ANY); 1004 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK);
1094 sm->anonymity_level = htonl (sc->anonymity); 1005 sm->anonymity_level = htonl (sc->anonymity);
1095 memset (&sm->target, 0, sizeof (struct GNUNET_HashCode)); 1006 memset (&sm->target, 0, sizeof (struct GNUNET_HashCode));
1096 sm->query = sc->requests[sc->keyword_offset].query; 1007 sm->query = sc->requests[sc->keyword_offset].uquery;
1097 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1008 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1098 &build_result_set, &mbc); 1009 &build_result_set, &mbc);
1099 GNUNET_assert (sqms >= sc->search_request_map_offset); 1010 GNUNET_assert (sqms >= sc->search_request_map_offset);
@@ -1118,13 +1029,22 @@ transmit_search_request (void *cls, size_t size, void *buf)
1118 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); 1029 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
1119 msize = sizeof (struct SearchMessage); 1030 msize = sizeof (struct SearchMessage);
1120 GNUNET_assert (size >= msize); 1031 GNUNET_assert (size >= msize);
1121 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK); 1032 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK);
1122 sm->anonymity_level = htonl (sc->anonymity); 1033 sm->anonymity_level = htonl (sc->anonymity);
1123 sm->target = sc->uri->data.sks.ns; 1034 memset (&sm->target, 0, sizeof (struct GNUNET_HashCode));
1035
1124 identifier = sc->uri->data.sks.identifier; 1036 identifier = sc->uri->data.sks.identifier;
1125 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key); 1037 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &id_hash);
1126 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &idh); 1038 GNUNET_CRYPTO_hash (&sc->uri->data.sks.ns,
1127 GNUNET_CRYPTO_hash_xor (&idh, &sm->target, &sm->query); 1039 sizeof (sc->uri->data.sks.ns), &ns_hash);
1040 GNUNET_CRYPTO_hash_xor (&id_hash, &ns_hash, &key);
1041 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &signing_key);
1042 GNUNET_PSEUDONYM_derive_verification_key (&sc->uri->data.sks.ns,
1043 &signing_key,
1044 &verification_key);
1045 GNUNET_CRYPTO_hash (&verification_key,
1046 sizeof (verification_key),
1047 &sm->query);
1128 mbc.put_cnt = (size - msize) / sizeof (struct GNUNET_HashCode); 1048 mbc.put_cnt = (size - msize) / sizeof (struct GNUNET_HashCode);
1129 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); 1049 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
1130 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt); 1050 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
@@ -1287,28 +1207,35 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1287{ 1207{
1288 unsigned int i; 1208 unsigned int i;
1289 const char *keyword; 1209 const char *keyword;
1290 struct GNUNET_HashCode hc; 1210 struct GNUNET_HashCode signing_key;
1291 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 1211 struct GNUNET_PseudonymHandle *ph;
1212 struct GNUNET_PseudonymIdentifier anon;
1213 struct GNUNET_PseudonymIdentifier verification_key;
1292 1214
1293 GNUNET_assert (NULL == sc->client); 1215 GNUNET_assert (NULL == sc->client);
1294 if (GNUNET_FS_uri_test_ksk (sc->uri)) 1216 if (GNUNET_FS_uri_test_ksk (sc->uri))
1295 { 1217 {
1296 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); 1218 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
1219 ph = GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle ();
1220 GNUNET_PSEUDONYM_get_identifier (ph, &anon);
1221 GNUNET_PSEUDONYM_destroy (ph);
1297 sc->requests = 1222 sc->requests =
1298 GNUNET_malloc (sizeof (struct SearchRequestEntry) * 1223 GNUNET_malloc (sizeof (struct SearchRequestEntry) *
1299 sc->uri->data.ksk.keywordCount); 1224 sc->uri->data.ksk.keywordCount);
1300 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) 1225 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1301 { 1226 {
1302 keyword = &sc->uri->data.ksk.keywords[i][1]; 1227 keyword = &sc->uri->data.ksk.keywords[i][1];
1303 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc); 1228 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].ukey);
1304 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); 1229 GNUNET_CRYPTO_hash (&sc->requests[i].ukey, sizeof (struct GNUNET_HashCode), &signing_key);
1305 GNUNET_assert (NULL != pk); 1230 GNUNET_PSEUDONYM_derive_verification_key (&anon,
1306 GNUNET_CRYPTO_rsa_get_public_key_hash (pk, &sc->requests[i].query); 1231 &signing_key,
1232 &verification_key);
1233 GNUNET_CRYPTO_hash (&verification_key, sizeof (struct GNUNET_PseudonymIdentifier),
1234 &sc->requests[i].uquery);
1307 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); 1235 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
1308 if (sc->requests[i].mandatory) 1236 if (sc->requests[i].mandatory)
1309 sc->mandatory_count++; 1237 sc->mandatory_count++;
1310 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); 1238 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
1311 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].key);
1312 } 1239 }
1313 } 1240 }
1314 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg); 1241 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 49518a3df..17c3731fe 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2003--2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -260,7 +260,7 @@ process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
260 260
261 261
262/** 262/**
263 * Function called when we are done with removing KBlocks. 263 * Function called when we are done with removing UBlocks.
264 * Disconnect from datastore and notify FS service about 264 * Disconnect from datastore and notify FS service about
265 * the unindex event. 265 * the unindex event.
266 * 266 *
@@ -314,7 +314,7 @@ unindex_finish (struct GNUNET_FS_UnindexContext *uc)
314 314
315/** 315/**
316 * Function called by the directory scanner as we extract keywords 316 * Function called by the directory scanner as we extract keywords
317 * that we will need to remove KBlocks. 317 * that we will need to remove UBlocks.
318 * 318 *
319 * @param cls the 'struct GNUNET_FS_UnindexContext *' 319 * @param cls the 'struct GNUNET_FS_UnindexContext *'
320 * @param filename which file we are making progress on 320 * @param filename which file we are making progress on
@@ -369,7 +369,7 @@ unindex_directory_scan_cb (void *cls,
369 369
370 370
371/** 371/**
372 * If necessary, connect to the datastore and remove the KBlocks. 372 * If necessary, connect to the datastore and remove the UBlocks.
373 * 373 *
374 * @param uc context for the unindex operation. 374 * @param uc context for the unindex operation.
375 */ 375 */
@@ -391,7 +391,7 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc)
391 391
392/** 392/**
393 * Continuation called to notify client about result of the remove 393 * Continuation called to notify client about result of the remove
394 * operation for the KBlock. 394 * operation for the UBlock.
395 * 395 *
396 * @param cls the 'struct GNUNET_FS_UnindexContext *' 396 * @param cls the 'struct GNUNET_FS_UnindexContext *'
397 * @param success GNUNET_SYSERR on failure (including timeout/queue drop) 397 * @param success GNUNET_SYSERR on failure (including timeout/queue drop)
@@ -413,7 +413,7 @@ continue_after_remove (void *cls,
413 uc->dqe = NULL; 413 uc->dqe = NULL;
414 if (success != GNUNET_YES) 414 if (success != GNUNET_YES)
415 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 415 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
416 _("Failed to remove KBlock: %s\n"), 416 _("Failed to remove UBlock: %s\n"),
417 msg); 417 msg);
418 uc->ksk_offset++; 418 uc->ksk_offset++;
419 GNUNET_FS_unindex_do_remove_kblocks_ (uc); 419 GNUNET_FS_unindex_do_remove_kblocks_ (uc);
@@ -422,11 +422,11 @@ continue_after_remove (void *cls,
422 422
423/** 423/**
424 * Function called from datastore with result from us looking for 424 * Function called from datastore with result from us looking for
425 * a KBlock. There are four cases: 425 * a UBlock. There are four cases:
426 * 1) no result, means we move on to the next keyword 426 * 1) no result, means we move on to the next keyword
427 * 2) UID is the same as the first UID, means we move on to next keyword 427 * 2) UID is the same as the first UID, means we move on to next keyword
428 * 3) KBlock for a different CHK, means we keep looking for more 428 * 3) UBlock for a different CHK, means we keep looking for more
429 * 4) KBlock is for our CHK, means we remove the block and then move 429 * 4) UBlock is for our CHK, means we remove the block and then move
430 * on to the next keyword 430 * on to the next keyword
431 * 431 *
432 * @param cls the 'struct GNUNET_FS_UnindexContext *' 432 * @param cls the 'struct GNUNET_FS_UnindexContext *'
@@ -442,7 +442,7 @@ continue_after_remove (void *cls,
442 */ 442 */
443static void 443static void
444process_kblock_for_unindex (void *cls, 444process_kblock_for_unindex (void *cls,
445 const struct GNUNET_HashCode * key, 445 const struct GNUNET_HashCode *key,
446 size_t size, const void *data, 446 size_t size, const void *data,
447 enum GNUNET_BLOCK_Type type, 447 enum GNUNET_BLOCK_Type type,
448 uint32_t priority, 448 uint32_t priority,
@@ -451,8 +451,9 @@ process_kblock_for_unindex (void *cls,
451 expiration, uint64_t uid) 451 expiration, uint64_t uid)
452{ 452{
453 struct GNUNET_FS_UnindexContext *uc = cls; 453 struct GNUNET_FS_UnindexContext *uc = cls;
454 const struct KBlock *kb; 454 const struct UBlock *ub;
455 struct GNUNET_FS_Uri *chk_uri; 455 struct GNUNET_FS_Uri *chk_uri;
456 struct GNUNET_HashCode query;
456 457
457 uc->dqe = NULL; 458 uc->dqe = NULL;
458 if (NULL == data) 459 if (NULL == data)
@@ -474,38 +475,43 @@ process_kblock_for_unindex (void *cls,
474 GNUNET_FS_unindex_do_remove_kblocks_ (uc); 475 GNUNET_FS_unindex_do_remove_kblocks_ (uc);
475 return; 476 return;
476 } 477 }
477 GNUNET_assert (GNUNET_BLOCK_TYPE_FS_KBLOCK == type); 478 GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type);
478 if (size < sizeof (struct KBlock)) 479 if (size < sizeof (struct UBlock))
479 { 480 {
480 GNUNET_break (0); 481 GNUNET_break (0);
481 goto get_next; 482 goto get_next;
482 } 483 }
483 kb = data; 484 ub = data;
485 GNUNET_CRYPTO_hash (&ub->verification_key,
486 sizeof (ub->verification_key),
487 &query);
488 if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode)))
489 {
490 /* result does not match our keyword, skip */
491 goto get_next;
492 }
484 { 493 {
485 char pt[size - sizeof (struct KBlock)]; 494 char pt[size - sizeof (struct UBlock)];
486 struct GNUNET_CRYPTO_AesSessionKey skey; 495 struct GNUNET_CRYPTO_AesSessionKey skey;
487 struct GNUNET_CRYPTO_AesInitializationVector iv; 496 struct GNUNET_CRYPTO_AesInitializationVector iv;
488 497
489 GNUNET_CRYPTO_hash_to_aes_key (&uc->key, &skey, &iv); 498 GNUNET_CRYPTO_hash_to_aes_key (&uc->ukey, &skey, &iv);
490 if (-1 == 499 if (-1 ==
491 GNUNET_CRYPTO_aes_decrypt (&kb[1], size - sizeof (struct KBlock), &skey, 500 GNUNET_CRYPTO_aes_decrypt (&ub[1], size - sizeof (struct UBlock), &skey,
492 &iv, pt)) 501 &iv, pt))
493 { 502 {
494 GNUNET_break (0); 503 GNUNET_break (0);
495 goto get_next; 504 goto get_next;
496 } 505 }
497 if (NULL == memchr (pt, 0, sizeof (pt))) 506 if (NULL == memchr (&pt[1], 0, sizeof (pt) - 1))
498 { 507 {
499 GNUNET_break (0); 508 GNUNET_break_op (0); /* malformed UBlock */
500 goto get_next; 509 goto get_next;
501 } 510 }
502 chk_uri = GNUNET_FS_uri_parse (pt, NULL); 511 chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL);
503 if (NULL == chk_uri) 512 if (NULL == chk_uri)
504 { 513 {
505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 514 GNUNET_break_op (0); /* malformed UBlock */
506 _("Failed to parse URI `%s' from KBlock!\n"),
507 pt);
508 GNUNET_break (0);
509 goto get_next; 515 goto get_next;
510 } 516 }
511 } 517 }
@@ -529,8 +535,8 @@ process_kblock_for_unindex (void *cls,
529 get_next: 535 get_next:
530 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, 536 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
531 uc->roff++, 537 uc->roff++,
532 &uc->query, 538 &uc->uquery,
533 GNUNET_BLOCK_TYPE_FS_KBLOCK, 539 GNUNET_BLOCK_TYPE_FS_UBLOCK,
534 0 /* priority */, 1 /* queue size */, 540 0 /* priority */, 1 /* queue size */,
535 GNUNET_TIME_UNIT_FOREVER_REL, 541 GNUNET_TIME_UNIT_FOREVER_REL,
536 &process_kblock_for_unindex, 542 &process_kblock_for_unindex,
@@ -547,7 +553,10 @@ void
547GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) 553GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
548{ 554{
549 const char *keyword; 555 const char *keyword;
550 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 556 struct GNUNET_PseudonymHandle *ph;
557 struct GNUNET_PseudonymIdentifier anon;
558 struct GNUNET_PseudonymIdentifier verification_key;
559 struct GNUNET_HashCode signing_key;
551 560
552 if (NULL == uc->dsh) 561 if (NULL == uc->dsh)
553 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); 562 uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
@@ -566,16 +575,23 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
566 return; 575 return;
567 } 576 }
568 /* FIXME: code duplication with fs_search.c here... */ 577 /* FIXME: code duplication with fs_search.c here... */
578 ph = GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle ();
579 GNUNET_PSEUDONYM_get_identifier (ph, &anon);
580 GNUNET_PSEUDONYM_destroy (ph);
569 keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; 581 keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1];
570 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &uc->key); 582 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &uc->ukey);
571 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&uc->key); 583 GNUNET_CRYPTO_hash (&uc->ukey, sizeof (struct GNUNET_HashCode), &signing_key);
572 GNUNET_assert (pk != NULL); 584 GNUNET_PSEUDONYM_derive_verification_key (&anon,
573 GNUNET_CRYPTO_rsa_get_public_key_hash (pk, &uc->query); 585 &signing_key,
586 &verification_key);
587 GNUNET_CRYPTO_hash (&verification_key,
588 sizeof (struct GNUNET_PseudonymIdentifier),
589 &uc->uquery);
574 uc->first_uid = 0; 590 uc->first_uid = 0;
575 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, 591 uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh,
576 uc->roff++, 592 uc->roff++,
577 &uc->query, 593 &uc->uquery,
578 GNUNET_BLOCK_TYPE_FS_KBLOCK, 594 GNUNET_BLOCK_TYPE_FS_UBLOCK,
579 0 /* priority */, 1 /* queue size */, 595 0 /* priority */, 1 /* queue size */,
580 GNUNET_TIME_UNIT_FOREVER_REL, 596 GNUNET_TIME_UNIT_FOREVER_REL,
581 &process_kblock_for_unindex, 597 &process_kblock_for_unindex,
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index e76693521..2b7af3c9e 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2003--2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -356,36 +356,30 @@ static struct GNUNET_FS_Uri *
356uri_sks_parse (const char *s, char **emsg) 356uri_sks_parse (const char *s, char **emsg)
357{ 357{
358 struct GNUNET_FS_Uri *ret; 358 struct GNUNET_FS_Uri *ret;
359 struct GNUNET_HashCode ns; 359 struct GNUNET_PseudonymIdentifier id;
360 char *identifier; 360 size_t pos;
361 unsigned int pos; 361 char *end;
362 size_t slen;
363 char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
364 362
365 GNUNET_assert (s != NULL); 363 GNUNET_assert (s != NULL);
366 slen = strlen (s);
367 pos = strlen (GNUNET_FS_URI_SKS_PREFIX); 364 pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
368 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) 365 if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
369 return NULL; /* not an SKS URI */ 366 return NULL; /* not an SKS URI */
370 if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) || 367 end = strchr (&s[pos], '/');
371 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/')) 368 if ( (NULL == end) ||
372 { 369 (GNUNET_OK !=
373 *emsg = GNUNET_strdup (_("Malformed SKS URI")); 370 GNUNET_STRINGS_string_to_data (&s[pos],
374 return NULL; 371 end - &s[pos],
375 } 372 &id,
376 memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 373 sizeof (id))) )
377 enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
378 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &ns))
379 { 374 {
380 *emsg = GNUNET_strdup (_("Malformed SKS URI")); 375 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
381 return NULL; 376 return NULL; /* malformed */
382 } 377 }
383 identifier = 378 end++; /* skip over '/' */
384 GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]);
385 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 379 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
386 ret->type = GNUNET_FS_URI_SKS; 380 ret->type = GNUNET_FS_URI_SKS;
387 ret->data.sks.ns = ns; 381 ret->data.sks.ns = id;
388 ret->data.sks.identifier = identifier; 382 ret->data.sks.identifier = GNUNET_strdup (end);
389 return ret; 383 return ret;
390} 384}
391 385
@@ -957,7 +951,7 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
957 } 951 }
958 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 952 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
959 ns_uri->type = GNUNET_FS_URI_SKS; 953 ns_uri->type = GNUNET_FS_URI_SKS;
960 GNUNET_FS_namespace_get_public_key_hash (ns, &ns_uri->data.sks.ns); 954 GNUNET_FS_namespace_get_public_identifier (ns, &ns_uri->data.sks.ns);
961 ns_uri->data.sks.identifier = GNUNET_strdup (id); 955 ns_uri->data.sks.identifier = GNUNET_strdup (id);
962 return ns_uri; 956 return ns_uri;
963} 957}
@@ -966,18 +960,19 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
966/** 960/**
967 * Create an SKS URI from a namespace ID and an identifier. 961 * Create an SKS URI from a namespace ID and an identifier.
968 * 962 *
969 * @param nsid namespace ID 963 * @param pseudonym namespace ID
970 * @param id identifier 964 * @param id identifier
971 * @return an FS URI for the given namespace and identifier 965 * @return an FS URI for the given namespace and identifier
972 */ 966 */
973struct GNUNET_FS_Uri * 967struct GNUNET_FS_Uri *
974GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_HashCode * nsid, const char *id) 968GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_PseudonymIdentifier *pseudonym,
969 const char *id)
975{ 970{
976 struct GNUNET_FS_Uri *ns_uri; 971 struct GNUNET_FS_Uri *ns_uri;
977 972
978 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 973 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
979 ns_uri->type = GNUNET_FS_URI_SKS; 974 ns_uri->type = GNUNET_FS_URI_SKS;
980 ns_uri->data.sks.ns = *nsid; 975 ns_uri->data.sks.ns = *pseudonym;
981 ns_uri->data.sks.identifier = GNUNET_strdup (id); 976 ns_uri->data.sks.identifier = GNUNET_strdup (id);
982 return ns_uri; 977 return ns_uri;
983} 978}
@@ -1337,19 +1332,19 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri)
1337 * namespace URI. 1332 * namespace URI.
1338 * 1333 *
1339 * @param uri the uri to get the namespace ID from 1334 * @param uri the uri to get the namespace ID from
1340 * @param nsid where to store the ID of the namespace 1335 * @param pseudonym where to store the ID of the namespace
1341 * @return GNUNET_OK on success 1336 * @return GNUNET_OK on success
1342 */ 1337 */
1343int 1338int
1344GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, 1339GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1345 struct GNUNET_HashCode * nsid) 1340 struct GNUNET_PseudonymIdentifier *pseudonym)
1346{ 1341{
1347 if (!GNUNET_FS_uri_test_sks (uri)) 1342 if (!GNUNET_FS_uri_test_sks (uri))
1348 { 1343 {
1349 GNUNET_break (0); 1344 GNUNET_break (0);
1350 return GNUNET_SYSERR; 1345 return GNUNET_SYSERR;
1351 } 1346 }
1352 *nsid = uri->data.sks.ns; 1347 *pseudonym = uri->data.sks.ns;
1353 return GNUNET_OK; 1348 return GNUNET_OK;
1354} 1349}
1355 1350
@@ -1939,18 +1934,20 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1939static char * 1934static char *
1940uri_sks_to_string (const struct GNUNET_FS_Uri *uri) 1935uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1941{ 1936{
1942 const struct GNUNET_HashCode *ns;
1943 const char *identifier;
1944 char *ret; 1937 char *ret;
1945 struct GNUNET_CRYPTO_HashAsciiEncoded nsasc; 1938 char buf[1024];
1946 1939
1947 if (uri->type != GNUNET_FS_URI_SKS) 1940 if (GNUNET_FS_URI_SKS != uri->type)
1948 return NULL; 1941 return NULL;
1949 ns = &uri->data.sks.ns; 1942 ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
1950 identifier = uri->data.sks.identifier; 1943 sizeof (struct GNUNET_PseudonymIdentifier),
1951 GNUNET_CRYPTO_hash_to_enc (ns, &nsasc); 1944 buf,
1945 sizeof (buf));
1946 GNUNET_assert (NULL != ret);
1947 ret[0] = '\0';
1952 GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, 1948 GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX,
1953 GNUNET_FS_URI_SKS_INFIX, (const char *) &nsasc, identifier); 1949 GNUNET_FS_URI_SKS_INFIX, buf,
1950 uri->data.sks.identifier);
1954 return ret; 1951 return ret;
1955} 1952}
1956 1953
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c
index a692917da..dd3c9d4a2 100644
--- a/src/fs/gnunet-pseudonym.c
+++ b/src/fs/gnunet-pseudonym.c
@@ -95,19 +95,37 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
95 95
96 96
97static void 97static void
98ns_printer (void *cls, const char *name, const struct GNUNET_HashCode * id) 98ns_printer (void *cls, const char *name, const struct GNUNET_PseudonymIdentifier *pseudonym)
99{ 99{
100 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 100 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
101 struct GNUNET_HashCode hc;
101 102
102 GNUNET_CRYPTO_hash_to_enc (id, &enc); 103 GNUNET_CRYPTO_hash (pseudonym,
104 sizeof (struct GNUNET_PseudonymIdentifier),
105 &hc);
106 GNUNET_CRYPTO_hash_to_enc (&hc, &enc);
103 FPRINTF (stdout, "%s (%s)\n", name, (const char *) &enc); 107 FPRINTF (stdout, "%s (%s)\n", name, (const char *) &enc);
104} 108}
105 109
106 110
111/**
112 * Output information about a pseudonym.
113 *
114 * @param cls closure
115 * @param pseudonym hash code of public key of pseudonym
116 * @param name name of the pseudonym (might be NULL)
117 * @param unique_name unique name of the pseudonym (might be NULL)
118 * @param md meta data known about the pseudonym
119 * @param rating the local rating of the pseudonym
120 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
121 */
107static int 122static int
108pseudo_printer (void *cls, const struct GNUNET_HashCode * pseudonym, 123pseudo_printer (void *cls,
109 const char *name, const char *unique_name, 124 const struct GNUNET_PseudonymIdentifier *pseudonym,
110 const struct GNUNET_CONTAINER_MetaData *md, int rating) 125 const char *name,
126 const char *unique_name,
127 const struct GNUNET_CONTAINER_MetaData *md,
128 int32_t rating)
111{ 129{
112 char *id; 130 char *id;
113 char *unique_id; 131 char *unique_id;
@@ -136,7 +154,7 @@ pseudo_printer (void *cls, const struct GNUNET_HashCode * pseudonym,
136static void 154static void
137post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) 155post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
138{ 156{
139 struct GNUNET_HashCode nsid; 157 struct GNUNET_PseudonymIdentifier nsid;
140 char *set; 158 char *set;
141 int delta; 159 int delta;
142 160
@@ -203,6 +221,7 @@ static void
203run (void *cls, char *const *args, const char *cfgfile, 221run (void *cls, char *const *args, const char *cfgfile,
204 const struct GNUNET_CONFIGURATION_Handle *c) 222 const struct GNUNET_CONFIGURATION_Handle *c)
205{ 223{
224 struct GNUNET_FS_Uri *sks_uri;
206 char *emsg; 225 char *emsg;
207 226
208 cfg = c; 227 cfg = c;
@@ -239,9 +258,13 @@ run (void *cls, char *const *args, const char *cfgfile,
239 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); 258 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
240 GNUNET_assert (NULL == emsg); 259 GNUNET_assert (NULL == emsg);
241 } 260 }
242 GNUNET_FS_namespace_advertise (h, ksk_uri, ns, adv_metadata, &bo, 261 sks_uri = GNUNET_FS_uri_sks_create (ns, root_identifier, &emsg);
243 root_identifier, &post_advertising, 262 GNUNET_assert (NULL == emsg);
244 NULL); 263 GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, sks_uri,
264 &bo,
265 GNUNET_FS_PUBLISH_OPTION_NONE,
266 &post_advertising, NULL);
267 GNUNET_FS_uri_destroy (sks_uri);
245 return; 268 return;
246 } 269 }
247 else 270 else
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 0f4d513ff..4364265a8 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -405,9 +405,7 @@ start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
405 "Considering stream-based download for block\n"); 405 "Considering stream-based download for block\n");
406 GSF_stream_lookup_ (pr); 406 GSF_stream_lookup_ (pr);
407 break; 407 break;
408 case GNUNET_BLOCK_TYPE_FS_KBLOCK: 408 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
409 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
410 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
411 /* the above block types are in the DHT */ 409 /* the above block types are in the DHT */
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Considering DHT-based search for block\n"); 411 "Considering DHT-based search for block\n");
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index 3213712c8..60075e097 100644
--- a/src/fs/gnunet-service-fs.h
+++ b/src/fs/gnunet-service-fs.h
@@ -63,12 +63,6 @@
63#define GET_MESSAGE_BIT_RETURN_TO 1 63#define GET_MESSAGE_BIT_RETURN_TO 1
64 64
65/** 65/**
66 * The hash of the public key of the target
67 * namespace is included (for SKS queries).
68 */
69#define GET_MESSAGE_BIT_SKS_NAMESPACE 2
70
71/**
72 * The peer identity of a peer that had claimed to have the content 66 * The peer identity of a peer that had claimed to have the content
73 * previously is included (can be used if responder-anonymity is not 67 * previously is included (can be used if responder-anonymity is not
74 * desired; note that the precursor presumably lacked a direct 68 * desired; note that the precursor presumably lacked a direct
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index e389a24b2..f38a32c81 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -1143,7 +1143,6 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1143 struct GSF_PendingRequestData *prd; 1143 struct GSF_PendingRequestData *prd;
1144 struct GSF_ConnectedPeer *cp; 1144 struct GSF_ConnectedPeer *cp;
1145 struct GSF_ConnectedPeer *cps; 1145 struct GSF_ConnectedPeer *cps;
1146 const struct GNUNET_HashCode *namespace;
1147 const struct GNUNET_PeerIdentity *target; 1146 const struct GNUNET_PeerIdentity *target;
1148 enum GSF_PendingRequestOptions options; 1147 enum GSF_PendingRequestOptions options;
1149 uint16_t msize; 1148 uint16_t msize;
@@ -1244,17 +1243,6 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1244 "Received request for `%s' of type %u from peer `%4s' with flags %u\n", 1243 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
1245 GNUNET_h2s (&gm->query), (unsigned int) type, GNUNET_i2s (other), 1244 GNUNET_h2s (&gm->query), (unsigned int) type, GNUNET_i2s (other),
1246 (unsigned int) bm); 1245 (unsigned int) bm);
1247 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
1248 if ((GNUNET_BLOCK_TYPE_FS_SBLOCK == type) && (NULL == namespace))
1249 {
1250 GNUNET_break_op (0);
1251 return NULL;
1252 }
1253 if ((GNUNET_BLOCK_TYPE_FS_SBLOCK != type) && (NULL != namespace))
1254 {
1255 GNUNET_break_op (0);
1256 return NULL;
1257 }
1258 target = 1246 target =
1259 (0 != 1247 (0 !=
1260 (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity 1248 (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity
@@ -1298,9 +1286,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1298 { 1286 {
1299 pr = peerreq->pr; 1287 pr = peerreq->pr;
1300 prd = GSF_pending_request_get_data_ (pr); 1288 prd = GSF_pending_request_get_data_ (pr);
1301 if ((prd->type == type) && 1289 if (prd->type == type)
1302 ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
1303 (0 == memcmp (&prd->namespace, namespace, sizeof (struct GNUNET_HashCode)))))
1304 { 1290 {
1305 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get ().abs_value + ttl) 1291 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get ().abs_value + ttl)
1306 { 1292 {
@@ -1324,7 +1310,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1324 1310
1325 peerreq = GNUNET_malloc (sizeof (struct PeerRequest)); 1311 peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
1326 peerreq->cp = cp; 1312 peerreq->cp = cp;
1327 pr = GSF_pending_request_create_ (options, type, &gm->query, namespace, 1313 pr = GSF_pending_request_create_ (options, type, &gm->query,
1328 target, 1314 target,
1329 (bfsize > 1315 (bfsize >
1330 0) ? (const char *) &opt[bits] : NULL, 1316 0) ? (const char *) &opt[bits] : NULL,
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index c3b6f40b0..f90131815 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -335,9 +335,9 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
335 GNUNET_h2s (&sm->query), (unsigned int) type); 335 GNUNET_h2s (&sm->query), (unsigned int) type);
336 lc = GSF_local_client_lookup_ (client); 336 lc = GSF_local_client_lookup_ (client);
337 cr = NULL; 337 cr = NULL;
338 /* detect duplicate KBLOCK requests */ 338 /* detect duplicate UBLOCK requests */
339 if ((type == GNUNET_BLOCK_TYPE_FS_KBLOCK) || 339 if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) ||
340 (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) || (type == GNUNET_BLOCK_TYPE_ANY)) 340 (type == GNUNET_BLOCK_TYPE_ANY))
341 { 341 {
342 cr = lc->cr_head; 342 cr = lc->cr_head;
343 while (cr != NULL) 343 while (cr != NULL)
@@ -353,7 +353,7 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
353 cr = cr->next; 353 cr = cr->next;
354 } 354 }
355 } 355 }
356 if (cr != NULL) 356 if (NULL != cr)
357 { 357 {
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
359 "Have existing request, merging content-seen lists.\n"); 359 "Have existing request, merging content-seen lists.\n");
@@ -374,8 +374,8 @@ GSF_local_client_start_search_handler_ (struct GNUNET_SERVER_Client *client,
374 options = GSF_PRO_LOCAL_REQUEST; 374 options = GSF_PRO_LOCAL_REQUEST;
375 if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options))) 375 if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options)))
376 options |= GSF_PRO_LOCAL_ONLY; 376 options |= GSF_PRO_LOCAL_ONLY;
377 cr->pr = GSF_pending_request_create_ (options, type, &sm->query, (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? &sm->target /* namespace */ 377 cr->pr = GSF_pending_request_create_ (options, type,
378 : NULL, 378 &sm->query,
379 (0 != 379 (0 !=
380 memcmp (&sm->target, &all_zeros, 380 memcmp (&sm->target, &all_zeros,
381 sizeof (struct GNUNET_HashCode))) 381 sizeof (struct GNUNET_HashCode)))
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index 76e04f57c..2ab4771b5 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -268,7 +268,6 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
268 * @param options request options 268 * @param options request options
269 * @param type type of the block that is being requested 269 * @param type type of the block that is being requested
270 * @param query key for the lookup 270 * @param query key for the lookup
271 * @param namespace namespace to lookup, NULL for no namespace
272 * @param target preferred target for the request, NULL for none 271 * @param target preferred target for the request, NULL for none
273 * @param bf_data raw data for bloom filter for known replies, can be NULL 272 * @param bf_data raw data for bloom filter for known replies, can be NULL
274 * @param bf_size number of bytes in bf_data 273 * @param bf_size number of bytes in bf_data
@@ -288,7 +287,6 @@ struct GSF_PendingRequest *
288GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, 287GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
289 enum GNUNET_BLOCK_Type type, 288 enum GNUNET_BLOCK_Type type,
290 const struct GNUNET_HashCode *query, 289 const struct GNUNET_HashCode *query,
291 const struct GNUNET_HashCode *namespace,
292 const struct GNUNET_PeerIdentity *target, 290 const struct GNUNET_PeerIdentity *target,
293 const char *bf_data, size_t bf_size, 291 const char *bf_data, size_t bf_size,
294 uint32_t mingle, uint32_t anonymity_level, 292 uint32_t mingle, uint32_t anonymity_level,
@@ -313,8 +311,6 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
313 GNUNET_NO); 311 GNUNET_NO);
314#endif 312#endif
315 extra = 0; 313 extra = 0;
316 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type)
317 extra += sizeof (struct GNUNET_HashCode);
318 if (NULL != target) 314 if (NULL != target)
319 extra += sizeof (struct GNUNET_PeerIdentity); 315 extra += sizeof (struct GNUNET_PeerIdentity);
320 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest) + extra); 316 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest) + extra);
@@ -322,13 +318,6 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
322 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 318 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
323 pr->public_data.query = *query; 319 pr->public_data.query = *query;
324 eptr = (struct GNUNET_HashCode *) &pr[1]; 320 eptr = (struct GNUNET_HashCode *) &pr[1];
325 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type)
326 {
327 GNUNET_assert (NULL != namespace);
328 pr->public_data.namespace = eptr;
329 memcpy (eptr, namespace, sizeof (struct GNUNET_HashCode));
330 eptr++;
331 }
332 if (NULL != target) 321 if (NULL != target)
333 { 322 {
334 pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr; 323 pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr;
@@ -435,12 +424,7 @@ GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
435 if ((pra->public_data.type != prb->public_data.type) || 424 if ((pra->public_data.type != prb->public_data.type) ||
436 (0 != 425 (0 !=
437 memcmp (&pra->public_data.query, &prb->public_data.query, 426 memcmp (&pra->public_data.query, &prb->public_data.query,
438 sizeof (struct GNUNET_HashCode))) || 427 sizeof (struct GNUNET_HashCode))))
439 ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
440 (0 !=
441 memcmp (pra->public_data.namespace,
442 prb->public_data.namespace,
443 sizeof (struct GNUNET_HashCode)))))
444 return GNUNET_NO; 428 return GNUNET_NO;
445 return GNUNET_OK; 429 return GNUNET_OK;
446} 430}
@@ -546,11 +530,6 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
546 bm |= GET_MESSAGE_BIT_RETURN_TO; 530 bm |= GET_MESSAGE_BIT_RETURN_TO;
547 k++; 531 k++;
548 } 532 }
549 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
550 {
551 bm |= GET_MESSAGE_BIT_SKS_NAMESPACE;
552 k++;
553 }
554 if (NULL != pr->public_data.target) 533 if (NULL != pr->public_data.target)
555 { 534 {
556 bm |= GET_MESSAGE_BIT_TRANSMIT_TO; 535 bm |= GET_MESSAGE_BIT_TRANSMIT_TO;
@@ -586,8 +565,6 @@ GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
586 if (!do_route) 565 if (!do_route)
587 GNUNET_PEER_resolve (pr->sender_pid, 566 GNUNET_PEER_resolve (pr->sender_pid,
588 (struct GNUNET_PeerIdentity *) &ext[k++]); 567 (struct GNUNET_PeerIdentity *) &ext[k++]);
589 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
590 memcpy (&ext[k++], pr->public_data.namespace, sizeof (struct GNUNET_HashCode));
591 if (NULL != pr->public_data.target) 568 if (NULL != pr->public_data.target)
592 memcpy (&ext[k++], 569 memcpy (&ext[k++],
593 pr->public_data.target, 570 pr->public_data.target,
@@ -836,10 +813,7 @@ process_reply (void *cls, const struct GNUNET_HashCode * key, void *value)
836 GNUNET_NO); 813 GNUNET_NO);
837 prq->eval = 814 prq->eval =
838 GNUNET_BLOCK_evaluate (GSF_block_ctx, prq->type, key, &pr->bf, pr->mingle, 815 GNUNET_BLOCK_evaluate (GSF_block_ctx, prq->type, key, &pr->bf, pr->mingle,
839 pr->public_data.namespace, 816 NULL, 0, prq->data,
840 (prq->type ==
841 GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
842 sizeof (struct GNUNET_HashCode) : 0, prq->data,
843 prq->size); 817 prq->size);
844 switch (prq->eval) 818 switch (prq->eval)
845 { 819 {
@@ -1140,12 +1114,6 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1140 } 1114 }
1141 xquery = NULL; 1115 xquery = NULL;
1142 xquery_size = 0; 1116 xquery_size = 0;
1143 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
1144 {
1145 xquery = buf;
1146 memcpy (buf, pr->public_data.namespace, sizeof (struct GNUNET_HashCode));
1147 xquery_size = sizeof (struct GNUNET_HashCode);
1148 }
1149 if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY)) 1117 if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY))
1150 { 1118 {
1151 GNUNET_assert (0 != pr->sender_pid); 1119 GNUNET_assert (0 != pr->sender_pid);
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index 371aa660b..66488f79c 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -87,12 +87,6 @@ struct GSF_PendingRequestData
87 struct GNUNET_HashCode query; 87 struct GNUNET_HashCode query;
88 88
89 /** 89 /**
90 * Namespace to query, only set if the type is SBLOCK.
91 * Allocated after struct only if needed. Do not free!
92 */
93 const struct GNUNET_HashCode *namespace;
94
95 /**
96 * Identity of a peer hosting the content, otherwise NULl. 90 * Identity of a peer hosting the content, otherwise NULl.
97 * Allocated after struct only if needed. Do not free! 91 * Allocated after struct only if needed. Do not free!
98 */ 92 */
@@ -212,7 +206,6 @@ typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
212 * @param options request options 206 * @param options request options
213 * @param type type of the block that is being requested 207 * @param type type of the block that is being requested
214 * @param query key for the lookup 208 * @param query key for the lookup
215 * @param namespace namespace to lookup, NULL for no namespace
216 * @param target preferred target for the request, NULL for none 209 * @param target preferred target for the request, NULL for none
217 * @param bf_data raw data for bloom filter for known replies, can be NULL 210 * @param bf_data raw data for bloom filter for known replies, can be NULL
218 * @param bf_size number of bytes in bf_data 211 * @param bf_size number of bytes in bf_data
@@ -233,7 +226,6 @@ struct GSF_PendingRequest *
233GSF_pending_request_create_ (enum GSF_PendingRequestOptions options, 226GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
234 enum GNUNET_BLOCK_Type type, 227 enum GNUNET_BLOCK_Type type,
235 const struct GNUNET_HashCode * query, 228 const struct GNUNET_HashCode * query,
236 const struct GNUNET_HashCode * namespace,
237 const struct GNUNET_PeerIdentity *target, 229 const struct GNUNET_PeerIdentity *target,
238 const char *bf_data, size_t bf_size, 230 const char *bf_data, size_t bf_size,
239 uint32_t mingle, uint32_t anonymity_level, 231 uint32_t mingle, uint32_t anonymity_level,
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index 49962d314..ef796f559 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -83,9 +83,7 @@ struct PutOperator
83 * of block that we're putting into the DHT). 83 * of block that we're putting into the DHT).
84 */ 84 */
85static struct PutOperator operators[] = { 85static struct PutOperator operators[] = {
86 {NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0}, 86 {NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0},
87 {NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0},
88 {NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0},
89 {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0} 87 {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0}
90}; 88};
91 89
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 8e90589cf..468dd96a3 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -56,75 +56,67 @@
56 */ 56 */
57static enum GNUNET_BLOCK_EvaluationResult 57static enum GNUNET_BLOCK_EvaluationResult
58block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type, 58block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
59 const struct GNUNET_HashCode * query, 59 const struct GNUNET_HashCode *query,
60 struct GNUNET_CONTAINER_BloomFilter **bf, 60 struct GNUNET_CONTAINER_BloomFilter **bf,
61 int32_t bf_mutator, const void *xquery, 61 int32_t bf_mutator, const void *xquery,
62 size_t xquery_size, const void *reply_block, 62 size_t xquery_size, const void *reply_block,
63 size_t reply_block_size) 63 size_t reply_block_size)
64{ 64{
65 const struct SBlock *sb; 65 const struct UBlock *ub;
66 struct GNUNET_HashCode hc;
66 struct GNUNET_HashCode chash; 67 struct GNUNET_HashCode chash;
67 struct GNUNET_HashCode mhash; 68 struct GNUNET_HashCode mhash;
68 const struct GNUNET_HashCode *nsid;
69 struct GNUNET_HashCode sh;
70 69
71 switch (type) 70 switch (type)
72 { 71 {
73 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 72 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
74 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 73 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
75 if (xquery_size != 0) 74 if (0 != xquery_size)
76 { 75 {
77 GNUNET_break_op (0); 76 GNUNET_break_op (0);
78 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 77 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
79 } 78 }
80 if (reply_block == NULL) 79 if (NULL == reply_block)
81 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 80 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
82 return GNUNET_BLOCK_EVALUATION_OK_LAST; 81 return GNUNET_BLOCK_EVALUATION_OK_LAST;
83 case GNUNET_BLOCK_TYPE_FS_KBLOCK: 82 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
84 case GNUNET_BLOCK_TYPE_FS_NBLOCK: 83 if (0 != xquery_size)
85 if (xquery_size != 0)
86 { 84 {
87 GNUNET_break_op (0); 85 GNUNET_break_op (0);
88 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 86 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
89 } 87 }
90 if (reply_block == NULL) 88 if (NULL == reply_block)
91 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 89 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
92 if (NULL != bf) 90
91 if (reply_block_size < sizeof (struct UBlock))
93 { 92 {
94 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 93 GNUNET_break_op (0);
95 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); 94 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
96 if (NULL != *bf)
97 {
98 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
99 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
100 }
101 else
102 {
103 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
104 }
105 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
106 } 95 }
107 return GNUNET_BLOCK_EVALUATION_OK_MORE; 96 ub = reply_block;
108 case GNUNET_BLOCK_TYPE_FS_SBLOCK: 97 GNUNET_CRYPTO_hash (&ub->verification_key,
109 if (xquery_size != sizeof (struct GNUNET_HashCode)) 98 sizeof (ub->verification_key),
99 &hc);
100 if (0 != memcmp (&hc,
101 query,
102 sizeof (struct GNUNET_HashCode)))
110 { 103 {
111 GNUNET_break_op (0); 104 GNUNET_break_op (0);
112 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 105 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
113 } 106 }
114 if (reply_block == NULL) 107 if (reply_block_size != ntohl (ub->purpose.size) + sizeof (struct GNUNET_PseudonymSignature))
115 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 108 {
116 nsid = xquery; 109 GNUNET_break_op (0);
117 if (reply_block_size < sizeof (struct SBlock)) 110 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
111 }
112 if (GNUNET_OK !=
113 GNUNET_PSEUDONYM_verify (&ub->purpose,
114 &ub->signature,
115 &ub->verification_key))
118 { 116 {
119 GNUNET_break_op (0); 117 GNUNET_break_op (0);
120 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 118 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
121 } 119 }
122 sb = reply_block;
123 GNUNET_CRYPTO_hash (&sb->subspace,
124 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
125 &sh);
126 if (0 != memcmp (nsid, &sh, sizeof (struct GNUNET_HashCode)))
127 return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT;
128 if (NULL != bf) 120 if (NULL != bf)
129 { 121 {
130 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 122 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
@@ -161,11 +153,9 @@ block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
161static int 153static int
162block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type, 154block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type,
163 const void *block, size_t block_size, 155 const void *block, size_t block_size,
164 struct GNUNET_HashCode * key) 156 struct GNUNET_HashCode *key)
165{ 157{
166 const struct KBlock *kb; 158 const struct UBlock *ub;
167 const struct SBlock *sb;
168 const struct NBlock *nb;
169 159
170 switch (type) 160 switch (type)
171 { 161 {
@@ -173,104 +163,19 @@ block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type,
173 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 163 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
174 GNUNET_CRYPTO_hash (block, block_size, key); 164 GNUNET_CRYPTO_hash (block, block_size, key);
175 return GNUNET_OK; 165 return GNUNET_OK;
176 case GNUNET_BLOCK_TYPE_FS_KBLOCK: 166 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
177 if (block_size < sizeof (struct KBlock)) 167 if (block_size < sizeof (struct UBlock))
178 {
179 GNUNET_break_op (0);
180 return GNUNET_NO;
181 }
182 kb = block;
183 if (block_size - sizeof (struct KBlock) !=
184 ntohl (kb->purpose.size) -
185 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
186 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
187 {
188 GNUNET_break_op (0);
189 return GNUNET_NO;
190 }
191 if (GNUNET_OK !=
192 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
193 &kb->purpose, &kb->signature, &kb->keyspace))
194 {
195 GNUNET_break_op (0);
196 return GNUNET_NO;
197 }
198 if (key != NULL)
199 GNUNET_CRYPTO_hash (&kb->keyspace,
200 sizeof (struct
201 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
202 key);
203 return GNUNET_OK;
204 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
205 if (block_size < sizeof (struct SBlock))
206 {
207 GNUNET_break_op (0);
208 return GNUNET_NO;
209 }
210 sb = block;
211 if (block_size !=
212 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
213 {
214 GNUNET_break_op (0);
215 return GNUNET_NO;
216 }
217 if (GNUNET_OK !=
218 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
219 &sb->purpose, &sb->signature, &sb->subspace))
220 {
221 GNUNET_break_op (0);
222 return GNUNET_NO;
223 }
224 if (key != NULL)
225 *key = sb->identifier;
226 return GNUNET_OK;
227 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
228 if (block_size < sizeof (struct NBlock))
229 { 168 {
230 GNUNET_break_op (0); 169 GNUNET_break (0);
231 return GNUNET_NO; 170 return GNUNET_SYSERR;
232 }
233 nb = block;
234 if (block_size - sizeof (struct NBlock) !=
235 ntohl (nb->ns_purpose.size) -
236 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
237 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
238 {
239 GNUNET_break_op (0);
240 return GNUNET_NO;
241 }
242 if (block_size !=
243 ntohl (nb->ksk_purpose.size) +
244 sizeof (struct GNUNET_CRYPTO_RsaSignature))
245 {
246 GNUNET_break_op (0);
247 return GNUNET_NO;
248 }
249 if (GNUNET_OK !=
250 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
251 &nb->ksk_purpose, &nb->ksk_signature,
252 &nb->keyspace))
253 {
254 GNUNET_break_op (0);
255 return GNUNET_NO;
256 }
257 if (GNUNET_OK !=
258 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
259 &nb->ns_purpose, &nb->ns_signature,
260 &nb->subspace))
261 {
262 GNUNET_break_op (0);
263 return GNUNET_NO;
264 } 171 }
265 /* FIXME: we used to xor ID with NSID, 172 ub = block;
266 * why not here? */ 173 GNUNET_CRYPTO_hash (&ub->verification_key,
267 if (key != NULL) 174 sizeof (ub->verification_key),
268 GNUNET_CRYPTO_hash (&nb->keyspace, 175 key);
269 sizeof (struct
270 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
271 key);
272 return GNUNET_OK; 176 return GNUNET_OK;
273 default: 177 default:
178 GNUNET_break (0);
274 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
275 } 180 }
276} 181}
@@ -286,9 +191,7 @@ libgnunet_plugin_block_fs_init (void *cls)
286 { 191 {
287 GNUNET_BLOCK_TYPE_FS_DBLOCK, 192 GNUNET_BLOCK_TYPE_FS_DBLOCK,
288 GNUNET_BLOCK_TYPE_FS_IBLOCK, 193 GNUNET_BLOCK_TYPE_FS_IBLOCK,
289 GNUNET_BLOCK_TYPE_FS_KBLOCK, 194 GNUNET_BLOCK_TYPE_FS_UBLOCK,
290 GNUNET_BLOCK_TYPE_FS_SBLOCK,
291 GNUNET_BLOCK_TYPE_FS_NBLOCK,
292 GNUNET_BLOCK_TYPE_ANY /* end of list */ 195 GNUNET_BLOCK_TYPE_ANY /* end of list */
293 }; 196 };
294 struct GNUNET_BLOCK_PluginFunctions *api; 197 struct GNUNET_BLOCK_PluginFunctions *api;
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
index 5d7eb841c..a72197e10 100644
--- a/src/fs/test_fs_namespace.c
+++ b/src/fs/test_fs_namespace.c
@@ -29,7 +29,7 @@
29#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
30 30
31 31
32static struct GNUNET_HashCode nsid; 32static struct GNUNET_PseudonymIdentifier nsid;
33 33
34static struct GNUNET_FS_Uri *sks_expect_uri; 34static struct GNUNET_FS_Uri *sks_expect_uri;
35 35
@@ -43,64 +43,27 @@ static struct GNUNET_FS_SearchContext *ksk_search;
43 43
44static GNUNET_SCHEDULER_TaskIdentifier kill_task; 44static GNUNET_SCHEDULER_TaskIdentifier kill_task;
45 45
46static GNUNET_SCHEDULER_TaskIdentifier kill_ncc_task;
47
48struct GNUNET_FS_NamespaceCreationContext *ncc;
49
50static int update_started; 46static int update_started;
51 47
52static int err; 48static int err;
53 49
54static int phase;
55
56const struct GNUNET_CONFIGURATION_Handle *config;
57
58static void ns_created (void *cls, struct GNUNET_FS_Namespace *ns, const char *emsg);
59
60static void do_ncc_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
61
62 50
63static void 51static void
64next_phase () 52abort_ksk_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
65{ 53{
66 switch (phase) 54 if (ksk_search != NULL)
67 { 55 {
68 case 0: 56 GNUNET_FS_search_stop (ksk_search);
69 phase += 1; 57 ksk_search = NULL;
70 FPRINTF (stderr, "%s", "Testing asynchronous namespace creation\n"); 58 if (sks_search == NULL)
71 ncc = GNUNET_FS_namespace_create_start (fs, "testNamespace", ns_created, NULL);
72 if (NULL == ncc)
73 { 59 {
74 FPRINTF (stderr, "%s", "Failed to start asynchronous namespace creation\n"); 60 GNUNET_FS_stop (fs);
75 err = 1; 61 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
76 next_phase (); 62 GNUNET_SCHEDULER_cancel (kill_task);
77 return;
78 } 63 }
79 kill_ncc_task =
80 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_ncc_timeout,
81 NULL);
82 break;
83 case 1:
84 FPRINTF (stderr, "%s", "Shutting down FS\n");
85 GNUNET_FS_stop (fs);
86 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
87 GNUNET_SCHEDULER_cancel (kill_task);
88 kill_task = GNUNET_SCHEDULER_NO_TASK;
89 } 64 }
90} 65}
91 66
92static void
93abort_ksk_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94{
95 if (NULL == ksk_search)
96 return;
97 FPRINTF (stderr, "%s", "Stopping KSK search\n");
98 GNUNET_FS_search_stop (ksk_search);
99 ksk_search = NULL;
100 if (sks_search == NULL)
101 next_phase ();
102}
103
104 67
105static void 68static void
106abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 69abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -109,14 +72,17 @@ abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 72
110 if (sks_search == NULL) 73 if (sks_search == NULL)
111 return; 74 return;
112 FPRINTF (stderr, "%s", "Stopping SKS search\n");
113 GNUNET_FS_search_stop (sks_search); 75 GNUNET_FS_search_stop (sks_search);
114 sks_search = NULL; 76 sks_search = NULL;
115 ns = GNUNET_FS_namespace_create (fs, "testNamespace"); 77 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
116 GNUNET_assert (NULL != ns); 78 GNUNET_assert (NULL != ns);
117 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES)); 79 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_YES));
118 if (ksk_search == NULL) 80 if (ksk_search == NULL)
119 next_phase (); 81 {
82 GNUNET_FS_stop (fs);
83 if (GNUNET_SCHEDULER_NO_TASK != kill_task)
84 GNUNET_SCHEDULER_cancel (kill_task);
85 }
120} 86}
121 87
122 88
@@ -133,25 +99,18 @@ do_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
133static void * 99static void *
134progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 100progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
135{ 101{
136 char *got;
137 switch (event->status) 102 switch (event->status)
138 { 103 {
139 case GNUNET_FS_STATUS_SEARCH_RESULT: 104 case GNUNET_FS_STATUS_SEARCH_RESULT:
140 got = GNUNET_FS_uri_to_string (event->value.search.specifics.result.uri);
141 FPRINTF (stderr, "Got a search result `%s'\n", got);
142 if (sks_search == event->value.search.sc) 105 if (sks_search == event->value.search.sc)
143 { 106 {
144 if (!GNUNET_FS_uri_test_equal 107 if (!GNUNET_FS_uri_test_equal
145 (sks_expect_uri, event->value.search.specifics.result.uri)) 108 (sks_expect_uri, event->value.search.specifics.result.uri))
146 { 109 {
147 char *expected; 110 FPRINTF (stderr, "%s", "Wrong result for sks search!\n");
148 expected = GNUNET_FS_uri_to_string (sks_expect_uri);
149 FPRINTF (stderr, "Wrong result for sks search! Expected:\n%s\nGot:\n%s\n", expected, got);
150 GNUNET_free (expected);
151 err = 1; 111 err = 1;
152 } 112 }
153 /* give system 1ms to initiate update search! */ 113 /* give system 1ms to initiate update search! */
154 FPRINTF (stderr, "scheduling `%s'\n", "abort_sks_search_task");
155 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
156 &abort_sks_search_task, NULL); 115 &abort_sks_search_task, NULL);
157 } 116 }
@@ -160,22 +119,17 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
160 if (!GNUNET_FS_uri_test_equal 119 if (!GNUNET_FS_uri_test_equal
161 (ksk_expect_uri, event->value.search.specifics.result.uri)) 120 (ksk_expect_uri, event->value.search.specifics.result.uri))
162 { 121 {
163 char *expected; 122 FPRINTF (stderr, "%s", "Wrong result for ksk search!\n");
164 expected = GNUNET_FS_uri_to_string (ksk_expect_uri);
165 FPRINTF (stderr, "Wrong result for ksk search! Expected:\n%s\nGot:\n%s\n", expected, got);
166 GNUNET_free (expected);
167 err = 1; 123 err = 1;
168 } 124 }
169 FPRINTF (stderr, "scheduling `%s'\n", "abort_ksk_search_task");
170 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, NULL, 125 GNUNET_SCHEDULER_add_continuation (&abort_ksk_search_task, NULL,
171 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 126 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
172 } 127 }
173 else 128 else
174 { 129 {
175 FPRINTF (stderr, "Unexpected search result `%s' received!\n", got); 130 FPRINTF (stderr, "%s", "Unexpected search result received!\n");
176 GNUNET_break (0); 131 GNUNET_break (0);
177 } 132 }
178 GNUNET_free (got);
179 break; 133 break;
180 case GNUNET_FS_STATUS_SEARCH_ERROR: 134 case GNUNET_FS_STATUS_SEARCH_ERROR:
181 FPRINTF (stderr, "Error searching file: %s\n", 135 FPRINTF (stderr, "Error searching file: %s\n",
@@ -190,7 +144,6 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
190 GNUNET_break (0); 144 GNUNET_break (0);
191 break; 145 break;
192 case GNUNET_FS_STATUS_SEARCH_START: 146 case GNUNET_FS_STATUS_SEARCH_START:
193 FPRINTF (stderr, "Search %s started\n", event->value.search.pctx);
194 GNUNET_assert ((NULL == event->value.search.cctx) || 147 GNUNET_assert ((NULL == event->value.search.cctx) ||
195 (0 == strcmp ("sks_search", event->value.search.cctx)) || 148 (0 == strcmp ("sks_search", event->value.search.cctx)) ||
196 (0 == strcmp ("ksk_search", event->value.search.cctx))); 149 (0 == strcmp ("ksk_search", event->value.search.cctx)));
@@ -202,10 +155,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
202 GNUNET_assert (1 == event->value.search.anonymity); 155 GNUNET_assert (1 == event->value.search.anonymity);
203 break; 156 break;
204 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED: 157 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
205 FPRINTF (stderr, "%s", "Search result stopped\n");
206 return NULL; 158 return NULL;
207 case GNUNET_FS_STATUS_SEARCH_STOPPED: 159 case GNUNET_FS_STATUS_SEARCH_STOPPED:
208 FPRINTF (stderr, "%s", "Search stopped\n");
209 return NULL; 160 return NULL;
210 default: 161 default:
211 FPRINTF (stderr, "Unexpected event: %d\n", event->status); 162 FPRINTF (stderr, "Unexpected event: %d\n", event->status);
@@ -221,18 +172,20 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
221 char *msg; 172 char *msg;
222 struct GNUNET_FS_Uri *sks_uri; 173 struct GNUNET_FS_Uri *sks_uri;
223 char sbuf[1024]; 174 char sbuf[1024];
224 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 175 char buf[1024];
176 char *ret;
225 177
226 if (NULL != emsg) 178 if (NULL != emsg)
227 { 179 {
228 FPRINTF (stderr, "Error publishing ksk: %s\n", emsg); 180 FPRINTF (stderr, "Error publishing: %s\n", emsg);
229 err = 1; 181 err = 1;
230 GNUNET_FS_stop (fs); 182 GNUNET_FS_stop (fs);
231 return; 183 return;
232 } 184 }
233 FPRINTF (stderr, "%s", "Published ksk\n"); 185 ret = GNUNET_STRINGS_data_to_string (&nsid, sizeof (nsid), buf, sizeof (buf));
234 GNUNET_CRYPTO_hash_to_enc (&nsid, &enc); 186 GNUNET_assert (NULL != ret);
235 GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", &enc); 187 ret[0] = '\0';
188 GNUNET_snprintf (sbuf, sizeof (sbuf), "gnunet://fs/sks/%s/this", buf);
236 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); 189 sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
237 if (NULL == sks_uri) 190 if (NULL == sks_uri)
238 { 191 {
@@ -242,7 +195,6 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg)
242 GNUNET_free_non_null (msg); 195 GNUNET_free_non_null (msg);
243 return; 196 return;
244 } 197 }
245 FPRINTF (stderr, "%s", "Starting searches\n");
246 ksk_search = 198 ksk_search =
247 GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, 199 GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE,
248 "ksk_search"); 200 "ksk_search");
@@ -260,21 +212,17 @@ sks_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
260 struct GNUNET_FS_Uri *ksk_uri; 212 struct GNUNET_FS_Uri *ksk_uri;
261 char *msg; 213 char *msg;
262 struct GNUNET_FS_BlockOptions bo; 214 struct GNUNET_FS_BlockOptions bo;
263 char *suri;
264 215
265 if (NULL == uri) 216 if (NULL == uri)
266 { 217 {
267 fprintf (stderr, "Error publishing sks: %s\n", emsg); 218 fprintf (stderr, "Error publishing: %s\n", emsg);
268 err = 1; 219 err = 1;
269 GNUNET_FS_stop (fs); 220 GNUNET_FS_stop (fs);
270 return; 221 return;
271 } 222 }
272 FPRINTF (stderr, "%s", "Published sks\n");
273 meta = GNUNET_CONTAINER_meta_data_create (); 223 meta = GNUNET_CONTAINER_meta_data_create ();
274 msg = NULL; 224 msg = NULL;
275 GNUNET_asprintf (&suri, "gnunet://fs/ksk/ns-search%d", phase); 225 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg);
276 ksk_uri = GNUNET_FS_uri_parse (suri, &msg);
277 GNUNET_free (suri);
278 GNUNET_assert (NULL == msg); 226 GNUNET_assert (NULL == msg);
279 ksk_expect_uri = GNUNET_FS_uri_dup (uri); 227 ksk_expect_uri = GNUNET_FS_uri_dup (uri);
280 bo.content_priority = 1; 228 bo.content_priority = 1;
@@ -298,12 +246,11 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
298 246
299 if (NULL != emsg) 247 if (NULL != emsg)
300 { 248 {
301 FPRINTF (stderr, "Error advertising: %s\n", emsg); 249 FPRINTF (stderr, "Error publishing: %s\n", emsg);
302 err = 1; 250 err = 1;
303 GNUNET_FS_stop (fs); 251 GNUNET_FS_stop (fs);
304 return; 252 return;
305 } 253 }
306 FPRINTF (stderr, "%s", "Created an advertising\n");
307 ns = GNUNET_FS_namespace_create (fs, "testNamespace"); 254 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
308 GNUNET_assert (NULL != ns); 255 GNUNET_assert (NULL != ns);
309 meta = GNUNET_CONTAINER_meta_data_create (); 256 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -314,7 +261,7 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
314 bo.replication_level = 0; 261 bo.replication_level = 0;
315 bo.expiration_time = 262 bo.expiration_time =
316 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 263 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
317 GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri, /* FIXME: this is non-sense (use CHK URI!?) */ 264 GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, uri,
318 &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL); 265 &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &sks_cont, NULL);
319 GNUNET_CONTAINER_meta_data_destroy (meta); 266 GNUNET_CONTAINER_meta_data_destroy (meta);
320 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 267 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
@@ -322,27 +269,29 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
322 269
323 270
324static void 271static void
325ns_iterator (void *cls, const char *name, const struct GNUNET_HashCode * id) 272ns_iterator (void *cls, const char *name, const struct GNUNET_PseudonymIdentifier *id)
326{ 273{
327 int *ok = cls; 274 int *ok = cls;
328 275
329 FPRINTF (stderr, "Namespace in the list: %s\n", name);
330 if (0 != strcmp (name, "testNamespace")) 276 if (0 != strcmp (name, "testNamespace"))
331 return; 277 return;
332 *ok = GNUNET_YES; 278 *ok = GNUNET_YES;
333 nsid = *id; 279 nsid = *id;
334} 280}
335 281
282
336static void 283static void
337testCreatedNamespace (struct GNUNET_FS_Namespace *ns) 284testNamespace ()
338{ 285{
286 struct GNUNET_FS_Namespace *ns;
339 struct GNUNET_FS_BlockOptions bo; 287 struct GNUNET_FS_BlockOptions bo;
340 struct GNUNET_CONTAINER_MetaData *meta; 288 struct GNUNET_CONTAINER_MetaData *meta;
341 struct GNUNET_FS_Uri *ksk_uri; 289 struct GNUNET_FS_Uri *ksk_uri;
290 struct GNUNET_FS_Uri *sks_uri;
342 int ok; 291 int ok;
343 char *uri;
344 292
345 FPRINTF (stderr, "%s", "Listing namespaces\n"); 293 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
294 GNUNET_assert (NULL != ns);
346 ok = GNUNET_NO; 295 ok = GNUNET_NO;
347 GNUNET_FS_namespace_list (fs, &ns_iterator, &ok); 296 GNUNET_FS_namespace_list (fs, &ns_iterator, &ok);
348 if (GNUNET_NO == ok) 297 if (GNUNET_NO == ok)
@@ -353,65 +302,24 @@ testCreatedNamespace (struct GNUNET_FS_Namespace *ns)
353 err = 1; 302 err = 1;
354 return; 303 return;
355 } 304 }
356 FPRINTF (stderr, "%s", "Creating an advertising\n");
357 meta = GNUNET_CONTAINER_meta_data_create (); 305 meta = GNUNET_CONTAINER_meta_data_create ();
358 GNUNET_asprintf (&uri, "gnunet://fs/ksk/testnsa%d", phase); 306 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/testnsa", NULL);
359 ksk_uri = GNUNET_FS_uri_parse (uri, NULL);
360 GNUNET_free (uri);
361 bo.content_priority = 1; 307 bo.content_priority = 1;
362 bo.anonymity_level = 1; 308 bo.anonymity_level = 1;
363 bo.replication_level = 0; 309 bo.replication_level = 0;
364 bo.expiration_time = 310 bo.expiration_time =
365 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); 311 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
366 GNUNET_FS_namespace_advertise (fs, ksk_uri, ns, meta, &bo, "root", &adv_cont, 312 sks_uri = GNUNET_FS_uri_sks_create (ns, "root", NULL);
367 NULL); 313 GNUNET_FS_publish_ksk (fs,
368 GNUNET_FS_uri_destroy (ksk_uri); 314 ksk_uri, meta, sks_uri, &bo, GNUNET_FS_PUBLISH_OPTION_NONE,
369 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 315 &adv_cont, NULL);
370 GNUNET_CONTAINER_meta_data_destroy (meta); 316 GNUNET_FS_uri_destroy (sks_uri);
371}
372
373static void
374do_ncc_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
375{
376 FPRINTF (stderr, "%s", "Asynchronous NS creation timed out\n");
377 kill_ncc_task = GNUNET_SCHEDULER_NO_TASK;
378 if (NULL == ncc)
379 return;
380 GNUNET_FS_namespace_create_stop (ncc);
381 ncc = NULL;
382 err = 1;
383}
384
385static void
386ns_created (void *cls, struct GNUNET_FS_Namespace *ns, const char *emsg)
387{
388 if (GNUNET_SCHEDULER_NO_TASK != kill_ncc_task)
389 GNUNET_SCHEDULER_cancel (kill_ncc_task);
390 kill_ncc_task = GNUNET_SCHEDULER_NO_TASK;
391 if (NULL == ns)
392 {
393 FPRINTF (stderr, "Asynchronous NS creation failed: %s\n", emsg);
394 err = 1;
395 return;
396 }
397
398 FPRINTF (stderr, "%s", "Namespace created asynchronously\n");
399 testCreatedNamespace (ns);
400}
401
402static void
403testNamespace ()
404{
405 struct GNUNET_FS_Namespace *ns;
406
407 FPRINTF (stderr, "%s", "Testing synchronous namespace creation\n");
408 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
409 GNUNET_assert (NULL != ns);
410 testCreatedNamespace (ns);
411
412 kill_task = 317 kill_task =
413 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout, 318 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &do_timeout,
414 NULL); 319 NULL);
320 GNUNET_FS_uri_destroy (ksk_uri);
321 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
322 GNUNET_CONTAINER_meta_data_destroy (meta);
415} 323}
416 324
417 325
@@ -420,10 +328,8 @@ run (void *cls,
420 const struct GNUNET_CONFIGURATION_Handle *cfg, 328 const struct GNUNET_CONFIGURATION_Handle *cfg,
421 struct GNUNET_TESTING_Peer *peer) 329 struct GNUNET_TESTING_Peer *peer)
422{ 330{
423 config = cfg;
424 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, 331 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
425 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 332 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
426 phase = 0;
427 testNamespace (); 333 testNamespace ();
428} 334}
429 335
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c
index 47fa2024b..6d0bfdea9 100644
--- a/src/fs/test_fs_uri.c
+++ b/src/fs/test_fs_uri.c
@@ -162,6 +162,11 @@ testNamespace (int i)
162 char *uri; 162 char *uri;
163 struct GNUNET_FS_Uri *ret; 163 struct GNUNET_FS_Uri *ret;
164 char *emsg; 164 char *emsg;
165 struct GNUNET_PseudonymHandle *ph;
166 struct GNUNET_PseudonymIdentifier id;
167 char buf[1024];
168 char ubuf[1024];
169 char *sret;
165 170
166 if (NULL != 171 if (NULL !=
167 (ret = 172 (ret =
@@ -187,11 +192,17 @@ testNamespace (int i)
187 GNUNET_assert (0); 192 GNUNET_assert (0);
188 } 193 }
189 GNUNET_free (emsg); 194 GNUNET_free (emsg);
190 ret = 195 ph = GNUNET_PSEUDONYM_create (NULL);
191 GNUNET_FS_uri_parse 196 GNUNET_PSEUDONYM_get_identifier (ph, &id);
192 ("gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test", 197 sret = GNUNET_STRINGS_data_to_string (&id, sizeof (id),
193 &emsg); 198 ubuf, sizeof (ubuf) - 1);
194 if (ret == NULL) 199 GNUNET_assert (NULL != sret);
200 sret[0] = '\0';
201 GNUNET_snprintf (buf, sizeof (buf),
202 "gnunet://fs/sks/%s/test",
203 ubuf);
204 ret = GNUNET_FS_uri_parse (buf, &emsg);
205 if (NULL == ret)
195 { 206 {
196 GNUNET_free (emsg); 207 GNUNET_free (emsg);
197 GNUNET_assert (0); 208 GNUNET_assert (0);
@@ -210,7 +221,7 @@ testNamespace (int i)
210 uri = GNUNET_FS_uri_to_string (ret); 221 uri = GNUNET_FS_uri_to_string (ret);
211 if (0 != 222 if (0 !=
212 strcmp (uri, 223 strcmp (uri,
213 "gnunet://fs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) 224 buf))
214 { 225 {
215 GNUNET_FS_uri_destroy (ret); 226 GNUNET_FS_uri_destroy (ret);
216 GNUNET_free (uri); 227 GNUNET_free (uri);
diff --git a/src/include/block_fs.h b/src/include/block_fs.h
index 0b77adc49..6f37dcf0e 100644
--- a/src/include/block_fs.h
+++ b/src/include/block_fs.h
@@ -28,119 +28,49 @@
28 28
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31/**
32 * @brief keyword block (advertising data under a keyword)
33 */
34struct KBlock
35{
36
37 /**
38 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
39 */
40 struct GNUNET_CRYPTO_RsaSignature signature;
41
42 /**
43 * What is being signed and why?
44 */
45 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
46
47 /**
48 * Key generated (!) from the H(keyword) as the seed!
49 */
50 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
51
52 /* 0-terminated URI here */
53
54 /* variable-size Meta-Data follows here */
55
56};
57
58 31
59/** 32/**
60 * @brief namespace content block (advertising data under an identifier in a namespace) 33 * Maximum legal size for a ublock.
61 */ 34 */
62struct SBlock 35#define MAX_UBLOCK_SIZE (60 * 1024)
63{
64 36
65 /**
66 * GNUNET_RSA_Signature using RSA-key of the namespace
67 */
68 struct GNUNET_CRYPTO_RsaSignature signature;
69 37
70 /**
71 * What is being signed and why?
72 */
73 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
74
75 /**
76 * Hash of the hash of the human-readable identifier used for
77 * this entry (the hash of the human-readable identifier is
78 * used as the key for decryption; the xor of this identifier
79 * and the hash of the "keyspace" is the datastore-query hash).
80 */
81 struct GNUNET_HashCode identifier;
82
83 /**
84 * Public key of the namespace.
85 */
86 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
87
88 /* 0-terminated update-identifier here */
89
90 /* 0-terminated URI here (except for NBlocks) */
91
92 /* variable-size Meta-Data follows here */
93
94};
95 38
39GNUNET_NETWORK_STRUCT_BEGIN
96 40
97/** 41/**
98 * @brief namespace advertisement block (advertising root of a namespace) 42 * @brief universal block for keyword and namespace search results
99 */ 43 */
100struct NBlock 44struct UBlock
101{ 45{
102 46
103 /** 47 /**
104 * GNUNET_RSA_Signature using RSA-key generated from search keyword. 48 * Signature using pseudonym and search keyword / identifier.
105 */ 49 */
106 struct GNUNET_CRYPTO_RsaSignature ksk_signature; 50 struct GNUNET_PseudonymSignature signature;
107 51
108 /** 52 /**
109 * What is being signed and why? 53 * What is being signed and why?
110 */ 54 */
111 struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose; 55 struct GNUNET_PseudonymSignaturePurpose purpose;
112 56
113 /** 57 /**
114 * Key generated (!) from the H(keyword) as the seed! 58 * Public key used to sign this block. Hash of this value
59 * is the query.
115 */ 60 */
116 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace; 61 struct GNUNET_PseudonymIdentifier verification_key;
117 62
118 /** 63 /* rest of the data is encrypted */
119 * GNUNET_RSA_Signature using RSA-key of the namespace
120 */
121 struct GNUNET_CRYPTO_RsaSignature ns_signature;
122
123 /**
124 * What is being signed and why?
125 */
126 struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose;
127 64
128 /** 65 /* 0-terminated update-identifier here (ignored for keyword results) */
129 * Public key of the namespace.
130 */
131 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
132
133 /* from here on, data is encrypted with H(keyword) */
134 66
135 /* 0-terminated root identifier here */ 67 /* 0-terminated URI here */
136 68
137 /* variable-size Meta-Data follows here */ 69 /* variable-size Meta-Data follows here */
138 70
139}; 71};
140 72
141 73
142GNUNET_NETWORK_STRUCT_BEGIN
143
144/** 74/**
145 * @brief index block (indexing a DBlock that 75 * @brief index block (indexing a DBlock that
146 * can be obtained directly from reading 76 * can be obtained directly from reading
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 002d5c11b..ac9d9d5f8 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -41,15 +41,15 @@ extern "C"
41 */ 41 */
42enum GNUNET_BLOCK_Type 42enum GNUNET_BLOCK_Type
43{ 43{
44 /** 44 /**
45 * Any type of block, used as a wildcard when searching. Should 45 * Any type of block, used as a wildcard when searching. Should
46 * never be attached to a specific block. 46 * never be attached to a specific block.
47 */ 47 */
48 GNUNET_BLOCK_TYPE_ANY = 0, 48 GNUNET_BLOCK_TYPE_ANY = 0,
49 49
50 /** 50 /**
51 * Data block (leaf) in the CHK tree. 51 * Data block (leaf) in the CHK tree.
52 */ 52 */
53 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1, 53 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
54 54
55 /** 55 /**
@@ -57,67 +57,73 @@ enum GNUNET_BLOCK_Type
57 */ 57 */
58 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2, 58 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
59 59
60 /** 60 /**
61 * Type of a block representing a keyword search result. Note that 61 * Legacy type, no longer in use.
62 * the values for KBLOCK, SBLOCK and NBLOCK must be consecutive. 62 */
63 */
64 GNUNET_BLOCK_TYPE_FS_KBLOCK = 3, 63 GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
65 64
66 /** 65 /**
67 * Type of a block that is used to advertise content in a namespace. 66 * Legacy type, no longer in use.
68 */ 67 */
69 GNUNET_BLOCK_TYPE_FS_SBLOCK = 4, 68 GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
70 69
71 /** 70 /**
72 * Type of a block that is used to advertise a namespace. 71 * Legacy type, no longer in use.
73 */ 72 */
74 GNUNET_BLOCK_TYPE_FS_NBLOCK = 5, 73 GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
75 74
76 /** 75 /**
77 * Type of a block representing a block to be encoded on demand from disk. 76 * Type of a block representing a block to be encoded on demand from disk.
78 * Should never appear on the network directly. 77 * Should never appear on the network directly.
79 */ 78 */
80 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6, 79 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
81 80
82 /** 81 /**
83 * Type of a block that contains a HELLO for a peer (for 82 * Type of a block that contains a HELLO for a peer (for
84 * DHT find-peer operations). 83 * DHT find-peer operations).
85 */ 84 */
86 GNUNET_BLOCK_TYPE_DHT_HELLO = 7, 85 GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
87 86
88 /** 87 /**
89 * Block for testing. 88 * Block for testing.
90 */ 89 */
91 GNUNET_BLOCK_TYPE_TEST = 8, 90 GNUNET_BLOCK_TYPE_TEST = 8,
92 91
93 /** 92 /**
94 * Block for storing .gnunet-domains 93 * Type of a block representing any type of search result
95 */ 94 * (universal). Implemented in the context of #2564, replaces
95 * SBLOCKS, KBLOCKS and NBLOCKS.
96 */
97 GNUNET_BLOCK_TYPE_FS_UBLOCK = 9,
98
99 /**
100 * Block for storing .gnunet-domains
101 */
96 GNUNET_BLOCK_TYPE_DNS = 10, 102 GNUNET_BLOCK_TYPE_DNS = 10,
97 103
98 /** 104 /**
99 * Block for storing record data 105 * Block for storing record data
100 */ 106 */
101 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11, 107 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
102 108
103 /** 109 /**
104 * Block for storing mesh peers 110 * Block for storing mesh peers
105 */ 111 */
106 GNUNET_BLOCK_TYPE_MESH_PEER = 20, 112 GNUNET_BLOCK_TYPE_MESH_PEER = 20,
107 113
108 /** 114 /**
109 * Block for finding peers by type 115 * Block for finding peers by type
110 */ 116 */
111 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE = 21, 117 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE = 21,
112 118
113 /** 119 /**
114 * Block to store a mesh regex state 120 * Block to store a mesh regex state
115 */ 121 */
116 GNUNET_BLOCK_TYPE_REGEX = 22, 122 GNUNET_BLOCK_TYPE_REGEX = 22,
117 123
118 /** 124 /**
119 * Block to store a mesh regex accepting state 125 * Block to store a mesh regex accepting state
120 */ 126 */
121 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23 127 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23
122}; 128};
123 129
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index efe2cd004..931406e2d 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2004--2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -54,8 +54,9 @@ extern "C"
54 * 6.1.x: with simplified namespace support 54 * 6.1.x: with simplified namespace support
55 * 9.0.0: CPS-style integrated API 55 * 9.0.0: CPS-style integrated API
56 * 9.1.1: asynchronous directory scanning 56 * 9.1.1: asynchronous directory scanning
57 * 9.2.0: unified K-Block and S-block format (#2564)
57 */ 58 */
58#define GNUNET_FS_VERSION 0x00090103 59#define GNUNET_FS_VERSION 0x00090200
59 60
60 61
61/* ******************** URI API *********************** */ 62/* ******************** URI API *********************** */
@@ -342,25 +343,26 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
342/** 343/**
343 * Create an SKS URI from a namespace ID and an identifier. 344 * Create an SKS URI from a namespace ID and an identifier.
344 * 345 *
345 * @param nsid namespace ID 346 * @param pseudonym pseudonym to use
346 * @param id identifier 347 * @param id identifier
347 * @return an FS URI for the given namespace and identifier 348 * @return an FS URI for the given namespace and identifier
348 */ 349 */
349struct GNUNET_FS_Uri * 350struct GNUNET_FS_Uri *
350GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_HashCode * nsid, const char *id); 351GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_PseudonymIdentifier *pseudonym,
352 const char *id);
351 353
352 354
353/** 355/**
354 * Get the ID of a namespace from the given 356 * Get the public key of a namespace from the given
355 * namespace URI. 357 * namespace URI.
356 * 358 *
357 * @param uri the uri to get the namespace ID from 359 * @param uri the uri to get the namespace ID from
358 * @param nsid where to store the ID of the namespace 360 * @param pseudonym where to store the public key of the namespace
359 * @return GNUNET_OK on success 361 * @return GNUNET_OK on success
360 */ 362 */
361int 363int
362GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, 364GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
363 struct GNUNET_HashCode * nsid); 365 struct GNUNET_PseudonymIdentifier *pseudonym);
364 366
365 367
366/** 368/**
@@ -1403,9 +1405,9 @@ struct GNUNET_FS_ProgressInfo
1403 const struct GNUNET_CONTAINER_MetaData *meta; 1405 const struct GNUNET_CONTAINER_MetaData *meta;
1404 1406
1405 /** 1407 /**
1406 * Hash-identifier for the namespace. 1408 * Public key of the namespace.
1407 */ 1409 */
1408 struct GNUNET_HashCode id; 1410 struct GNUNET_PseudonymIdentifier pseudonym;
1409 1411
1410 } ns; 1412 } ns;
1411 1413
@@ -2189,60 +2191,6 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2189 2191
2190 2192
2191/** 2193/**
2192 * Context for advertising a namespace.
2193 */
2194struct GNUNET_FS_AdvertisementContext;
2195
2196
2197/**
2198 * Publish an advertismement for a namespace.
2199 *
2200 * @param h handle to the file sharing subsystem
2201 * @param ksk_uri keywords to use for advertisment
2202 * @param ns handle for the namespace that should be advertised
2203 * @param meta meta-data for the namespace advertisement
2204 * @param bo block options
2205 * @param rootEntry name of the root of the namespace
2206 * @param cont continuation
2207 * @param cont_cls closure for cont
2208 * @return NULL on error ('cont' will still be called)
2209 */
2210struct GNUNET_FS_AdvertisementContext *
2211GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2212 struct GNUNET_FS_Uri *ksk_uri,
2213 struct GNUNET_FS_Namespace *ns,
2214 const struct GNUNET_CONTAINER_MetaData *meta,
2215 const struct GNUNET_FS_BlockOptions *bo,
2216 const char *rootEntry,
2217 GNUNET_FS_PublishContinuation cont,
2218 void *cont_cls);
2219
2220
2221/**
2222 * Create an SKS uri that points to the root entry of the namespace,
2223 * then insert that SKS uri into metadata.
2224 *
2225 * @param ns handle for the namespace that should be advertised
2226 * @param meta meta-data into which namespace advertisement should be inserted
2227 * @param rootEntry name of the root of the namespace (use NULL to use default)
2228 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2229 */
2230int
2231GNUNET_FS_namespace_insert_advertisement_into_metadata (
2232 struct GNUNET_FS_Namespace *ns, struct GNUNET_CONTAINER_MetaData *meta,
2233 const char *rootEntry);
2234
2235
2236/**
2237 * Abort the namespace advertisement operation.
2238 *
2239 * @param ac context of the operation to abort.
2240 */
2241void
2242GNUNET_FS_namespace_advertise_cancel (struct GNUNET_FS_AdvertisementContext *ac);
2243
2244
2245/**
2246 * Create a namespace with the given name; if one already 2194 * Create a namespace with the given name; if one already
2247 * exists, return a handle to the existing namespace. 2195 * exists, return a handle to the existing namespace.
2248 * 2196 *
@@ -2268,45 +2216,6 @@ GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name)
2268 2216
2269 2217
2270/** 2218/**
2271 * Context for creating a namespace asynchronously.
2272 */
2273struct GNUNET_FS_NamespaceCreationContext;
2274
2275/**
2276 * Function called upon completion of 'GNUNET_FS_namespace_create_start'.
2277 *
2278 * @param cls closure
2279 * @param ns NULL on error, otherwise the namespace (which must be free'd by the callee)
2280 * @param emsg NULL on success, otherwise an error message
2281 */
2282typedef void (*GNUNET_FS_NamespaceCreationCallback)(void *cls,
2283 struct GNUNET_FS_Namespace *ns, const char *emsg);
2284
2285
2286/**
2287 * Create a namespace with the given name; if one already
2288 * exists, return a handle to the existing namespace immediately.
2289 * Otherwise create a namespace asynchronously.
2290 *
2291 * @param h handle to the file sharing subsystem
2292 * @param name name to use for the namespace
2293 * @return namespace creation context, NULL on error (i.e. invalid filename)
2294 */
2295struct GNUNET_FS_NamespaceCreationContext *
2296GNUNET_FS_namespace_create_start (struct GNUNET_FS_Handle *h, const char *name,
2297 GNUNET_FS_NamespaceCreationCallback cont, void *cont_cls);
2298
2299
2300/**
2301 * Abort namespace creation.
2302 *
2303 * @param ncc namespace creation context to abort
2304 */
2305void
2306GNUNET_FS_namespace_create_stop (struct GNUNET_FS_NamespaceCreationContext *ncc);
2307
2308
2309/**
2310 * Rename a local namespace. 2219 * Rename a local namespace.
2311 * 2220 *
2312 * @param h handle to the file sharing subsystem 2221 * @param h handle to the file sharing subsystem
@@ -2338,8 +2247,8 @@ GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns);
2338 * GNUNET_SYSERR on failure (contents of id remain intact) 2247 * GNUNET_SYSERR on failure (contents of id remain intact)
2339 */ 2248 */
2340int 2249int
2341GNUNET_FS_namespace_get_public_key_hash (struct GNUNET_FS_Namespace *ns, 2250GNUNET_FS_namespace_get_public_identifier (struct GNUNET_FS_Namespace *ns,
2342 struct GNUNET_HashCode *id); 2251 struct GNUNET_PseudonymIdentifier *id);
2343 2252
2344 2253
2345/** 2254/**
@@ -2364,10 +2273,10 @@ GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze);
2364 * 2273 *
2365 * @param cls closure 2274 * @param cls closure
2366 * @param name human-readable identifier of the namespace 2275 * @param name human-readable identifier of the namespace
2367 * @param id hash identifier for the namespace 2276 * @param id identifier for the namespace
2368 */ 2277 */
2369typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name, 2278typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2370 const struct GNUNET_HashCode * id); 2279 const struct GNUNET_PseudonymIdentifier *id);
2371 2280
2372 2281
2373/** 2282/**
diff --git a/src/include/gnunet_pseudonym_lib.h b/src/include/gnunet_pseudonym_lib.h
index 6ec51b678..11b5cd9e4 100644
--- a/src/include/gnunet_pseudonym_lib.h
+++ b/src/include/gnunet_pseudonym_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2001--2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -39,6 +39,166 @@ extern "C"
39#include "gnunet_configuration_lib.h" 39#include "gnunet_configuration_lib.h"
40#include "gnunet_container_lib.h" 40#include "gnunet_container_lib.h"
41 41
42
43/**
44 * Identifier for a GNUnet pseudonym (the public key).
45 */
46struct GNUNET_PseudonymIdentifier
47{
48 /**
49 * The public key of the pseudonym.
50 */
51 char public_key[42];
52};
53
54
55/**
56 * Handle for a pseudonym (private key).
57 */
58struct GNUNET_PseudonymHandle;
59
60
61/**
62 * Signature made with a pseudonym (includes the full public key)
63 */
64struct GNUNET_PseudonymSignature
65{
66
67 /**
68 * Who created the signature? (public key of the signer)
69 */
70 struct GNUNET_PseudonymIdentifier signer;
71
72 /**
73 * Binary signature data, padded with zeros if needed.
74 */
75 char signature[42];
76};
77
78
79/**
80 * Purpose for signature made with a pseudonym.
81 */
82struct GNUNET_PseudonymSignaturePurpose
83{
84 /**
85 * How many bytes are being signed (including this header)?
86 */
87 uint32_t size;
88
89 /**
90 * What is the context/purpose of the signature?
91 */
92 uint32_t purpose;
93};
94
95
96/**
97 * Create a pseudonym.
98 *
99 * @param filename name of the file to use for storage, NULL for in-memory only
100 * @return handle to the private key of the pseudonym
101 */
102struct GNUNET_PseudonymHandle *
103GNUNET_PSEUDONYM_create (const char *filename);
104
105
106/**
107 * Create a pseudonym, from a file that must already exist.
108 *
109 * @param filename name of the file to use for storage, NULL for in-memory only
110 * @return handle to the private key of the pseudonym
111 */
112struct GNUNET_PseudonymHandle *
113GNUNET_PSEUDONYM_create_from_existing_file (const char *filename);
114
115
116/**
117 * Get the handle for the 'anonymous' pseudonym shared by all users.
118 * That pseudonym uses a fixed 'secret' for the private key; this
119 * construction is useful to make anonymous and pseudonymous APIs
120 * (and packets) indistinguishable on the network. See #2564.
121 *
122 * @return handle to the (non-secret) private key of the 'anonymous' pseudonym
123 */
124struct GNUNET_PseudonymHandle *
125GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle (void);
126
127
128/**
129 * Destroy a pseudonym handle. Does NOT remove the private key from
130 * the disk.
131 *
132 * @param ph pseudonym handle to destroy
133 */
134void
135GNUNET_PSEUDONYM_destroy (struct GNUNET_PseudonymHandle *ph);
136
137
138/**
139 * Cryptographically sign some data with the pseudonym.
140 *
141 * @param ph private key used for signing (corresponds to 'x' in #2564)
142 * @param purpose data to sign
143 * @param seed hash of the plaintext of the data that we are signing,
144 * used for deterministic PRNG for anonymous signing;
145 * corresponds to 'k' in section 2.7 of #2564
146 * @param signing_key modifier to apply to the private key for signing;
147 * corresponds to 'h' in section 2.3 of #2564.
148 * @param signature where to store the signature
149 */
150void
151GNUNET_PSEUDONYM_sign (struct GNUNET_PseudonymHandle *ph,
152 const struct GNUNET_PseudonymSignaturePurpose *purpose,
153 const struct GNUNET_HashCode *seed,
154 const struct GNUNET_HashCode *signing_key,
155 struct GNUNET_PseudonymSignature *signature);
156
157
158/**
159 * Given a pseudonym and a signing key, derive the corresponding public
160 * key that would be used to verify the resulting signature.
161 *
162 * @param pseudonym the public key (g^x)
163 * @param signing_key input to derive 'h' (see section 2.4 of #2564)
164 * @param verification_key resulting public key to verify the signature
165 * created from the 'ph' of 'pseudonym' and the 'signing_key';
166 * the value stored here can then be given to GNUNET_PSEUDONYM_verify.
167 */
168void
169GNUNET_PSEUDONYM_derive_verification_key (struct GNUNET_PseudonymIdentifier *pseudonym,
170 const struct GNUNET_HashCode *signing_key,
171 struct GNUNET_PseudonymIdentifier *verification_key);
172
173
174/**
175 * Verify a signature made with a pseudonym.
176 *
177 * @param purpose data that was signed
178 * @param signature signature to verify
179 * @param verification_key public key to use for checking the signature;
180 * corresponds to 'g^(x+h)' in section 2.4 of #2564.
181 * @return GNUNET_OK on success (signature valid, 'pseudonym' set),
182 * GNUNET_SYSERR if the signature is invalid
183 */
184int
185GNUNET_PSEUDONYM_verify (const struct GNUNET_PseudonymSignaturePurpose *purpose,
186 const struct GNUNET_PseudonymSignature *signature,
187 const struct GNUNET_PseudonymIdentifier *verification_key);
188
189
190/**
191 * Get the identifier (public key) of a pseudonym.
192 *
193 * @param ph pseudonym handle with the private key
194 * @param pseudonym pseudonym identifier (set based on 'ph')
195 */
196void
197GNUNET_PSEUDONYM_get_identifier (struct GNUNET_PseudonymHandle *ph,
198 struct GNUNET_PseudonymIdentifier *pseudonym);
199
200
201
42/** 202/**
43 * Iterator over all known pseudonyms. 203 * Iterator over all known pseudonyms.
44 * 204 *
@@ -51,23 +211,26 @@ extern "C"
51 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort 211 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
52 */ 212 */
53typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, 213typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls,
54 const struct GNUNET_HashCode * pseudonym, 214 const struct GNUNET_PseudonymIdentifier *pseudonym,
55 const char *name, 215 const char *name,
56 const char *unique_name, 216 const char *unique_name,
57 const struct GNUNET_CONTAINER_MetaData 217 const struct GNUNET_CONTAINER_MetaData *md,
58 * md, int rating); 218 int32_t rating);
219
59 220
60/** 221/**
61 * Change the ranking of a pseudonym. 222 * Change the rank of a pseudonym.
62 * 223 *
63 * @param cfg overall configuration 224 * @param cfg overall configuration
64 * @param nsid id of the pseudonym 225 * @param pseudonym identity of the pseudonym
65 * @param delta by how much should the rating be changed? 226 * @param delta by how much should the rating be changed?
66 * @return new rating of the namespace 227 * @return new rating of the pseudonym
67 */ 228 */
68int 229int
69GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, 230GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
70 const struct GNUNET_HashCode * nsid, int delta); 231 const struct GNUNET_PseudonymIdentifier *pseudonym,
232 int32_t delta);
233
71 234
72/** 235/**
73 * Add a pseudonym to the set of known pseudonyms. 236 * Add a pseudonym to the set of known pseudonyms.
@@ -77,10 +240,11 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
77 * @param cfg overall configuration 240 * @param cfg overall configuration
78 * @param id the pseudonym identifier 241 * @param id the pseudonym identifier
79 * @param meta metadata for the pseudonym 242 * @param meta metadata for the pseudonym
243 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
80 */ 244 */
81void 245int
82GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, 246GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
83 const struct GNUNET_HashCode * id, 247 const struct GNUNET_PseudonymIdentifier *pseudonym,
84 const struct GNUNET_CONTAINER_MetaData *meta); 248 const struct GNUNET_CONTAINER_MetaData *meta);
85 249
86 250
@@ -89,37 +253,51 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
89 * 253 *
90 * @param cfg overall configuration 254 * @param cfg overall configuration
91 * @param iterator function to call for each pseudonym 255 * @param iterator function to call for each pseudonym
92 * @param closure closure for iterator 256 * @param iterator_cls closure for iterator
93 * @return number of pseudonyms found 257 * @return number of pseudonyms found
94 */ 258 */
95int 259int
96GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, 260GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
97 GNUNET_PSEUDONYM_Iterator iterator, void *closure); 261 GNUNET_PSEUDONYM_Iterator iterator,
262 void *iterator_cls);
263
264
265/**
266 * Handle for a discovery callback registration.
267 */
268struct GNUNET_PSEUDONYM_DiscoveryHandle;
269
98 270
99/** 271/**
100 * Register callback to be invoked whenever we discover 272 * Register callback to be invoked whenever we discover
101 * a new pseudonym. 273 * a new pseudonym.
274 *
275 * @param cfg our configuration
276 * @param iterator function to invoke on discovery
277 * @param iterator_cls closure for iterator
278 * @return registration handle
102 */ 279 */
103int 280struct GNUNET_PSEUDONYM_DiscoveryHandle *
104GNUNET_PSEUDONYM_discovery_callback_register (const struct 281GNUNET_PSEUDONYM_discovery_callback_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
105 GNUNET_CONFIGURATION_Handle *cfg, 282 GNUNET_PSEUDONYM_Iterator iterator,
106 GNUNET_PSEUDONYM_Iterator 283 void *iterator_cls);
107 iterator, void *closure); 284
108 285
109/** 286/**
110 * Unregister namespace discovery callback. 287 * Unregister pseudonym discovery callback.
288 *
289 * @param dh registration to unregister
111 */ 290 */
112int 291void
113GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator 292GNUNET_PSEUDONYM_discovery_callback_unregister (struct GNUNET_PSEUDONYM_DiscoveryHandle *dh);
114 iterator, void *closure); 293
115 294
116/** 295/**
117 * Return unique variant of the namespace name. 296 * Return unique variant of the pseudonym name. Use after
118 * Use after GNUNET_PSEUDONYM_id_to_name() to make sure 297 * GNUNET_PSEUDONYM_id_to_name() to make sure that name is unique.
119 * that name is unique.
120 * 298 *
121 * @param cfg configuration 299 * @param cfg configuration
122 * @param nsid cryptographic ID of the namespace 300 * @param pseudonym cryptographic ID of the pseudonym
123 * @param name name to uniquify 301 * @param name name to uniquify
124 * @param suffix if not NULL, filled with the suffix value 302 * @param suffix if not NULL, filled with the suffix value
125 * @return NULL on failure (should never happen), name on success. 303 * @return NULL on failure (should never happen), name on success.
@@ -127,18 +305,20 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
127 */ 305 */
128char * 306char *
129GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, 307GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
130 const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix); 308 const struct GNUNET_PseudonymIdentifier *pseudonym,
309 const char *name,
310 unsigned int *suffix);
311
131 312
132/** 313/**
133 * Get namespace name, metadata and rank 314 * Get pseudonym name, metadata and rank. This is a wrapper around
134 * This is a wrapper around internal read_info() call, and ensures that 315 * internal read_info() call, and ensures that returned data is not
135 * returned data is not invalid (not NULL). 316 * invalid (not NULL). Writing back information returned by this
136 * Writing back information returned by this function will give 317 * function will give a name "no-name" to pseudonyms that have no
137 * a name "no-name" to pseudonyms that have no name. This side-effect is 318 * name. This side-effect is unavoidable, but hardly harmful.
138 * unavoidable, but hardly harmful.
139 * 319 *
140 * @param cfg configuration 320 * @param cfg configuration
141 * @param nsid cryptographic ID of the namespace 321 * @param pseudonym cryptographic ID of the pseudonym
142 * @param ret_meta a location to store metadata pointer. NULL, if metadata 322 * @param ret_meta a location to store metadata pointer. NULL, if metadata
143 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy(). 323 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
144 * @param ret_rank a location to store rank. NULL, if rank not needed. 324 * @param ret_rank a location to store rank. NULL, if rank not needed.
@@ -152,27 +332,32 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
152 */ 332 */
153int 333int
154GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 334GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
155 const struct GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta, 335 const struct GNUNET_PseudonymIdentifier *pseudonym,
156 int32_t *ret_rank, char **ret_name, int *name_is_a_dup); 336 struct GNUNET_CONTAINER_MetaData **ret_meta,
337 int32_t *ret_rank,
338 char **ret_name,
339 int *name_is_a_dup);
157 340
158 341
159/** 342/**
160 * Get the namespace ID belonging to the given namespace name. 343 * Get the pseudonym ID belonging to the given pseudonym name.
161 * 344 *
162 * @param cfg configuration to use 345 * @param cfg configuration to use
163 * @param ns_uname unique (!) human-readable name for the namespace 346 * @param ps_uname unique (!) human-readable name for the pseudonym
164 * @param nsid set to namespace ID based on 'ns_uname' 347 * @param pseudonym set to pseudonym ID based on 'ns_uname'
165 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 348 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
166 */ 349 */
167int 350int
168GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, 351GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
169 const char *ns_uname, struct GNUNET_HashCode * nsid); 352 const char *ps_uname,
353 struct GNUNET_PseudonymIdentifier *pseudonym);
354
170 355
171/** 356/**
172 * Set the pseudonym metadata, rank and name. 357 * Set the pseudonym metadata, rank and name.
173 * 358 *
174 * @param cfg overall configuration 359 * @param cfg overall configuration
175 * @param nsid id of the pseudonym 360 * @param pseudonym id of the pseudonym
176 * @param name name to set. Must be the non-unique version of it. 361 * @param name name to set. Must be the non-unique version of it.
177 * May be NULL, in which case it erases pseudonym's name! 362 * May be NULL, in which case it erases pseudonym's name!
178 * @param md metadata to set 363 * @param md metadata to set
@@ -182,8 +367,10 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
182 */ 367 */
183int 368int
184GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 369GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
185 const struct GNUNET_HashCode * nsid, const char *name, 370 const struct GNUNET_PseudonymIdentifier *pseudonym,
186 const struct GNUNET_CONTAINER_MetaData *md, int rank); 371 const char *name,
372 const struct GNUNET_CONTAINER_MetaData *md,
373 int32_t rank);
187 374
188 375
189#if 0 /* keep Emacsens' auto-indent happy */ 376#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 2a2ba4755..a821a74df 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -66,22 +66,22 @@ extern "C"
66#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5 66#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5
67 67
68/** 68/**
69 * Signature in a KBlock of the FS module. 69 * Obsolete, legacy value.
70 */ 70 */
71#define GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK 6 71#define GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK 6
72 72
73/** 73/**
74 * Signature of content URI placed into a namespace. 74 * Obsolete, legacy value.
75 */ 75 */
76#define GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK 7 76#define GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK 7
77 77
78/** 78/**
79 * Signature of advertisment for a namespace. 79 * Obsolete, legacy value.
80 */ 80 */
81#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK 8 81#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK 8
82 82
83/** 83/**
84 * Keyword-based signature of advertisment for a namespace. 84 * Obsolete, legacy value.
85 */ 85 */
86#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG 9 86#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG 9
87 87
@@ -121,6 +121,10 @@ extern "C"
121#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16 121#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16
122 122
123 123
124/**
125 * UBlock Signature, done using DSS, not ECC
126 */
127#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17
124 128
125#if 0 /* keep Emacsens' auto-indent happy */ 129#if 0 /* keep Emacsens' auto-indent happy */
126{ 130{
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c
index fa48e19e3..02600cd6d 100644
--- a/src/util/pseudonym.c
+++ b/src/util/pseudonym.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2003, 2004, 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing authors) 3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -17,19 +17,22 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * @file util/pseudonym.c 21 * @file util/pseudonym.c
23 * @brief helper functions 22 * @brief helper functions
24 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 * TODO:
26 * - all cryptographic operations are currently NOT implemented and
27 * provided by stubs that merely pretend to work!
25 */ 28 */
26
27#include "platform.h" 29#include "platform.h"
28#include "gnunet_common.h" 30#include "gnunet_common.h"
29#include "gnunet_container_lib.h" 31#include "gnunet_container_lib.h"
30#include "gnunet_disk_lib.h" 32#include "gnunet_disk_lib.h"
31#include "gnunet_pseudonym_lib.h" 33#include "gnunet_pseudonym_lib.h"
32#include "gnunet_bio_lib.h" 34#include "gnunet_bio_lib.h"
35#include <gcrypt.h>
33 36
34#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 37#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
35 38
@@ -38,12 +41,12 @@
38/** 41/**
39 * Name of the directory which stores meta data for pseudonym 42 * Name of the directory which stores meta data for pseudonym
40 */ 43 */
41#define PS_METADATA_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms" DIR_SEPARATOR_STR "metadata" DIR_SEPARATOR_STR 44#define PS_METADATA_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonym" DIR_SEPARATOR_STR "metadata" DIR_SEPARATOR_STR
42 45
43/** 46/**
44 * Name of the directory which stores names for pseudonyms 47 * Name of the directory which stores names for pseudonyms
45 */ 48 */
46#define PS_NAMES_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms" DIR_SEPARATOR_STR "names" DIR_SEPARATOR_STR 49#define PS_NAMES_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonym" DIR_SEPARATOR_STR "names" DIR_SEPARATOR_STR
47 50
48 51
49/** 52/**
@@ -52,16 +55,22 @@
52#define GNUNET_CLIENT_SERVICE_NAME "client" 55#define GNUNET_CLIENT_SERVICE_NAME "client"
53 56
54 57
58/* ************************* Disk operations (pseudonym data mgmt) **************** */
55 59
56/** 60/**
57 * Registered callbacks for discovery of pseudonyms. 61 * Registered callbacks for discovery of pseudonyms.
58 */ 62 */
59struct DiscoveryCallback 63struct GNUNET_PSEUDONYM_DiscoveryHandle
60{ 64{
61 /** 65 /**
62 * This is a linked list. 66 * This is a doubly linked list.
63 */ 67 */
64 struct DiscoveryCallback *next; 68 struct GNUNET_PSEUDONYM_DiscoveryHandle *next;
69
70 /**
71 * This is a doubly linked list.
72 */
73 struct GNUNET_PSEUDONYM_DiscoveryHandle *prev;
65 74
66 /** 75 /**
67 * Function to call each time a pseudonym is discovered. 76 * Function to call each time a pseudonym is discovered.
@@ -71,7 +80,7 @@ struct DiscoveryCallback
71 /** 80 /**
72 * Closure for callback. 81 * Closure for callback.
73 */ 82 */
74 void *closure; 83 void *callback_cls;
75}; 84};
76 85
77 86
@@ -79,28 +88,33 @@ struct DiscoveryCallback
79 * Head of the linked list of functions to call when 88 * Head of the linked list of functions to call when
80 * new pseudonyms are added. 89 * new pseudonyms are added.
81 */ 90 */
82static struct DiscoveryCallback *head; 91static struct GNUNET_PSEUDONYM_DiscoveryHandle *disco_head;
92
93/**
94 * Tail of the linked list of functions to call when
95 * new pseudonyms are added.
96 */
97static struct GNUNET_PSEUDONYM_DiscoveryHandle *disco_tail;
98
83 99
84/** 100/**
85 * Internal notification about new tracked URI. 101 * Internal notification about new tracked URI.
86 * @param id a point to the hash code of pseudonym 102 *
103 * @param pseudonym public key of the pseudonym
87 * @param md meta data to be written 104 * @param md meta data to be written
88 * @param rating rating of pseudonym 105 * @param rating rating of pseudonym
89 */ 106 */
90static void 107static void
91internal_notify (const struct GNUNET_HashCode * id, 108internal_notify (const struct GNUNET_PseudonymIdentifier *pseudonym,
92 const struct GNUNET_CONTAINER_MetaData *md, int rating) 109 const struct GNUNET_CONTAINER_MetaData *md, int rating)
93{ 110{
94 struct DiscoveryCallback *pos; 111 struct GNUNET_PSEUDONYM_DiscoveryHandle *pos;
95 112
96 pos = head; 113 for (pos = disco_head; NULL != pos; pos = pos->next)
97 while (pos != NULL) 114 pos->callback (pos->callback_cls, pseudonym, NULL, NULL, md, rating);
98 {
99 pos->callback (pos->closure, id, NULL, NULL, md, rating);
100 pos = pos->next;
101 }
102} 115}
103 116
117
104/** 118/**
105 * Register callback to be invoked whenever we discover 119 * Register callback to be invoked whenever we discover
106 * a new pseudonym. 120 * a new pseudonym.
@@ -109,164 +123,197 @@ internal_notify (const struct GNUNET_HashCode * id,
109 * 123 *
110 * @param cfg configuration to use 124 * @param cfg configuration to use
111 * @param iterator iterator over pseudonym 125 * @param iterator iterator over pseudonym
112 * @param closure point to a closure 126 * @param iterator_cls point to a closure
127 * @return registration handle
113 */ 128 */
114int 129struct GNUNET_PSEUDONYM_DiscoveryHandle *
115GNUNET_PSEUDONYM_discovery_callback_register (const struct 130GNUNET_PSEUDONYM_discovery_callback_register (const struct
116 GNUNET_CONFIGURATION_Handle *cfg, 131 GNUNET_CONFIGURATION_Handle *cfg,
117 GNUNET_PSEUDONYM_Iterator 132 GNUNET_PSEUDONYM_Iterator iterator,
118 iterator, void *closure) 133 void *iterator_cls)
119{ 134{
120 struct DiscoveryCallback *list; 135 struct GNUNET_PSEUDONYM_DiscoveryHandle *dh;
121 136
122 list = GNUNET_malloc (sizeof (struct DiscoveryCallback)); 137 dh = GNUNET_malloc (sizeof (struct GNUNET_PSEUDONYM_DiscoveryHandle));
123 list->callback = iterator; 138 dh->callback = iterator;
124 list->closure = closure; 139 dh->callback_cls = iterator_cls;
125 list->next = head; 140 GNUNET_CONTAINER_DLL_insert (disco_head, disco_tail, dh);
126 head = list; 141 GNUNET_PSEUDONYM_list_all (cfg, iterator, iterator_cls);
127 GNUNET_PSEUDONYM_list_all (cfg, iterator, closure); 142 return dh;
128 return GNUNET_OK;
129} 143}
130 144
145
131/** 146/**
132 * Unregister pseudonym discovery callback. 147 * Unregister pseudonym discovery callback.
133 * @param iterator iterator over pseudonym 148 *
134 * @param closure point to a closure 149 * @param dh registration to unregister
135 */ 150 */
136int 151void
137GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator 152GNUNET_PSEUDONYM_discovery_callback_unregister (struct GNUNET_PSEUDONYM_DiscoveryHandle *dh)
138 iterator, void *closure)
139{ 153{
140 struct DiscoveryCallback *prev; 154 GNUNET_CONTAINER_DLL_remove (disco_head, disco_tail, dh);
141 struct DiscoveryCallback *pos; 155 GNUNET_free (dh);
142
143 prev = NULL;
144 pos = head;
145 while ((pos != NULL) &&
146 ((pos->callback != iterator) || (pos->closure != closure)))
147 {
148 prev = pos;
149 pos = pos->next;
150 }
151 if (pos == NULL)
152 return GNUNET_SYSERR;
153 if (prev == NULL)
154 head = pos->next;
155 else
156 prev->next = pos->next;
157 GNUNET_free (pos);
158 return GNUNET_OK;
159} 156}
160 157
161 158
162/** 159/**
163 * Get the filename (or directory name) for the given 160 * Get the filename (or directory name) for the given
164 * pseudonym identifier and directory prefix. 161 * pseudonym identifier and directory prefix.
162 *
165 * @param cfg configuration to use 163 * @param cfg configuration to use
166 * @param prefix path components to append to the private directory name 164 * @param prefix path components to append to the private directory name
167 * @param psid hash code of pseudonym, can be NULL 165 * @param pseudonym the pseudonym, can be NULL
168 * @return filename of the pseudonym (if psid != NULL) or directory with the data (if psid == NULL) 166 * @return filename of the pseudonym (if pseudonym != NULL) or directory with the data (if pseudonym == NULL)
169 */ 167 */
170static char * 168static char *
171get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, 169get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
172 const char *prefix, const struct GNUNET_HashCode * psid) 170 const char *prefix,
171 const struct GNUNET_PseudonymIdentifier *pseudonym)
173{ 172{
174 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 173 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
174 struct GNUNET_HashCode psid;
175 175
176 if (psid != NULL) 176 if (NULL != pseudonym)
177 GNUNET_CRYPTO_hash_to_enc (psid, &enc); 177 {
178 return GNUNET_DISK_get_home_filename (cfg, GNUNET_CLIENT_SERVICE_NAME, prefix, 178 GNUNET_CRYPTO_hash (pseudonym,
179 (psid == 179 sizeof (struct GNUNET_PseudonymIdentifier),
180 NULL) ? NULL : (const char *) &enc, 180 &psid);
181 GNUNET_CRYPTO_hash_to_enc (&psid, &enc);
182 }
183 return GNUNET_DISK_get_home_filename (cfg,
184 GNUNET_CLIENT_SERVICE_NAME, prefix,
185 (NULL == pseudonym)
186 ? NULL
187 : (const char *) &enc,
181 NULL); 188 NULL);
182} 189}
183 190
184 191
185/** 192/**
186 * Write the pseudonym infomation into a file 193 * Get the filename (or directory name) for the given
194 * hash code and directory prefix.
195 *
187 * @param cfg configuration to use 196 * @param cfg configuration to use
188 * @param nsid hash code of a pseudonym 197 * @param prefix path components to append to the private directory name
189 * @param meta meta data to be written into a file 198 * @param hc some hash code
190 * @param ranking ranking of a pseudonym 199 * @return filename of the pseudonym (if hc != NULL) or directory with the data (if hc == NULL)
191 * @param ns_name non-unique name of a pseudonym
192 */ 200 */
193static void 201static char *
194write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 202get_data_filename_hash (const struct GNUNET_CONFIGURATION_Handle *cfg,
195 const struct GNUNET_HashCode * nsid, 203 const char *prefix,
196 const struct GNUNET_CONTAINER_MetaData *meta, 204 const struct GNUNET_HashCode *hc)
197 int32_t ranking, const char *ns_name) 205{
206 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
207
208 if (NULL != hc)
209 GNUNET_CRYPTO_hash_to_enc (hc, &enc);
210 return GNUNET_DISK_get_home_filename (cfg,
211 GNUNET_CLIENT_SERVICE_NAME, prefix,
212 (NULL == hc)
213 ? NULL
214 : (const char *) &enc,
215 NULL);
216}
217
218
219/**
220 * Set the pseudonym metadata, rank and name.
221 * Writes the pseudonym infomation into a file
222 *
223 * @param cfg overall configuration
224 * @param nsid id of the pseudonym
225 * @param name name to set. Must be the non-unique version of it.
226 * May be NULL, in which case it erases pseudonym's name!
227 * @param md metadata to set
228 * May be NULL, in which case it erases pseudonym's metadata!
229 * @param rank rank to assign
230 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
231 */
232int
233GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
234 const struct GNUNET_PseudonymIdentifier *pseudonym,
235 const char *name,
236 const struct GNUNET_CONTAINER_MetaData *md,
237 int32_t rank)
198{ 238{
199 char *fn; 239 char *fn;
200 struct GNUNET_BIO_WriteHandle *fileW; 240 struct GNUNET_BIO_WriteHandle *fileW;
201 241
202 fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); 242 fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym);
203 GNUNET_assert (fn != NULL); 243 if (NULL == (fileW = GNUNET_BIO_write_open (fn)))
204 fileW = GNUNET_BIO_write_open (fn);
205 if (NULL != fileW)
206 { 244 {
207 if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) || 245 GNUNET_free (fn);
208 (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) || 246 return GNUNET_SYSERR;
209 (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta)))
210 {
211 (void) GNUNET_BIO_write_close (fileW);
212 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
213 GNUNET_free (fn);
214 return;
215 }
216 if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
217 {
218 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
219 GNUNET_free (fn);
220 return;
221 }
222 } 247 }
248 if ((GNUNET_OK != GNUNET_BIO_write (fileW, pseudonym,
249 sizeof (struct GNUNET_PseudonymIdentifier))) ||
250 (GNUNET_OK != GNUNET_BIO_write_int32 (fileW, rank)) ||
251 (GNUNET_OK != GNUNET_BIO_write_string (fileW, name)) ||
252 (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, md)))
253 {
254 (void) GNUNET_BIO_write_close (fileW);
255 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
256 GNUNET_free (fn);
257 return GNUNET_SYSERR;
258 }
259 if (GNUNET_OK != GNUNET_BIO_write_close (fileW))
260 {
261 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
262 GNUNET_free (fn);
263 return GNUNET_SYSERR;
264 }
223 GNUNET_free (fn); 265 GNUNET_free (fn);
224 /* create entry for pseudonym name in names */ 266 /* create entry for pseudonym name in names */
225 if (ns_name != NULL) 267 if (NULL != name)
226 GNUNET_free_non_null (GNUNET_PSEUDONYM_name_uniquify (cfg, nsid, ns_name, 268 GNUNET_free_non_null (GNUNET_PSEUDONYM_name_uniquify (cfg, pseudonym,
227 NULL)); 269 name, NULL));
270 return GNUNET_OK;
228} 271}
229 272
230 273
231/** 274/**
232 * read the pseudonym infomation from a file 275 * Read pseudonym infomation from a file
276 *
233 * @param cfg configuration to use 277 * @param cfg configuration to use
234 * @param nsid hash code of a pseudonym 278 * @param nsid hash code of a pseudonym
235 * @param meta meta data to be read from a file 279 * @param meta meta data to be read from a file
236 * @param ranking ranking of a pseudonym 280 * @param rank rank of a pseudonym
237 * @param ns_name name of a pseudonym 281 * @param ns_name name of a pseudonym
282 * @return GNUNET_OK on success, GNUNET_SYSERR on error
238 */ 283 */
239static int 284static int
240read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 285read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
241 const struct GNUNET_HashCode * nsid, 286 const struct GNUNET_PseudonymIdentifier *pseudonym,
242 struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking, 287 struct GNUNET_CONTAINER_MetaData **meta,
288 int32_t *rank,
243 char **ns_name) 289 char **ns_name)
244{ 290{
291 struct GNUNET_PseudonymIdentifier pd;
245 char *fn; 292 char *fn;
246 char *emsg; 293 char *emsg;
247 struct GNUNET_BIO_ReadHandle *fileR; 294 struct GNUNET_BIO_ReadHandle *fileR;
248 295
249 fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); 296 fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym);
250 GNUNET_assert (fn != NULL);
251 if (GNUNET_YES != 297 if (GNUNET_YES !=
252 GNUNET_DISK_file_test (fn)) 298 GNUNET_DISK_file_test (fn))
253 { 299 {
254 GNUNET_free (fn); 300 GNUNET_free (fn);
255 return GNUNET_SYSERR; 301 return GNUNET_SYSERR;
256 } 302 }
257 fileR = GNUNET_BIO_read_open (fn); 303 if (NULL == (fileR = GNUNET_BIO_read_open (fn)))
258 if (fileR == NULL)
259 { 304 {
260 GNUNET_free (fn); 305 GNUNET_free (fn);
261 return GNUNET_SYSERR; 306 return GNUNET_SYSERR;
262 } 307 }
263 emsg = NULL; 308 emsg = NULL;
264 *ns_name = NULL; 309 *ns_name = NULL;
265 if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || 310 if ( (GNUNET_OK != GNUNET_BIO_read (fileR, "pseudonym", &pd, sizeof (pd))) ||
266 (GNUNET_OK != 311 (0 != memcmp (&pd, pseudonym, sizeof (pd))) ||
267 GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || 312 (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, rank)) ||
268 (GNUNET_OK != 313 (GNUNET_OK !=
269 GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta))) 314 GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) ||
315 (GNUNET_OK !=
316 GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta)) )
270 { 317 {
271 (void) GNUNET_BIO_read_close (fileR, &emsg); 318 (void) GNUNET_BIO_read_close (fileR, &emsg);
272 GNUNET_free_non_null (emsg); 319 GNUNET_free_non_null (emsg);
@@ -296,12 +343,11 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
296 343
297 344
298/** 345/**
299 * Return unique variant of the namespace name. 346 * Return unique variant of the namespace name. Use it after
300 * Use it after GNUNET_PSEUDONYM_get_info() to make sure 347 * GNUNET_PSEUDONYM_get_info() to make sure that name is unique.
301 * that name is unique.
302 * 348 *
303 * @param cfg configuration 349 * @param cfg configuration
304 * @param nsid cryptographic ID of the namespace 350 * @param pseudonym public key of the pseudonym
305 * @param name name to uniquify 351 * @param name name to uniquify
306 * @param suffix if not NULL, filled with the suffix value 352 * @param suffix if not NULL, filled with the suffix value
307 * @return NULL on failure (should never happen), name on success. 353 * @return NULL on failure (should never happen), name on success.
@@ -309,9 +355,12 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
309 */ 355 */
310char * 356char *
311GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, 357GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
312 const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix) 358 const struct GNUNET_PseudonymIdentifier *pseudonym,
359 const char *name,
360 unsigned int *suffix)
313{ 361{
314 struct GNUNET_HashCode nh; 362 struct GNUNET_HashCode nh;
363 struct GNUNET_PseudonymIdentifier pi;
315 uint64_t len; 364 uint64_t len;
316 char *fn; 365 char *fn;
317 struct GNUNET_DISK_FileHandle *fh; 366 struct GNUNET_DISK_FileHandle *fh;
@@ -321,9 +370,7 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
321 struct stat sbuf; 370 struct stat sbuf;
322 371
323 GNUNET_CRYPTO_hash (name, strlen (name), &nh); 372 GNUNET_CRYPTO_hash (name, strlen (name), &nh);
324 fn = get_data_filename (cfg, PS_NAMES_DIR, &nh); 373 fn = get_data_filename_hash (cfg, PS_NAMES_DIR, &nh);
325 GNUNET_assert (fn != NULL);
326
327 len = 0; 374 len = 0;
328 if (0 == STAT (fn, &sbuf)) 375 if (0 == STAT (fn, &sbuf))
329 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES)); 376 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES));
@@ -334,11 +381,11 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
334 GNUNET_DISK_PERM_USER_WRITE); 381 GNUNET_DISK_PERM_USER_WRITE);
335 i = 0; 382 i = 0;
336 idx = -1; 383 idx = -1;
337 while ((len >= sizeof (struct GNUNET_HashCode)) && 384 while ((len >= sizeof (struct GNUNET_PseudonymIdentifier)) &&
338 (sizeof (struct GNUNET_HashCode) == 385 (sizeof (struct GNUNET_PseudonymIdentifier) ==
339 GNUNET_DISK_file_read (fh, &nh, sizeof (struct GNUNET_HashCode)))) 386 GNUNET_DISK_file_read (fh, &pi, sizeof (struct GNUNET_PseudonymIdentifier))))
340 { 387 {
341 if (0 == memcmp (&nh, nsid, sizeof (struct GNUNET_HashCode))) 388 if (0 == memcmp (&pi, pseudonym, sizeof (struct GNUNET_PseudonymIdentifier)))
342 { 389 {
343 idx = i; 390 idx = i;
344 break; 391 break;
@@ -346,11 +393,11 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
346 i++; 393 i++;
347 len -= sizeof (struct GNUNET_HashCode); 394 len -= sizeof (struct GNUNET_HashCode);
348 } 395 }
349 if (idx == -1) 396 if (-1 == idx)
350 { 397 {
351 idx = i; 398 idx = i;
352 if (sizeof (struct GNUNET_HashCode) != 399 if (sizeof (struct GNUNET_PseudonymIdentifier) !=
353 GNUNET_DISK_file_write (fh, nsid, sizeof (struct GNUNET_HashCode))) 400 GNUNET_DISK_file_write (fh, pseudonym, sizeof (struct GNUNET_PseudonymIdentifier)))
354 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn); 401 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn);
355 } 402 }
356 GNUNET_DISK_file_close (fh); 403 GNUNET_DISK_file_close (fh);
@@ -362,13 +409,14 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
362 return ret; 409 return ret;
363} 410}
364 411
412
365/** 413/**
366 * Get namespace name, metadata and rank 414 * Get namespace name, metadata and rank
367 * This is a wrapper around internal read_info() call, and ensures that 415 * This is a wrapper around internal read_info() call, and ensures that
368 * returned data is not invalid (not NULL). 416 * returned data is not invalid (not NULL).
369 * 417 *
370 * @param cfg configuration 418 * @param cfg configuration
371 * @param nsid cryptographic ID of the namespace 419 * @param pseudonym public key of the pseudonym
372 * @param ret_meta a location to store metadata pointer. NULL, if metadata 420 * @param ret_meta a location to store metadata pointer. NULL, if metadata
373 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy(). 421 * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
374 * @param ret_rank a location to store rank. NULL, if rank not needed. 422 * @param ret_rank a location to store rank. NULL, if rank not needed.
@@ -382,8 +430,11 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 */ 430 */
383int 431int
384GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, 432GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
385 const struct GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta, 433 const struct GNUNET_PseudonymIdentifier *pseudonym,
386 int32_t *ret_rank, char **ret_name, int *name_is_a_dup) 434 struct GNUNET_CONTAINER_MetaData **ret_meta,
435 int32_t *ret_rank,
436 char **ret_name,
437 int *name_is_a_dup)
387{ 438{
388 struct GNUNET_CONTAINER_MetaData *meta; 439 struct GNUNET_CONTAINER_MetaData *meta;
389 char *name; 440 char *name;
@@ -391,7 +442,7 @@ GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
391 442
392 meta = NULL; 443 meta = NULL;
393 name = NULL; 444 name = NULL;
394 if (GNUNET_OK == read_info (cfg, nsid, &meta, &rank, &name)) 445 if (GNUNET_OK == read_info (cfg, pseudonym, &meta, &rank, &name))
395 { 446 {
396 if ((meta != NULL) && (name == NULL)) 447 if ((meta != NULL) && (name == NULL))
397 name = 448 name =
@@ -446,17 +497,19 @@ GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
446 return GNUNET_SYSERR; 497 return GNUNET_SYSERR;
447} 498}
448 499
500
449/** 501/**
450 * Get the namespace ID belonging to the given namespace name. 502 * Get the namespace ID belonging to the given namespace name.
451 * 503 *
452 * @param cfg configuration to use 504 * @param cfg configuration to use
453 * @param ns_uname unique (!) human-readable name for the namespace 505 * @param ns_uname unique (!) human-readable name for the namespace
454 * @param nsid set to namespace ID based on 'ns_uname' 506 * @param pseudonym set to public key of pseudonym based on 'ns_uname'
455 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 507 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
456 */ 508 */
457int 509int
458GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, 510GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
459 const char *ns_uname, struct GNUNET_HashCode * nsid) 511 const char *ns_uname,
512 struct GNUNET_PseudonymIdentifier *pseudonym)
460{ 513{
461 size_t slen; 514 size_t slen;
462 uint64_t len; 515 uint64_t len;
@@ -470,19 +523,18 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
470 slen = strlen (ns_uname); 523 slen = strlen (ns_uname);
471 while ((slen > 0) && (1 != SSCANF (&ns_uname[slen - 1], "-%u", &idx))) 524 while ((slen > 0) && (1 != SSCANF (&ns_uname[slen - 1], "-%u", &idx)))
472 slen--; 525 slen--;
473 if (slen == 0) 526 if (0 == slen)
474 return GNUNET_SYSERR; 527 return GNUNET_SYSERR;
475 name = GNUNET_strdup (ns_uname); 528 name = GNUNET_strdup (ns_uname);
476 name[slen - 1] = '\0'; 529 name[slen - 1] = '\0';
477 530
478 GNUNET_CRYPTO_hash (name, strlen (name), &nh); 531 GNUNET_CRYPTO_hash (name, strlen (name), &nh);
479 GNUNET_free (name); 532 GNUNET_free (name);
480 fn = get_data_filename (cfg, PS_NAMES_DIR, &nh); 533 fn = get_data_filename_hash (cfg, PS_NAMES_DIR, &nh);
481 GNUNET_assert (fn != NULL);
482 534
483 if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || 535 if ((GNUNET_OK != GNUNET_DISK_file_test (fn) ||
484 (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES))) || 536 (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES))) ||
485 ((idx + 1) * sizeof (struct GNUNET_HashCode) > len)) 537 ((idx + 1) * sizeof (struct GNUNET_PseudonymIdentifier) > len))
486 { 538 {
487 GNUNET_free (fn); 539 GNUNET_free (fn);
488 return GNUNET_SYSERR; 540 return GNUNET_SYSERR;
@@ -494,14 +546,14 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
494 GNUNET_DISK_PERM_USER_WRITE); 546 GNUNET_DISK_PERM_USER_WRITE);
495 GNUNET_free (fn); 547 GNUNET_free (fn);
496 if (GNUNET_SYSERR == 548 if (GNUNET_SYSERR ==
497 GNUNET_DISK_file_seek (fh, idx * sizeof (struct GNUNET_HashCode), 549 GNUNET_DISK_file_seek (fh, idx * sizeof (struct GNUNET_PseudonymIdentifier),
498 GNUNET_DISK_SEEK_SET)) 550 GNUNET_DISK_SEEK_SET))
499 { 551 {
500 GNUNET_DISK_file_close (fh); 552 GNUNET_DISK_file_close (fh);
501 return GNUNET_SYSERR; 553 return GNUNET_SYSERR;
502 } 554 }
503 if (sizeof (struct GNUNET_HashCode) != 555 if (sizeof (struct GNUNET_PseudonymIdentifier) !=
504 GNUNET_DISK_file_read (fh, nsid, sizeof (struct GNUNET_HashCode))) 556 GNUNET_DISK_file_read (fh, pseudonym, sizeof (struct GNUNET_PseudonymIdentifier)))
505 { 557 {
506 GNUNET_DISK_file_close (fh); 558 GNUNET_DISK_file_close (fh);
507 return GNUNET_SYSERR; 559 return GNUNET_SYSERR;
@@ -526,7 +578,7 @@ struct ListPseudonymClosure
526 /** 578 /**
527 * Closure for iterator. 579 * Closure for iterator.
528 */ 580 */
529 void *closure; 581 void *iterator_cls;
530 582
531 /** 583 /**
532 * Configuration to use. 584 * Configuration to use.
@@ -537,47 +589,59 @@ struct ListPseudonymClosure
537 589
538 590
539/** 591/**
540 * the help function to list all available pseudonyms 592 * Helper function to list all available pseudonyms
593 *
541 * @param cls point to a struct ListPseudonymClosure 594 * @param cls point to a struct ListPseudonymClosure
542 * @param fullname name of pseudonym 595 * @param fullname name of pseudonym
543 */ 596 */
544static int 597static int
545list_pseudonym_helper (void *cls, const char *fullname) 598list_pseudonym_helper (void *cls, const char *fullname)
546{ 599{
547 struct ListPseudonymClosure *c = cls; 600 struct ListPseudonymClosure *lpc = cls;
548 int ret; 601 struct GNUNET_PseudonymIdentifier pd;
549 struct GNUNET_HashCode id; 602 char *emsg;
550 int32_t rating; 603 struct GNUNET_BIO_ReadHandle *fileR;
604 int32_t rank;
605 char *ns_name;
551 struct GNUNET_CONTAINER_MetaData *meta; 606 struct GNUNET_CONTAINER_MetaData *meta;
552 const char *fn; 607 int ret;
553 char *str;
554 char *name_unique; 608 char *name_unique;
555 609
556 if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) 610 if (NULL == (fileR = GNUNET_BIO_read_open (fullname)))
557 return GNUNET_OK; 611 return GNUNET_SYSERR;
558 fn = &fullname[strlen (fullname) + 1 - 612 emsg = NULL;
559 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; 613 ns_name = NULL;
560 if (fn[-1] != DIR_SEPARATOR) 614 if ( (GNUNET_OK != GNUNET_BIO_read (fileR, "pseudonym", &pd, sizeof (pd))) ||
561 return GNUNET_OK; 615 (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, &rank)) ||
562 ret = GNUNET_OK; 616 (GNUNET_OK !=
563 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id)) 617 GNUNET_BIO_read_string (fileR, "Read string error!", &ns_name, 200)) ||
564 return GNUNET_OK; /* invalid name */ 618 (GNUNET_OK !=
565 str = NULL; 619 GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", &meta)) )
566 if (GNUNET_OK != GNUNET_PSEUDONYM_get_info (c->cfg, &id, &meta, &rating,
567 &str, NULL))
568 { 620 {
569 /* ignore entry. FIXME: Why? Lack of data about a pseudonym is not a reason 621 (void) GNUNET_BIO_read_close (fileR, &emsg);
570 * to ignore it... So yeah, it will have placeholders instead of name, 622 GNUNET_free_non_null (emsg);
571 * empty metadata container and a default rank == -1, so what? We know 623 GNUNET_free_non_null (ns_name);
572 * its nsid - that's all we really need. Right? */ 624 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fullname));
573 GNUNET_free (str); 625 return GNUNET_SYSERR;
626 }
627 if (NULL == ns_name)
628 ns_name = GNUNET_strdup (_("no-name"));
629 if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg))
630 {
631 LOG (GNUNET_ERROR_TYPE_WARNING,
632 _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fullname,
633 emsg);
634 GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fullname));
574 GNUNET_CONTAINER_meta_data_destroy (meta); 635 GNUNET_CONTAINER_meta_data_destroy (meta);
575 return GNUNET_OK; 636 GNUNET_free (ns_name);
637 GNUNET_free_non_null (emsg);
638 return GNUNET_SYSERR;
576 } 639 }
577 name_unique = GNUNET_PSEUDONYM_name_uniquify (c->cfg, &id, str, NULL); 640 ret = GNUNET_OK;
578 if (c->iterator != NULL) 641 name_unique = GNUNET_PSEUDONYM_name_uniquify (lpc->cfg, &pd, ns_name, NULL);
579 ret = c->iterator (c->closure, &id, str, name_unique, meta, rating); 642 if (NULL != lpc->iterator)
580 GNUNET_free_non_null (str); 643 ret = lpc->iterator (lpc->iterator_cls, &pd, ns_name, name_unique, meta, rank);
644 GNUNET_free (ns_name);
581 GNUNET_free_non_null (name_unique); 645 GNUNET_free_non_null (name_unique);
582 GNUNET_CONTAINER_meta_data_destroy (meta); 646 GNUNET_CONTAINER_meta_data_destroy (meta);
583 return ret; 647 return ret;
@@ -589,19 +653,20 @@ list_pseudonym_helper (void *cls, const char *fullname)
589 * 653 *
590 * @param cfg overall configuration 654 * @param cfg overall configuration
591 * @param iterator function to call for each pseudonym 655 * @param iterator function to call for each pseudonym
592 * @param closure closure for iterator 656 * @param iterator_cls closure for iterator
593 * @return number of pseudonyms found 657 * @return number of pseudonyms found
594 */ 658 */
595int 659int
596GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, 660GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
597 GNUNET_PSEUDONYM_Iterator iterator, void *closure) 661 GNUNET_PSEUDONYM_Iterator iterator,
662 void *iterator_cls)
598{ 663{
599 struct ListPseudonymClosure cls; 664 struct ListPseudonymClosure cls;
600 char *fn; 665 char *fn;
601 int ret; 666 int ret;
602 667
603 cls.iterator = iterator; 668 cls.iterator = iterator;
604 cls.closure = closure; 669 cls.iterator_cls = iterator_cls;
605 cls.cfg = cfg; 670 cls.cfg = cfg;
606 fn = get_data_filename (cfg, PS_METADATA_DIR, NULL); 671 fn = get_data_filename (cfg, PS_METADATA_DIR, NULL);
607 GNUNET_assert (fn != NULL); 672 GNUNET_assert (fn != NULL);
@@ -613,60 +678,35 @@ GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
613 678
614 679
615/** 680/**
616 * Change the ranking of a pseudonym. 681 * Change the rank of a pseudonym.
617 * 682 *
618 * @param cfg overall configuration 683 * @param cfg overall configuration
619 * @param nsid id of the pseudonym 684 * @param pseudonym the pseudonym
620 * @param delta by how much should the rating be 685 * @param delta by how much should the rating be changed?
621 * changed?
622 * @return new rating of the pseudonym 686 * @return new rating of the pseudonym
623 */ 687 */
624int 688int
625GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, 689GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
626 const struct GNUNET_HashCode * nsid, int delta) 690 const struct GNUNET_PseudonymIdentifier *pseudonym,
691 int32_t delta)
627{ 692{
628 struct GNUNET_CONTAINER_MetaData *meta; 693 struct GNUNET_CONTAINER_MetaData *meta;
629 int ret; 694 int ret;
630 int32_t ranking; 695 int32_t rank;
631 char *name; 696 char *name;
632 697
633 name = NULL; 698 name = NULL;
634 ret = read_info (cfg, nsid, &meta, &ranking, &name); 699 ret = read_info (cfg, pseudonym, &meta, &rank, &name);
635 if (ret == GNUNET_SYSERR) 700 if (ret == GNUNET_SYSERR)
636 { 701 {
637 ranking = 0; 702 rank = 0;
638 meta = GNUNET_CONTAINER_meta_data_create (); 703 meta = GNUNET_CONTAINER_meta_data_create ();
639 } 704 }
640 ranking += delta; 705 rank += delta;
641 write_pseudonym_info (cfg, nsid, meta, ranking, name); 706 GNUNET_PSEUDONYM_set_info (cfg, pseudonym, name, meta, rank);
642 GNUNET_CONTAINER_meta_data_destroy (meta); 707 GNUNET_CONTAINER_meta_data_destroy (meta);
643 GNUNET_free_non_null (name); 708 GNUNET_free_non_null (name);
644 return ranking; 709 return rank;
645}
646
647
648/**
649 * Set the pseudonym metadata, rank and name.
650 *
651 * @param cfg overall configuration
652 * @param nsid id of the pseudonym
653 * @param name name to set. Must be the non-unique version of it.
654 * May be NULL, in which case it erases pseudonym's name!
655 * @param md metadata to set
656 * May be NULL, in which case it erases pseudonym's metadata!
657 * @param rank rank to assign
658 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
659 */
660int
661GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
662 const struct GNUNET_HashCode * nsid, const char *name,
663 const struct GNUNET_CONTAINER_MetaData *md, int rank)
664{
665 GNUNET_assert (cfg != NULL);
666 GNUNET_assert (nsid != NULL);
667
668 write_pseudonym_info (cfg, nsid, md, rank, name);
669 return GNUNET_OK;
670} 710}
671 711
672 712
@@ -676,38 +716,233 @@ GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
676 * FS should automatically call this function. 716 * FS should automatically call this function.
677 * 717 *
678 * @param cfg overall configuration 718 * @param cfg overall configuration
679 * @param id the pseudonym identifier 719 * @param pseudonym the pseudonym to add
680 * @param meta metadata for the pseudonym 720 * @param meta metadata for the pseudonym
721 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
681 */ 722 */
682void 723int
683GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, 724GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
684 const struct GNUNET_HashCode * id, 725 const struct GNUNET_PseudonymIdentifier *pseudonym,
685 const struct GNUNET_CONTAINER_MetaData *meta) 726 const struct GNUNET_CONTAINER_MetaData *meta)
686{ 727{
687 char *name; 728 char *name;
688 int32_t ranking; 729 int32_t rank;
689 struct GNUNET_CONTAINER_MetaData *old; 730 struct GNUNET_CONTAINER_MetaData *old;
690 char *fn; 731 char *fn;
691 struct stat sbuf; 732 struct stat sbuf;
733 int ret;
692 734
693 ranking = 0; 735 rank = 0;
694 fn = get_data_filename (cfg, PS_METADATA_DIR, id); 736 fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym);
695 GNUNET_assert (fn != NULL); 737 GNUNET_assert (fn != NULL);
696 738
697 if ((0 == STAT (fn, &sbuf)) && 739 if ((0 == STAT (fn, &sbuf)) &&
698 (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) 740 (GNUNET_OK == read_info (cfg, pseudonym, &old, &rank, &name)))
699 { 741 {
700 GNUNET_CONTAINER_meta_data_merge (old, meta); 742 GNUNET_CONTAINER_meta_data_merge (old, meta);
701 write_pseudonym_info (cfg, id, old, ranking, name); 743 ret = GNUNET_PSEUDONYM_set_info (cfg, pseudonym, name, old, rank);
702 GNUNET_CONTAINER_meta_data_destroy (old); 744 GNUNET_CONTAINER_meta_data_destroy (old);
703 GNUNET_free_non_null (name); 745 GNUNET_free_non_null (name);
704 } 746 }
705 else 747 else
706 { 748 {
707 write_pseudonym_info (cfg, id, meta, ranking, NULL); 749 ret = GNUNET_PSEUDONYM_set_info (cfg, pseudonym, NULL, meta, rank);
708 } 750 }
709 GNUNET_free (fn); 751 GNUNET_free (fn);
710 internal_notify (id, meta, ranking); 752 internal_notify (pseudonym, meta, rank);
753 return ret;
754}
755
756
757/* ***************************** cryptographic operations ************************* */
758
759/**
760 * Handle for a pseudonym (private key).
761 */
762struct GNUNET_PseudonymHandle
763{
764 /**
765 * FIXME.
766 */
767 char data[42];
768};
769
770
771/**
772 * Create a pseudonym.
773 *
774 * @param filename name of the file to use for storage, NULL for in-memory only
775 * @return handle to the private key of the pseudonym
776 */
777struct GNUNET_PseudonymHandle *
778GNUNET_PSEUDONYM_create (const char *filename)
779{
780 struct GNUNET_PseudonymHandle *ph;
781 ssize_t ret;
782
783 ph = GNUNET_malloc (sizeof (struct GNUNET_PseudonymHandle));
784 if (NULL != filename)
785 {
786 ret = GNUNET_DISK_fn_read (filename, ph,
787 sizeof (struct GNUNET_PseudonymHandle));
788 if (sizeof (struct GNUNET_PseudonymHandle) == ret)
789 return ph;
790 }
791 GNUNET_break (0); // not implemented...
792 gcry_randomize (ph, sizeof (struct GNUNET_PseudonymHandle),
793 GCRY_STRONG_RANDOM);
794 if (NULL != filename)
795 {
796 ret = GNUNET_DISK_fn_write (filename, ph, sizeof (struct GNUNET_PseudonymHandle),
797 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
798 if (sizeof (struct GNUNET_PseudonymHandle) != ret)
799 {
800 GNUNET_free (ph);
801 return NULL;
802 }
803 }
804 return ph;
805}
806
807
808/**
809 * Create a pseudonym, from a file that must already exist.
810 *
811 * @param filename name of the file to use for storage, NULL for in-memory only
812 * @return handle to the private key of the pseudonym
813 */
814struct GNUNET_PseudonymHandle *
815GNUNET_PSEUDONYM_create_from_existing_file (const char *filename)
816{
817 struct GNUNET_PseudonymHandle *ph;
818 ssize_t ret;
819
820 ph = GNUNET_malloc (sizeof (struct GNUNET_PseudonymHandle));
821 ret = GNUNET_DISK_fn_read (filename, ph,
822 sizeof (struct GNUNET_PseudonymHandle));
823 if (sizeof (struct GNUNET_PseudonymHandle) == ret)
824 return ph;
825 GNUNET_free (ph);
826 return NULL;
827}
828
829
830/**
831 * Get the handle for the 'anonymous' pseudonym shared by all users.
832 * That pseudonym uses a fixed 'secret' for the private key; this
833 * construction is useful to make anonymous and pseudonymous APIs
834 * (and packets) indistinguishable on the network. See #2564.
835 *
836 * @return handle to the (non-secret) private key of the 'anonymous' pseudonym
837 */
838struct GNUNET_PseudonymHandle *
839GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle ()
840{
841 struct GNUNET_PseudonymHandle *ph;
842
843 ph = GNUNET_malloc (sizeof (struct GNUNET_PseudonymHandle));
844 GNUNET_break (0);
845 return ph;
846}
847
848
849/**
850 * Destroy a pseudonym handle. Does NOT remove the private key from
851 * the disk.
852 *
853 * @param ph pseudonym handle to destroy
854 */
855void
856GNUNET_PSEUDONYM_destroy (struct GNUNET_PseudonymHandle *ph)
857{
858 GNUNET_free (ph);
859}
860
861
862/**
863 * Cryptographically sign some data with the pseudonym.
864 *
865 * @param ph private key used for signing (corresponds to 'x' in #2564)
866 * @param purpose data to sign
867 * @param seed hash of the plaintext of the data that we are signing,
868 * used for deterministic PRNG for anonymous signing;
869 * corresponds to 'k' in section 2.7 of #2564
870 * @param signing_key modifier to apply to the private key for signing;
871 * corresponds to 'h' in section 2.3 of #2564.
872 * @param signature where to store the signature
873 */
874void
875GNUNET_PSEUDONYM_sign (struct GNUNET_PseudonymHandle *ph,
876 const struct GNUNET_PseudonymSignaturePurpose *purpose,
877 const struct GNUNET_HashCode *seed,
878 const struct GNUNET_HashCode *signing_key,
879 struct GNUNET_PseudonymSignature *signature)
880{
881 memset (signature, 0, sizeof (struct GNUNET_PseudonymSignature));
882 GNUNET_break (0);
883}
884
885
886/**
887 * Given a pseudonym and a signing key, derive the corresponding public
888 * key that would be used to verify the resulting signature.
889 *
890 * @param pseudonym the public key (g^x)
891 * @param signing_key input to derive 'h' (see section 2.4 of #2564)
892 * @param verification_key resulting public key to verify the signature
893 * created from the 'ph' of 'pseudonym' and the 'signing_key';
894 * the value stored here can then be given to GNUNET_PSEUDONYM_verify.
895 */
896void
897GNUNET_PSEUDONYM_derive_verification_key (struct GNUNET_PseudonymIdentifier *pseudonym,
898 const struct GNUNET_HashCode *signing_key,
899 struct GNUNET_PseudonymIdentifier *verification_key)
900{
901 struct GNUNET_HashCode hc;
902 struct GNUNET_HashCode x;
903
904 GNUNET_break (0);
905 GNUNET_CRYPTO_hash (pseudonym, sizeof (*pseudonym), &hc);
906 GNUNET_CRYPTO_hash_xor (&hc, signing_key, &x);
907 memset (verification_key, 0, sizeof (struct GNUNET_PseudonymIdentifier));
908 memcpy (verification_key, &x, GNUNET_MIN (sizeof (x), sizeof (*verification_key)));
909}
910
911
912/**
913 * Verify a signature made with a pseudonym.
914 *
915 * @param purpose data that was signed
916 * @param signature signature to verify
917 * @param verification_key public key to use for checking the signature;
918 * corresponds to 'g^(x+h)' in section 2.4 of #2564.
919 * @return GNUNET_OK on success (signature valid, 'pseudonym' set),
920 * GNUNET_SYSERR if the signature is invalid
921 */
922int
923GNUNET_PSEUDONYM_verify (const struct GNUNET_PseudonymSignaturePurpose *purpose,
924 const struct GNUNET_PseudonymSignature *signature,
925 const struct GNUNET_PseudonymIdentifier *verification_key)
926{
927 GNUNET_break (0);
928 return GNUNET_OK;
929}
930
931
932/**
933 * Get the identifier (public key) of a pseudonym.
934 *
935 * @param ph pseudonym handle with the private key
936 * @param pseudonym pseudonym identifier (set based on 'ph')
937 */
938void
939GNUNET_PSEUDONYM_get_identifier (struct GNUNET_PseudonymHandle *ph,
940 struct GNUNET_PseudonymIdentifier *pseudonym)
941{
942 GNUNET_break (0);
943 memcpy (pseudonym, ph,
944 GNUNET_MIN (sizeof (struct GNUNET_PseudonymIdentifier),
945 sizeof (*ph)));
711} 946}
712 947
713 948
diff --git a/src/util/strings.c b/src/util/strings.c
index 9856a15c4..de32b1c03 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -803,11 +803,6 @@ GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out, size_t
803 out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; 803 out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
804 vbit -= 5; 804 vbit -= 5;
805 } 805 }
806 if (wpos != out_size)
807 {
808 GNUNET_break (0);
809 return NULL;
810 }
811 GNUNET_assert (vbit == 0); 806 GNUNET_assert (vbit == 0);
812 return &out[wpos]; 807 return &out[wpos];
813} 808}
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c
index 56159be1c..2586aadd0 100644
--- a/src/util/test_pseudonym.c
+++ b/src/util/test_pseudonym.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2005--2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -23,7 +23,6 @@
23 * @brief testcase for pseudonym.c 23 * @brief testcase for pseudonym.c
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_common.h" 27#include "gnunet_common.h"
29#include "gnunet_container_lib.h" 28#include "gnunet_container_lib.h"
@@ -35,16 +34,17 @@
35 34
36static struct GNUNET_CONTAINER_MetaData *meta; 35static struct GNUNET_CONTAINER_MetaData *meta;
37 36
38static struct GNUNET_HashCode id1; 37static struct GNUNET_PseudonymIdentifier id1;
38
39 39
40static int 40static int
41iter (void *cls, const struct GNUNET_HashCode * pseudonym, 41iter (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym,
42 const char *name, const char *unique_name, 42 const char *name, const char *unique_name,
43 const struct GNUNET_CONTAINER_MetaData *md, int rating) 43 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
44{ 44{
45 int *ok = cls; 45 int *ok = cls;
46 46
47 if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_HashCode))) && 47 if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_PseudonymIdentifier))) &&
48 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) 48 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta)))
49 { 49 {
50 *ok = GNUNET_NO; 50 *ok = GNUNET_NO;
@@ -53,10 +53,11 @@ iter (void *cls, const struct GNUNET_HashCode * pseudonym,
53 return GNUNET_OK; 53 return GNUNET_OK;
54} 54}
55 55
56
56static int 57static int
57noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, 58noti_callback (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym,
58 const char *name, const char *unique_name, 59 const char *name, const char *unique_name,
59 const struct GNUNET_CONTAINER_MetaData *md, int rating) 60 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
60{ 61{
61 int *ret = cls; 62 int *ret = cls;
62 63
@@ -64,10 +65,11 @@ noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym,
64 return GNUNET_OK; 65 return GNUNET_OK;
65} 66}
66 67
68
67static int 69static int
68fake_noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, 70fake_noti_callback (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym,
69 const char *name, const char *unique_name, 71 const char *name, const char *unique_name,
70 const struct GNUNET_CONTAINER_MetaData *md, int rating) 72 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
71{ 73{
72 int *ret = cls; 74 int *ret = cls;
73 75
@@ -75,24 +77,30 @@ fake_noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym,
75 return GNUNET_OK; 77 return GNUNET_OK;
76} 78}
77 79
78static int 80
79false_callback (void *cls, const struct GNUNET_HashCode * pseudonym, 81static void
80 const char *name, const char *unique_name, 82create_pseu (struct GNUNET_PseudonymIdentifier *pseu)
81 const struct GNUNET_CONTAINER_MetaData *md, int rating)
82{ 83{
83 return GNUNET_OK; 84 struct GNUNET_PseudonymHandle *ph;
85
86 ph = GNUNET_PSEUDONYM_create (NULL);
87 GNUNET_PSEUDONYM_get_identifier (ph, pseu);
88 GNUNET_PSEUDONYM_destroy (ph);
84} 89}
85 90
86int 91
87main (int argc, char *argv[]) 92/**
93 * Testcase for meta data / ranking IO routines.
94 */
95static int
96test_io ()
88{ 97{
89 int ok; 98 int ok;
90 struct GNUNET_HashCode rid1; 99 struct GNUNET_PseudonymIdentifier rid1;
91 struct GNUNET_HashCode id2; 100 struct GNUNET_PseudonymIdentifier id2;
92 struct GNUNET_HashCode rid2; 101 struct GNUNET_PseudonymIdentifier rid2;
93 struct GNUNET_HashCode fid; 102 struct GNUNET_PseudonymIdentifier fid;
94 struct GNUNET_HashCode id3; 103 struct GNUNET_PseudonymIdentifier id3;
95
96 int old; 104 int old;
97 int newVal; 105 int newVal;
98 struct GNUNET_CONFIGURATION_Handle *cfg; 106 struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -104,8 +112,9 @@ main (int argc, char *argv[])
104 char *noname; 112 char *noname;
105 int noname_is_a_dup; 113 int noname_is_a_dup;
106 int notiCount, fakenotiCount; 114 int notiCount, fakenotiCount;
107 int count;
108 static char m[1024 * 1024 * 10]; 115 static char m[1024 * 1024 * 10];
116 struct GNUNET_PSEUDONYM_DiscoveryHandle *dh1;
117 struct GNUNET_PSEUDONYM_DiscoveryHandle *dh2;
109 118
110 memset (m, 'b', sizeof (m)); 119 memset (m, 'b', sizeof (m));
111 m[sizeof (m) - 1] = '\0'; 120 m[sizeof (m) - 1] = '\0';
@@ -122,14 +131,11 @@ main (int argc, char *argv[])
122 } 131 }
123 notiCount = 0; 132 notiCount = 0;
124 fakenotiCount = 0; 133 fakenotiCount = 0;
125 count = 0; 134 dh1 = GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback,
126 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, 135 &fakenotiCount);
127 &fakenotiCount); 136 dh2 = GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback,
128 GNUNET_PSEUDONYM_discovery_callback_register (cfg, &noti_callback, 137 &notiCount);
129 &notiCount); 138 GNUNET_PSEUDONYM_discovery_callback_unregister (dh1);
130 GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count);
131 GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback,
132 &fakenotiCount);
133 139
134 /* ACTUAL TEST CODE */ 140 /* ACTUAL TEST CODE */
135 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); 141 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
@@ -137,7 +143,7 @@ main (int argc, char *argv[])
137 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, 143 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
138 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 144 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
139 "test", strlen ("test") + 1); 145 "test", strlen ("test") + 1);
140 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); 146 create_pseu (&id1);
141 GNUNET_PSEUDONYM_add (cfg, &id1, meta); 147 GNUNET_PSEUDONYM_add (cfg, &id1, meta);
142 CHECK (notiCount == 1); 148 CHECK (notiCount == 1);
143 GNUNET_PSEUDONYM_add (cfg, &id1, meta); 149 GNUNET_PSEUDONYM_add (cfg, &id1, meta);
@@ -145,7 +151,7 @@ main (int argc, char *argv[])
145 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); 151 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
146 CHECK (old < newVal); 152 CHECK (old < newVal);
147 old = newVal; 153 old = newVal;
148 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); 154 create_pseu (&id2);
149 GNUNET_PSEUDONYM_add (cfg, &id2, meta); 155 GNUNET_PSEUDONYM_add (cfg, &id2, meta);
150 CHECK (notiCount == 3); 156 CHECK (notiCount == 3);
151 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); 157 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
@@ -156,7 +162,7 @@ main (int argc, char *argv[])
156 EXTRACTOR_METAFORMAT_UTF8, 162 EXTRACTOR_METAFORMAT_UTF8,
157 "text/plain", m, 163 "text/plain", m,
158 strlen (m) + 1)); 164 strlen (m) + 1));
159 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); 165 create_pseu (&id3);
160 GNUNET_PSEUDONYM_add (cfg, &id3, meta); 166 GNUNET_PSEUDONYM_add (cfg, &id3, meta);
161 GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); 167 GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL);
162 CHECK (name3 != NULL); 168 CHECK (name3 != NULL);
@@ -173,10 +179,10 @@ main (int argc, char *argv[])
173 CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); 179 CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1));
174 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); 180 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2));
175 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); 181 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1));
176 CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_HashCode))); 182 CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_PseudonymIdentifier)));
177 CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_HashCode))); 183 CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_PseudonymIdentifier)));
178 184
179 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid); 185 create_pseu (&fid);
180 GNUNET_log_skip (1, GNUNET_NO); 186 GNUNET_log_skip (1, GNUNET_NO);
181 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); 187 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0));
182 GNUNET_log_skip (0, GNUNET_NO); 188 GNUNET_log_skip (0, GNUNET_NO);
@@ -195,7 +201,7 @@ main (int argc, char *argv[])
195 GNUNET_free (noname); 201 GNUNET_free (noname);
196 /* END OF TEST CODE */ 202 /* END OF TEST CODE */
197FAILURE: 203FAILURE:
198 GNUNET_PSEUDONYM_discovery_callback_unregister (&noti_callback, &notiCount); 204 GNUNET_PSEUDONYM_discovery_callback_unregister (dh2);
199 GNUNET_CONTAINER_meta_data_destroy (meta); 205 GNUNET_CONTAINER_meta_data_destroy (meta);
200 GNUNET_CONFIGURATION_destroy (cfg); 206 GNUNET_CONFIGURATION_destroy (cfg);
201 GNUNET_break (GNUNET_OK == 207 GNUNET_break (GNUNET_OK ==
@@ -203,4 +209,29 @@ FAILURE:
203 return (ok == GNUNET_YES) ? 0 : 1; 209 return (ok == GNUNET_YES) ? 0 : 1;
204} 210}
205 211
212
213static int
214test_crypto ()
215{
216 struct GNUNET_PseudonymHandle *ph;
217
218 ph = GNUNET_PSEUDONYM_create (NULL);
219 // FIXME: call sign, verify APIs...
220 GNUNET_PSEUDONYM_destroy (ph);
221 return 0;
222}
223
224
225int
226main (int argc, char *argv[])
227{
228 if (0 != test_io ())
229 return 1;
230 if (0 != test_crypto ())
231 return 1;
232
233 return 0;
234}
235
236
206/* end of test_pseudoynm.c */ 237/* end of test_pseudoynm.c */