aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_search.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-04 11:55:52 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-04 11:55:52 +0000
commit3d8988d8bda24d394d72302cefd0d7d76336d068 (patch)
tree7d6016d6b9132e608c18fb1235c5712d4d1984ef /src/fs/fs_search.c
parent6276a671135e01b119f198d0ae3092bfeb14903e (diff)
downloadgnunet-3d8988d8bda24d394d72302cefd0d7d76336d068.tar.gz
gnunet-3d8988d8bda24d394d72302cefd0d7d76336d068.zip
code cleanup
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r--src/fs/fs_search.c92
1 files changed, 81 insertions, 11 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 8db9f115d..f36b46a16 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 * - remove *directory* with search results upon completion
28 * - centralize code that sprintf's the 'pbuf[32]' strings 27 * - centralize code that sprintf's the 'pbuf[32]' strings
29 * - add support for pushing "already seen" information 28 * - add support for pushing "already seen" information
30 * to FS service for bloomfilter (can wait) 29 * to FS service for bloomfilter (can wait)
@@ -38,8 +37,6 @@
38 37
39#define DEBUG_SEARCH GNUNET_NO 38#define DEBUG_SEARCH GNUNET_NO
40 39
41
42
43/** 40/**
44 * Fill in all of the generic fields for a search event and 41 * Fill in all of the generic fields for a search event and
45 * call the callback. 42 * call the callback.
@@ -527,8 +524,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
527 uu.type = sks; 524 uu.type = sks;
528 uu.data.sks.namespace = sc->uri->data.sks.namespace; 525 uu.data.sks.namespace = sc->uri->data.sks.namespace;
529 uu.data.sks.identifier = GNUNET_strdup (id_update); 526 uu.data.sks.identifier = GNUNET_strdup (id_update);
530 /* FIXME: should attach update search 527 /* FIXME: should attach update search to the individual result, not
531 to the individual result, not
532 the entire SKS search! */ 528 the entire SKS search! */
533 search_start (sc->h, 529 search_start (sc->h,
534 &uu, 530 &uu,
@@ -956,6 +952,9 @@ transmit_search_request (void *cls,
956 sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY); 952 sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY);
957 sm[i].anonymity_level = htonl (sc->anonymity); 953 sm[i].anonymity_level = htonl (sc->anonymity);
958 sm[i].query = sc->requests[i].query; 954 sm[i].query = sc->requests[i].query;
955 /* FIXME: should transmit hash codes of all already-known results here!
956 (and if they do not fit, add another message with the same
957 header and additional already-seen results!) */
959 } 958 }
960 } 959 }
961 else 960 else
@@ -984,6 +983,9 @@ transmit_search_request (void *cls,
984 GNUNET_CRYPTO_hash_xor (&idh, 983 GNUNET_CRYPTO_hash_xor (&idh,
985 &sm->target, 984 &sm->target,
986 &sm->query); 985 &sm->query);
986 /* FIXME: should transmit hash codes of all already-known results here!
987 (and if they do not fit, add another message with the same
988 header and additional already-seen results!) */
987 } 989 }
988 GNUNET_CLIENT_receive (sc->client, 990 GNUNET_CLIENT_receive (sc->client,
989 &receive_results, 991 &receive_results,
@@ -1177,6 +1179,57 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1177} 1179}
1178 1180
1179 1181
1182/**
1183 * Freeze probes for the given search result.
1184 *
1185 * @param cls the global FS handle
1186 * @param key the key for the search result (unused)
1187 * @param value the search result to free
1188 * @return GNUNET_OK
1189 */
1190static int
1191search_result_freeze_probes (void *cls,
1192 const GNUNET_HashCode * key,
1193 void *value)
1194{
1195 struct GNUNET_FS_SearchContext *sc = cls;
1196 struct GNUNET_FS_Handle *h = sc->h;
1197 struct GNUNET_FS_SearchResult *sr = value;
1198
1199 if (sr->probe_ctx != NULL)
1200 {
1201 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1202 sr->probe_ctx = NULL;
1203 }
1204 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1205 {
1206 GNUNET_SCHEDULER_cancel (h->sched,
1207 sr->probe_cancel_task);
1208 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
1209 }
1210 return GNUNET_OK;
1211}
1212
1213
1214/**
1215 * Resume probes for the given search result.
1216 *
1217 * @param cls the global FS handle
1218 * @param key the key for the search result (unused)
1219 * @param value the search result to free
1220 * @return GNUNET_OK
1221 */
1222static int
1223search_result_resume_probes (void *cls,
1224 const GNUNET_HashCode * key,
1225 void *value)
1226{
1227 struct GNUNET_FS_SearchResult *sr = value;
1228
1229 GNUNET_FS_search_start_probe_ (sr);
1230 return GNUNET_OK;
1231}
1232
1180 1233
1181/** 1234/**
1182 * Signal suspend and free the given search result. 1235 * Signal suspend and free the given search result.
@@ -1309,7 +1362,9 @@ GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc)
1309 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); 1362 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1310 sc->client = NULL; 1363 sc->client = NULL;
1311 GNUNET_FS_search_sync_ (sc); 1364 GNUNET_FS_search_sync_ (sc);
1312 // FIXME: should this freeze all active probes? 1365 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1366 &search_result_freeze_probes,
1367 sc);
1313 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED; 1368 pi.status = GNUNET_FS_STATUS_SEARCH_PAUSED;
1314 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1369 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1315} 1370}
@@ -1331,6 +1386,9 @@ GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc)
1331 GNUNET_FS_search_sync_ (sc); 1386 GNUNET_FS_search_sync_ (sc);
1332 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED; 1387 pi.status = GNUNET_FS_STATUS_SEARCH_CONTINUED;
1333 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1388 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1389 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1390 &search_result_resume_probes,
1391 sc);
1334} 1392}
1335 1393
1336 1394
@@ -1356,10 +1414,18 @@ search_result_free (void *cls,
1356 if (NULL != sr->download) 1414 if (NULL != sr->download)
1357 { 1415 {
1358 sr->download->search = NULL; 1416 sr->download->search = NULL;
1417 if (NULL != sr->download->serialization)
1418 {
1419 GNUNET_FS_remove_sync_file_ (sc->h,
1420 GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD,
1421 sr->download->serialization);
1422 GNUNET_free (sr->download->serialization);
1423 sr->download->serialization = NULL;
1424 }
1359 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; 1425 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
1360 GNUNET_FS_download_make_status_ (&pi, 1426 GNUNET_FS_download_make_status_ (&pi,
1361 sr->download); 1427 sr->download);
1362 /* FIXME: promote download to top-level! */ 1428 GNUNET_FS_download_sync_ (sr->download);
1363 sr->download = NULL; 1429 sr->download = NULL;
1364 } 1430 }
1365 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; 1431 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
@@ -1373,7 +1439,7 @@ search_result_free (void *cls,
1373 GNUNET_snprintf (pbuf, 1439 GNUNET_snprintf (pbuf,
1374 sizeof (pbuf), 1440 sizeof (pbuf),
1375 "%s%s%s", 1441 "%s%s%s",
1376 "search-results", 1442 GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
1377 DIR_SEPARATOR_STR, 1443 DIR_SEPARATOR_STR,
1378 sc->serialization); 1444 sc->serialization);
1379 GNUNET_FS_remove_sync_file_ (sc->h, 1445 GNUNET_FS_remove_sync_file_ (sc->h,
@@ -1410,7 +1476,9 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1410 GNUNET_FS_end_top (sc->h, sc->top); 1476 GNUNET_FS_end_top (sc->h, sc->top);
1411 if (sc->serialization != NULL) 1477 if (sc->serialization != NULL)
1412 GNUNET_FS_remove_sync_file_ (sc->h, 1478 GNUNET_FS_remove_sync_file_ (sc->h,
1413 (sc->parent != NULL) ? "search-children" : "search", 1479 (sc->parent != NULL)
1480 ? GNUNET_FS_SYNC_PATH_CHILD_SEARCH
1481 : GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
1414 sc->serialization); 1482 sc->serialization);
1415 if (NULL != (parent = sc->parent)) 1483 if (NULL != (parent = sc->parent))
1416 { 1484 {
@@ -1426,7 +1494,9 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1426 &search_result_free, 1494 &search_result_free,
1427 sc); 1495 sc);
1428 if (had_result) 1496 if (had_result)
1429 GNUNET_FS_remove_sync_dir_ (sc->h, "search-results", sc->serialization); 1497 GNUNET_FS_remove_sync_dir_ (sc->h,
1498 GNUNET_FS_SYNC_PATH_SEARCH_RESULT,
1499 sc->serialization);
1430 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED; 1500 pi.status = GNUNET_FS_STATUS_SEARCH_STOPPED;
1431 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc); 1501 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1432 GNUNET_break (NULL == sc->client_info); 1502 GNUNET_break (NULL == sc->client_info);