X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ffs%2Ffs_unindex.c;h=c87c4e4e9ae342ccaf06fab28fb2051b636eb4e3;hb=6da7b6a2dc5ec3645d5f8bdbd4ab77d6090b823f;hp=132109c59f8050c61d586b42c5c39ce2054cb10f;hpb=ddf8da52e94c520a93383edddfef3f537664a7c3;p=oweals%2Fgnunet.git diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index 132109c59..c87c4e4e9 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2003--2013 Christian Grothoff (and other contributing authors) + Copyright (C) 2003--2013 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -31,6 +31,7 @@ #include "fs_api.h" #include "fs_tree.h" #include "block_fs.h" +#include "fs_publish_ublock.h" /** @@ -270,15 +271,12 @@ static void unindex_finish (struct GNUNET_FS_UnindexContext *uc) { char *emsg; - struct GNUNET_FS_Uri *uri; struct UnindexMessage req; /* generate final progress message */ unindex_progress (uc, uc->file_size, NULL, 0, 0); - GNUNET_FS_tree_encoder_finish (uc->tc, &uri, &emsg); + GNUNET_FS_tree_encoder_finish (uc->tc, &emsg); uc->tc = NULL; - if (uri != NULL) - GNUNET_FS_uri_destroy (uri); GNUNET_DISK_file_close (uc->fh); uc->fh = NULL; GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); @@ -324,8 +322,8 @@ unindex_finish (struct GNUNET_FS_UnindexContext *uc) * @param reason kind of progress we are making */ static void -unindex_directory_scan_cb (void *cls, - const char *filename, +unindex_directory_scan_cb (void *cls, + const char *filename, int is_directory, enum GNUNET_FS_DirScannerProgressUpdateReason reason) { @@ -383,7 +381,7 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) ex = NULL; uc->dscan = GNUNET_FS_directory_scan_start (uc->filename, GNUNET_NO, ex, - &unindex_directory_scan_cb, + &unindex_directory_scan_cb, uc); GNUNET_free_non_null (ex); } @@ -393,7 +391,7 @@ GNUNET_FS_unindex_do_extract_keywords_ (struct GNUNET_FS_UnindexContext *uc) * Continuation called to notify client about result of the remove * operation for the UBlock. * - * @param cls the 'struct GNUNET_FS_UnindexContext *' + * @param cls the 'struct GNUNET_FS_UnindexContext *' * @param success GNUNET_SYSERR on failure (including timeout/queue drop) * GNUNET_NO if content was already there * GNUNET_YES (or other positive value) on success @@ -411,10 +409,10 @@ continue_after_remove (void *cls, struct GNUNET_FS_UnindexContext *uc = cls; uc->dqe = NULL; - if (success != GNUNET_YES) + if (success != GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to remove UBlock: %s\n"), - msg); + msg); uc->ksk_offset++; GNUNET_FS_unindex_do_remove_kblocks_ (uc); } @@ -466,14 +464,14 @@ process_kblock_for_unindex (void *cls, if (0 == uc->first_uid) { /* remember UID of first result to detect cycles */ - uc->first_uid = uid; + uc->first_uid = uid; } else if (uid == uc->first_uid) { /* no more additional results */ uc->ksk_offset++; GNUNET_FS_unindex_do_remove_kblocks_ (uc); - return; + return; } GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); if (size < sizeof (struct UBlock)) @@ -491,18 +489,17 @@ process_kblock_for_unindex (void *cls, goto get_next; } { - char pt[size - sizeof (struct UBlock)]; - struct GNUNET_CRYPTO_AesSessionKey skey; - struct GNUNET_CRYPTO_AesInitializationVector iv; - - GNUNET_CRYPTO_hash_to_aes_key (&uc->ukey, &skey, &iv); - if (-1 == - GNUNET_CRYPTO_aes_decrypt (&ub[1], size - sizeof (struct UBlock), &skey, - &iv, pt)) - { - GNUNET_break (0); - goto get_next; - } + char pt[size - sizeof (struct UBlock)]; + struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; + const char *keyword; + + GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), + &anon_pub); + keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; + GNUNET_FS_ublock_decrypt_ (&ub[1], size - sizeof (struct UBlock), + &anon_pub, + keyword, + pt); if (NULL == memchr (&pt[1], 0, sizeof (pt) - 1)) { GNUNET_break_op (0); /* malformed UBlock */ @@ -553,10 +550,9 @@ void GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) { const char *keyword; - struct GNUNET_FS_PseudonymHandle *ph; - struct GNUNET_FS_PseudonymIdentifier anon; - struct GNUNET_FS_PseudonymIdentifier verification_key; - struct GNUNET_HashCode signing_key; + const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; + struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; + struct GNUNET_CRYPTO_EcdsaPublicKey dpub; if (NULL == uc->dsh) uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); @@ -574,18 +570,15 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) unindex_finish (uc); return; } - /* FIXME: code duplication with fs_search.c here... */ - ph = GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle (); - GNUNET_FS_pseudonym_get_identifier (ph, &anon); - GNUNET_FS_pseudonym_destroy (ph); + anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); + GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; - GNUNET_CRYPTO_hash (keyword, strlen (keyword), &uc->ukey); - GNUNET_CRYPTO_hash (&uc->ukey, sizeof (struct GNUNET_HashCode), &signing_key); - GNUNET_FS_pseudonym_derive_verification_key (&anon, - &signing_key, - &verification_key); - GNUNET_CRYPTO_hash (&verification_key, - sizeof (struct GNUNET_FS_PseudonymIdentifier), + GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, + keyword, + "fs-ublock", + &dpub); + GNUNET_CRYPTO_hash (&dpub, + sizeof (dpub), &uc->uquery); uc->first_uid = 0; uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, @@ -693,7 +686,7 @@ GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_ * Create SUSPEND event for the given unindex operation * and then clean up our state (without stop signal). * - * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for + * @param cls the `struct GNUNET_FS_UnindexContext` to signal for */ void GNUNET_FS_unindex_signal_suspend_ (void *cls) @@ -734,7 +727,7 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) } if (NULL != uc->tc) { - GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL); + GNUNET_FS_tree_encoder_finish (uc->tc, NULL); uc->tc = NULL; } if (uc->fh != NULL) @@ -764,7 +757,8 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) * @return NULL on error, otherwise handle */ struct GNUNET_FS_UnindexContext * -GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename, +GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, + const char *filename, void *cctx) { struct GNUNET_FS_UnindexContext *ret; @@ -773,7 +767,7 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename, if (GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) return NULL; - ret = GNUNET_malloc (sizeof (struct GNUNET_FS_UnindexContext)); + ret = GNUNET_new (struct GNUNET_FS_UnindexContext); ret->h = h; ret->filename = GNUNET_strdup (filename); ret->start_time = GNUNET_TIME_absolute_get (); @@ -834,7 +828,7 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) } if (NULL != uc->tc) { - GNUNET_FS_tree_encoder_finish (uc->tc, NULL, NULL); + GNUNET_FS_tree_encoder_finish (uc->tc, NULL); uc->tc = NULL; } if (uc->fh != NULL)