aboutsummaryrefslogtreecommitdiff
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.c480
1 files changed, 239 insertions, 241 deletions
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index df5f70b3d..e21b2ca57 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/gnunet-service-fs_indexing.c 22 * @file fs/gnunet-service-fs_indexing.c
@@ -39,9 +39,7 @@
39 * In-memory information about indexed files (also available 39 * In-memory information about indexed files (also available
40 * on-disk). 40 * on-disk).
41 */ 41 */
42struct IndexInfo 42struct IndexInfo {
43{
44
45 /** 43 /**
46 * This is a doubly linked list. 44 * This is a doubly linked list.
47 */ 45 */
@@ -110,44 +108,44 @@ static struct GNUNET_DATASTORE_Handle *dsh;
110 * Write the current index information list to disk. 108 * Write the current index information list to disk.
111 */ 109 */
112static void 110static void
113write_index_list () 111write_index_list()
114{ 112{
115 struct GNUNET_BIO_WriteHandle *wh; 113 struct GNUNET_BIO_WriteHandle *wh;
116 char *fn; 114 char *fn;
117 struct IndexInfo *pos; 115 struct IndexInfo *pos;
118 116
119 if (GNUNET_OK != 117 if (GNUNET_OK !=
120 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) 118 GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn))
121 { 119 {
122 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 120 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
123 "fs", 121 "fs",
124 "INDEXDB"); 122 "INDEXDB");
125 return; 123 return;
126 } 124 }
127 wh = GNUNET_BIO_write_open (fn); 125 wh = GNUNET_BIO_write_open(fn);
128 if (NULL == wh) 126 if (NULL == wh)
129 { 127 {
130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 128 GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
131 _ ("Could not open `%s'.\n"), 129 _("Could not open `%s'.\n"),
132 fn); 130 fn);
133 GNUNET_free (fn); 131 GNUNET_free(fn);
134 return; 132 return;
135 } 133 }
136 for (pos = indexed_files_head; NULL != pos; pos = pos->next) 134 for (pos = indexed_files_head; NULL != pos; pos = pos->next)
137 if ((GNUNET_OK != GNUNET_BIO_write (wh, 135 if ((GNUNET_OK != GNUNET_BIO_write(wh,
138 &pos->file_id, 136 &pos->file_id,
139 sizeof (struct GNUNET_HashCode))) || 137 sizeof(struct GNUNET_HashCode))) ||
140 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) 138 (GNUNET_OK != GNUNET_BIO_write_string(wh, pos->filename)))
141 break; 139 break;
142 if (GNUNET_OK != GNUNET_BIO_write_close (wh)) 140 if (GNUNET_OK != GNUNET_BIO_write_close(wh))
143 { 141 {
144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
145 _ ("Error writing `%s'.\n"), 143 _("Error writing `%s'.\n"),
146 fn); 144 fn);
147 GNUNET_free (fn); 145 GNUNET_free(fn);
148 return; 146 return;
149 } 147 }
150 GNUNET_free (fn); 148 GNUNET_free(fn);
151} 149}
152 150
153 151
@@ -155,7 +153,7 @@ write_index_list ()
155 * Read index information from disk. 153 * Read index information from disk.
156 */ 154 */
157static void 155static void
158read_index_list () 156read_index_list()
159{ 157{
160 struct GNUNET_BIO_ReadHandle *rh; 158 struct GNUNET_BIO_ReadHandle *rh;
161 char *fn; 159 char *fn;
@@ -166,59 +164,59 @@ read_index_list ()
166 char *emsg; 164 char *emsg;
167 165
168 if (GNUNET_OK != 166 if (GNUNET_OK !=
169 GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) 167 GNUNET_CONFIGURATION_get_value_filename(cfg, "FS", "INDEXDB", &fn))
170 { 168 {
171 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 169 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
172 "fs", 170 "fs",
173 "INDEXDB"); 171 "INDEXDB");
174 return; 172 return;
175 } 173 }
176 if (GNUNET_NO == GNUNET_DISK_file_test (fn)) 174 if (GNUNET_NO == GNUNET_DISK_file_test(fn))
177 { 175 {
178 /* no index info yet */ 176 /* no index info yet */
179 GNUNET_free (fn); 177 GNUNET_free(fn);
180 return; 178 return;
181 } 179 }
182 rh = GNUNET_BIO_read_open (fn); 180 rh = GNUNET_BIO_read_open(fn);
183 if (NULL == rh) 181 if (NULL == rh)
184 { 182 {
185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 183 GNUNET_log(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
186 _ ("Could not open `%s'.\n"), 184 _("Could not open `%s'.\n"),
187 fn); 185 fn);
188 GNUNET_free (fn); 186 GNUNET_free(fn);
189 return; 187 return;
190 } 188 }
191 while ( 189 while (
192 (GNUNET_OK == GNUNET_BIO_read (rh, 190 (GNUNET_OK == GNUNET_BIO_read(rh,
193 "Hash of indexed file", 191 "Hash of indexed file",
194 &hc, 192 &hc,
195 sizeof (struct GNUNET_HashCode))) && 193 sizeof(struct GNUNET_HashCode))) &&
196 (GNUNET_OK == 194 (GNUNET_OK ==
197 GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && 195 GNUNET_BIO_read_string(rh, "Name of indexed file", &fname, 1024 * 16)) &&
198 (fname != NULL)) 196 (fname != NULL))
199 {
200 slen = strlen (fname) + 1;
201 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
202 pos->file_id = hc;
203 pos->filename = (const char *) &pos[1];
204 GNUNET_memcpy (&pos[1], fname, slen);
205 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
206 ifm,
207 &pos->file_id,
208 pos,
209 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
210 {
211 GNUNET_free (pos);
212 }
213 else
214 { 197 {
215 GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); 198 slen = strlen(fname) + 1;
199 pos = GNUNET_malloc(sizeof(struct IndexInfo) + slen);
200 pos->file_id = hc;
201 pos->filename = (const char *)&pos[1];
202 GNUNET_memcpy(&pos[1], fname, slen);
203 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(
204 ifm,
205 &pos->file_id,
206 pos,
207 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
208 {
209 GNUNET_free(pos);
210 }
211 else
212 {
213 GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, pos);
214 }
215 GNUNET_free(fname);
216 } 216 }
217 GNUNET_free (fname); 217 if (GNUNET_OK != GNUNET_BIO_read_close(rh, &emsg))
218 } 218 GNUNET_free(emsg);
219 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 219 GNUNET_free(fn);
220 GNUNET_free (emsg);
221 GNUNET_free (fn);
222} 220}
223 221
224 222
@@ -232,15 +230,15 @@ read_index_list ()
232 * @param msg error message 230 * @param msg error message
233 */ 231 */
234static void 232static void
235remove_cont (void *cls, 233remove_cont(void *cls,
236 int success, 234 int success,
237 struct GNUNET_TIME_Absolute min_expiration, 235 struct GNUNET_TIME_Absolute min_expiration,
238 const char *msg) 236 const char *msg)
239{ 237{
240 if (GNUNET_OK != success) 238 if (GNUNET_OK != success)
241 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 239 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
242 _ ("Failed to delete bogus block: %s\n"), 240 _("Failed to delete bogus block: %s\n"),
243 msg); 241 msg);
244} 242}
245 243
246 244
@@ -265,17 +263,17 @@ remove_cont (void *cls,
265 * @return GNUNET_OK on success 263 * @return GNUNET_OK on success
266 */ 264 */
267int 265int
268GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, 266GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key,
269 uint32_t size, 267 uint32_t size,
270 const void *data, 268 const void *data,
271 enum GNUNET_BLOCK_Type type, 269 enum GNUNET_BLOCK_Type type,
272 uint32_t priority, 270 uint32_t priority,
273 uint32_t anonymity, 271 uint32_t anonymity,
274 uint32_t replication, 272 uint32_t replication,
275 struct GNUNET_TIME_Absolute expiration, 273 struct GNUNET_TIME_Absolute expiration,
276 uint64_t uid, 274 uint64_t uid,
277 GNUNET_DATASTORE_DatumProcessor cont, 275 GNUNET_DATASTORE_DatumProcessor cont,
278 void *cont_cls) 276 void *cont_cls)
279{ 277{
280 const struct OnDemandBlock *odb; 278 const struct OnDemandBlock *odb;
281 struct GNUNET_HashCode nkey; 279 struct GNUNET_HashCode nkey;
@@ -290,79 +288,79 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
290 uint64_t off; 288 uint64_t off;
291 struct IndexInfo *ii; 289 struct IndexInfo *ii;
292 290
293 if (size != sizeof (struct OnDemandBlock)) 291 if (size != sizeof(struct OnDemandBlock))
294 { 292 {
295 GNUNET_break (0); 293 GNUNET_break(0);
296 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); 294 GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL);
297 return GNUNET_SYSERR; 295 return GNUNET_SYSERR;
298 } 296 }
299 odb = (const struct OnDemandBlock *) data; 297 odb = (const struct OnDemandBlock *)data;
300 off = GNUNET_ntohll (odb->offset); 298 off = GNUNET_ntohll(odb->offset);
301 ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); 299 ii = GNUNET_CONTAINER_multihashmap_get(ifm, &odb->file_id);
302 if (NULL == ii) 300 if (NULL == ii)
303 { 301 {
304 GNUNET_break (0); 302 GNUNET_break(0);
305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
306 "Failed to find index %s\n", 304 "Failed to find index %s\n",
307 GNUNET_h2s (&odb->file_id)); 305 GNUNET_h2s(&odb->file_id));
308 return GNUNET_SYSERR; 306 return GNUNET_SYSERR;
309 } 307 }
310 fn = ii->filename; 308 fn = ii->filename;
311 if ((NULL == fn) || (0 != access (fn, R_OK))) 309 if ((NULL == fn) || (0 != access(fn, R_OK)))
312 { 310 {
313 GNUNET_STATISTICS_update ( 311 GNUNET_STATISTICS_update(
314 GSF_stats, 312 GSF_stats,
315 gettext_noop ("# index blocks removed: original file inaccessible"), 313 gettext_noop("# index blocks removed: original file inaccessible"),
316 1, 314 1,
317 GNUNET_YES); 315 GNUNET_YES);
318 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); 316 GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL);
319 return GNUNET_SYSERR; 317 return GNUNET_SYSERR;
320 } 318 }
321 if ((NULL == (fh = GNUNET_DISK_file_open (fn, 319 if ((NULL == (fh = GNUNET_DISK_file_open(fn,
322 GNUNET_DISK_OPEN_READ, 320 GNUNET_DISK_OPEN_READ,
323 GNUNET_DISK_PERM_NONE))) || 321 GNUNET_DISK_PERM_NONE))) ||
324 (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || 322 (off != GNUNET_DISK_file_seek(fh, off, GNUNET_DISK_SEEK_SET)) ||
325 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) 323 (-1 == (nsize = GNUNET_DISK_file_read(fh, ndata, sizeof(ndata)))))
326 { 324 {
327 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 325 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
328 _ ( 326 _(
329 "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), 327 "Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
330 GNUNET_h2s (&odb->file_id), 328 GNUNET_h2s(&odb->file_id),
331 fn, 329 fn,
332 (unsigned long long) off, 330 (unsigned long long)off,
333 (fn == NULL) ? _ ("not indexed") : strerror (errno)); 331 (fn == NULL) ? _("not indexed") : strerror(errno));
334 if (fh != NULL) 332 if (fh != NULL)
335 GNUNET_DISK_file_close (fh); 333 GNUNET_DISK_file_close(fh);
336 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); 334 GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL);
337 return GNUNET_SYSERR; 335 return GNUNET_SYSERR;
338 } 336 }
339 GNUNET_DISK_file_close (fh); 337 GNUNET_DISK_file_close(fh);
340 GNUNET_CRYPTO_hash (ndata, nsize, &nkey); 338 GNUNET_CRYPTO_hash(ndata, nsize, &nkey);
341 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); 339 GNUNET_CRYPTO_hash_to_aes_key(&nkey, &skey, &iv);
342 GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); 340 GNUNET_CRYPTO_symmetric_encrypt(ndata, nsize, &skey, &iv, edata);
343 GNUNET_CRYPTO_hash (edata, nsize, &query); 341 GNUNET_CRYPTO_hash(edata, nsize, &query);
344 if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) 342 if (0 != memcmp(&query, key, sizeof(struct GNUNET_HashCode)))
345 { 343 {
346 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 344 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
347 _ ("Indexed file `%s' changed at offset %llu\n"), 345 _("Indexed file `%s' changed at offset %llu\n"),
348 fn, 346 fn,
349 (unsigned long long) off); 347 (unsigned long long)off);
350 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); 348 GNUNET_DATASTORE_remove(dsh, key, size, data, -1, -1, &remove_cont, NULL);
351 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
352 } 350 }
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
354 "On-demand encoded block for query `%s'\n", 352 "On-demand encoded block for query `%s'\n",
355 GNUNET_h2s (key)); 353 GNUNET_h2s(key));
356 cont (cont_cls, 354 cont(cont_cls,
357 key, 355 key,
358 nsize, 356 nsize,
359 edata, 357 edata,
360 GNUNET_BLOCK_TYPE_FS_DBLOCK, 358 GNUNET_BLOCK_TYPE_FS_DBLOCK,
361 priority, 359 priority,
362 anonymity, 360 anonymity,
363 replication, 361 replication,
364 expiration, 362 expiration,
365 uid); 363 uid);
366 return GNUNET_OK; 364 return GNUNET_OK;
367} 365}
368 366
@@ -373,7 +371,7 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
373 * @param mq message queue to send information to 371 * @param mq message queue to send information to
374 */ 372 */
375void 373void
376GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) 374GNUNET_FS_indexing_send_list(struct GNUNET_MQ_Handle *mq)
377{ 375{
378 struct GNUNET_MQ_Envelope *env; 376 struct GNUNET_MQ_Envelope *env;
379 struct IndexInfoMessage *iim; 377 struct IndexInfoMessage *iim;
@@ -383,23 +381,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
383 struct IndexInfo *pos; 381 struct IndexInfo *pos;
384 382
385 for (pos = indexed_files_head; NULL != pos; pos = pos->next) 383 for (pos = indexed_files_head; NULL != pos; pos = pos->next)
386 {
387 fn = pos->filename;
388 slen = strlen (fn) + 1;
389 if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
390 { 384 {
391 GNUNET_break (0); 385 fn = pos->filename;
392 break; 386 slen = strlen(fn) + 1;
387 if (slen + sizeof(struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
388 {
389 GNUNET_break(0);
390 break;
391 }
392 env =
393 GNUNET_MQ_msg_extra(iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
394 iim->reserved = 0;
395 iim->file_id = pos->file_id;
396 GNUNET_memcpy(&iim[1], fn, slen);
397 GNUNET_MQ_send(mq, env);
393 } 398 }
394 env = 399 env = GNUNET_MQ_msg(iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
395 GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); 400 GNUNET_MQ_send(mq, env);
396 iim->reserved = 0;
397 iim->file_id = pos->file_id;
398 GNUNET_memcpy (&iim[1], fn, slen);
399 GNUNET_MQ_send (mq, env);
400 }
401 env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
402 GNUNET_MQ_send (mq, env);
403} 401}
404 402
405 403
@@ -410,23 +408,23 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq)
410 * @return #GNUNET_YES if the @a fid was found 408 * @return #GNUNET_YES if the @a fid was found
411 */ 409 */
412int 410int
413GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) 411GNUNET_FS_indexing_do_unindex(const struct GNUNET_HashCode *fid)
414{ 412{
415 struct IndexInfo *pos; 413 struct IndexInfo *pos;
416 414
417 for (pos = indexed_files_head; NULL != pos; pos = pos->next) 415 for (pos = indexed_files_head; NULL != pos; pos = pos->next)
418 {
419 if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode)))
420 { 416 {
421 GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); 417 if (0 == memcmp(&pos->file_id, fid, sizeof(struct GNUNET_HashCode)))
422 GNUNET_break ( 418 {
423 GNUNET_OK == 419 GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos);
424 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); 420 GNUNET_break(
425 GNUNET_free (pos); 421 GNUNET_OK ==
426 write_index_list (); 422 GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos));
427 return GNUNET_YES; 423 GNUNET_free(pos);
424 write_index_list();
425 return GNUNET_YES;
426 }
428 } 427 }
429 }
430 return GNUNET_NO; 428 return GNUNET_NO;
431} 429}
432 430
@@ -438,40 +436,40 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid)
438 * @param file_id hash identifier for @a filename 436 * @param file_id hash identifier for @a filename
439 */ 437 */
440void 438void
441GNUNET_FS_add_to_index (const char *filename, 439GNUNET_FS_add_to_index(const char *filename,
442 const struct GNUNET_HashCode *file_id) 440 const struct GNUNET_HashCode *file_id)
443{ 441{
444 struct IndexInfo *ii; 442 struct IndexInfo *ii;
445 size_t slen; 443 size_t slen;
446 444
447 ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); 445 ii = GNUNET_CONTAINER_multihashmap_get(ifm, file_id);
448 if (NULL != ii) 446 if (NULL != ii)
449 { 447 {
450 GNUNET_log ( 448 GNUNET_log(
451 GNUNET_ERROR_TYPE_INFO, 449 GNUNET_ERROR_TYPE_INFO,
452 _ ( 450 _(
453 "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 451 "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
454 filename, 452 filename,
455 ii->filename); 453 ii->filename);
456 return; 454 return;
457 } 455 }
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 456 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
459 "Adding file %s to index as %s\n", 457 "Adding file %s to index as %s\n",
460 filename, 458 filename,
461 GNUNET_h2s (file_id)); 459 GNUNET_h2s(file_id));
462 slen = strlen (filename) + 1; 460 slen = strlen(filename) + 1;
463 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 461 ii = GNUNET_malloc(sizeof(struct IndexInfo) + slen);
464 ii->file_id = *file_id; 462 ii->file_id = *file_id;
465 ii->filename = (const char *) &ii[1]; 463 ii->filename = (const char *)&ii[1];
466 GNUNET_memcpy (&ii[1], filename, slen); 464 GNUNET_memcpy(&ii[1], filename, slen);
467 GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); 465 GNUNET_CONTAINER_DLL_insert(indexed_files_head, indexed_files_tail, ii);
468 GNUNET_assert (GNUNET_OK == 466 GNUNET_assert(GNUNET_OK ==
469 GNUNET_CONTAINER_multihashmap_put ( 467 GNUNET_CONTAINER_multihashmap_put(
470 ifm, 468 ifm,
471 &ii->file_id, 469 &ii->file_id,
472 ii, 470 ii,
473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 471 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
474 write_index_list (); 472 write_index_list();
475} 473}
476 474
477 475
@@ -479,21 +477,21 @@ GNUNET_FS_add_to_index (const char *filename,
479 * Shutdown the module. 477 * Shutdown the module.
480 */ 478 */
481void 479void
482GNUNET_FS_indexing_done () 480GNUNET_FS_indexing_done()
483{ 481{
484 struct IndexInfo *pos; 482 struct IndexInfo *pos;
485 483
486 while (NULL != (pos = indexed_files_head)) 484 while (NULL != (pos = indexed_files_head))
487 { 485 {
488 GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); 486 GNUNET_CONTAINER_DLL_remove(indexed_files_head, indexed_files_tail, pos);
489 if (pos->fhc != NULL) 487 if (pos->fhc != NULL)
490 GNUNET_CRYPTO_hash_file_cancel (pos->fhc); 488 GNUNET_CRYPTO_hash_file_cancel(pos->fhc);
491 GNUNET_break ( 489 GNUNET_break(
492 GNUNET_OK == 490 GNUNET_OK ==
493 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); 491 GNUNET_CONTAINER_multihashmap_remove(ifm, &pos->file_id, pos));
494 GNUNET_free (pos); 492 GNUNET_free(pos);
495 } 493 }
496 GNUNET_CONTAINER_multihashmap_destroy (ifm); 494 GNUNET_CONTAINER_multihashmap_destroy(ifm);
497 ifm = NULL; 495 ifm = NULL;
498 cfg = NULL; 496 cfg = NULL;
499} 497}
@@ -506,13 +504,13 @@ GNUNET_FS_indexing_done ()
506 * @param d datastore to use 504 * @param d datastore to use
507 */ 505 */
508int 506int
509GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, 507GNUNET_FS_indexing_init(const struct GNUNET_CONFIGURATION_Handle *c,
510 struct GNUNET_DATASTORE_Handle *d) 508 struct GNUNET_DATASTORE_Handle *d)
511{ 509{
512 cfg = c; 510 cfg = c;
513 dsh = d; 511 dsh = d;
514 ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); 512 ifm = GNUNET_CONTAINER_multihashmap_create(128, GNUNET_YES);
515 read_index_list (); 513 read_index_list();
516 return GNUNET_OK; 514 return GNUNET_OK;
517} 515}
518 516