aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--src/fs/fs.h10
-rw-r--r--src/fs/fs_download.c79
-rw-r--r--src/fs/fs_publish.c56
-rw-r--r--src/fs/fs_search.c74
-rw-r--r--src/fs/fs_unindex.c11
-rw-r--r--src/include/gnunet_fs_service.h6
7 files changed, 207 insertions, 32 deletions
diff --git a/TODO b/TODO
index 861e2915d..14f1d5ce6 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
10.9.0pre1: 10.9.0pre1:
2* FS: [CG] 2* FS: [CG]
3 - generate SUSPEND events (publish, unindex, search, download) AND free memory!
4 => test SUSPEND events
5 - actually call 'sync' functions (publish, unindex, search, download) 3 - actually call 'sync' functions (publish, unindex, search, download)
6 - code review: 4 - code review:
7 => refactor fs.c to join common code segments! 5 => refactor fs.c to join common code segments!
@@ -10,6 +8,7 @@
10 - persistence testing (publish, unindex, search, download): 8 - persistence testing (publish, unindex, search, download):
11 => need driver! 9 => need driver!
12 => schedule suspending tasks DURING event handler => good coverage! 10 => schedule suspending tasks DURING event handler => good coverage!
11 => test SUSPEND events
13 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks) 12 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks)
14 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used 13 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used
15 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used 14 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 275882c4f..1d3498a7c 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -1026,6 +1026,16 @@ GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1026 1026
1027 1027
1028/** 1028/**
1029 * Create SUSPEND event for the given download operation
1030 * and then clean up our state (without stop signal).
1031 *
1032 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1033 */
1034void
1035GNUNET_FS_download_signal_suspend_ (void *cls);
1036
1037
1038/**
1029 * Master context for most FS operations. 1039 * Master context for most FS operations.
1030 */ 1040 */
1031struct GNUNET_FS_Handle 1041struct GNUNET_FS_Handle
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index d7c5370b1..2fd8e0412 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -1384,18 +1384,67 @@ deactivate_fs_download (void *cls)
1384 1384
1385 1385
1386/** 1386/**
1387 * Free entries in the map.
1388 *
1389 * @param cls unused (NULL)
1390 * @param key unused
1391 * @param entry entry of type "struct DownloadRequest" which is freed
1392 * @return GNUNET_OK
1393 */
1394static int
1395free_entry (void *cls,
1396 const GNUNET_HashCode *key,
1397 void *entry)
1398{
1399 GNUNET_free (entry);
1400 return GNUNET_OK;
1401}
1402
1403
1404/**
1387 * Create SUSPEND event for the given download operation 1405 * Create SUSPEND event for the given download operation
1388 * and then clean up our state (without stop signal). 1406 * and then clean up our state (without stop signal).
1389 * 1407 *
1390 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for 1408 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1391 */ 1409 */
1392static void 1410void
1393download_signal_suspend (void *cls) 1411GNUNET_FS_download_signal_suspend_ (void *cls)
1394{ 1412{
1395 struct GNUNET_FS_DownloadContext *dc = cls; 1413 struct GNUNET_FS_DownloadContext *dc = cls;
1414 struct GNUNET_FS_ProgressInfo pi;
1396 1415
1397 GNUNET_FS_end_top (dc->h, dc->top); 1416 if (dc->top != NULL)
1398 /* FIXME: signal! */ 1417 GNUNET_FS_end_top (dc->h, dc->top);
1418 while (NULL != dc->child_head)
1419 GNUNET_FS_download_signal_suspend_ (dc->child_head);
1420 if (dc->search != NULL)
1421 {
1422 dc->search->download = NULL;
1423 dc->search = NULL;
1424 }
1425 if (dc->job_queue != NULL)
1426 {
1427 GNUNET_FS_dequeue_ (dc->job_queue);
1428 dc->job_queue = NULL;
1429 }
1430 if (dc->parent != NULL)
1431 GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
1432 dc->parent->child_tail,
1433 dc);
1434 pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND;
1435 GNUNET_FS_download_make_status_ (&pi, dc);
1436 if (GNUNET_SCHEDULER_NO_TASK != dc->task)
1437 GNUNET_SCHEDULER_cancel (dc->h->sched,
1438 dc->task);
1439 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1440 &free_entry,
1441 NULL);
1442 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
1443 GNUNET_free_non_null (dc->filename);
1444 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
1445 GNUNET_FS_uri_destroy (dc->uri);
1446 GNUNET_free_non_null (dc->temp_filename);
1447 GNUNET_free_non_null (dc->serialization);
1399 GNUNET_free (dc); 1448 GNUNET_free (dc);
1400} 1449}
1401 1450
@@ -1515,7 +1564,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
1515 GNUNET_FS_download_start_downloading_ (dc); 1564 GNUNET_FS_download_start_downloading_ (dc);
1516 if (parent == NULL) 1565 if (parent == NULL)
1517 dc->top = GNUNET_FS_make_top (dc->h, 1566 dc->top = GNUNET_FS_make_top (dc->h,
1518 &download_signal_suspend, 1567 &GNUNET_FS_download_signal_suspend_,
1519 dc); 1568 dc);
1520 1569
1521 return dc; 1570 return dc;
@@ -1663,24 +1712,6 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
1663 1712
1664 1713
1665/** 1714/**
1666 * Free entries in the map.
1667 *
1668 * @param cls unused (NULL)
1669 * @param key unused
1670 * @param entry entry of type "struct DownloadRequest" which is freed
1671 * @return GNUNET_OK
1672 */
1673static int
1674free_entry (void *cls,
1675 const GNUNET_HashCode *key,
1676 void *entry)
1677{
1678 GNUNET_free (entry);
1679 return GNUNET_OK;
1680}
1681
1682
1683/**
1684 * Stop a download (aborts if download is incomplete). 1715 * Stop a download (aborts if download is incomplete).
1685 * 1716 *
1686 * @param dc handle for the download 1717 * @param dc handle for the download
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 4101174bb..0c4ebba7b 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -930,6 +930,46 @@ fip_signal_start(void *cls,
930 930
931 931
932/** 932/**
933 * Signal the FS's progress function that we are suspending
934 * an upload.
935 *
936 * @param cls closure (of type "struct GNUNET_FS_PublishContext*")
937 * @param fi the entry in the publish-structure
938 * @param length length of the file or directory
939 * @param meta metadata for the file or directory (can be modified)
940 * @param uri pointer to the keywords that will be used for this entry (can be modified)
941 * @param anonymity pointer to selected anonymity level (can be modified)
942 * @param priority pointer to selected priority (can be modified)
943 * @param expirationTime pointer to selected expiration time (can be modified)
944 * @param client_info pointer to client context set upon creation (can be modified)
945 * @return GNUNET_OK to continue (always)
946 */
947static int
948fip_signal_suspend(void *cls,
949 struct GNUNET_FS_FileInformation *fi,
950 uint64_t length,
951 struct GNUNET_CONTAINER_MetaData *meta,
952 struct GNUNET_FS_Uri **uri,
953 uint32_t *anonymity,
954 uint32_t *priority,
955 struct GNUNET_TIME_Absolute *expirationTime,
956 void **client_info)
957{
958 struct GNUNET_FS_PublishContext*sc = cls;
959 struct GNUNET_FS_ProgressInfo pi;
960 uint64_t off;
961
962 GNUNET_free_non_null (fi->serialization);
963 fi->serialization = NULL;
964 off = (fi->chk_uri == NULL) ? 0 : length;
965 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
966 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off));
967 *client_info = NULL;
968 return GNUNET_OK;
969}
970
971
972/**
933 * Create SUSPEND event for the given publish operation 973 * Create SUSPEND event for the given publish operation
934 * and then clean up our state (without stop signal). 974 * and then clean up our state (without stop signal).
935 * 975 *
@@ -940,9 +980,16 @@ publish_signal_suspend (void *cls)
940{ 980{
941 struct GNUNET_FS_PublishContext *pc = cls; 981 struct GNUNET_FS_PublishContext *pc = cls;
942 982
983 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
984 {
985 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
986 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
987 }
988 GNUNET_FS_file_information_inspect (pc->fi,
989 &fip_signal_suspend,
990 pc);
943 GNUNET_FS_end_top (pc->h, pc->top); 991 GNUNET_FS_end_top (pc->h, pc->top);
944 /* FIXME: signal! */ 992 publish_cleanup (pc);
945 GNUNET_free (pc);
946} 993}
947 994
948/** 995/**
@@ -1074,7 +1121,10 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1074{ 1121{
1075 GNUNET_FS_end_top (pc->h, pc->top); 1122 GNUNET_FS_end_top (pc->h, pc->top);
1076 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task) 1123 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1077 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task); 1124 {
1125 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1126 pc->upload_task = GNUNET_SCHEDULER_NO_TASK;
1127 }
1078 if (pc->serialization != NULL) 1128 if (pc->serialization != NULL)
1079 { 1129 {
1080 GNUNET_FS_remove_sync_file_ (pc->h, "publish", pc->serialization); 1130 GNUNET_FS_remove_sync_file_ (pc->h, "publish", pc->serialization);
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 9ab024eeb..36aa26193 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1168,6 +1168,46 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1168} 1168}
1169 1169
1170 1170
1171
1172/**
1173 * Signal suspend and free the given search result.
1174 *
1175 * @param cls the global FS handle
1176 * @param key the key for the search result (unused)
1177 * @param value the search result to free
1178 * @return GNUNET_OK
1179 */
1180static int
1181search_result_suspend (void *cls,
1182 const GNUNET_HashCode * key,
1183 void *value)
1184{
1185 struct GNUNET_FS_SearchContext *sc = cls;
1186 struct GNUNET_FS_Handle *h = sc->h;
1187 struct GNUNET_FS_SearchResult *sr = value;
1188 struct GNUNET_FS_ProgressInfo pi;
1189
1190 if (sr->download != NULL)
1191 GNUNET_FS_download_signal_suspend_ (sr->download);
1192 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND;
1193 pi.value.search.specifics.result_suspend.cctx = sr->client_info;
1194 pi.value.search.specifics.result_suspend.meta = sr->meta;
1195 pi.value.search.specifics.result_suspend.uri = sr->uri;
1196 sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1197 GNUNET_break (NULL == sr->client_info);
1198 GNUNET_free_non_null (sr->serialization);
1199 GNUNET_FS_uri_destroy (sr->uri);
1200 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
1201 if (sr->probe_ctx != NULL)
1202 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1203 if (sr->probe_cancel_task != GNUNET_SCHEDULER_NO_TASK)
1204 GNUNET_SCHEDULER_cancel (h->sched,
1205 sr->probe_cancel_task);
1206 GNUNET_free (sr);
1207 return GNUNET_OK;
1208}
1209
1210
1171/** 1211/**
1172 * Create SUSPEND event for the given search operation 1212 * Create SUSPEND event for the given search operation
1173 * and then clean up our state (without stop signal). 1213 * and then clean up our state (without stop signal).
@@ -1178,9 +1218,41 @@ static void
1178search_signal_suspend (void *cls) 1218search_signal_suspend (void *cls)
1179{ 1219{
1180 struct GNUNET_FS_SearchContext *sc = cls; 1220 struct GNUNET_FS_SearchContext *sc = cls;
1221 struct GNUNET_FS_SearchContext *parent = cls;
1222 struct GNUNET_FS_ProgressInfo pi;
1223 unsigned int i;
1181 1224
1182 GNUNET_FS_end_top (sc->h, sc->top); 1225 GNUNET_FS_end_top (sc->h, sc->top);
1183 /* FIXME: signal! */ 1226 if (NULL != (parent = sc->parent))
1227 {
1228 GNUNET_CONTAINER_DLL_remove (parent->child_head,
1229 parent->child_tail,
1230 sc);
1231 sc->parent = NULL;
1232 }
1233 while (NULL != sc->child_head)
1234 search_signal_suspend (sc->child_head);
1235 GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
1236 &search_result_suspend,
1237 sc);
1238 pi.status = GNUNET_FS_STATUS_SEARCH_SUSPEND;
1239 sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
1240 GNUNET_break (NULL == sc->client_info);
1241 if (sc->task != GNUNET_SCHEDULER_NO_TASK)
1242 GNUNET_SCHEDULER_cancel (sc->h->sched,
1243 sc->task);
1244 if (NULL != sc->client)
1245 GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
1246 GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
1247 if (sc->requests != NULL)
1248 {
1249 GNUNET_assert (GNUNET_FS_uri_test_ksk (sc->uri));
1250 for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
1251 GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
1252 }
1253 GNUNET_free_non_null (sc->requests);
1254 GNUNET_free_non_null (sc->emsg);
1255 GNUNET_FS_uri_destroy (sc->uri);
1184 GNUNET_free (sc); 1256 GNUNET_free (sc);
1185} 1257}
1186 1258
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 6d4ee3f54..c79b3413e 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -403,9 +403,16 @@ static void
403unindex_signal_suspend (void *cls) 403unindex_signal_suspend (void *cls)
404{ 404{
405 struct GNUNET_FS_UnindexContext *uc = cls; 405 struct GNUNET_FS_UnindexContext *uc = cls;
406 struct GNUNET_FS_ProgressInfo pi;
406 407
407 GNUNET_FS_end_top (uc->h, uc->top); 408 GNUNET_FS_end_top (uc->h, uc->top);
408 /* FIXME: signal! */ 409 pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND;
410 GNUNET_FS_unindex_make_status_ (&pi, uc,
411 (uc->state == UNINDEX_STATE_COMPLETE)
412 ? uc->file_size : 0);
413 GNUNET_break (NULL == uc->client_info);
414 GNUNET_free (uc->filename);
415 GNUNET_free_non_null (uc->serialization);
409 GNUNET_free (uc); 416 GNUNET_free (uc);
410} 417}
411 418
@@ -476,6 +483,7 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
476 if (uc->serialization != NULL) 483 if (uc->serialization != NULL)
477 { 484 {
478 GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization); 485 GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
486 GNUNET_free (uc->serialization);
479 uc->serialization = NULL; 487 uc->serialization = NULL;
480 } 488 }
481 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; 489 pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED;
@@ -485,7 +493,6 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
485 ? uc->file_size : 0); 493 ? uc->file_size : 0);
486 GNUNET_break (NULL == uc->client_info); 494 GNUNET_break (NULL == uc->client_info);
487 GNUNET_free (uc->filename); 495 GNUNET_free (uc->filename);
488 GNUNET_free_non_null (uc->serialization);
489 GNUNET_free (uc); 496 GNUNET_free (uc);
490} 497}
491 498
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 0645a11c4..2207e274e 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -647,6 +647,12 @@ enum GNUNET_FS_Status
647 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED, 647 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
648 648
649 /** 649 /**
650 * Event generated for each search result
651 * when the respective search is suspended.
652 */
653 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND,
654
655 /**
650 * Last message from a search; this signals 656 * Last message from a search; this signals
651 * that there will be no further events associated 657 * that there will be no further events associated
652 * with this search. 658 * with this search.