2 This file is part of GNUnet.
3 (C) 2001-2006, 2008-2012 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/fs_search.c
23 * @brief Helper functions for searching.
24 * @author Christian Grothoff
28 #include "gnunet_constants.h"
29 #include "gnunet_fs_service.h"
30 #include "gnunet_protocols.h"
35 * Number of availability trials we perform per search result.
37 #define AVAILABILITY_TRIALS_MAX 8
40 * Fill in all of the generic fields for a search event and
43 * @param pi structure to fill in
44 * @param sc overall search context
45 * @return value returned by the callback
48 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
49 struct GNUNET_FS_SearchContext *sc)
53 pi->value.search.sc = sc;
54 pi->value.search.cctx = sc->client_info;
55 pi->value.search.pctx =
56 (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info;
57 pi->value.search.query = sc->uri;
58 pi->value.search.duration =
59 GNUNET_TIME_absolute_get_duration (sc->start_time);
60 pi->value.search.anonymity = sc->anonymity;
61 ret = sc->h->upcb (sc->h->upcb_cls, pi);
67 * Check if the given result is identical
70 * @param cls points to the URI we check against
72 * @param value a "struct GNUNET_FS_SearchResult" who's URI we
74 * @return GNUNET_SYSERR if the result is present,
78 test_result_present (void *cls, const GNUNET_HashCode * key, void *value)
80 const struct GNUNET_FS_Uri *uri = cls;
81 struct GNUNET_FS_SearchResult *sr = value;
83 if (GNUNET_FS_uri_test_equal (uri, sr->uri))
90 * We've found a new CHK result. Let the client
93 * @param sc the search context
94 * @param sr the specific result
97 notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
98 struct GNUNET_FS_SearchResult *sr)
100 struct GNUNET_FS_ProgressInfo pi;
102 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
103 pi.value.search.specifics.result.meta = sr->meta;
104 pi.value.search.specifics.result.uri = sr->uri;
105 pi.value.search.specifics.result.result = sr;
106 pi.value.search.specifics.result.applicability_rank = sr->optional_support;
107 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
112 * We've found new information about an existing CHK result. Let the
113 * client know about it.
115 * @param sc the search context
116 * @param sr the specific result
119 notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
120 struct GNUNET_FS_SearchResult *sr)
122 struct GNUNET_FS_ProgressInfo pi;
124 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
125 pi.value.search.specifics.update.cctx = sr->client_info;
126 pi.value.search.specifics.update.meta = sr->meta;
127 pi.value.search.specifics.update.uri = sr->uri;
128 pi.value.search.specifics.update.availability_rank =
129 2 * sr->availability_success - sr->availability_trials;
130 pi.value.search.specifics.update.availability_certainty =
131 sr->availability_trials;
132 pi.value.search.specifics.update.applicability_rank = sr->optional_support;
133 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
138 * Context for "get_result_present".
140 struct GetResultContext
143 * The URI we're looking for.
145 const struct GNUNET_FS_Uri *uri;
148 * Where to store a pointer to the search
149 * result struct if we found a match.
151 struct GNUNET_FS_SearchResult *sr;
156 * Check if the given result is identical to the given URI and if so
159 * @param cls a "struct GetResultContext"
160 * @param key not used
161 * @param value a "struct GNUNET_FS_SearchResult" who's URI we
162 * should compare with
166 get_result_present (void *cls, const GNUNET_HashCode * key, void *value)
168 struct GetResultContext *grc = cls;
169 struct GNUNET_FS_SearchResult *sr = value;
171 if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri))
178 * Signal result of last probe to client and then schedule next
182 signal_probe_result (struct GNUNET_FS_SearchResult *sr)
184 struct GNUNET_FS_ProgressInfo pi;
186 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
187 pi.value.search.specifics.update.cctx = sr->client_info;
188 pi.value.search.specifics.update.meta = sr->meta;
189 pi.value.search.specifics.update.uri = sr->uri;
190 pi.value.search.specifics.update.availability_rank = sr->availability_success;
191 pi.value.search.specifics.update.availability_certainty =
192 sr->availability_trials;
193 pi.value.search.specifics.update.applicability_rank = sr->optional_support;
194 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc);
195 GNUNET_FS_search_start_probe_ (sr);
200 * Handle the case where we have failed to receive a response for our probe.
202 * @param cls our 'struct GNUNET_FS_SearchResult*'
203 * @param tc scheduler context
206 probe_failure_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 struct GNUNET_FS_SearchResult *sr = cls;
210 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
211 sr->availability_trials++;
212 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
213 sr->probe_ctx = NULL;
214 GNUNET_FS_search_result_sync_ (sr);
215 signal_probe_result (sr);
220 * Handle the case where we have gotten a response for our probe.
222 * @param cls our 'struct GNUNET_FS_SearchResult*'
223 * @param tc scheduler context
226 probe_success_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228 struct GNUNET_FS_SearchResult *sr = cls;
230 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
231 sr->availability_trials++;
232 sr->availability_success++;
233 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
234 sr->probe_ctx = NULL;
235 GNUNET_FS_search_result_sync_ (sr);
236 signal_probe_result (sr);
241 * Notification of FS that a search probe has made progress.
242 * This function is used INSTEAD of the client's event handler
243 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
245 * @param cls closure, always NULL (!), actual closure
246 * is in the client-context of the info struct
247 * @param info details about the event, specifying the event type
248 * and various bits about the event
249 * @return client-context (for the next progress call
250 * for this operation; should be set to NULL for
251 * SUSPEND and STOPPED events). The value returned
252 * will be passed to future callbacks in the respective
253 * field in the GNUNET_FS_ProgressInfo struct.
256 GNUNET_FS_search_probe_progress_ (void *cls,
257 const struct GNUNET_FS_ProgressInfo *info)
259 struct GNUNET_FS_SearchResult *sr = info->value.download.cctx;
260 struct GNUNET_TIME_Relative dur;
262 switch (info->status)
264 case GNUNET_FS_STATUS_DOWNLOAD_START:
267 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
268 /* probes should never be resumed */
271 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
272 /* probes should never be suspended */
275 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
278 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
279 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
281 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
282 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
284 sr->probe_cancel_task =
285 GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
286 &probe_failure_handler, sr);
288 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
289 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
291 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
292 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
294 sr->probe_cancel_task =
295 GNUNET_SCHEDULER_add_now (&probe_success_handler, sr);
297 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
298 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
300 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
301 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
305 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
306 GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK);
307 sr->probe_active_time = GNUNET_TIME_absolute_get ();
308 sr->probe_cancel_task =
309 GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
310 &probe_failure_handler, sr);
312 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
313 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
315 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
316 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
318 dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
319 sr->remaining_probe_time =
320 GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur);
321 GNUNET_FS_search_result_sync_ (sr);
332 * Start download probes for the given search result.
334 * @param sr the search result
337 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
342 if (sr->probe_ctx != NULL)
344 if (sr->download != NULL)
346 if (0 == (sr->sc->h->flags & GNUNET_FS_FLAGS_DO_PROBES))
348 if (sr->availability_trials > AVAILABILITY_TRIALS_MAX)
350 len = GNUNET_FS_uri_chk_get_file_size (sr->uri);
353 if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0))
355 off = len / DBLOCK_SIZE;
357 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, off);
359 if (len - off < DBLOCK_SIZE)
363 sr->remaining_probe_time =
364 GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency,
365 2 * (1 + sr->availability_trials));
367 GNUNET_FS_download_start (sr->sc->h, sr->uri, sr->meta, NULL, NULL, off,
368 len, sr->sc->anonymity,
369 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
370 GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
375 * We have received a KSK result. Check how it fits in with the
376 * overall query and notify the client accordingly.
378 * @param sc context for the overall query
379 * @param ent entry for the specific keyword
380 * @param uri the URI that was found
381 * @param meta metadata associated with the URI
382 * under the "ent" keyword
385 process_ksk_result (struct GNUNET_FS_SearchContext *sc,
386 struct SearchRequestEntry *ent,
387 const struct GNUNET_FS_Uri *uri,
388 const struct GNUNET_CONTAINER_MetaData *meta)
391 struct GNUNET_FS_SearchResult *sr;
392 struct GetResultContext grc;
397 GNUNET_assert (NULL != sc);
398 GNUNET_FS_uri_to_key (uri, &key);
400 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, &key,
401 &test_result_present,
403 return; /* duplicate result */
404 /* try to find search result in master map */
407 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
408 &get_result_present, &grc);
410 is_new = (NULL == sr) || (sr->mandatory_missing > 0);
413 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
415 sr->uri = GNUNET_FS_uri_dup (uri);
416 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
417 sr->mandatory_missing = sc->mandatory_count;
419 sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
420 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
421 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
425 GNUNET_CONTAINER_meta_data_merge (sr->meta, meta);
427 koff = ent - sc->requests;
428 GNUNET_assert ( (ent >= sc->requests) && (koff < sc->uri->data.ksk.keywordCount));
429 sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8));
430 /* check if mandatory satisfied */
432 sr->mandatory_missing--;
434 sr->optional_support++;
435 if (0 != sr->mandatory_missing)
438 notify_client_chk_result (sc, sr);
440 notify_client_chk_update (sc, sr);
441 GNUNET_FS_search_result_sync_ (sr);
442 GNUNET_FS_search_start_probe_ (sr);
447 * Start search for content, internal API.
449 * @param h handle to the file sharing subsystem
450 * @param uri specifies the search parameters; can be
451 * a KSK URI or an SKS URI.
452 * @param anonymity desired level of anonymity
453 * @param options options for the search
454 * @param cctx client context
455 * @param psearch parent search result (for namespace update searches)
456 * @return context that can be used to control the search
458 static struct GNUNET_FS_SearchContext *
459 search_start (struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri,
460 uint32_t anonymity, enum GNUNET_FS_SearchOptions options,
461 void *cctx, struct GNUNET_FS_SearchResult *psearch);
465 * We have received an SKS result. Start searching for updates and
466 * notify the client if it is a new result.
468 * @param sc context for the overall query
469 * @param id_update identifier for updates, NULL for none
470 * @param uri the URI that was found
471 * @param meta metadata associated with the URI
474 process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
475 const struct GNUNET_FS_Uri *uri,
476 const struct GNUNET_CONTAINER_MetaData *meta)
478 struct GNUNET_FS_Uri uu;
480 struct GNUNET_FS_SearchResult *sr;
483 GNUNET_assert (NULL != sc);
484 GNUNET_FS_uri_to_key (uri, &key);
485 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query,
488 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
489 &test_result_present,
491 return; /* duplicate result */
492 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
494 sr->uri = GNUNET_FS_uri_dup (uri);
495 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
497 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
498 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
499 GNUNET_FS_search_result_sync_ (sr);
500 GNUNET_FS_search_start_probe_ (sr);
502 notify_client_chk_result (sc, sr);
503 /* search for updates */
504 if (strlen (id_update) == 0)
505 return; /* no updates */
507 uu.data.sks.namespace = sc->uri->data.sks.namespace;
508 uu.data.sks.identifier = GNUNET_strdup (id_update);
509 (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr);
510 GNUNET_free (uu.data.sks.identifier);
515 * Decrypt a block using a 'keyword' as the passphrase. Given the
516 * KSK public key derived from the keyword, this function looks up
517 * the original keyword in the search context and decrypts the
518 * given ciphertext block.
520 * @param sc search context with the keywords
521 * @param public_key public key to use to lookup the keyword
522 * @param edata encrypted data
523 * @param edata_size number of bytes in 'edata' (and 'data')
524 * @param data where to store the plaintext
525 * @return keyword index on success, GNUNET_SYSERR on error (no such
526 * keyword, internal error)
529 decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
530 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
536 struct GNUNET_CRYPTO_AesSessionKey skey;
537 struct GNUNET_CRYPTO_AesInitializationVector iv;
540 GNUNET_CRYPTO_hash (public_key,
541 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
544 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
545 if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode)))
547 if (i == sc->uri->data.ksk.keywordCount)
549 /* oops, does not match any of our keywords!? */
551 return GNUNET_SYSERR;
554 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
556 GNUNET_CRYPTO_aes_decrypt (edata, edata_size, &skey,
560 return GNUNET_SYSERR;
567 * Process a keyword-search result.
569 * @param sc our search context
570 * @param kb the kblock
571 * @param size size of kb
574 process_kblock (struct GNUNET_FS_SearchContext *sc, const struct KBlock *kb,
578 char pt[size - sizeof (struct KBlock)];
580 struct GNUNET_CONTAINER_MetaData *meta;
581 struct GNUNET_FS_Uri *uri;
585 if (-1 == (i = decrypt_block_with_keyword (sc,
588 size - sizeof (struct KBlock),
592 eos = memchr (pt, 0, sizeof (pt));
599 if (sizeof (pt) == j)
600 meta = GNUNET_CONTAINER_meta_data_create ();
602 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
605 GNUNET_break_op (0); /* kblock malformed */
608 uri = GNUNET_FS_uri_parse (pt, &emsg);
611 GNUNET_break_op (0); /* kblock malformed */
612 GNUNET_free_non_null (emsg);
613 GNUNET_CONTAINER_meta_data_destroy (meta);
617 process_ksk_result (sc, &sc->requests[i], uri, meta);
620 GNUNET_CONTAINER_meta_data_destroy (meta);
621 GNUNET_FS_uri_destroy (uri);
626 * Process a keyword-search result with a namespace advertisment.
628 * @param sc our search context
629 * @param nb the nblock
630 * @param size size of nb
633 process_nblock (struct GNUNET_FS_SearchContext *sc, const struct NBlock *nb,
637 char pt[size - sizeof (struct NBlock)];
639 struct GNUNET_CONTAINER_MetaData *meta;
640 struct GNUNET_FS_Uri *uri;
644 if (-1 == (i = decrypt_block_with_keyword (sc,
647 size - sizeof (struct NBlock),
651 eos = memchr (pt, 0, sizeof (pt));
658 if (sizeof (pt) == j)
659 meta = GNUNET_CONTAINER_meta_data_create ();
661 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j);
664 GNUNET_break_op (0); /* nblock malformed */
668 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
670 uri->data.sks.identifier = GNUNET_strdup (pt);
671 GNUNET_CRYPTO_hash (&nb->subspace,
672 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
673 &uri->data.sks.namespace);
674 uris = GNUNET_FS_uri_to_string (uri);
675 GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", EXTRACTOR_METATYPE_URI,
676 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
677 uris, strlen (uris) + 1);
679 GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta);
681 process_ksk_result (sc, &sc->requests[i], uri, meta);
684 GNUNET_CONTAINER_meta_data_destroy (meta);
685 GNUNET_FS_uri_destroy (uri);
690 * Process a namespace-search result.
692 * @param sc our search context
693 * @param sb the sblock
694 * @param size size of sb
697 process_sblock (struct GNUNET_FS_SearchContext *sc, const struct SBlock *sb,
700 size_t len = size - sizeof (struct SBlock);
702 struct GNUNET_CRYPTO_AesSessionKey skey;
703 struct GNUNET_CRYPTO_AesInitializationVector iv;
704 struct GNUNET_FS_Uri *uri;
705 struct GNUNET_CONTAINER_MetaData *meta;
714 identifier = sc->uri->data.sks.identifier;
715 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
716 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
717 if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], len, &skey, &iv, pt))
723 off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris);
726 GNUNET_break_op (0); /* sblock malformed */
729 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off);
732 GNUNET_break_op (0); /* sblock malformed */
735 uri = GNUNET_FS_uri_parse (uris, &emsg);
738 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse URI `%s': %s\n", uris,
740 GNUNET_break_op (0); /* sblock malformed */
741 GNUNET_free_non_null (emsg);
742 GNUNET_CONTAINER_meta_data_destroy (meta);
746 process_sks_result (sc, id, uri, meta);
748 GNUNET_FS_uri_destroy (uri);
749 GNUNET_CONTAINER_meta_data_destroy (meta);
754 * Process a search result.
756 * @param sc our search context
757 * @param type type of the result
758 * @param expiration when it will expire
759 * @param data the (encrypted) response
760 * @param size size of data
763 process_result (struct GNUNET_FS_SearchContext *sc, enum GNUNET_BLOCK_Type type,
764 struct GNUNET_TIME_Absolute expiration, const void *data,
767 if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0)
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Result received has already expired.\n");
771 return; /* result expired */
775 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
776 if (!GNUNET_FS_uri_test_ksk (sc->uri))
781 if (sizeof (struct KBlock) > size)
786 process_kblock (sc, data, size);
788 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
789 if (!GNUNET_FS_uri_test_sks (sc->uri))
794 if (sizeof (struct SBlock) > size)
799 process_sblock (sc, data, size);
801 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
802 if (!GNUNET_FS_uri_test_ksk (sc->uri))
807 if (sizeof (struct NBlock) > size)
812 process_nblock (sc, data, size);
814 case GNUNET_BLOCK_TYPE_ANY:
817 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
820 case GNUNET_BLOCK_TYPE_FS_ONDEMAND:
823 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
827 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
828 _("Got result with unknown block type `%d', ignoring"), type);
835 * Shutdown any existing connection to the FS
836 * service and try to establish a fresh one
837 * (and then re-transmit our search request).
839 * @param sc the search to reconnec
842 try_reconnect (struct GNUNET_FS_SearchContext *sc);
846 * Type of a function to call when we receive a message
850 * @param msg message received, NULL on timeout or fatal error
853 receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
855 struct GNUNET_FS_SearchContext *sc = cls;
856 const struct ClientPutMessage *cm;
859 if ((NULL == msg) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
860 (ntohs (msg->size) <= sizeof (struct ClientPutMessage)))
865 msize = ntohs (msg->size);
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
867 "Receiving %u bytes of result from fs service\n", msize);
868 cm = (const struct ClientPutMessage *) msg;
869 process_result (sc, ntohl (cm->type),
870 GNUNET_TIME_absolute_ntoh (cm->expiration), &cm[1],
871 msize - sizeof (struct ClientPutMessage));
872 /* continue receiving */
873 GNUNET_CLIENT_receive (sc->client, &receive_results, sc,
874 GNUNET_TIME_UNIT_FOREVER_REL);
879 * Schedule the transmission of the (next) search request
882 * @param sc context for the search
885 schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc);
889 * Closure for 'build_result_set'.
891 struct MessageBuilderContext
894 * How many entries can we store to xoff.
896 unsigned int put_cnt;
899 * How many entries should we skip.
901 unsigned int skip_cnt;
904 * Where to store the keys.
906 GNUNET_HashCode *xoff;
909 * Search context we are iterating for.
911 struct GNUNET_FS_SearchContext *sc;
914 * Keyword offset the search result must match (0 for SKS)
916 unsigned int keyword_offset;
921 * Iterating over the known results, pick those matching the given
922 * result range and store their keys at 'xoff'.
924 * @param cls the 'struct MessageBuilderContext'
925 * @param key key for a result
926 * @param value the search result
927 * @return GNUNET_OK to continue iterating
930 build_result_set (void *cls, const GNUNET_HashCode * key, void *value)
932 struct MessageBuilderContext *mbc = cls;
933 struct GNUNET_FS_SearchResult *sr = value;
935 if ( (sr->keyword_bitmap != NULL) &&
936 (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) )
937 return GNUNET_OK; /* have no match for this keyword yet */
938 if (mbc->skip_cnt > 0)
943 if (mbc->put_cnt == 0)
944 return GNUNET_SYSERR;
945 mbc->sc->search_request_map_offset++;
946 mbc->xoff[--mbc->put_cnt] = *key;
952 * Iterating over the known results, count those
953 * matching the given result range and increment
954 * put count for each.
956 * @param cls the 'struct MessageBuilderContext'
957 * @param key key for a result
958 * @param value the search result
959 * @return GNUNET_OK to continue iterating
962 find_result_set (void *cls, const GNUNET_HashCode * key, void *value)
964 struct MessageBuilderContext *mbc = cls;
965 struct GNUNET_FS_SearchResult *sr = value;
967 if ( (sr->keyword_bitmap != NULL) &&
968 (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1 << (mbc->keyword_offset % 8)))) )
969 return GNUNET_OK; /* have no match for this keyword yet */
976 * We're ready to transmit the search request to the
977 * file-sharing service. Do it.
980 * @param size number of bytes available in buf
981 * @param buf where the callee should write the message
982 * @return number of bytes written to buf
985 transmit_search_request (void *cls, size_t size, void *buf)
987 struct GNUNET_FS_SearchContext *sc = cls;
988 struct MessageBuilderContext mbc;
990 struct SearchMessage *sm;
991 const char *identifier;
1003 mbc.skip_cnt = sc->search_request_map_offset;
1005 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
1006 mbc.xoff = (GNUNET_HashCode *) & sm[1];
1007 options = SEARCH_MESSAGE_OPTION_NONE;
1008 if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
1009 options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY;
1010 if (GNUNET_FS_uri_test_ksk (sc->uri))
1012 msize = sizeof (struct SearchMessage);
1013 GNUNET_assert (size >= msize);
1014 mbc.keyword_offset = sc->keyword_offset;
1016 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1017 &find_result_set, &mbc);
1019 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1020 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
1021 if (sc->search_request_map_offset < sqms)
1022 GNUNET_assert (mbc.put_cnt > 0);
1024 sm->header.size = htons (msize);
1025 sm->type = htonl (GNUNET_BLOCK_TYPE_ANY);
1026 sm->anonymity_level = htonl (sc->anonymity);
1027 memset (&sm->target, 0, sizeof (GNUNET_HashCode));
1028 sm->query = sc->requests[sc->keyword_offset].query;
1029 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1030 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1031 &build_result_set, &mbc);
1032 sm->header.size = htons (msize);
1033 GNUNET_assert (sqms >= sc->search_request_map_offset);
1034 if (sqms != sc->search_request_map_offset)
1036 /* more requesting to be done... */
1037 sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED);
1038 schedule_transmit_search_request (sc);
1041 sm->options = htonl (options);
1042 sc->keyword_offset++;
1043 if (sc->uri->data.ksk.keywordCount != sc->keyword_offset)
1045 /* more requesting to be done... */
1046 schedule_transmit_search_request (sc);
1052 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
1053 msize = sizeof (struct SearchMessage);
1054 GNUNET_assert (size >= msize);
1055 sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK);
1056 sm->anonymity_level = htonl (sc->anonymity);
1057 sm->target = sc->uri->data.sks.namespace;
1058 identifier = sc->uri->data.sks.identifier;
1059 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key);
1060 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &idh);
1061 GNUNET_CRYPTO_hash_xor (&idh, &sm->target, &sm->query);
1062 mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode);
1063 sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
1064 mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt);
1065 mbc.keyword_offset = 0;
1066 if (sc->search_request_map_offset < sqms)
1067 GNUNET_assert (mbc.put_cnt > 0);
1068 msize += sizeof (GNUNET_HashCode) * mbc.put_cnt;
1069 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1070 &build_result_set, &mbc);
1071 sm->header.size = htons (msize);
1072 GNUNET_assert (sqms >= sc->search_request_map_offset);
1073 if (sqms != sc->search_request_map_offset)
1075 /* more requesting to be done... */
1076 sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED);
1077 schedule_transmit_search_request (sc);
1080 sm->options = htonl (options);
1082 GNUNET_CLIENT_receive (sc->client, &receive_results, sc,
1083 GNUNET_TIME_UNIT_FOREVER_REL);
1089 * Schedule the transmission of the (next) search request
1092 * @param sc context for the search
1095 schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc)
1101 size = sizeof (struct SearchMessage);
1103 GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) -
1104 sc->search_request_map_offset;
1105 fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode);
1106 fit = GNUNET_MIN (fit, sqms);
1107 size += sizeof (GNUNET_HashCode) * fit;
1108 GNUNET_CLIENT_notify_transmit_ready (sc->client, size,
1109 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1110 GNUNET_NO, &transmit_search_request, sc);
1116 * Reconnect to the FS service and transmit
1119 * @param cls our search context
1123 do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1125 struct GNUNET_FS_SearchContext *sc = cls;
1126 struct GNUNET_CLIENT_Connection *client;
1128 sc->task = GNUNET_SCHEDULER_NO_TASK;
1129 client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
1135 sc->client = client;
1136 sc->search_request_map_offset = 0;
1137 sc->keyword_offset = 0;
1138 schedule_transmit_search_request (sc);
1143 * Shutdown any existing connection to the FS
1144 * service and try to establish a fresh one
1145 * (and then re-transmit our search request).
1147 * @param sc the search to reconnec
1150 try_reconnect (struct GNUNET_FS_SearchContext *sc)
1152 if (NULL != sc->client)
1154 GNUNET_CLIENT_disconnect (sc->client);
1158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_reconnect,
1164 * Start search for content, internal API.
1166 * @param h handle to the file sharing subsystem
1167 * @param uri specifies the search parameters; can be
1168 * a KSK URI or an SKS URI.
1169 * @param anonymity desired level of anonymity
1170 * @param options options for the search
1171 * @param cctx initial value for the client context
1172 * @param psearch parent search result (for namespace update searches)
1173 * @return context that can be used to control the search
1175 static struct GNUNET_FS_SearchContext *
1176 search_start (struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri,
1177 uint32_t anonymity, enum GNUNET_FS_SearchOptions options,
1178 void *cctx, struct GNUNET_FS_SearchResult *psearch)
1180 struct GNUNET_FS_SearchContext *sc;
1181 struct GNUNET_FS_ProgressInfo pi;
1183 sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
1185 sc->options = options;
1186 sc->uri = GNUNET_FS_uri_dup (uri);
1187 sc->anonymity = anonymity;
1188 sc->start_time = GNUNET_TIME_absolute_get ();
1189 if (psearch != NULL)
1191 sc->psearch_result = psearch;
1192 psearch->update_search = sc;
1194 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
1195 sc->client_info = cctx;
1196 if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))
1198 GNUNET_FS_uri_destroy (sc->uri);
1199 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1203 GNUNET_FS_search_sync_ (sc);
1204 pi.status = GNUNET_FS_STATUS_SEARCH_START;
1205 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1211 * Build the request and actually initiate the search using the
1212 * GNUnet FS service.
1214 * @param sc search context
1215 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1218 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1221 const char *keyword;
1223 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
1224 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
1226 GNUNET_assert (NULL == sc->client);
1227 if (GNUNET_FS_uri_test_ksk (sc->uri))
1229 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
1231 GNUNET_malloc (sizeof (struct SearchRequestEntry) *
1232 sc->uri->data.ksk.keywordCount);
1233 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1235 keyword = &sc->uri->data.ksk.keywords[i][1];
1236 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
1237 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
1238 GNUNET_assert (pk != NULL);
1239 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
1240 GNUNET_CRYPTO_rsa_key_free (pk);
1241 GNUNET_CRYPTO_hash (&pub,
1243 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1244 &sc->requests[i].query);
1245 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
1246 if (sc->requests[i].mandatory)
1247 sc->mandatory_count++;
1248 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
1249 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].key);
1252 sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg);
1253 if (NULL == sc->client)
1254 return GNUNET_SYSERR;
1255 schedule_transmit_search_request (sc);
1261 * Freeze probes for the given search result.
1263 * @param cls the global FS handle
1264 * @param key the key for the search result (unused)
1265 * @param value the search result to free
1269 search_result_freeze_probes (void *cls, const GNUNET_HashCode * key,
1272 struct GNUNET_FS_SearchResult *sr = value;
1274 if (sr->probe_ctx != NULL)
1276 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1277 sr->probe_ctx = NULL;
1279 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1281 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1282 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
1284 if (sr->update_search != NULL)
1285 GNUNET_FS_search_pause (sr->update_search);
1291 * Resume probes for the given search result.
1293 * @param cls the global FS handle
1294 * @param key the key for the search result (unused)
1295 * @param value the search result to free
1299 search_result_resume_probes (void *cls, const GNUNET_HashCode * key,
1302 struct GNUNET_FS_SearchResult *sr = value;
1304 GNUNET_FS_search_start_probe_ (sr);
1305 if (sr->update_search != NULL)
1306 GNUNET_FS_search_continue (sr->update_search);
1312 * Signal suspend and free the given search result.
1314 * @param cls the global FS handle
1315 * @param key the key for the search result (unused)
1316 * @param value the search result to free
1320 search_result_suspend (void *cls, const GNUNET_HashCode * key, void *value)
1322 struct GNUNET_FS_SearchContext *sc = cls;
1323 struct GNUNET_FS_SearchResult *sr = value;
1324 struct GNUNET_FS_ProgressInfo pi;
1326 if (sr->download != NULL)
1327 GNUNET_FS_download_signal_suspend_ (sr->download);
1328 if (sr->update_search != NULL)
1329 GNUNET_FS_search_signal_suspend_ (sr->update_search);
1330 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND;
1331 pi.value.search.specifics.result_suspend.cctx = sr->client_info;
1332 pi.value.search.specifics.result_suspend.meta = sr->meta;
1333 pi.value.search.specifics.result_suspend.uri = sr->uri;
1334 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1335 GNUNET_break (NULL == sr->client_info);
1336 GNUNET_free_non_null (sr->serialization);
1337 GNUNET_FS_uri_destroy (sr->uri);
1338 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
1339 if (sr->probe_ctx != NULL)
1340 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1341 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1342 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1343 GNUNET_free_non_null (sr->keyword_bitmap);
1350 * Create SUSPEND event for the given search operation
1351 * and then clean up our state (without stop signal).
1353 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1356 GNUNET_FS_search_signal_suspend_ (void *cls)
1358 struct GNUNET_FS_SearchContext *sc = cls;
1359 struct GNUNET_FS_ProgressInfo pi;
1362 GNUNET_FS_end_top (sc->h, sc->top);
1363 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1364 &search_result_suspend, sc);
1365 pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND;
1366 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1367 GNUNET_break (NULL == sc->client_info);
1368 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
1369 GNUNET_SCHEDULER_cancel (sc->task);
1370 if (NULL != sc->client)
1371 GNUNET_CLIENT_disconnect (sc->client);
1372 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1373 if (sc->requests != NULL)
1375 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1376 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1377 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1379 GNUNET_free_non_null (sc->requests);
1380 GNUNET_free_non_null (sc->emsg);
1381 GNUNET_FS_uri_destroy (sc->uri);
1382 GNUNET_free_non_null (sc->serialization);
1388 * Start search for content.
1390 * @param h handle to the file sharing subsystem
1391 * @param uri specifies the search parameters; can be
1392 * a KSK URI or an SKS URI.
1393 * @param anonymity desired level of anonymity
1394 * @param options options for the search
1395 * @param cctx initial value for the client context
1396 * @return context that can be used to control the search
1398 struct GNUNET_FS_SearchContext *
1399 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1400 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
1401 enum GNUNET_FS_SearchOptions options, void *cctx)
1403 struct GNUNET_FS_SearchContext *ret;
1405 ret = search_start (h, uri, anonymity, options, cctx, NULL);
1408 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret);
1416 * @param sc context for the search that should be paused
1419 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1421 struct GNUNET_FS_ProgressInfo pi;
1423 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
1424 GNUNET_SCHEDULER_cancel (sc->task);
1425 sc->task = GNUNET_SCHEDULER_NO_TASK;
1426 if (NULL != sc->client)
1427 GNUNET_CLIENT_disconnect (sc->client);
1429 GNUNET_FS_search_sync_ (sc);
1430 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1431 &search_result_freeze_probes, sc);
1432 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
1433 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1438 * Continue paused search.
1440 * @param sc context for the search that should be resumed
1443 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1445 struct GNUNET_FS_ProgressInfo pi;
1447 GNUNET_assert (sc->client == NULL);
1448 GNUNET_assert (sc->task == GNUNET_SCHEDULER_NO_TASK);
1449 do_reconnect (sc, NULL);
1450 GNUNET_FS_search_sync_ (sc);
1451 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
1452 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1453 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1454 &search_result_resume_probes, sc);
1459 * Signal stop for the given search result.
1461 * @param cls the global FS handle
1462 * @param key the key for the search result (unused)
1463 * @param value the search result to free
1467 search_result_stop (void *cls, const GNUNET_HashCode * key, void *value)
1469 struct GNUNET_FS_SearchContext *sc = cls;
1470 struct GNUNET_FS_SearchResult *sr = value;
1471 struct GNUNET_FS_ProgressInfo pi;
1473 if (NULL != sr->download)
1475 sr->download->search = NULL;
1477 GNUNET_FS_make_top (sr->download->h,
1478 &GNUNET_FS_download_signal_suspend_, sr->download);
1479 if (NULL != sr->download->serialization)
1481 GNUNET_FS_remove_sync_file_ (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1482 sr->download->serialization);
1483 GNUNET_free (sr->download->serialization);
1484 sr->download->serialization = NULL;
1486 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
1487 GNUNET_FS_download_make_status_ (&pi, sr->download);
1488 GNUNET_FS_download_sync_ (sr->download);
1489 sr->download = NULL;
1491 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
1492 pi.value.search.specifics.result_stopped.cctx = sr->client_info;
1493 pi.value.search.specifics.result_stopped.meta = sr->meta;
1494 pi.value.search.specifics.result_stopped.uri = sr->uri;
1495 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1501 * Free the given search result.
1503 * @param cls the global FS handle
1504 * @param key the key for the search result (unused)
1505 * @param value the search result to free
1509 search_result_free (void *cls, const GNUNET_HashCode * key, void *value)
1511 struct GNUNET_FS_SearchResult *sr = value;
1513 if (NULL != sr->update_search)
1515 GNUNET_FS_search_stop (sr->update_search);
1516 GNUNET_assert (sr->update_search == NULL);
1518 GNUNET_break (NULL == sr->client_info);
1519 GNUNET_free_non_null (sr->serialization);
1520 GNUNET_FS_uri_destroy (sr->uri);
1521 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
1522 if (sr->probe_ctx != NULL)
1523 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1524 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1525 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1526 GNUNET_free_non_null (sr->keyword_bitmap);
1533 * Stop search for content.
1535 * @param sc context for the search that should be stopped
1538 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1540 struct GNUNET_FS_ProgressInfo pi;
1543 if (sc->top != NULL)
1544 GNUNET_FS_end_top (sc->h, sc->top);
1545 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1546 &search_result_stop, sc);
1547 if (sc->psearch_result != NULL)
1548 sc->psearch_result->update_search = NULL;
1549 if (sc->serialization != NULL)
1551 GNUNET_FS_remove_sync_file_ (sc->h,
1552 (sc->psearch_result !=
1553 NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH :
1554 GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1556 GNUNET_FS_remove_sync_dir_ (sc->h,
1557 (sc->psearch_result !=
1558 NULL) ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH :
1559 GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1561 GNUNET_free (sc->serialization);
1563 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
1564 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1565 GNUNET_break (NULL == sc->client_info);
1566 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
1567 GNUNET_SCHEDULER_cancel (sc->task);
1568 if (NULL != sc->client)
1569 GNUNET_CLIENT_disconnect (sc->client);
1570 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1571 &search_result_free, sc);
1572 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1573 if (sc->requests != NULL)
1575 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1576 for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
1577 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1579 GNUNET_free_non_null (sc->requests);
1580 GNUNET_free_non_null (sc->emsg);
1581 GNUNET_FS_uri_destroy (sc->uri);
1585 /* end of fs_search.c */