aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_indexing.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/fs/gnunet-service-fs_indexing.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/fs/gnunet-service-fs_indexing.c')
-rw-r--r--src/fs/gnunet-service-fs_indexing.c129
1 files changed, 44 insertions, 85 deletions
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index 4bf02adb0..c7bff3a9d 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -126,9 +126,7 @@ write_index_list ()
126 while (pos != NULL) 126 while (pos != NULL)
127 { 127 {
128 if ((GNUNET_OK != 128 if ((GNUNET_OK !=
129 GNUNET_BIO_write (wh, 129 GNUNET_BIO_write (wh, &pos->file_id, sizeof (GNUNET_HashCode))) ||
130 &pos->file_id,
131 sizeof (GNUNET_HashCode))) ||
132 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) 130 (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
133 break; 131 break;
134 pos = pos->next; 132 pos = pos->next;
@@ -181,14 +179,11 @@ read_index_list ()
181 return; 179 return;
182 } 180 }
183 while ((GNUNET_OK == 181 while ((GNUNET_OK ==
184 GNUNET_BIO_read (rh, 182 GNUNET_BIO_read (rh, "Hash of indexed file", &hc,
185 "Hash of indexed file",
186 &hc,
187 sizeof (GNUNET_HashCode))) && 183 sizeof (GNUNET_HashCode))) &&
188 (GNUNET_OK == 184 (GNUNET_OK ==
189 GNUNET_BIO_read_string (rh, 185 GNUNET_BIO_read_string (rh, "Name of indexed file", &fname,
190 "Name of indexed file", 186 1024 * 16)) && (fname != NULL))
191 &fname, 1024 * 16)) && (fname != NULL))
192 { 187 {
193 slen = strlen (fname) + 1; 188 slen = strlen (fname) + 1;
194 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 189 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
@@ -196,9 +191,7 @@ read_index_list ()
196 pos->filename = (const char *) &pos[1]; 191 pos->filename = (const char *) &pos[1];
197 memcpy (&pos[1], fname, slen); 192 memcpy (&pos[1], fname, slen);
198 if (GNUNET_SYSERR == 193 if (GNUNET_SYSERR ==
199 GNUNET_CONTAINER_multihashmap_put (ifm, 194 GNUNET_CONTAINER_multihashmap_put (ifm, &hc, (void *) pos->filename,
200 &hc,
201 (void *) pos->filename,
202 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 195 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
203 { 196 {
204 GNUNET_free (pos); 197 GNUNET_free (pos);
@@ -226,8 +219,7 @@ static void
226signal_index_ok (struct IndexInfo *ii) 219signal_index_ok (struct IndexInfo *ii)
227{ 220{
228 if (GNUNET_SYSERR == 221 if (GNUNET_SYSERR ==
229 GNUNET_CONTAINER_multihashmap_put (ifm, 222 GNUNET_CONTAINER_multihashmap_put (ifm, &ii->file_id,
230 &ii->file_id,
231 (void *) ii->filename, 223 (void *) ii->filename,
232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
233 { 225 {
@@ -236,7 +228,8 @@ signal_index_ok (struct IndexInfo *ii)
236 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), 228 ("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
237 ii->filename, 229 ii->filename,
238 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, 230 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
239 &ii->file_id)); 231 &ii->
232 file_id));
240 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0, 233 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
241 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 234 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
242 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 235 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
@@ -246,8 +239,7 @@ signal_index_ok (struct IndexInfo *ii)
246 ii->next = indexed_files; 239 ii->next = indexed_files;
247 indexed_files = ii; 240 indexed_files = ii;
248 write_index_list (); 241 write_index_list ();
249 GNUNET_SERVER_transmit_context_append_data (ii->tc, 242 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
250 NULL, 0,
251 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 243 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
252 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 244 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
253 ii->tc = NULL; 245 ii->tc = NULL;
@@ -275,11 +267,10 @@ hash_for_index_val (void *cls, const GNUNET_HashCode * res)
275 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"), 267 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
276 ii->filename, GNUNET_h2s (res)); 268 ii->filename, GNUNET_h2s (res));
277#if DEBUG_FS 269#if DEBUG_FS
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wanted `%s'\n",
279 "Wanted `%s'\n", GNUNET_h2s (&ii->file_id)); 271 GNUNET_h2s (&ii->file_id));
280#endif 272#endif
281 GNUNET_SERVER_transmit_context_append_data (ii->tc, 273 GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
282 NULL, 0,
283 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 274 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
284 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES); 275 GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
285 GNUNET_free (ii); 276 GNUNET_free (ii);
@@ -297,8 +288,7 @@ hash_for_index_val (void *cls, const GNUNET_HashCode * res)
297 * @param message the actual message 288 * @param message the actual message
298 */ 289 */
299void 290void
300GNUNET_FS_handle_index_start (void *cls, 291GNUNET_FS_handle_index_start (void *cls, struct GNUNET_SERVER_Client *client,
301 struct GNUNET_SERVER_Client *client,
302 const struct GNUNET_MessageHeader *message) 292 const struct GNUNET_MessageHeader *message)
303{ 293{
304 const struct IndexStartMessage *ism; 294 const struct IndexStartMessage *ism;
@@ -341,19 +331,15 @@ GNUNET_FS_handle_index_start (void *cls,
341 memcpy (&ii[1], fn, slen); 331 memcpy (&ii[1], fn, slen);
342 ii->file_id = ism->file_id; 332 ii->file_id = ism->file_id;
343#if DEBUG_FS 333#if DEBUG_FS
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for file `%s'\n",
345 "Received `%s' message for file `%s'\n",
346 "START_INDEX", ii->filename); 335 "START_INDEX", ii->filename);
347#endif 336#endif
348 337
349 ii->tc = GNUNET_SERVER_transmit_context_create (client); 338 ii->tc = GNUNET_SERVER_transmit_context_create (client);
350 mydev = 0; 339 mydev = 0;
351 myino = 0; 340 myino = 0;
352 if (((dev != 0) || 341 if (((dev != 0) || (ino != 0)) &&
353 (ino != 0)) && 342 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, &mydev, &myino)) &&
354 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
355 &mydev,
356 &myino)) &&
357 ((dev == mydev) && (ino == myino))) 343 ((dev == mydev) && (ino == myino)))
358 { 344 {
359 /* fast validation OK! */ 345 /* fast validation OK! */
@@ -364,15 +350,13 @@ GNUNET_FS_handle_index_start (void *cls,
364#if DEBUG_FS 350#if DEBUG_FS
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", 352 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
367 (unsigned long long) ino, 353 (unsigned long long) ino, (unsigned long long) myino,
368 (unsigned long long) myino,
369 (unsigned int) dev, (unsigned int) mydev); 354 (unsigned int) dev, (unsigned int) mydev);
370#endif 355#endif
371 /* slow validation, need to hash full file (again) */ 356 /* slow validation, need to hash full file (again) */
372 ii->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 357 ii->fhc =
373 fn, 358 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, fn,
374 HASHING_BLOCKSIZE, 359 HASHING_BLOCKSIZE, &hash_for_index_val, ii);
375 &hash_for_index_val, ii);
376 if (ii->fhc == NULL) 360 if (ii->fhc == NULL)
377 hash_for_index_val (ii, NULL); 361 hash_for_index_val (ii, NULL);
378 GNUNET_free (fn); 362 GNUNET_free (fn);
@@ -387,8 +371,7 @@ GNUNET_FS_handle_index_start (void *cls,
387 * @param message the actual message 371 * @param message the actual message
388 */ 372 */
389void 373void
390GNUNET_FS_handle_index_list_get (void *cls, 374GNUNET_FS_handle_index_list_get (void *cls, struct GNUNET_SERVER_Client *client,
391 struct GNUNET_SERVER_Client *client,
392 const struct GNUNET_MessageHeader *message) 375 const struct GNUNET_MessageHeader *message)
393{ 376{
394 struct GNUNET_SERVER_TransmitContext *tc; 377 struct GNUNET_SERVER_TransmitContext *tc;
@@ -419,8 +402,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
419 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header); 402 GNUNET_SERVER_transmit_context_append_message (tc, &iim->header);
420 pos = pos->next; 403 pos = pos->next;
421 } 404 }
422 GNUNET_SERVER_transmit_context_append_data (tc, 405 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
423 NULL, 0,
424 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); 406 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
425 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES); 407 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
426} 408}
@@ -434,8 +416,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
434 * @param message the actual message 416 * @param message the actual message
435 */ 417 */
436void 418void
437GNUNET_FS_handle_unindex (void *cls, 419GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
438 struct GNUNET_SERVER_Client *client,
439 const struct GNUNET_MessageHeader *message) 420 const struct GNUNET_MessageHeader *message)
440{ 421{
441 const struct UnindexMessage *um; 422 const struct UnindexMessage *um;
@@ -465,10 +446,9 @@ GNUNET_FS_handle_unindex (void *cls,
465 else 446 else
466 prev->next = next; 447 prev->next = next;
467 GNUNET_break (GNUNET_OK == 448 GNUNET_break (GNUNET_OK ==
468 GNUNET_CONTAINER_multihashmap_remove (ifm, 449 GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id,
469 &pos->file_id, 450 (void *) pos->
470 (void *) 451 filename));
471 pos->filename));
472 GNUNET_free (pos); 452 GNUNET_free (pos);
473 found = GNUNET_YES; 453 found = GNUNET_YES;
474 } 454 }
@@ -486,8 +466,7 @@ GNUNET_FS_handle_unindex (void *cls,
486 if (GNUNET_YES == found) 466 if (GNUNET_YES == found)
487 write_index_list (); 467 write_index_list ();
488 tc = GNUNET_SERVER_transmit_context_create (client); 468 tc = GNUNET_SERVER_transmit_context_create (client);
489 GNUNET_SERVER_transmit_context_append_data (tc, 469 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
490 NULL, 0,
491 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); 470 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
492 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES); 471 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_MINUTES);
493} 472}
@@ -530,14 +509,11 @@ remove_cont (void *cls, int success, const char *msg)
530 * @return GNUNET_OK on success 509 * @return GNUNET_OK on success
531 */ 510 */
532int 511int
533GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, 512GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size,
534 uint32_t size, 513 const void *data, enum GNUNET_BLOCK_Type type,
535 const void *data, 514 uint32_t priority, uint32_t anonymity,
536 enum GNUNET_BLOCK_Type type, 515 struct GNUNET_TIME_Absolute expiration,
537 uint32_t priority, 516 uint64_t uid,
538 uint32_t anonymity,
539 struct GNUNET_TIME_Absolute
540 expiration, uint64_t uid,
541 GNUNET_DATASTORE_DatumProcessor cont, 517 GNUNET_DATASTORE_DatumProcessor cont,
542 void *cont_cls) 518 void *cont_cls)
543{ 519{
@@ -556,11 +532,7 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
556 if (size != sizeof (struct OnDemandBlock)) 532 if (size != sizeof (struct OnDemandBlock))
557 { 533 {
558 GNUNET_break (0); 534 GNUNET_break (0);
559 GNUNET_DATASTORE_remove (dsh, 535 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
560 key,
561 size,
562 data,
563 -1, -1,
564 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 536 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
565 return GNUNET_SYSERR; 537 return GNUNET_SYSERR;
566 } 538 }
@@ -569,13 +541,11 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
569 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); 541 fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
570 fh = NULL; 542 fh = NULL;
571 if ((NULL == fn) || 543 if ((NULL == fn) ||
572 (NULL == (fh = GNUNET_DISK_file_open (fn, 544 (NULL ==
573 GNUNET_DISK_OPEN_READ, 545 (fh =
574 GNUNET_DISK_PERM_NONE))) || 546 GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
575 (off != 547 GNUNET_DISK_PERM_NONE))) ||
576 GNUNET_DISK_file_seek (fh, 548 (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) ||
577 off,
578 GNUNET_DISK_SEEK_SET)) ||
579 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) 549 (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
580 { 550 {
581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 551 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -585,11 +555,7 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
585 (fn == NULL) ? _("not indexed") : STRERROR (errno)); 555 (fn == NULL) ? _("not indexed") : STRERROR (errno));
586 if (fh != NULL) 556 if (fh != NULL)
587 GNUNET_DISK_file_close (fh); 557 GNUNET_DISK_file_close (fh);
588 GNUNET_DATASTORE_remove (dsh, 558 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
589 key,
590 size,
591 data,
592 -1, -1,
593 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 559 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
594 return GNUNET_SYSERR; 560 return GNUNET_SYSERR;
595 } 561 }
@@ -601,13 +567,9 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
601 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode))) 567 if (0 != memcmp (&query, key, sizeof (GNUNET_HashCode)))
602 { 568 {
603 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
604 _("Indexed file `%s' changed at offset %llu\n"), 570 _("Indexed file `%s' changed at offset %llu\n"), fn,
605 fn, (unsigned long long) off); 571 (unsigned long long) off);
606 GNUNET_DATASTORE_remove (dsh, 572 GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
607 key,
608 size,
609 data,
610 -1, -1,
611 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL); 573 GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
612 return GNUNET_SYSERR; 574 return GNUNET_SYSERR;
613 } 575 }
@@ -615,11 +577,8 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key,
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key)); 578 "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
617#endif 579#endif
618 cont (cont_cls, 580 cont (cont_cls, key, nsize, edata, GNUNET_BLOCK_TYPE_FS_DBLOCK, priority,
619 key, 581 anonymity, expiration, uid);
620 nsize,
621 edata,
622 GNUNET_BLOCK_TYPE_FS_DBLOCK, priority, anonymity, expiration, uid);
623 return GNUNET_OK; 582 return GNUNET_OK;
624} 583}
625 584