summaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_indexing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs_indexing.c')
-rw-r--r--src/fs/gnunet-service-fs_indexing.c248
1 files changed, 88 insertions, 160 deletions
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 0e8e62fc7..df5f70b3d 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -73,7 +73,6 @@ struct IndexInfo
* Hash of the contents of the file.
*/
struct GNUNET_HashCode file_id;
-
};
@@ -118,12 +117,10 @@ write_index_list ()
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_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "fs",
+ "fs",
"INDEXDB");
return;
}
@@ -131,24 +128,21 @@ write_index_list ()
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
+ _ ("Could not open `%s'.\n"),
fn);
GNUNET_free (fn);
return;
}
for (pos = indexed_files_head; NULL != pos; pos = pos->next)
- if ((GNUNET_OK !=
- GNUNET_BIO_write (wh,
- &pos->file_id,
- sizeof (struct GNUNET_HashCode))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- pos->filename)))
+ if ((GNUNET_OK != GNUNET_BIO_write (wh,
+ &pos->file_id,
+ sizeof (struct GNUNET_HashCode))) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
break;
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Error writing `%s'.\n"),
+ _ ("Error writing `%s'.\n"),
fn);
GNUNET_free (fn);
return;
@@ -172,13 +166,10 @@ read_index_list ()
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_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "fs",
+ "fs",
"INDEXDB");
return;
}
@@ -192,39 +183,36 @@ read_index_list ()
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
+ _ ("Could not open `%s'.\n"),
fn);
GNUNET_free (fn);
return;
}
- 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) )
+ 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];
GNUNET_memcpy (&pos[1], fname, slen);
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
+ ifm,
+ &pos->file_id,
+ pos,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_free (pos);
}
else
{
- GNUNET_CONTAINER_DLL_insert (indexed_files_head,
- indexed_files_tail,
- pos);
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos);
}
GNUNET_free (fname);
}
@@ -244,13 +232,15 @@ read_index_list ()
* @param msg error message
*/
static void
-remove_cont (void *cls, int success,
- struct GNUNET_TIME_Absolute min_expiration,
- const char *msg)
+remove_cont (void *cls,
+ int success,
+ struct GNUNET_TIME_Absolute min_expiration,
+ const char *msg)
{
if (GNUNET_OK != success)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to delete bogus block: %s\n"), msg);
+ _ ("Failed to delete bogus block: %s\n"),
+ msg);
}
@@ -275,7 +265,7 @@ remove_cont (void *cls, int success,
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
+GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
uint32_t size,
const void *data,
enum GNUNET_BLOCK_Type type,
@@ -303,19 +293,12 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
if (size != sizeof (struct OnDemandBlock))
{
GNUNET_break (0);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1,
- -1,
- &remove_cont, NULL);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &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);
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
if (NULL == ii)
{
GNUNET_break (0);
@@ -325,83 +308,46 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
return GNUNET_SYSERR;
}
fn = ii->filename;
- if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
+ 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,
- &remove_cont,
- NULL);
+ 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;
}
- 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)))) )
+ 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"),
+ _ (
+ "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));
+ (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);
+ 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_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"),
+ _ ("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);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -440,27 +386,20 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
{
fn = pos->filename;
slen = strlen (fn) + 1;
- if (slen + sizeof (struct IndexInfoMessage) >=
- GNUNET_MAX_MESSAGE_SIZE)
+ if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
break;
}
- env = GNUNET_MQ_msg_extra (iim,
- slen,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+ env =
+ GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
iim->reserved = 0;
iim->file_id = pos->file_id;
- GNUNET_memcpy (&iim[1],
- fn,
- slen);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_memcpy (&iim[1], fn, slen);
+ GNUNET_MQ_send (mq, env);
}
- env = GNUNET_MQ_msg (iem,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
- GNUNET_MQ_send (mq,
- env);
+ env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+ GNUNET_MQ_send (mq, env);
}
@@ -477,17 +416,12 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid)
for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
- if (0 == memcmp (&pos->file_id,
- fid,
- sizeof (struct GNUNET_HashCode)))
+ if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode)))
{
- GNUNET_CONTAINER_DLL_remove (indexed_files_head,
- indexed_files_tail,
- pos);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ifm,
- &pos->file_id,
- pos));
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos);
+ GNUNET_break (
+ GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
GNUNET_free (pos);
write_index_list ();
return GNUNET_YES;
@@ -510,14 +444,15 @@ GNUNET_FS_add_to_index (const char *filename,
struct IndexInfo *ii;
size_t slen;
- ii = GNUNET_CONTAINER_multihashmap_get (ifm,
- file_id);
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id);
if (NULL != ii)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
- filename,
- ii->filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
+ filename,
+ ii->filename);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -528,17 +463,14 @@ GNUNET_FS_add_to_index (const char *filename,
ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
ii->file_id = *file_id;
ii->filename = (const char *) &ii[1];
- GNUNET_memcpy (&ii[1],
- filename,
- slen);
- GNUNET_CONTAINER_DLL_insert (indexed_files_head,
- indexed_files_tail,
- ii);
+ GNUNET_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));
+ GNUNET_CONTAINER_multihashmap_put (
+ ifm,
+ &ii->file_id,
+ ii,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
write_index_list ();
}
@@ -553,15 +485,12 @@ GNUNET_FS_indexing_done ()
while (NULL != (pos = indexed_files_head))
{
- GNUNET_CONTAINER_DLL_remove (indexed_files_head,
- indexed_files_tail,
- pos);
+ 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_break (
+ GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
GNUNET_free (pos);
}
GNUNET_CONTAINER_multihashmap_destroy (ifm);
@@ -582,8 +511,7 @@ GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c,
{
cfg = c;
dsh = d;
- ifm = GNUNET_CONTAINER_multihashmap_create (128,
- GNUNET_YES);
+ ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
read_index_list ();
return GNUNET_OK;
}