summaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs.c')
-rw-r--r--src/fs/gnunet-service-fs.c1124
1 files changed, 558 insertions, 566 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 691242ce3..70aff8a75 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -16,7 +16,7 @@
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.c 22 * @file fs/gnunet-service-fs.c
@@ -59,7 +59,7 @@
59 * time interval, remaining cover traffic counters are 59 * time interval, remaining cover traffic counters are
60 * decremented by 1/16th. 60 * decremented by 1/16th.
61 */ 61 */
62#define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 62#define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
63 63
64/** 64/**
65 * Collect an instane number of statistics? May cause excessive IPC. 65 * Collect an instane number of statistics? May cause excessive IPC.
@@ -72,9 +72,7 @@
72 * Doubly-linked list of requests we are performing 72 * Doubly-linked list of requests we are performing
73 * on behalf of the same client. 73 * on behalf of the same client.
74 */ 74 */
75struct ClientRequest 75struct ClientRequest {
76{
77
78 /** 76 /**
79 * This is a doubly-linked list. 77 * This is a doubly-linked list.
80 */ 78 */
@@ -99,7 +97,6 @@ struct ClientRequest
99 * Task scheduled to destroy the request. 97 * Task scheduled to destroy the request.
100 */ 98 */
101 struct GNUNET_SCHEDULER_Task * kill_task; 99 struct GNUNET_SCHEDULER_Task * kill_task;
102
103}; 100};
104 101
105 102
@@ -107,8 +104,7 @@ struct ClientRequest
107 * Replies to be transmitted to the client. The actual 104 * Replies to be transmitted to the client. The actual
108 * response message is allocated after this struct. 105 * response message is allocated after this struct.
109 */ 106 */
110struct ClientResponse 107struct ClientResponse {
111{
112 /** 108 /**
113 * This is a doubly-linked list. 109 * This is a doubly-linked list.
114 */ 110 */
@@ -135,9 +131,7 @@ struct ClientResponse
135 * Information we track while handling an index 131 * Information we track while handling an index
136 * start request from a client. 132 * start request from a client.
137 */ 133 */
138struct IndexStartContext 134struct IndexStartContext {
139{
140
141 /** 135 /**
142 * This is a doubly linked list. 136 * This is a doubly linked list.
143 */ 137 */
@@ -167,16 +161,13 @@ struct IndexStartContext
167 * Hash of the contents of the file. 161 * Hash of the contents of the file.
168 */ 162 */
169 struct GNUNET_HashCode file_id; 163 struct GNUNET_HashCode file_id;
170
171}; 164};
172 165
173 166
174/** 167/**
175 * A local client. 168 * A local client.
176 */ 169 */
177struct GSF_LocalClient 170struct GSF_LocalClient {
178{
179
180 /** 171 /**
181 * ID of the client. 172 * ID of the client.
182 */ 173 */
@@ -218,7 +209,6 @@ struct GSF_LocalClient
218 * Tail of linked list of responses. 209 * Tail of linked list of responses.
219 */ 210 */
220 struct ClientResponse *res_tail; 211 struct ClientResponse *res_tail;
221
222}; 212};
223 213
224 214
@@ -343,13 +333,13 @@ static struct GNUNET_LOAD_Value *datastore_get_load;
343 * @return handle to local client entry 333 * @return handle to local client entry
344 */ 334 */
345static void * 335static void *
346client_connect_cb (void *cls, 336client_connect_cb(void *cls,
347 struct GNUNET_SERVICE_Client *client, 337 struct GNUNET_SERVICE_Client *client,
348 struct GNUNET_MQ_Handle *mq) 338 struct GNUNET_MQ_Handle *mq)
349{ 339{
350 struct GSF_LocalClient *pos; 340 struct GSF_LocalClient *pos;
351 341
352 pos = GNUNET_new (struct GSF_LocalClient); 342 pos = GNUNET_new(struct GSF_LocalClient);
353 pos->client = client; 343 pos->client = client;
354 pos->mq = mq; 344 pos->mq = mq;
355 return pos; 345 return pos;
@@ -362,22 +352,22 @@ client_connect_cb (void *cls,
362 * @param cls the client request to free 352 * @param cls the client request to free
363 */ 353 */
364static void 354static void
365client_request_destroy (void *cls) 355client_request_destroy(void *cls)
366{ 356{
367 struct ClientRequest *cr = cls; 357 struct ClientRequest *cr = cls;
368 struct GSF_LocalClient *lc = cr->lc; 358 struct GSF_LocalClient *lc = cr->lc;
369 359
370 cr->kill_task = NULL; 360 cr->kill_task = NULL;
371 GNUNET_CONTAINER_DLL_remove (lc->cr_head, 361 GNUNET_CONTAINER_DLL_remove(lc->cr_head,
372 lc->cr_tail, 362 lc->cr_tail,
373 cr); 363 cr);
374 GSF_pending_request_cancel_ (cr->pr, 364 GSF_pending_request_cancel_(cr->pr,
375 GNUNET_YES); 365 GNUNET_YES);
376 GNUNET_STATISTICS_update (GSF_stats, 366 GNUNET_STATISTICS_update(GSF_stats,
377 gettext_noop ("# client searches active"), 367 gettext_noop("# client searches active"),
378 -1, 368 -1,
379 GNUNET_NO); 369 GNUNET_NO);
380 GNUNET_free (cr); 370 GNUNET_free(cr);
381} 371}
382 372
383 373
@@ -400,15 +390,15 @@ client_request_destroy (void *cls)
400 * @param data_len number of bytes in @a data 390 * @param data_len number of bytes in @a data
401 */ 391 */
402static void 392static void
403client_response_handler (void *cls, 393client_response_handler(void *cls,
404 enum GNUNET_BLOCK_EvaluationResult eval, 394 enum GNUNET_BLOCK_EvaluationResult eval,
405 struct GSF_PendingRequest *pr, 395 struct GSF_PendingRequest *pr,
406 uint32_t reply_anonymity_level, 396 uint32_t reply_anonymity_level,
407 struct GNUNET_TIME_Absolute expiration, 397 struct GNUNET_TIME_Absolute expiration,
408 struct GNUNET_TIME_Absolute last_transmission, 398 struct GNUNET_TIME_Absolute last_transmission,
409 enum GNUNET_BLOCK_Type type, 399 enum GNUNET_BLOCK_Type type,
410 const void *data, 400 const void *data,
411 size_t data_len) 401 size_t data_len)
412{ 402{
413 struct ClientRequest *cr = cls; 403 struct ClientRequest *cr = cls;
414 struct GSF_LocalClient *lc; 404 struct GSF_LocalClient *lc;
@@ -417,52 +407,52 @@ client_response_handler (void *cls,
417 const struct GSF_PendingRequestData *prd; 407 const struct GSF_PendingRequestData *prd;
418 408
419 if (NULL == data) 409 if (NULL == data)
420 { 410 {
421 /* local-only request, with no result, clean up. */ 411 /* local-only request, with no result, clean up. */
422 if (NULL == cr->kill_task) 412 if (NULL == cr->kill_task)
423 cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, 413 cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy,
424 cr); 414 cr);
425 return; 415 return;
426 } 416 }
427 prd = GSF_pending_request_get_data_ (pr); 417 prd = GSF_pending_request_get_data_(pr);
428 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); 418 GNUNET_break(type != GNUNET_BLOCK_TYPE_ANY);
429 if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY)) 419 if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
430 { 420 {
431 GNUNET_break (0); 421 GNUNET_break(0);
432 return; 422 return;
433 } 423 }
434 GNUNET_STATISTICS_update (GSF_stats, 424 GNUNET_STATISTICS_update(GSF_stats,
435 gettext_noop 425 gettext_noop
436 ("# replies received for local clients"), 1, 426 ("# replies received for local clients"), 1,
437 GNUNET_NO); 427 GNUNET_NO);
438 GNUNET_assert (pr == cr->pr); 428 GNUNET_assert(pr == cr->pr);
439 lc = cr->lc; 429 lc = cr->lc;
440 env = GNUNET_MQ_msg_extra (pm, 430 env = GNUNET_MQ_msg_extra(pm,
441 data_len, 431 data_len,
442 GNUNET_MESSAGE_TYPE_FS_PUT); 432 GNUNET_MESSAGE_TYPE_FS_PUT);
443 pm->type = htonl (type); 433 pm->type = htonl(type);
444 pm->expiration = GNUNET_TIME_absolute_hton (expiration); 434 pm->expiration = GNUNET_TIME_absolute_hton(expiration);
445 pm->last_transmission = GNUNET_TIME_absolute_hton (last_transmission); 435 pm->last_transmission = GNUNET_TIME_absolute_hton(last_transmission);
446 pm->num_transmissions = htonl (prd->num_transmissions); 436 pm->num_transmissions = htonl(prd->num_transmissions);
447 pm->respect_offered = htonl (prd->respect_offered); 437 pm->respect_offered = htonl(prd->respect_offered);
448 GNUNET_memcpy (&pm[1], 438 GNUNET_memcpy(&pm[1],
449 data, 439 data,
450 data_len); 440 data_len);
451 GNUNET_MQ_send (lc->mq, 441 GNUNET_MQ_send(lc->mq,
452 env); 442 env);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 443 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
454 "Queued reply to query `%s' for local client\n", 444 "Queued reply to query `%s' for local client\n",
455 GNUNET_h2s (&prd->query)); 445 GNUNET_h2s(&prd->query));
456 if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval) 446 if (GNUNET_BLOCK_EVALUATION_OK_LAST != eval)
457 { 447 {
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 448 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
459 "Evaluation %d - keeping query alive\n", 449 "Evaluation %d - keeping query alive\n",
460 (int) eval); 450 (int)eval);
461 return; 451 return;
462 } 452 }
463 if (NULL == cr->kill_task) 453 if (NULL == cr->kill_task)
464 cr->kill_task = GNUNET_SCHEDULER_add_now (&client_request_destroy, 454 cr->kill_task = GNUNET_SCHEDULER_add_now(&client_request_destroy,
465 cr); 455 cr);
466} 456}
467 457
468 458
@@ -475,9 +465,9 @@ client_response_handler (void *cls,
475 * @param app_ctx the `struct GSF_LocalClient` 465 * @param app_ctx the `struct GSF_LocalClient`
476 */ 466 */
477static void 467static void
478client_disconnect_cb (void *cls, 468client_disconnect_cb(void *cls,
479 struct GNUNET_SERVICE_Client *client, 469 struct GNUNET_SERVICE_Client *client,
480 void *app_ctx) 470 void *app_ctx)
481{ 471{
482 struct GSF_LocalClient *lc = app_ctx; 472 struct GSF_LocalClient *lc = app_ctx;
483 struct IndexStartContext *isc; 473 struct IndexStartContext *isc;
@@ -485,27 +475,27 @@ client_disconnect_cb (void *cls,
485 struct ClientResponse *res; 475 struct ClientResponse *res;
486 476
487 while (NULL != (cr = lc->cr_head)) 477 while (NULL != (cr = lc->cr_head))
488 { 478 {
489 if (NULL != cr->kill_task) 479 if (NULL != cr->kill_task)
490 GNUNET_SCHEDULER_cancel (cr->kill_task); 480 GNUNET_SCHEDULER_cancel(cr->kill_task);
491 client_request_destroy (cr); 481 client_request_destroy(cr);
492 } 482 }
493 while (NULL != (res = lc->res_head)) 483 while (NULL != (res = lc->res_head))
494 { 484 {
495 GNUNET_CONTAINER_DLL_remove (lc->res_head, 485 GNUNET_CONTAINER_DLL_remove(lc->res_head,
496 lc->res_tail, 486 lc->res_tail,
497 res); 487 res);
498 GNUNET_free (res); 488 GNUNET_free(res);
499 } 489 }
500 while (NULL != (isc = lc->isc_head)) 490 while (NULL != (isc = lc->isc_head))
501 { 491 {
502 GNUNET_CONTAINER_DLL_remove (lc->isc_head, 492 GNUNET_CONTAINER_DLL_remove(lc->isc_head,
503 lc->isc_tail, 493 lc->isc_tail,
504 isc); 494 isc);
505 GNUNET_CRYPTO_hash_file_cancel (isc->fhc); 495 GNUNET_CRYPTO_hash_file_cancel(isc->fhc);
506 GNUNET_free (isc); 496 GNUNET_free(isc);
507 } 497 }
508 GNUNET_free (lc); 498 GNUNET_free(lc);
509} 499}
510 500
511 501
@@ -518,14 +508,14 @@ client_disconnect_cb (void *cls,
518 * @param cls unused closure 508 * @param cls unused closure
519 */ 509 */
520static void 510static void
521age_cover_counters (void *cls) 511age_cover_counters(void *cls)
522{ 512{
523 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16; 513 GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
524 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16; 514 GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
525 cover_age_task = 515 cover_age_task =
526 GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 516 GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY,
527 &age_cover_counters, 517 &age_cover_counters,
528 NULL); 518 NULL);
529} 519}
530 520
531 521
@@ -536,12 +526,12 @@ age_cover_counters (void *cls)
536 * @param start time when the datastore request was issued 526 * @param start time when the datastore request was issued
537 */ 527 */
538void 528void
539GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start) 529GSF_update_datastore_delay_(struct GNUNET_TIME_Absolute start)
540{ 530{
541 struct GNUNET_TIME_Relative delay; 531 struct GNUNET_TIME_Relative delay;
542 532
543 delay = GNUNET_TIME_absolute_get_duration (start); 533 delay = GNUNET_TIME_absolute_get_duration(start);
544 GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us); 534 GNUNET_LOAD_update(datastore_get_load, delay.rel_value_us);
545} 535}
546 536
547 537
@@ -556,11 +546,11 @@ GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start)
556 * #GNUNET_SYSERR to process for free (load low) 546 * #GNUNET_SYSERR to process for free (load low)
557 */ 547 */
558int 548int
559GSF_test_get_load_too_high_ (uint32_t priority) 549GSF_test_get_load_too_high_(uint32_t priority)
560{ 550{
561 double ld; 551 double ld;
562 552
563 ld = GNUNET_LOAD_get_load (datastore_get_load); 553 ld = GNUNET_LOAD_get_load(datastore_get_load);
564 if (ld < 1) 554 if (ld < 1)
565 return GNUNET_SYSERR; 555 return GNUNET_SYSERR;
566 if (ld <= priority) 556 if (ld <= priority)
@@ -581,30 +571,30 @@ GSF_test_get_load_too_high_ (uint32_t priority)
581 * @param prop performance data for the address (as far as known) 571 * @param prop performance data for the address (as far as known)
582 */ 572 */
583static void 573static void
584update_latencies (void *cls, 574update_latencies(void *cls,
585 const struct GNUNET_HELLO_Address *address, 575 const struct GNUNET_HELLO_Address *address,
586 int active, 576 int active,
587 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 577 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
588 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 578 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
589 const struct GNUNET_ATS_Properties *prop) 579 const struct GNUNET_ATS_Properties *prop)
590{ 580{
591 if (NULL == address) 581 if (NULL == address)
592 { 582 {
593 /* ATS service temporarily disconnected */ 583 /* ATS service temporarily disconnected */
594 return; 584 return;
595 } 585 }
596 586
597 if (GNUNET_YES != active) 587 if (GNUNET_YES != active)
598 return; 588 return;
599 GSF_update_peer_latency_ (&address->peer, 589 GSF_update_peer_latency_(&address->peer,
600 prop->delay); 590 prop->delay);
601 GSF_avg_latency.rel_value_us = 591 GSF_avg_latency.rel_value_us =
602 (GSF_avg_latency.rel_value_us * 31 + 592 (GSF_avg_latency.rel_value_us * 31 +
603 GNUNET_MIN (5000, prop->delay.rel_value_us)) / 32; 593 GNUNET_MIN(5000, prop->delay.rel_value_us)) / 32;
604 GNUNET_STATISTICS_set (GSF_stats, 594 GNUNET_STATISTICS_set(GSF_stats,
605 gettext_noop ("# running average P2P latency (ms)"), 595 gettext_noop("# running average P2P latency (ms)"),
606 GSF_avg_latency.rel_value_us / 1000LL, 596 GSF_avg_latency.rel_value_us / 1000LL,
607 GNUNET_NO); 597 GNUNET_NO);
608} 598}
609 599
610 600
@@ -617,17 +607,17 @@ update_latencies (void *cls,
617 * #GNUNET_SYSERR to close it (signal serious error) 607 * #GNUNET_SYSERR to close it (signal serious error)
618 */ 608 */
619static int 609static int
620check_p2p_put (void *cls, 610check_p2p_put(void *cls,
621 const struct PutMessage *put) 611 const struct PutMessage *put)
622{ 612{
623 enum GNUNET_BLOCK_Type type; 613 enum GNUNET_BLOCK_Type type;
624 614
625 type = ntohl (put->type); 615 type = ntohl(put->type);
626 if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) 616 if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type)
627 { 617 {
628 GNUNET_break_op (0); 618 GNUNET_break_op(0);
629 return GNUNET_SYSERR; 619 return GNUNET_SYSERR;
630 } 620 }
631 return GNUNET_OK; 621 return GNUNET_OK;
632} 622}
633 623
@@ -642,25 +632,25 @@ check_p2p_put (void *cls,
642 * @param ppd peer performance data 632 * @param ppd peer performance data
643 */ 633 */
644static void 634static void
645consider_request_for_forwarding (void *cls, 635consider_request_for_forwarding(void *cls,
646 const struct GNUNET_PeerIdentity *peer, 636 const struct GNUNET_PeerIdentity *peer,
647 struct GSF_ConnectedPeer *cp, 637 struct GSF_ConnectedPeer *cp,
648 const struct GSF_PeerPerformanceData *ppd) 638 const struct GSF_PeerPerformanceData *ppd)
649{ 639{
650 struct GSF_PendingRequest *pr = cls; 640 struct GSF_PendingRequest *pr = cls;
651 641
652 if (GNUNET_YES != 642 if (GNUNET_YES !=
653 GSF_pending_request_test_target_ (pr, peer)) 643 GSF_pending_request_test_target_(pr, peer))
654 { 644 {
655#if INSANE_STATISTICS 645#if INSANE_STATISTICS
656 GNUNET_STATISTICS_update (GSF_stats, 646 GNUNET_STATISTICS_update(GSF_stats,
657 gettext_noop ("# Loopback routes suppressed"), 1, 647 gettext_noop("# Loopback routes suppressed"), 1,
658 GNUNET_NO); 648 GNUNET_NO);
659#endif 649#endif
660 return; 650 return;
661 } 651 }
662 GSF_plan_add_ (cp, 652 GSF_plan_add_(cp,
663 pr); 653 pr);
664} 654}
665 655
666 656
@@ -675,17 +665,17 @@ consider_request_for_forwarding (void *cls,
675 * @param result final datastore lookup result 665 * @param result final datastore lookup result
676 */ 666 */
677void 667void
678GSF_consider_forwarding (void *cls, 668GSF_consider_forwarding(void *cls,
679 struct GSF_PendingRequest *pr, 669 struct GSF_PendingRequest *pr,
680 enum GNUNET_BLOCK_EvaluationResult result) 670 enum GNUNET_BLOCK_EvaluationResult result)
681{ 671{
682 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 672 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
683 return; /* we're done... */ 673 return; /* we're done... */
684 if (GNUNET_YES != 674 if (GNUNET_YES !=
685 GSF_pending_request_test_active_ (pr)) 675 GSF_pending_request_test_active_(pr))
686 return; /* request is not actually active, skip! */ 676 return; /* request is not actually active, skip! */
687 GSF_iterate_connected_peers_ (&consider_request_for_forwarding, 677 GSF_iterate_connected_peers_(&consider_request_for_forwarding,
688 pr); 678 pr);
689} 679}
690 680
691 681
@@ -698,35 +688,35 @@ GSF_consider_forwarding (void *cls,
698 * #GNUNET_SYSERR to close it (signal serious error) 688 * #GNUNET_SYSERR to close it (signal serious error)
699 */ 689 */
700static int 690static int
701check_p2p_get (void *cls, 691check_p2p_get(void *cls,
702 const struct GetMessage *gm) 692 const struct GetMessage *gm)
703{ 693{
704 size_t msize; 694 size_t msize;
705 unsigned int bm; 695 unsigned int bm;
706 unsigned int bits; 696 unsigned int bits;
707 size_t bfsize; 697 size_t bfsize;
708 698
709 msize = ntohs (gm->header.size); 699 msize = ntohs(gm->header.size);
710 bm = ntohl (gm->hash_bitmap); 700 bm = ntohl(gm->hash_bitmap);
711 bits = 0; 701 bits = 0;
712 while (bm > 0) 702 while (bm > 0)
713 { 703 {
714 if (1 == (bm & 1)) 704 if (1 == (bm & 1))
715 bits++; 705 bits++;
716 bm >>= 1; 706 bm >>= 1;
717 } 707 }
718 if (msize < sizeof (struct GetMessage) + bits * sizeof (struct GNUNET_PeerIdentity)) 708 if (msize < sizeof(struct GetMessage) + bits * sizeof(struct GNUNET_PeerIdentity))
719 { 709 {
720 GNUNET_break_op (0); 710 GNUNET_break_op(0);
721 return GNUNET_SYSERR; 711 return GNUNET_SYSERR;
722 } 712 }
723 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity); 713 bfsize = msize - sizeof(struct GetMessage) - bits * sizeof(struct GNUNET_PeerIdentity);
724 /* bfsize must be power of 2, check! */ 714 /* bfsize must be power of 2, check! */
725 if (0 != ((bfsize - 1) & bfsize)) 715 if (0 != ((bfsize - 1) & bfsize))
726 { 716 {
727 GNUNET_break_op (0); 717 GNUNET_break_op(0);
728 return GNUNET_SYSERR; 718 return GNUNET_SYSERR;
729 } 719 }
730 return GNUNET_OK; 720 return GNUNET_OK;
731} 721}
732 722
@@ -742,46 +732,48 @@ check_p2p_get (void *cls,
742 * @param result final datastore lookup result 732 * @param result final datastore lookup result
743 */ 733 */
744static void 734static void
745start_p2p_processing (void *cls, 735start_p2p_processing(void *cls,
746 struct GSF_PendingRequest *pr, 736 struct GSF_PendingRequest *pr,
747 enum GNUNET_BLOCK_EvaluationResult result) 737 enum GNUNET_BLOCK_EvaluationResult result)
748{ 738{
749 struct GSF_LocalClient *lc = cls; 739 struct GSF_LocalClient *lc = cls;
750 struct GSF_PendingRequestData *prd; 740 struct GSF_PendingRequestData *prd;
751 741
752 GNUNET_SERVICE_client_continue (lc->client); 742 GNUNET_SERVICE_client_continue(lc->client);
753 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result) 743 if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
754 return; /* we're done, 'pr' was already destroyed... */ 744 return; /* we're done, 'pr' was already destroyed... */
755 prd = GSF_pending_request_get_data_ (pr); 745 prd = GSF_pending_request_get_data_(pr);
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 746 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
757 "Finished database lookup for local request `%s' with result %d\n", 747 "Finished database lookup for local request `%s' with result %d\n",
758 GNUNET_h2s (&prd->query), 748 GNUNET_h2s(&prd->query),
759 result); 749 result);
760 if (0 == prd->anonymity_level) 750 if (0 == prd->anonymity_level)
761 {
762 switch (prd->type)
763 { 751 {
764 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 752 switch (prd->type)
765 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 753 {
766 /* the above block types MAY be available via 'cadet' */ 754 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 755 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
768 "Considering cadet-based download for block\n"); 756 /* the above block types MAY be available via 'cadet' */
769 GSF_cadet_lookup_ (pr); 757 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
770 break; 758 "Considering cadet-based download for block\n");
771 case GNUNET_BLOCK_TYPE_FS_UBLOCK: 759 GSF_cadet_lookup_(pr);
772 /* the above block types are in the DHT */ 760 break;
773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 761
774 "Considering DHT-based search for block\n"); 762 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
775 GSF_dht_lookup_ (pr); 763 /* the above block types are in the DHT */
776 break; 764 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
777 default: 765 "Considering DHT-based search for block\n");
778 GNUNET_break (0); 766 GSF_dht_lookup_(pr);
779 break; 767 break;
768
769 default:
770 GNUNET_break(0);
771 break;
772 }
780 } 773 }
781 } 774 GSF_consider_forwarding(NULL,
782 GSF_consider_forwarding (NULL, 775 pr,
783 pr, 776 result);
784 result);
785} 777}
786 778
787 779
@@ -794,17 +786,17 @@ start_p2p_processing (void *cls,
794 * @return #GNUNET_OK if @a sm is well-formed 786 * @return #GNUNET_OK if @a sm is well-formed
795 */ 787 */
796static int 788static int
797check_client_start_search (void *cls, 789check_client_start_search(void *cls,
798 const struct SearchMessage *sm) 790 const struct SearchMessage *sm)
799{ 791{
800 uint16_t msize; 792 uint16_t msize;
801 793
802 msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); 794 msize = ntohs(sm->header.size) - sizeof(struct SearchMessage);
803 if (0 != msize % sizeof (struct GNUNET_HashCode)) 795 if (0 != msize % sizeof(struct GNUNET_HashCode))
804 { 796 {
805 GNUNET_break (0); 797 GNUNET_break(0);
806 return GNUNET_SYSERR; 798 return GNUNET_SYSERR;
807 } 799 }
808 return GNUNET_OK; 800 return GNUNET_OK;
809} 801}
810 802
@@ -820,8 +812,8 @@ check_client_start_search (void *cls,
820 * @param sm the actual message 812 * @param sm the actual message
821 */ 813 */
822static void 814static void
823handle_client_start_search (void *cls, 815handle_client_start_search(void *cls,
824 const struct SearchMessage *sm) 816 const struct SearchMessage *sm)
825{ 817{
826 static struct GNUNET_PeerIdentity all_zeros; 818 static struct GNUNET_PeerIdentity all_zeros;
827 struct GSF_LocalClient *lc = cls; 819 struct GSF_LocalClient *lc = cls;
@@ -832,90 +824,90 @@ handle_client_start_search (void *cls,
832 enum GNUNET_BLOCK_Type type; 824 enum GNUNET_BLOCK_Type type;
833 enum GSF_PendingRequestOptions options; 825 enum GSF_PendingRequestOptions options;
834 826
835 GNUNET_STATISTICS_update (GSF_stats, 827 GNUNET_STATISTICS_update(GSF_stats,
836 gettext_noop ("# client searches received"), 828 gettext_noop("# client searches received"),
837 1, 829 1,
838 GNUNET_NO); 830 GNUNET_NO);
839 msize = ntohs (sm->header.size) - sizeof (struct SearchMessage); 831 msize = ntohs(sm->header.size) - sizeof(struct SearchMessage);
840 sc = msize / sizeof (struct GNUNET_HashCode); 832 sc = msize / sizeof(struct GNUNET_HashCode);
841 type = ntohl (sm->type); 833 type = ntohl(sm->type);
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 834 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
843 "Received request for `%s' of type %u from local client\n", 835 "Received request for `%s' of type %u from local client\n",
844 GNUNET_h2s (&sm->query), 836 GNUNET_h2s(&sm->query),
845 (unsigned int) type); 837 (unsigned int)type);
846 cr = NULL; 838 cr = NULL;
847 /* detect duplicate UBLOCK requests */ 839 /* detect duplicate UBLOCK requests */
848 if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) || 840 if ((type == GNUNET_BLOCK_TYPE_FS_UBLOCK) ||
849 (type == GNUNET_BLOCK_TYPE_ANY)) 841 (type == GNUNET_BLOCK_TYPE_ANY))
850 {
851 cr = lc->cr_head;
852 while (NULL != cr)
853 { 842 {
854 prd = GSF_pending_request_get_data_ (cr->pr); 843 cr = lc->cr_head;
855 /* only unify with queries that hae not yet started local processing 844 while (NULL != cr)
856 (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a 845 {
857 matching query and type */ 846 prd = GSF_pending_request_get_data_(cr->pr);
858 if ((GNUNET_YES != prd->has_started) && 847 /* only unify with queries that hae not yet started local processing
859 (0 != memcmp (&prd->query, 848 (SEARCH_MESSAGE_OPTION_CONTINUED was always set) and that have a
860 &sm->query, 849 matching query and type */
861 sizeof (struct GNUNET_HashCode))) && 850 if ((GNUNET_YES != prd->has_started) &&
862 (prd->type == type)) 851 (0 != memcmp(&prd->query,
863 break; 852 &sm->query,
864 cr = cr->next; 853 sizeof(struct GNUNET_HashCode))) &&
854 (prd->type == type))
855 break;
856 cr = cr->next;
857 }
865 } 858 }
866 }
867 if (NULL != cr) 859 if (NULL != cr)
868 { 860 {
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 861 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
870 "Have existing request, merging content-seen lists.\n"); 862 "Have existing request, merging content-seen lists.\n");
871 GSF_pending_request_update_ (cr->pr, 863 GSF_pending_request_update_(cr->pr,
872 (const struct GNUNET_HashCode *) &sm[1], 864 (const struct GNUNET_HashCode *)&sm[1],
873 sc); 865 sc);
874 GNUNET_STATISTICS_update (GSF_stats, 866 GNUNET_STATISTICS_update(GSF_stats,
875 gettext_noop ("# client searches updated (merged content seen list)"), 867 gettext_noop("# client searches updated (merged content seen list)"),
876 1, 868 1,
877 GNUNET_NO); 869 GNUNET_NO);
878 } 870 }
879 else 871 else
880 { 872 {
881 GNUNET_STATISTICS_update (GSF_stats, 873 GNUNET_STATISTICS_update(GSF_stats,
882 gettext_noop ("# client searches active"), 874 gettext_noop("# client searches active"),
883 1, 875 1,
884 GNUNET_NO); 876 GNUNET_NO);
885 cr = GNUNET_new (struct ClientRequest); 877 cr = GNUNET_new(struct ClientRequest);
886 cr->lc = lc; 878 cr->lc = lc;
887 GNUNET_CONTAINER_DLL_insert (lc->cr_head, 879 GNUNET_CONTAINER_DLL_insert(lc->cr_head,
888 lc->cr_tail, 880 lc->cr_tail,
889 cr); 881 cr);
890 options = GSF_PRO_LOCAL_REQUEST; 882 options = GSF_PRO_LOCAL_REQUEST;
891 if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl (sm->options))) 883 if (0 != (SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY & ntohl(sm->options)))
892 options |= GSF_PRO_LOCAL_ONLY; 884 options |= GSF_PRO_LOCAL_ONLY;
893 cr->pr = GSF_pending_request_create_ (options, type, 885 cr->pr = GSF_pending_request_create_(options, type,
894 &sm->query, 886 &sm->query,
895 (0 != 887 (0 !=
896 memcmp (&sm->target, 888 memcmp(&sm->target,
897 &all_zeros, 889 &all_zeros,
898 sizeof (struct GNUNET_PeerIdentity))) 890 sizeof(struct GNUNET_PeerIdentity)))
899 ? &sm->target : NULL, NULL, 0, 891 ? &sm->target : NULL, NULL, 0,
900 0 /* bf */ , 892 0 /* bf */,
901 ntohl (sm->anonymity_level), 893 ntohl(sm->anonymity_level),
902 0 /* priority */ , 894 0 /* priority */,
903 0 /* ttl */ , 895 0 /* ttl */,
904 0 /* sender PID */ , 896 0 /* sender PID */,
905 0 /* origin PID */ , 897 0 /* origin PID */,
906 (const struct GNUNET_HashCode *) &sm[1], sc, 898 (const struct GNUNET_HashCode *)&sm[1], sc,
907 &client_response_handler, 899 &client_response_handler,
908 cr); 900 cr);
909 } 901 }
910 if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl (sm->options))) 902 if (0 != (SEARCH_MESSAGE_OPTION_CONTINUED & ntohl(sm->options)))
911 { 903 {
912 GNUNET_SERVICE_client_continue (lc->client); 904 GNUNET_SERVICE_client_continue(lc->client);
913 return; 905 return;
914 } 906 }
915 GSF_pending_request_get_data_ (cr->pr)->has_started = GNUNET_YES; 907 GSF_pending_request_get_data_(cr->pr)->has_started = GNUNET_YES;
916 GSF_local_lookup_ (cr->pr, 908 GSF_local_lookup_(cr->pr,
917 &start_p2p_processing, 909 &start_p2p_processing,
918 lc); 910 lc);
919} 911}
920 912
921 913
@@ -926,8 +918,8 @@ handle_client_start_search (void *cls,
926 * @param msg the actual message 918 * @param msg the actual message
927 */ 919 */
928static void 920static void
929handle_client_loc_sign (void *cls, 921handle_client_loc_sign(void *cls,
930 const struct RequestLocSignatureMessage *msg) 922 const struct RequestLocSignatureMessage *msg)
931{ 923{
932 struct GSF_LocalClient *lc = cls; 924 struct GSF_LocalClient *lc = cls;
933 struct GNUNET_FS_Uri base; 925 struct GNUNET_FS_Uri base;
@@ -935,24 +927,24 @@ handle_client_loc_sign (void *cls,
935 struct GNUNET_MQ_Envelope *env; 927 struct GNUNET_MQ_Envelope *env;
936 struct ResponseLocSignatureMessage *resp; 928 struct ResponseLocSignatureMessage *resp;
937 929
938 GNUNET_break (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT == 930 GNUNET_break(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT ==
939 ntohl (msg->purpose)); 931 ntohl(msg->purpose));
940 base.type = GNUNET_FS_URI_CHK; 932 base.type = GNUNET_FS_URI_CHK;
941 base.data.chk.chk = msg->chk; 933 base.data.chk.chk = msg->chk;
942 base.data.chk.file_length = GNUNET_ntohll (msg->file_length); 934 base.data.chk.file_length = GNUNET_ntohll(msg->file_length);
943 loc = GNUNET_FS_uri_loc_create (&base, 935 loc = GNUNET_FS_uri_loc_create(&base,
944 pk, 936 pk,
945 GNUNET_TIME_absolute_ntoh (msg->expiration_time)); 937 GNUNET_TIME_absolute_ntoh(msg->expiration_time));
946 env = GNUNET_MQ_msg (resp, 938 env = GNUNET_MQ_msg(resp,
947 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE); 939 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE);
948 resp->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 940 resp->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
949 resp->expiration_time = GNUNET_TIME_absolute_hton (loc->data.loc.expirationTime); 941 resp->expiration_time = GNUNET_TIME_absolute_hton(loc->data.loc.expirationTime);
950 resp->signature = loc->data.loc.contentSignature; 942 resp->signature = loc->data.loc.contentSignature;
951 resp->peer = loc->data.loc.peer; 943 resp->peer = loc->data.loc.peer;
952 GNUNET_FS_uri_destroy (loc); 944 GNUNET_FS_uri_destroy(loc);
953 GNUNET_MQ_send (lc->mq, 945 GNUNET_MQ_send(lc->mq,
954 env); 946 env);
955 GNUNET_SERVICE_client_continue (lc->client); 947 GNUNET_SERVICE_client_continue(lc->client);
956} 948}
957 949
958 950
@@ -964,24 +956,24 @@ handle_client_loc_sign (void *cls,
964 * @return #GNUNET_OK if @a ism is well-formed 956 * @return #GNUNET_OK if @a ism is well-formed
965 */ 957 */
966static int 958static int
967check_client_index_start (void *cls, 959check_client_index_start(void *cls,
968 const struct IndexStartMessage *ism) 960 const struct IndexStartMessage *ism)
969{ 961{
970 char *fn; 962 char *fn;
971 963
972 GNUNET_MQ_check_zero_termination (ism); 964 GNUNET_MQ_check_zero_termination(ism);
973 if (0 != ism->reserved) 965 if (0 != ism->reserved)
974 { 966 {
975 GNUNET_break (0); 967 GNUNET_break(0);
976 return GNUNET_SYSERR; 968 return GNUNET_SYSERR;
977 } 969 }
978 fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); 970 fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]);
979 if (NULL == fn) 971 if (NULL == fn)
980 { 972 {
981 GNUNET_break (0); 973 GNUNET_break(0);
982 return GNUNET_SYSERR; 974 return GNUNET_SYSERR;
983 } 975 }
984 GNUNET_free (fn); 976 GNUNET_free(fn);
985 return GNUNET_OK; 977 return GNUNET_OK;
986} 978}
987 979
@@ -993,21 +985,21 @@ check_client_index_start (void *cls,
993 * @param isc the data about the index info entry for the request 985 * @param isc the data about the index info entry for the request
994 */ 986 */
995static void 987static void
996signal_index_ok (struct IndexStartContext *isc) 988signal_index_ok(struct IndexStartContext *isc)
997{ 989{
998 struct GSF_LocalClient *lc = isc->lc; 990 struct GSF_LocalClient *lc = isc->lc;
999 struct GNUNET_MQ_Envelope *env; 991 struct GNUNET_MQ_Envelope *env;
1000 struct GNUNET_MessageHeader *msg; 992 struct GNUNET_MessageHeader *msg;
1001 993
1002 GNUNET_FS_add_to_index (isc->filename, 994 GNUNET_FS_add_to_index(isc->filename,
1003 &isc->file_id); 995 &isc->file_id);
1004 env = GNUNET_MQ_msg (msg, 996 env = GNUNET_MQ_msg(msg,
1005 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); 997 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
1006 GNUNET_MQ_send (lc->mq, 998 GNUNET_MQ_send(lc->mq,
1007 env); 999 env);
1008 GNUNET_free (isc->filename); 1000 GNUNET_free(isc->filename);
1009 GNUNET_free (isc); 1001 GNUNET_free(isc);
1010 GNUNET_SERVICE_client_continue (lc->client); 1002 GNUNET_SERVICE_client_continue(lc->client);
1011} 1003}
1012 1004
1013 1005
@@ -1019,36 +1011,36 @@ signal_index_ok (struct IndexStartContext *isc)
1019 * @param res resulting hash, NULL on error 1011 * @param res resulting hash, NULL on error
1020 */ 1012 */
1021static void 1013static void
1022hash_for_index_val (void *cls, 1014hash_for_index_val(void *cls,
1023 const struct GNUNET_HashCode *res) 1015 const struct GNUNET_HashCode *res)
1024{ 1016{
1025 struct IndexStartContext *isc = cls; 1017 struct IndexStartContext *isc = cls;
1026 struct GSF_LocalClient *lc = isc->lc; 1018 struct GSF_LocalClient *lc = isc->lc;
1027 struct GNUNET_MQ_Envelope *env; 1019 struct GNUNET_MQ_Envelope *env;
1028 struct GNUNET_MessageHeader *msg; 1020 struct GNUNET_MessageHeader *msg;
1029 1021
1030 GNUNET_CONTAINER_DLL_remove (lc->isc_head, 1022 GNUNET_CONTAINER_DLL_remove(lc->isc_head,
1031 lc->isc_tail, 1023 lc->isc_tail,
1032 isc); 1024 isc);
1033 isc->fhc = NULL; 1025 isc->fhc = NULL;
1034 if ( (NULL == res) || 1026 if ((NULL == res) ||
1035 (0 != memcmp (res, 1027 (0 != memcmp(res,
1036 &isc->file_id, 1028 &isc->file_id,
1037 sizeof (struct GNUNET_HashCode)))) 1029 sizeof(struct GNUNET_HashCode))))
1038 { 1030 {
1039 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1031 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1040 _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"), 1032 _("Hash mismatch trying to index file `%s' which does not have hash `%s'\n"),
1041 isc->filename, 1033 isc->filename,
1042 GNUNET_h2s (&isc->file_id)); 1034 GNUNET_h2s(&isc->file_id));
1043 env = GNUNET_MQ_msg (msg, 1035 env = GNUNET_MQ_msg(msg,
1044 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); 1036 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
1045 GNUNET_MQ_send (lc->mq, 1037 GNUNET_MQ_send(lc->mq,
1046 env); 1038 env);
1047 GNUNET_SERVICE_client_continue (lc->client); 1039 GNUNET_SERVICE_client_continue(lc->client);
1048 GNUNET_free (isc); 1040 GNUNET_free(isc);
1049 return; 1041 return;
1050 } 1042 }
1051 signal_index_ok (isc); 1043 signal_index_ok(isc);
1052} 1044}
1053 1045
1054 1046
@@ -1059,8 +1051,8 @@ hash_for_index_val (void *cls,
1059 * @param message the actual message 1051 * @param message the actual message
1060 */ 1052 */
1061static void 1053static void
1062handle_client_index_start (void *cls, 1054handle_client_index_start(void *cls,
1063 const struct IndexStartMessage *ism) 1055 const struct IndexStartMessage *ism)
1064{ 1056{
1065 struct GSF_LocalClient *lc = cls; 1057 struct GSF_LocalClient *lc = cls;
1066 struct IndexStartContext *isc; 1058 struct IndexStartContext *isc;
@@ -1070,49 +1062,49 @@ handle_client_index_start (void *cls,
1070 uint64_t mydev; 1062 uint64_t mydev;
1071 uint64_t myino; 1063 uint64_t myino;
1072 1064
1073 fn = GNUNET_STRINGS_filename_expand ((const char *) &ism[1]); 1065 fn = GNUNET_STRINGS_filename_expand((const char *)&ism[1]);
1074 GNUNET_assert (NULL != fn); 1066 GNUNET_assert(NULL != fn);
1075 dev = GNUNET_ntohll (ism->device); 1067 dev = GNUNET_ntohll(ism->device);
1076 ino = GNUNET_ntohll (ism->inode); 1068 ino = GNUNET_ntohll(ism->inode);
1077 isc = GNUNET_new (struct IndexStartContext); 1069 isc = GNUNET_new(struct IndexStartContext);
1078 isc->filename = fn; 1070 isc->filename = fn;
1079 isc->file_id = ism->file_id; 1071 isc->file_id = ism->file_id;
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1072 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1081 "Received START_INDEX message for file `%s'\n", 1073 "Received START_INDEX message for file `%s'\n",
1082 isc->filename); 1074 isc->filename);
1083 isc->lc = lc; 1075 isc->lc = lc;
1084 mydev = 0; 1076 mydev = 0;
1085 myino = 0; 1077 myino = 0;
1086 if ( ( (dev != 0) || 1078 if (((dev != 0) ||
1087 (ino != 0) ) && 1079 (ino != 0)) &&
1088 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn, 1080 (GNUNET_OK == GNUNET_DISK_file_get_identifiers(fn,
1089 &mydev, 1081 &mydev,
1090 &myino)) && 1082 &myino)) &&
1091 (dev == mydev) && 1083 (dev == mydev) &&
1092 (ino == myino) ) 1084 (ino == myino))
1093 { 1085 {
1094 /* fast validation OK! */ 1086 /* fast validation OK! */
1095 signal_index_ok (isc); 1087 signal_index_ok(isc);
1096 return; 1088 return;
1097 } 1089 }
1098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1090 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1099 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n", 1091 "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
1100 (unsigned long long) ino, 1092 (unsigned long long)ino,
1101 (unsigned long long) myino, 1093 (unsigned long long)myino,
1102 (unsigned int) dev, 1094 (unsigned int)dev,
1103 (unsigned int) mydev); 1095 (unsigned int)mydev);
1104 /* slow validation, need to hash full file (again) */ 1096 /* slow validation, need to hash full file (again) */
1105 GNUNET_CONTAINER_DLL_insert (lc->isc_head, 1097 GNUNET_CONTAINER_DLL_insert(lc->isc_head,
1106 lc->isc_tail, 1098 lc->isc_tail,
1107 isc); 1099 isc);
1108 isc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, 1100 isc->fhc = GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE,
1109 isc->filename, 1101 isc->filename,
1110 HASHING_BLOCKSIZE, 1102 HASHING_BLOCKSIZE,
1111 &hash_for_index_val, 1103 &hash_for_index_val,
1112 isc); 1104 isc);
1113 if (NULL == isc->fhc) 1105 if (NULL == isc->fhc)
1114 hash_for_index_val (isc, 1106 hash_for_index_val(isc,
1115 NULL); 1107 NULL);
1116} 1108}
1117 1109
1118 1110
@@ -1123,13 +1115,13 @@ handle_client_index_start (void *cls,
1123 * @param message the actual message 1115 * @param message the actual message
1124 */ 1116 */
1125static void 1117static void
1126handle_client_index_list_get (void *cls, 1118handle_client_index_list_get(void *cls,
1127 const struct GNUNET_MessageHeader *message) 1119 const struct GNUNET_MessageHeader *message)
1128{ 1120{
1129 struct GSF_LocalClient *lc = cls; 1121 struct GSF_LocalClient *lc = cls;
1130 1122
1131 GNUNET_FS_indexing_send_list (lc->mq); 1123 GNUNET_FS_indexing_send_list(lc->mq);
1132 GNUNET_SERVICE_client_continue (lc->client); 1124 GNUNET_SERVICE_client_continue(lc->client);
1133} 1125}
1134 1126
1135 1127
@@ -1140,25 +1132,25 @@ handle_client_index_list_get (void *cls,
1140 * @param message the actual message 1132 * @param message the actual message
1141 */ 1133 */
1142static void 1134static void
1143handle_client_unindex (void *cls, 1135handle_client_unindex(void *cls,
1144 const struct UnindexMessage *um) 1136 const struct UnindexMessage *um)
1145{ 1137{
1146 struct GSF_LocalClient *lc = cls; 1138 struct GSF_LocalClient *lc = cls;
1147 struct GNUNET_MQ_Envelope *env; 1139 struct GNUNET_MQ_Envelope *env;
1148 struct GNUNET_MessageHeader *msg; 1140 struct GNUNET_MessageHeader *msg;
1149 int found; 1141 int found;
1150 1142
1151 GNUNET_break (0 == um->reserved); 1143 GNUNET_break(0 == um->reserved);
1152 found = GNUNET_FS_indexing_do_unindex (&um->file_id); 1144 found = GNUNET_FS_indexing_do_unindex(&um->file_id);
1153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1154 "Client requested unindexing of file `%s': %s\n", 1146 "Client requested unindexing of file `%s': %s\n",
1155 GNUNET_h2s (&um->file_id), 1147 GNUNET_h2s(&um->file_id),
1156 found ? "found" : "not found"); 1148 found ? "found" : "not found");
1157 env = GNUNET_MQ_msg (msg, 1149 env = GNUNET_MQ_msg(msg,
1158 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); 1150 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
1159 GNUNET_MQ_send (lc->mq, 1151 GNUNET_MQ_send(lc->mq,
1160 env); 1152 env);
1161 GNUNET_SERVICE_client_continue (lc->client); 1153 GNUNET_SERVICE_client_continue(lc->client);
1162} 1154}
1163 1155
1164 1156
@@ -1168,44 +1160,44 @@ handle_client_unindex (void *cls,
1168 * @param cls unused 1160 * @param cls unused
1169 */ 1161 */
1170static void 1162static void
1171shutdown_task (void *cls) 1163shutdown_task(void *cls)
1172{ 1164{
1173 GSF_cadet_stop_server (); 1165 GSF_cadet_stop_server();
1174 if (NULL != GSF_core) 1166 if (NULL != GSF_core)
1175 { 1167 {
1176 GNUNET_CORE_disconnect (GSF_core); 1168 GNUNET_CORE_disconnect(GSF_core);
1177 GSF_core = NULL; 1169 GSF_core = NULL;
1178 } 1170 }
1179 if (NULL != GSF_ats) 1171 if (NULL != GSF_ats)
1180 { 1172 {
1181 GNUNET_ATS_performance_done (GSF_ats); 1173 GNUNET_ATS_performance_done(GSF_ats);
1182 GSF_ats = NULL; 1174 GSF_ats = NULL;
1183 } 1175 }
1184 GSF_put_done_ (); 1176 GSF_put_done_();
1185 GSF_push_done_ (); 1177 GSF_push_done_();
1186 GSF_pending_request_done_ (); 1178 GSF_pending_request_done_();
1187 GSF_plan_done (); 1179 GSF_plan_done();
1188 GSF_connected_peer_done_ (); 1180 GSF_connected_peer_done_();
1189 GNUNET_DATASTORE_disconnect (GSF_dsh, 1181 GNUNET_DATASTORE_disconnect(GSF_dsh,
1190 GNUNET_NO); 1182 GNUNET_NO);
1191 GSF_dsh = NULL; 1183 GSF_dsh = NULL;
1192 GNUNET_DHT_disconnect (GSF_dht); 1184 GNUNET_DHT_disconnect(GSF_dht);
1193 GSF_dht = NULL; 1185 GSF_dht = NULL;
1194 GNUNET_BLOCK_context_destroy (GSF_block_ctx); 1186 GNUNET_BLOCK_context_destroy(GSF_block_ctx);
1195 GSF_block_ctx = NULL; 1187 GSF_block_ctx = NULL;
1196 GNUNET_CONFIGURATION_destroy (block_cfg); 1188 GNUNET_CONFIGURATION_destroy(block_cfg);
1197 block_cfg = NULL; 1189 block_cfg = NULL;
1198 GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO); 1190 GNUNET_STATISTICS_destroy(GSF_stats, GNUNET_NO);
1199 GSF_stats = NULL; 1191 GSF_stats = NULL;
1200 if (NULL != cover_age_task) 1192 if (NULL != cover_age_task)
1201 { 1193 {
1202 GNUNET_SCHEDULER_cancel (cover_age_task); 1194 GNUNET_SCHEDULER_cancel(cover_age_task);
1203 cover_age_task = NULL; 1195 cover_age_task = NULL;
1204 } 1196 }
1205 GNUNET_FS_indexing_done (); 1197 GNUNET_FS_indexing_done();
1206 GNUNET_LOAD_value_free (datastore_get_load); 1198 GNUNET_LOAD_value_free(datastore_get_load);
1207 datastore_get_load = NULL; 1199 datastore_get_load = NULL;
1208 GNUNET_LOAD_value_free (GSF_rt_entry_lifetime); 1200 GNUNET_LOAD_value_free(GSF_rt_entry_lifetime);
1209 GSF_rt_entry_lifetime = NULL; 1201 GSF_rt_entry_lifetime = NULL;
1210} 1202}
1211 1203
@@ -1221,16 +1213,16 @@ shutdown_task (void *cls)
1221 * @param my_identity ID of this peer, NULL if we failed 1213 * @param my_identity ID of this peer, NULL if we failed
1222 */ 1214 */
1223static void 1215static void
1224peer_init_handler (void *cls, 1216peer_init_handler(void *cls,
1225 const struct GNUNET_PeerIdentity *my_identity) 1217 const struct GNUNET_PeerIdentity *my_identity)
1226{ 1218{
1227 if (0 != GNUNET_memcmp (&GSF_my_id, 1219 if (0 != GNUNET_memcmp(&GSF_my_id,
1228 my_identity)) 1220 my_identity))
1229 { 1221 {
1230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1222 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1231 "Peer identity mismatch, refusing to start!\n"); 1223 "Peer identity mismatch, refusing to start!\n");
1232 GNUNET_SCHEDULER_shutdown (); 1224 GNUNET_SCHEDULER_shutdown();
1233 } 1225 }
1234} 1226}
1235 1227
1236 1228
@@ -1240,25 +1232,25 @@ peer_init_handler (void *cls,
1240 * @param c configuration to use 1232 * @param c configuration to use
1241 */ 1233 */
1242static int 1234static int
1243main_init (const struct GNUNET_CONFIGURATION_Handle *c) 1235main_init(const struct GNUNET_CONFIGURATION_Handle *c)
1244{ 1236{
1245 struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = { 1237 struct GNUNET_MQ_MessageHandler no_p2p_handlers[] = {
1246 GNUNET_MQ_handler_end () 1238 GNUNET_MQ_handler_end()
1247 }; 1239 };
1248 struct GNUNET_MQ_MessageHandler p2p_handlers[] = { 1240 struct GNUNET_MQ_MessageHandler p2p_handlers[] = {
1249 GNUNET_MQ_hd_var_size (p2p_get, 1241 GNUNET_MQ_hd_var_size(p2p_get,
1250 GNUNET_MESSAGE_TYPE_FS_GET, 1242 GNUNET_MESSAGE_TYPE_FS_GET,
1251 struct GetMessage, 1243 struct GetMessage,
1252 NULL), 1244 NULL),
1253 GNUNET_MQ_hd_var_size (p2p_put, 1245 GNUNET_MQ_hd_var_size(p2p_put,
1254 GNUNET_MESSAGE_TYPE_FS_PUT, 1246 GNUNET_MESSAGE_TYPE_FS_PUT,
1255 struct PutMessage, 1247 struct PutMessage,
1256 NULL), 1248 NULL),
1257 GNUNET_MQ_hd_fixed_size (p2p_migration_stop, 1249 GNUNET_MQ_hd_fixed_size(p2p_migration_stop,
1258 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, 1250 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
1259 struct MigrationStopMessage, 1251 struct MigrationStopMessage,
1260 NULL), 1252 NULL),
1261 GNUNET_MQ_handler_end () 1253 GNUNET_MQ_handler_end()
1262 }; 1254 };
1263 int anon_p2p_off; 1255 int anon_p2p_off;
1264 char *keyfile; 1256 char *keyfile;
@@ -1266,54 +1258,54 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c)
1266 /* this option is really only for testcases that need to disable 1258 /* this option is really only for testcases that need to disable
1267 _anonymous_ file-sharing for some reason */ 1259 _anonymous_ file-sharing for some reason */
1268 anon_p2p_off = (GNUNET_YES == 1260 anon_p2p_off = (GNUNET_YES ==
1269 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, 1261 GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg,
1270 "fs", 1262 "fs",
1271 "DISABLE_ANON_TRANSFER")); 1263 "DISABLE_ANON_TRANSFER"));
1272 1264
1273 if (GNUNET_OK != 1265 if (GNUNET_OK !=
1274 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, 1266 GNUNET_CONFIGURATION_get_value_filename(GSF_cfg,
1275 "PEER", 1267 "PEER",
1276 "PRIVATE_KEY", 1268 "PRIVATE_KEY",
1277 &keyfile)) 1269 &keyfile))
1278 { 1270 {
1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1271 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1280 _("FS service is lacking HOSTKEY configuration setting. Exiting.\n")); 1272 _("FS service is lacking HOSTKEY configuration setting. Exiting.\n"));
1281 GNUNET_SCHEDULER_shutdown (); 1273 GNUNET_SCHEDULER_shutdown();
1282 return GNUNET_SYSERR; 1274 return GNUNET_SYSERR;
1283 } 1275 }
1284 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 1276 pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile);
1285 GNUNET_free (keyfile); 1277 GNUNET_free(keyfile);
1286 GNUNET_assert (NULL != pk); 1278 GNUNET_assert(NULL != pk);
1287 GNUNET_CRYPTO_eddsa_key_get_public (pk, 1279 GNUNET_CRYPTO_eddsa_key_get_public(pk,
1288 &GSF_my_id.public_key); 1280 &GSF_my_id.public_key);
1289 1281
1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1282 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1291 "I am peer %s\n", 1283 "I am peer %s\n",
1292 GNUNET_i2s (&GSF_my_id)); 1284 GNUNET_i2s(&GSF_my_id));
1293 GSF_core 1285 GSF_core
1294 = GNUNET_CORE_connect (GSF_cfg, 1286 = GNUNET_CORE_connect(GSF_cfg,
1295 NULL, 1287 NULL,
1296 &peer_init_handler, 1288 &peer_init_handler,
1297 &GSF_peer_connect_handler, 1289 &GSF_peer_connect_handler,
1298 &GSF_peer_disconnect_handler, 1290 &GSF_peer_disconnect_handler,
1299 (GNUNET_YES == anon_p2p_off) 1291 (GNUNET_YES == anon_p2p_off)
1300 ? no_p2p_handlers 1292 ? no_p2p_handlers
1301 : p2p_handlers); 1293 : p2p_handlers);
1302 if (NULL == GSF_core) 1294 if (NULL == GSF_core)
1303 { 1295 {
1304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1296 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1305 _("Failed to connect to `%s' service.\n"), 1297 _("Failed to connect to `%s' service.\n"),
1306 "core"); 1298 "core");
1307 return GNUNET_SYSERR; 1299 return GNUNET_SYSERR;
1308 } 1300 }
1309 cover_age_task = 1301 cover_age_task =
1310 GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, 1302 GNUNET_SCHEDULER_add_delayed(COVER_AGE_FREQUENCY,
1311 &age_cover_counters, 1303 &age_cover_counters,
1312 NULL); 1304 NULL);
1313 datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); 1305 datastore_get_load = GNUNET_LOAD_value_init(DATASTORE_LOAD_AUTODECLINE);
1314 GSF_cadet_start_server (); 1306 GSF_cadet_start_server();
1315 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1307 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
1316 NULL); 1308 NULL);
1317 return GNUNET_OK; 1309 return GNUNET_OK;
1318} 1310}
1319 1311
@@ -1326,55 +1318,55 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c)
1326 * @param service the initialized service 1318 * @param service the initialized service
1327 */ 1319 */
1328static void 1320static void
1329run (void *cls, 1321run(void *cls,
1330 const struct GNUNET_CONFIGURATION_Handle *cfg, 1322 const struct GNUNET_CONFIGURATION_Handle *cfg,
1331 struct GNUNET_SERVICE_Handle *service) 1323 struct GNUNET_SERVICE_Handle *service)
1332{ 1324{
1333 unsigned long long dqs; 1325 unsigned long long dqs;
1334 1326
1335 GSF_cfg = cfg; 1327 GSF_cfg = cfg;
1336 if (GNUNET_OK != 1328 if (GNUNET_OK !=
1337 GNUNET_CONFIGURATION_get_value_size (GSF_cfg, 1329 GNUNET_CONFIGURATION_get_value_size(GSF_cfg,
1338 "fs", 1330 "fs",
1339 "DATASTORE_QUEUE_SIZE", 1331 "DATASTORE_QUEUE_SIZE",
1340 &dqs)) 1332 &dqs))
1341 { 1333 {
1342 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO, 1334 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_INFO,
1343 "fs", 1335 "fs",
1344 "DATASTORE_QUEUE_SIZE"); 1336 "DATASTORE_QUEUE_SIZE");
1345 dqs = 32; 1337 dqs = 32;
1346 } 1338 }
1347 GSF_datastore_queue_size = (unsigned int) dqs; 1339 GSF_datastore_queue_size = (unsigned int)dqs;
1348 GSF_enable_randomized_delays = 1340 GSF_enable_randomized_delays =
1349 GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY"); 1341 GNUNET_CONFIGURATION_get_value_yesno(cfg, "fs", "DELAY");
1350 GSF_dsh = GNUNET_DATASTORE_connect (cfg); 1342 GSF_dsh = GNUNET_DATASTORE_connect(cfg);
1351 if (NULL == GSF_dsh) 1343 if (NULL == GSF_dsh)
1352 { 1344 {
1353 GNUNET_SCHEDULER_shutdown (); 1345 GNUNET_SCHEDULER_shutdown();
1354 return; 1346 return;
1355 } 1347 }
1356 GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL); 1348 GSF_rt_entry_lifetime = GNUNET_LOAD_value_init(GNUNET_TIME_UNIT_FOREVER_REL);
1357 GSF_stats = GNUNET_STATISTICS_create ("fs", cfg); 1349 GSF_stats = GNUNET_STATISTICS_create("fs", cfg);
1358 block_cfg = GNUNET_CONFIGURATION_create (); 1350 block_cfg = GNUNET_CONFIGURATION_create();
1359 GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg); 1351 GSF_block_ctx = GNUNET_BLOCK_context_create(block_cfg);
1360 GNUNET_assert (NULL != GSF_block_ctx); 1352 GNUNET_assert(NULL != GSF_block_ctx);
1361 GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE); 1353 GSF_dht = GNUNET_DHT_connect(cfg, FS_DHT_HT_SIZE);
1362 GSF_plan_init (); 1354 GSF_plan_init();
1363 GSF_pending_request_init_ (); 1355 GSF_pending_request_init_();
1364 GSF_connected_peer_init_ (); 1356 GSF_connected_peer_init_();
1365 GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, 1357 GSF_ats = GNUNET_ATS_performance_init(GSF_cfg,
1366 &update_latencies, 1358 &update_latencies,
1367 NULL); 1359 NULL);
1368 GSF_push_init_ (); 1360 GSF_push_init_();
1369 GSF_put_init_ (); 1361 GSF_put_init_();
1370 if ( (GNUNET_OK != GNUNET_FS_indexing_init (cfg, 1362 if ((GNUNET_OK != GNUNET_FS_indexing_init(cfg,
1371 GSF_dsh)) || 1363 GSF_dsh)) ||
1372 (GNUNET_OK != main_init (cfg)) ) 1364 (GNUNET_OK != main_init(cfg)))
1373 { 1365 {
1374 GNUNET_SCHEDULER_shutdown (); 1366 GNUNET_SCHEDULER_shutdown();
1375 shutdown_task (NULL); 1367 shutdown_task(NULL);
1376 return; 1368 return;
1377 } 1369 }
1378} 1370}
1379 1371
1380 1372
@@ -1382,33 +1374,33 @@ run (void *cls,
1382 * Define "main" method using service macro. 1374 * Define "main" method using service macro.
1383 */ 1375 */
1384GNUNET_SERVICE_MAIN 1376GNUNET_SERVICE_MAIN
1385("fs", 1377 ("fs",
1386 GNUNET_SERVICE_OPTION_NONE, 1378 GNUNET_SERVICE_OPTION_NONE,
1387 &run, 1379 &run,
1388 &client_connect_cb, 1380 &client_connect_cb,
1389 &client_disconnect_cb, 1381 &client_disconnect_cb,
1390 NULL, 1382 NULL,
1391 GNUNET_MQ_hd_var_size (client_index_start, 1383 GNUNET_MQ_hd_var_size(client_index_start,
1392 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 1384 GNUNET_MESSAGE_TYPE_FS_INDEX_START,
1393 struct IndexStartMessage, 1385 struct IndexStartMessage,
1394 NULL), 1386 NULL),
1395 GNUNET_MQ_hd_fixed_size (client_index_list_get, 1387 GNUNET_MQ_hd_fixed_size(client_index_list_get,
1396 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, 1388 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
1397 struct GNUNET_MessageHeader, 1389 struct GNUNET_MessageHeader,
1398 NULL), 1390 NULL),
1399 GNUNET_MQ_hd_fixed_size (client_unindex, 1391 GNUNET_MQ_hd_fixed_size(client_unindex,
1400 GNUNET_MESSAGE_TYPE_FS_UNINDEX, 1392 GNUNET_MESSAGE_TYPE_FS_UNINDEX,
1401 struct UnindexMessage, 1393 struct UnindexMessage,
1402 NULL), 1394 NULL),
1403 GNUNET_MQ_hd_var_size (client_start_search, 1395 GNUNET_MQ_hd_var_size(client_start_search,
1404 GNUNET_MESSAGE_TYPE_FS_START_SEARCH, 1396 GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
1405 struct SearchMessage, 1397 struct SearchMessage,
1406 NULL), 1398 NULL),
1407 GNUNET_MQ_hd_fixed_size (client_loc_sign, 1399 GNUNET_MQ_hd_fixed_size(client_loc_sign,
1408 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN, 1400 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN,
1409 struct RequestLocSignatureMessage, 1401 struct RequestLocSignatureMessage,
1410 NULL), 1402 NULL),
1411 GNUNET_MQ_handler_end ()); 1403 GNUNET_MQ_handler_end());
1412 1404
1413 1405
1414/* end of gnunet-service-fs.c */ 1406/* end of gnunet-service-fs.c */