fs_search.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001-2014 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file fs/fs_search.c
  18. * @brief Helper functions for searching.
  19. * @author Christian Grothoff
  20. */
  21. #include "platform.h"
  22. #include "gnunet_constants.h"
  23. #include "gnunet_fs_service.h"
  24. #include "gnunet_protocols.h"
  25. #include "fs_api.h"
  26. #include "fs_publish_ublock.h"
  27. /**
  28. * Number of availability trials we perform per search result.
  29. */
  30. #define AVAILABILITY_TRIALS_MAX 8
  31. /**
  32. * Fill in all of the generic fields for a search event and
  33. * call the callback.
  34. *
  35. * @param pi structure to fill in
  36. * @param h file-sharing handle
  37. * @param sc overall search context
  38. * @return value returned by the callback
  39. */
  40. void *
  41. GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
  42. struct GNUNET_FS_Handle *h,
  43. struct GNUNET_FS_SearchContext *sc)
  44. {
  45. void *ret;
  46. pi->value.search.sc = sc;
  47. pi->value.search.cctx = (NULL != sc) ? sc->client_info : NULL;
  48. pi->value.search.pctx =
  49. ((NULL == sc) || (NULL == sc->psearch_result))
  50. ? NULL
  51. : sc->psearch_result->client_info;
  52. pi->value.search.query = (NULL != sc) ? sc->uri : NULL;
  53. pi->value.search.duration = (NULL != sc)
  54. ? GNUNET_TIME_absolute_get_duration (
  55. sc->start_time)
  56. : GNUNET_TIME_UNIT_ZERO;
  57. pi->value.search.anonymity = (NULL != sc) ? sc->anonymity : 0;
  58. pi->fsh = h;
  59. ret = h->upcb (h->upcb_cls, pi);
  60. return ret;
  61. }
  62. /**
  63. * Check if the given result is identical to the given URI.
  64. *
  65. * @param cls points to the URI we check against
  66. * @param key not used
  67. * @param value a `struct GNUNET_FS_SearchResult` who's URI we
  68. * should compare with
  69. * @return #GNUNET_SYSERR if the result is present,
  70. * #GNUNET_OK otherwise
  71. */
  72. static int
  73. test_result_present (void *cls,
  74. const struct GNUNET_HashCode *key,
  75. void *value)
  76. {
  77. const struct GNUNET_FS_Uri *uri = cls;
  78. struct GNUNET_FS_SearchResult *sr = value;
  79. if (GNUNET_FS_uri_test_equal (uri, sr->uri))
  80. return GNUNET_SYSERR;
  81. return GNUNET_OK;
  82. }
  83. /**
  84. * We've found a new CHK result. Let the client
  85. * know about it.
  86. *
  87. * @param sc the search context
  88. * @param sr the specific result
  89. */
  90. static void
  91. notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
  92. struct GNUNET_FS_SearchResult *sr)
  93. {
  94. struct GNUNET_FS_ProgressInfo pi;
  95. pi.status = GNUNET_FS_STATUS_SEARCH_RESULT;
  96. pi.value.search.specifics.result.meta = sr->meta;
  97. pi.value.search.specifics.result.uri = sr->uri;
  98. pi.value.search.specifics.result.result = sr;
  99. pi.value.search.specifics.result.applicability_rank = sr->optional_support;
  100. sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  101. }
  102. /**
  103. * We've found new information about an existing CHK result. Let the
  104. * client know about it.
  105. *
  106. * @param sc the search context
  107. * @param sr the specific result
  108. */
  109. static void
  110. notify_client_chk_update (struct GNUNET_FS_SearchContext *sc,
  111. struct GNUNET_FS_SearchResult *sr)
  112. {
  113. struct GNUNET_FS_ProgressInfo pi;
  114. pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
  115. pi.value.search.specifics.update.cctx = sr->client_info;
  116. pi.value.search.specifics.update.meta = sr->meta;
  117. pi.value.search.specifics.update.uri = sr->uri;
  118. pi.value.search.specifics.update.availability_rank =
  119. 2 * sr->availability_success - sr->availability_trials;
  120. pi.value.search.specifics.update.availability_certainty =
  121. sr->availability_trials;
  122. pi.value.search.specifics.update.applicability_rank = sr->optional_support;
  123. pi.value.search.specifics.update.current_probe_time
  124. = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
  125. sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  126. }
  127. /**
  128. * Context for "get_result_present".
  129. */
  130. struct GetResultContext
  131. {
  132. /**
  133. * The URI we're looking for.
  134. */
  135. const struct GNUNET_FS_Uri *uri;
  136. /**
  137. * Where to store a pointer to the search
  138. * result struct if we found a match.
  139. */
  140. struct GNUNET_FS_SearchResult *sr;
  141. };
  142. /**
  143. * Check if the given result is identical to the given URI and if so
  144. * return it.
  145. *
  146. * @param cls a `struct GetResultContext`
  147. * @param key not used
  148. * @param value a `struct GNUNET_FS_SearchResult` who's URI we
  149. * should compare with
  150. * @return #GNUNET_OK
  151. */
  152. static int
  153. get_result_present (void *cls,
  154. const struct GNUNET_HashCode *key,
  155. void *value)
  156. {
  157. struct GetResultContext *grc = cls;
  158. struct GNUNET_FS_SearchResult *sr = value;
  159. if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri))
  160. grc->sr = sr;
  161. return GNUNET_OK;
  162. }
  163. /**
  164. * Signal result of last probe to client and then schedule next
  165. * probe.
  166. *
  167. * @param sr search result to signal for
  168. */
  169. static void
  170. signal_probe_result (struct GNUNET_FS_SearchResult *sr)
  171. {
  172. struct GNUNET_FS_ProgressInfo pi;
  173. pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE;
  174. pi.value.search.specifics.update.cctx = sr->client_info;
  175. pi.value.search.specifics.update.meta = sr->meta;
  176. pi.value.search.specifics.update.uri = sr->uri;
  177. pi.value.search.specifics.update.availability_rank
  178. = 2 * sr->availability_success - sr->availability_trials;
  179. pi.value.search.specifics.update.availability_certainty
  180. = sr->availability_trials;
  181. pi.value.search.specifics.update.applicability_rank = sr->optional_support;
  182. pi.value.search.specifics.update.current_probe_time
  183. = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
  184. sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sr->sc);
  185. GNUNET_FS_search_start_probe_ (sr);
  186. }
  187. /**
  188. * Handle the case where we have failed to receive a response for our probe.
  189. *
  190. * @param cls our `struct GNUNET_FS_SearchResult *`
  191. */
  192. static void
  193. probe_failure_handler (void *cls)
  194. {
  195. struct GNUNET_FS_SearchResult *sr = cls;
  196. sr->probe_cancel_task = NULL;
  197. sr->availability_trials++;
  198. GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
  199. sr->probe_ctx = NULL;
  200. GNUNET_FS_stop_probe_ping_task_ (sr);
  201. GNUNET_FS_search_result_sync_ (sr);
  202. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  203. "Probe #%u for search result %p failed\n",
  204. sr->availability_trials,
  205. sr);
  206. signal_probe_result (sr);
  207. }
  208. /**
  209. * Handle the case where we have gotten a response for our probe.
  210. *
  211. * @param cls our `struct GNUNET_FS_SearchResult *`
  212. */
  213. static void
  214. probe_success_handler (void *cls)
  215. {
  216. struct GNUNET_FS_SearchResult *sr = cls;
  217. sr->probe_cancel_task = NULL;
  218. sr->availability_trials++;
  219. sr->availability_success++;
  220. GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
  221. sr->probe_ctx = NULL;
  222. GNUNET_FS_stop_probe_ping_task_ (sr);
  223. GNUNET_FS_search_result_sync_ (sr);
  224. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  225. "Probe #%u for search result %p succeeded\n",
  226. sr->availability_trials,
  227. sr);
  228. signal_probe_result (sr);
  229. }
  230. /**
  231. * Notification of FS that a search probe has made progress.
  232. * This function is used INSTEAD of the client's event handler
  233. * for downloads where the #GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
  234. *
  235. * @param cls closure, always NULL (!), actual closure
  236. * is in the client-context of the info struct
  237. * @param info details about the event, specifying the event type
  238. * and various bits about the event
  239. * @return client-context (for the next progress call
  240. * for this operation; should be set to NULL for
  241. * SUSPEND and STOPPED events). The value returned
  242. * will be passed to future callbacks in the respective
  243. * field in the `struct GNUNET_FS_ProgressInfo`.
  244. */
  245. void *
  246. GNUNET_FS_search_probe_progress_ (void *cls,
  247. const struct GNUNET_FS_ProgressInfo *info)
  248. {
  249. struct GNUNET_FS_SearchResult *sr = info->value.download.cctx;
  250. struct GNUNET_TIME_Relative dur;
  251. switch (info->status)
  252. {
  253. case GNUNET_FS_STATUS_DOWNLOAD_START:
  254. /* ignore */
  255. break;
  256. case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
  257. /* probes should never be resumed */
  258. GNUNET_assert (0);
  259. break;
  260. case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
  261. /* probes should never be suspended */
  262. GNUNET_break (0);
  263. break;
  264. case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
  265. /* ignore */
  266. break;
  267. case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
  268. if (NULL != sr->probe_cancel_task)
  269. {
  270. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  271. sr->probe_cancel_task = NULL;
  272. }
  273. sr->probe_cancel_task =
  274. GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
  275. &probe_failure_handler, sr);
  276. break;
  277. case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
  278. if (NULL != sr->probe_cancel_task)
  279. {
  280. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  281. sr->probe_cancel_task = NULL;
  282. }
  283. sr->probe_cancel_task =
  284. GNUNET_SCHEDULER_add_now (&probe_success_handler, sr);
  285. break;
  286. case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
  287. if (NULL != sr->probe_cancel_task)
  288. {
  289. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  290. sr->probe_cancel_task = NULL;
  291. }
  292. sr = NULL;
  293. break;
  294. case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
  295. if (NULL == sr->probe_cancel_task)
  296. {
  297. sr->probe_active_time = GNUNET_TIME_absolute_get ();
  298. sr->probe_cancel_task =
  299. GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time,
  300. &probe_failure_handler, sr);
  301. }
  302. break;
  303. case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
  304. if (NULL != sr->probe_cancel_task)
  305. {
  306. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  307. sr->probe_cancel_task = NULL;
  308. }
  309. dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
  310. sr->remaining_probe_time =
  311. GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur);
  312. if (0 == sr->remaining_probe_time.rel_value_us)
  313. sr->probe_cancel_task =
  314. GNUNET_SCHEDULER_add_now (&probe_failure_handler, sr);
  315. GNUNET_FS_search_result_sync_ (sr);
  316. break;
  317. default:
  318. GNUNET_break (0);
  319. return NULL;
  320. }
  321. return sr;
  322. }
  323. /**
  324. * Task run periodically to remind clients that a probe is active.
  325. *
  326. * @param cls the `struct GNUNET_FS_SearchResult` that we are probing for
  327. */
  328. static void
  329. probe_ping_task_cb (void *cls)
  330. {
  331. struct GNUNET_FS_Handle *h = cls;
  332. for (struct GNUNET_FS_SearchResult *sr = h->probes_head;
  333. NULL != sr;
  334. sr = sr->next)
  335. if (NULL != sr->probe_ctx->mq)
  336. signal_probe_result (sr);
  337. h->probe_ping_task
  338. = GNUNET_SCHEDULER_add_delayed (GNUNET_FS_PROBE_UPDATE_FREQUENCY,
  339. &probe_ping_task_cb,
  340. h);
  341. }
  342. /**
  343. * Start the ping task for this search result.
  344. *
  345. * @param sr result to start pinging for.
  346. */
  347. static void
  348. start_probe_ping_task (struct GNUNET_FS_SearchResult *sr)
  349. {
  350. struct GNUNET_FS_Handle *h = sr->h;
  351. GNUNET_CONTAINER_DLL_insert (h->probes_head,
  352. h->probes_tail,
  353. sr);
  354. if (NULL == h->probe_ping_task)
  355. h->probe_ping_task
  356. = GNUNET_SCHEDULER_add_now (&probe_ping_task_cb,
  357. h);
  358. }
  359. /**
  360. * Stop the ping task for this search result.
  361. *
  362. * @param sr result to start pinging for.
  363. */
  364. void
  365. GNUNET_FS_stop_probe_ping_task_ (struct GNUNET_FS_SearchResult *sr)
  366. {
  367. struct GNUNET_FS_Handle *h = sr->h;
  368. GNUNET_CONTAINER_DLL_remove (h->probes_head,
  369. h->probes_tail,
  370. sr);
  371. if (NULL == h->probes_head)
  372. {
  373. GNUNET_SCHEDULER_cancel (h->probe_ping_task);
  374. h->probe_ping_task = NULL;
  375. }
  376. }
  377. /**
  378. * Start download probes for the given search result.
  379. *
  380. * @param sr the search result
  381. */
  382. void
  383. GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
  384. {
  385. uint64_t off;
  386. uint64_t len;
  387. if (NULL != sr->probe_ctx)
  388. return;
  389. if (NULL != sr->download)
  390. return;
  391. if (0 == (sr->h->flags & GNUNET_FS_FLAGS_DO_PROBES))
  392. return;
  393. if (sr->availability_trials > AVAILABILITY_TRIALS_MAX)
  394. return;
  395. if ( (GNUNET_FS_URI_CHK != sr->uri->type) &&
  396. (GNUNET_FS_URI_LOC != sr->uri->type) )
  397. return;
  398. len = GNUNET_FS_uri_chk_get_file_size (sr->uri);
  399. if (0 == len)
  400. return;
  401. if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0))
  402. return;
  403. off = len / DBLOCK_SIZE;
  404. if (off > 0)
  405. off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, off);
  406. off *= DBLOCK_SIZE;
  407. if (len - off < DBLOCK_SIZE)
  408. len = len - off;
  409. else
  410. len = DBLOCK_SIZE;
  411. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  412. "Starting probe #%u (at offset %llu) for search result %p\n",
  413. sr->availability_trials + 1,
  414. (unsigned long long) off,
  415. sr);
  416. sr->remaining_probe_time =
  417. GNUNET_TIME_relative_saturating_multiply (sr->h->avg_block_latency,
  418. 2 * (1
  419. + sr->availability_trials));
  420. sr->probe_ctx =
  421. GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off,
  422. len, sr->anonymity,
  423. GNUNET_FS_DOWNLOAD_NO_TEMPORARIES
  424. | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
  425. start_probe_ping_task (sr);
  426. }
  427. /**
  428. * Start download probes for the given search result.
  429. *
  430. * @param h file-sharing handle to use for the operation
  431. * @param uri URI to probe
  432. * @param meta meta data associated with the URI
  433. * @param client_info client info pointer to use for associated events
  434. * @param anonymity anonymity level to use for the probes
  435. * @return the search result handle to access the probe activity
  436. */
  437. struct GNUNET_FS_SearchResult *
  438. GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
  439. const struct GNUNET_FS_Uri *uri,
  440. const struct GNUNET_CONTAINER_MetaData *meta,
  441. void *client_info,
  442. uint32_t anonymity)
  443. {
  444. struct GNUNET_FS_SearchResult *sr;
  445. GNUNET_assert (NULL != h);
  446. GNUNET_assert (NULL != uri);
  447. sr = GNUNET_new (struct GNUNET_FS_SearchResult);
  448. sr->h = h;
  449. sr->uri = GNUNET_FS_uri_dup (uri);
  450. sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
  451. sr->client_info = client_info;
  452. sr->anonymity = anonymity;
  453. GNUNET_FS_search_start_probe_ (sr);
  454. return sr;
  455. }
  456. /**
  457. * Stop probing activity associated with a search result.
  458. *
  459. * @param sr search result
  460. */
  461. static void
  462. GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr)
  463. {
  464. if (NULL != sr->probe_ctx)
  465. {
  466. GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
  467. sr->probe_ctx = NULL;
  468. GNUNET_FS_stop_probe_ping_task_ (sr);
  469. }
  470. if (NULL != sr->probe_cancel_task)
  471. {
  472. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  473. sr->probe_cancel_task = NULL;
  474. }
  475. }
  476. /**
  477. * Stop probe activity. Must ONLY be used on values
  478. * returned from #GNUNET_FS_probe.
  479. *
  480. * @param sr search result to stop probing for (freed)
  481. * @return the value of the 'client_info' pointer
  482. */
  483. void *
  484. GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr)
  485. {
  486. void *client_info;
  487. GNUNET_assert (NULL == sr->sc);
  488. GNUNET_FS_search_stop_probe_ (sr);
  489. GNUNET_FS_uri_destroy (sr->uri);
  490. GNUNET_CONTAINER_meta_data_destroy (sr->meta);
  491. client_info = sr->client_info;
  492. GNUNET_free (sr);
  493. return client_info;
  494. }
  495. /**
  496. * We have received a KSK result. Check how it fits in with the
  497. * overall query and notify the client accordingly.
  498. *
  499. * @param sc context for the overall query
  500. * @param ent entry for the specific keyword
  501. * @param uri the URI that was found
  502. * @param meta metadata associated with the URI
  503. * under the @a ent keyword
  504. */
  505. static void
  506. process_ksk_result (struct GNUNET_FS_SearchContext *sc,
  507. struct SearchRequestEntry *ent,
  508. const struct GNUNET_FS_Uri *uri,
  509. const struct GNUNET_CONTAINER_MetaData *meta)
  510. {
  511. struct GNUNET_HashCode key;
  512. struct GNUNET_FS_SearchResult *sr;
  513. struct GetResultContext grc;
  514. int is_new;
  515. unsigned int koff;
  516. /* check if new */
  517. GNUNET_assert (NULL != sc);
  518. if (GNUNET_OK !=
  519. GNUNET_FS_uri_to_key (uri,
  520. &key))
  521. {
  522. GNUNET_break_op (0);
  523. return;
  524. }
  525. if (GNUNET_SYSERR ==
  526. GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
  527. &key,
  528. &test_result_present,
  529. (void *) uri))
  530. return; /* duplicate result */
  531. /* try to find search result in master map */
  532. grc.sr = NULL;
  533. grc.uri = uri;
  534. GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map,
  535. &key,
  536. &get_result_present, &grc);
  537. sr = grc.sr;
  538. is_new = (NULL == sr) || (sr->mandatory_missing > 0);
  539. if (NULL == sr)
  540. {
  541. sr = GNUNET_new (struct GNUNET_FS_SearchResult);
  542. sr->h = sc->h;
  543. sr->sc = sc;
  544. sr->anonymity = sc->anonymity;
  545. sr->uri = GNUNET_FS_uri_dup (uri);
  546. sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
  547. sr->mandatory_missing = sc->mandatory_count;
  548. sr->key = key;
  549. sr->keyword_bitmap = GNUNET_malloc ((sc->uri->data.ksk.keywordCount + 7)
  550. / 8); /* round up, count bits */
  551. GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
  552. GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
  553. }
  554. else
  555. {
  556. GNUNET_CONTAINER_meta_data_merge (sr->meta, meta);
  557. }
  558. GNUNET_break (GNUNET_OK ==
  559. GNUNET_CONTAINER_multihashmap_put (ent->results,
  560. &sr->key,
  561. sr,
  562. GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
  563. koff = ent - sc->requests;
  564. GNUNET_assert ((ent >= sc->requests) &&
  565. (koff < sc->uri->data.ksk.keywordCount));
  566. sr->keyword_bitmap[koff / 8] |= (1 << (koff % 8));
  567. /* check if mandatory satisfied */
  568. if (1 <= GNUNET_CONTAINER_multihashmap_size (ent->results))
  569. {
  570. if (ent->mandatory)
  571. {
  572. GNUNET_break (sr->mandatory_missing > 0);
  573. sr->mandatory_missing--;
  574. }
  575. else
  576. {
  577. sr->optional_support++;
  578. }
  579. }
  580. if (0 != sr->mandatory_missing)
  581. {
  582. GNUNET_break (NULL == sr->client_info);
  583. return;
  584. }
  585. if (is_new)
  586. notify_client_chk_result (sc, sr);
  587. else
  588. notify_client_chk_update (sc, sr);
  589. GNUNET_FS_search_result_sync_ (sr);
  590. GNUNET_FS_search_start_probe_ (sr);
  591. }
  592. /**
  593. * Start search for content, internal API.
  594. *
  595. * @param h handle to the file sharing subsystem
  596. * @param uri specifies the search parameters; can be
  597. * a KSK URI or an SKS URI.
  598. * @param anonymity desired level of anonymity
  599. * @param options options for the search
  600. * @param cctx client context
  601. * @param psearch parent search result (for namespace update searches)
  602. * @return context that can be used to control the search
  603. */
  604. static struct GNUNET_FS_SearchContext *
  605. search_start (struct GNUNET_FS_Handle *h,
  606. const struct GNUNET_FS_Uri *uri,
  607. uint32_t anonymity,
  608. enum GNUNET_FS_SearchOptions options,
  609. void *cctx,
  610. struct GNUNET_FS_SearchResult *psearch);
  611. /**
  612. * We have received an SKS result. Start searching for updates and
  613. * notify the client if it is a new result.
  614. *
  615. * @param sc context for the overall query
  616. * @param id_update identifier for updates, NULL for none
  617. * @param uri the URI that was found
  618. * @param meta metadata associated with the URI
  619. */
  620. static void
  621. process_sks_result (struct GNUNET_FS_SearchContext *sc,
  622. const char *id_update,
  623. const struct GNUNET_FS_Uri *uri,
  624. const struct GNUNET_CONTAINER_MetaData *meta)
  625. {
  626. struct GNUNET_FS_Uri uu;
  627. struct GNUNET_HashCode key;
  628. struct GNUNET_FS_SearchResult *sr;
  629. /* check if new */
  630. GNUNET_assert (NULL != sc);
  631. if (GNUNET_OK !=
  632. GNUNET_FS_uri_to_key (uri,
  633. &key))
  634. {
  635. GNUNET_break (0);
  636. return;
  637. }
  638. GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
  639. &uri->data.chk.chk.query,
  640. &key);
  641. if (GNUNET_SYSERR ==
  642. GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
  643. &test_result_present,
  644. (void *) uri))
  645. return; /* duplicate result */
  646. sr = GNUNET_new (struct GNUNET_FS_SearchResult);
  647. sr->h = sc->h;
  648. sr->sc = sc;
  649. sr->anonymity = sc->anonymity;
  650. sr->uri = GNUNET_FS_uri_dup (uri);
  651. sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
  652. sr->key = key;
  653. GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, &key, sr,
  654. GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
  655. GNUNET_FS_search_result_sync_ (sr);
  656. GNUNET_FS_search_start_probe_ (sr);
  657. /* notify client */
  658. if (0 == sr->mandatory_missing)
  659. notify_client_chk_result (sc, sr);
  660. else
  661. GNUNET_break (NULL == sr->client_info);
  662. /* search for updates */
  663. if (0 == strlen (id_update))
  664. return; /* no updates */
  665. uu.type = GNUNET_FS_URI_SKS;
  666. uu.data.sks.ns = sc->uri->data.sks.ns;
  667. uu.data.sks.identifier = GNUNET_strdup (id_update);
  668. (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr);
  669. GNUNET_free (uu.data.sks.identifier);
  670. }
  671. /**
  672. * Decrypt a ublock using a 'keyword' as the passphrase. Given the
  673. * KSK public key derived from the keyword, this function looks up
  674. * the original keyword in the search context and decrypts the
  675. * given ciphertext block.
  676. *
  677. * @param sc search context with the keywords
  678. * @param dpub derived public key used for the search
  679. * @param edata encrypted data
  680. * @param edata_size number of bytes in @a edata (and @a data)
  681. * @param data where to store the plaintext
  682. * @return keyword index on success, #GNUNET_SYSERR on error (no such
  683. * keyword, internal error)
  684. */
  685. static int
  686. decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc,
  687. const struct GNUNET_CRYPTO_EcdsaPublicKey *dpub,
  688. const void *edata,
  689. size_t edata_size,
  690. char *data)
  691. {
  692. const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon;
  693. struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub;
  694. unsigned int i;
  695. /* find key */
  696. for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
  697. if (0 == memcmp (dpub,
  698. &sc->requests[i].dpub,
  699. sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
  700. break;
  701. if (i == sc->uri->data.ksk.keywordCount)
  702. {
  703. /* oops, does not match any of our keywords!? */
  704. GNUNET_break (0);
  705. return GNUNET_SYSERR;
  706. }
  707. /* decrypt */
  708. anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
  709. GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub);
  710. GNUNET_FS_ublock_decrypt_ (edata, edata_size,
  711. &anon_pub,
  712. sc->requests[i].keyword,
  713. data);
  714. return i;
  715. }
  716. /**
  717. * Process a keyword search result. The actual type of block is
  718. * a UBlock; we know it is a keyword search result because that's
  719. * what we were searching for.
  720. *
  721. * @param sc our search context
  722. * @param ub the ublock with the keyword search result
  723. * @param size size of @a ub
  724. */
  725. static void
  726. process_kblock (struct GNUNET_FS_SearchContext *sc,
  727. const struct UBlock *ub,
  728. size_t size)
  729. {
  730. size_t j;
  731. char pt[size - sizeof(struct UBlock)];
  732. const char *eos;
  733. struct GNUNET_CONTAINER_MetaData *meta;
  734. struct GNUNET_FS_Uri *uri;
  735. char *emsg;
  736. int i;
  737. if (-1 == (i = decrypt_block_with_keyword (sc,
  738. &ub->verification_key,
  739. &ub[1],
  740. size - sizeof(struct UBlock),
  741. pt)))
  742. return;
  743. /* parse; pt[0] is just '\0', so we skip over that */
  744. eos = memchr (&pt[1], '\0', sizeof(pt) - 1);
  745. if (NULL == eos)
  746. {
  747. GNUNET_break_op (0);
  748. return;
  749. }
  750. if (NULL == (uri = GNUNET_FS_uri_parse (&pt[1], &emsg)))
  751. {
  752. if (GNUNET_FS_VERSION > 0x00090400)
  753. {
  754. /* we broke this in 0x00090300, so don't bitch
  755. too loudly just one version up... */
  756. GNUNET_break_op (0); /* ublock malformed */
  757. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  758. _ ("Failed to parse URI `%s': %s\n"),
  759. &pt[1],
  760. emsg);
  761. }
  762. GNUNET_free_non_null (emsg);
  763. return;
  764. }
  765. j = eos - pt + 1;
  766. if (sizeof(pt) == j)
  767. meta = GNUNET_CONTAINER_meta_data_create ();
  768. else
  769. meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof(pt) - j);
  770. if (NULL == meta)
  771. {
  772. GNUNET_break_op (0); /* ublock malformed */
  773. GNUNET_FS_uri_destroy (uri);
  774. return;
  775. }
  776. process_ksk_result (sc,
  777. &sc->requests[i],
  778. uri,
  779. meta);
  780. /* clean up */
  781. GNUNET_CONTAINER_meta_data_destroy (meta);
  782. GNUNET_FS_uri_destroy (uri);
  783. }
  784. /**
  785. * Process a namespace-search result. The actual type of block is
  786. * a UBlock; we know it is a namespace search result because that's
  787. * what we were searching for.
  788. *
  789. * @param sc our search context
  790. * @param ub the ublock with a namespace result
  791. * @param size size of @a ub
  792. */
  793. static void
  794. process_sblock (struct GNUNET_FS_SearchContext *sc,
  795. const struct UBlock *ub,
  796. size_t size)
  797. {
  798. size_t len = size - sizeof(struct UBlock);
  799. char pt[len];
  800. struct GNUNET_FS_Uri *uri;
  801. struct GNUNET_CONTAINER_MetaData *meta;
  802. const char *id;
  803. const char *uris;
  804. size_t off;
  805. char *emsg;
  806. GNUNET_FS_ublock_decrypt_ (&ub[1], len,
  807. &sc->uri->data.sks.ns,
  808. sc->uri->data.sks.identifier,
  809. pt);
  810. /* parse */
  811. if (0 == (off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris)))
  812. {
  813. GNUNET_break_op (0); /* ublock malformed */
  814. return;
  815. }
  816. if (NULL == (meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len
  817. - off)))
  818. {
  819. GNUNET_break_op (0); /* ublock malformed */
  820. return;
  821. }
  822. if (NULL == (uri = GNUNET_FS_uri_parse (uris, &emsg)))
  823. {
  824. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  825. _ ("Failed to parse URI `%s': %s\n"),
  826. uris, emsg);
  827. GNUNET_break_op (0); /* ublock malformed */
  828. GNUNET_free_non_null (emsg);
  829. GNUNET_CONTAINER_meta_data_destroy (meta);
  830. return;
  831. }
  832. /* process */
  833. process_sks_result (sc, id, uri, meta);
  834. /* clean up */
  835. GNUNET_FS_uri_destroy (uri);
  836. GNUNET_CONTAINER_meta_data_destroy (meta);
  837. }
  838. /**
  839. * Shutdown any existing connection to the FS
  840. * service and try to establish a fresh one
  841. * (and then re-transmit our search request).
  842. *
  843. * @param sc the search to reconnec
  844. */
  845. static void
  846. try_reconnect (struct GNUNET_FS_SearchContext *sc);
  847. /**
  848. * We check a result message from the service.
  849. *
  850. * @param cls closure
  851. * @param msg result message received
  852. */
  853. static int
  854. check_result (void *cls,
  855. const struct ClientPutMessage *cm)
  856. {
  857. /* payload of any variable size is OK */
  858. return GNUNET_OK;
  859. }
  860. /**
  861. * We process a search result from the service.
  862. *
  863. * @param cls closure
  864. * @param msg result message received
  865. */
  866. static void
  867. handle_result (void *cls,
  868. const struct ClientPutMessage *cm)
  869. {
  870. struct GNUNET_FS_SearchContext *sc = cls;
  871. uint16_t msize = ntohs (cm->header.size) - sizeof(*cm);
  872. enum GNUNET_BLOCK_Type type = ntohl (cm->type);
  873. if (GNUNET_TIME_absolute_get_duration (GNUNET_TIME_absolute_ntoh (
  874. cm->expiration)).rel_value_us > 0)
  875. {
  876. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  877. "Result received has already expired.\n");
  878. return; /* result expired */
  879. }
  880. switch (type)
  881. {
  882. case GNUNET_BLOCK_TYPE_FS_UBLOCK:
  883. if (GNUNET_FS_URI_SKS == sc->uri->type)
  884. process_sblock (sc,
  885. (const struct UBlock *) &cm[1],
  886. msize);
  887. else
  888. process_kblock (sc,
  889. (const struct UBlock *) &cm[1],
  890. msize);
  891. break;
  892. case GNUNET_BLOCK_TYPE_ANY:
  893. GNUNET_break (0);
  894. break;
  895. case GNUNET_BLOCK_TYPE_FS_DBLOCK:
  896. GNUNET_break (0);
  897. break;
  898. case GNUNET_BLOCK_TYPE_FS_ONDEMAND:
  899. GNUNET_break (0);
  900. break;
  901. case GNUNET_BLOCK_TYPE_FS_IBLOCK:
  902. GNUNET_break (0);
  903. break;
  904. default:
  905. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  906. _ ("Got result with unknown block type `%d', ignoring"),
  907. type);
  908. break;
  909. }
  910. }
  911. /**
  912. * Schedule the transmission of the (next) search request
  913. * to the service.
  914. *
  915. * @param sc context for the search
  916. */
  917. static void
  918. schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc);
  919. /**
  920. * Closure for #build_result_set().
  921. */
  922. struct MessageBuilderContext
  923. {
  924. /**
  925. * How many entries can we store to xoff.
  926. */
  927. unsigned int put_cnt;
  928. /**
  929. * How many entries should we skip.
  930. */
  931. unsigned int skip_cnt;
  932. /**
  933. * Where to store the keys.
  934. */
  935. struct GNUNET_HashCode *xoff;
  936. /**
  937. * Search context we are iterating for.
  938. */
  939. struct GNUNET_FS_SearchContext *sc;
  940. /**
  941. * Keyword offset the search result must match (0 for SKS)
  942. */
  943. unsigned int keyword_offset;
  944. };
  945. /**
  946. * Iterating over the known results, pick those matching the given
  947. * result range and store their keys at 'xoff'.
  948. *
  949. * @param cls the `struct MessageBuilderContext`
  950. * @param key key for a result
  951. * @param value the search result
  952. * @return #GNUNET_OK to continue iterating
  953. */
  954. static int
  955. build_result_set (void *cls,
  956. const struct GNUNET_HashCode *key,
  957. void *value)
  958. {
  959. struct MessageBuilderContext *mbc = cls;
  960. struct GNUNET_FS_SearchResult *sr = value;
  961. if ((NULL != sr->keyword_bitmap) &&
  962. (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1
  963. << (mbc->
  964. keyword_offset
  965. % 8)))))
  966. return GNUNET_OK; /* have no match for this keyword yet */
  967. if (mbc->skip_cnt > 0)
  968. {
  969. mbc->skip_cnt--;
  970. return GNUNET_OK;
  971. }
  972. if (0 == mbc->put_cnt)
  973. return GNUNET_SYSERR;
  974. mbc->xoff[--mbc->put_cnt] = *key;
  975. return GNUNET_OK;
  976. }
  977. /**
  978. * Iterating over the known results, count those matching the given
  979. * result range and increment put count for each.
  980. *
  981. * @param cls the `struct MessageBuilderContext`
  982. * @param key key for a result
  983. * @param value the search result
  984. * @return #GNUNET_OK to continue iterating
  985. */
  986. static int
  987. find_result_set (void *cls,
  988. const struct GNUNET_HashCode *key,
  989. void *value)
  990. {
  991. struct MessageBuilderContext *mbc = cls;
  992. struct GNUNET_FS_SearchResult *sr = value;
  993. if ((NULL != sr->keyword_bitmap) &&
  994. (0 == (sr->keyword_bitmap[mbc->keyword_offset / 8] & (1
  995. << (mbc->
  996. keyword_offset
  997. % 8)))))
  998. return GNUNET_OK; /* have no match for this keyword yet */
  999. mbc->put_cnt++;
  1000. return GNUNET_OK;
  1001. }
  1002. /**
  1003. * Schedule the transmission of the (next) search request
  1004. * to the service.
  1005. *
  1006. * @param sc context for the search
  1007. */
  1008. static void
  1009. schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc)
  1010. {
  1011. struct MessageBuilderContext mbc;
  1012. struct GNUNET_MQ_Envelope *env;
  1013. struct SearchMessage *sm;
  1014. struct GNUNET_CRYPTO_EcdsaPublicKey dpub;
  1015. unsigned int total_seen_results; /* total number of result hashes to send */
  1016. uint32_t options;
  1017. unsigned int left;
  1018. unsigned int todo;
  1019. unsigned int fit;
  1020. unsigned int search_request_map_offset;
  1021. unsigned int keyword_offset;
  1022. int first_call;
  1023. memset (&mbc, 0, sizeof(mbc));
  1024. mbc.sc = sc;
  1025. if (GNUNET_FS_uri_test_ksk (sc->uri))
  1026. {
  1027. /* This will calculate the result set size ONLY for
  1028. "keyword_offset == 0", so we will have to recalculate
  1029. it for the other keywords later! */
  1030. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1031. &find_result_set,
  1032. &mbc);
  1033. total_seen_results = mbc.put_cnt;
  1034. }
  1035. else
  1036. {
  1037. total_seen_results
  1038. = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map);
  1039. }
  1040. search_request_map_offset = 0;
  1041. keyword_offset = 0;
  1042. first_call = GNUNET_YES;
  1043. while ((0 != (left =
  1044. (total_seen_results - search_request_map_offset))) ||
  1045. (GNUNET_YES == first_call))
  1046. {
  1047. first_call = GNUNET_NO;
  1048. options = SEARCH_MESSAGE_OPTION_NONE;
  1049. if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY))
  1050. options |= SEARCH_MESSAGE_OPTION_LOOPBACK_ONLY;
  1051. fit = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*sm)) / sizeof(struct
  1052. GNUNET_HashCode);
  1053. todo = GNUNET_MIN (fit,
  1054. left);
  1055. env = GNUNET_MQ_msg_extra (sm,
  1056. sizeof(struct GNUNET_HashCode) * todo,
  1057. GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
  1058. mbc.skip_cnt = search_request_map_offset;
  1059. mbc.xoff = (struct GNUNET_HashCode *) &sm[1];
  1060. sm->type = htonl (GNUNET_BLOCK_TYPE_FS_UBLOCK);
  1061. sm->anonymity_level = htonl (sc->anonymity);
  1062. memset (&sm->target,
  1063. 0,
  1064. sizeof(struct GNUNET_PeerIdentity));
  1065. if (GNUNET_FS_uri_test_ksk (sc->uri))
  1066. {
  1067. mbc.keyword_offset = keyword_offset;
  1068. /* calculate how many results we can send in this message */
  1069. mbc.put_cnt = todo;
  1070. /* now build message */
  1071. sm->query = sc->requests[keyword_offset].uquery;
  1072. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1073. &build_result_set,
  1074. &mbc);
  1075. search_request_map_offset += todo;
  1076. GNUNET_assert (0 == mbc.put_cnt);
  1077. GNUNET_assert (total_seen_results >= search_request_map_offset);
  1078. if (total_seen_results != search_request_map_offset)
  1079. {
  1080. /* more requesting to be done... */
  1081. sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED);
  1082. }
  1083. else
  1084. {
  1085. sm->options = htonl (options);
  1086. keyword_offset++;
  1087. if (sc->uri->data.ksk.keywordCount != keyword_offset)
  1088. {
  1089. /* more keywords => more requesting to be done... */
  1090. first_call = GNUNET_YES;
  1091. search_request_map_offset = 0;
  1092. mbc.put_cnt = 0;
  1093. mbc.keyword_offset = keyword_offset;
  1094. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1095. &find_result_set,
  1096. &mbc);
  1097. total_seen_results = mbc.put_cnt;
  1098. }
  1099. }
  1100. }
  1101. else
  1102. {
  1103. GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri));
  1104. GNUNET_CRYPTO_ecdsa_public_key_derive (&sc->uri->data.sks.ns,
  1105. sc->uri->data.sks.identifier,
  1106. "fs-ublock",
  1107. &dpub);
  1108. GNUNET_CRYPTO_hash (&dpub,
  1109. sizeof(dpub),
  1110. &sm->query);
  1111. mbc.put_cnt = todo;
  1112. mbc.keyword_offset = 0;
  1113. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1114. &build_result_set,
  1115. &mbc);
  1116. GNUNET_assert (total_seen_results >= search_request_map_offset);
  1117. if (total_seen_results != search_request_map_offset)
  1118. {
  1119. /* more requesting to be done... */
  1120. sm->options = htonl (options | SEARCH_MESSAGE_OPTION_CONTINUED);
  1121. }
  1122. else
  1123. {
  1124. sm->options = htonl (options);
  1125. }
  1126. }
  1127. GNUNET_MQ_send (sc->mq,
  1128. env);
  1129. }
  1130. }
  1131. /**
  1132. * Generic error handler, called with the appropriate error code and
  1133. * the same closure specified at the creation of the message queue.
  1134. * Not every message queue implementation supports an error handler.
  1135. *
  1136. * @param cls closure with the `struct GNUNET_FS_SearchContext *`
  1137. * @param error error code
  1138. */
  1139. static void
  1140. search_mq_error_handler (void *cls,
  1141. enum GNUNET_MQ_Error error)
  1142. {
  1143. struct GNUNET_FS_SearchContext *sc = cls;
  1144. if (NULL != sc->mq)
  1145. {
  1146. GNUNET_MQ_destroy (sc->mq);
  1147. sc->mq = NULL;
  1148. }
  1149. try_reconnect (sc);
  1150. }
  1151. /**
  1152. * Reconnect to the FS service and transmit
  1153. * our queries NOW.
  1154. *
  1155. * @param cls our search context
  1156. */
  1157. static void
  1158. do_reconnect (void *cls)
  1159. {
  1160. struct GNUNET_FS_SearchContext *sc = cls;
  1161. struct GNUNET_MQ_MessageHandler handlers[] = {
  1162. GNUNET_MQ_hd_var_size (result,
  1163. GNUNET_MESSAGE_TYPE_FS_PUT,
  1164. struct ClientPutMessage,
  1165. sc),
  1166. GNUNET_MQ_handler_end ()
  1167. };
  1168. sc->task = NULL;
  1169. sc->mq = GNUNET_CLIENT_connect (sc->h->cfg,
  1170. "fs",
  1171. handlers,
  1172. &search_mq_error_handler,
  1173. sc);
  1174. if (NULL == sc->mq)
  1175. {
  1176. try_reconnect (sc);
  1177. return;
  1178. }
  1179. schedule_transmit_search_request (sc);
  1180. }
  1181. /**
  1182. * Shutdown any existing connection to the FS
  1183. * service and try to establish a fresh one
  1184. * (and then re-transmit our search request).
  1185. *
  1186. * @param sc the search to reconnec
  1187. */
  1188. static void
  1189. try_reconnect (struct GNUNET_FS_SearchContext *sc)
  1190. {
  1191. if (NULL != sc->mq)
  1192. {
  1193. GNUNET_MQ_destroy (sc->mq);
  1194. sc->mq = NULL;
  1195. }
  1196. sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff);
  1197. sc->task =
  1198. GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff,
  1199. &do_reconnect,
  1200. sc);
  1201. }
  1202. /**
  1203. * Start search for content, internal API.
  1204. *
  1205. * @param h handle to the file sharing subsystem
  1206. * @param uri specifies the search parameters; can be
  1207. * a KSK URI or an SKS URI.
  1208. * @param anonymity desired level of anonymity
  1209. * @param options options for the search
  1210. * @param cctx initial value for the client context
  1211. * @param psearch parent search result (for namespace update searches)
  1212. * @return context that can be used to control the search
  1213. */
  1214. static struct GNUNET_FS_SearchContext *
  1215. search_start (struct GNUNET_FS_Handle *h,
  1216. const struct GNUNET_FS_Uri *uri,
  1217. uint32_t anonymity,
  1218. enum GNUNET_FS_SearchOptions options,
  1219. void *cctx,
  1220. struct GNUNET_FS_SearchResult *psearch)
  1221. {
  1222. struct GNUNET_FS_SearchContext *sc;
  1223. struct GNUNET_FS_ProgressInfo pi;
  1224. sc = GNUNET_new (struct GNUNET_FS_SearchContext);
  1225. sc->h = h;
  1226. sc->options = options;
  1227. sc->uri = GNUNET_FS_uri_dup (uri);
  1228. sc->anonymity = anonymity;
  1229. sc->start_time = GNUNET_TIME_absolute_get ();
  1230. if (NULL != psearch)
  1231. {
  1232. sc->psearch_result = psearch;
  1233. psearch->update_search = sc;
  1234. }
  1235. sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
  1236. sc->client_info = cctx;
  1237. if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))
  1238. {
  1239. GNUNET_FS_uri_destroy (sc->uri);
  1240. GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
  1241. GNUNET_free (sc);
  1242. return NULL;
  1243. }
  1244. GNUNET_FS_search_sync_ (sc);
  1245. pi.status = GNUNET_FS_STATUS_SEARCH_START;
  1246. sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  1247. return sc;
  1248. }
  1249. /**
  1250. * Update the 'results' map for the individual keywords with the
  1251. * results from the 'global' result set.
  1252. *
  1253. * @param cls closure, the `struct GNUNET_FS_SearchContext *`
  1254. * @param key current key code
  1255. * @param value value in the hash map, the `struct GNUNET_FS_SearchResult *`
  1256. * @return #GNUNET_YES (we should continue to iterate)
  1257. */
  1258. static int
  1259. update_sre_result_maps (void *cls,
  1260. const struct GNUNET_HashCode *key,
  1261. void *value)
  1262. {
  1263. struct GNUNET_FS_SearchContext *sc = cls;
  1264. struct GNUNET_FS_SearchResult *sr = value;
  1265. for (unsigned int i = 0; i < sc->uri->data.ksk.keywordCount; i++)
  1266. {
  1267. if (0 != (sr->keyword_bitmap[i / 8] & (1 << (i % 8))))
  1268. GNUNET_break (GNUNET_OK ==
  1269. GNUNET_CONTAINER_multihashmap_put (sc->requests[i].results,
  1270. &sr->key,
  1271. sr,
  1272. GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
  1273. }
  1274. return GNUNET_YES;
  1275. }
  1276. /**
  1277. * Build the request and actually initiate the search using the
  1278. * GNUnet FS service.
  1279. *
  1280. * @param sc search context
  1281. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  1282. */
  1283. int
  1284. GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
  1285. {
  1286. unsigned int i;
  1287. const char *keyword;
  1288. const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon;
  1289. struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub;
  1290. struct SearchRequestEntry *sre;
  1291. GNUNET_assert (NULL == sc->mq);
  1292. if (GNUNET_FS_uri_test_ksk (sc->uri))
  1293. {
  1294. GNUNET_assert (0 != sc->uri->data.ksk.keywordCount);
  1295. anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
  1296. GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub);
  1297. sc->requests
  1298. = GNUNET_new_array (sc->uri->data.ksk.keywordCount,
  1299. struct SearchRequestEntry);
  1300. for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
  1301. {
  1302. keyword = &sc->uri->data.ksk.keywords[i][1];
  1303. sre = &sc->requests[i];
  1304. sre->keyword = GNUNET_strdup (keyword);
  1305. GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub,
  1306. keyword,
  1307. "fs-ublock",
  1308. &sre->dpub);
  1309. GNUNET_CRYPTO_hash (&sre->dpub,
  1310. sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
  1311. &sre->uquery);
  1312. sre->mandatory = (sc->uri->data.ksk.keywords[i][0] == '+');
  1313. if (sre->mandatory)
  1314. sc->mandatory_count++;
  1315. sre->results = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
  1316. }
  1317. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1318. &update_sre_result_maps,
  1319. sc);
  1320. }
  1321. GNUNET_assert (NULL == sc->task);
  1322. do_reconnect (sc);
  1323. if (NULL == sc->mq)
  1324. {
  1325. GNUNET_SCHEDULER_cancel (sc->task);
  1326. sc->task = NULL;
  1327. return GNUNET_SYSERR;
  1328. }
  1329. return GNUNET_OK;
  1330. }
  1331. /**
  1332. * Freeze probes for the given search result.
  1333. *
  1334. * @param cls the global FS handle
  1335. * @param key the key for the search result (unused)
  1336. * @param value the search result to free
  1337. * @return #GNUNET_OK
  1338. */
  1339. static int
  1340. search_result_freeze_probes (void *cls,
  1341. const struct GNUNET_HashCode *key,
  1342. void *value)
  1343. {
  1344. struct GNUNET_FS_SearchResult *sr = value;
  1345. if (NULL != sr->probe_ctx)
  1346. {
  1347. GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
  1348. sr->probe_ctx = NULL;
  1349. GNUNET_FS_stop_probe_ping_task_ (sr);
  1350. }
  1351. if (NULL != sr->probe_cancel_task)
  1352. {
  1353. GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
  1354. sr->probe_cancel_task = NULL;
  1355. }
  1356. if (NULL != sr->update_search)
  1357. GNUNET_FS_search_pause (sr->update_search);
  1358. return GNUNET_OK;
  1359. }
  1360. /**
  1361. * Resume probes for the given search result.
  1362. *
  1363. * @param cls the global FS handle
  1364. * @param key the key for the search result (unused)
  1365. * @param value the search result to free
  1366. * @return #GNUNET_OK
  1367. */
  1368. static int
  1369. search_result_resume_probes (void *cls,
  1370. const struct GNUNET_HashCode *key,
  1371. void *value)
  1372. {
  1373. struct GNUNET_FS_SearchResult *sr = value;
  1374. GNUNET_FS_search_start_probe_ (sr);
  1375. if (NULL != sr->update_search)
  1376. GNUNET_FS_search_continue (sr->update_search);
  1377. return GNUNET_OK;
  1378. }
  1379. /**
  1380. * Signal suspend and free the given search result.
  1381. *
  1382. * @param cls the global FS handle
  1383. * @param key the key for the search result (unused)
  1384. * @param value the search result to free
  1385. * @return #GNUNET_OK
  1386. */
  1387. static int
  1388. search_result_suspend (void *cls,
  1389. const struct GNUNET_HashCode *key,
  1390. void *value)
  1391. {
  1392. struct GNUNET_FS_SearchContext *sc = cls;
  1393. struct GNUNET_FS_SearchResult *sr = value;
  1394. struct GNUNET_FS_ProgressInfo pi;
  1395. if (NULL != sr->download)
  1396. {
  1397. GNUNET_FS_download_signal_suspend_ (sr->download);
  1398. sr->download = NULL;
  1399. }
  1400. if (NULL != sr->update_search)
  1401. {
  1402. GNUNET_FS_search_signal_suspend_ (sr->update_search);
  1403. sr->update_search = NULL;
  1404. }
  1405. GNUNET_FS_search_stop_probe_ (sr);
  1406. if (0 == sr->mandatory_missing)
  1407. {
  1408. /* client is aware of search result, notify about suspension event */
  1409. pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND;
  1410. pi.value.search.specifics.result_suspend.cctx = sr->client_info;
  1411. pi.value.search.specifics.result_suspend.meta = sr->meta;
  1412. pi.value.search.specifics.result_suspend.uri = sr->uri;
  1413. sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  1414. }
  1415. GNUNET_break (NULL == sr->client_info);
  1416. GNUNET_free_non_null (sr->serialization);
  1417. GNUNET_FS_uri_destroy (sr->uri);
  1418. GNUNET_CONTAINER_meta_data_destroy (sr->meta);
  1419. GNUNET_free_non_null (sr->keyword_bitmap);
  1420. GNUNET_free (sr);
  1421. return GNUNET_OK;
  1422. }
  1423. /**
  1424. * Create SUSPEND event for the given search operation
  1425. * and then clean up our state (without stop signal).
  1426. *
  1427. * @param cls the `struct GNUNET_FS_SearchContext` to signal for
  1428. */
  1429. void
  1430. GNUNET_FS_search_signal_suspend_ (void *cls)
  1431. {
  1432. struct GNUNET_FS_SearchContext *sc = cls;
  1433. struct GNUNET_FS_ProgressInfo pi;
  1434. unsigned int i;
  1435. GNUNET_FS_end_top (sc->h, sc->top);
  1436. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1437. &search_result_suspend, sc);
  1438. pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND;
  1439. sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  1440. GNUNET_break (NULL == sc->client_info);
  1441. if (sc->task != NULL)
  1442. {
  1443. GNUNET_SCHEDULER_cancel (sc->task);
  1444. sc->task = NULL;
  1445. }
  1446. if (NULL != sc->mq)
  1447. {
  1448. GNUNET_MQ_destroy (sc->mq);
  1449. sc->mq = NULL;
  1450. }
  1451. GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
  1452. if (NULL != sc->requests)
  1453. {
  1454. GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
  1455. for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
  1456. {
  1457. GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
  1458. GNUNET_free (sc->requests[i].keyword);
  1459. }
  1460. }
  1461. GNUNET_free_non_null (sc->requests);
  1462. GNUNET_free_non_null (sc->emsg);
  1463. GNUNET_FS_uri_destroy (sc->uri);
  1464. GNUNET_free_non_null (sc->serialization);
  1465. GNUNET_free (sc);
  1466. }
  1467. /**
  1468. * Start search for content.
  1469. *
  1470. * @param h handle to the file sharing subsystem
  1471. * @param uri specifies the search parameters; can be
  1472. * a KSK URI or an SKS URI.
  1473. * @param anonymity desired level of anonymity
  1474. * @param options options for the search
  1475. * @param cctx initial value for the client context
  1476. * @return context that can be used to control the search
  1477. */
  1478. struct GNUNET_FS_SearchContext *
  1479. GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
  1480. const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
  1481. enum GNUNET_FS_SearchOptions options, void *cctx)
  1482. {
  1483. struct GNUNET_FS_SearchContext *ret;
  1484. ret = search_start (h, uri, anonymity, options, cctx, NULL);
  1485. if (NULL == ret)
  1486. return NULL;
  1487. ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret);
  1488. return ret;
  1489. }
  1490. /**
  1491. * Pause search.
  1492. *
  1493. * @param sc context for the search that should be paused
  1494. */
  1495. void
  1496. GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
  1497. {
  1498. struct GNUNET_FS_ProgressInfo pi;
  1499. if (NULL != sc->task)
  1500. {
  1501. GNUNET_SCHEDULER_cancel (sc->task);
  1502. sc->task = NULL;
  1503. }
  1504. if (NULL != sc->mq)
  1505. {
  1506. GNUNET_MQ_destroy (sc->mq);
  1507. sc->mq = NULL;
  1508. }
  1509. GNUNET_FS_search_sync_ (sc);
  1510. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1511. &search_result_freeze_probes,
  1512. sc);
  1513. pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
  1514. sc->client_info = GNUNET_FS_search_make_status_ (&pi,
  1515. sc->h,
  1516. sc);
  1517. }
  1518. /**
  1519. * Continue paused search.
  1520. *
  1521. * @param sc context for the search that should be resumed
  1522. */
  1523. void
  1524. GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
  1525. {
  1526. struct GNUNET_FS_ProgressInfo pi;
  1527. GNUNET_assert (NULL == sc->mq);
  1528. GNUNET_assert (NULL == sc->task);
  1529. do_reconnect (sc);
  1530. GNUNET_FS_search_sync_ (sc);
  1531. pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
  1532. sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
  1533. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1534. &search_result_resume_probes, sc);
  1535. }
  1536. /**
  1537. * Signal stop for the given search result.
  1538. *
  1539. * @param cls the global FS handle
  1540. * @param key the key for the search result (unused)
  1541. * @param value the search result to free
  1542. * @return #GNUNET_OK
  1543. */
  1544. static int
  1545. search_result_stop (void *cls,
  1546. const struct GNUNET_HashCode *key,
  1547. void *value)
  1548. {
  1549. struct GNUNET_FS_SearchContext *sc = cls;
  1550. struct GNUNET_FS_SearchResult *sr = value;
  1551. struct GNUNET_FS_ProgressInfo pi;
  1552. GNUNET_FS_search_stop_probe_ (sr);
  1553. if (NULL != sr->download)
  1554. {
  1555. sr->download->search = NULL;
  1556. sr->download->top
  1557. = GNUNET_FS_make_top (sr->download->h,
  1558. &GNUNET_FS_download_signal_suspend_,
  1559. sr->download);
  1560. if (NULL != sr->download->serialization)
  1561. {
  1562. GNUNET_FS_remove_sync_file_ (sc->h,
  1563. GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
  1564. sr->download->serialization);
  1565. GNUNET_free (sr->download->serialization);
  1566. sr->download->serialization = NULL;
  1567. }
  1568. pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
  1569. GNUNET_FS_download_make_status_ (&pi,
  1570. sr->download);
  1571. GNUNET_FS_download_sync_ (sr->download);
  1572. sr->download = NULL;
  1573. }
  1574. if (0 != sr->mandatory_missing)
  1575. {
  1576. /* client is unaware of search result as
  1577. it does not match required keywords */
  1578. GNUNET_break (NULL == sr->client_info);
  1579. return GNUNET_OK;
  1580. }
  1581. pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
  1582. pi.value.search.specifics.result_stopped.cctx = sr->client_info;
  1583. pi.value.search.specifics.result_stopped.meta = sr->meta;
  1584. pi.value.search.specifics.result_stopped.uri = sr->uri;
  1585. sr->client_info = GNUNET_FS_search_make_status_ (&pi, sr->h, sc);
  1586. return GNUNET_OK;
  1587. }
  1588. /**
  1589. * Free the given search result.
  1590. *
  1591. * @param cls the global FS handle
  1592. * @param key the key for the search result (unused)
  1593. * @param value the search result to free
  1594. * @return #GNUNET_OK
  1595. */
  1596. static int
  1597. search_result_free (void *cls,
  1598. const struct GNUNET_HashCode *key,
  1599. void *value)
  1600. {
  1601. struct GNUNET_FS_SearchResult *sr = value;
  1602. if (NULL != sr->update_search)
  1603. {
  1604. GNUNET_FS_search_stop (sr->update_search);
  1605. GNUNET_assert (NULL == sr->update_search);
  1606. }
  1607. GNUNET_break (NULL == sr->probe_ctx);
  1608. GNUNET_break (NULL == sr->probe_cancel_task);
  1609. GNUNET_break (NULL == sr->client_info);
  1610. GNUNET_free_non_null (sr->serialization);
  1611. GNUNET_FS_uri_destroy (sr->uri);
  1612. GNUNET_CONTAINER_meta_data_destroy (sr->meta);
  1613. GNUNET_free_non_null (sr->keyword_bitmap);
  1614. GNUNET_free (sr);
  1615. return GNUNET_OK;
  1616. }
  1617. /**
  1618. * Stop search for content.
  1619. *
  1620. * @param sc context for the search that should be stopped
  1621. */
  1622. void
  1623. GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
  1624. {
  1625. struct GNUNET_FS_ProgressInfo pi;
  1626. unsigned int i;
  1627. if (NULL != sc->top)
  1628. GNUNET_FS_end_top (sc->h, sc->top);
  1629. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1630. &search_result_stop,
  1631. sc);
  1632. if (NULL != sc->psearch_result)
  1633. sc->psearch_result->update_search = NULL;
  1634. if (NULL != sc->serialization)
  1635. {
  1636. GNUNET_FS_remove_sync_file_ (sc->h,
  1637. (NULL != sc->psearch_result)
  1638. ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
  1639. : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
  1640. sc->serialization);
  1641. GNUNET_FS_remove_sync_dir_ (sc->h,
  1642. (NULL != sc->psearch_result)
  1643. ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
  1644. : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
  1645. sc->serialization);
  1646. GNUNET_free (sc->serialization);
  1647. }
  1648. pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
  1649. sc->client_info = GNUNET_FS_search_make_status_ (&pi,
  1650. sc->h,
  1651. sc);
  1652. GNUNET_break (NULL == sc->client_info);
  1653. if (NULL != sc->task)
  1654. {
  1655. GNUNET_SCHEDULER_cancel (sc->task);
  1656. sc->task = NULL;
  1657. }
  1658. if (NULL != sc->mq)
  1659. {
  1660. GNUNET_MQ_destroy (sc->mq);
  1661. sc->mq = NULL;
  1662. }
  1663. GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
  1664. &search_result_free, sc);
  1665. GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
  1666. if (NULL != sc->requests)
  1667. {
  1668. GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
  1669. for (i = 0; i < sc->uri->data.ksk.keywordCount; i++)
  1670. GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
  1671. }
  1672. GNUNET_free_non_null (sc->requests);
  1673. GNUNET_free_non_null (sc->emsg);
  1674. GNUNET_FS_uri_destroy (sc->uri);
  1675. GNUNET_free (sc);
  1676. }
  1677. /* end of fs_search.c */