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