* @author Christian Grothoff
*
* TODO:
- * - indexed files/blocks not removed on errors
+ * - consider doing GNUNET_CRYPTO_hash_file_cancel on active indexing
+ * jobs during shutdown (currently, shutdown will only happen after
+ * all of those are done, not sure if this is good or bad)
*/
#include "platform.h"
#include <float.h>
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_util_lib.h"
+#include "gnunet-service-fs_drq.h"
#include "gnunet-service-fs_indexing.h"
#include "fs.h"
-#define DEBUG_FS GNUNET_NO
-
+#define DEBUG_FS GNUNET_YES
/**
* In-memory information about indexed files (also available
* NULL if we've done this already.
*/
struct GNUNET_SERVER_TransmitContext *tc;
+
+ /**
+ * Context for hashing of the file.
+ */
+ struct GNUNET_CRYPTO_FileHashContext *fhc;
/**
* Hash of the contents of the file.
/**
* Our configuration.
*/
-const struct GNUNET_CONFIGURATION_Handle *cfg;
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Datastore handle. Created and destroyed by code in
+ * gnunet-service-fs (this is an alias).
+ */
+static struct GNUNET_DATASTORE_Handle *dsh;
/**
}
if (GNUNET_NO == GNUNET_DISK_file_test (fn))
{
- /* no index info yet */
+ /* no index info yet */
GNUNET_free (fn);
return;
}
(void*) ii->filename,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Index request received for file `%s' is indexed as `%s'. Permitting anyway.\n"),
+ 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));
res)
{
struct IndexInfo *ii = cls;
-
+
+ ii->fhc = NULL;
if ( (res == NULL) ||
(0 != memcmp (res,
&ii->file_id,
const struct GNUNET_MessageHeader *message)
{
const struct IndexStartMessage *ism;
- const char *fn;
+ char *fn;
uint16_t msize;
struct IndexInfo *ii;
size_t slen;
return;
}
ism = (const struct IndexStartMessage*) message;
- fn = (const char*) &ism[1];
+ fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]);
dev = ntohl (ism->device);
ino = GNUNET_ntohll (ism->inode);
ism = (const struct IndexStartMessage*) message;
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,
{
/* fast validation OK! */
signal_index_ok (ii);
+ GNUNET_free (fn);
return;
}
#if DEBUG_FS
(unsigned int) mydev);
#endif
/* slow validation, need to hash full file (again) */
- GNUNET_CRYPTO_hash_file (sched,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- fn,
- HASHING_BLOCKSIZE,
- &hash_for_index_val,
- ii);
+ ii->fhc = GNUNET_CRYPTO_hash_file (sched,
+ 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);
}
int success,
const char *msg)
{
- struct GNUNET_DATASTORE_Handle *dsh = cls;
-
if (GNUNET_OK != success)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to delete bogus block: %s\n"),
msg);
- GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
}
* @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
+ * @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
+int
GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
uint32_t size,
const void *data,
- uint32_t type,
+ enum GNUNET_BLOCK_Type type,
uint32_t priority,
uint32_t anonymity,
struct GNUNET_TIME_Absolute
expiration, uint64_t uid,
- struct GNUNET_DATASTORE_Handle *dsh,
GNUNET_DATASTORE_Iterator cont,
void *cont_cls)
{
if (size != sizeof (struct OnDemandBlock))
{
GNUNET_break (0);
- GNUNET_DATASTORE_remove (dsh,
+ GNUNET_DATASTORE_remove (dsh,
key,
size,
data,
+ -1, -1,
+ GNUNET_TIME_UNIT_FOREVER_REL,
&remove_cont,
- dsh,
- GNUNET_TIME_UNIT_FOREVER_REL);
- return;
+ NULL);
+ return GNUNET_SYSERR;
}
odb = (const struct OnDemandBlock*) data;
off = GNUNET_ntohll (odb->offset);
sizeof (ndata)))) )
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not access indexed file `%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,
STRERROR (errno));
if (fh != NULL)
GNUNET_DISK_file_close (fh);
- /* FIXME: if this happens often, we need
- to remove the OnDemand block from the DS! */
- GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
- return;
+ 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,
_("Indexed file `%s' changed at offset %llu\n"),
fn,
(unsigned long long) off);
- /* FIXME: if this happens often, we need
- to remove the OnDemand block from the DS! */
- GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
- return;
+ GNUNET_DATASTORE_remove (dsh,
+ key,
+ size,
+ data,
+ -1, -1,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &remove_cont,
+ NULL);
+ return GNUNET_SYSERR;
}
+#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_DATASTORE_BLOCKTYPE_DBLOCK,
+ GNUNET_BLOCK_TYPE_DBLOCK,
priority,
anonymity,
expiration,
uid);
+ return GNUNET_OK;
}
*
* @param s scheduler to use
* @param c configuration to use
+ * @param d datastore to use
*/
-void
-GNUNET_FS_init_indexing (struct GNUNET_SCHEDULER_Handle *s,
- const struct GNUNET_CONFIGURATION_Handle *c)
+int
+GNUNET_FS_indexing_init (struct GNUNET_SCHEDULER_Handle *s,
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ struct GNUNET_DATASTORE_Handle *d)
{
sched = s;
cfg = c;
+ dsh = d;
ifm = GNUNET_CONTAINER_multihashmap_create (128);
GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task,
NULL);
read_index_list ();
+ return GNUNET_OK;
}
/* end of gnunet-service-fs_indexing.c */