aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-02-15 14:01:44 +0000
committerChristian Grothoff <christian@grothoff.org>2011-02-15 14:01:44 +0000
commit0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49 (patch)
tree6a08051f08ff896ed9d61e80c8b74a1d282f8539 /src/fs
parente3d12cb6fa5ddfb181dcade2e06888619f384457 (diff)
downloadgnunet-0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49.tar.gz
gnunet-0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49.zip
stuff
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/gnunet-service-fs_cp.c136
-rw-r--r--src/fs/gnunet-service-fs_lc.c15
-rw-r--r--src/fs/gnunet-service-fs_pr.c33
-rw-r--r--src/fs/gnunet-service-fs_pr.h8
4 files changed, 108 insertions, 84 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index f9a642199..d88598be7 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -32,6 +32,11 @@
32 */ 32 */
33#define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 33#define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
34 34
35/**
36 * After how long do we discard a reply?
37 */
38#define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
39
35 40
36/** 41/**
37 * Handle to cancel a transmission request. 42 * Handle to cancel a transmission request.
@@ -445,6 +450,43 @@ GSF_handle_p2p_migration_stop_ (void *cls,
445 450
446 451
447/** 452/**
453 * Copy reply and free put message.
454 *
455 * @param cls the 'struct PutMessage'
456 * @param buf_size number of bytes available in buf
457 * @param buf where to copy the message, NULL on error (peer disconnect)
458 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
459 */
460static size_t
461copy_reply (void *cls,
462 size_t buf_size,
463 void *buf)
464{
465 struct PutMessage *pm = cls;
466
467 if (buf != NULL)
468 {
469 GNUNET_assert (size >= ntohs (pm->header.size));
470 size = ntohs (pm->header.size);
471 memcpy (buf, pm, size);
472 GNUNET_STATISTICS_update (stats,
473 gettext_noop ("# replies transmitted to other peers"),
474 1,
475 GNUNET_NO);
476 }
477 else
478 {
479 GNUNET_STATISTICS_update (stats,
480 gettext_noop ("# replies dropped"),
481 1,
482 GNUNET_NO);
483 }
484 GNUNET_free (pm);
485 return size;
486}
487
488
489/**
448 * Handle a reply to a pending request. Also called if a request 490 * Handle a reply to a pending request. Also called if a request
449 * expires (then with data == NULL). The handler may be called 491 * expires (then with data == NULL). The handler may be called
450 * many times (depending on the request type), but will not be 492 * many times (depending on the request type), but will not be
@@ -455,84 +497,62 @@ GSF_handle_p2p_migration_stop_ (void *cls,
455 * @param cls 'struct GSF_ConnectedPeer' of the peer that would 497 * @param cls 'struct GSF_ConnectedPeer' of the peer that would
456 * have liked an answer to the request 498 * have liked an answer to the request
457 * @param pr handle to the original pending request 499 * @param pr handle to the original pending request
500 * @param expiration when does 'data' expire?
458 * @param data response data, NULL on request expiration 501 * @param data response data, NULL on request expiration
459 * @param data_len number of bytes in data 502 * @param data_len number of bytes in data
503 * @param more GNUNET_YES if the request remains active (may call
504 * this function again), GNUNET_NO if the request is
505 * finished (client must not call GSF_pending_request_cancel_)
460 */ 506 */
461static void 507static void
462handle_p2p_reply (void *cls, 508handle_p2p_reply (void *cls,
463 struct GSF_PendingRequest *pr, 509 struct GSF_PendingRequest *pr,
510 struct GNUNET_TIME_Absolute expiration,
464 const void *data, 511 const void *data,
465 size_t data_len) 512 size_t data_len,
513 int more)
466{ 514{
467 struct GSF_ConnectedPeer *cp = cls; 515 struct GSF_ConnectedPeer *cp = cls;
516 struct GSF_PendingRequest *prd;
517 struct PutMessage *pm;
518 size_t msize;
468 519
469#if SUPPORT_DELAYS 520 prd = GSF_pending_request_get_data_ (pr);
470 struct GNUNET_TIME_Relative art_delay;
471#endif
472
473 /* FIXME: adapt code fragments below to new API! */
474 if (NULL == data) 521 if (NULL == data)
475 { 522 {
476 /* FIXME: request expired! clean up! */ 523 GNUNET_assert (GNUNET_NO == more);
477 GNUNET_STATISTICS_update (stats, 524 GNUNET_STATISTICS_update (stats,
478 gettext_noop ("# P2P searches active"), 525 gettext_noop ("# P2P searches active"),
479 -1, 526 -1,
480 GNUNET_NO); 527 GNUNET_NO);
528 GNUNET_break (GNUNET_OK ==
529 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
530 &prd->query,
531 pr));
481 return; 532 return;
482 } 533 }
483
484 /* reply will go over the network, check for cover traffic */
485 if ( (prq->anonymity_level > 1) &&
486 (cover_content_count < prq->anonymity_level - 1) )
487 {
488 /* insufficient cover traffic, skip */
489 GNUNET_STATISTICS_update (stats,
490 gettext_noop ("# replies suppressed due to lack of cover traffic"),
491 1,
492 GNUNET_NO);
493 return GNUNET_YES;
494 }
495 if (prq->anonymity_level > 1)
496 cover_content_count -= prq->anonymity_level - 1;
497
498
499 cp = pr->cp;
500#if DEBUG_FS 534#if DEBUG_FS
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Transmitting result for query `%s' to other peer (PID=%u)\n", 536 "Transmitting result for query `%s'\n",
503 GNUNET_h2s (key), 537 GNUNET_h2s (key));
504 (unsigned int) cp->pid);
505#endif 538#endif
506 GNUNET_STATISTICS_update (stats, 539 GNUNET_STATISTICS_update (stats,
507 gettext_noop ("# replies received for other peers"), 540 gettext_noop ("# replies received for other peers"),
508 1, 541 1,
509 GNUNET_NO); 542 GNUNET_NO);
510 msize = sizeof (struct PutMessage) + prq->size; 543 msize = sizeof (struct PutMessage) + data_len;
511 reply = GNUNET_malloc (msize + sizeof (struct PendingMessage)); 544 pm = GNUNET_malloc (sizeof (msize));
512 reply->cont = &transmit_reply_continuation; 545 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
513 reply->cont_cls = pr; 546 pm->header.size = htons (msize);
514#if SUPPORT_DELAYS 547 pm->type = htonl (prd->type);
515 art_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 548 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
516 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 549 memcpy (&pm[1], data, data_len);
517 TTL_DECREMENT)); 550 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
518 reply->delay_until 551 UINT32_MAX,
519 = GNUNET_TIME_relative_to_absolute (art_delay); 552 REPLY_TIMEOUT,
520 GNUNET_STATISTICS_update (stats, 553 msize,
521 gettext_noop ("cummulative artificial delay introduced (ms)"), 554 &copy_reply,
522 art_delay.abs_value, 555 pm);
523 GNUNET_NO);
524#endif
525 reply->msize = msize;
526 reply->priority = UINT32_MAX; /* send replies first! */
527 pm = (struct PutMessage*) &reply[1];
528 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
529 pm->header.size = htons (msize);
530 pm->type = htonl (prq->type);
531 pm->expiration = GNUNET_TIME_absolute_hton (prq->expiration);
532 memcpy (&pm[1], prq->data, prq->size);
533 add_to_pending_messages_for_peer (cp, reply, pr);
534
535
536} 556}
537 557
538 558
diff --git a/src/fs/gnunet-service-fs_lc.c b/src/fs/gnunet-service-fs_lc.c
index 469475fe0..e8d6bda47 100644
--- a/src/fs/gnunet-service-fs_lc.c
+++ b/src/fs/gnunet-service-fs_lc.c
@@ -190,13 +190,26 @@ GSF_local_client_lookup_ (struct GNUNET_SERVER_Client *client)
190 * @param pr handle to the original pending request 190 * @param pr handle to the original pending request
191 * @param data response data, NULL on request expiration 191 * @param data response data, NULL on request expiration
192 * @param data_len number of bytes in data 192 * @param data_len number of bytes in data
193 * @param more GNUNET_YES if the request remains active (may call
194 * this function again), GNUNET_NO if the request is
195 * finished (client must not call GSF_pending_request_cancel_)
193 */ 196 */
194static void 197static void
195client_response_handler (void *cls, 198client_response_handler (void *cls,
196 struct GSF_PendingRequest *pr, 199 struct GSF_PendingRequest *pr,
197 const void *data, 200 const void *data,
198 size_t data_len) 201 size_t data_len,
202 int more)
199{ 203{
204 struct ClientRequest *cr = cls;
205
206 if (NULL == data)
207 {
208 /* ugh, request 'timed out' -- how can this be? */
209 GNUNET_break (0);
210 GNUNET_assert (GNUNET_NO == more);
211 return;
212 }
200 /* FIXME: adapt old code below to new API! */ 213 /* FIXME: adapt old code below to new API! */
201 214
202 GNUNET_STATISTICS_update (stats, 215 GNUNET_STATISTICS_update (stats,
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index d2248989f..4dc00f54c 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -615,7 +615,6 @@ update_request_performance_data (struct ProcessReplyClosure *prq,
615} 615}
616 616
617 617
618
619/** 618/**
620 * We have received a reply; handle it! 619 * We have received a reply; handle it!
621 * 620 *
@@ -663,30 +662,13 @@ process_reply (void *cls,
663 break; 662 break;
664 case GNUNET_BLOCK_EVALUATION_OK_LAST: 663 case GNUNET_BLOCK_EVALUATION_OK_LAST:
665 update_request_performance_data (prq, pr); 664 update_request_performance_data (prq, pr);
666 /* FIXME: adapt code to new API! */
667 while (NULL != pr->pending_head)
668 destroy_pending_message_list_entry (pr->pending_head);
669 if (pr->qe != NULL)
670 {
671 if (pr->client_request_list != NULL)
672 GNUNET_SERVER_receive_done (pr->client_request_list->client_list->client,
673 GNUNET_YES);
674 GNUNET_DATASTORE_cancel (pr->qe);
675 pr->qe = NULL;
676 }
677 pr->do_remove = GNUNET_YES;
678 if (pr->task != GNUNET_SCHEDULER_NO_TASK)
679 {
680 GNUNET_SCHEDULER_cancel (pr->task);
681 pr->task = GNUNET_SCHEDULER_NO_TASK;
682 }
683 GNUNET_break (GNUNET_YES ==
684 GNUNET_CONTAINER_multihashmap_remove (query_request_map,
685 key,
686 pr));
687 GNUNET_LOAD_update (rt_entry_lifetime, 665 GNUNET_LOAD_update (rt_entry_lifetime,
688 GNUNET_TIME_absolute_get_duration (pr->start_time).rel_value); 666 GNUNET_TIME_absolute_get_duration (pr->start_time).rel_value);
689 break; 667 /* pass on to other peers / local clients */
668 pr->rh (pr->rh_cls, pr, prq->data, prq->size, GNUNET_NO);
669 /* destroy request, we're done */
670 GSF_pending_request_cancel_ (pr);
671 return GNUNET_YES;
690 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 672 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
691 GNUNET_STATISTICS_update (stats, 673 GNUNET_STATISTICS_update (stats,
692 gettext_noop ("# duplicate replies discarded (bloomfilter)"), 674 gettext_noop ("# duplicate replies discarded (bloomfilter)"),
@@ -741,7 +723,7 @@ process_reply (void *cls,
741 pr->results_found++; 723 pr->results_found++;
742 prq->request_found = GNUNET_YES; 724 prq->request_found = GNUNET_YES;
743 /* finally, pass on to other peers / local clients */ 725 /* finally, pass on to other peers / local clients */
744 pr->rh (pr->rh_cls, pr, prq->data, prq->size); 726 pr->rh (pr->rh_cls, pr, prq->data, prq->size, GNUNET_YES);
745 return GNUNET_YES; 727 return GNUNET_YES;
746} 728}
747 729
@@ -975,6 +957,7 @@ void
975GSF_pending_request_init_ () 957GSF_pending_request_init_ ()
976{ 958{
977 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024); 959 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024);
960 requests_by_expiration_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
978} 961}
979 962
980 963
@@ -989,6 +972,8 @@ GSF_pending_request_done_ ()
989 NULL); 972 NULL);
990 GNUNET_CONTAINER_multihashmap_destroy (pr_map); 973 GNUNET_CONTAINER_multihashmap_destroy (pr_map);
991 pr_map = NULL; 974 pr_map = NULL;
975 GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap);
976 requests_by_expiration_heap = NULL;
992} 977}
993 978
994 979
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index bb6920ab1..2cb7cb843 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -139,13 +139,19 @@ struct GSF_PendingRequestData
139 * 139 *
140 * @param cls user-specified closure 140 * @param cls user-specified closure
141 * @param pr handle to the original pending request 141 * @param pr handle to the original pending request
142 * @param expiration when does 'data' expire?
142 * @param data response data, NULL on request expiration 143 * @param data response data, NULL on request expiration
143 * @param data_len number of bytes in data 144 * @param data_len number of bytes in data
145 * @param more GNUNET_YES if the request remains active (may call
146 * this function again), GNUNET_NO if the request is
147 * finished (client must not call GSF_pending_request_cancel_)
144 */ 148 */
145typedef void (*GSF_PendingRequestReplyHandler)(void *cls, 149typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
146 struct GSF_PendingRequest *pr, 150 struct GSF_PendingRequest *pr,
151 struct GNUNET_TIME_Absolute expiration,
147 const void *data, 152 const void *data,
148 size_t data_len); 153 size_t data_len,
154 int more);
149 155
150 156
151/** 157/**