aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO5
-rw-r--r--src/fs/fs.c50
-rw-r--r--src/fs/fs.h128
-rw-r--r--src/fs/fs_download.c24
-rw-r--r--src/fs/fs_publish.c19
-rw-r--r--src/fs/fs_search.c23
-rw-r--r--src/fs/fs_unindex.c21
7 files changed, 260 insertions, 10 deletions
diff --git a/TODO b/TODO
index 88d5d2877..c9141e21f 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,8 @@
10.9.0pre1: 10.9.0pre1:
2* FS: [CG] 2* FS: [CG]
3 - implement linking of downloads to searches in syncing (serialize/deserialize) 3 - implement linking of downloads to searches in syncing (serialize/deserialize)
4 - generate SUSPEND events (publish, unindex, search, download) AND free memory!
5 => test SUSPEND events
4 - actually call 'sync' functions (publish, unindex, search, download) 6 - actually call 'sync' functions (publish, unindex, search, download)
5 - code review: 7 - code review:
6 => refactor fs.c to join common code segments! 8 => refactor fs.c to join common code segments!
@@ -9,9 +11,6 @@
9 - persistence testing (publish, unindex, search, download): 11 - persistence testing (publish, unindex, search, download):
10 => need driver! 12 => need driver!
11 => schedule suspending tasks DURING event handler => good coverage! 13 => schedule suspending tasks DURING event handler => good coverage!
12 - track top-level operations in FS_Handle (needed for SUSPEND signalling)
13 - generate SUSPEND events (publish, unindex, search, download) AND free memory!
14 => test SUSPEND events
15 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks) 14 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks)
16 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used 15 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used
17 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used 16 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used
diff --git a/src/fs/fs.c b/src/fs/fs.c
index f0753eee2..d0e73b21a 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -213,6 +213,49 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh)
213 213
214 214
215/** 215/**
216 * Create a top-level activity entry.
217 *
218 * @param h global fs handle
219 * @param ssf suspend signal function to use
220 * @param ssf_cls closure for ssf
221 * @return fresh top-level activity handle
222 */
223struct TopLevelActivity *
224GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
225 SuspendSignalFunction ssf,
226 void *ssf_cls)
227{
228 struct TopLevelActivity *ret;
229
230 ret = GNUNET_malloc (sizeof (struct TopLevelActivity));
231 ret->ssf = ssf;
232 ret->ssf_cls = ssf_cls;
233 GNUNET_CONTAINER_DLL_insert (h->top_head,
234 h->top_tail,
235 ret);
236 return ret;
237}
238
239
240/**
241 * Destroy a top-level activity entry.
242 *
243 * @param h global fs handle
244 * @param top top level activity entry
245 */
246void
247GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
248 struct TopLevelActivity *top)
249{
250 GNUNET_CONTAINER_DLL_remove (h->top_head,
251 h->top_tail,
252 top);
253 GNUNET_free (top);
254}
255
256
257
258/**
216 * Closure for "data_reader_file". 259 * Closure for "data_reader_file".
217 */ 260 */
218struct FileInfo 261struct FileInfo
@@ -2513,10 +2556,9 @@ GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
2513void 2556void
2514GNUNET_FS_stop (struct GNUNET_FS_Handle *h) 2557GNUNET_FS_stop (struct GNUNET_FS_Handle *h)
2515{ 2558{
2516 if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & h->flags)) 2559 /* generate SUSPEND events and clean up state */
2517 { 2560 while (h->top_head != NULL)
2518 // FIXME: generate SUSPEND events and clean up state! 2561 h->top_head->ssf (h->top_head->ssf_cls);
2519 }
2520 // FIXME: terminate receive-loop with client (do we need one?) 2562 // FIXME: terminate receive-loop with client (do we need one?)
2521 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK) 2563 if (h->queue_job != GNUNET_SCHEDULER_NO_TASK)
2522 GNUNET_SCHEDULER_cancel (h->sched, 2564 GNUNET_SCHEDULER_cancel (h->sched,
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 7b30367ea..275882c4f 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -158,7 +158,14 @@
158 */ 158 */
159struct ContentHashKey 159struct ContentHashKey
160{ 160{
161 /**
162 * Hash of the original content, used for encryption.
163 */
161 GNUNET_HashCode key; 164 GNUNET_HashCode key;
165
166 /**
167 * Hash of the encrypted content, used for querying.
168 */
162 GNUNET_HashCode query; 169 GNUNET_HashCode query;
163}; 170};
164 171
@@ -212,15 +219,42 @@ struct Location
212 219
213}; 220};
214 221
222/**
223 * Types of URIs.
224 */
215enum uri_types 225enum uri_types
216{ chk, sks, ksk, loc }; 226 {
227 /**
228 * Content-hash-key (simple file).
229 */
230 chk,
231
232 /**
233 * Signed key space (file in namespace).
234 */
235 sks,
236
237 /**
238 * Keyword search key (query with keywords).
239 */
240 ksk,
241
242 /**
243 * Location (chk with identity of hosting peer).
244 */
245 loc
246 };
217 247
218/** 248/**
219 * A Universal Resource Identifier (URI), opaque. 249 * A Universal Resource Identifier (URI), opaque.
220 */ 250 */
221struct GNUNET_FS_Uri 251struct GNUNET_FS_Uri
222{ 252{
253 /**
254 * Type of the URI.
255 */
223 enum uri_types type; 256 enum uri_types type;
257
224 union 258 union
225 { 259 {
226 struct 260 struct
@@ -930,6 +964,68 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
930 964
931 965
932/** 966/**
967 * Function signature of the functions that can be called
968 * to trigger suspend signals and clean-up for top-level
969 * activities.
970 *
971 * @param cls closure
972 */
973typedef void (*SuspendSignalFunction)(void *cls);
974
975/**
976 * We track all of the top-level activities of FS
977 * so that we can signal 'suspend' on shutdown.
978 */
979struct TopLevelActivity
980{
981 /**
982 * This is a doubly-linked list.
983 */
984 struct TopLevelActivity *next;
985
986 /**
987 * This is a doubly-linked list.
988 */
989 struct TopLevelActivity *prev;
990
991 /**
992 * Function to call for suspend-signalling and clean up.
993 */
994 SuspendSignalFunction ssf;
995
996 /**
997 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
998 */
999 void *ssf_cls;
1000};
1001
1002
1003/**
1004 * Create a top-level activity entry.
1005 *
1006 * @param h global fs handle
1007 * @param ssf suspend signal function to use
1008 * @param ssf_cls closure for ssf
1009 * @return fresh top-level activity handle
1010 */
1011struct TopLevelActivity *
1012GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1013 SuspendSignalFunction ssf,
1014 void *ssf_cls);
1015
1016
1017/**
1018 * Destroy a top-level activity entry.
1019 *
1020 * @param h global fs handle
1021 * @param top top level activity entry
1022 */
1023void
1024GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1025 struct TopLevelActivity *top);
1026
1027
1028/**
933 * Master context for most FS operations. 1029 * Master context for most FS operations.
934 */ 1030 */
935struct GNUNET_FS_Handle 1031struct GNUNET_FS_Handle
@@ -965,6 +1061,16 @@ struct GNUNET_FS_Handle
965 struct GNUNET_CLIENT_Connection *client; 1061 struct GNUNET_CLIENT_Connection *client;
966 1062
967 /** 1063 /**
1064 * Head of DLL of top-level activities.
1065 */
1066 struct TopLevelActivity *top_head;
1067
1068 /**
1069 * Tail of DLL of top-level activities.
1070 */
1071 struct TopLevelActivity *top_tail;
1072
1073 /**
968 * Head of DLL of running jobs. 1074 * Head of DLL of running jobs.
969 */ 1075 */
970 struct GNUNET_FS_QueueEntry *running_head; 1076 struct GNUNET_FS_QueueEntry *running_head;
@@ -1035,6 +1141,11 @@ struct GNUNET_FS_PublishContext
1035 struct GNUNET_FS_Handle *h; 1141 struct GNUNET_FS_Handle *h;
1036 1142
1037 /** 1143 /**
1144 * Our top-level activity entry (if we are top-level, otherwise NULL).
1145 */
1146 struct TopLevelActivity *top;
1147
1148 /**
1038 * File-structure that is being shared. 1149 * File-structure that is being shared.
1039 */ 1150 */
1040 struct GNUNET_FS_FileInformation *fi; 1151 struct GNUNET_FS_FileInformation *fi;
@@ -1163,6 +1274,11 @@ struct GNUNET_FS_UnindexContext
1163 struct GNUNET_FS_Handle *h; 1274 struct GNUNET_FS_Handle *h;
1164 1275
1165 /** 1276 /**
1277 * Our top-level activity entry.
1278 */
1279 struct TopLevelActivity *top;
1280
1281 /**
1166 * Name of the file that we are unindexing. 1282 * Name of the file that we are unindexing.
1167 */ 1283 */
1168 char *filename; 1284 char *filename;
@@ -1274,6 +1390,11 @@ struct GNUNET_FS_SearchContext
1274 struct GNUNET_FS_Handle *h; 1390 struct GNUNET_FS_Handle *h;
1275 1391
1276 /** 1392 /**
1393 * Our top-level activity entry (if we are top-level, otherwise NULL).
1394 */
1395 struct TopLevelActivity *top;
1396
1397 /**
1277 * List of keywords that we're looking for. 1398 * List of keywords that we're looking for.
1278 */ 1399 */
1279 struct GNUNET_FS_Uri *uri; 1400 struct GNUNET_FS_Uri *uri;
@@ -1420,6 +1541,11 @@ struct GNUNET_FS_DownloadContext
1420 * Global FS context. 1541 * Global FS context.
1421 */ 1542 */
1422 struct GNUNET_FS_Handle *h; 1543 struct GNUNET_FS_Handle *h;
1544
1545 /**
1546 * Our top-level activity entry (if we are top-level, otherwise NULL).
1547 */
1548 struct TopLevelActivity *top;
1423 1549
1424 /** 1550 /**
1425 * Connection to the FS service. 1551 * Connection to the FS service.
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index 6390539bc..bf59918e7 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -1384,6 +1384,23 @@ deactivate_fs_download (void *cls)
1384 1384
1385 1385
1386/** 1386/**
1387 * Create SUSPEND event for the given download operation
1388 * and then clean up our state (without stop signal).
1389 *
1390 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1391 */
1392static void
1393download_signal_suspend (void *cls)
1394{
1395 struct GNUNET_FS_DownloadContext *dc = cls;
1396
1397 GNUNET_FS_end_top (dc->h, dc->top);
1398 /* FIXME: signal! */
1399 GNUNET_free (dc);
1400}
1401
1402
1403/**
1387 * Download parts of a file. Note that this will store 1404 * Download parts of a file. Note that this will store
1388 * the blocks at the respective offset in the given file. Also, the 1405 * the blocks at the respective offset in the given file. Also, the
1389 * download is still using the blocking of the underlying FS 1406 * download is still using the blocking of the underlying FS
@@ -1496,6 +1513,11 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
1496 0, 1513 0,
1497 1 /* 0 == CHK, 1 == top */); 1514 1 /* 0 == CHK, 1 == top */);
1498 GNUNET_FS_download_start_downloading_ (dc); 1515 GNUNET_FS_download_start_downloading_ (dc);
1516 if (parent == NULL)
1517 dc->top = GNUNET_FS_make_top (dc->h,
1518 &download_signal_suspend,
1519 dc);
1520
1499 return dc; 1521 return dc;
1500} 1522}
1501 1523
@@ -1665,6 +1687,8 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
1665{ 1687{
1666 struct GNUNET_FS_ProgressInfo pi; 1688 struct GNUNET_FS_ProgressInfo pi;
1667 1689
1690 if (dc->top != NULL)
1691 GNUNET_FS_end_top (dc->h, dc->top);
1668 if (dc->search != NULL) 1692 if (dc->search != NULL)
1669 { 1693 {
1670 dc->search->download = NULL; 1694 dc->search->download = NULL;
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index c4dbe624e..4101174bb 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -930,6 +930,22 @@ fip_signal_start(void *cls,
930 930
931 931
932/** 932/**
933 * Create SUSPEND event for the given publish operation
934 * and then clean up our state (without stop signal).
935 *
936 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
937 */
938static void
939publish_signal_suspend (void *cls)
940{
941 struct GNUNET_FS_PublishContext *pc = cls;
942
943 GNUNET_FS_end_top (pc->h, pc->top);
944 /* FIXME: signal! */
945 GNUNET_free (pc);
946}
947
948/**
933 * Publish a file or directory. 949 * Publish a file or directory.
934 * 950 *
935 * @param h handle to the file sharing subsystem 951 * @param h handle to the file sharing subsystem
@@ -983,7 +999,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
983 &fip_signal_start, 999 &fip_signal_start,
984 ret); 1000 ret);
985 ret->fi_pos = ret->fi; 1001 ret->fi_pos = ret->fi;
986 1002 ret->top = GNUNET_FS_make_top (h, &publish_signal_suspend, ret);
987 // FIXME: calculate space needed for "fi" 1003 // FIXME: calculate space needed for "fi"
988 // and reserve as first task (then trigger 1004 // and reserve as first task (then trigger
989 // "publish_main" from that continuation)! 1005 // "publish_main" from that continuation)!
@@ -1056,6 +1072,7 @@ fip_signal_stop(void *cls,
1056void 1072void
1057GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) 1073GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1058{ 1074{
1075 GNUNET_FS_end_top (pc->h, pc->top);
1059 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task) 1076 if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task)
1060 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task); 1077 GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task);
1061 if (pc->serialization != NULL) 1078 if (pc->serialization != NULL)
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 611a089c4..00909ce97 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1161,6 +1161,21 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
1161} 1161}
1162 1162
1163 1163
1164/**
1165 * Create SUSPEND event for the given search operation
1166 * and then clean up our state (without stop signal).
1167 *
1168 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1169 */
1170static void
1171search_signal_suspend (void *cls)
1172{
1173 struct GNUNET_FS_SearchContext *sc = cls;
1174
1175 GNUNET_FS_end_top (sc->h, sc->top);
1176 /* FIXME: signal! */
1177 GNUNET_free (sc);
1178}
1164 1179
1165 1180
1166/** 1181/**
@@ -1181,7 +1196,10 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1181 enum GNUNET_FS_SearchOptions options, 1196 enum GNUNET_FS_SearchOptions options,
1182 void *cctx) 1197 void *cctx)
1183{ 1198{
1184 return search_start (h, uri, anonymity, options, cctx, NULL); 1199 struct GNUNET_FS_SearchContext *ret;
1200 ret = search_start (h, uri, anonymity, options, cctx, NULL);
1201 ret->top = GNUNET_FS_make_top (h, &search_signal_suspend, ret);
1202 return ret;
1185} 1203}
1186 1204
1187 1205
@@ -1253,6 +1271,7 @@ search_result_free (void *cls,
1253 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT; 1271 pi.status = GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT;
1254 GNUNET_FS_download_make_status_ (&pi, 1272 GNUNET_FS_download_make_status_ (&pi,
1255 sr->download); 1273 sr->download);
1274 /* FIXME: promote download to top-level! */
1256 sr->download = NULL; 1275 sr->download = NULL;
1257 } 1276 }
1258 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED; 1277 pi.status = GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED;
@@ -1298,6 +1317,8 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc)
1298 unsigned int i; 1317 unsigned int i;
1299 struct GNUNET_FS_SearchContext *parent; 1318 struct GNUNET_FS_SearchContext *parent;
1300 1319
1320 if (sc->top != NULL)
1321 GNUNET_FS_end_top (sc->h, sc->top);
1301 // FIXME: make un-persistent! 1322 // FIXME: make un-persistent!
1302 if (NULL != (parent = sc->parent)) 1323 if (NULL != (parent = sc->parent))
1303 { 1324 {
diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c
index 4b4e526dd..6d4ee3f54 100644
--- a/src/fs/fs_unindex.c
+++ b/src/fs/fs_unindex.c
@@ -394,6 +394,23 @@ GNUNET_FS_unindex_process_hash_ (void *cls,
394 394
395 395
396/** 396/**
397 * Create SUSPEND event for the given unindex operation
398 * and then clean up our state (without stop signal).
399 *
400 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
401 */
402static void
403unindex_signal_suspend (void *cls)
404{
405 struct GNUNET_FS_UnindexContext *uc = cls;
406
407 GNUNET_FS_end_top (uc->h, uc->top);
408 /* FIXME: signal! */
409 GNUNET_free (uc);
410}
411
412
413/**
397 * Unindex a file. 414 * Unindex a file.
398 * 415 *
399 * @param h handle to the file sharing subsystem 416 * @param h handle to the file sharing subsystem
@@ -432,6 +449,9 @@ GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
432 HASHING_BLOCKSIZE, 449 HASHING_BLOCKSIZE,
433 &GNUNET_FS_unindex_process_hash_, 450 &GNUNET_FS_unindex_process_hash_,
434 ret); 451 ret);
452 ret->top = GNUNET_FS_make_top (h,
453 &unindex_signal_suspend,
454 ret);
435 return ret; 455 return ret;
436} 456}
437 457
@@ -446,6 +466,7 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
446{ 466{
447 struct GNUNET_FS_ProgressInfo pi; 467 struct GNUNET_FS_ProgressInfo pi;
448 468
469 GNUNET_FS_end_top (uc->h, uc->top);
449 if ( (uc->state != UNINDEX_STATE_COMPLETE) && 470 if ( (uc->state != UNINDEX_STATE_COMPLETE) &&
450 (uc->state != UNINDEX_STATE_ERROR) ) 471 (uc->state != UNINDEX_STATE_ERROR) )
451 { 472 {