2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/gnunet-service-fs_pr.c
23 * @brief API to handle pending requests
24 * @author Christian Grothoff
27 #include "gnunet_load_lib.h"
28 #include "gnunet-service-fs.h"
29 #include "gnunet-service-fs_cp.h"
30 #include "gnunet-service-fs_indexing.h"
31 #include "gnunet-service-fs_pe.h"
32 #include "gnunet-service-fs_pr.h"
35 * Maximum size of the datastore queue for P2P operations. Needs to
36 * be large enough to queue MAX_QUEUE_PER_PEER operations for roughly
37 * the number of active (connected) peers.
39 #define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
42 * Bandwidth value of a 0-priority content (must be fairly high
43 * compared to query since content is typically significantly larger
44 * -- and more valueable since it can take many queries to get one
47 #define CONTENT_BANDWIDTH_VALUE 800
50 * Hard limit on the number of results we may get from the datastore per query.
52 #define MAX_RESULTS (100 * 1024)
57 struct GSF_PendingRequest
60 * Public data for the request.
62 struct GSF_PendingRequestData public_data;
65 * Function to call if we encounter a reply.
67 GSF_PendingRequestReplyHandler rh;
75 * Array of hash codes of replies we've already seen.
77 GNUNET_HashCode *replies_seen;
80 * Bloomfilter masking replies we've already seen.
82 struct GNUNET_CONTAINER_BloomFilter *bf;
85 * Entry for this pending request in the expiration heap, or NULL.
87 struct GNUNET_CONTAINER_HeapNode *hnode;
90 * Datastore queue entry for this request (or NULL for none).
92 struct GNUNET_DATASTORE_QueueEntry *qe;
95 * DHT request handle for this request (or NULL for none).
97 struct GNUNET_DHT_GetHandle *gh;
100 * Function to call upon completion of the local get
101 * request, or NULL for none.
103 GSF_LocalLookupContinuation llc_cont;
106 * Closure for llc_cont.
111 * Last result from the local datastore lookup evaluation.
113 enum GNUNET_BLOCK_EvaluationResult local_result;
116 * Identity of the peer that we should use for the 'sender'
117 * (recipient of the response) when forwarding (0 for none).
119 GNUNET_PEER_Id sender_pid;
122 * Identity of the peer that we should never forward this query
123 * to since it originated this query (0 for none).
125 GNUNET_PEER_Id origin_pid;
128 * Time we started the last datastore lookup.
130 struct GNUNET_TIME_Absolute qe_start;
133 * Task that warns us if the local datastore lookup takes too long.
135 GNUNET_SCHEDULER_TaskIdentifier warn_task;
138 * Current offset for querying our local datastore for results.
139 * Starts at a random value, incremented until we get the same
140 * UID again (detected using 'first_uid'), which is then used
141 * to termiante the iteration.
143 uint64_t local_result_offset;
146 * Unique ID of the first result from the local datastore;
147 * used to detect wrap-around of the offset.
152 * Number of valid entries in the 'replies_seen' array.
154 unsigned int replies_seen_count;
157 * Length of the 'replies_seen' array.
159 unsigned int replies_seen_size;
162 * Mingle value we currently use for the bf.
167 * Do we have a first UID yet?
169 unsigned int have_first_uid;
175 * All pending requests, ordered by the query. Entries
176 * are of type 'struct GSF_PendingRequest*'.
178 static struct GNUNET_CONTAINER_MultiHashMap *pr_map;
182 * Datastore 'PUT' load tracking.
184 static struct GNUNET_LOAD_Value *datastore_put_load;
188 * Are we allowed to migrate content to this peer.
190 static int active_to_migration;
194 * Size of the datastore queue we assume for common requests.
195 * Determined based on the network quota.
197 static unsigned int datastore_queue_size;
200 * Heap with the request that will expire next at the top. Contains
201 * pointers of type "struct PendingRequest*"; these will *also* be
202 * aliased from the "requests_by_peer" data structures and the
203 * "requests_by_query" table. Note that requests from our clients
204 * don't expire and are thus NOT in the "requests_by_expiration"
205 * (or the "requests_by_peer" tables).
207 static struct GNUNET_CONTAINER_Heap *requests_by_expiration_heap;
211 * Maximum number of requests (from other peers, overall) that we're
212 * willing to have pending at any given point in time. Can be changed
213 * via the configuration file (32k is just the default).
215 static unsigned long long max_pending_requests = (32 * 1024);
220 * Recalculate our bloom filter for filtering replies. This function
221 * will create a new bloom filter from scratch, so it should only be
222 * called if we have no bloomfilter at all (and hence can create a
223 * fresh one of minimal size without problems) OR if our peer is the
224 * initiator (in which case we may resize to larger than mimimum size).
226 * @param pr request for which the BF is to be recomputed
229 refresh_bloomfilter (struct GSF_PendingRequest *pr)
232 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
234 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
236 GNUNET_BLOCK_construct_bloomfilter (pr->mingle, pr->replies_seen,
237 pr->replies_seen_count);
242 * Create a new pending request.
244 * @param options request options
245 * @param type type of the block that is being requested
246 * @param query key for the lookup
247 * @param namespace namespace to lookup, NULL for no namespace
248 * @param target preferred target for the request, NULL for none
249 * @param bf_data raw data for bloom filter for known replies, can be NULL
250 * @param bf_size number of bytes in bf_data
251 * @param mingle mingle value for bf
252 * @param anonymity_level desired anonymity level
253 * @param priority maximum outgoing cummulative request priority to use
254 * @param ttl current time-to-live for the request
255 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none
256 * @param origin_pid peer ID of origin of query (do not loop back)
257 * @param replies_seen hash codes of known local replies
258 * @param replies_seen_count size of the 'replies_seen' array
259 * @param rh handle to call when we get a reply
260 * @param rh_cls closure for rh
261 * @return handle for the new pending request
263 struct GSF_PendingRequest *
264 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
265 enum GNUNET_BLOCK_Type type,
266 const GNUNET_HashCode * query,
267 const GNUNET_HashCode * namespace,
268 const struct GNUNET_PeerIdentity *target,
269 const char *bf_data, size_t bf_size,
270 uint32_t mingle, uint32_t anonymity_level,
271 uint32_t priority, int32_t ttl,
272 GNUNET_PEER_Id sender_pid,
273 GNUNET_PEER_Id origin_pid,
274 const GNUNET_HashCode * replies_seen,
275 unsigned int replies_seen_count,
276 GSF_PendingRequestReplyHandler rh, void *rh_cls)
278 struct GSF_PendingRequest *pr;
279 struct GSF_PendingRequest *dpr;
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Creating request handle for `%s' of type %d\n",
284 GNUNET_h2s (query), type);
286 GNUNET_STATISTICS_update (GSF_stats,
287 gettext_noop ("# Pending requests created"), 1,
289 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest));
290 pr->local_result_offset =
291 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
292 pr->public_data.query = *query;
293 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == type)
295 GNUNET_assert (NULL != namespace);
296 pr->public_data.namespace = *namespace;
300 pr->public_data.target = *target;
301 pr->public_data.has_target = GNUNET_YES;
303 pr->public_data.anonymity_level = anonymity_level;
304 pr->public_data.priority = priority;
305 pr->public_data.original_priority = priority;
306 pr->public_data.options = options;
307 pr->public_data.type = type;
308 pr->public_data.start_time = GNUNET_TIME_absolute_get ();
309 pr->sender_pid = sender_pid;
310 pr->origin_pid = origin_pid;
313 GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
315 pr->public_data.ttl =
316 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
317 (GNUNET_TIME_UNIT_SECONDS,
320 pr->public_data.ttl =
321 GNUNET_TIME_absolute_subtract (pr->public_data.start_time,
322 GNUNET_TIME_relative_multiply
323 (GNUNET_TIME_UNIT_SECONDS,
325 if (replies_seen_count > 0)
327 pr->replies_seen_size = replies_seen_count;
329 GNUNET_malloc (sizeof (GNUNET_HashCode) * pr->replies_seen_size);
330 memcpy (pr->replies_seen, replies_seen,
331 replies_seen_count * sizeof (GNUNET_HashCode));
332 pr->replies_seen_count = replies_seen_count;
337 GNUNET_CONTAINER_bloomfilter_init (bf_data, bf_size,
338 GNUNET_CONSTANTS_BLOOMFILTER_K);
341 else if ((replies_seen_count > 0) &&
342 (0 != (options & GSF_PRO_BLOOMFILTER_FULL_REFRESH)))
344 refresh_bloomfilter (pr);
346 GNUNET_CONTAINER_multihashmap_put (pr_map, query, pr,
347 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
348 if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
351 GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap, pr,
352 pr->public_data.ttl.abs_value);
353 /* make sure we don't track too many requests */
354 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) >
355 max_pending_requests)
357 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
358 GNUNET_assert (dpr != NULL);
360 break; /* let the request live briefly... */
361 dpr->rh (dpr->rh_cls, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, dpr,
362 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_BLOCK_TYPE_ANY,
364 GSF_pending_request_cancel_ (dpr, GNUNET_YES);
367 GNUNET_STATISTICS_update (GSF_stats,
368 gettext_noop ("# Pending requests active"), 1,
375 * Obtain the public data associated with a pending request
377 * @param pr pending request
378 * @return associated public data
380 struct GSF_PendingRequestData *
381 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr)
383 return &pr->public_data;
388 * Test if two pending requests are compatible (would generate
389 * the same query modulo filters and should thus be processed
392 * @param pra a pending request
393 * @param prb another pending request
394 * @return GNUNET_OK if the requests are compatible
397 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
398 struct GSF_PendingRequest *prb)
400 if ((pra->public_data.type != prb->public_data.type) ||
402 memcmp (&pra->public_data.query, &prb->public_data.query,
403 sizeof (GNUNET_HashCode))) ||
404 ((pra->public_data.type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
406 memcmp (&pra->public_data.namespace, &prb->public_data.namespace,
407 sizeof (GNUNET_HashCode)))))
415 * Update a given pending request with additional replies
416 * that have been seen.
418 * @param pr request to update
419 * @param replies_seen hash codes of replies that we've seen
420 * @param replies_seen_count size of the replies_seen array
423 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
424 const GNUNET_HashCode * replies_seen,
425 unsigned int replies_seen_count)
428 GNUNET_HashCode mhash;
430 if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count)
431 return; /* integer overflow */
432 if (0 != (pr->public_data.options & GSF_PRO_BLOOMFILTER_FULL_REFRESH))
434 /* we're responsible for the BF, full refresh */
435 if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
436 GNUNET_array_grow (pr->replies_seen, pr->replies_seen_size,
437 replies_seen_count + pr->replies_seen_count);
438 memcpy (&pr->replies_seen[pr->replies_seen_count], replies_seen,
439 sizeof (GNUNET_HashCode) * replies_seen_count);
440 pr->replies_seen_count += replies_seen_count;
441 refresh_bloomfilter (pr);
447 /* we're not the initiator, but the initiator did not give us
448 * any bloom-filter, so we need to create one on-the-fly */
450 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
452 GNUNET_BLOCK_construct_bloomfilter (pr->mingle, replies_seen,
457 for (i = 0; i < pr->replies_seen_count; i++)
459 GNUNET_BLOCK_mingle_hash (&replies_seen[i], pr->mingle, &mhash);
460 GNUNET_CONTAINER_bloomfilter_add (pr->bf, &mhash);
468 * Generate the message corresponding to the given pending request for
469 * transmission to other peers (or at least determine its size).
471 * @param pr request to generate the message for
472 * @param buf_size number of bytes available in buf
473 * @param buf where to copy the message (can be NULL)
474 * @return number of bytes needed (if > buf_size) or used
477 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
478 size_t buf_size, void *buf)
480 char lbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
481 struct GetMessage *gm;
482 GNUNET_HashCode *ext;
488 struct GNUNET_TIME_Absolute now;
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Building request message for `%s' of type %d\n",
496 GNUNET_h2s (&pr->public_data.query), pr->public_data.type);
500 do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY));
501 if ((!do_route) && (pr->sender_pid == 0))
504 do_route = GNUNET_YES;
508 bm |= GET_MESSAGE_BIT_RETURN_TO;
511 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
513 bm |= GET_MESSAGE_BIT_SKS_NAMESPACE;
516 if (GNUNET_YES == pr->public_data.has_target)
518 bm |= GET_MESSAGE_BIT_TRANSMIT_TO;
521 bf_size = GNUNET_CONTAINER_bloomfilter_get_size (pr->bf);
522 msize = sizeof (struct GetMessage) + bf_size + k * sizeof (GNUNET_HashCode);
523 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
524 if (buf_size < msize)
526 gm = (struct GetMessage *) lbuf;
527 gm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_GET);
528 gm->header.size = htons (msize);
529 gm->type = htonl (pr->public_data.type);
532 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
533 pr->public_data.priority + 1);
536 pr->public_data.priority -= prio;
537 gm->priority = htonl (prio);
538 now = GNUNET_TIME_absolute_get ();
539 ttl = (int64_t) (pr->public_data.ttl.abs_value - now.abs_value);
540 gm->ttl = htonl (ttl / 1000);
541 gm->filter_mutator = htonl (pr->mingle);
542 gm->hash_bitmap = htonl (bm);
543 gm->query = pr->public_data.query;
544 ext = (GNUNET_HashCode *) & gm[1];
547 GNUNET_PEER_resolve (pr->sender_pid,
548 (struct GNUNET_PeerIdentity *) &ext[k++]);
549 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
550 memcpy (&ext[k++], &pr->public_data.namespace, sizeof (GNUNET_HashCode));
551 if (GNUNET_YES == pr->public_data.has_target)
552 ext[k++] = pr->public_data.target.hashPubKey;
554 GNUNET_assert (GNUNET_SYSERR !=
555 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
558 memcpy (buf, gm, msize);
564 * Iterator to free pending requests.
566 * @param cls closure, unused
567 * @param key current key code
568 * @param value value in the hash map (pending request)
569 * @return GNUNET_YES (we should continue to iterate)
572 clean_request (void *cls, const GNUNET_HashCode * key, void *value)
574 struct GSF_PendingRequest *pr = value;
575 GSF_LocalLookupContinuation cont;
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Cleaning up pending request for `%s'.\n", GNUNET_h2s (key));
581 if (NULL != (cont = pr->llc_cont))
584 cont (pr->llc_cont_cls, pr, pr->local_result);
586 GSF_plan_notify_request_done_ (pr);
587 GNUNET_free_non_null (pr->replies_seen);
590 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
593 GNUNET_PEER_change_rc (pr->sender_pid, -1);
595 GNUNET_PEER_change_rc (pr->origin_pid, -1);
597 if (NULL != pr->hnode)
599 GNUNET_CONTAINER_heap_remove_node (pr->hnode);
604 GNUNET_DATASTORE_cancel (pr->qe);
609 GNUNET_DHT_get_stop (pr->gh);
612 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
614 GNUNET_SCHEDULER_cancel (pr->warn_task);
615 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
617 GNUNET_assert (GNUNET_OK ==
618 GNUNET_CONTAINER_multihashmap_remove (pr_map,
619 &pr->public_data.query,
621 GNUNET_STATISTICS_update (GSF_stats,
622 gettext_noop ("# Pending requests active"), -1,
630 * Explicitly cancel a pending request.
632 * @param pr request to cancel
633 * @param full_cleanup fully purge the request
636 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup)
638 GSF_LocalLookupContinuation cont;
641 return; /* already cleaned up! */
642 if (GNUNET_YES != full_cleanup)
644 /* make request inactive (we're no longer interested in more results),
645 * but do NOT remove from our data-structures, we still need it there
646 * to prevent the request from looping */
648 if (NULL != (cont = pr->llc_cont))
651 cont (pr->llc_cont_cls, pr, pr->local_result);
653 GSF_plan_notify_request_done_ (pr);
656 GNUNET_DATASTORE_cancel (pr->qe);
661 GNUNET_DHT_get_stop (pr->gh);
664 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
666 GNUNET_SCHEDULER_cancel (pr->warn_task);
667 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
671 GNUNET_assert (GNUNET_YES ==
672 clean_request (NULL, &pr->public_data.query, pr));
677 * Iterate over all pending requests.
679 * @param it function to call for each request
680 * @param cls closure for it
683 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls)
685 GNUNET_CONTAINER_multihashmap_iterate (pr_map,
686 (GNUNET_CONTAINER_HashMapIterator) it,
694 * Closure for "process_reply" function.
696 struct ProcessReplyClosure
699 * The data for the reply.
704 * Who gave us this reply? NULL for local host (or DHT)
706 struct GSF_ConnectedPeer *sender;
709 * When the reply expires.
711 struct GNUNET_TIME_Absolute expiration;
721 enum GNUNET_BLOCK_Type type;
724 * How much was this reply worth to us?
729 * Anonymity requirements for this reply.
731 uint32_t anonymity_level;
734 * Evaluation result (returned).
736 enum GNUNET_BLOCK_EvaluationResult eval;
739 * Did we find a matching request?
746 * Update the performance data for the sender (if any) since
747 * the sender successfully answered one of our queries.
749 * @param prq information about the sender
750 * @param pr request that was satisfied
753 update_request_performance_data (struct ProcessReplyClosure *prq,
754 struct GSF_PendingRequest *pr)
756 if (prq->sender == NULL)
758 GSF_peer_update_performance_ (prq->sender, pr->public_data.start_time,
764 * We have received a reply; handle it!
766 * @param cls response (struct ProcessReplyClosure)
767 * @param key our query
768 * @param value value in the hash map (info about the query)
769 * @return GNUNET_YES (we should continue to iterate)
772 process_reply (void *cls, const GNUNET_HashCode * key, void *value)
774 struct ProcessReplyClosure *prq = cls;
775 struct GSF_PendingRequest *pr = value;
776 GNUNET_HashCode chash;
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Matched result (type %u) for query `%s' with pending request\n",
783 (unsigned int) prq->type, GNUNET_h2s (key));
785 GNUNET_STATISTICS_update (GSF_stats,
786 gettext_noop ("# replies received and matched"), 1,
789 GNUNET_BLOCK_evaluate (GSF_block_ctx, prq->type, key, &pr->bf, pr->mingle,
790 &pr->public_data.namespace,
792 GNUNET_BLOCK_TYPE_FS_SBLOCK) ?
793 sizeof (GNUNET_HashCode) : 0, prq->data,
797 case GNUNET_BLOCK_EVALUATION_OK_MORE:
798 update_request_performance_data (prq, pr);
800 case GNUNET_BLOCK_EVALUATION_OK_LAST:
801 /* short cut: stop processing early, no BF-update, etc. */
802 update_request_performance_data (prq, pr);
803 GNUNET_LOAD_update (GSF_rt_entry_lifetime,
804 GNUNET_TIME_absolute_get_duration (pr->
805 public_data.start_time).rel_value);
806 /* pass on to other peers / local clients */
807 pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
808 prq->type, prq->data, prq->size);
810 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
811 GNUNET_STATISTICS_update (GSF_stats,
813 ("# duplicate replies discarded (bloomfilter)"),
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
817 "Duplicate response `%s', discarding.\n", GNUNET_h2s (&mhash));
819 return GNUNET_YES; /* duplicate */
820 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
821 return GNUNET_YES; /* wrong namespace */
822 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
825 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
828 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
829 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported block type %u\n"),
833 /* update bloomfilter */
834 GNUNET_CRYPTO_hash (prq->data, prq->size, &chash);
835 GSF_pending_request_update_ (pr, &chash, 1);
836 if (NULL == prq->sender)
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
840 "Found result for query `%s' in local datastore\n",
843 GNUNET_STATISTICS_update (GSF_stats,
844 gettext_noop ("# results found locally"), 1,
849 GSF_dht_lookup_ (pr);
851 prq->priority += pr->public_data.original_priority;
852 pr->public_data.priority = 0;
853 pr->public_data.original_priority = 0;
854 pr->public_data.results_found++;
855 prq->request_found = GNUNET_YES;
856 /* finally, pass on to other peer / local client */
857 pr->rh (pr->rh_cls, prq->eval, pr, prq->anonymity_level, prq->expiration,
858 prq->type, prq->data, prq->size);
864 * Context for the 'put_migration_continuation'.
866 struct PutMigrationContext
870 * Start time for the operation.
872 struct GNUNET_TIME_Absolute start;
877 struct GNUNET_PeerIdentity origin;
880 * GNUNET_YES if we had a matching request for this block,
888 * Continuation called to notify client about result of the
892 * @param success GNUNET_SYSERR on failure
893 * @param min_expiration minimum expiration time required for content to be stored
894 * @param msg NULL on success, otherwise an error message
897 put_migration_continuation (void *cls, int success,
898 struct GNUNET_TIME_Absolute min_expiration,
901 struct PutMigrationContext *pmc = cls;
902 struct GNUNET_TIME_Relative block_time;
903 struct GSF_ConnectedPeer *cp;
904 struct GSF_PeerPerformanceData *ppd;
906 cp = GSF_peer_get_ (&pmc->origin);
907 if ((GNUNET_OK != success) && (GNUNET_NO == pmc->requested))
909 /* block migration for a bit... */
912 ppd = GSF_get_peer_performance_data_ (cp);
913 ppd->migration_duplication++;
915 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
916 5 * ppd->migration_duplication +
917 GNUNET_CRYPTO_random_u32
918 (GNUNET_CRYPTO_QUALITY_WEAK, 5));
919 GSF_block_peer_migration_ (cp, block_time);
926 ppd = GSF_get_peer_performance_data_ (cp);
927 ppd->migration_duplication = 0; /* reset counter */
931 /* on failure, increase the put load dramatically */
932 if (NULL != datastore_put_load)
933 GNUNET_LOAD_update (datastore_put_load,
934 GNUNET_TIME_UNIT_HOURS.rel_value);
935 if (GNUNET_OK == success)
937 GNUNET_STATISTICS_update (GSF_stats,
938 gettext_noop ("# Datastore `PUT' failures"), 1,
944 * Test if the DATABASE (PUT) load on this peer is too high
945 * to even consider processing the query at
948 * @return GNUNET_YES if the load is too high to do anything (load high)
949 * GNUNET_NO to process normally (load normal or low)
952 test_put_load_too_high (uint32_t priority)
956 if (NULL == datastore_put_load)
958 if (GNUNET_LOAD_get_average (datastore_put_load) < 50)
959 return GNUNET_NO; /* very fast */
960 ld = GNUNET_LOAD_get_load (datastore_put_load);
961 if (ld < 2.0 * (1 + priority))
963 GNUNET_STATISTICS_update (GSF_stats,
965 ("# storage requests dropped due to high load"), 1,
972 * Iterator called on each result obtained for a DHT
973 * operation that expects a reply
976 * @param exp when will this value expire
977 * @param key key of the result
978 * @param get_path peers on reply path (or NULL if not recorded)
979 * @param get_path_length number of entries in get_path
980 * @param put_path peers on the PUT path (or NULL if not recorded)
981 * @param put_path_length number of entries in get_path
982 * @param type type of the result
983 * @param size number of bytes in data
984 * @param data pointer to the result data
987 handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp,
988 const GNUNET_HashCode * key,
989 const struct GNUNET_PeerIdentity *get_path,
990 unsigned int get_path_length,
991 const struct GNUNET_PeerIdentity *put_path,
992 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
993 size_t size, const void *data)
995 struct GSF_PendingRequest *pr = cls;
996 struct ProcessReplyClosure prq;
997 struct PutMigrationContext *pmc;
999 GNUNET_STATISTICS_update (GSF_stats,
1000 gettext_noop ("# Replies received from DHT"), 1,
1002 memset (&prq, 0, sizeof (prq));
1004 prq.expiration = exp;
1007 process_reply (&prq, key, pr);
1008 if ((GNUNET_YES == active_to_migration) &&
1009 (GNUNET_NO == test_put_load_too_high (prq.priority)))
1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1013 "Replicating result for query `%s' with priority %u\n",
1014 GNUNET_h2s (key), prq.priority);
1016 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
1017 pmc->start = GNUNET_TIME_absolute_get ();
1018 pmc->requested = GNUNET_YES;
1020 GNUNET_DATASTORE_put (GSF_dsh, 0, key, size, data, type, prq.priority,
1022 0 /* replication */ ,
1023 exp, 1 + prq.priority, MAX_DATASTORE_QUEUE,
1024 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1025 &put_migration_continuation, pmc))
1027 put_migration_continuation (pmc, GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
1034 * Consider looking up the data in the DHT (anonymity-level permitting).
1036 * @param pr the pending request to process
1039 GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
1043 struct GNUNET_PeerIdentity pi;
1044 char buf[sizeof (GNUNET_HashCode) * 2];
1046 if (0 != pr->public_data.anonymity_level)
1050 GNUNET_DHT_get_stop (pr->gh);
1055 if (GNUNET_BLOCK_TYPE_FS_SBLOCK == pr->public_data.type)
1058 memcpy (buf, &pr->public_data.namespace, sizeof (GNUNET_HashCode));
1059 xquery_size = sizeof (GNUNET_HashCode);
1061 if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY))
1063 GNUNET_assert (0 != pr->sender_pid);
1064 GNUNET_PEER_resolve (pr->sender_pid, &pi);
1065 memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
1066 xquery_size += sizeof (struct GNUNET_PeerIdentity);
1069 GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL,
1070 pr->public_data.type, &pr->public_data.query,
1071 5 /* DEFAULT_GET_REPLICATION */ ,
1072 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1073 /* FIXME: can no longer pass pr->bf/pr->mingle... */
1074 xquery, xquery_size, &handle_dht_reply, pr);
1079 * Task that issues a warning if the datastore lookup takes too long.
1081 * @param cls the 'struct GSF_PendingRequest'
1082 * @param tc task context
1085 warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1087 struct GSF_PendingRequest *pr = cls;
1089 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1090 _("Datastore lookup already took %llu ms!\n"),
1091 (unsigned long long)
1092 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
1094 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1100 * Task that issues a warning if the datastore lookup takes too long.
1102 * @param cls the 'struct GSF_PendingRequest'
1103 * @param tc task context
1106 odc_warn_delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1108 struct GSF_PendingRequest *pr = cls;
1110 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1111 _("On-demand lookup already took %llu ms!\n"),
1112 (unsigned long long)
1113 GNUNET_TIME_absolute_get_duration (pr->qe_start).rel_value);
1115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1116 &odc_warn_delay_task, pr);
1121 * We're processing (local) results for a search request
1122 * from another peer. Pass applicable results to the
1123 * peer and if we are done either clean up (operation
1124 * complete) or forward to other peers (more results possible).
1126 * @param cls our closure (struct PendingRequest)
1127 * @param key key for the content
1128 * @param size number of bytes in data
1129 * @param data content stored
1130 * @param type type of the content
1131 * @param priority priority of the content
1132 * @param anonymity anonymity-level for the content
1133 * @param expiration expiration time for the content
1134 * @param uid unique identifier for the datum;
1135 * maybe 0 if no unique identifier is available
1138 process_local_reply (void *cls, const GNUNET_HashCode * key, size_t size,
1139 const void *data, enum GNUNET_BLOCK_Type type,
1140 uint32_t priority, uint32_t anonymity,
1141 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1143 struct GSF_PendingRequest *pr = cls;
1144 GSF_LocalLookupContinuation cont;
1145 struct ProcessReplyClosure prq;
1146 GNUNET_HashCode query;
1147 unsigned int old_rf;
1149 GNUNET_SCHEDULER_cancel (pr->warn_task);
1150 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1156 GNUNET_STATISTICS_update (GSF_stats,
1158 ("# Datastore lookups concluded (no results)"),
1161 if (GNUNET_NO == pr->have_first_uid)
1163 pr->first_uid = uid;
1164 pr->have_first_uid = 1;
1168 if ((uid == pr->first_uid) && (key != NULL))
1170 GNUNET_STATISTICS_update (GSF_stats,
1172 ("# Datastore lookups concluded (seen all)"),
1174 key = NULL; /* all replies seen! */
1176 pr->have_first_uid++;
1177 if ((pr->have_first_uid > MAX_RESULTS) && (key != NULL))
1179 GNUNET_STATISTICS_update (GSF_stats,
1181 ("# Datastore lookups aborted (more than MAX_RESULTS)"),
1183 key = NULL; /* all replies seen! */
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1191 "No further local responses available.\n");
1193 if ((pr->public_data.type == GNUNET_BLOCK_TYPE_FS_DBLOCK) ||
1194 (pr->public_data.type == GNUNET_BLOCK_TYPE_FS_IBLOCK))
1195 GNUNET_STATISTICS_update (GSF_stats,
1197 ("# requested DBLOCK or IBLOCK not found"), 1,
1199 goto check_error_and_continue;
1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1203 "Received reply for `%s' of type %d with UID %llu from datastore.\n",
1204 GNUNET_h2s (key), type, (unsigned long long) uid);
1206 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1210 "Found ONDEMAND block, performing on-demand encoding\n");
1212 GNUNET_STATISTICS_update (GSF_stats,
1214 ("# on-demand blocks matched requests"), 1,
1216 pr->qe_start = GNUNET_TIME_absolute_get ();
1218 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1219 &odc_warn_delay_task, pr);
1221 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
1222 anonymity, expiration, uid,
1223 &process_local_reply, pr))
1225 GNUNET_STATISTICS_update (GSF_stats,
1227 ("# on-demand lookups performed successfully"),
1229 return; /* we're done */
1231 GNUNET_STATISTICS_update (GSF_stats,
1232 gettext_noop ("# on-demand lookups failed"), 1,
1234 GNUNET_SCHEDULER_cancel (pr->warn_task);
1236 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1237 &warn_delay_task, pr);
1239 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset - 1,
1240 &pr->public_data.query,
1241 pr->public_data.type ==
1242 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1243 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1245 (GSF_PRO_PRIORITY_UNLIMITED &
1246 pr->public_data.options)) ? UINT_MAX : 1
1247 /* queue priority */ ,
1249 (GSF_PRO_PRIORITY_UNLIMITED &
1250 pr->public_data.options)) ? UINT_MAX :
1251 datastore_queue_size
1252 /* max queue size */ ,
1253 GNUNET_TIME_UNIT_FOREVER_REL,
1254 &process_local_reply, pr);
1256 return; /* we're done */
1257 GNUNET_STATISTICS_update (GSF_stats,
1259 ("# Datastore lookups concluded (error queueing)"),
1261 goto check_error_and_continue;
1263 old_rf = pr->public_data.results_found;
1264 memset (&prq, 0, sizeof (prq));
1266 prq.expiration = expiration;
1269 GNUNET_BLOCK_get_key (GSF_block_ctx, type, data, size, &query))
1272 GNUNET_DATASTORE_remove (GSF_dsh, key, size, data, -1, -1,
1273 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
1274 pr->qe_start = GNUNET_TIME_absolute_get ();
1276 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1277 &warn_delay_task, pr);
1279 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset - 1,
1280 &pr->public_data.query,
1281 pr->public_data.type ==
1282 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1283 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1285 (GSF_PRO_PRIORITY_UNLIMITED &
1286 pr->public_data.options)) ? UINT_MAX : 1
1287 /* queue priority */ ,
1289 (GSF_PRO_PRIORITY_UNLIMITED &
1290 pr->public_data.options)) ? UINT_MAX :
1291 datastore_queue_size
1292 /* max queue size */ ,
1293 GNUNET_TIME_UNIT_FOREVER_REL,
1294 &process_local_reply, pr);
1297 GNUNET_STATISTICS_update (GSF_stats,
1299 ("# Datastore lookups concluded (error queueing)"),
1301 goto check_error_and_continue;
1306 prq.priority = priority;
1307 prq.request_found = GNUNET_NO;
1308 prq.anonymity_level = anonymity;
1309 if ((old_rf == 0) && (pr->public_data.results_found == 0))
1310 GSF_update_datastore_delay_ (pr->public_data.start_time);
1311 process_reply (&prq, key, pr);
1312 pr->local_result = prq.eval;
1313 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST)
1315 GNUNET_STATISTICS_update (GSF_stats,
1317 ("# Datastore lookups concluded (found last result)"),
1319 goto check_error_and_continue;
1321 if ((0 == (GSF_PRO_PRIORITY_UNLIMITED & pr->public_data.options)) &&
1322 ((GNUNET_YES == GSF_test_get_load_too_high_ (0)) ||
1323 (pr->public_data.results_found > 5 + 2 * pr->public_data.priority)))
1326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load too high, done with request\n");
1328 GNUNET_STATISTICS_update (GSF_stats,
1330 ("# Datastore lookups concluded (load too high)"),
1332 goto check_error_and_continue;
1334 pr->qe_start = GNUNET_TIME_absolute_get ();
1336 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1339 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++,
1340 &pr->public_data.query,
1341 pr->public_data.type ==
1342 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1343 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1345 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1346 public_data.options)) ? UINT_MAX : 1
1347 /* queue priority */ ,
1349 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1350 public_data.options)) ? UINT_MAX :
1351 datastore_queue_size
1352 /* max queue size */ ,
1353 GNUNET_TIME_UNIT_FOREVER_REL,
1354 &process_local_reply, pr);
1355 /* check if we successfully queued another datastore request;
1356 * if so, return, otherwise call our continuation (if we have
1358 check_error_and_continue:
1361 if (GNUNET_SCHEDULER_NO_TASK != pr->warn_task)
1363 GNUNET_SCHEDULER_cancel (pr->warn_task);
1364 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1366 if (NULL == (cont = pr->llc_cont))
1367 return; /* no continuation */
1368 pr->llc_cont = NULL;
1369 cont (pr->llc_cont_cls, pr, pr->local_result);
1374 * Is the given target a legitimate peer for forwarding the given request?
1378 * @return GNUNET_YES if this request could be forwarded to the given peer
1381 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
1382 const struct GNUNET_PeerIdentity *target)
1384 struct GNUNET_PeerIdentity pi;
1386 if (0 == pr->origin_pid)
1388 GNUNET_PEER_resolve (pr->origin_pid, &pi);
1390 memcmp (&pi, target,
1391 sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_NO :
1397 * Look up the request in the local datastore.
1399 * @param pr the pending request to process
1400 * @param cont function to call at the end
1401 * @param cont_cls closure for cont
1404 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
1405 GSF_LocalLookupContinuation cont, void *cont_cls)
1407 GNUNET_assert (NULL == pr->gh);
1408 GNUNET_assert (NULL == pr->llc_cont);
1409 pr->llc_cont = cont;
1410 pr->llc_cont_cls = cont_cls;
1411 pr->qe_start = GNUNET_TIME_absolute_get ();
1413 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &warn_delay_task,
1415 GNUNET_STATISTICS_update (GSF_stats,
1416 gettext_noop ("# Datastore lookups initiated"), 1,
1419 GNUNET_DATASTORE_get_key (GSF_dsh, pr->local_result_offset++,
1420 &pr->public_data.query,
1421 pr->public_data.type ==
1422 GNUNET_BLOCK_TYPE_FS_DBLOCK ?
1423 GNUNET_BLOCK_TYPE_ANY : pr->public_data.type,
1425 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1426 public_data.options)) ? UINT_MAX : 1
1427 /* queue priority */ ,
1429 (GSF_PRO_PRIORITY_UNLIMITED & pr->
1430 public_data.options)) ? UINT_MAX :
1431 datastore_queue_size
1432 /* max queue size */ ,
1433 GNUNET_TIME_UNIT_FOREVER_REL,
1434 &process_local_reply, pr);
1437 GNUNET_STATISTICS_update (GSF_stats,
1439 ("# Datastore lookups concluded (error queueing)"),
1441 GNUNET_SCHEDULER_cancel (pr->warn_task);
1442 pr->warn_task = GNUNET_SCHEDULER_NO_TASK;
1443 pr->llc_cont = NULL;
1445 cont (cont_cls, pr, pr->local_result);
1451 * Handle P2P "CONTENT" message. Checks that the message is
1452 * well-formed and then checks if there are any pending requests for
1453 * this content and possibly passes it on (to local clients or other
1454 * peers). Does NOT perform migration (content caching at this peer).
1456 * @param cp the other peer involved (sender or receiver, NULL
1457 * for loopback messages where we are both sender and receiver)
1458 * @param message the actual message
1459 * @return GNUNET_OK if the message was well-formed,
1460 * GNUNET_SYSERR if the message was malformed (close connection,
1461 * do not cache under any circumstances)
1464 GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
1465 const struct GNUNET_MessageHeader *message)
1467 const struct PutMessage *put;
1470 enum GNUNET_BLOCK_Type type;
1471 struct GNUNET_TIME_Absolute expiration;
1472 GNUNET_HashCode query;
1473 struct ProcessReplyClosure prq;
1474 struct GNUNET_TIME_Relative block_time;
1476 struct PutMigrationContext *pmc;
1478 msize = ntohs (message->size);
1479 if (msize < sizeof (struct PutMessage))
1481 GNUNET_break_op (0);
1482 return GNUNET_SYSERR;
1484 put = (const struct PutMessage *) message;
1485 dsize = msize - sizeof (struct PutMessage);
1486 type = ntohl (put->type);
1487 expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
1488 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
1489 return GNUNET_SYSERR;
1491 GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query))
1493 GNUNET_break_op (0);
1494 return GNUNET_SYSERR;
1496 GNUNET_STATISTICS_update (GSF_stats,
1497 gettext_noop ("# GAP PUT messages received"), 1,
1499 /* now, lookup 'query' */
1500 prq.data = (const void *) &put[1];
1507 prq.expiration = expiration;
1509 prq.anonymity_level = UINT32_MAX;
1510 prq.request_found = GNUNET_NO;
1511 GNUNET_CONTAINER_multihashmap_get_multiple (pr_map, &query, &process_reply,
1515 GSF_connected_peer_change_preference_ (cp,
1516 CONTENT_BANDWIDTH_VALUE +
1517 1000 * prq.priority);
1518 GSF_get_peer_performance_data_ (cp)->trust += prq.priority;
1520 if ((GNUNET_YES == active_to_migration) &&
1521 (GNUNET_NO == test_put_load_too_high (prq.priority)))
1524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1525 "Replicating result for query `%s' with priority %u\n",
1526 GNUNET_h2s (&query), prq.priority);
1528 pmc = GNUNET_malloc (sizeof (struct PutMigrationContext));
1529 pmc->start = GNUNET_TIME_absolute_get ();
1530 pmc->requested = prq.request_found;
1531 GNUNET_assert (0 != GSF_get_peer_performance_data_ (cp)->pid);
1532 GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid,
1535 GNUNET_DATASTORE_put (GSF_dsh, 0, &query, dsize, &put[1], type,
1536 prq.priority, 1 /* anonymity */ ,
1537 0 /* replication */ ,
1538 expiration, 1 + prq.priority, MAX_DATASTORE_QUEUE,
1539 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1540 &put_migration_continuation, pmc))
1542 put_migration_continuation (pmc, GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1549 "Choosing not to keep content `%s' (%d/%d)\n",
1550 GNUNET_h2s (&query), active_to_migration,
1551 test_put_load_too_high (prq.priority));
1554 putl = GNUNET_LOAD_get_load (datastore_put_load);
1555 if ((NULL != (cp = prq.sender)) && (GNUNET_NO == prq.request_found) &&
1556 ((GNUNET_YES != active_to_migration) ||
1557 (putl > 2.5 * (1 + prq.priority))))
1559 if (GNUNET_YES != active_to_migration)
1560 putl = 1.0 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5);
1562 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1564 GNUNET_CRYPTO_random_u32
1565 (GNUNET_CRYPTO_QUALITY_WEAK,
1566 (unsigned int) (60000 * putl * putl)));
1567 GSF_block_peer_migration_ (cp, block_time);
1574 * Setup the subsystem.
1577 GSF_pending_request_init_ ()
1579 unsigned long long bps;
1582 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, "fs",
1583 "MAX_PENDING_REQUESTS",
1584 &max_pending_requests))
1586 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1588 ("Configuration fails to specify `%s', assuming default value."),
1589 "MAX_PENDING_REQUESTS");
1592 GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "ats", "WAN_QUOTA_OUT",
1595 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1597 ("Configuration fails to specify `%s', assuming default value."),
1601 /* queue size should be #queries we can have pending and satisfy within
1602 * a carry interval: */
1603 datastore_queue_size =
1604 bps * GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S / DBLOCK_SIZE;
1606 active_to_migration =
1607 GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
1608 datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
1609 pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024);
1610 requests_by_expiration_heap =
1611 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1616 * Shutdown the subsystem.
1619 GSF_pending_request_done_ ()
1621 GNUNET_CONTAINER_multihashmap_iterate (pr_map, &clean_request, NULL);
1622 GNUNET_CONTAINER_multihashmap_destroy (pr_map);
1624 GNUNET_CONTAINER_heap_destroy (requests_by_expiration_heap);
1625 requests_by_expiration_heap = NULL;
1626 GNUNET_LOAD_value_free (datastore_put_load);
1627 datastore_put_load = NULL;
1631 /* end of gnunet-service-fs_pr.c */