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