diff options
Diffstat (limited to 'src/fs/fs_unindex.c')
-rw-r--r-- | src/fs/fs_unindex.c | 84 |
1 files changed, 50 insertions, 34 deletions
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 | */ |
443 | static void | 443 | static void |
444 | process_kblock_for_unindex (void *cls, | 444 | process_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 | |||
547 | GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) | 553 | GNUNET_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, |