GNUnet  0.11.x
Data Structures | Functions | Variables
gnunet-service-fs_indexing.c File Reference

program that provides indexing functions of the file-sharing service More...

#include "platform.h"
#include <float.h>
#include "gnunet_core_service.h"
#include "gnunet_datastore_service.h"
#include "gnunet_peer_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_util_lib.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_indexing.h"
#include "fs.h"
Include dependency graph for gnunet-service-fs_indexing.c:

Go to the source code of this file.

Data Structures

struct  IndexInfo
 In-memory information about indexed files (also available on-disk). More...


static void write_index_list ()
 Write the current index information list to disk. More...
static void read_index_list ()
 Read index information from disk. More...
static void remove_cont (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 Continuation called from datastore's remove function. More...
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, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid, GNUNET_DATASTORE_DatumProcessor cont, void *cont_cls)
 We've received an on-demand encoded block from the datastore. More...
void GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
 Transmit information about indexed files to mq. More...
int GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid)
 Remove a file from the index. More...
void GNUNET_FS_add_to_index (const char *filename, const struct GNUNET_HashCode *file_id)
 Add the given file to the list of indexed files. More...
void GNUNET_FS_indexing_done ()
 Shutdown the module. More...
int GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_DATASTORE_Handle *d)
 Initialize the indexing submodule. More...


static struct IndexInfoindexed_files_head
 Head of linked list of indexed files. More...
static struct IndexInfoindexed_files_tail
 Tail of linked list of indexed files. More...
static struct GNUNET_CONTAINER_MultiHashMapifm
 Maps hash over content of indexed files to the respective 'struct IndexInfo'. More...
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
static struct GNUNET_DATASTORE_Handledsh
 Datastore handle. More...

Detailed Description

program that provides indexing functions of the file-sharing service

Christian Grothoff

Definition in file gnunet-service-fs_indexing.c.

Function Documentation

◆ write_index_list()

static void write_index_list ( )

Write the current index information list to disk.

Definition at line 112 of file gnunet-service-fs_indexing.c.

113 {
114  struct GNUNET_BIO_WriteHandle *wh;
115  char *fn;
116  struct IndexInfo *pos;
118  if (GNUNET_OK !=
119  GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
120  {
122  "fs",
123  "INDEXDB");
124  return;
125  }
127  if (NULL == wh)
128  {
130  _ ("Could not open `%s'.\n"),
131  fn);
132  GNUNET_free (fn);
133  return;
134  }
135  for (pos = indexed_files_head; NULL != pos; pos = pos->next)
136  if ((GNUNET_OK != GNUNET_BIO_write (wh,
137  "fs-indexing-file-id",
138  &pos->file_id,
139  sizeof(struct GNUNET_HashCode))) ||
141  "fs-indexing-filename",
142  pos->filename)))
143  break;
144  if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL))
145  {
147  _ ("Error writing `%s'.\n"),
148  fn);
149  GNUNET_free (fn);
150  return;
151  }
152  GNUNET_free (fn);
153 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct IndexInfo * indexed_files_head
Head of linked list of indexed files.
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
#define GNUNET_log(kind,...)
Definition: gnunet_common.h:95
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:795
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:832
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:559
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_free(ptr)
Wrapper around free.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Handle for buffered writing.
Definition: bio.c:517
A 512-bit hashcode.
In-memory information about indexed files (also available on-disk).
const char * filename
Name of the indexed file.
struct IndexInfo * next
This is a doubly linked list.
struct GNUNET_HashCode file_id
Hash of the contents of the file.

References _, cfg, IndexInfo::file_id, IndexInfo::filename, GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_open_file(), GNUNET_BIO_write_string(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, indexed_files_head, IndexInfo::next, and wh.

Referenced by GNUNET_FS_add_to_index(), and GNUNET_FS_indexing_do_unindex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_index_list()

static void read_index_list ( )

Read index information from disk.

Definition at line 160 of file gnunet-service-fs_indexing.c.

161 {
162  struct GNUNET_BIO_ReadHandle *rh;
163  char *fn;
164  struct IndexInfo *pos;
165  char *fname;
166  struct GNUNET_HashCode hc;
167  size_t slen;
168  char *emsg;
170  if (GNUNET_OK !=
171  GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
172  {
174  "fs",
175  "INDEXDB");
176  return;
177  }
178  if (GNUNET_NO == GNUNET_DISK_file_test (fn))
179  {
180  /* no index info yet */
181  GNUNET_free (fn);
182  return;
183  }
184  rh = GNUNET_BIO_read_open_file (fn);
185  if (NULL == rh)
186  {
188  _ ("Could not open `%s'.\n"),
189  fn);
190  GNUNET_free (fn);
191  return;
192  }
193  while (
194  (GNUNET_OK == GNUNET_BIO_read (rh,
195  "Hash of indexed file",
196  &hc,
197  sizeof(struct GNUNET_HashCode))) &&
198  (GNUNET_OK ==
199  GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) &&
200  (fname != NULL))
201  {
202  slen = strlen (fname) + 1;
203  pos = GNUNET_malloc (sizeof(struct IndexInfo) + slen);
204  pos->file_id = hc;
205  pos->filename = (const char *) &pos[1];
206  GNUNET_memcpy (&pos[1], fname, slen);
208  ifm,
209  &pos->file_id,
210  pos,
212  {
213  GNUNET_free (pos);
214  }
215  else
216  {
218  }
219  GNUNET_free (fname);
220  }
221  if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
222  GNUNET_free (emsg);
223  GNUNET_free (fn);
224 }
static struct GNUNET_CONTAINER_MultiHashMap * ifm
Maps hash over content of indexed files to the respective 'struct IndexInfo'.
static struct IndexInfo * indexed_files_tail
Tail of linked list of indexed files.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Definition: gnunet_common.h:94
Definition: gnunet_common.h:93
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:326
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:166
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:287
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
Definition: bio.c:74

References _, cfg, IndexInfo::file_id, IndexInfo::filename, GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_open_file(), GNUNET_BIO_read_string(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, ifm, indexed_files_head, and indexed_files_tail.

Referenced by GNUNET_FS_indexing_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_cont()

static void remove_cont ( void *  cls,
int  success,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  msg 

Continuation called from datastore's remove function.

successdid the deletion work?
min_expirationminimum expiration time required for content to be stored
msgerror message

Definition at line 237 of file gnunet-service-fs_indexing.c.

241 {
242  if (GNUNET_OK != success)
244  _ ("Failed to delete bogus block: %s\n"),
245  msg);
246 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2


Referenced by GNUNET_FS_handle_on_demand_block().

Here is the caller graph for this function:

◆ GNUNET_FS_handle_on_demand_block()

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,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
uint64_t  uid,
GNUNET_DATASTORE_DatumProcessor  cont,
void *  cont_cls 

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.

keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
contfunction to call with the actual block (at most once, on success)
cont_clsclosure for cont
GNUNET_OK on success

Definition at line 270 of file gnunet-service-fs_indexing.c.

281 {
282  const struct OnDemandBlock *odb;
283  struct GNUNET_HashCode nkey;
286  struct GNUNET_HashCode query;
287  ssize_t nsize;
288  char ndata[DBLOCK_SIZE];
289  char edata[DBLOCK_SIZE];
290  const char *fn;
291  struct GNUNET_DISK_FileHandle *fh;
292  uint64_t off;
293  struct IndexInfo *ii;
295  if (size != sizeof(struct OnDemandBlock))
296  {
297  GNUNET_break (0);
298  GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
299  return GNUNET_SYSERR;
300  }
301  odb = (const struct OnDemandBlock *) data;
302  off = GNUNET_ntohll (odb->offset);
304  if (NULL == ii)
305  {
306  GNUNET_break (0);
308  "Failed to find index %s\n",
309  GNUNET_h2s (&odb->file_id));
310  return GNUNET_SYSERR;
311  }
312  fn = ii->filename;
313  if ((NULL == fn) || (0 != access (fn, R_OK)))
314  {
316  GSF_stats,
317  gettext_noop ("# index blocks removed: original file inaccessible"),
318  1,
320  GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
321  return GNUNET_SYSERR;
322  }
323  if ((NULL == (fh = GNUNET_DISK_file_open (fn,
326  (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) ||
327  (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof(ndata)))))
328  {
330  _ (
331  "Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
332  GNUNET_h2s (&odb->file_id),
333  fn,
334  (unsigned long long) off,
335  (fn == NULL) ? _ ("not indexed") : strerror (errno));
336  if (fh != NULL)
338  GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
339  return GNUNET_SYSERR;
340  }
342  GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
343  GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
344  GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata);
345  GNUNET_CRYPTO_hash (edata, nsize, &query);
346  if (0 != memcmp (&query, key, sizeof(struct GNUNET_HashCode)))
347  {
349  _ ("Indexed file `%s' changed at offset %llu\n"),
350  fn,
351  (unsigned long long) off);
352  GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
353  return GNUNET_SYSERR;
354  }
356  "On-demand encoded block for query `%s'\n",
357  GNUNET_h2s (key));
358  cont (cont_cls,
359  key,
360  nsize,
361  edata,
363  priority,
364  anonymity,
365  replication,
366  expiration,
367  uid);
368  return GNUNET_OK;
369 }
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
#define gettext_noop(String)
Definition: gettext.h:69
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
static unsigned int replication
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int anonymity
uint32_t data
The data value.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
static void remove_cont(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Continuation called from datastore's remove function.
static struct GNUNET_DATASTORE_Handle * dsh
Datastore handle.
static struct GNUNET_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Definition: gnunet_common.h:97
Data block (leaf) in the CHK tree.
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_remove(struct GNUNET_DATASTORE_Handle *h, const struct GNUNET_HashCode *key, size_t size, const void *data, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Explicitly remove some content from the database.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
Open the file for reading.
Nobody is allowed to do anything to the file.
Seek an absolute position (from the start of the file).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
Definition: crypto_hash.c:146
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle used to access files (and pipes).
index block (indexing a DBlock that can be obtained directly from reading the plaintext file)
Definition: block_fs.h:82
uint64_t offset
At which offset should we be able to find this on-demand encoded block? (in NBO)
Definition: block_fs.h:94
struct GNUNET_HashCode file_id
Hash code of the entire content of the file that was indexed (used to uniquely identify the plaintext...
Definition: block_fs.h:88

References _, anonymity, data, DBLOCK_SIZE, dsh, expiration, fh, OnDemandBlock::file_id, IndexInfo::filename, gettext_noop, GNUNET_BLOCK_TYPE_FS_DBLOCK, GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_to_aes_key(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_DATASTORE_remove(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_DISK_SEEK_SET, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_ntohll(), GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, GSF_stats, ifm, key, OnDemandBlock::offset, remove_cont(), replication, and size.

Referenced by handle_datastore_reply(), process_local_reply(), and process_migration_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_indexing_send_list()

void GNUNET_FS_indexing_send_list ( struct GNUNET_MQ_Handle mq)

Transmit information about indexed files to mq.

mqmessage queue to send information to

Definition at line 378 of file gnunet-service-fs_indexing.c.

379 {
380  struct GNUNET_MQ_Envelope *env;
381  struct IndexInfoMessage *iim;
382  struct GNUNET_MessageHeader *iem;
383  size_t slen;
384  const char *fn;
385  struct IndexInfo *pos;
387  for (pos = indexed_files_head; NULL != pos; pos = pos->next)
388  {
389  fn = pos->filename;
390  slen = strlen (fn) + 1;
391  if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
392  {
393  GNUNET_break (0);
394  break;
395  }
396  env =
398  iim->reserved = 0;
399  iim->file_id = pos->file_id;
400  GNUNET_memcpy (&iim[1], fn, slen);
401  GNUNET_MQ_send (mq, env);
402  }
404  GNUNET_MQ_send (mq, env);
405 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Largest supported message (to be precise, one byte more than the largest possible message,...
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Reply to client with an indexed file name.
Reply to client indicating end of list.
Header for all communications.
Message send by FS service in response to a request asking for a list of all indexed files.
Definition: fs.h:196
struct GNUNET_HashCode file_id
Hash of the indexed file.
Definition: fs.h:211
uint32_t reserved
Always zero.
Definition: fs.h:206

References env, IndexInfoMessage::file_id, IndexInfo::file_id, IndexInfo::filename, GNUNET_break, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY, GNUNET_MQ_msg, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), indexed_files_head, mq, IndexInfo::next, and IndexInfoMessage::reserved.

Referenced by handle_client_index_list_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_indexing_do_unindex()

int GNUNET_FS_indexing_do_unindex ( const struct GNUNET_HashCode fid)

Remove a file from the index.

fididentifier of the file to remove
GNUNET_YES if the fid was found

Definition at line 415 of file gnunet-service-fs_indexing.c.

416 {
417  struct IndexInfo *pos;
419  for (pos = indexed_files_head; NULL != pos; pos = pos->next)
420  {
421  if (0 == memcmp (&pos->file_id, fid, sizeof(struct GNUNET_HashCode)))
422  {
424  GNUNET_break (
425  GNUNET_OK ==
427  GNUNET_free (pos);
428  write_index_list ();
429  return GNUNET_YES;
430  }
431  }
432  return GNUNET_NO;
433 }
static void write_index_list()
Write the current index information list to disk.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.

References IndexInfo::file_id, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, ifm, indexed_files_head, indexed_files_tail, IndexInfo::next, and write_index_list().

Referenced by handle_client_unindex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_add_to_index()

void GNUNET_FS_add_to_index ( const char *  filename,
const struct GNUNET_HashCode file_id 

Add the given file to the list of indexed files.

filenamename of the file
file_idhash identifier for filename

Definition at line 443 of file gnunet-service-fs_indexing.c.

445 {
446  struct IndexInfo *ii;
447  size_t slen;
450  if (NULL != ii)
451  {
452  GNUNET_log (
454  _ (
455  "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
456  filename,
457  ii->filename);
458  return;
459  }
461  "Adding file %s to index as %s\n",
462  filename,
463  GNUNET_h2s (file_id));
464  slen = strlen (filename) + 1;
465  ii = GNUNET_malloc (sizeof(struct IndexInfo) + slen);
466  ii->file_id = *file_id;
467  ii->filename = (const char *) &ii[1];
468  GNUNET_memcpy (&ii[1], filename, slen);
472  ifm,
473  &ii->file_id,
474  ii,
476  write_index_list ();
477 }
static char * filename
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References _, IndexInfo::file_id, filename, IndexInfo::filename, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, ifm, indexed_files_head, indexed_files_tail, and write_index_list().

Referenced by signal_index_ok().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_indexing_done()

void GNUNET_FS_indexing_done ( void  )

Shutdown the module.

Definition at line 484 of file gnunet-service-fs_indexing.c.

485 {
486  struct IndexInfo *pos;
488  while (NULL != (pos = indexed_files_head))
489  {
491  if (pos->fhc != NULL)
493  GNUNET_break (
494  GNUNET_OK ==
496  GNUNET_free (pos);
497  }
499  ifm = NULL;
500  cfg = NULL;
501 }
void GNUNET_CRYPTO_hash_file_cancel(struct GNUNET_CRYPTO_FileHashContext *fhc)
Cancel a file hashing operation.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CRYPTO_FileHashContext * fhc
Context for hashing of the file.

References cfg, IndexInfo::fhc, IndexInfo::file_id, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash_file_cancel(), GNUNET_free, GNUNET_OK, ifm, indexed_files_head, and indexed_files_tail.

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_FS_indexing_init()

int GNUNET_FS_indexing_init ( const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_DATASTORE_Handle d 

Initialize the indexing submodule.

cconfiguration to use
ddatastore to use

Definition at line 511 of file gnunet-service-fs_indexing.c.

513 {
514  cfg = c;
515  dsh = d;
517  read_index_list ();
518  return GNUNET_OK;
519 }
static void read_index_list()
Read index information from disk.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.

References cfg, dsh, GNUNET_CONTAINER_multihashmap_create(), GNUNET_OK, GNUNET_YES, ifm, and read_index_list().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ indexed_files_head

struct IndexInfo* indexed_files_head

Head of linked list of indexed files.

FIXME: we don't need both a DLL and a hashmap here!

Definition at line 82 of file gnunet-service-fs_indexing.c.

Referenced by GNUNET_FS_add_to_index(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), GNUNET_FS_indexing_send_list(), read_index_list(), and write_index_list().

◆ indexed_files_tail

struct IndexInfo* indexed_files_tail

Tail of linked list of indexed files.

Definition at line 87 of file gnunet-service-fs_indexing.c.

Referenced by GNUNET_FS_add_to_index(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), and read_index_list().

◆ ifm

struct GNUNET_CONTAINER_MultiHashMap* ifm

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.

Definition at line 94 of file gnunet-service-fs_indexing.c.

Referenced by GNUNET_FS_add_to_index(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), GNUNET_FS_indexing_init(), and read_index_list().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

◆ dsh

struct GNUNET_DATASTORE_Handle* dsh

Datastore handle.

Created and destroyed by code in gnunet-service-fs (this is an alias).

Definition at line 105 of file gnunet-service-fs_indexing.c.

Referenced by GNUNET_FS_handle_on_demand_block(), GNUNET_FS_indexing_init(), GNUNET_FS_publish_start(), and GNUNET_FS_publish_ublock_().