/*
This file is part of GNUnet.
- (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009, 2010 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
{
/**
- * This is a linked list.
+ * This is a doubly linked list.
*/
struct IndexInfo *next;
+ /**
+ * This is a doubly linked list.
+ */
+ struct IndexInfo *prev;
+
/**
* Name of the indexed file. Memory allocated
* at the end of this struct (do not free).
/**
* Hash of the contents of the file.
*/
- GNUNET_HashCode file_id;
+ struct GNUNET_HashCode file_id;
};
/**
- * Linked list of indexed files.
+ * Head of linked list of indexed files.
+ * FIXME: we don't need both a DLL and a hashmap here!
+ */
+static struct IndexInfo *indexed_files_head;
+
+/**
+ * Tail of linked list of indexed files.
*/
-static struct IndexInfo *indexed_files;
+static struct IndexInfo *indexed_files_tail;
/**
- * Maps hash over content of indexed files to the respective filename.
+ * Maps hash over content of indexed files to the respective 'struct IndexInfo'.
* The filenames are pointers into the indexed_files linked list and
* do not need to be freed.
*/
struct IndexInfo *pos;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "FS",
+ "INDEXDB",
+ &fn))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Configuration option `%s' in section `%s' missing.\n"),
- "INDEXDB", "FS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "fs",
+ "INDEXDB");
return;
}
wh = GNUNET_BIO_write_open (fn);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"), fn);
+ _("Could not open `%s'.\n"),
+ fn);
GNUNET_free (fn);
return;
}
- pos = indexed_files;
- while (pos != NULL)
- {
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
if ((GNUNET_OK !=
- GNUNET_BIO_write (wh, &pos->file_id, sizeof (GNUNET_HashCode))) ||
- (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
+ GNUNET_BIO_write (wh,
+ &pos->file_id,
+ sizeof (struct GNUNET_HashCode))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_string (wh,
+ pos->filename)))
break;
- pos = pos->next;
- }
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Error writing `%s'.\n"), fn);
+ _("Error writing `%s'.\n"),
+ fn);
GNUNET_free (fn);
return;
}
char *fn;
struct IndexInfo *pos;
char *fname;
- GNUNET_HashCode hc;
+ struct GNUNET_HashCode hc;
size_t slen;
char *emsg;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "FS",
+ "INDEXDB",
+ &fn))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Configuration option `%s' in section `%s' missing.\n"),
- "INDEXDB", "FS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "fs",
+ "INDEXDB");
return;
}
if (GNUNET_NO == GNUNET_DISK_file_test (fn))
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"), fn);
+ _("Could not open `%s'.\n"),
+ fn);
GNUNET_free (fn);
return;
}
- while ((GNUNET_OK ==
- GNUNET_BIO_read (rh, "Hash of indexed file", &hc,
- sizeof (GNUNET_HashCode))) &&
- (GNUNET_OK ==
- GNUNET_BIO_read_string (rh, "Name of indexed file", &fname,
- 1024 * 16)) && (fname != NULL))
+ while ( (GNUNET_OK ==
+ GNUNET_BIO_read (rh,
+ "Hash of indexed file",
+ &hc,
+ sizeof (struct GNUNET_HashCode))) &&
+ (GNUNET_OK ==
+ GNUNET_BIO_read_string (rh,
+ "Name of indexed file",
+ &fname,
+ 1024 * 16)) &&
+ (fname != NULL) )
{
slen = strlen (fname) + 1;
pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
pos->file_id = hc;
pos->filename = (const char *) &pos[1];
- memcpy (&pos[1], fname, slen);
+ GNUNET_memcpy (&pos[1], fname, slen);
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm, &hc, (void *) pos->filename,
+ GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_free (pos);
}
else
{
- pos->next = indexed_files;
- indexed_files = pos;
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head,
+ indexed_files_tail,
+ pos);
}
GNUNET_free (fname);
}
/**
- * We've validated the hash of the file we're about to index. Signal
- * success to the client and update our internal data structures.
- *
- * @param ii the index info entry for the request
- */
-static void
-signal_index_ok (struct IndexInfo *ii)
-{
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm, &ii->file_id,
- (void *) ii->filename,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
- ii->filename,
- (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
- &ii->file_id));
- GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
- GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
- GNUNET_free (ii);
- return;
- }
- ii->next = indexed_files;
- indexed_files = ii;
- write_index_list ();
- GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
- GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
- ii->tc = NULL;
-}
-
-
-/**
- * Function called once the hash computation over an
- * indexed file has completed.
+ * Continuation called from datastore's remove
+ * function.
*
- * @param cls closure, our publishing context
- * @param res resulting hash, NULL on error
+ * @param cls unused
+ * @param success did the deletion work?
+ * @param min_expiration minimum expiration time required for content to be stored
+ * @param msg error message
*/
static void
-hash_for_index_val (void *cls, const GNUNET_HashCode * res)
+remove_cont (void *cls, int success,
+ struct GNUNET_TIME_Absolute min_expiration,
+ const char *msg)
{
- struct IndexInfo *ii = cls;
-
- ii->fhc = NULL;
- if ((res == NULL) ||
- (0 != memcmp (res, &ii->file_id, sizeof (GNUNET_HashCode))))
- {
+ if (GNUNET_OK != success)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
- ii->filename, GNUNET_h2s (res));
-#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wanted `%s'\n",
- GNUNET_h2s (&ii->file_id));
-#endif
- GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
- GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
- GNUNET_free (ii);
- return;
- }
- signal_index_ok (ii);
+ _("Failed to delete bogus block: %s\n"), msg);
}
/**
- * Handle INDEX_START-message.
+ * 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 cls closure
- * @param client identification of the client
- * @param message the actual message
+ * @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
*/
-void
-GNUNET_FS_handle_index_start (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+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 IndexStartMessage *ism;
- char *fn;
- uint16_t msize;
+ const struct OnDemandBlock *odb;
+ struct GNUNET_HashCode nkey;
+ struct GNUNET_CRYPTO_SymmetricSessionKey skey;
+ struct GNUNET_CRYPTO_SymmetricInitializationVector 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;
- size_t slen;
- uint64_t dev;
- uint64_t ino;
- uint64_t mydev;
- uint64_t myino;
-
- msize = ntohs (message->size);
- if ((msize <= sizeof (struct IndexStartMessage)) ||
- (((const char *) message)[msize - 1] != '\0'))
+
+ if (size != sizeof (struct OnDemandBlock))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
+ GNUNET_DATASTORE_remove (dsh,
+ key,
+ size,
+ data,
+ -1,
+ -1,
+ &remove_cont, NULL);
+ return GNUNET_SYSERR;
}
- ism = (const struct IndexStartMessage *) message;
- if (0 != ism->reserved)
+ 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);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to find index %s\n",
+ GNUNET_h2s (&odb->file_id));
+ return GNUNET_SYSERR;
}
- fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]);
- if (fn == NULL)
+ fn = ii->filename;
+ if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
{
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
+ 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,
+ &remove_cont,
+ NULL);
+ return GNUNET_SYSERR;
}
- dev = GNUNET_ntohll (ism->device);
- ino = GNUNET_ntohll (ism->inode);
- ism = (const struct IndexStartMessage *) message;
- slen = strlen (fn) + 1;
- ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
- ii->filename = (const char *) &ii[1];
- memcpy (&ii[1], fn, slen);
- ii->file_id = ism->file_id;
-#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for file `%s'\n",
- "START_INDEX", ii->filename);
-#endif
-
- ii->tc = GNUNET_SERVER_transmit_context_create (client);
- mydev = 0;
- myino = 0;
- if (((dev != 0) || (ino != 0)) &&
- (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, &mydev, &myino)) &&
- ((dev == mydev) && (ino == myino)))
+ 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)))) )
{
- /* fast validation OK! */
- signal_index_ok (ii);
- GNUNET_free (fn);
- return;
+ 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,
+ &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_symmetric_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,
+ &remove_cont,
+ NULL);
+ return GNUNET_SYSERR;
}
-#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
- (unsigned long long) ino, (unsigned long long) myino,
- (unsigned int) dev, (unsigned int) mydev);
-#endif
- /* slow validation, need to hash full file (again) */
- ii->fhc =
- GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, fn,
- HASHING_BLOCKSIZE, &hash_for_index_val, ii);
- if (ii->fhc == NULL)
- hash_for_index_val (ii, NULL);
- GNUNET_free (fn);
+ "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;
}
/**
- * Handle INDEX_LIST_GET-message.
+ * Transmit information about indexed files to @a mq.
*
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
+ * @param mq message queue to send information to
*/
void
-GNUNET_FS_handle_index_list_get (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
{
- struct GNUNET_SERVER_TransmitContext *tc;
+ struct GNUNET_MQ_Envelope *env;
struct IndexInfoMessage *iim;
- char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
+ struct GNUNET_MessageHeader *iem;
size_t slen;
const char *fn;
struct IndexInfo *pos;
- tc = GNUNET_SERVER_transmit_context_create (client);
- iim = (struct IndexInfoMessage *) buf;
- pos = indexed_files;
- while (NULL != pos)
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
fn = pos->filename;
slen = strlen (fn) + 1;
GNUNET_break (0);
break;
}
- iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
- iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
+ env = GNUNET_MQ_msg_extra (iim,
+ slen,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
iim->reserved = 0;
iim->file_id = pos->file_id;
- memcpy (&iim[1], fn, slen);
- GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
- pos = pos->next;
+ GNUNET_memcpy (&iim[1],
+ fn,
+ slen);
+ GNUNET_MQ_send (mq,
+ env);
}
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
+ env = GNUNET_MQ_msg (iem,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+ GNUNET_MQ_send (mq,
+ env);
}
/**
- * Handle UNINDEX-message.
+ * Remove a file from the index.
*
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
+ * @param fid identifier of the file to remove
+ * @return #GNUNET_YES if the @a fid was found
*/
-void
-GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+int
+GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid)
{
- const struct UnindexMessage *um;
struct IndexInfo *pos;
- struct IndexInfo *prev;
- struct IndexInfo *next;
- struct GNUNET_SERVER_TransmitContext *tc;
- int found;
- um = (const struct UnindexMessage *) message;
- if (0 != um->reserved)
+ for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- found = GNUNET_NO;
- prev = NULL;
- pos = indexed_files;
- while (NULL != pos)
- {
- next = pos->next;
- if (0 == memcmp (&pos->file_id, &um->file_id, sizeof (GNUNET_HashCode)))
+ if (0 == memcmp (&pos->file_id,
+ fid,
+ sizeof (struct GNUNET_HashCode)))
{
- if (prev == NULL)
- indexed_files = next;
- else
- prev->next = next;
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head,
+ indexed_files_tail,
+ pos);
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id,
- (void *)
- pos->filename));
+ GNUNET_CONTAINER_multihashmap_remove (ifm,
+ &pos->file_id,
+ pos));
GNUNET_free (pos);
- found = GNUNET_YES;
- }
- else
- {
- prev = pos;
+ write_index_list ();
+ return GNUNET_YES;
}
- pos = next;
}
-#if DEBUG_FS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client requested unindexing of file `%s': %s\n",
- GNUNET_h2s (&um->file_id), found ? "found" : "not found");
-#endif
- if (GNUNET_YES == found)
- write_index_list ();
- tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
- GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
+ return GNUNET_NO;
}
/**
- * Continuation called from datastore's remove
- * function.
+ * Add the given file to the list of indexed files.
*
- * @param cls unused
- * @param success did the deletion work?
- * @param msg error message
+ * @param filename name of the file
+ * @param file_id hash identifier for @a filename
*/
-static void
-remove_cont (void *cls, int success, const char *msg)
-{
- if (GNUNET_OK != success)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to delete bogus block: %s\n"), msg);
-}
-
-
-/**
- * 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 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)
+void
+GNUNET_FS_add_to_index (const char *filename,
+ const struct GNUNET_HashCode *file_id)
{
- const struct OnDemandBlock *odb;
- GNUNET_HashCode nkey;
- struct GNUNET_CRYPTO_AesSessionKey skey;
- struct GNUNET_CRYPTO_AesInitializationVector iv;
- 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;
+ size_t slen;
- 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);
- fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
- 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 (GNUNET_HashCode)))
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm,
+ file_id);
+ if (NULL != ii)
{
- 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_INFO,
+ _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
+ filename,
+ ii->filename);
+ return;
}
-#if DEBUG_FS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
-#endif
- cont (cont_cls, key, nsize, edata, GNUNET_BLOCK_TYPE_FS_DBLOCK, priority,
- anonymity, expiration, uid);
- return GNUNET_OK;
+ "Adding file %s to index as %s\n",
+ filename,
+ GNUNET_h2s (file_id));
+ slen = strlen (filename) + 1;
+ ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
+ ii->file_id = *file_id;
+ ii->filename = (const char *) &ii[1];
+ memcpy (&ii[1],
+ filename,
+ slen);
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head,
+ indexed_files_tail,
+ ii);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (ifm,
+ &ii->file_id,
+ ii,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ write_index_list ();
}
{
struct IndexInfo *pos;
- GNUNET_CONTAINER_multihashmap_destroy (ifm);
- ifm = NULL;
- while (NULL != (pos = indexed_files))
+ while (NULL != (pos = indexed_files_head))
{
- indexed_files = pos->next;
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head,
+ indexed_files_tail,
+ pos);
if (pos->fhc != NULL)
GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm,
+ &pos->file_id,
+ pos));
GNUNET_free (pos);
}
+ GNUNET_CONTAINER_multihashmap_destroy (ifm);
+ ifm = NULL;
cfg = NULL;
}
{
cfg = c;
dsh = d;
- ifm = GNUNET_CONTAINER_multihashmap_create (128);
+ ifm = GNUNET_CONTAINER_multihashmap_create (128,
+ GNUNET_YES);
read_index_list ();
return GNUNET_OK;
}