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 namespace advertisements (can wait; might already work!?)
28 * - add support for pushing "already seen" information
29 * to FS service for bloomfilter (can wait)
30 * - handle availability probes (can wait)
31 * - make operations persistent (can wait)
35 #include "gnunet_constants.h"
36 #include "gnunet_fs_service.h"
37 #include "gnunet_protocols.h"
40 #define DEBUG_SEARCH GNUNET_NO
45 * Fill in all of the generic fields for
48 * @param pi structure to fill in
49 * @param sc overall search context
52 make_search_status (struct GNUNET_FS_ProgressInfo *pi,
53 struct GNUNET_FS_SearchContext *sc)
55 pi->value.search.sc = sc;
59 = (sc->parent == NULL) ? NULL : sc->parent->client_info;
60 pi->value.search.query
62 pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time);
63 pi->value.search.anonymity = sc->anonymity;
68 * Check if the given result is identical
71 * @param cls points to the URI we check against
73 * @param value a "struct SearchResult" who's URI we
75 * @return GNUNET_SYSERR if the result is present,
79 test_result_present (void *cls,
80 const GNUNET_HashCode * key,
83 const struct GNUNET_FS_Uri *uri = cls;
84 struct SearchResult *sr = value;
86 if (GNUNET_FS_uri_test_equal (uri,
94 * We've found a new CHK result. Let the client
97 * @param sc the search context
98 * @param sr the specific result
101 notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
102 struct SearchResult *sr)
104 struct GNUNET_FS_ProgressInfo pi;
106 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
107 make_search_status (&pi, sc);
108 pi.value.search.specifics.result.meta = sr->meta;
109 pi.value.search.specifics.result.uri = sr->uri;
110 sr->client_info = sc->h->upcb (sc->h->upcb_cls,
116 * We've found new information about an existing CHK result. Let the
117 * client know about it.
119 * @param sc the search context
120 * @param sr the specific result
123 notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
124 struct SearchResult *sr)
126 struct GNUNET_FS_ProgressInfo pi;
128 pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
129 make_search_status (&pi, sc);
130 pi.value.search.specifics.update.cctx = sr->client_info;
131 pi.value.search.specifics.update.meta = sr->meta;
132 pi.value.search.specifics.update.uri = sr->uri;
133 pi.value.search.specifics.update.availability_rank
134 = 2*sr->availability_success - sr->availability_trials;
135 pi.value.search.specifics.update.availability_certainty
136 = sr->availability_trials;
137 pi.value.search.specifics.update.applicability_rank
138 = sr->optional_support;
139 sr->client_info = sc->h->upcb (sc->h->upcb_cls,
145 * Context for "get_result_present".
147 struct GetResultContext
150 * The URI we're looking for.
152 const struct GNUNET_FS_Uri *uri;
155 * Where to store a pointer to the search
156 * result struct if we found a match.
158 struct SearchResult *sr;
163 * Check if the given result is identical to the given URI and if so
166 * @param cls a "struct GetResultContext"
167 * @param key not used
168 * @param value a "struct SearchResult" who's URI we
169 * should compare with
173 get_result_present (void *cls,
174 const GNUNET_HashCode * key,
177 struct GetResultContext *grc = cls;
178 struct SearchResult *sr = value;
180 if (GNUNET_FS_uri_test_equal (grc->uri,
188 * We have received a KSK result. Check how it fits in with the
189 * overall query and notify the client accordingly.
191 * @param sc context for the overall query
192 * @param ent entry for the specific keyword
193 * @param uri the URI that was found
194 * @param meta metadata associated with the URI
195 * under the "ent" keyword
198 process_ksk_result (struct GNUNET_FS_SearchContext *sc,
199 struct SearchRequestEntry *ent,
200 const struct GNUNET_FS_Uri *uri,
201 const struct GNUNET_CONTAINER_MetaData *meta)
204 struct SearchResult *sr;
205 struct GetResultContext grc;
209 GNUNET_FS_uri_to_key (uri, &key);
211 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
213 &test_result_present,
215 return; /* duplicate result */
216 /* try to find search result in master map */
219 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
224 is_new = (NULL == sr) || (sr->mandatory_missing > 0);
227 sr = GNUNET_malloc (sizeof (struct SearchResult));
228 sr->uri = GNUNET_FS_uri_dup (uri);
229 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
230 sr->mandatory_missing = sc->mandatory_count;
231 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
234 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
238 /* FIXME: consider combining the meta data */
240 /* check if mandatory satisfied */
242 sr->mandatory_missing--;
244 sr->optional_support++;
245 if (0 != sr->mandatory_missing)
248 notify_client_chk_result (sc, sr);
250 notify_client_chk_update (sc, sr);
251 /* FIXME: consider starting probes for "sr" */
256 * Start search for content, internal API.
258 * @param h handle to the file sharing subsystem
259 * @param uri specifies the search parameters; can be
260 * a KSK URI or an SKS URI.
261 * @param anonymity desired level of anonymity
262 * @param cctx client context
263 * @param parent parent search (for namespace update searches)
264 * @return context that can be used to control the search
266 static struct GNUNET_FS_SearchContext *
267 search_start (struct GNUNET_FS_Handle *h,
268 const struct GNUNET_FS_Uri *uri,
271 struct GNUNET_FS_SearchContext *parent);
275 * We have received an SKS result. Start searching for updates and
276 * notify the client if it is a new result.
278 * @param sc context for the overall query
279 * @param id_update identifier for updates, NULL for none
280 * @param uri the URI that was found
281 * @param meta metadata associated with the URI
284 process_sks_result (struct GNUNET_FS_SearchContext *sc,
285 const char *id_update,
286 const struct GNUNET_FS_Uri *uri,
287 const struct GNUNET_CONTAINER_MetaData *meta)
289 struct GNUNET_FS_Uri uu;
291 struct SearchResult *sr;
294 GNUNET_FS_uri_to_key (uri, &key);
295 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
296 &uri->data.chk.chk.query,
299 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
301 &test_result_present,
303 return; /* duplicate result */
304 sr = GNUNET_malloc (sizeof (struct SearchResult));
305 sr->uri = GNUNET_FS_uri_dup (uri);
306 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
307 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
310 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
311 /* FIXME: consider starting probes for "sr" */
314 notify_client_chk_result (sc, sr);
315 /* search for updates */
316 if (strlen (id_update) == 0)
317 return; /* no updates */
319 uu.data.sks.namespace = sc->uri->data.sks.namespace;
320 uu.data.sks.identifier = GNUNET_strdup (id_update);
321 /* FIXME: should attach update search
322 to the individual result, not
323 the entire SKS search! */
333 * Process a keyword-search result.
335 * @param sc our search context
336 * @param kb the kblock
337 * @param size size of kb
340 process_kblock (struct GNUNET_FS_SearchContext *sc,
341 const struct KBlock *kb,
347 char pt[size - sizeof (struct KBlock)];
348 struct GNUNET_CRYPTO_AesSessionKey skey;
349 struct GNUNET_CRYPTO_AesInitializationVector iv;
351 struct GNUNET_CONTAINER_MetaData *meta;
352 struct GNUNET_FS_Uri *uri;
355 GNUNET_CRYPTO_hash (&kb->keyspace,
356 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
359 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
361 &sc->requests[i].query,
362 sizeof (GNUNET_HashCode)))
364 if (i == sc->uri->data.ksk.keywordCount)
366 /* oops, does not match any of our keywords!? */
371 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
372 GNUNET_CRYPTO_aes_decrypt (&kb[1],
373 size - sizeof (struct KBlock),
378 eos = memchr (pt, 0, sizeof (pt));
385 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j],
389 GNUNET_break_op (0); /* kblock malformed */
392 uri = GNUNET_FS_uri_parse (pt, &emsg);
395 GNUNET_break_op (0); /* kblock malformed */
396 GNUNET_free_non_null (emsg);
397 GNUNET_CONTAINER_meta_data_destroy (meta);
401 process_ksk_result (sc, &sc->requests[i], uri, meta);
404 GNUNET_CONTAINER_meta_data_destroy (meta);
405 GNUNET_FS_uri_destroy (uri);
410 * Process a namespace-search result.
412 * @param sc our search context
413 * @param sb the sblock
414 * @param size size of sb
417 process_sblock (struct GNUNET_FS_SearchContext *sc,
418 const struct SBlock *sb,
421 size_t len = size - sizeof (struct SBlock);
423 struct GNUNET_CRYPTO_AesSessionKey skey;
424 struct GNUNET_CRYPTO_AesInitializationVector iv;
425 struct GNUNET_FS_Uri *uri;
426 struct GNUNET_CONTAINER_MetaData *meta;
435 identifier = sc->uri->data.sks.identifier;
436 GNUNET_CRYPTO_hash (identifier,
439 GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
440 GNUNET_CRYPTO_aes_decrypt (&sb[1],
446 off = GNUNET_STRINGS_buffer_tokenize (pt,
453 GNUNET_break_op (0); /* sblock malformed */
456 meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off],
460 GNUNET_break_op (0); /* sblock malformed */
463 uri = GNUNET_FS_uri_parse (uris, &emsg);
466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
467 "Failed to parse URI `%s': %s\n",
469 GNUNET_break_op (0); /* sblock malformed */
470 GNUNET_free_non_null (emsg);
471 GNUNET_CONTAINER_meta_data_destroy (meta);
475 process_sks_result (sc, id, uri, meta);
477 GNUNET_FS_uri_destroy (uri);
478 GNUNET_CONTAINER_meta_data_destroy (meta);
483 * Process a search result.
485 * @param sc our search context
486 * @param type type of the result
487 * @param expiration when it will expire
488 * @param data the (encrypted) response
489 * @param size size of data
492 process_result (struct GNUNET_FS_SearchContext *sc,
494 struct GNUNET_TIME_Absolute expiration,
498 if (GNUNET_TIME_absolute_get_duration (expiration).value > 0)
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 "Result received has already expired.\n");
502 return; /* result expired */
506 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
507 if (! GNUNET_FS_uri_test_ksk (sc->uri))
512 if (sizeof (struct KBlock) > size)
517 process_kblock (sc, data, size);
519 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
520 if (! GNUNET_FS_uri_test_sks (sc->uri))
525 if (sizeof (struct SBlock) > size)
530 process_sblock (sc, data, size);
532 case GNUNET_DATASTORE_BLOCKTYPE_ANY:
533 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
534 case GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND:
535 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
539 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
540 _("Got result with unknown block type `%d', ignoring"),
548 * Shutdown any existing connection to the FS
549 * service and try to establish a fresh one
550 * (and then re-transmit our search request).
552 * @param sc the search to reconnec
555 try_reconnect (struct GNUNET_FS_SearchContext *sc);
559 * Type of a function to call when we receive a message
563 * @param msg message received, NULL on timeout or fatal error
566 receive_results (void *cls,
567 const struct GNUNET_MessageHeader * msg)
569 struct GNUNET_FS_SearchContext *sc = cls;
570 const struct PutMessage *cm;
573 if ( (NULL == msg) ||
574 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
575 (ntohs (msg->size) <= sizeof (struct PutMessage)) )
580 msize = ntohs (msg->size);
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "Receiving %u bytes of result from fs service\n",
584 cm = (const struct PutMessage*) msg;
587 GNUNET_TIME_absolute_ntoh (cm->expiration),
589 msize - sizeof (struct PutMessage));
590 /* continue receiving */
591 GNUNET_CLIENT_receive (sc->client,
594 GNUNET_TIME_UNIT_FOREVER_REL);
599 * We're ready to transmit the search request to the
600 * file-sharing service. Do it.
603 * @param size number of bytes available in buf
604 * @param buf where the callee should write the message
605 * @return number of bytes written to buf
608 transmit_search_request (void *cls,
612 struct GNUNET_FS_SearchContext *sc = cls;
614 struct SearchMessage *sm;
616 const char *identifier;
625 if (GNUNET_FS_uri_test_ksk (sc->uri))
627 msize = sizeof (struct SearchMessage) * sc->uri->data.ksk.keywordCount;
628 GNUNET_assert (size >= msize);
630 memset (sm, 0, msize);
631 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
633 sm[i].header.size = htons (sizeof (struct SearchMessage));
634 sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
635 sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_KBLOCK);
636 sm[i].anonymity_level = htonl (sc->anonymity);
637 sm[i].query = sc->requests[i].query;
642 GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
643 msize = sizeof (struct SearchMessage);
644 GNUNET_assert (size >= msize);
646 memset (sm, 0, msize);
647 sm->header.size = htons (sizeof (struct SearchMessage));
648 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
649 sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_SBLOCK);
650 sm->anonymity_level = htonl (sc->anonymity);
651 sm->target = sc->uri->data.sks.namespace;
652 identifier = sc->uri->data.sks.identifier;
653 GNUNET_CRYPTO_hash (identifier,
656 GNUNET_CRYPTO_hash (&key,
657 sizeof (GNUNET_HashCode),
659 GNUNET_CRYPTO_hash_xor (&idh,
663 GNUNET_CLIENT_receive (sc->client,
666 GNUNET_TIME_UNIT_FOREVER_REL);
672 * Reconnect to the FS service and transmit
675 * @param cls our search context
679 do_reconnect (void *cls,
680 const struct GNUNET_SCHEDULER_TaskContext *tc)
682 struct GNUNET_FS_SearchContext *sc = cls;
683 struct GNUNET_CLIENT_Connection *client;
686 sc->task = GNUNET_SCHEDULER_NO_TASK;
687 client = GNUNET_CLIENT_connect (sc->h->sched,
696 if (GNUNET_FS_uri_test_ksk (sc->uri))
697 size = sizeof (struct SearchMessage) * sc->uri->data.ksk.keywordCount;
699 size = sizeof (struct SearchMessage);
700 GNUNET_CLIENT_notify_transmit_ready (client,
702 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
704 &transmit_search_request,
710 * Shutdown any existing connection to the FS
711 * service and try to establish a fresh one
712 * (and then re-transmit our search request).
714 * @param sc the search to reconnec
717 try_reconnect (struct GNUNET_FS_SearchContext *sc)
719 if (NULL != sc->client)
721 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
725 = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
726 GNUNET_TIME_UNIT_SECONDS,
733 * Start search for content, internal API.
735 * @param h handle to the file sharing subsystem
736 * @param uri specifies the search parameters; can be
737 * a KSK URI or an SKS URI.
738 * @param anonymity desired level of anonymity
739 * @param cctx initial value for the client context
740 * @param parent parent search (for namespace update searches)
741 * @return context that can be used to control the search
743 static struct GNUNET_FS_SearchContext *
744 search_start (struct GNUNET_FS_Handle *h,
745 const struct GNUNET_FS_Uri *uri,
748 struct GNUNET_FS_SearchContext *parent)
750 struct GNUNET_FS_SearchContext *sc;
751 struct GNUNET_CLIENT_Connection *client;
752 struct GNUNET_FS_ProgressInfo pi;
757 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
758 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
760 if (GNUNET_FS_uri_test_ksk (uri))
762 size = sizeof (struct SearchMessage) * uri->data.ksk.keywordCount;
766 GNUNET_assert (GNUNET_FS_uri_test_sks (uri));
767 size = sizeof (struct SearchMessage);
769 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
772 _("Too many keywords specified for a single search."));
775 client = GNUNET_CLIENT_connect (h->sched,
780 sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext));
782 sc->uri = GNUNET_FS_uri_dup (uri);
783 sc->anonymity = anonymity;
784 sc->start_time = GNUNET_TIME_absolute_get ();
787 sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16);
788 sc->client_info = cctx;
789 if (GNUNET_FS_uri_test_ksk (uri))
791 GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
792 sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) *
793 sc->uri->data.ksk.keywordCount);
794 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
796 keyword = &sc->uri->data.ksk.keywords[i][1];
797 GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
798 pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
799 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
800 GNUNET_CRYPTO_rsa_key_free (pk);
801 GNUNET_CRYPTO_hash (&pub,
802 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
803 &sc->requests[i].query);
804 sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
805 if (sc->requests[i].mandatory)
806 sc->mandatory_count++;
807 sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4);
808 GNUNET_CRYPTO_hash (keyword,
810 &sc->requests[i].key);
814 GNUNET_CONTAINER_DLL_insert (parent->child_head,
817 pi.status = GNUNET_FS_STATUS_SEARCH_START;
818 make_search_status (&pi, sc);
819 sc->client_info = h->upcb (h->upcb_cls,
821 GNUNET_CLIENT_notify_transmit_ready (client,
823 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
825 &transmit_search_request,
832 * Start search for content.
834 * @param h handle to the file sharing subsystem
835 * @param uri specifies the search parameters; can be
836 * a KSK URI or an SKS URI.
837 * @param anonymity desired level of anonymity
838 * @param cctx initial value for the client context
839 * @return context that can be used to control the search
841 struct GNUNET_FS_SearchContext *
842 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
843 const struct GNUNET_FS_Uri *uri,
847 return search_start (h, uri, anonymity, cctx, NULL);
854 * @param sc context for the search that should be paused
857 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
859 struct GNUNET_FS_ProgressInfo pi;
861 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
862 GNUNET_SCHEDULER_cancel (sc->h->sched,
864 sc->task = GNUNET_SCHEDULER_NO_TASK;
865 if (NULL != sc->client)
866 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
868 // FIXME: make persistent!
869 // FIXME: should this freeze all active probes?
870 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
871 make_search_status (&pi, sc);
872 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
878 * Continue paused search.
880 * @param sc context for the search that should be resumed
883 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
885 struct GNUNET_FS_ProgressInfo pi;
887 GNUNET_assert (sc->client == NULL);
888 GNUNET_assert (sc->task == GNUNET_SCHEDULER_NO_TASK);
889 do_reconnect (sc, NULL);
890 // FIXME: make persistent!
891 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
892 make_search_status (&pi, sc);
893 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
899 * Free the given search result.
901 * @param cls the global FS handle
902 * @param key the key for the search result (unused)
903 * @param value the search result to free
907 search_result_free (void *cls,
908 const GNUNET_HashCode * key,
911 struct GNUNET_FS_SearchContext *sc = cls;
912 struct GNUNET_FS_Handle *h = sc->h;
913 struct SearchResult *sr = value;
914 struct GNUNET_FS_ProgressInfo pi;
916 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
917 make_search_status (&pi, sc);
918 pi.value.search.specifics.result_stopped.cctx = sr->client_info;
919 pi.value.search.specifics.result_stopped.meta = sr->meta;
920 pi.value.search.specifics.result_stopped.uri = sr->uri;
921 sr->client_info = h->upcb (h->upcb_cls,
923 GNUNET_break (NULL == sr->client_info);
925 GNUNET_FS_uri_destroy (sr->uri);
926 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
927 if (sr->probe_ctx != NULL)
929 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
931 /* FIXME: trigger starting of new
932 probes here!? Maybe not -- could
933 cause new probes to be immediately
936 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
938 GNUNET_SCHEDULER_cancel (h->sched,
939 sr->probe_cancel_task);
947 * Stop search for content.
949 * @param sc context for the search that should be stopped
952 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
954 struct GNUNET_FS_ProgressInfo pi;
956 struct GNUNET_FS_SearchContext *parent;
958 // FIXME: make un-persistent!
959 if (NULL != (parent = sc->parent))
961 GNUNET_CONTAINER_DLL_remove (parent->child_head,
966 while (NULL != sc->child_head)
967 GNUNET_FS_search_stop (sc->child_head);
968 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
971 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
972 make_search_status (&pi, sc);
973 sc->client_info = sc->h->upcb (sc->h->upcb_cls,
975 GNUNET_break (NULL == sc->client_info);
976 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
977 GNUNET_SCHEDULER_cancel (sc->h->sched,
979 if (NULL != sc->client)
980 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
981 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
982 if (sc->requests != NULL)
984 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
985 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
986 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
988 GNUNET_free_non_null (sc->requests);
989 GNUNET_FS_uri_destroy (sc->uri);
993 /* end of fs_search.c */