3 This file is part of GNUnet.
4 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
24 * @brief definitions for the entire fs module
25 * @author Igor Wronsky, Christian Grothoff
30 #include "gnunet_constants.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_dht_service.h"
33 #include "gnunet_fs_service.h"
34 #include "gnunet_block_lib.h"
39 * Maximum number of outgoing messages we queue per peer.
41 * Performance measurements for 2 peer setup for 50 MB file
42 * (with MAX_DATASTORE_QUEUE = 1 and RETRY_PROBABILITY_INV = 1):
44 * 2: 1700 kb/s, 1372 kb/s
45 * 8: 2117 kb/s, 1284 kb/s, 1112 kb/s
46 * 16: 3500 kb/s, 3200 kb/s, 3388 kb/s
47 * 32: 3441 kb/s, 3163 kb/s, 3277 kb/s
48 * 128: 1700 kb/s; 2010 kb/s, 3383 kb/s, 1156 kb/s
50 * Conclusion: 16 seems to be a pretty good value (stable
51 * and high performance, no excessive memory use).
53 #define MAX_QUEUE_PER_PEER 16
56 * Maximum size of the datastore queue for P2P operations.
57 * Needs to be large enough to queue MAX_QUEUE_PER_PEER
58 * operations for roughly the number of active (connected)
61 #define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
64 * Maximum number of blocks we keep in memory for migration.
66 #define MAX_MIGRATION_QUEUE 32
69 * How many peers do we select as possible
70 * targets per block obtained for migration?
72 #define MIGRATION_LIST_SIZE 4
75 * To how many peers do we forward each migration block ultimately?
76 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
77 * a smaller value allows for variation in available bandwidth (for
78 * migration) between the peers.
80 #define MIGRATION_TARGET_COUNT 2
83 * Ratio for moving average delay calculation. The previous
84 * average goes in with a factor of (n-1) into the calculation.
87 #define RUNAVG_DELAY_N 16
90 * Size of the individual blocks used for file-sharing.
92 #define DBLOCK_SIZE (32*1024)
95 * Maximum legal size for a kblock.
97 #define MAX_KBLOCK_SIZE (60 * 1024)
100 * Maximum legal size for an sblock.
102 #define MAX_SBLOCK_SIZE (60 * 1024)
105 * Maximum legal size for an nblock.
107 #define MAX_NBLOCK_SIZE (60 * 1024)
110 * Pick a multiple of 2 here to achive 8-byte alignment!
111 * We also probably want DBlocks to have (roughly) the
112 * same size as IBlocks. With SHA-512, the optimal
113 * value is 32768 byte / 128 byte = 256
114 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
116 #define CHK_PER_INODE 256
120 * Maximum size for a file to be considered for
121 * inlining in a directory.
123 #define MAX_INLINE_SIZE 65536
127 * Blocksize to use when hashing files
128 * for indexing (blocksize for IO, not for
129 * the DBlocks). Larger blocksizes can
130 * be more efficient but will be more disruptive
131 * as far as the scheduler is concerned.
133 #define HASHING_BLOCKSIZE (1024 * 128)
136 * Number of bits we set per entry in the bloomfilter.
139 #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
142 * Number of availability trials we perform per search result.
144 #define AVAILABILITY_TRIALS_MAX 8
147 * Length of the P2P success tracker. Note that
148 * having a very long list can also hurt performance.
150 #define P2P_SUCCESS_LIST_SIZE 8
154 * Length of the CS-2-P success tracker. Note that
155 * having a very long list can also hurt performance.
157 #define CS2P_SUCCESS_LIST_SIZE 8
160 * How long are we willing to wait for the datastore to be ready to
161 * process a request for a query without priority?
163 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
167 * How long are we willing to wait for the core to be ready to
168 * transmit a reply to the target peer (if we can not transmit
169 * until then, we will discard the reply).
171 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
175 * Bandwidth value of an (effectively) 0-priority query.
177 #define QUERY_BANDWIDTH_VALUE 1
180 * Bandwidth value of a 0-priority content (must be
181 * fairly high compared to query since content is
182 * typically significantly larger -- and more valueable
183 * since it can take many queries to get one piece of
186 #define CONTENT_BANDWIDTH_VALUE 800
189 * By which amount do we decrement the TTL for simple forwarding /
190 * indirection of the query; in milli-seconds. Set somewhat in
191 * accordance to your network latency (above the time it'll take you
192 * to send a packet and get a reply).
194 #define TTL_DECREMENT 5000
197 * Until which load do we consider the peer idle and do not
198 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
199 * by the rest of the code)!
201 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
204 * Name of the directory with top-level searches.
206 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
209 * Name of the directory with sub-searches (namespace-updates).
211 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
214 * Name of the directory with master downloads (not associated
215 * with search or part of another download).
217 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
220 * Name of the directory with downloads that are part of another
221 * download or a search.
223 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
226 * Name of the directory with publishing operations.
228 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
231 * Name of the directory with files that are being published
233 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
236 * Name of the directory with unindex operations.
238 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
242 * @brief content hash key
244 struct ContentHashKey
247 * Hash of the original content, used for encryption.
252 * Hash of the encrypted content, used for querying.
254 GNUNET_HashCode query;
259 * @brief complete information needed
260 * to download a file.
262 struct FileIdentifier
266 * Total size of the file in bytes. (network byte order (!))
268 uint64_t file_length;
271 * Query and key of the top GNUNET_EC_IBlock.
273 struct ContentHashKey chk;
279 * Information about a file and its location
280 * (peer claiming to share the file).
285 * Information about the shared file.
287 struct FileIdentifier fi;
290 * Identity of the peer sharing the file.
292 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
295 * Time when this location URI expires.
297 struct GNUNET_TIME_Absolute expirationTime;
300 * RSA signature over the GNUNET_EC_FileIdentifier,
301 * GNUNET_hash of the peer and expiration time.
303 struct GNUNET_CRYPTO_RsaSignature contentSignature;
313 * Content-hash-key (simple file).
318 * Signed key space (file in namespace).
323 * Keyword search key (query with keywords).
328 * Location (chk with identity of hosting peer).
334 * A Universal Resource Identifier (URI), opaque.
348 * Keywords start with a '+' if they are
349 * mandatory (in which case the '+' is NOT
350 * part of the keyword) and with a
351 * simple space if they are optional
352 * (in which case the space is ALSO not
353 * part of the actual keyword).
355 * Double-quotes to protect spaces and
356 * %-encoding are NOT used internally
357 * (only in URI-strings).
362 * Size of the keywords array.
364 unsigned int keywordCount;
370 * Hash of the public key for the namespace.
372 GNUNET_HashCode namespace;
375 * Human-readable identifier chosen for this
376 * entry in the namespace.
382 * Information needed to retrieve a file (content-hash-key
385 struct FileIdentifier chk;
388 * Information needed to retrieve a file including signed
389 * location (identity of a peer) of the content.
398 * Information for a file or directory that is
399 * about to be published.
401 struct GNUNET_FS_FileInformation
405 * Files in a directory are kept as a linked list.
407 struct GNUNET_FS_FileInformation *next;
410 * If this is a file in a directory, "dir" refers to
411 * the directory; otherwise NULL.
413 struct GNUNET_FS_FileInformation *dir;
416 * Handle to the master context.
418 struct GNUNET_FS_Handle *h;
421 * Pointer kept for the client.
426 * Metadata to use for the file.
428 struct GNUNET_CONTAINER_MetaData *meta;
431 * Keywords to use for KBlocks.
433 struct GNUNET_FS_Uri *keywords;
436 * CHK for this file or directory. NULL if
437 * we have not yet computed it.
439 struct GNUNET_FS_Uri *chk_uri;
442 * At what time should the content expire?
444 struct GNUNET_TIME_Absolute expirationTime;
447 * At what time did we start this upload?
449 struct GNUNET_TIME_Absolute start_time;
452 * Under what filename is this struct serialized
453 * (for operational persistence). Should be determined
459 * Encoder being used to publish this file.
461 struct GNUNET_FS_TreeEncoder *te;
464 * Error message (non-NULL if this operation failed).
469 * Name of the file or directory (must be an absolute path).
474 * Data describing either the file or the directory.
485 * Function that can be used to read the data for the file.
487 GNUNET_FS_DataReader reader;
490 * Closure for reader.
495 * If this file is being indexed, this value is set to the hash
496 * over the entire file (when the indexing process is started).
497 * Otherwise this field is not used.
499 GNUNET_HashCode file_id;
502 * Size of the file (in bytes).
507 * Should the file be indexed or inserted?
512 * Is "file_id" already valid? Set to GNUNET_YES once the hash
513 * has been calculated.
518 * Has the service confirmed our INDEX_START request?
519 * GNUNET_YES if this step has been completed.
521 int index_start_confirmed;
526 * Data for a directory.
531 * Linked list of entries in the directory.
533 struct GNUNET_FS_FileInformation *entries;
536 * Size of the directory itself (in bytes); 0 if the
537 * size has not yet been calculated.
542 * Pointer to the data for the directory (or NULL if not
552 * Desired anonymity level.
557 * Desired priority (for keeping the content in the DB).
562 * Is this struct for a file or directory?
567 * Are we done publishing this file?
575 * The job is now ready to run and should use the given client
576 * handle to communicate with the FS service.
579 * @param client handle to use for FS communication
581 typedef void (*GNUNET_FS_QueueStart)(void *cls,
582 struct GNUNET_CLIENT_Connection *client);
586 * The job must now stop to run and should destry the client handle as
587 * soon as possible (ideally prior to returning).
589 typedef void (*GNUNET_FS_QueueStop)(void *cls);
593 * Entry in the job queue.
595 struct GNUNET_FS_QueueEntry
598 * This is a linked list.
600 struct GNUNET_FS_QueueEntry *next;
603 * This is a linked list.
605 struct GNUNET_FS_QueueEntry *prev;
608 * Function to call when the job is started.
610 GNUNET_FS_QueueStart start;
613 * Function to call when the job needs to stop (or is done / dequeued).
615 GNUNET_FS_QueueStop stop;
618 * Closure for start and stop.
623 * Handle to FS primary context.
625 struct GNUNET_FS_Handle *h;
628 * Client handle, or NULL if job is not running.
630 struct GNUNET_CLIENT_Connection *client;
633 * Time the job was originally queued.
635 struct GNUNET_TIME_Absolute queue_time;
638 * Time the job was started last.
640 struct GNUNET_TIME_Absolute start_time;
643 * Total amount of time the job has been running (except for the
646 struct GNUNET_TIME_Relative run_time;
649 * How many blocks do the active downloads have?
654 * How often have we (re)started this download?
656 unsigned int start_times;
664 * Information we store for each search result.
666 struct GNUNET_FS_SearchResult
670 * Search context this result belongs to.
672 struct GNUNET_FS_SearchContext *sc;
675 * URI to which this search result refers to.
677 struct GNUNET_FS_Uri *uri;
680 * Metadata for the search result.
682 struct GNUNET_CONTAINER_MetaData *meta;
685 * Client info for this search result.
690 * ID of a job that is currently probing this results' availability
691 * (NULL if we are not currently probing).
693 struct GNUNET_FS_DownloadContext *probe_ctx;
696 * ID of an associated download based on this search result (or
699 struct GNUNET_FS_DownloadContext *download;
702 * If this search result triggered an update search, this field
703 * links to the update search.
705 struct GNUNET_FS_SearchContext *update_search;
708 * Name under which this search result is stored on disk.
713 * Key for the search result
718 * ID of the task that will clean up the probe_ctx should it not
719 * complete on time (and that will need to be cancelled if we clean
720 * up the search result before then).
722 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
725 * When did the current probe become active?
727 struct GNUNET_TIME_Absolute probe_active_time;
730 * How much longer should we run the current probe before giving up?
732 struct GNUNET_TIME_Relative remaining_probe_time;
735 * Number of mandatory keywords for which we have NOT yet found the
736 * search result; when this value hits zero, the search result is
737 * given to the callback.
739 uint32_t mandatory_missing;
742 * Number of optional keywords under which this result was also
745 uint32_t optional_support;
748 * Number of availability tests that have succeeded for this result.
750 uint32_t availability_success;
753 * Number of availability trials that we have performed for this
756 uint32_t availability_trials;
762 * Add a job to the queue.
764 * @param h handle to the overall FS state
765 * @param start function to call to begin the job
766 * @param stop function to call to pause the job, or on dequeue (if the job was running)
767 * @param cls closure for start and stop
768 * @param blocks number of blocks this download has
769 * @return queue handle
771 struct GNUNET_FS_QueueEntry *
772 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
773 GNUNET_FS_QueueStart start,
774 GNUNET_FS_QueueStop stop,
776 unsigned int blocks);
780 * Dequeue a job from the queue.
781 * @param qh handle for the job
784 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
788 * Function that provides data by reading from a file.
790 * @param cls closure (points to the file information)
791 * @param offset offset to read from; it is possible
792 * that the caller might need to go backwards
794 * @param max maximum number of bytes that should be
795 * copied to buf; readers are not allowed
796 * to provide less data unless there is an error;
797 * a value of "0" will be used at the end to allow
798 * the reader to clean up its internal state
799 * @param buf where the reader should write the data
800 * @param emsg location for the reader to store an error message
801 * @return number of bytes written, usually "max", 0 on error
804 GNUNET_FS_data_reader_file_(void *cls,
812 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
814 * @param filename file to read
815 * @return closure to use
818 GNUNET_FS_make_file_reader_context_ (const char *filename);
823 * Function that provides data by copying from a buffer.
825 * @param cls closure (points to the buffer)
826 * @param offset offset to read from; it is possible
827 * that the caller might need to go backwards
829 * @param max maximum number of bytes that should be
830 * copied to buf; readers are not allowed
831 * to provide less data unless there is an error;
832 * a value of "0" will be used at the end to allow
833 * the reader to clean up its internal state
834 * @param buf where the reader should write the data
835 * @param emsg location for the reader to store an error message
836 * @return number of bytes written, usually "max", 0 on error
839 GNUNET_FS_data_reader_copy_(void *cls,
846 * Notification of FS that a search probe has made progress.
847 * This function is used INSTEAD of the client's event handler
848 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
850 * @param cls closure, always NULL (!), actual closure
851 * is in the client-context of the info struct
852 * @param info details about the event, specifying the event type
853 * and various bits about the event
854 * @return client-context (for the next progress call
855 * for this operation; should be set to NULL for
856 * SUSPEND and STOPPED events). The value returned
857 * will be passed to future callbacks in the respective
858 * field in the GNUNET_FS_ProgressInfo struct.
861 GNUNET_FS_search_probe_progress_ (void *cls,
862 const struct GNUNET_FS_ProgressInfo *info);
866 * Main function that performs the upload.
868 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
869 * @param tc task context
872 GNUNET_FS_publish_main_ (void *cls,
873 const struct GNUNET_SCHEDULER_TaskContext *tc);
877 * Function called once the hash of the file
878 * that is being unindexed has been computed.
880 * @param cls closure, unindex context
881 * @param file_id computed hash, NULL on error
884 GNUNET_FS_unindex_process_hash_ (void *cls,
885 const GNUNET_HashCode *file_id);
889 * Fill in all of the generic fields for a publish event and call the
892 * @param pi structure to fill in
893 * @param sc overall publishing context
894 * @param p file information for the file being published
895 * @param offset where in the file are we so far
896 * @return value returned from callback
899 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
900 struct GNUNET_FS_PublishContext *sc,
901 const struct GNUNET_FS_FileInformation *p,
906 * Fill in all of the generic fields for a download event and call the
909 * @param pi structure to fill in
910 * @param dc overall download context
913 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
914 struct GNUNET_FS_DownloadContext *dc);
918 * Fill in all of the generic fields for
919 * an unindex event and call the callback.
921 * @param pi structure to fill in
922 * @param uc overall unindex context
923 * @param offset where we are in the file (for progress)
926 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
927 struct GNUNET_FS_UnindexContext *uc,
931 * Fill in all of the generic fields for a search event and
934 * @param pi structure to fill in
935 * @param sc overall search context
936 * @return value returned by the callback
939 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
940 struct GNUNET_FS_SearchContext *sc);
944 * Connect to the datastore and remove the blocks.
946 * @param uc context for the unindex operation.
949 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
952 * Build the request and actually initiate the search using the
955 * @param sc search context
956 * @return GNUNET_OK on success, GNUNET_SYSERR on error
959 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
962 * Start the downloading process (by entering the queue).
964 * @param dc our download context
967 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
971 * Start download probes for the given search result.
973 * @param sr the search result
976 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
979 * Remove serialization/deserialization file from disk.
981 * @param h master context
982 * @param ext component of the path
983 * @param ent entity identifier
986 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
992 * Remove serialization/deserialization directory from disk.
994 * @param h master context
995 * @param ext component of the path
996 * @param uni unique name of parent
999 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
1005 * Synchronize this file-information struct with its mirror
1006 * on disk. Note that all internal FS-operations that change
1007 * file information data should already call "sync" internally,
1008 * so this function is likely not useful for clients.
1010 * @param fi the struct to sync
1013 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1016 * Synchronize this publishing struct with its mirror
1017 * on disk. Note that all internal FS-operations that change
1018 * publishing structs should already call "sync" internally,
1019 * so this function is likely not useful for clients.
1021 * @param pc the struct to sync
1024 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1027 * Synchronize this unindex struct with its mirror
1028 * on disk. Note that all internal FS-operations that change
1029 * publishing structs should already call "sync" internally,
1030 * so this function is likely not useful for clients.
1032 * @param uc the struct to sync
1035 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1038 * Synchronize this search struct with its mirror
1039 * on disk. Note that all internal FS-operations that change
1040 * publishing structs should already call "sync" internally,
1041 * so this function is likely not useful for clients.
1043 * @param sc the struct to sync
1046 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1049 * Synchronize this search result with its mirror
1050 * on disk. Note that all internal FS-operations that change
1051 * publishing structs should already call "sync" internally,
1052 * so this function is likely not useful for clients.
1054 * @param sr the struct to sync
1057 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1060 * Synchronize this download struct with its mirror
1061 * on disk. Note that all internal FS-operations that change
1062 * publishing structs should already call "sync" internally,
1063 * so this function is likely not useful for clients.
1065 * @param dc the struct to sync
1068 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1071 * Create SUSPEND event for the given publish operation
1072 * and then clean up our state (without stop signal).
1074 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1077 GNUNET_FS_publish_signal_suspend_ (void *cls);
1080 * Create SUSPEND event for the given search operation
1081 * and then clean up our state (without stop signal).
1083 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1086 GNUNET_FS_search_signal_suspend_ (void *cls);
1089 * Create SUSPEND event for the given download operation
1090 * and then clean up our state (without stop signal).
1092 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1095 GNUNET_FS_download_signal_suspend_ (void *cls);
1098 * Create SUSPEND event for the given unindex operation
1099 * and then clean up our state (without stop signal).
1101 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1104 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1107 * Function signature of the functions that can be called
1108 * to trigger suspend signals and clean-up for top-level
1111 * @param cls closure
1113 typedef void (*SuspendSignalFunction)(void *cls);
1116 * We track all of the top-level activities of FS
1117 * so that we can signal 'suspend' on shutdown.
1119 struct TopLevelActivity
1122 * This is a doubly-linked list.
1124 struct TopLevelActivity *next;
1127 * This is a doubly-linked list.
1129 struct TopLevelActivity *prev;
1132 * Function to call for suspend-signalling and clean up.
1134 SuspendSignalFunction ssf;
1137 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1144 * Create a top-level activity entry.
1146 * @param h global fs handle
1147 * @param ssf suspend signal function to use
1148 * @param ssf_cls closure for ssf
1149 * @return fresh top-level activity handle
1151 struct TopLevelActivity *
1152 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1153 SuspendSignalFunction ssf,
1158 * Destroy a top-level activity entry.
1160 * @param h global fs handle
1161 * @param top top level activity entry
1164 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1165 struct TopLevelActivity *top);
1170 * Master context for most FS operations.
1172 struct GNUNET_FS_Handle
1175 * Configuration to use.
1177 const struct GNUNET_CONFIGURATION_Handle *cfg;
1180 * Name of our client.
1185 * Function to call with updates on our progress.
1187 GNUNET_FS_ProgressCallback upcb;
1195 * Head of DLL of top-level activities.
1197 struct TopLevelActivity *top_head;
1200 * Tail of DLL of top-level activities.
1202 struct TopLevelActivity *top_tail;
1205 * Head of DLL of running jobs.
1207 struct GNUNET_FS_QueueEntry *running_head;
1210 * Tail of DLL of running jobs.
1212 struct GNUNET_FS_QueueEntry *running_tail;
1215 * Head of DLL of pending jobs.
1217 struct GNUNET_FS_QueueEntry *pending_head;
1220 * Tail of DLL of pending jobs.
1222 struct GNUNET_FS_QueueEntry *pending_tail;
1225 * Task that processes the jobs in the running and pending queues
1226 * (and moves jobs around as needed).
1228 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1231 * Average time we take for a single request to be satisfied.
1232 * FIXME: not yet calcualted properly...
1234 struct GNUNET_TIME_Relative avg_block_latency;
1237 * How many actual downloads do we have running right now?
1239 unsigned int active_downloads;
1242 * How many blocks do the active downloads have?
1244 unsigned int active_blocks;
1249 enum GNUNET_FS_Flags flags;
1252 * Maximum number of parallel downloads.
1254 unsigned int max_parallel_downloads;
1257 * Maximum number of parallel requests.
1259 unsigned int max_parallel_requests;
1265 * Handle for controlling a publication process.
1267 struct GNUNET_FS_PublishContext
1270 * Handle to the global fs context.
1272 struct GNUNET_FS_Handle *h;
1275 * Our top-level activity entry (if we are top-level, otherwise NULL).
1277 struct TopLevelActivity *top;
1280 * File-structure that is being shared.
1282 struct GNUNET_FS_FileInformation *fi;
1285 * Namespace that we are publishing in, NULL if we have no namespace.
1287 struct GNUNET_FS_Namespace *namespace;
1290 * ID of the content in the namespace, NULL if we have no namespace.
1295 * ID for future updates, NULL if we have no namespace or no updates.
1300 * Filename used for serializing information about this operation
1301 * (should be determined using 'mktemp').
1303 char *serialization;
1306 * Our own client handle for the FS service; only briefly used when
1307 * we start to index a file, otherwise NULL.
1309 struct GNUNET_CLIENT_Connection *client;
1312 * Current position in the file-tree for the upload.
1314 struct GNUNET_FS_FileInformation *fi_pos;
1317 * Non-null if we are currently hashing a file.
1319 struct GNUNET_CRYPTO_FileHashContext *fhc;
1322 * Connection to the datastore service.
1324 struct GNUNET_DATASTORE_Handle *dsh;
1327 * Queue entry for reservation/unreservation.
1329 struct GNUNET_DATASTORE_QueueEntry *qre;
1332 * ID of the task performing the upload. NO_TASK if the upload has
1335 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1338 * Storage space to reserve for the operation.
1340 uint64_t reserve_space;
1343 * Overall number of entries to reserve for the
1344 * publish operation.
1346 uint32_t reserve_entries;
1349 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1350 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1351 * the datastore service (in which case this struct must not be
1352 * freed until we have that response). If someone tries to stop the
1353 * download for good during this period, "in_network_wait" is set to
1354 * GNUNET_SYSERR which will cause the struct to be destroyed right
1355 * after we have the reply (or timeout) from the datastore service.
1357 int in_network_wait;
1360 * Options for publishing.
1362 enum GNUNET_FS_PublishOptions options;
1365 * Space reservation ID with datastore service
1371 * Set to GNUNET_YES if all processing has completed.
1378 * Phases of unindex processing (state machine).
1383 * We're currently hashing the file.
1385 UNINDEX_STATE_HASHING = 0,
1388 * We're telling the datastore to delete
1389 * the respective entries.
1391 UNINDEX_STATE_DS_REMOVE = 1,
1394 * We're notifying the FS service about
1397 UNINDEX_STATE_FS_NOTIFY = 2,
1402 UNINDEX_STATE_COMPLETE = 3,
1405 * We've encountered a fatal error.
1407 UNINDEX_STATE_ERROR = 4
1413 * Handle for controlling an unindexing operation.
1415 struct GNUNET_FS_UnindexContext
1419 * Global FS context.
1421 struct GNUNET_FS_Handle *h;
1424 * Our top-level activity entry.
1426 struct TopLevelActivity *top;
1429 * Name of the file that we are unindexing.
1434 * Short name under which we are serializing the state of this operation.
1436 char *serialization;
1439 * Connection to the FS service, only valid during the
1440 * UNINDEX_STATE_FS_NOTIFY phase.
1442 struct GNUNET_CLIENT_Connection *client;
1445 * Connection to the datastore service, only valid during the
1446 * UNINDEX_STATE_DS_NOTIFY phase.
1448 struct GNUNET_DATASTORE_Handle *dsh;
1451 * Pointer kept for the client.
1456 * Merkle-ish tree encoder context.
1458 struct GNUNET_FS_TreeEncoder *tc;
1461 * Handle used to read the file.
1463 struct GNUNET_DISK_FileHandle *fh;
1466 * Error message, NULL on success.
1471 * Context for hashing of the file.
1473 struct GNUNET_CRYPTO_FileHashContext *fhc;
1476 * Overall size of the file.
1481 * When did we start?
1483 struct GNUNET_TIME_Absolute start_time;
1486 * Hash of the file's contents (once computed).
1488 GNUNET_HashCode file_id;
1491 * Current operatinonal phase.
1493 enum UnindexState state;
1499 * Information we keep for each keyword in
1502 struct SearchRequestEntry
1505 * Hash of the original keyword, also known as the
1506 * key (for decrypting the KBlock).
1508 GNUNET_HashCode key;
1511 * Hash of the public key, also known as the query.
1513 GNUNET_HashCode query;
1516 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1517 * was found under this keyword. Note that the entries will point
1518 * to the same locations as those in the master result map (in
1519 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1520 * The key for each entry is the XOR of the key and query in the CHK
1521 * URI (as a unique identifier for the search result).
1523 struct GNUNET_CONTAINER_MultiHashMap *results;
1526 * Is this keyword a mandatory keyword
1527 * (started with '+')?
1535 * Handle for controlling a search.
1537 struct GNUNET_FS_SearchContext
1540 * Handle to the global FS context.
1542 struct GNUNET_FS_Handle *h;
1545 * Our top-level activity entry (if we are top-level, otherwise NULL).
1547 struct TopLevelActivity *top;
1550 * List of keywords that we're looking for.
1552 struct GNUNET_FS_Uri *uri;
1555 * For update-searches, link to the search result that triggered
1556 * the update search; otherwise NULL.
1558 struct GNUNET_FS_SearchResult *psearch_result;
1561 * Connection to the FS service.
1563 struct GNUNET_CLIENT_Connection *client;
1566 * Pointer we keep for the client.
1571 * Name of the file on disk we use for persistence.
1573 char *serialization;
1576 * Error message (non-NULL if this operation failed).
1581 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1582 * was found in the search. The key for each entry is the XOR of
1583 * the key and query in the CHK URI (as a unique identifier for the
1586 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1589 * Per-keyword information for a keyword search. This array will
1590 * have exactly as many entries as there were keywords.
1592 struct SearchRequestEntry *requests;
1595 * When did we start?
1597 struct GNUNET_TIME_Absolute start_time;
1600 * ID of a task that is using this struct and that must be cancelled
1601 * when the search is being stopped (if not
1602 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1603 * artificial delay when trying to reconnect to the FS service.
1605 GNUNET_SCHEDULER_TaskIdentifier task;
1608 * Anonymity level for the search.
1613 * Number of mandatory keywords in this query.
1615 uint32_t mandatory_count;
1618 * Options for the search.
1620 enum GNUNET_FS_SearchOptions options;
1625 * Information about an active download request.
1627 struct DownloadRequest
1630 * While pending, we keep all download requests in a linked list.
1632 struct DownloadRequest *next;
1635 * CHK for the request.
1637 struct ContentHashKey chk;
1640 * Offset of the corresponding block.
1645 * Depth of the corresponding block in the tree.
1650 * Set if this request is currently in the linked list of pending
1651 * requests. Needed in case we get a response for a request that we
1652 * have not yet send (i.e. due to two blocks with identical
1653 * content); in this case, we would need to remove the block from
1654 * the pending list (and need a fast way to check if the block is on
1663 * Context for controlling a download.
1665 struct GNUNET_FS_DownloadContext
1669 * Global FS context.
1671 struct GNUNET_FS_Handle *h;
1674 * Our top-level activity entry (if we are top-level, otherwise NULL).
1676 struct TopLevelActivity *top;
1679 * Connection to the FS service.
1681 struct GNUNET_CLIENT_Connection *client;
1684 * Parent download (used when downloading files
1687 struct GNUNET_FS_DownloadContext *parent;
1690 * Associated search (used when downloading files
1691 * based on search results), or NULL for none.
1693 struct GNUNET_FS_SearchResult *search;
1696 * Head of list of child downloads.
1698 struct GNUNET_FS_DownloadContext *child_head;
1701 * Tail of list of child downloads.
1703 struct GNUNET_FS_DownloadContext *child_tail;
1706 * Previous download belonging to the same parent.
1708 struct GNUNET_FS_DownloadContext *prev;
1711 * Next download belonging to the same parent.
1713 struct GNUNET_FS_DownloadContext *next;
1716 * Context kept for the client.
1721 * URI that identifies the file that
1722 * we are downloading.
1724 struct GNUNET_FS_Uri *uri;
1727 * Known meta-data for the file (can be NULL).
1729 struct GNUNET_CONTAINER_MetaData *meta;
1732 * Error message, NULL if we're doing OK.
1737 * Random portion of filename we use for syncing state of this
1740 char *serialization;
1743 * Where are we writing the data (name of the
1744 * file, can be NULL!).
1749 * Where are we writing the data temporarily (name of the
1750 * file, can be NULL!); used if we do not have a permanent
1751 * name and we are a directory and we do a recursive download.
1753 char *temp_filename;
1756 * Map of active requests (those waiting
1757 * for a response). The key is the hash
1758 * of the encryped block (aka query).
1760 struct GNUNET_CONTAINER_MultiHashMap *active;
1763 * Linked list of pending requests.
1765 struct DownloadRequest *pending;
1768 * Non-NULL if we are currently having a request for
1769 * transmission pending with the client handle.
1771 struct GNUNET_CLIENT_TransmitHandle *th;
1774 * Our entry in the job queue.
1776 struct GNUNET_FS_QueueEntry *job_queue;
1779 * Identity of the peer having the content, or all-zeros
1780 * if we don't know of such a peer.
1782 struct GNUNET_PeerIdentity target;
1785 * ID of a task that is using this struct
1786 * and that must be cancelled when the download
1787 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1788 * Used for the task that adds some artificial
1789 * delay when trying to reconnect to the FS
1792 GNUNET_SCHEDULER_TaskIdentifier task;
1795 * What was the size of the file on disk that we're downloading
1796 * before we started? Used to detect if there is a point in
1797 * checking an existing block on disk for matching the desired
1798 * content. 0 if the file did not exist already.
1800 uint64_t old_file_size;
1803 * What is the first offset that we're interested
1809 * How many bytes starting from offset are desired?
1810 * This is NOT the overall length of the file!
1815 * How many bytes have we already received within
1816 * the specified range (DBlocks only).
1821 * Time download was started.
1823 struct GNUNET_TIME_Absolute start_time;
1826 * Desired level of anonymity.
1831 * The depth of the file-tree.
1833 unsigned int treedepth;
1836 * Options for the download.
1838 enum GNUNET_FS_DownloadOptions options;
1841 * Flag set upon transitive completion (includes child downloads).
1842 * This flag is only set to GNUNET_YES for directories where all
1843 * child-downloads have also completed (and signalled completion).
1848 * Have we tried (and failed) to find matching full
1849 * data from the meta data yet?
1851 int tried_full_data;
1856 * Information about an (updateable) node in the
1859 struct NamespaceUpdateNode
1862 * Identifier for this node.
1867 * Identifier of children of this node.
1872 * Metadata for this entry.
1874 struct GNUNET_CONTAINER_MetaData *md;
1877 * URI of this entry in the namespace.
1879 struct GNUNET_FS_Uri *uri;
1882 * Namespace update generation ID. Used to ensure
1883 * freshness of the scc_id.
1888 * SCC this entry belongs to (if nug is current).
1890 unsigned int scc_id;
1895 struct GNUNET_FS_Namespace
1899 * Handle to the FS service context.
1901 struct GNUNET_FS_Handle *h;
1904 * Array with information about nodes in the namespace.
1906 struct NamespaceUpdateNode **update_nodes;
1909 * Private key for the namespace.
1911 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1914 * Hash map mapping identifiers of update nodes
1915 * to the update nodes (initialized on-demand).
1917 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1920 * Name of the file with the private key.
1925 * Name of the namespace.
1930 * Size of the update nodes array.
1932 unsigned int update_node_count;
1935 * Reference counter.
1940 * Generator for unique nug numbers.
1942 unsigned int nug_gen;
1947 * Message sent from a GNUnet (fs) publishing activity to the
1948 * gnunet-fs-service to initiate indexing of a file. The service is
1949 * supposed to check if the specified file is available and has the
1950 * same cryptographic hash. It should then respond with either a
1951 * confirmation or a denial.
1953 * On OSes where this works, it is considered acceptable if the
1954 * service only checks that the path, device and inode match (it can
1955 * then be assumed that the hash will also match without actually
1956 * computing it; this is an optimization that should be safe given
1957 * that the client is not our adversary).
1959 struct IndexStartMessage
1963 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1965 struct GNUNET_MessageHeader header;
1970 uint32_t reserved GNUNET_PACKED;
1973 * ID of device containing the file, as seen by the client. This
1974 * device ID is obtained using a call like "statvfs" (and converting
1975 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1976 * OS does not support this, in which case the service must do a
1977 * full hash recomputation.
1979 uint64_t device GNUNET_PACKED;
1982 * Inode of the file on the given device, as seen by the client
1983 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1984 * support this, in which case the service must do a full hash
1987 uint64_t inode GNUNET_PACKED;
1990 * Hash of the file that we would like to index.
1992 GNUNET_HashCode file_id;
1994 /* this is followed by a 0-terminated
1995 filename of a file with the hash
1996 "file_id" as seen by the client */
2002 * Message send by FS service in response to a request
2003 * asking for a list of all indexed files.
2005 struct IndexInfoMessage
2008 * Message type will be
2009 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
2011 struct GNUNET_MessageHeader header;
2016 uint32_t reserved GNUNET_PACKED;
2019 * Hash of the indexed file.
2021 GNUNET_HashCode file_id;
2023 /* this is followed by a 0-terminated
2024 filename of a file with the hash
2025 "file_id" as seen by the client */
2031 * Message sent from a GNUnet (fs) unindexing activity to the
2032 * gnunet-service-fs to indicate that a file will be unindexed. The
2033 * service is supposed to remove the file from the list of indexed
2034 * files and response with a confirmation message (even if the file
2035 * was already not on the list).
2037 struct UnindexMessage
2041 * Message type will be
2042 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2044 struct GNUNET_MessageHeader header;
2049 uint32_t reserved GNUNET_PACKED;
2052 * Hash of the file that we will unindex.
2054 GNUNET_HashCode file_id;
2060 * Message sent from a GNUnet (fs) search activity to the
2061 * gnunet-service-fs to start a search.
2063 struct SearchMessage
2067 * Message type will be
2068 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2070 struct GNUNET_MessageHeader header;
2073 * Bitmask with options. Zero for no options, one for loopback-only.
2074 * Other bits are currently not defined.
2076 int32_t options GNUNET_PACKED;
2079 * Type of the content that we're looking for.
2081 uint32_t type GNUNET_PACKED;
2084 * Desired anonymity level, big-endian.
2086 uint32_t anonymity_level GNUNET_PACKED;
2089 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2090 * the peer that is known to have a response. Set to all-zeros if
2091 * such a target is not known (note that even if OUR anonymity
2092 * level is >0 we may happen to know the responder's identity;
2093 * nevertheless, we should probably not use it for a DHT-lookup
2094 * or similar blunt actions in order to avoid exposing ourselves).
2096 * If the request is for an SBLOCK, this is the identity of the
2097 * pseudonym to which the SBLOCK belongs.
2099 * If the request is for a KBLOCK, "target" must be all zeros.
2101 GNUNET_HashCode target;
2104 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2105 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2106 * and hash of the identifier XORed with the target for
2107 * SBLOCKS (aka query).
2109 GNUNET_HashCode query;
2111 /* this is followed by the hash codes of already-known
2112 results (which should hence be excluded from what
2113 the service returns); naturally, this only applies
2114 to queries that can have multiple results, such as
2115 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2120 * Only the (mandatory) query is included.
2122 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2125 * The peer identity of a peer waiting for the
2126 * reply is included (used if the response
2127 * should be transmitted to someone other than
2128 * the sender of the GET).
2130 #define GET_MESSAGE_BIT_RETURN_TO 1
2133 * The hash of the public key of the target
2134 * namespace is included (for SKS queries).
2136 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2139 * The peer identity of a peer that had claimed to have the content
2140 * previously is included (can be used if responder-anonymity is not
2141 * desired; note that the precursor presumably lacked a direct
2142 * connection to the specified peer; still, the receiver is in no way
2143 * required to limit forwarding only to the specified peer, it should
2144 * only prefer it somewhat if possible).
2146 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2150 * Message sent between peers asking for FS-content.
2156 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2158 struct GNUNET_MessageHeader header;
2161 * Type of the query (block type).
2163 uint32_t type GNUNET_PACKED;
2166 * How important is this request (network byte order)
2168 uint32_t priority GNUNET_PACKED;
2171 * Relative time to live in MILLISECONDS (network byte order)
2173 int32_t ttl GNUNET_PACKED;
2176 * The content hash should be mutated using this value
2177 * before checking against the bloomfilter (used to
2178 * get many different filters for the same hash codes).
2179 * The number should be in big-endian format when used
2182 int32_t filter_mutator GNUNET_PACKED;
2185 * Which of the optional hash codes are present at the end of the
2186 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2187 * set, an additional GNUNET_HashCode with the respective content
2188 * (in order of the bits) will be appended to the end of the GET
2191 uint32_t hash_bitmap GNUNET_PACKED;
2194 * Hashcodes of the file(s) we're looking for.
2195 * Details depend on the query type.
2197 GNUNET_HashCode query GNUNET_PACKED;
2199 /* this is followed by hash codes
2200 as specified in the "hash_bitmap";
2201 after that, an optional bloomfilter
2202 (with bits set for replies that should
2203 be suppressed) can be present */
2208 * Response from FS service with a result for a previous FS search.
2209 * Note that queries for DBLOCKS and IBLOCKS that have received a
2210 * single response are considered done. This message is transmitted
2211 * between peers as well as between the service and a client.
2217 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2219 struct GNUNET_MessageHeader header;
2222 * Type of the block (in big endian). Should never be zero.
2224 uint32_t type GNUNET_PACKED;
2227 * When does this result expire?
2229 struct GNUNET_TIME_AbsoluteNBO expiration;
2231 /* this is followed by the actual encrypted content */
2237 * Message send by a peer that wants to be excluded
2238 * from migration for a while.
2240 struct MigrationStopMessage
2243 * Message type will be
2244 * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2246 struct GNUNET_MessageHeader header;
2251 uint32_t reserved GNUNET_PACKED;
2254 * How long should the block last?
2256 struct GNUNET_TIME_RelativeNBO duration;