aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_search.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-04 11:14:25 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-04 11:14:25 +0000
commit6276a671135e01b119f198d0ae3092bfeb14903e (patch)
treebe184253d3c14e2b9ea6b2f4dd335b4c935d68b1 /src/fs/fs_search.c
parent6aefa4ac85435c8e7afb86e4e6daef77da69709a (diff)
downloadgnunet-6276a671135e01b119f198d0ae3092bfeb14903e.tar.gz
gnunet-6276a671135e01b119f198d0ae3092bfeb14903e.zip
calling sync, cleaning up files
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r--src/fs/fs_search.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 36aa26193..8db9f115d 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -24,7 +24,6 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO: 26 * TODO:
27 * - insert code for serialization where needed
28 * - remove *directory* with search results upon completion 27 * - remove *directory* with search results upon completion
29 * - centralize code that sprintf's the 'pbuf[32]' strings 28 * - centralize code that sprintf's the 'pbuf[32]' strings
30 * - add support for pushing "already seen" information 29 * - add support for pushing "already seen" information
@@ -52,7 +51,8 @@
52void * 51void *
53GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi, 52GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
54 struct GNUNET_FS_SearchContext *sc) 53 struct GNUNET_FS_SearchContext *sc)
55{ 54{
55 void *ret;
56 pi->value.search.sc = sc; 56 pi->value.search.sc = sc;
57 pi->value.search.cctx 57 pi->value.search.cctx
58 = sc->client_info; 58 = sc->client_info;
@@ -62,8 +62,9 @@ GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
62 = sc->uri; 62 = sc->uri;
63 pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time); 63 pi->value.search.duration = GNUNET_TIME_absolute_get_duration (sc->start_time);
64 pi->value.search.anonymity = sc->anonymity; 64 pi->value.search.anonymity = sc->anonymity;
65 return sc->h->upcb (sc->h->upcb_cls, 65 ret = sc->h->upcb (sc->h->upcb_cls,
66 pi); 66 pi);
67 return ret;
67} 68}
68 69
69 70
@@ -217,6 +218,7 @@ probe_failure_handler (void *cls,
217{ 218{
218 struct GNUNET_FS_SearchResult *sr = cls; 219 struct GNUNET_FS_SearchResult *sr = cls;
219 sr->availability_trials++; 220 sr->availability_trials++;
221 GNUNET_FS_search_result_sync_ (sr);
220 signal_probe_result (sr); 222 signal_probe_result (sr);
221} 223}
222 224
@@ -234,6 +236,7 @@ probe_success_handler (void *cls,
234 struct GNUNET_FS_SearchResult *sr = cls; 236 struct GNUNET_FS_SearchResult *sr = cls;
235 sr->availability_trials++; 237 sr->availability_trials++;
236 sr->availability_success++; 238 sr->availability_success++;
239 GNUNET_FS_search_result_sync_ (sr);
237 signal_probe_result (sr); 240 signal_probe_result (sr);
238} 241}
239 242
@@ -327,6 +330,7 @@ GNUNET_FS_search_probe_progress_ (void *cls,
327 dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time); 330 dur = GNUNET_TIME_absolute_get_duration (sr->probe_active_time);
328 sr->remaining_probe_time = GNUNET_TIME_relative_subtract (sr->remaining_probe_time, 331 sr->remaining_probe_time = GNUNET_TIME_relative_subtract (sr->remaining_probe_time,
329 dur); 332 dur);
333 GNUNET_FS_search_result_sync_ (sr);
330 break; 334 break;
331 default: 335 default:
332 GNUNET_break (0); 336 GNUNET_break (0);
@@ -427,6 +431,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
427 sr->uri = GNUNET_FS_uri_dup (uri); 431 sr->uri = GNUNET_FS_uri_dup (uri);
428 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 432 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
429 sr->mandatory_missing = sc->mandatory_count; 433 sr->mandatory_missing = sc->mandatory_count;
434 sr->key = key;
430 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 435 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
431 &key, 436 &key,
432 sr, 437 sr,
@@ -447,6 +452,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
447 notify_client_chk_result (sc, sr); 452 notify_client_chk_result (sc, sr);
448 else 453 else
449 notify_client_chk_update (sc, sr); 454 notify_client_chk_update (sc, sr);
455 GNUNET_FS_search_result_sync_ (sr);
450 GNUNET_FS_search_start_probe_ (sr); 456 GNUNET_FS_search_start_probe_ (sr);
451} 457}
452 458
@@ -506,10 +512,12 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
506 sr->sc = sc; 512 sr->sc = sc;
507 sr->uri = GNUNET_FS_uri_dup (uri); 513 sr->uri = GNUNET_FS_uri_dup (uri);
508 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 514 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
515 sr->key = key;
509 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, 516 GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
510 &key, 517 &key,
511 sr, 518 sr,
512 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 519 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
520 GNUNET_FS_search_result_sync_ (sr);
513 GNUNET_FS_search_start_probe_ (sr); 521 GNUNET_FS_search_start_probe_ (sr);
514 /* notify client */ 522 /* notify client */
515 notify_client_chk_result (sc, sr); 523 notify_client_chk_result (sc, sr);
@@ -1090,6 +1098,7 @@ search_start (struct GNUNET_FS_Handle *h,
1090 GNUNET_free (sc); 1098 GNUNET_free (sc);
1091 return NULL; 1099 return NULL;
1092 } 1100 }
1101 GNUNET_FS_search_sync_ (sc);
1093 pi.status = GNUNET_FS_STATUS_SEARCH_START; 1102 pi.status = GNUNET_FS_STATUS_SEARCH_START;
1094 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1103 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1095 return sc; 1104 return sc;
@@ -1299,7 +1308,7 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1299 if (NULL != sc->client) 1308 if (NULL != sc->client)
1300 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1309 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1301 sc->client = NULL; 1310 sc->client = NULL;
1302 // FIXME: make persistent! 1311 GNUNET_FS_search_sync_ (sc);
1303 // FIXME: should this freeze all active probes? 1312 // FIXME: should this freeze all active probes?
1304 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; 1313 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
1305 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1314 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
@@ -1319,7 +1328,7 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1319 GNUNET_assert (sc->client == NULL); 1328 GNUNET_assert (sc->client == NULL);
1320 GNUNET_assert (sc->task == GNUNET_SCHEDULER_NO_TASK); 1329 GNUNET_assert (sc->task == GNUNET_SCHEDULER_NO_TASK);
1321 do_reconnect (sc, NULL); 1330 do_reconnect (sc, NULL);
1322 // FIXME: make persistent! 1331 GNUNET_FS_search_sync_ (sc);
1323 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; 1332 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
1324 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1333 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1325} 1334}
@@ -1395,10 +1404,14 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1395 struct GNUNET_FS_ProgressInfo pi; 1404 struct GNUNET_FS_ProgressInfo pi;
1396 unsigned int i; 1405 unsigned int i;
1397 struct GNUNET_FS_SearchContext *parent; 1406 struct GNUNET_FS_SearchContext *parent;
1407 int had_result;
1398 1408
1399 if (sc->top != NULL) 1409 if (sc->top != NULL)
1400 GNUNET_FS_end_top (sc->h, sc->top); 1410 GNUNET_FS_end_top (sc->h, sc->top);
1401 // FIXME: make un-persistent! 1411 if (sc->serialization != NULL)
1412 GNUNET_FS_remove_sync_file_ (sc->h,
1413 (sc->parent != NULL) ? "search-children" : "search",
1414 sc->serialization);
1402 if (NULL != (parent = sc->parent)) 1415 if (NULL != (parent = sc->parent))
1403 { 1416 {
1404 GNUNET_CONTAINER_DLL_remove (parent->child_head, 1417 GNUNET_CONTAINER_DLL_remove (parent->child_head,
@@ -1408,9 +1421,12 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1408 } 1421 }
1409 while (NULL != sc->child_head) 1422 while (NULL != sc->child_head)
1410 GNUNET_FS_search_stop (sc->child_head); 1423 GNUNET_FS_search_stop (sc->child_head);
1424 had_result = (0 != GNUNET_CONTAINER_multihashmap_size (sc->master_result_map)) ? GNUNET_YES : GNUNET_NO;
1411 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, 1425 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1412 &search_result_free, 1426 &search_result_free,
1413 sc); 1427 sc);
1428 if (had_result)
1429 GNUNET_FS_remove_sync_dir_ (sc->h, "search-results", sc->serialization);
1414 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; 1430 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
1415 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1431 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1416 GNUNET_break (NULL == sc->client_info); 1432 GNUNET_break (NULL == sc->client_info);