/** * We have selected a value for deletion, trigger removal. * * @param cls the `struct CpsRunContext` * @param key key for the content * @param size number of bytes in data * @param data content stored * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content * @param expiration expiration time for the content * @param uid unique identifier for the datum; * maybe 0 if no unique identifier is available */ static void delete_value (void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, uint64_t uid) { struct CpsRunContext *crc = cls; GNUNET_assert (NULL != key); stored_ops++; stored_bytes -= size; stored_entries--; stored_ops++; if (stored_bytes < MAX_SIZE) crc->phase = RP_PUT; GNUNET_assert (NULL != GNUNET_DATASTORE_remove (datastore, key, size, data, 1, 1, &remove_next, crc)); }
/** * Function called asking for the current (encoded) * block to be processed. After processing the * client should either call "GNUNET_FS_tree_encode_next" * or (on error) "GNUNET_FS_tree_encode_finish". * * @param cls closure * @param chk content hash key for the block (key for lookup in the datastore) * @param offset offset of the block * @param depth depth of the block, 0 for DBLOCK * @param type type of the block (IBLOCK or DBLOCK) * @param block the (encrypted) block * @param block_size size of block (in bytes) */ static void unindex_process (void *cls, const struct ContentHashKey *chk, uint64_t offset, unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block, uint16_t block_size) { struct GNUNET_FS_UnindexContext *uc = cls; uint32_t size; const void *data; struct OnDemandBlock odb; if (type != GNUNET_BLOCK_TYPE_FS_DBLOCK) { size = block_size; data = block; } else /* on-demand encoded DBLOCK */ { size = sizeof (struct OnDemandBlock); odb.offset = GNUNET_htonll (offset); odb.file_id = uc->file_id; data = &odb; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending REMOVE request to DATASTORE service\n"); GNUNET_DATASTORE_remove (uc->dsh, &chk->query, size, data, -2, 1, GNUNET_CONSTANTS_SERVICE_TIMEOUT, &process_cont, uc); uc->chk = *chk; }
/** * We've received an on-demand encoded block from the datastore. * Attempt to do on-demand encoding and (if successful), call the * continuation with the resulting block. On error, clean up and ask * the datastore for more results. * * @param key key for the content * @param size number of bytes in data * @param data content stored * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content * @param expiration expiration time for the content * @param uid unique identifier for the datum; * maybe 0 if no unique identifier is available * @param cont function to call with the actual block (at most once, on success) * @param cont_cls closure for cont * @return GNUNET_OK on success */ int GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, uint64_t uid, GNUNET_DATASTORE_DatumProcessor cont, void *cont_cls) { const struct OnDemandBlock *odb; struct GNUNET_HashCode nkey; struct GNUNET_CRYPTO_AesSessionKey skey; struct GNUNET_CRYPTO_AesInitializationVector iv; struct GNUNET_HashCode query; ssize_t nsize; char ndata[DBLOCK_SIZE]; char edata[DBLOCK_SIZE]; const char *fn; struct GNUNET_DISK_FileHandle *fh; uint64_t off; struct IndexInfo *ii; if (size != sizeof (struct OnDemandBlock)) { GNUNET_break (0); GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); return GNUNET_SYSERR; } odb = (const struct OnDemandBlock *) data; off = GNUNET_ntohll (odb->offset); ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); if (NULL == ii) { GNUNET_break (0); return GNUNET_SYSERR; } fn = ii->filename; if ((NULL == fn) || (0 != ACCESS (fn, R_OK))) { GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# index blocks removed: original file inaccessible"), 1, GNUNET_YES); GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); return GNUNET_SYSERR; } if ((NULL == (fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE))) || (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), GNUNET_h2s (&odb->file_id), fn, (unsigned long long) off, (fn == NULL) ? _("not indexed") : STRERROR (errno)); if (fh != NULL) GNUNET_DISK_file_close (fh); GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); return GNUNET_SYSERR; } GNUNET_DISK_file_close (fh); GNUNET_CRYPTO_hash (ndata, nsize, &nkey); GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); GNUNET_CRYPTO_aes_encrypt (ndata, nsize, &skey, &iv, edata); GNUNET_CRYPTO_hash (edata, nsize, &query); if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Indexed file `%s' changed at offset %llu\n"), fn, (unsigned long long) off); GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); return GNUNET_SYSERR; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "On-demand encoded block for query `%s'\n", GNUNET_h2s (key)); cont (cont_cls, key, nsize, edata, GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid); return GNUNET_OK; }
/** * Function called from datastore with result from us looking for * a UBlock. There are four cases: * 1) no result, means we move on to the next keyword * 2) UID is the same as the first UID, means we move on to next keyword * 3) UBlock for a different CHK, means we keep looking for more * 4) UBlock is for our CHK, means we remove the block and then move * on to the next keyword * * @param cls the 'struct GNUNET_FS_UnindexContext *' * @param key key for the content * @param size number of bytes in data * @param data content stored * @param type type of the content * @param priority priority of the content * @param anonymity anonymity-level for the content * @param expiration expiration time for the content * @param uid unique identifier for the datum; * maybe 0 if no unique identifier is available */ static void process_kblock_for_unindex (void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, uint64_t uid) { struct GNUNET_FS_UnindexContext *uc = cls; const struct UBlock *ub; struct GNUNET_FS_Uri *chk_uri; struct GNUNET_HashCode query; struct GNUNET_HashCode dh; uc->dqe = NULL; if (NULL == data) { /* no result */ GNUNET_CONTAINER_multihashmap_clear (uc->seen_dh); uc->ksk_offset++; GNUNET_FS_unindex_do_remove_kblocks_ (uc); return; } GNUNET_CRYPTO_hash (data, size, &dh); if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (uc->seen_dh, &dh)) { GNUNET_CONTAINER_multihashmap_clear (uc->seen_dh); uc->ksk_offset++; GNUNET_FS_unindex_do_remove_kblocks_ (uc); return; } GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (uc->seen_dh, &dh, uc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); GNUNET_assert (GNUNET_BLOCK_TYPE_FS_UBLOCK == type); if (size < sizeof (struct UBlock)) { GNUNET_break (0); goto get_next; } ub = data; GNUNET_CRYPTO_hash (&ub->verification_key, sizeof (ub->verification_key), &query); if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) { /* result does not match our keyword, skip */ 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 */ goto get_next; } chk_uri = GNUNET_FS_uri_parse (&pt[1], NULL); if (NULL == chk_uri) { GNUNET_break_op (0); /* malformed UBlock */ goto get_next; } } if (0 != memcmp (&uc->chk, &chk_uri->data.chk.chk, sizeof (struct ContentHashKey))) { /* different CHK, ignore */ GNUNET_FS_uri_destroy (chk_uri); goto get_next; } GNUNET_FS_uri_destroy (chk_uri); /* matches! */ uc->dqe = GNUNET_DATASTORE_remove (uc->dsh, key, size, data, 0 /* priority */, 1 /* queue size */, GNUNET_TIME_UNIT_FOREVER_REL, &continue_after_remove, uc); return; get_next: uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, uc->roff++, &uc->uquery, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0 /* priority */, 1 /* queue size */, GNUNET_TIME_UNIT_FOREVER_REL, &process_kblock_for_unindex, uc); }