2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 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 2, 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
27 * - handle SKS updates searches nicely (can wait)
28 * - handle availability probes (can wait)
29 * - make operations persistent (can wait)
30 * - handle namespace advertisements (can wait)
31 * - add support for pushing "already seen" information
32 * to FS service for bloomfilter (can wait)
36 #include "gnunet_constants.h"
37 #include "gnunet_fs_service.h"
38 #include "gnunet_protocols.h"
41 #define DEBUG_SEARCH GNUNET_YES
46 * Fill in all of the generic fields for
49 * @param pi structure to fill in
50 * @param sc overall search context
53 make_search_status (struct GNUNET_FS_ProgressInfo *pi,
54 struct GNUNET_FS_SearchContext *sc)
56 pi->value.search.sc = sc;
60 = (sc->parent == NULL) ? NULL : sc->parent->client_info;
61 pi->value.search.query
63 pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time);
64 pi->value.search.anonymity = sc->anonymity;
69 * Check if the given result is identical
72 * @param cls points to the URI we check against
74 * @param value a "struct SearchResult" who's URI we
76 * @return GNUNET_SYSERR if the result is present,
80 test_result_present (void *cls,
81 const GNUNET_HashCode * key,
84 const struct GNUNET_FS_Uri *uri = cls;
85 struct SearchResult *sr = value;
87 if (GNUNET_FS_uri_test_equal (uri,
95 * We've found a new CHK result. Let the client
98 * @param sc the search context
99 * @param sr the specific result
102 notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
103 struct SearchResult *sr)
105 struct GNUNET_FS_ProgressInfo pi;
107 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
108 make_search_status (&pi, sc);
109 pi.value.search.specifics.result.meta = sr->meta;
110 pi.value.search.specifics.result.uri = sr->uri;
111 sr->client_info = sc->h->upcb (sc->h->upcb_cls,
117 * We've found new information about an existing CHK result. Let the
118 * client know about it.
120 * @param sc the search context
121 * @param sr the specific result
124 notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
125 struct SearchResult *sr)
127 struct GNUNET_FS_ProgressInfo pi;
129 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
130 make_search_status (&pi, sc);
131 pi.value.search.specifics.update.cctx = sr->client_info;
132 pi.value.search.specifics.update.meta = sr->meta;
133 pi.value.search.specifics.update.uri = sr->uri;
134 pi.value.search.specifics.update.availability_rank
135 = 2*sr->availability_success - sr->availability_trials;
136 pi.value.search.specifics.update.availability_certainty
137 = sr->availability_trials;
138 pi.value.search.specifics.update.applicability_rank
139 = sr->optional_support;
140 sr->client_info = sc->h->upcb (sc->h->upcb_cls,
146 * Context for "get_result_present".
148 struct GetResultContext
151 * The URI we're looking for.
153 const struct GNUNET_FS_Uri *uri;
156 * Where to store a pointer to the search
157 * result struct if we found a match.
159 struct SearchResult *sr;
164 * Check if the given result is identical to the given URI and if so
167 * @param cls a "struct GetResultContext"
168 * @param key not used
169 * @param value a "struct SearchResult" who's URI we
170 * should compare with
174 get_result_present (void *cls,
175 const GNUNET_HashCode * key,
178 struct GetResultContext *grc = cls;
179 struct SearchResult *sr = value;
181 if (GNUNET_FS_uri_test_equal (grc->uri,
189 * We have received a KSK result. Check how it fits in with the
190 * overall query and notify the client accordingly.
192 * @param sc context for the overall query
193 * @param ent entry for the specific keyword
194 * @param uri the URI that was found
195 * @param meta metadata associated with the URI
196 * under the "ent" keyword
199 process_ksk_result (struct GNUNET_FS_SearchContext *sc,
200 struct SearchRequestEntry *ent,
201 const struct GNUNET_FS_Uri *uri,
202 const struct GNUNET_CONTAINER_MetaData *meta)
205 struct SearchResult *sr;
206 struct GetResultContext grc;
210 GNUNET_FS_uri_to_key (uri, &key);
212 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
214 &test_result_present,
216 return; /* duplicate result */
217 /* try to find search result in master map */
220 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
225 is_new = (NULL == sr) || (sr->mandatory_missing > 0);
228 sr = GNUNET_malloc (sizeof (struct SearchResult));
229 sr->uri = GNUNET_FS_uri_dup (uri);
230 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
231 sr->mandatory_missing = sc->mandatory_count;
232 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
235 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
239 /* FIXME: consider combining the meta data */
241 /* check if mandatory satisfied */
243 sr->mandatory_missing--;
245 sr->optional_support++;
246 if (0 != sr->mandatory_missing)
249 notify_client_chk_result (sc, sr);
251 notify_client_chk_update (sc, sr);
252 /* FIXME: consider starting probes for "sr" */
257 * Start search for content, internal API.
259 * @param h handle to the file sharing subsystem
260 * @param uri specifies the search parameters; can be
261 * a KSK URI or an SKS URI.
262 * @param anonymity desired level of anonymity
263 * @param cctx client context
264 * @param parent parent search (for namespace update searches)
265 * @return context that can be used to control the search
267 static struct GNUNET_FS_SearchContext *
268 search_start (struct GNUNET_FS_Handle *h,
269 const struct GNUNET_FS_Uri *uri,
272 struct GNUNET_FS_SearchContext *parent);
276 * We have received an SKS result. Start searching for updates and
277 * notify the client if it is a new result.
279 * @param sc context for the overall query
280 * @param id_update identifier for updates, NULL for none
281 * @param uri the URI that was found
282 * @param meta metadata associated with the URI
285 process_sks_result (struct GNUNET_FS_SearchContext *sc,
286 const char *id_update,
287 const struct GNUNET_FS_Uri *uri,
288 const struct GNUNET_CONTAINER_MetaData *meta)
290 struct GNUNET_FS_Uri uu;
292 struct SearchResult *sr;
295 GNUNET_FS_uri_to_key (uri, &key);
296 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
297 &uri->data.chk.chk.query,
300 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
302 &test_result_present,
304 return; /* duplicate result */
305 sr = GNUNET_malloc (sizeof (struct SearchResult));
306 sr->uri = GNUNET_FS_uri_dup (uri);
307 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
308 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
311 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
312 /* FIXME: consider starting probes for "sr" */
315 notify_client_chk_result (sc, sr);
316 /* search for updates */
317 if (strlen (id_update) == 0)
318 return; /* no updates */
320 uu.data.sks.namespace = sc->uri->data.sks.namespace;
321 uu.data.sks.identifier = GNUNET_strdup (id_update);
322 /* FIXME: should attach update search
323 to the individual result, not
324 the entire SKS search! */
334 * Process a keyword-search result.
336 * @param sc our search context
337 * @param kb the kblock
338 * @param size size of kb
341 process_kblock (struct GNUNET_FS_SearchContext *sc,
342 const struct KBlock *kb,
348 char pt[size - sizeof (struct KBlock)];
349 struct GNUNET_CRYPTO_AesSessionKey skey;
350 struct GNUNET_CRYPTO_AesInitializationVector iv;
352 struct GNUNET_CONTAINER_MetaData *meta;
353 struct GNUNET_FS_Uri *uri;
356 GNUNET_CRYPTO_hash (&kb->keyspace,
357 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
360 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
362 &sc->requests[i].query,
363 sizeof (GNUNET_HashCode)))
365 if (i == sc->uri->data.ksk.keywordCount)
367 /* oops, does not match any of our keywords!? */
372 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
373 GNUNET_CRYPTO_aes_decrypt (&kb[1],
374 size - sizeof (struct KBlock),
379 eos = memchr (pt, 0, sizeof (pt));
386 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
390 GNUNET_break_op (0); /* kblock malformed */
393 uri = GNUNET_FS_uri_parse (pt, &emsg);
396 GNUNET_break_op (0); /* kblock malformed */
397 GNUNET_free_non_null (emsg);
398 GNUNET_CONTAINER_meta_data_destroy (meta);
402 process_ksk_result (sc, &sc->requests[i], uri, meta);
405 GNUNET_CONTAINER_meta_data_destroy (meta);
406 GNUNET_FS_uri_destroy (uri);
411 * Process a namespace-search result.
413 * @param sc our search context
414 * @param sb the sblock
415 * @param size size of sb
418 process_sblock (struct GNUNET_FS_SearchContext *sc,
419 const struct SBlock *sb,
422 size_t len = size - sizeof (struct SBlock);
424 struct GNUNET_CRYPTO_AesSessionKey skey;
425 struct GNUNET_CRYPTO_AesInitializationVector iv;
426 struct GNUNET_FS_Uri *uri;
427 struct GNUNET_CONTAINER_MetaData *meta;
436 identifier = sc->uri->data.sks.identifier;
437 GNUNET_CRYPTO_hash (identifier,
440 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
441 GNUNET_CRYPTO_aes_decrypt (&sb[1],
447 off = GNUNET_STRINGS_buffer_tokenize (pt,
454 GNUNET_break_op (0); /* sblock malformed */
457 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off],
461 GNUNET_break_op (0); /* sblock malformed */
464 uri = GNUNET_FS_uri_parse (uris, &emsg);
467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
468 "Failed to parse URI `%s': %s\n",
470 GNUNET_break_op (0); /* sblock malformed */
471 GNUNET_free_non_null (emsg);
472 GNUNET_CONTAINER_meta_data_destroy (meta);
476 process_sks_result (sc, id, uri, meta);
478 GNUNET_FS_uri_destroy (uri);
479 GNUNET_CONTAINER_meta_data_destroy (meta);
484 * Process a search result.
486 * @param sc our search context
487 * @param type type of the result
488 * @param expiration when it will expire
489 * @param data the (encrypted) response
490 * @param size size of data
493 process_result (struct GNUNET_FS_SearchContext *sc,
495 struct GNUNET_TIME_Absolute expiration,
499 if (GNUNET_TIME_absolute_get_duration (expiration).value > 0)
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Result received has already expired.\n");
503 return; /* result expired */
507 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
508 if (! GNUNET_FS_uri_test_ksk (sc->uri))
513 if (sizeof (struct KBlock) > size)
518 process_kblock (sc, data, size);
520 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
521 if (! GNUNET_FS_uri_test_sks (sc->uri))
526 if (sizeof (struct SBlock) > size)
531 process_sblock (sc, data, size);
533 case GNUNET_DATASTORE_BLOCKTYPE_ANY:
534 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
535 case GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND:
536 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
540 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
541 _("Got result with unknown block type `%d', ignoring"),
549 * Shutdown any existing connection to the FS
550 * service and try to establish a fresh one
551 * (and then re-transmit our search request).
553 * @param sc the search to reconnec
556 try_reconnect (struct GNUNET_FS_SearchContext *sc);
560 * Type of a function to call when we receive a message
564 * @param msg message received, NULL on timeout or fatal error
567 receive_results (void *cls,
568 const struct GNUNET_MessageHeader * msg)
570 struct GNUNET_FS_SearchContext *sc = cls;
571 const struct PutMessage *cm;
574 if ( (NULL == msg) ||
575 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
576 (ntohs (msg->size) <= sizeof (struct PutMessage)) )
581 msize = ntohs (msg->size);
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "Receiving %u bytes of result from fs service\n",
585 cm = (const struct PutMessage*) msg;
588 GNUNET_TIME_absolute_ntoh (cm->expiration),
590 msize - sizeof (struct PutMessage));
591 /* continue receiving */
592 GNUNET_CLIENT_receive (sc->client,
595 GNUNET_TIME_UNIT_FOREVER_REL);
600 * We're ready to transmit the search request to the
601 * file-sharing service. Do it.
604 * @param size number of bytes available in buf
605 * @param buf where the callee should write the message
606 * @return number of bytes written to buf
609 transmit_search_request (void *cls,
613 struct GNUNET_FS_SearchContext *sc = cls;
615 struct SearchMessage *sm;
617 const char *identifier;
626 if (GNUNET_FS_uri_test_ksk (sc->uri))
628 msize = sizeof (struct SearchMessage) * sc->uri->data.ksk.keywordCount;
629 GNUNET_assert (size >= msize);
631 memset (sm, 0, msize);
632 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
634 sm[i].header.size = htons (sizeof (struct SearchMessage));
635 sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
636 sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_KBLOCK);
637 sm[i].anonymity_level = htonl (sc->anonymity);
638 sm[i].query = sc->requests[i].query;
643 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
644 msize = sizeof (struct SearchMessage);
645 GNUNET_assert (size >= msize);
647 memset (sm, 0, msize);
648 sm->header.size = htons (sizeof (struct SearchMessage));
649 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
650 sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_SBLOCK);
651 sm->anonymity_level = htonl (sc->anonymity);
652 sm->target = sc->uri->data.sks.namespace;
653 identifier = sc->uri->data.sks.identifier;
654 GNUNET_CRYPTO_hash (identifier,
657 GNUNET_CRYPTO_hash (&key,
658 sizeof (GNUNET_HashCode),
660 GNUNET_CRYPTO_hash_xor (&idh,
664 GNUNET_CLIENT_receive (sc->client,
667 GNUNET_TIME_UNIT_FOREVER_REL);
673 * Reconnect to the FS service and transmit
676 * @param cls our search context
680 do_reconnect (void *cls,
681 const struct GNUNET_SCHEDULER_TaskContext *tc)
683 struct GNUNET_FS_SearchContext *sc = cls;
684 struct GNUNET_CLIENT_Connection *client;
687 sc->task = GNUNET_SCHEDULER_NO_TASK;
688 client = GNUNET_CLIENT_connect (sc->h->sched,
697 if (GNUNET_FS_uri_test_ksk (sc->uri))
698 size = sizeof (struct SearchMessage) * sc->uri->data.ksk.keywordCount;
700 size = sizeof (struct SearchMessage);
701 GNUNET_CLIENT_notify_transmit_ready (client,
703 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
705 &transmit_search_request,
711 * Shutdown any existing connection to the FS
712 * service and try to establish a fresh one
713 * (and then re-transmit our search request).
715 * @param sc the search to reconnec
718 try_reconnect (struct GNUNET_FS_SearchContext *sc)
720 if (NULL != sc->client)
722 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
726 = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
727 GNUNET_TIME_UNIT_SECONDS,
734 * Start search for content, internal API.
736 * @param h handle to the file sharing subsystem
737 * @param uri specifies the search parameters; can be
738 * a KSK URI or an SKS URI.
739 * @param anonymity desired level of anonymity
740 * @param cctx initial value for the client context
741 * @param parent parent search (for namespace update searches)
742 * @return context that can be used to control the search
744 static struct GNUNET_FS_SearchContext *
745 search_start (struct GNUNET_FS_Handle *h,
746 const struct GNUNET_FS_Uri *uri,
749 struct GNUNET_FS_SearchContext *parent)
751 struct GNUNET_FS_SearchContext *sc;
752 struct GNUNET_CLIENT_Connection *client;
753 struct GNUNET_FS_ProgressInfo pi;
758 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
759 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
761 if (GNUNET_FS_uri_test_ksk (uri))
763 size = sizeof (struct SearchMessage) * uri->data.ksk.keywordCount;
767 GNUNET_assert (GNUNET_FS_uri_test_sks (uri));
768 size = sizeof (struct SearchMessage);
770 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
772 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
773 _("Too many keywords specified for a single search."));
776 client = GNUNET_CLIENT_connect (h->sched,
781 sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext));
783 sc->uri = GNUNET_FS_uri_dup (uri);
784 sc->anonymity = anonymity;
785 sc->start_time = GNUNET_TIME_absolute_get ();
788 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
789 sc->client_info = cctx;
790 if (GNUNET_FS_uri_test_ksk (uri))
792 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
793 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
794 sc->uri->data.ksk.keywordCount);
795 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
797 keyword = &sc->uri->data.ksk.keywords[i][1];
798 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
799 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
800 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
801 GNUNET_CRYPTO_rsa_key_free (pk);
802 GNUNET_CRYPTO_hash (&pub,
803 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
804 &sc->requests[i].query);
805 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
806 if (sc->requests[i].mandatory)
807 sc->mandatory_count++;
808 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
809 GNUNET_CRYPTO_hash (keyword,
811 &sc->requests[i].key);
815 GNUNET_CONTAINER_DLL_insert (parent->child_head,
818 pi.status = GNUNET_FS_STATUS_SEARCH_START;
819 make_search_status (&pi, sc);
820 sc->client_info = h->upcb (h->upcb_cls,
822 GNUNET_CLIENT_notify_transmit_ready (client,
824 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
826 &transmit_search_request,
833 * Start search for content.
835 * @param h handle to the file sharing subsystem
836 * @param uri specifies the search parameters; can be
837 * a KSK URI or an SKS URI.
838 * @param anonymity desired level of anonymity
839 * @param cctx initial value for the client context
840 * @return context that can be used to control the search
842 struct GNUNET_FS_SearchContext *
843 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
844 const struct GNUNET_FS_Uri *uri,
848 return search_start (h, uri, anonymity, cctx, NULL);
855 * @param sc context for the search that should be paused
858 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
860 struct GNUNET_FS_ProgressInfo pi;
862 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
863 GNUNET_SCHEDULER_cancel (sc->h->sched,
865 sc->task = GNUNET_SCHEDULER_NO_TASK;
866 if (NULL != sc->client)
867 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
869 // FIXME: make persistent!
870 // FIXME: should this freeze all active probes?
871 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
872 make_search_status (&pi, sc);
873 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
879 * Continue paused search.
881 * @param sc context for the search that should be resumed
884 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
886 struct GNUNET_FS_ProgressInfo pi;
888 GNUNET_assert (sc->client == NULL);
889 GNUNET_assert (sc->task == GNUNET_SCHEDULER_NO_TASK);
890 do_reconnect (sc, NULL);
891 // FIXME: make persistent!
892 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
893 make_search_status (&pi, sc);
894 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
900 * Free the given search result.
902 * @param cls the global FS handle
903 * @param key the key for the search result (unused)
904 * @param value the search result to free
908 search_result_free (void *cls,
909 const GNUNET_HashCode * key,
912 struct GNUNET_FS_SearchContext *sc = cls;
913 struct GNUNET_FS_Handle *h = sc->h;
914 struct SearchResult *sr = value;
915 struct GNUNET_FS_ProgressInfo pi;
917 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
918 make_search_status (&pi, sc);
919 pi.value.search.specifics.result_stopped.cctx = sr->client_info;
920 pi.value.search.specifics.result_stopped.meta = sr->meta;
921 pi.value.search.specifics.result_stopped.uri = sr->uri;
922 sr->client_info = h->upcb (h->upcb_cls,
924 GNUNET_break (NULL == sr->client_info);
926 GNUNET_FS_uri_destroy (sr->uri);
927 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
928 if (sr->probe_ctx != NULL)
930 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
932 /* FIXME: trigger starting of new
933 probes here!? Maybe not -- could
934 cause new probes to be immediately
937 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
939 GNUNET_SCHEDULER_cancel (h->sched,
940 sr->probe_cancel_task);
948 * Stop search for content.
950 * @param sc context for the search that should be stopped
953 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
955 struct GNUNET_FS_ProgressInfo pi;
957 struct GNUNET_FS_SearchContext *parent;
959 // FIXME: make un-persistent!
960 if (NULL != (parent = sc->parent))
962 GNUNET_CONTAINER_DLL_remove (parent->child_head,
967 while (NULL != sc->child_head)
968 GNUNET_FS_search_stop (sc->child_head);
969 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
972 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
973 make_search_status (&pi, sc);
974 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
976 GNUNET_break (NULL == sc->client_info);
977 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
978 GNUNET_SCHEDULER_cancel (sc->h->sched,
980 if (NULL != sc->client)
981 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
982 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
983 if (sc->requests != NULL)
985 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
986 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
987 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
989 GNUNET_free_non_null (sc->requests);
990 GNUNET_FS_uri_destroy (sc->uri);
994 /* end of fs_search.c */