diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/fs_search.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r-- | src/fs/fs_search.c | 1159 |
1 files changed, 532 insertions, 627 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 526e6513b..60b7a1cc8 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -42,20 +42,19 @@ | |||
42 | */ | 42 | */ |
43 | void * | 43 | void * |
44 | GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | 44 | GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
45 | struct GNUNET_FS_SearchContext *sc) | 45 | struct GNUNET_FS_SearchContext *sc) |
46 | { | 46 | { |
47 | void *ret; | 47 | void *ret; |
48 | |||
48 | pi->value.search.sc = sc; | 49 | pi->value.search.sc = sc; |
49 | pi->value.search.cctx | 50 | pi->value.search.cctx = sc->client_info; |
50 | = sc->client_info; | ||
51 | pi->value.search.pctx | 51 | pi->value.search.pctx |
52 | = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info; | 52 | = (sc->psearch_result == NULL) ? NULL : sc->psearch_result->client_info; |
53 | pi->value.search.query | 53 | pi->value.search.query = sc->uri; |
54 | = sc->uri; | 54 | pi->value.search.duration = |
55 | pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time); | 55 | GNUNET_TIME_absolute_get_duration (sc->start_time); |
56 | pi->value.search.anonymity = sc->anonymity; | 56 | pi->value.search.anonymity = sc->anonymity; |
57 | ret = sc->h->upcb (sc->h->upcb_cls, | 57 | ret = sc->h->upcb (sc->h->upcb_cls, pi); |
58 | pi); | ||
59 | return ret; | 58 | return ret; |
60 | } | 59 | } |
61 | 60 | ||
@@ -72,15 +71,12 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
72 | * GNUNET_OK otherwise | 71 | * GNUNET_OK otherwise |
73 | */ | 72 | */ |
74 | static int | 73 | static int |
75 | test_result_present (void *cls, | 74 | test_result_present (void *cls, const GNUNET_HashCode * key, void *value) |
76 | const GNUNET_HashCode * key, | ||
77 | void *value) | ||
78 | { | 75 | { |
79 | const struct GNUNET_FS_Uri *uri = cls; | 76 | const struct GNUNET_FS_Uri *uri = cls; |
80 | struct GNUNET_FS_SearchResult *sr = value; | 77 | struct GNUNET_FS_SearchResult *sr = value; |
81 | 78 | ||
82 | if (GNUNET_FS_uri_test_equal (uri, | 79 | if (GNUNET_FS_uri_test_equal (uri, sr->uri)) |
83 | sr->uri)) | ||
84 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
85 | return GNUNET_OK; | 81 | return GNUNET_OK; |
86 | } | 82 | } |
@@ -94,9 +90,9 @@ test_result_present (void *cls, | |||
94 | * @param sr the specific result | 90 | * @param sr the specific result |
95 | */ | 91 | */ |
96 | static void | 92 | static void |
97 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | 93 | notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, |
98 | struct GNUNET_FS_SearchResult *sr) | 94 | struct GNUNET_FS_SearchResult *sr) |
99 | { | 95 | { |
100 | struct GNUNET_FS_ProgressInfo pi; | 96 | struct GNUNET_FS_ProgressInfo pi; |
101 | 97 | ||
102 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT; | 98 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT; |
@@ -116,9 +112,9 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc, | |||
116 | * @param sr the specific result | 112 | * @param sr the specific result |
117 | */ | 113 | */ |
118 | static void | 114 | static void |
119 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | 115 | notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, |
120 | struct GNUNET_FS_SearchResult *sr) | 116 | struct GNUNET_FS_SearchResult *sr) |
121 | { | 117 | { |
122 | struct GNUNET_FS_ProgressInfo pi; | 118 | struct GNUNET_FS_ProgressInfo pi; |
123 | 119 | ||
124 | pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE; | 120 | pi.status = GNUNET_FS_STATUS_SEARCH_UPDATE; |
@@ -126,11 +122,10 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | |||
126 | pi.value.search.specifics.update.meta = sr->meta; | 122 | pi.value.search.specifics.update.meta = sr->meta; |
127 | pi.value.search.specifics.update.uri = sr->uri; | 123 | pi.value.search.specifics.update.uri = sr->uri; |
128 | pi.value.search.specifics.update.availability_rank | 124 | pi.value.search.specifics.update.availability_rank |
129 | = 2*sr->availability_success - sr->availability_trials; | 125 | = 2 * sr->availability_success - sr->availability_trials; |
130 | pi.value.search.specifics.update.availability_certainty | 126 | pi.value.search.specifics.update.availability_certainty |
131 | = sr->availability_trials; | 127 | = sr->availability_trials; |
132 | pi.value.search.specifics.update.applicability_rank | 128 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
133 | = sr->optional_support; | ||
134 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 129 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
135 | } | 130 | } |
136 | 131 | ||
@@ -138,7 +133,7 @@ notify_client_chk_update (struct GNUNET_FS_SearchContext *sc, | |||
138 | /** | 133 | /** |
139 | * Context for "get_result_present". | 134 | * Context for "get_result_present". |
140 | */ | 135 | */ |
141 | struct GetResultContext | 136 | struct GetResultContext |
142 | { | 137 | { |
143 | /** | 138 | /** |
144 | * The URI we're looking for. | 139 | * The URI we're looking for. |
@@ -164,15 +159,12 @@ struct GetResultContext | |||
164 | * @return GNUNET_OK | 159 | * @return GNUNET_OK |
165 | */ | 160 | */ |
166 | static int | 161 | static int |
167 | get_result_present (void *cls, | 162 | get_result_present (void *cls, const GNUNET_HashCode * key, void *value) |
168 | const GNUNET_HashCode * key, | ||
169 | void *value) | ||
170 | { | 163 | { |
171 | struct GetResultContext *grc = cls; | 164 | struct GetResultContext *grc = cls; |
172 | struct GNUNET_FS_SearchResult *sr = value; | 165 | struct GNUNET_FS_SearchResult *sr = value; |
173 | 166 | ||
174 | if (GNUNET_FS_uri_test_equal (grc->uri, | 167 | if (GNUNET_FS_uri_test_equal (grc->uri, sr->uri)) |
175 | sr->uri)) | ||
176 | grc->sr = sr; | 168 | grc->sr = sr; |
177 | return GNUNET_OK; | 169 | return GNUNET_OK; |
178 | } | 170 | } |
@@ -192,7 +184,8 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) | |||
192 | pi.value.search.specifics.update.meta = sr->meta; | 184 | pi.value.search.specifics.update.meta = sr->meta; |
193 | pi.value.search.specifics.update.uri = sr->uri; | 185 | pi.value.search.specifics.update.uri = sr->uri; |
194 | pi.value.search.specifics.update.availability_rank = sr->availability_success; | 186 | pi.value.search.specifics.update.availability_rank = sr->availability_success; |
195 | pi.value.search.specifics.update.availability_certainty = sr->availability_trials; | 187 | pi.value.search.specifics.update.availability_certainty = |
188 | sr->availability_trials; | ||
196 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; | 189 | pi.value.search.specifics.update.applicability_rank = sr->optional_support; |
197 | sr->sc->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc); | 190 | sr->sc->client_info = GNUNET_FS_search_make_status_ (&pi, sr->sc); |
198 | GNUNET_FS_search_start_probe_ (sr); | 191 | GNUNET_FS_search_start_probe_ (sr); |
@@ -206,10 +199,10 @@ signal_probe_result (struct GNUNET_FS_SearchResult *sr) | |||
206 | * @param tc scheduler context | 199 | * @param tc scheduler context |
207 | */ | 200 | */ |
208 | static void | 201 | static void |
209 | probe_failure_handler (void *cls, | 202 | probe_failure_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
210 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
211 | { | 203 | { |
212 | struct GNUNET_FS_SearchResult *sr = cls; | 204 | struct GNUNET_FS_SearchResult *sr = cls; |
205 | |||
213 | sr->availability_trials++; | 206 | sr->availability_trials++; |
214 | GNUNET_FS_search_result_sync_ (sr); | 207 | GNUNET_FS_search_result_sync_ (sr); |
215 | signal_probe_result (sr); | 208 | signal_probe_result (sr); |
@@ -223,10 +216,10 @@ probe_failure_handler (void *cls, | |||
223 | * @param tc scheduler context | 216 | * @param tc scheduler context |
224 | */ | 217 | */ |
225 | static void | 218 | static void |
226 | probe_success_handler (void *cls, | 219 | probe_success_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
227 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
228 | { | 220 | { |
229 | struct GNUNET_FS_SearchResult *sr = cls; | 221 | struct GNUNET_FS_SearchResult *sr = cls; |
222 | |||
230 | sr->availability_trials++; | 223 | sr->availability_trials++; |
231 | sr->availability_success++; | 224 | sr->availability_success++; |
232 | GNUNET_FS_search_result_sync_ (sr); | 225 | GNUNET_FS_search_result_sync_ (sr); |
@@ -249,79 +242,79 @@ probe_success_handler (void *cls, | |||
249 | * will be passed to future callbacks in the respective | 242 | * will be passed to future callbacks in the respective |
250 | * field in the GNUNET_FS_ProgressInfo struct. | 243 | * field in the GNUNET_FS_ProgressInfo struct. |
251 | */ | 244 | */ |
252 | void* | 245 | void * |
253 | GNUNET_FS_search_probe_progress_ (void *cls, | 246 | GNUNET_FS_search_probe_progress_ (void *cls, |
254 | const struct GNUNET_FS_ProgressInfo *info) | 247 | const struct GNUNET_FS_ProgressInfo *info) |
255 | { | 248 | { |
256 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; | 249 | struct GNUNET_FS_SearchResult *sr = info->value.download.cctx; |
257 | struct GNUNET_TIME_Relative dur; | 250 | struct GNUNET_TIME_Relative dur; |
258 | 251 | ||
259 | switch (info->status) | 252 | switch (info->status) |
253 | { | ||
254 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
255 | /* ignore */ | ||
256 | break; | ||
257 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | ||
258 | /* probes should never be resumed */ | ||
259 | GNUNET_assert (0); | ||
260 | break; | ||
261 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | ||
262 | /* probes should never be suspended */ | ||
263 | GNUNET_break (0); | ||
264 | break; | ||
265 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
266 | /* ignore */ | ||
267 | break; | ||
268 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
269 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | ||
260 | { | 270 | { |
261 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 271 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
262 | /* ignore */ | 272 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; |
263 | break; | 273 | } |
264 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | 274 | sr->probe_cancel_task = |
265 | /* probes should never be resumed */ | 275 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, |
266 | GNUNET_assert (0); | 276 | &probe_failure_handler, sr); |
267 | break; | 277 | break; |
268 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | 278 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
269 | /* probes should never be suspended */ | 279 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) |
270 | GNUNET_break (0); | 280 | { |
271 | break; | 281 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
272 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 282 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; |
273 | /* ignore */ | 283 | } |
274 | break; | 284 | sr->probe_cancel_task = |
275 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 285 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, |
276 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | 286 | &probe_success_handler, sr); |
277 | { | 287 | break; |
278 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 288 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: |
279 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | 289 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) |
280 | } | 290 | { |
281 | sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | 291 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
282 | &probe_failure_handler, | 292 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; |
283 | sr); | ||
284 | break; | ||
285 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
286 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | ||
287 | { | ||
288 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
289 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | ||
290 | } | ||
291 | sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | ||
292 | &probe_success_handler, | ||
293 | sr); | ||
294 | break; | ||
295 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
296 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | ||
297 | { | ||
298 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
299 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | ||
300 | } | ||
301 | sr = NULL; | ||
302 | break; | ||
303 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
304 | GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK); | ||
305 | sr->probe_active_time = GNUNET_TIME_absolute_get (); | ||
306 | sr->probe_cancel_task = GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | ||
307 | &probe_failure_handler, | ||
308 | sr); | ||
309 | break; | ||
310 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
311 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | ||
312 | { | ||
313 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
314 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | ||
315 | } | ||
316 | dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | ||
317 | sr->remaining_probe_time = GNUNET_TIME_relative_subtract (sr->remaining_probe_time, | ||
318 | dur); | ||
319 | GNUNET_FS_search_result_sync_ (sr); | ||
320 | break; | ||
321 | default: | ||
322 | GNUNET_break (0); | ||
323 | return NULL; | ||
324 | } | 293 | } |
294 | sr = NULL; | ||
295 | break; | ||
296 | case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: | ||
297 | GNUNET_assert (sr->probe_cancel_task == GNUNET_SCHEDULER_NO_TASK); | ||
298 | sr->probe_active_time = GNUNET_TIME_absolute_get (); | ||
299 | sr->probe_cancel_task = | ||
300 | GNUNET_SCHEDULER_add_delayed (sr->remaining_probe_time, | ||
301 | &probe_failure_handler, sr); | ||
302 | break; | ||
303 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | ||
304 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | ||
305 | { | ||
306 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | ||
307 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | ||
308 | } | ||
309 | dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); | ||
310 | sr->remaining_probe_time = | ||
311 | GNUNET_TIME_relative_subtract (sr->remaining_probe_time, dur); | ||
312 | GNUNET_FS_search_result_sync_ (sr); | ||
313 | break; | ||
314 | default: | ||
315 | GNUNET_break (0); | ||
316 | return NULL; | ||
317 | } | ||
325 | return sr; | 318 | return sr; |
326 | } | 319 | } |
327 | 320 | ||
@@ -336,7 +329,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
336 | { | 329 | { |
337 | uint64_t off; | 330 | uint64_t off; |
338 | uint64_t len; | 331 | uint64_t len; |
339 | 332 | ||
340 | if (sr->probe_ctx != NULL) | 333 | if (sr->probe_ctx != NULL) |
341 | return; | 334 | return; |
342 | if (sr->download != NULL) | 335 | if (sr->download != NULL) |
@@ -348,7 +341,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
348 | len = GNUNET_FS_uri_chk_get_file_size (sr->uri); | 341 | len = GNUNET_FS_uri_chk_get_file_size (sr->uri); |
349 | if (len == 0) | 342 | if (len == 0) |
350 | return; | 343 | return; |
351 | if ( (len <= DBLOCK_SIZE) && (sr->availability_success > 0)) | 344 | if ((len <= DBLOCK_SIZE) && (sr->availability_success > 0)) |
352 | return; | 345 | return; |
353 | off = len / DBLOCK_SIZE; | 346 | off = len / DBLOCK_SIZE; |
354 | if (off > 0) | 347 | if (off > 0) |
@@ -358,17 +351,14 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
358 | len = len - off; | 351 | len = len - off; |
359 | else | 352 | else |
360 | len = DBLOCK_SIZE; | 353 | len = DBLOCK_SIZE; |
361 | sr->remaining_probe_time = GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency, | 354 | sr->remaining_probe_time = |
362 | 2 * (1 + sr->availability_trials)); | 355 | GNUNET_TIME_relative_multiply (sr->sc->h->avg_block_latency, |
363 | sr->probe_ctx = GNUNET_FS_download_start (sr->sc->h, | 356 | 2 * (1 + sr->availability_trials)); |
364 | sr->uri, | 357 | sr->probe_ctx = |
365 | sr->meta, | 358 | GNUNET_FS_download_start (sr->sc->h, sr->uri, sr->meta, NULL, NULL, off, |
366 | NULL, NULL, | 359 | len, sr->sc->anonymity, |
367 | off, len, | 360 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | |
368 | sr->sc->anonymity, | 361 | GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); |
369 | GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | | ||
370 | GNUNET_FS_DOWNLOAD_IS_PROBE, | ||
371 | sr, NULL); | ||
372 | } | 362 | } |
373 | 363 | ||
374 | 364 | ||
@@ -383,10 +373,10 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr) | |||
383 | * under the "ent" keyword | 373 | * under the "ent" keyword |
384 | */ | 374 | */ |
385 | static void | 375 | static void |
386 | process_ksk_result (struct GNUNET_FS_SearchContext *sc, | 376 | process_ksk_result (struct GNUNET_FS_SearchContext *sc, |
387 | struct SearchRequestEntry *ent, | 377 | struct SearchRequestEntry *ent, |
388 | const struct GNUNET_FS_Uri *uri, | 378 | const struct GNUNET_FS_Uri *uri, |
389 | const struct GNUNET_CONTAINER_MetaData *meta) | 379 | const struct GNUNET_CONTAINER_MetaData *meta) |
390 | { | 380 | { |
391 | GNUNET_HashCode key; | 381 | GNUNET_HashCode key; |
392 | struct GNUNET_FS_SearchResult *sr; | 382 | struct GNUNET_FS_SearchResult *sr; |
@@ -397,36 +387,34 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
397 | GNUNET_FS_uri_to_key (uri, &key); | 387 | GNUNET_FS_uri_to_key (uri, &key); |
398 | if (GNUNET_SYSERR == | 388 | if (GNUNET_SYSERR == |
399 | GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, | 389 | GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, |
400 | &key, | 390 | &key, |
401 | &test_result_present, | 391 | &test_result_present, |
402 | (void*) uri)) | 392 | (void *) uri)) |
403 | return; /* duplicate result */ | 393 | return; /* duplicate result */ |
404 | /* try to find search result in master map */ | 394 | /* try to find search result in master map */ |
405 | grc.sr = NULL; | 395 | grc.sr = NULL; |
406 | grc.uri = uri; | 396 | grc.uri = uri; |
407 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, | 397 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, |
408 | &key, | 398 | &key, &get_result_present, &grc); |
409 | &get_result_present, | ||
410 | &grc); | ||
411 | sr = grc.sr; | 399 | sr = grc.sr; |
412 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); | 400 | is_new = (NULL == sr) || (sr->mandatory_missing > 0); |
413 | if (NULL == sr) | 401 | if (NULL == sr) |
414 | { | 402 | { |
415 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); | 403 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); |
416 | sr->sc = sc; | 404 | sr->sc = sc; |
417 | sr->uri = GNUNET_FS_uri_dup (uri); | 405 | sr->uri = GNUNET_FS_uri_dup (uri); |
418 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 406 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
419 | sr->mandatory_missing = sc->mandatory_count; | 407 | sr->mandatory_missing = sc->mandatory_count; |
420 | sr->key = key; | 408 | sr->key = key; |
421 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, | 409 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, |
422 | &key, | 410 | &key, |
423 | sr, | 411 | sr, |
424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 412 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
425 | } | 413 | } |
426 | else | 414 | else |
427 | { | 415 | { |
428 | GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); | 416 | GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); |
429 | } | 417 | } |
430 | /* check if mandatory satisfied */ | 418 | /* check if mandatory satisfied */ |
431 | if (ent->mandatory) | 419 | if (ent->mandatory) |
432 | sr->mandatory_missing--; | 420 | sr->mandatory_missing--; |
@@ -455,13 +443,15 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
455 | * @param psearch parent search result (for namespace update searches) | 443 | * @param psearch parent search result (for namespace update searches) |
456 | * @return context that can be used to control the search | 444 | * @return context that can be used to control the search |
457 | */ | 445 | */ |
458 | static struct GNUNET_FS_SearchContext * | 446 | static struct GNUNET_FS_SearchContext *search_start (struct GNUNET_FS_Handle *h, |
459 | search_start (struct GNUNET_FS_Handle *h, | 447 | const struct GNUNET_FS_Uri |
460 | const struct GNUNET_FS_Uri *uri, | 448 | *uri, uint32_t anonymity, |
461 | uint32_t anonymity, | 449 | enum |
462 | enum GNUNET_FS_SearchOptions options, | 450 | GNUNET_FS_SearchOptions |
463 | void *cctx, | 451 | options, void *cctx, |
464 | struct GNUNET_FS_SearchResult *psearch); | 452 | struct |
453 | GNUNET_FS_SearchResult | ||
454 | *psearch); | ||
465 | 455 | ||
466 | 456 | ||
467 | /** | 457 | /** |
@@ -474,10 +464,10 @@ search_start (struct GNUNET_FS_Handle *h, | |||
474 | * @param meta metadata associated with the URI | 464 | * @param meta metadata associated with the URI |
475 | */ | 465 | */ |
476 | static void | 466 | static void |
477 | process_sks_result (struct GNUNET_FS_SearchContext *sc, | 467 | process_sks_result (struct GNUNET_FS_SearchContext *sc, |
478 | const char *id_update, | 468 | const char *id_update, |
479 | const struct GNUNET_FS_Uri *uri, | 469 | const struct GNUNET_FS_Uri *uri, |
480 | const struct GNUNET_CONTAINER_MetaData *meta) | 470 | const struct GNUNET_CONTAINER_MetaData *meta) |
481 | { | 471 | { |
482 | struct GNUNET_FS_Uri uu; | 472 | struct GNUNET_FS_Uri uu; |
483 | GNUNET_HashCode key; | 473 | GNUNET_HashCode key; |
@@ -486,39 +476,33 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
486 | /* check if new */ | 476 | /* check if new */ |
487 | GNUNET_FS_uri_to_key (uri, &key); | 477 | GNUNET_FS_uri_to_key (uri, &key); |
488 | GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, | 478 | GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, |
489 | &uri->data.chk.chk.query, | 479 | &uri->data.chk.chk.query, &key); |
490 | &key); | ||
491 | if (GNUNET_SYSERR == | 480 | if (GNUNET_SYSERR == |
492 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, | 481 | GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, |
493 | &key, | 482 | &key, |
494 | &test_result_present, | 483 | &test_result_present, |
495 | (void*) uri)) | 484 | (void *) uri)) |
496 | return; /* duplicate result */ | 485 | return; /* duplicate result */ |
497 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); | 486 | sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); |
498 | sr->sc = sc; | 487 | sr->sc = sc; |
499 | sr->uri = GNUNET_FS_uri_dup (uri); | 488 | sr->uri = GNUNET_FS_uri_dup (uri); |
500 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 489 | sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
501 | sr->key = key; | 490 | sr->key = key; |
502 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, | 491 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, |
503 | &key, | 492 | &key, |
504 | sr, | 493 | sr, |
505 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 494 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
506 | GNUNET_FS_search_result_sync_ (sr); | 495 | GNUNET_FS_search_result_sync_ (sr); |
507 | GNUNET_FS_search_start_probe_ (sr); | 496 | GNUNET_FS_search_start_probe_ (sr); |
508 | /* notify client */ | 497 | /* notify client */ |
509 | notify_client_chk_result (sc, sr); | 498 | notify_client_chk_result (sc, sr); |
510 | /* search for updates */ | 499 | /* search for updates */ |
511 | if (strlen (id_update) == 0) | 500 | if (strlen (id_update) == 0) |
512 | return; /* no updates */ | 501 | return; /* no updates */ |
513 | uu.type = sks; | 502 | uu.type = sks; |
514 | uu.data.sks.namespace = sc->uri->data.sks.namespace; | 503 | uu.data.sks.namespace = sc->uri->data.sks.namespace; |
515 | uu.data.sks.identifier = GNUNET_strdup (id_update); | 504 | uu.data.sks.identifier = GNUNET_strdup (id_update); |
516 | (void) search_start (sc->h, | 505 | (void) search_start (sc->h, &uu, sc->anonymity, sc->options, NULL, sr); |
517 | &uu, | ||
518 | sc->anonymity, | ||
519 | sc->options, | ||
520 | NULL, | ||
521 | sr); | ||
522 | GNUNET_free (uu.data.sks.identifier); | 506 | GNUNET_free (uu.data.sks.identifier); |
523 | } | 507 | } |
524 | 508 | ||
@@ -532,8 +516,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
532 | */ | 516 | */ |
533 | static void | 517 | static void |
534 | process_kblock (struct GNUNET_FS_SearchContext *sc, | 518 | process_kblock (struct GNUNET_FS_SearchContext *sc, |
535 | const struct KBlock *kb, | 519 | const struct KBlock *kb, size_t size) |
536 | size_t size) | ||
537 | { | 520 | { |
538 | unsigned int i; | 521 | unsigned int i; |
539 | size_t j; | 522 | size_t j; |
@@ -545,59 +528,54 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, | |||
545 | struct GNUNET_CONTAINER_MetaData *meta; | 528 | struct GNUNET_CONTAINER_MetaData *meta; |
546 | struct GNUNET_FS_Uri *uri; | 529 | struct GNUNET_FS_Uri *uri; |
547 | char *emsg; | 530 | char *emsg; |
548 | 531 | ||
549 | GNUNET_CRYPTO_hash (&kb->keyspace, | 532 | GNUNET_CRYPTO_hash (&kb->keyspace, |
550 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 533 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
551 | &q); | 534 | &q); |
552 | /* find key */ | 535 | /* find key */ |
553 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | 536 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
554 | if (0 == memcmp (&q, | 537 | if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode))) |
555 | &sc->requests[i].query, | ||
556 | sizeof (GNUNET_HashCode))) | ||
557 | break; | 538 | break; |
558 | if (i == sc->uri->data.ksk.keywordCount) | 539 | if (i == sc->uri->data.ksk.keywordCount) |
559 | { | 540 | { |
560 | /* oops, does not match any of our keywords!? */ | 541 | /* oops, does not match any of our keywords!? */ |
561 | GNUNET_break (0); | 542 | GNUNET_break (0); |
562 | return; | 543 | return; |
563 | } | 544 | } |
564 | /* decrypt */ | 545 | /* decrypt */ |
565 | GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); | 546 | GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); |
566 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1], | 547 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1], |
567 | size - sizeof (struct KBlock), | 548 | size - sizeof (struct KBlock), |
568 | &skey, | 549 | &skey, &iv, pt)) |
569 | &iv, | 550 | { |
570 | pt)) | 551 | GNUNET_break (0); |
571 | { | 552 | return; |
572 | GNUNET_break (0); | 553 | } |
573 | return; | ||
574 | } | ||
575 | /* parse */ | 554 | /* parse */ |
576 | eos = memchr (pt, 0, sizeof (pt)); | 555 | eos = memchr (pt, 0, sizeof (pt)); |
577 | if (NULL == eos) | 556 | if (NULL == eos) |
578 | { | 557 | { |
579 | GNUNET_break_op (0); | 558 | GNUNET_break_op (0); |
580 | return; | 559 | return; |
581 | } | 560 | } |
582 | j = eos - pt + 1; | 561 | j = eos - pt + 1; |
583 | if (sizeof (pt) == j) | 562 | if (sizeof (pt) == j) |
584 | meta = GNUNET_CONTAINER_meta_data_create (); | 563 | meta = GNUNET_CONTAINER_meta_data_create (); |
585 | else | 564 | else |
586 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], | 565 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j); |
587 | sizeof (pt) - j); | ||
588 | if (meta == NULL) | 566 | if (meta == NULL) |
589 | { | 567 | { |
590 | GNUNET_break_op (0); /* kblock malformed */ | 568 | GNUNET_break_op (0); /* kblock malformed */ |
591 | return; | 569 | return; |
592 | } | 570 | } |
593 | uri = GNUNET_FS_uri_parse (pt, &emsg); | 571 | uri = GNUNET_FS_uri_parse (pt, &emsg); |
594 | if (uri == NULL) | 572 | if (uri == NULL) |
595 | { | 573 | { |
596 | GNUNET_break_op (0); /* kblock malformed */ | 574 | GNUNET_break_op (0); /* kblock malformed */ |
597 | GNUNET_free_non_null (emsg); | 575 | GNUNET_free_non_null (emsg); |
598 | GNUNET_CONTAINER_meta_data_destroy (meta); | 576 | GNUNET_CONTAINER_meta_data_destroy (meta); |
599 | return; | 577 | return; |
600 | } | 578 | } |
601 | /* process */ | 579 | /* process */ |
602 | process_ksk_result (sc, &sc->requests[i], uri, meta); | 580 | process_ksk_result (sc, &sc->requests[i], uri, meta); |
603 | 581 | ||
@@ -616,8 +594,7 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, | |||
616 | */ | 594 | */ |
617 | static void | 595 | static void |
618 | process_nblock (struct GNUNET_FS_SearchContext *sc, | 596 | process_nblock (struct GNUNET_FS_SearchContext *sc, |
619 | const struct NBlock *nb, | 597 | const struct NBlock *nb, size_t size) |
620 | size_t size) | ||
621 | { | 598 | { |
622 | unsigned int i; | 599 | unsigned int i; |
623 | size_t j; | 600 | size_t j; |
@@ -629,70 +606,61 @@ process_nblock (struct GNUNET_FS_SearchContext *sc, | |||
629 | struct GNUNET_CONTAINER_MetaData *meta; | 606 | struct GNUNET_CONTAINER_MetaData *meta; |
630 | struct GNUNET_FS_Uri *uri; | 607 | struct GNUNET_FS_Uri *uri; |
631 | char *uris; | 608 | char *uris; |
632 | 609 | ||
633 | GNUNET_CRYPTO_hash (&nb->keyspace, | 610 | GNUNET_CRYPTO_hash (&nb->keyspace, |
634 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 611 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
635 | &q); | 612 | &q); |
636 | /* find key */ | 613 | /* find key */ |
637 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | 614 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
638 | if (0 == memcmp (&q, | 615 | if (0 == memcmp (&q, &sc->requests[i].query, sizeof (GNUNET_HashCode))) |
639 | &sc->requests[i].query, | ||
640 | sizeof (GNUNET_HashCode))) | ||
641 | break; | 616 | break; |
642 | if (i == sc->uri->data.ksk.keywordCount) | 617 | if (i == sc->uri->data.ksk.keywordCount) |
643 | { | 618 | { |
644 | /* oops, does not match any of our keywords!? */ | 619 | /* oops, does not match any of our keywords!? */ |
645 | GNUNET_break (0); | 620 | GNUNET_break (0); |
646 | return; | 621 | return; |
647 | } | 622 | } |
648 | /* decrypt */ | 623 | /* decrypt */ |
649 | GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); | 624 | GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); |
650 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1], | 625 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1], |
651 | size - sizeof (struct NBlock), | 626 | size - sizeof (struct NBlock), |
652 | &skey, | 627 | &skey, &iv, pt)) |
653 | &iv, | 628 | { |
654 | pt)) | 629 | GNUNET_break (0); |
655 | { | 630 | return; |
656 | GNUNET_break (0); | 631 | } |
657 | return; | ||
658 | } | ||
659 | /* parse */ | 632 | /* parse */ |
660 | eos = memchr (pt, 0, sizeof (pt)); | 633 | eos = memchr (pt, 0, sizeof (pt)); |
661 | if (NULL == eos) | 634 | if (NULL == eos) |
662 | { | 635 | { |
663 | GNUNET_break_op (0); | 636 | GNUNET_break_op (0); |
664 | return; | 637 | return; |
665 | } | 638 | } |
666 | j = eos - pt + 1; | 639 | j = eos - pt + 1; |
667 | if (sizeof (pt) == j) | 640 | if (sizeof (pt) == j) |
668 | meta = GNUNET_CONTAINER_meta_data_create (); | 641 | meta = GNUNET_CONTAINER_meta_data_create (); |
669 | else | 642 | else |
670 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], | 643 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], sizeof (pt) - j); |
671 | sizeof (pt) - j); | ||
672 | if (meta == NULL) | 644 | if (meta == NULL) |
673 | { | 645 | { |
674 | GNUNET_break_op (0); /* nblock malformed */ | 646 | GNUNET_break_op (0); /* nblock malformed */ |
675 | return; | 647 | return; |
676 | } | 648 | } |
677 | 649 | ||
678 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 650 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
679 | uri->type = sks; | 651 | uri->type = sks; |
680 | uri->data.sks.identifier = GNUNET_strdup (pt); | 652 | uri->data.sks.identifier = GNUNET_strdup (pt); |
681 | GNUNET_CRYPTO_hash (&nb->subspace, | 653 | GNUNET_CRYPTO_hash (&nb->subspace, |
682 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 654 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
683 | &uri->data.sks.namespace); | 655 | &uri->data.sks.namespace); |
684 | uris = GNUNET_FS_uri_to_string (uri); | 656 | uris = GNUNET_FS_uri_to_string (uri); |
685 | GNUNET_CONTAINER_meta_data_insert (meta, | 657 | GNUNET_CONTAINER_meta_data_insert (meta, |
686 | "<gnunet>", | 658 | "<gnunet>", |
687 | EXTRACTOR_METATYPE_URI, | 659 | EXTRACTOR_METATYPE_URI, |
688 | EXTRACTOR_METAFORMAT_UTF8, | 660 | EXTRACTOR_METAFORMAT_UTF8, |
689 | "text/plain", | 661 | "text/plain", uris, strlen (uris) + 1); |
690 | uris, | ||
691 | strlen (uris)+1); | ||
692 | GNUNET_free (uris); | 662 | GNUNET_free (uris); |
693 | GNUNET_PSEUDONYM_add (sc->h->cfg, | 663 | GNUNET_PSEUDONYM_add (sc->h->cfg, &uri->data.sks.namespace, meta); |
694 | &uri->data.sks.namespace, | ||
695 | meta); | ||
696 | /* process */ | 664 | /* process */ |
697 | process_ksk_result (sc, &sc->requests[i], uri, meta); | 665 | process_ksk_result (sc, &sc->requests[i], uri, meta); |
698 | 666 | ||
@@ -711,8 +679,7 @@ process_nblock (struct GNUNET_FS_SearchContext *sc, | |||
711 | */ | 679 | */ |
712 | static void | 680 | static void |
713 | process_sblock (struct GNUNET_FS_SearchContext *sc, | 681 | process_sblock (struct GNUNET_FS_SearchContext *sc, |
714 | const struct SBlock *sb, | 682 | const struct SBlock *sb, size_t size) |
715 | size_t size) | ||
716 | { | 683 | { |
717 | size_t len = size - sizeof (struct SBlock); | 684 | size_t len = size - sizeof (struct SBlock); |
718 | char pt[len]; | 685 | char pt[len]; |
@@ -729,48 +696,36 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, | |||
729 | 696 | ||
730 | /* decrypt */ | 697 | /* decrypt */ |
731 | identifier = sc->uri->data.sks.identifier; | 698 | identifier = sc->uri->data.sks.identifier; |
732 | GNUNET_CRYPTO_hash (identifier, | 699 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key); |
733 | strlen (identifier), | ||
734 | &key); | ||
735 | GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); | 700 | GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv); |
736 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], | 701 | if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1], len, &skey, &iv, pt)) |
737 | len, | 702 | { |
738 | &skey, | 703 | GNUNET_break (0); |
739 | &iv, | 704 | return; |
740 | pt)) | 705 | } |
741 | { | ||
742 | GNUNET_break (0); | ||
743 | return; | ||
744 | } | ||
745 | /* parse */ | 706 | /* parse */ |
746 | off = GNUNET_STRINGS_buffer_tokenize (pt, | 707 | off = GNUNET_STRINGS_buffer_tokenize (pt, len, 2, &id, &uris); |
747 | len, | ||
748 | 2, | ||
749 | &id, | ||
750 | &uris); | ||
751 | if (off == 0) | 708 | if (off == 0) |
752 | { | 709 | { |
753 | GNUNET_break_op (0); /* sblock malformed */ | 710 | GNUNET_break_op (0); /* sblock malformed */ |
754 | return; | 711 | return; |
755 | } | 712 | } |
756 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], | 713 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[off], len - off); |
757 | len - off); | ||
758 | if (meta == NULL) | 714 | if (meta == NULL) |
759 | { | 715 | { |
760 | GNUNET_break_op (0); /* sblock malformed */ | 716 | GNUNET_break_op (0); /* sblock malformed */ |
761 | return; | 717 | return; |
762 | } | 718 | } |
763 | uri = GNUNET_FS_uri_parse (uris, &emsg); | 719 | uri = GNUNET_FS_uri_parse (uris, &emsg); |
764 | if (uri == NULL) | 720 | if (uri == NULL) |
765 | { | 721 | { |
766 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 722 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
767 | "Failed to parse URI `%s': %s\n", | 723 | "Failed to parse URI `%s': %s\n", uris, emsg); |
768 | uris, emsg); | 724 | GNUNET_break_op (0); /* sblock malformed */ |
769 | GNUNET_break_op (0); /* sblock malformed */ | 725 | GNUNET_free_non_null (emsg); |
770 | GNUNET_free_non_null (emsg); | 726 | GNUNET_CONTAINER_meta_data_destroy (meta); |
771 | GNUNET_CONTAINER_meta_data_destroy (meta); | 727 | return; |
772 | return; | 728 | } |
773 | } | ||
774 | /* process */ | 729 | /* process */ |
775 | process_sks_result (sc, id, uri, meta); | 730 | process_sks_result (sc, id, uri, meta); |
776 | /* clean up */ | 731 | /* clean up */ |
@@ -790,76 +745,74 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, | |||
790 | */ | 745 | */ |
791 | static void | 746 | static void |
792 | process_result (struct GNUNET_FS_SearchContext *sc, | 747 | process_result (struct GNUNET_FS_SearchContext *sc, |
793 | enum GNUNET_BLOCK_Type type, | 748 | enum GNUNET_BLOCK_Type type, |
794 | struct GNUNET_TIME_Absolute expiration, | 749 | struct GNUNET_TIME_Absolute expiration, |
795 | const void *data, | 750 | const void *data, size_t size) |
796 | size_t size) | ||
797 | { | 751 | { |
798 | if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0) | 752 | if (GNUNET_TIME_absolute_get_duration (expiration).rel_value > 0) |
799 | { | 753 | { |
800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
801 | "Result received has already expired.\n"); | 755 | "Result received has already expired.\n"); |
802 | return; /* result expired */ | 756 | return; /* result expired */ |
803 | } | 757 | } |
804 | switch (type) | 758 | switch (type) |
759 | { | ||
760 | case GNUNET_BLOCK_TYPE_FS_KBLOCK: | ||
761 | if (!GNUNET_FS_uri_test_ksk (sc->uri)) | ||
805 | { | 762 | { |
806 | case GNUNET_BLOCK_TYPE_FS_KBLOCK: | ||
807 | if (! GNUNET_FS_uri_test_ksk (sc->uri)) | ||
808 | { | ||
809 | GNUNET_break (0); | ||
810 | return; | ||
811 | } | ||
812 | if (sizeof (struct KBlock) > size) | ||
813 | { | ||
814 | GNUNET_break_op (0); | ||
815 | return; | ||
816 | } | ||
817 | process_kblock (sc, data, size); | ||
818 | break; | ||
819 | case GNUNET_BLOCK_TYPE_FS_SBLOCK: | ||
820 | if (! GNUNET_FS_uri_test_sks (sc->uri)) | ||
821 | { | ||
822 | GNUNET_break (0); | ||
823 | return; | ||
824 | } | ||
825 | if (sizeof (struct SBlock) > size) | ||
826 | { | ||
827 | GNUNET_break_op (0); | ||
828 | return; | ||
829 | } | ||
830 | process_sblock (sc, data, size); | ||
831 | break; | ||
832 | case GNUNET_BLOCK_TYPE_FS_NBLOCK: | ||
833 | if (! GNUNET_FS_uri_test_ksk (sc->uri)) | ||
834 | { | ||
835 | GNUNET_break (0); | ||
836 | return; | ||
837 | } | ||
838 | if (sizeof (struct NBlock) > size) | ||
839 | { | ||
840 | GNUNET_break_op (0); | ||
841 | return; | ||
842 | } | ||
843 | process_nblock (sc, data, size); | ||
844 | break; | ||
845 | case GNUNET_BLOCK_TYPE_ANY: | ||
846 | GNUNET_break (0); | ||
847 | break; | ||
848 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
849 | GNUNET_break (0); | 763 | GNUNET_break (0); |
850 | break; | 764 | return; |
851 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: | 765 | } |
766 | if (sizeof (struct KBlock) > size) | ||
767 | { | ||
768 | GNUNET_break_op (0); | ||
769 | return; | ||
770 | } | ||
771 | process_kblock (sc, data, size); | ||
772 | break; | ||
773 | case GNUNET_BLOCK_TYPE_FS_SBLOCK: | ||
774 | if (!GNUNET_FS_uri_test_sks (sc->uri)) | ||
775 | { | ||
852 | GNUNET_break (0); | 776 | GNUNET_break (0); |
853 | break; | 777 | return; |
854 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | 778 | } |
779 | if (sizeof (struct SBlock) > size) | ||
780 | { | ||
781 | GNUNET_break_op (0); | ||
782 | return; | ||
783 | } | ||
784 | process_sblock (sc, data, size); | ||
785 | break; | ||
786 | case GNUNET_BLOCK_TYPE_FS_NBLOCK: | ||
787 | if (!GNUNET_FS_uri_test_ksk (sc->uri)) | ||
788 | { | ||
855 | GNUNET_break (0); | 789 | GNUNET_break (0); |
856 | break; | 790 | return; |
857 | default: | ||
858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
859 | _("Got result with unknown block type `%d', ignoring"), | ||
860 | type); | ||
861 | break; | ||
862 | } | 791 | } |
792 | if (sizeof (struct NBlock) > size) | ||
793 | { | ||
794 | GNUNET_break_op (0); | ||
795 | return; | ||
796 | } | ||
797 | process_nblock (sc, data, size); | ||
798 | break; | ||
799 | case GNUNET_BLOCK_TYPE_ANY: | ||
800 | GNUNET_break (0); | ||
801 | break; | ||
802 | case GNUNET_BLOCK_TYPE_FS_DBLOCK: | ||
803 | GNUNET_break (0); | ||
804 | break; | ||
805 | case GNUNET_BLOCK_TYPE_FS_ONDEMAND: | ||
806 | GNUNET_break (0); | ||
807 | break; | ||
808 | case GNUNET_BLOCK_TYPE_FS_IBLOCK: | ||
809 | GNUNET_break (0); | ||
810 | break; | ||
811 | default: | ||
812 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
813 | _("Got result with unknown block type `%d', ignoring"), type); | ||
814 | break; | ||
815 | } | ||
863 | } | 816 | } |
864 | 817 | ||
865 | 818 | ||
@@ -870,8 +823,7 @@ process_result (struct GNUNET_FS_SearchContext *sc, | |||
870 | * | 823 | * |
871 | * @param sc the search to reconnec | 824 | * @param sc the search to reconnec |
872 | */ | 825 | */ |
873 | static void | 826 | static void try_reconnect (struct GNUNET_FS_SearchContext *sc); |
874 | try_reconnect (struct GNUNET_FS_SearchContext *sc); | ||
875 | 827 | ||
876 | 828 | ||
877 | /** | 829 | /** |
@@ -881,36 +833,31 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc); | |||
881 | * @param cls closure | 833 | * @param cls closure |
882 | * @param msg message received, NULL on timeout or fatal error | 834 | * @param msg message received, NULL on timeout or fatal error |
883 | */ | 835 | */ |
884 | static void | 836 | static void |
885 | receive_results (void *cls, | 837 | receive_results (void *cls, const struct GNUNET_MessageHeader *msg) |
886 | const struct GNUNET_MessageHeader * msg) | ||
887 | { | 838 | { |
888 | struct GNUNET_FS_SearchContext *sc = cls; | 839 | struct GNUNET_FS_SearchContext *sc = cls; |
889 | const struct PutMessage *cm; | 840 | const struct PutMessage *cm; |
890 | uint16_t msize; | 841 | uint16_t msize; |
891 | 842 | ||
892 | if ( (NULL == msg) || | 843 | if ((NULL == msg) || |
893 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || | 844 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || |
894 | (ntohs (msg->size) <= sizeof (struct PutMessage)) ) | 845 | (ntohs (msg->size) <= sizeof (struct PutMessage))) |
895 | { | 846 | { |
896 | try_reconnect (sc); | 847 | try_reconnect (sc); |
897 | return; | 848 | return; |
898 | } | 849 | } |
899 | msize = ntohs (msg->size); | 850 | msize = ntohs (msg->size); |
900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
901 | "Receiving %u bytes of result from fs service\n", | 852 | "Receiving %u bytes of result from fs service\n", msize); |
902 | msize); | 853 | cm = (const struct PutMessage *) msg; |
903 | cm = (const struct PutMessage*) msg; | 854 | process_result (sc, |
904 | process_result (sc, | 855 | ntohl (cm->type), |
905 | ntohl (cm->type), | 856 | GNUNET_TIME_absolute_ntoh (cm->expiration), |
906 | GNUNET_TIME_absolute_ntoh (cm->expiration), | 857 | &cm[1], msize - sizeof (struct PutMessage)); |
907 | &cm[1], | ||
908 | msize - sizeof (struct PutMessage)); | ||
909 | /* continue receiving */ | 858 | /* continue receiving */ |
910 | GNUNET_CLIENT_receive (sc->client, | 859 | GNUNET_CLIENT_receive (sc->client, |
911 | &receive_results, | 860 | &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL); |
912 | sc, | ||
913 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
914 | } | 861 | } |
915 | 862 | ||
916 | 863 | ||
@@ -967,22 +914,19 @@ struct MessageBuilderContext | |||
967 | * @return GNUNET_OK to continue iterating | 914 | * @return GNUNET_OK to continue iterating |
968 | */ | 915 | */ |
969 | static int | 916 | static int |
970 | build_result_set (void *cls, | 917 | build_result_set (void *cls, const GNUNET_HashCode * key, void *value) |
971 | const GNUNET_HashCode *key, | ||
972 | void *value) | ||
973 | { | 918 | { |
974 | struct MessageBuilderContext *mbc = cls; | 919 | struct MessageBuilderContext *mbc = cls; |
975 | struct GNUNET_FS_SearchResult *sr = value; | 920 | struct GNUNET_FS_SearchResult *sr = value; |
976 | 921 | ||
977 | if ( (mbc->uri != NULL) && | 922 | if ((mbc->uri != NULL) && |
978 | (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, | 923 | (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri))) |
979 | sr->uri)) ) | ||
980 | return GNUNET_OK; | 924 | return GNUNET_OK; |
981 | if (mbc->skip_cnt > 0) | 925 | if (mbc->skip_cnt > 0) |
982 | { | 926 | { |
983 | mbc->skip_cnt--; | 927 | mbc->skip_cnt--; |
984 | return GNUNET_OK; | 928 | return GNUNET_OK; |
985 | } | 929 | } |
986 | if (mbc->put_cnt == 0) | 930 | if (mbc->put_cnt == 0) |
987 | return GNUNET_SYSERR; | 931 | return GNUNET_SYSERR; |
988 | mbc->sc->search_request_map_offset++; | 932 | mbc->sc->search_request_map_offset++; |
@@ -1002,16 +946,13 @@ build_result_set (void *cls, | |||
1002 | * @return GNUNET_OK to continue iterating | 946 | * @return GNUNET_OK to continue iterating |
1003 | */ | 947 | */ |
1004 | static int | 948 | static int |
1005 | find_result_set (void *cls, | 949 | find_result_set (void *cls, const GNUNET_HashCode * key, void *value) |
1006 | const GNUNET_HashCode *key, | ||
1007 | void *value) | ||
1008 | { | 950 | { |
1009 | struct MessageBuilderContext *mbc = cls; | 951 | struct MessageBuilderContext *mbc = cls; |
1010 | struct GNUNET_FS_SearchResult *sr = value; | 952 | struct GNUNET_FS_SearchResult *sr = value; |
1011 | 953 | ||
1012 | if ( (mbc->uri != NULL) && | 954 | if ((mbc->uri != NULL) && |
1013 | (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, | 955 | (GNUNET_YES != GNUNET_FS_uri_test_equal (mbc->uri, sr->uri))) |
1014 | sr->uri)) ) | ||
1015 | return GNUNET_OK; | 956 | return GNUNET_OK; |
1016 | mbc->put_cnt++; | 957 | mbc->put_cnt++; |
1017 | return GNUNET_OK; | 958 | return GNUNET_OK; |
@@ -1028,9 +969,7 @@ find_result_set (void *cls, | |||
1028 | * @return number of bytes written to buf | 969 | * @return number of bytes written to buf |
1029 | */ | 970 | */ |
1030 | static size_t | 971 | static size_t |
1031 | transmit_search_request (void *cls, | 972 | transmit_search_request (void *cls, size_t size, void *buf) |
1032 | size_t size, | ||
1033 | void *buf) | ||
1034 | { | 973 | { |
1035 | struct GNUNET_FS_SearchContext *sc = cls; | 974 | struct GNUNET_FS_SearchContext *sc = cls; |
1036 | struct MessageBuilderContext mbc; | 975 | struct MessageBuilderContext mbc; |
@@ -1042,105 +981,91 @@ transmit_search_request (void *cls, | |||
1042 | unsigned int sqms; | 981 | unsigned int sqms; |
1043 | 982 | ||
1044 | if (NULL == buf) | 983 | if (NULL == buf) |
1045 | { | 984 | { |
1046 | try_reconnect (sc); | 985 | try_reconnect (sc); |
1047 | return 0; | 986 | return 0; |
1048 | } | 987 | } |
1049 | mbc.sc = sc; | 988 | mbc.sc = sc; |
1050 | mbc.skip_cnt = sc->search_request_map_offset; | 989 | mbc.skip_cnt = sc->search_request_map_offset; |
1051 | sm = buf; | 990 | sm = buf; |
1052 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 991 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
1053 | mbc.xoff = (GNUNET_HashCode* ) &sm[1]; | 992 | mbc.xoff = (GNUNET_HashCode *) & sm[1]; |
1054 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 993 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
994 | { | ||
995 | msize = sizeof (struct SearchMessage); | ||
996 | GNUNET_assert (size >= msize); | ||
997 | mbc.uri = NULL; | ||
998 | mbc.put_cnt = 0; | ||
999 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1000 | &find_result_set, &mbc); | ||
1001 | sqms = mbc.put_cnt; | ||
1002 | mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode); | ||
1003 | mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt); | ||
1004 | if (sc->search_request_map_offset < sqms) | ||
1005 | GNUNET_assert (mbc.put_cnt > 0); | ||
1006 | |||
1007 | sm->header.size = htons (msize); | ||
1008 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1009 | sm->options = htonl (1); | ||
1010 | else | ||
1011 | sm->options = htonl (0); | ||
1012 | sm->type = htonl (GNUNET_BLOCK_TYPE_ANY); | ||
1013 | sm->anonymity_level = htonl (sc->anonymity); | ||
1014 | memset (&sm->target, 0, sizeof (GNUNET_HashCode)); | ||
1015 | sm->query = sc->requests[sc->keyword_offset].query; | ||
1016 | msize += sizeof (GNUNET_HashCode) * mbc.put_cnt; | ||
1017 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1018 | &build_result_set, &mbc); | ||
1019 | sm->header.size = htons (msize); | ||
1020 | if (sqms != sc->search_request_map_offset) | ||
1021 | { | ||
1022 | /* more requesting to be done... */ | ||
1023 | schedule_transmit_search_request (sc); | ||
1024 | return msize; | ||
1025 | } | ||
1026 | sc->keyword_offset++; | ||
1027 | if (sc->uri->data.ksk.keywordCount != sc->keyword_offset) | ||
1055 | { | 1028 | { |
1056 | msize = sizeof (struct SearchMessage); | 1029 | /* more requesting to be done... */ |
1057 | GNUNET_assert (size >= msize); | 1030 | schedule_transmit_search_request (sc); |
1058 | mbc.uri = NULL; | 1031 | return msize; |
1059 | mbc.put_cnt = 0; | ||
1060 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1061 | &find_result_set, | ||
1062 | &mbc); | ||
1063 | sqms = mbc.put_cnt; | ||
1064 | mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode); | ||
1065 | mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, | ||
1066 | sqms - mbc.skip_cnt); | ||
1067 | if (sc->search_request_map_offset < sqms) | ||
1068 | GNUNET_assert (mbc.put_cnt > 0); | ||
1069 | |||
1070 | sm->header.size = htons (msize); | ||
1071 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1072 | sm->options = htonl (1); | ||
1073 | else | ||
1074 | sm->options = htonl (0); | ||
1075 | sm->type = htonl (GNUNET_BLOCK_TYPE_ANY); | ||
1076 | sm->anonymity_level = htonl (sc->anonymity); | ||
1077 | memset (&sm->target, 0, sizeof (GNUNET_HashCode)); | ||
1078 | sm->query = sc->requests[sc->keyword_offset].query; | ||
1079 | msize += sizeof (GNUNET_HashCode) * mbc.put_cnt; | ||
1080 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1081 | &build_result_set, | ||
1082 | &mbc); | ||
1083 | sm->header.size = htons (msize); | ||
1084 | if (sqms != sc->search_request_map_offset) | ||
1085 | { | ||
1086 | /* more requesting to be done... */ | ||
1087 | schedule_transmit_search_request (sc); | ||
1088 | return msize; | ||
1089 | } | ||
1090 | sc->keyword_offset++; | ||
1091 | if (sc->uri->data.ksk.keywordCount != | ||
1092 | sc->keyword_offset) | ||
1093 | { | ||
1094 | /* more requesting to be done... */ | ||
1095 | schedule_transmit_search_request (sc); | ||
1096 | return msize; | ||
1097 | } | ||
1098 | } | 1032 | } |
1033 | } | ||
1099 | else | 1034 | else |
1035 | { | ||
1036 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); | ||
1037 | msize = sizeof (struct SearchMessage); | ||
1038 | GNUNET_assert (size >= msize); | ||
1039 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1040 | sm->options = htonl (1); | ||
1041 | else | ||
1042 | sm->options = htonl (0); | ||
1043 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK); | ||
1044 | sm->anonymity_level = htonl (sc->anonymity); | ||
1045 | sm->target = sc->uri->data.sks.namespace; | ||
1046 | identifier = sc->uri->data.sks.identifier; | ||
1047 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &key); | ||
1048 | GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &idh); | ||
1049 | GNUNET_CRYPTO_hash_xor (&idh, &sm->target, &sm->query); | ||
1050 | mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode); | ||
1051 | sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); | ||
1052 | mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, sqms - mbc.skip_cnt); | ||
1053 | mbc.uri = NULL; | ||
1054 | if (sc->search_request_map_offset < sqms) | ||
1055 | GNUNET_assert (mbc.put_cnt > 0); | ||
1056 | msize += sizeof (GNUNET_HashCode) * mbc.put_cnt; | ||
1057 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1058 | &build_result_set, &mbc); | ||
1059 | sm->header.size = htons (msize); | ||
1060 | if (sqms != sc->search_request_map_offset) | ||
1100 | { | 1061 | { |
1101 | GNUNET_assert (GNUNET_FS_uri_test_sks (sc->uri)); | 1062 | /* more requesting to be done... */ |
1102 | msize = sizeof (struct SearchMessage); | 1063 | schedule_transmit_search_request (sc); |
1103 | GNUNET_assert (size >= msize); | 1064 | return msize; |
1104 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
1105 | sm->options = htonl (1); | ||
1106 | else | ||
1107 | sm->options = htonl (0); | ||
1108 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_SBLOCK); | ||
1109 | sm->anonymity_level = htonl (sc->anonymity); | ||
1110 | sm->target = sc->uri->data.sks.namespace; | ||
1111 | identifier = sc->uri->data.sks.identifier; | ||
1112 | GNUNET_CRYPTO_hash (identifier, | ||
1113 | strlen (identifier), | ||
1114 | &key); | ||
1115 | GNUNET_CRYPTO_hash (&key, | ||
1116 | sizeof (GNUNET_HashCode), | ||
1117 | &idh); | ||
1118 | GNUNET_CRYPTO_hash_xor (&idh, | ||
1119 | &sm->target, | ||
1120 | &sm->query); | ||
1121 | mbc.put_cnt = (size - msize) / sizeof (GNUNET_HashCode); | ||
1122 | sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map); | ||
1123 | mbc.put_cnt = GNUNET_MIN (mbc.put_cnt, | ||
1124 | sqms - mbc.skip_cnt); | ||
1125 | mbc.uri = NULL; | ||
1126 | if (sc->search_request_map_offset < sqms) | ||
1127 | GNUNET_assert (mbc.put_cnt > 0); | ||
1128 | msize += sizeof (GNUNET_HashCode) * mbc.put_cnt; | ||
1129 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | ||
1130 | &build_result_set, | ||
1131 | &mbc); | ||
1132 | sm->header.size = htons (msize); | ||
1133 | if (sqms != sc->search_request_map_offset) | ||
1134 | { | ||
1135 | /* more requesting to be done... */ | ||
1136 | schedule_transmit_search_request (sc); | ||
1137 | return msize; | ||
1138 | } | ||
1139 | } | 1065 | } |
1066 | } | ||
1140 | GNUNET_CLIENT_receive (sc->client, | 1067 | GNUNET_CLIENT_receive (sc->client, |
1141 | &receive_results, | 1068 | &receive_results, sc, GNUNET_TIME_UNIT_FOREVER_REL); |
1142 | sc, | ||
1143 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1144 | return msize; | 1069 | return msize; |
1145 | } | 1070 | } |
1146 | 1071 | ||
@@ -1159,16 +1084,16 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1159 | unsigned int fit; | 1084 | unsigned int fit; |
1160 | 1085 | ||
1161 | size = sizeof (struct SearchMessage); | 1086 | size = sizeof (struct SearchMessage); |
1162 | sqms = GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) - sc->search_request_map_offset; | 1087 | sqms = |
1088 | GNUNET_CONTAINER_multihashmap_size (sc->master_result_map) - | ||
1089 | sc->search_request_map_offset; | ||
1163 | fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode); | 1090 | fit = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - size) / sizeof (GNUNET_HashCode); |
1164 | fit = GNUNET_MIN (fit, sqms); | 1091 | fit = GNUNET_MIN (fit, sqms); |
1165 | size += sizeof (GNUNET_HashCode) * fit; | 1092 | size += sizeof (GNUNET_HashCode) * fit; |
1166 | GNUNET_CLIENT_notify_transmit_ready (sc->client, | 1093 | GNUNET_CLIENT_notify_transmit_ready (sc->client, |
1167 | size, | 1094 | size, |
1168 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 1095 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
1169 | GNUNET_NO, | 1096 | GNUNET_NO, &transmit_search_request, sc); |
1170 | &transmit_search_request, | ||
1171 | sc); | ||
1172 | 1097 | ||
1173 | } | 1098 | } |
1174 | 1099 | ||
@@ -1181,20 +1106,18 @@ schedule_transmit_search_request (struct GNUNET_FS_SearchContext *sc) | |||
1181 | * @param tc unused | 1106 | * @param tc unused |
1182 | */ | 1107 | */ |
1183 | static void | 1108 | static void |
1184 | do_reconnect (void *cls, | 1109 | do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1185 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1186 | { | 1110 | { |
1187 | struct GNUNET_FS_SearchContext *sc = cls; | 1111 | struct GNUNET_FS_SearchContext *sc = cls; |
1188 | struct GNUNET_CLIENT_Connection *client; | 1112 | struct GNUNET_CLIENT_Connection *client; |
1189 | 1113 | ||
1190 | sc->task = GNUNET_SCHEDULER_NO_TASK; | 1114 | sc->task = GNUNET_SCHEDULER_NO_TASK; |
1191 | client = GNUNET_CLIENT_connect ("fs", | 1115 | client = GNUNET_CLIENT_connect ("fs", sc->h->cfg); |
1192 | sc->h->cfg); | ||
1193 | if (NULL == client) | 1116 | if (NULL == client) |
1194 | { | 1117 | { |
1195 | try_reconnect (sc); | 1118 | try_reconnect (sc); |
1196 | return; | 1119 | return; |
1197 | } | 1120 | } |
1198 | sc->client = client; | 1121 | sc->client = client; |
1199 | sc->search_request_map_offset = 0; | 1122 | sc->search_request_map_offset = 0; |
1200 | sc->keyword_offset = 0; | 1123 | sc->keyword_offset = 0; |
@@ -1209,18 +1132,17 @@ do_reconnect (void *cls, | |||
1209 | * | 1132 | * |
1210 | * @param sc the search to reconnec | 1133 | * @param sc the search to reconnec |
1211 | */ | 1134 | */ |
1212 | static void | 1135 | static void |
1213 | try_reconnect (struct GNUNET_FS_SearchContext *sc) | 1136 | try_reconnect (struct GNUNET_FS_SearchContext *sc) |
1214 | { | 1137 | { |
1215 | if (NULL != sc->client) | 1138 | if (NULL != sc->client) |
1216 | { | 1139 | { |
1217 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); | 1140 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); |
1218 | sc->client = NULL; | 1141 | sc->client = NULL; |
1219 | } | 1142 | } |
1220 | sc->task | 1143 | sc->task |
1221 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 1144 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
1222 | &do_reconnect, | 1145 | &do_reconnect, sc); |
1223 | sc); | ||
1224 | } | 1146 | } |
1225 | 1147 | ||
1226 | 1148 | ||
@@ -1238,36 +1160,34 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc) | |||
1238 | */ | 1160 | */ |
1239 | static struct GNUNET_FS_SearchContext * | 1161 | static struct GNUNET_FS_SearchContext * |
1240 | search_start (struct GNUNET_FS_Handle *h, | 1162 | search_start (struct GNUNET_FS_Handle *h, |
1241 | const struct GNUNET_FS_Uri *uri, | 1163 | const struct GNUNET_FS_Uri *uri, |
1242 | uint32_t anonymity, | 1164 | uint32_t anonymity, |
1243 | enum GNUNET_FS_SearchOptions options, | 1165 | enum GNUNET_FS_SearchOptions options, |
1244 | void *cctx, | 1166 | void *cctx, struct GNUNET_FS_SearchResult *psearch) |
1245 | struct GNUNET_FS_SearchResult *psearch) | ||
1246 | { | 1167 | { |
1247 | struct GNUNET_FS_SearchContext *sc; | 1168 | struct GNUNET_FS_SearchContext *sc; |
1248 | struct GNUNET_FS_ProgressInfo pi; | 1169 | struct GNUNET_FS_ProgressInfo pi; |
1249 | 1170 | ||
1250 | sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext)); | 1171 | sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext)); |
1251 | sc->h = h; | 1172 | sc->h = h; |
1252 | sc->options = options; | 1173 | sc->options = options; |
1253 | sc->uri = GNUNET_FS_uri_dup (uri); | 1174 | sc->uri = GNUNET_FS_uri_dup (uri); |
1254 | sc->anonymity = anonymity; | 1175 | sc->anonymity = anonymity; |
1255 | sc->start_time = GNUNET_TIME_absolute_get (); | 1176 | sc->start_time = GNUNET_TIME_absolute_get (); |
1256 | if (psearch != NULL) | 1177 | if (psearch != NULL) |
1257 | { | 1178 | { |
1258 | sc->psearch_result = psearch; | 1179 | sc->psearch_result = psearch; |
1259 | psearch->update_search = sc; | 1180 | psearch->update_search = sc; |
1260 | } | 1181 | } |
1261 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); | 1182 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16); |
1262 | sc->client_info = cctx; | 1183 | sc->client_info = cctx; |
1263 | if (GNUNET_OK != | 1184 | if (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)) |
1264 | GNUNET_FS_search_start_searching_ (sc)) | 1185 | { |
1265 | { | 1186 | GNUNET_FS_uri_destroy (sc->uri); |
1266 | GNUNET_FS_uri_destroy (sc->uri); | 1187 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1267 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1188 | GNUNET_free (sc); |
1268 | GNUNET_free (sc); | 1189 | return NULL; |
1269 | return NULL; | 1190 | } |
1270 | } | ||
1271 | GNUNET_FS_search_sync_ (sc); | 1191 | GNUNET_FS_search_sync_ (sc); |
1272 | pi.status = GNUNET_FS_STATUS_SEARCH_START; | 1192 | pi.status = GNUNET_FS_STATUS_SEARCH_START; |
1273 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 1193 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
@@ -1288,39 +1208,35 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | |||
1288 | unsigned int i; | 1208 | unsigned int i; |
1289 | const char *keyword; | 1209 | const char *keyword; |
1290 | GNUNET_HashCode hc; | 1210 | GNUNET_HashCode hc; |
1291 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 1211 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
1292 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; | 1212 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; |
1293 | 1213 | ||
1294 | GNUNET_assert (NULL == sc->client); | 1214 | GNUNET_assert (NULL == sc->client); |
1295 | if (GNUNET_FS_uri_test_ksk (sc->uri)) | 1215 | if (GNUNET_FS_uri_test_ksk (sc->uri)) |
1216 | { | ||
1217 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); | ||
1218 | sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) * | ||
1219 | sc->uri->data.ksk.keywordCount); | ||
1220 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) | ||
1296 | { | 1221 | { |
1297 | GNUNET_assert (0 != sc->uri->data.ksk.keywordCount); | 1222 | keyword = &sc->uri->data.ksk.keywords[i][1]; |
1298 | sc->requests = GNUNET_malloc (sizeof (struct SearchRequestEntry) * | 1223 | GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc); |
1299 | sc->uri->data.ksk.keywordCount); | 1224 | pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); |
1300 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | 1225 | GNUNET_assert (pk != NULL); |
1301 | { | 1226 | GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); |
1302 | keyword = &sc->uri->data.ksk.keywords[i][1]; | 1227 | GNUNET_CRYPTO_rsa_key_free (pk); |
1303 | GNUNET_CRYPTO_hash (keyword, | 1228 | GNUNET_CRYPTO_hash (&pub, |
1304 | strlen (keyword), | 1229 | sizeof (struct |
1305 | &hc); | 1230 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1306 | pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); | 1231 | &sc->requests[i].query); |
1307 | GNUNET_assert (pk != NULL); | 1232 | sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); |
1308 | GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); | 1233 | if (sc->requests[i].mandatory) |
1309 | GNUNET_CRYPTO_rsa_key_free (pk); | 1234 | sc->mandatory_count++; |
1310 | GNUNET_CRYPTO_hash (&pub, | 1235 | sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4); |
1311 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1236 | GNUNET_CRYPTO_hash (keyword, strlen (keyword), &sc->requests[i].key); |
1312 | &sc->requests[i].query); | ||
1313 | sc->requests[i].mandatory = (sc->uri->data.ksk.keywords[i][0] == '+'); | ||
1314 | if (sc->requests[i].mandatory) | ||
1315 | sc->mandatory_count++; | ||
1316 | sc->requests[i].results = GNUNET_CONTAINER_multihashmap_create (4); | ||
1317 | GNUNET_CRYPTO_hash (keyword, | ||
1318 | strlen (keyword), | ||
1319 | &sc->requests[i].key); | ||
1320 | } | ||
1321 | } | 1237 | } |
1322 | sc->client = GNUNET_CLIENT_connect ("fs", | 1238 | } |
1323 | sc->h->cfg); | 1239 | sc->client = GNUNET_CLIENT_connect ("fs", sc->h->cfg); |
1324 | if (NULL == sc->client) | 1240 | if (NULL == sc->client) |
1325 | return GNUNET_SYSERR; | 1241 | return GNUNET_SYSERR; |
1326 | schedule_transmit_search_request (sc); | 1242 | schedule_transmit_search_request (sc); |
@@ -1338,21 +1254,20 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) | |||
1338 | */ | 1254 | */ |
1339 | static int | 1255 | static int |
1340 | search_result_freeze_probes (void *cls, | 1256 | search_result_freeze_probes (void *cls, |
1341 | const GNUNET_HashCode * key, | 1257 | const GNUNET_HashCode * key, void *value) |
1342 | void *value) | ||
1343 | { | 1258 | { |
1344 | struct GNUNET_FS_SearchResult *sr = value; | 1259 | struct GNUNET_FS_SearchResult *sr = value; |
1345 | 1260 | ||
1346 | if (sr->probe_ctx != NULL) | 1261 | if (sr->probe_ctx != NULL) |
1347 | { | 1262 | { |
1348 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 1263 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
1349 | sr->probe_ctx = NULL; | 1264 | sr->probe_ctx = NULL; |
1350 | } | 1265 | } |
1351 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | 1266 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) |
1352 | { | 1267 | { |
1353 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 1268 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
1354 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; | 1269 | sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK; |
1355 | } | 1270 | } |
1356 | if (sr->update_search != NULL) | 1271 | if (sr->update_search != NULL) |
1357 | GNUNET_FS_search_pause (sr->update_search); | 1272 | GNUNET_FS_search_pause (sr->update_search); |
1358 | return GNUNET_OK; | 1273 | return GNUNET_OK; |
@@ -1369,8 +1284,7 @@ search_result_freeze_probes (void *cls, | |||
1369 | */ | 1284 | */ |
1370 | static int | 1285 | static int |
1371 | search_result_resume_probes (void *cls, | 1286 | search_result_resume_probes (void *cls, |
1372 | const GNUNET_HashCode * key, | 1287 | const GNUNET_HashCode * key, void *value) |
1373 | void *value) | ||
1374 | { | 1288 | { |
1375 | struct GNUNET_FS_SearchResult *sr = value; | 1289 | struct GNUNET_FS_SearchResult *sr = value; |
1376 | 1290 | ||
@@ -1390,9 +1304,7 @@ search_result_resume_probes (void *cls, | |||
1390 | * @return GNUNET_OK | 1304 | * @return GNUNET_OK |
1391 | */ | 1305 | */ |
1392 | static int | 1306 | static int |
1393 | search_result_suspend (void *cls, | 1307 | search_result_suspend (void *cls, const GNUNET_HashCode * key, void *value) |
1394 | const GNUNET_HashCode * key, | ||
1395 | void *value) | ||
1396 | { | 1308 | { |
1397 | struct GNUNET_FS_SearchContext *sc = cls; | 1309 | struct GNUNET_FS_SearchContext *sc = cls; |
1398 | struct GNUNET_FS_SearchResult *sr = value; | 1310 | struct GNUNET_FS_SearchResult *sr = value; |
@@ -1412,7 +1324,7 @@ search_result_suspend (void *cls, | |||
1412 | GNUNET_FS_uri_destroy (sr->uri); | 1324 | GNUNET_FS_uri_destroy (sr->uri); |
1413 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 1325 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
1414 | if (sr->probe_ctx != NULL) | 1326 | if (sr->probe_ctx != NULL) |
1415 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 1327 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
1416 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | 1328 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) |
1417 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 1329 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
1418 | GNUNET_free (sr); | 1330 | GNUNET_free (sr); |
@@ -1435,8 +1347,7 @@ GNUNET_FS_search_signal_suspend_ (void *cls) | |||
1435 | 1347 | ||
1436 | GNUNET_FS_end_top (sc->h, sc->top); | 1348 | GNUNET_FS_end_top (sc->h, sc->top); |
1437 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1349 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1438 | &search_result_suspend, | 1350 | &search_result_suspend, sc); |
1439 | sc); | ||
1440 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; | 1351 | pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND; |
1441 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 1352 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
1442 | GNUNET_break (NULL == sc->client_info); | 1353 | GNUNET_break (NULL == sc->client_info); |
@@ -1446,11 +1357,11 @@ GNUNET_FS_search_signal_suspend_ (void *cls) | |||
1446 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); | 1357 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); |
1447 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1358 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1448 | if (sc->requests != NULL) | 1359 | if (sc->requests != NULL) |
1449 | { | 1360 | { |
1450 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); | 1361 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); |
1451 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | 1362 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1452 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); | 1363 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); |
1453 | } | 1364 | } |
1454 | GNUNET_free_non_null (sc->requests); | 1365 | GNUNET_free_non_null (sc->requests); |
1455 | GNUNET_free_non_null (sc->emsg); | 1366 | GNUNET_free_non_null (sc->emsg); |
1456 | GNUNET_FS_uri_destroy (sc->uri); | 1367 | GNUNET_FS_uri_destroy (sc->uri); |
@@ -1472,12 +1383,12 @@ GNUNET_FS_search_signal_suspend_ (void *cls) | |||
1472 | */ | 1383 | */ |
1473 | struct GNUNET_FS_SearchContext * | 1384 | struct GNUNET_FS_SearchContext * |
1474 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | 1385 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, |
1475 | const struct GNUNET_FS_Uri *uri, | 1386 | const struct GNUNET_FS_Uri *uri, |
1476 | uint32_t anonymity, | 1387 | uint32_t anonymity, |
1477 | enum GNUNET_FS_SearchOptions options, | 1388 | enum GNUNET_FS_SearchOptions options, void *cctx) |
1478 | void *cctx) | ||
1479 | { | 1389 | { |
1480 | struct GNUNET_FS_SearchContext *ret; | 1390 | struct GNUNET_FS_SearchContext *ret; |
1391 | |||
1481 | ret = search_start (h, uri, anonymity, options, cctx, NULL); | 1392 | ret = search_start (h, uri, anonymity, options, cctx, NULL); |
1482 | if (ret == NULL) | 1393 | if (ret == NULL) |
1483 | return NULL; | 1394 | return NULL; |
@@ -1491,7 +1402,7 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | |||
1491 | * | 1402 | * |
1492 | * @param sc context for the search that should be paused | 1403 | * @param sc context for the search that should be paused |
1493 | */ | 1404 | */ |
1494 | void | 1405 | void |
1495 | GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) | 1406 | GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) |
1496 | { | 1407 | { |
1497 | struct GNUNET_FS_ProgressInfo pi; | 1408 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1504,8 +1415,7 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) | |||
1504 | sc->client = NULL; | 1415 | sc->client = NULL; |
1505 | GNUNET_FS_search_sync_ (sc); | 1416 | GNUNET_FS_search_sync_ (sc); |
1506 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1417 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1507 | &search_result_freeze_probes, | 1418 | &search_result_freeze_probes, sc); |
1508 | sc); | ||
1509 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; | 1419 | pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; |
1510 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 1420 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
1511 | } | 1421 | } |
@@ -1516,7 +1426,7 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) | |||
1516 | * | 1426 | * |
1517 | * @param sc context for the search that should be resumed | 1427 | * @param sc context for the search that should be resumed |
1518 | */ | 1428 | */ |
1519 | void | 1429 | void |
1520 | GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) | 1430 | GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) |
1521 | { | 1431 | { |
1522 | struct GNUNET_FS_ProgressInfo pi; | 1432 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1528,8 +1438,7 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) | |||
1528 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; | 1438 | pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; |
1529 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 1439 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
1530 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1440 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1531 | &search_result_resume_probes, | 1441 | &search_result_resume_probes, sc); |
1532 | sc); | ||
1533 | } | 1442 | } |
1534 | 1443 | ||
1535 | 1444 | ||
@@ -1542,39 +1451,36 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) | |||
1542 | * @return GNUNET_OK | 1451 | * @return GNUNET_OK |
1543 | */ | 1452 | */ |
1544 | static int | 1453 | static int |
1545 | search_result_free (void *cls, | 1454 | search_result_free (void *cls, const GNUNET_HashCode * key, void *value) |
1546 | const GNUNET_HashCode * key, | ||
1547 | void *value) | ||
1548 | { | 1455 | { |
1549 | struct GNUNET_FS_SearchContext *sc = cls; | 1456 | struct GNUNET_FS_SearchContext *sc = cls; |
1550 | struct GNUNET_FS_SearchResult *sr = value; | 1457 | struct GNUNET_FS_SearchResult *sr = value; |
1551 | struct GNUNET_FS_ProgressInfo pi; | 1458 | struct GNUNET_FS_ProgressInfo pi; |
1552 | 1459 | ||
1553 | if (NULL != sr->download) | 1460 | if (NULL != sr->download) |
1461 | { | ||
1462 | sr->download->search = NULL; | ||
1463 | sr->download->top = GNUNET_FS_make_top (sr->download->h, | ||
1464 | &GNUNET_FS_download_signal_suspend_, | ||
1465 | sr->download); | ||
1466 | if (NULL != sr->download->serialization) | ||
1554 | { | 1467 | { |
1555 | sr->download->search = NULL; | 1468 | GNUNET_FS_remove_sync_file_ (sc->h, |
1556 | sr->download->top = GNUNET_FS_make_top (sr->download->h, | 1469 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, |
1557 | &GNUNET_FS_download_signal_suspend_, | 1470 | sr->download->serialization); |
1558 | sr->download); | 1471 | GNUNET_free (sr->download->serialization); |
1559 | if (NULL != sr->download->serialization) | 1472 | sr->download->serialization = NULL; |
1560 | { | ||
1561 | GNUNET_FS_remove_sync_file_ (sc->h, | ||
1562 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, | ||
1563 | sr->download->serialization); | ||
1564 | GNUNET_free (sr->download->serialization); | ||
1565 | sr->download->serialization = NULL; | ||
1566 | } | ||
1567 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1568 | GNUNET_FS_download_make_status_ (&pi, | ||
1569 | sr->download); | ||
1570 | GNUNET_FS_download_sync_ (sr->download); | ||
1571 | sr->download = NULL; | ||
1572 | } | 1473 | } |
1474 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; | ||
1475 | GNUNET_FS_download_make_status_ (&pi, sr->download); | ||
1476 | GNUNET_FS_download_sync_ (sr->download); | ||
1477 | sr->download = NULL; | ||
1478 | } | ||
1573 | if (NULL != sr->update_search) | 1479 | if (NULL != sr->update_search) |
1574 | { | 1480 | { |
1575 | GNUNET_FS_search_stop (sr->update_search); | 1481 | GNUNET_FS_search_stop (sr->update_search); |
1576 | GNUNET_assert (sr->update_search == NULL); | 1482 | GNUNET_assert (sr->update_search == NULL); |
1577 | } | 1483 | } |
1578 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; | 1484 | pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; |
1579 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; | 1485 | pi.value.search.specifics.result_stopped.cctx = sr->client_info; |
1580 | pi.value.search.specifics.result_stopped.meta = sr->meta; | 1486 | pi.value.search.specifics.result_stopped.meta = sr->meta; |
@@ -1585,7 +1491,7 @@ search_result_free (void *cls, | |||
1585 | GNUNET_FS_uri_destroy (sr->uri); | 1491 | GNUNET_FS_uri_destroy (sr->uri); |
1586 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); | 1492 | GNUNET_CONTAINER_meta_data_destroy (sr->meta); |
1587 | if (sr->probe_ctx != NULL) | 1493 | if (sr->probe_ctx != NULL) |
1588 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); | 1494 | GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES); |
1589 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) | 1495 | if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK) |
1590 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); | 1496 | GNUNET_SCHEDULER_cancel (sr->probe_cancel_task); |
1591 | GNUNET_free (sr); | 1497 | GNUNET_free (sr); |
@@ -1598,7 +1504,7 @@ search_result_free (void *cls, | |||
1598 | * | 1504 | * |
1599 | * @param sc context for the search that should be stopped | 1505 | * @param sc context for the search that should be stopped |
1600 | */ | 1506 | */ |
1601 | void | 1507 | void |
1602 | GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) | 1508 | GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) |
1603 | { | 1509 | { |
1604 | struct GNUNET_FS_ProgressInfo pi; | 1510 | struct GNUNET_FS_ProgressInfo pi; |
@@ -1609,22 +1515,21 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) | |||
1609 | if (sc->psearch_result != NULL) | 1515 | if (sc->psearch_result != NULL) |
1610 | sc->psearch_result->update_search = NULL; | 1516 | sc->psearch_result->update_search = NULL; |
1611 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 1517 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
1612 | &search_result_free, | 1518 | &search_result_free, sc); |
1613 | sc); | ||
1614 | if (sc->serialization != NULL) | 1519 | if (sc->serialization != NULL) |
1615 | { | 1520 | { |
1616 | GNUNET_FS_remove_sync_file_ (sc->h, | 1521 | GNUNET_FS_remove_sync_file_ (sc->h, |
1617 | (sc->psearch_result != NULL) | 1522 | (sc->psearch_result != NULL) |
1618 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | 1523 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1619 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1524 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1620 | sc->serialization); | 1525 | sc->serialization); |
1621 | GNUNET_FS_remove_sync_dir_ (sc->h, | 1526 | GNUNET_FS_remove_sync_dir_ (sc->h, |
1622 | (sc->psearch_result != NULL) | 1527 | (sc->psearch_result != NULL) |
1623 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH | 1528 | ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH |
1624 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 1529 | : GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
1625 | sc->serialization); | 1530 | sc->serialization); |
1626 | GNUNET_free (sc->serialization); | 1531 | GNUNET_free (sc->serialization); |
1627 | } | 1532 | } |
1628 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; | 1533 | pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; |
1629 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); | 1534 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); |
1630 | GNUNET_break (NULL == sc->client_info); | 1535 | GNUNET_break (NULL == sc->client_info); |
@@ -1634,11 +1539,11 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) | |||
1634 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); | 1539 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); |
1635 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 1540 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
1636 | if (sc->requests != NULL) | 1541 | if (sc->requests != NULL) |
1637 | { | 1542 | { |
1638 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); | 1543 | GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri)); |
1639 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | 1544 | for (i = 0; i < sc->uri->data.ksk.keywordCount; i++) |
1640 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); | 1545 | GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results); |
1641 | } | 1546 | } |
1642 | GNUNET_free_non_null (sc->requests); | 1547 | GNUNET_free_non_null (sc->requests); |
1643 | GNUNET_free_non_null (sc->emsg); | 1548 | GNUNET_free_non_null (sc->emsg); |
1644 | GNUNET_FS_uri_destroy (sc->uri); | 1549 | GNUNET_FS_uri_destroy (sc->uri); |