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 #define MAX_QUEUE_PER_PEER 16
44 * Maximum size of the datastore queue for P2P operations.
45 * Needs to be large enough to queue MAX_QUEUE_PER_PEER
46 * operations for roughly the number of active (connected)
49 #define MAX_DATASTORE_QUEUE (16 * MAX_QUEUE_PER_PEER)
52 * Maximum number of blocks we keep in memory for migration.
54 #define MAX_MIGRATION_QUEUE 32
57 * How many peers do we select as possible
58 * targets per block obtained for migration?
60 #define MIGRATION_LIST_SIZE 4
63 * To how many peers do we forward each migration block ultimately?
64 * This number must be smaller or equal to MIGRATION_LIST_SIZE. Using
65 * a smaller value allows for variation in available bandwidth (for
66 * migration) between the peers.
68 #define MIGRATION_TARGET_COUNT 2
71 * Ratio for moving average delay calculation. The previous
72 * average goes in with a factor of (n-1) into the calculation.
75 #define RUNAVG_DELAY_N 16
78 * Size of the individual blocks used for file-sharing.
80 #define DBLOCK_SIZE (32*1024)
83 * Maximum legal size for a kblock.
85 #define MAX_KBLOCK_SIZE (60 * 1024)
88 * Maximum legal size for an sblock.
90 #define MAX_SBLOCK_SIZE (60 * 1024)
93 * Maximum legal size for an nblock.
95 #define MAX_NBLOCK_SIZE (60 * 1024)
98 * Pick a multiple of 2 here to achive 8-byte alignment!
99 * We also probably want DBlocks to have (roughly) the
100 * same size as IBlocks. With SHA-512, the optimal
101 * value is 32768 byte / 128 byte = 256
102 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
104 #define CHK_PER_INODE 256
108 * Maximum size for a file to be considered for
109 * inlining in a directory.
111 #define MAX_INLINE_SIZE 65536
115 * Blocksize to use when hashing files
116 * for indexing (blocksize for IO, not for
117 * the DBlocks). Larger blocksizes can
118 * be more efficient but will be more disruptive
119 * as far as the scheduler is concerned.
121 #define HASHING_BLOCKSIZE (1024 * 128)
124 * Number of bits we set per entry in the bloomfilter.
127 #define BLOOMFILTER_K GNUNET_DHT_GET_BLOOMFILTER_K
130 * Number of availability trials we perform per search result.
132 #define AVAILABILITY_TRIALS_MAX 8
135 * Length of the P2P success tracker. Note that
136 * having a very long list can also hurt performance.
138 #define P2P_SUCCESS_LIST_SIZE 8
142 * Length of the CS-2-P success tracker. Note that
143 * having a very long list can also hurt performance.
145 #define CS2P_SUCCESS_LIST_SIZE 8
148 * How long are we willing to wait for the datastore to be ready to
149 * process a request for a query without priority?
151 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
155 * How long are we willing to wait for the core to be ready to
156 * transmit a reply to the target peer (if we can not transmit
157 * until then, we will discard the reply).
159 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
163 * Bandwidth value of an (effectively) 0-priority query.
165 #define QUERY_BANDWIDTH_VALUE 1
168 * Bandwidth value of a 0-priority content (must be
169 * fairly high compared to query since content is
170 * typically significantly larger -- and more valueable
171 * since it can take many queries to get one piece of
174 #define CONTENT_BANDWIDTH_VALUE 800
177 * By which amount do we decrement the TTL for simple forwarding /
178 * indirection of the query; in milli-seconds. Set somewhat in
179 * accordance to your network latency (above the time it'll take you
180 * to send a packet and get a reply).
182 #define TTL_DECREMENT 5000
185 * Until which load do we consider the peer idle and do not
186 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
187 * by the rest of the code)!
189 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
192 * Name of the directory with top-level searches.
194 #define GNUNET_FS_SYNC_PATH_MASTER_SEARCH "search"
197 * Name of the directory with sub-searches (namespace-updates).
199 #define GNUNET_FS_SYNC_PATH_CHILD_SEARCH "search-child"
202 * Name of the directory with master downloads (not associated
203 * with search or part of another download).
205 #define GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD "download"
208 * Name of the directory with downloads that are part of another
209 * download or a search.
211 #define GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD "download-child"
214 * Name of the directory with publishing operations.
216 #define GNUNET_FS_SYNC_PATH_MASTER_PUBLISH "publish"
219 * Name of the directory with files that are being published
221 #define GNUNET_FS_SYNC_PATH_FILE_INFO "publish-file"
224 * Name of the directory with unindex operations.
226 #define GNUNET_FS_SYNC_PATH_MASTER_UNINDEX "unindex"
230 * @brief content hash key
232 struct ContentHashKey
235 * Hash of the original content, used for encryption.
240 * Hash of the encrypted content, used for querying.
242 GNUNET_HashCode query;
247 * @brief complete information needed
248 * to download a file.
250 struct FileIdentifier
254 * Total size of the file in bytes. (network byte order (!))
256 uint64_t file_length;
259 * Query and key of the top GNUNET_EC_IBlock.
261 struct ContentHashKey chk;
267 * Information about a file and its location
268 * (peer claiming to share the file).
273 * Information about the shared file.
275 struct FileIdentifier fi;
278 * Identity of the peer sharing the file.
280 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
283 * Time when this location URI expires.
285 struct GNUNET_TIME_Absolute expirationTime;
288 * RSA signature over the GNUNET_EC_FileIdentifier,
289 * GNUNET_hash of the peer and expiration time.
291 struct GNUNET_CRYPTO_RsaSignature contentSignature;
301 * Content-hash-key (simple file).
306 * Signed key space (file in namespace).
311 * Keyword search key (query with keywords).
316 * Location (chk with identity of hosting peer).
322 * A Universal Resource Identifier (URI), opaque.
336 * Keywords start with a '+' if they are
337 * mandatory (in which case the '+' is NOT
338 * part of the keyword) and with a
339 * simple space if they are optional
340 * (in which case the space is ALSO not
341 * part of the actual keyword).
343 * Double-quotes to protect spaces and
344 * %-encoding are NOT used internally
345 * (only in URI-strings).
350 * Size of the keywords array.
352 unsigned int keywordCount;
358 * Hash of the public key for the namespace.
360 GNUNET_HashCode namespace;
363 * Human-readable identifier chosen for this
364 * entry in the namespace.
370 * Information needed to retrieve a file (content-hash-key
373 struct FileIdentifier chk;
376 * Information needed to retrieve a file including signed
377 * location (identity of a peer) of the content.
386 * Information for a file or directory that is
387 * about to be published.
389 struct GNUNET_FS_FileInformation
393 * Files in a directory are kept as a linked list.
395 struct GNUNET_FS_FileInformation *next;
398 * If this is a file in a directory, "dir" refers to
399 * the directory; otherwise NULL.
401 struct GNUNET_FS_FileInformation *dir;
404 * Handle to the master context.
406 struct GNUNET_FS_Handle *h;
409 * Pointer kept for the client.
414 * Metadata to use for the file.
416 struct GNUNET_CONTAINER_MetaData *meta;
419 * Keywords to use for KBlocks.
421 struct GNUNET_FS_Uri *keywords;
424 * CHK for this file or directory. NULL if
425 * we have not yet computed it.
427 struct GNUNET_FS_Uri *chk_uri;
430 * At what time should the content expire?
432 struct GNUNET_TIME_Absolute expirationTime;
435 * At what time did we start this upload?
437 struct GNUNET_TIME_Absolute start_time;
440 * Under what filename is this struct serialized
441 * (for operational persistence). Should be determined
447 * Encoder being used to publish this file.
449 struct GNUNET_FS_TreeEncoder *te;
452 * Error message (non-NULL if this operation failed).
457 * Name of the file or directory (must be an absolute path).
462 * Data describing either the file or the directory.
473 * Function that can be used to read the data for the file.
475 GNUNET_FS_DataReader reader;
478 * Closure for reader.
483 * If this file is being indexed, this value is set to the hash
484 * over the entire file (when the indexing process is started).
485 * Otherwise this field is not used.
487 GNUNET_HashCode file_id;
490 * Size of the file (in bytes).
495 * Should the file be indexed or inserted?
500 * Is "file_id" already valid? Set to GNUNET_YES once the hash
501 * has been calculated.
506 * Has the service confirmed our INDEX_START request?
507 * GNUNET_YES if this step has been completed.
509 int index_start_confirmed;
514 * Data for a directory.
519 * Linked list of entries in the directory.
521 struct GNUNET_FS_FileInformation *entries;
524 * Size of the directory itself (in bytes); 0 if the
525 * size has not yet been calculated.
530 * Pointer to the data for the directory (or NULL if not
540 * Desired anonymity level.
545 * Desired priority (for keeping the content in the DB).
550 * Is this struct for a file or directory?
555 * Are we done publishing this file?
563 * The job is now ready to run and should use the given client
564 * handle to communicate with the FS service.
567 * @param client handle to use for FS communication
569 typedef void (*GNUNET_FS_QueueStart)(void *cls,
570 struct GNUNET_CLIENT_Connection *client);
574 * The job must now stop to run and should destry the client handle as
575 * soon as possible (ideally prior to returning).
577 typedef void (*GNUNET_FS_QueueStop)(void *cls);
581 * Entry in the job queue.
583 struct GNUNET_FS_QueueEntry
586 * This is a linked list.
588 struct GNUNET_FS_QueueEntry *next;
591 * This is a linked list.
593 struct GNUNET_FS_QueueEntry *prev;
596 * Function to call when the job is started.
598 GNUNET_FS_QueueStart start;
601 * Function to call when the job needs to stop (or is done / dequeued).
603 GNUNET_FS_QueueStop stop;
606 * Closure for start and stop.
611 * Handle to FS primary context.
613 struct GNUNET_FS_Handle *h;
616 * Client handle, or NULL if job is not running.
618 struct GNUNET_CLIENT_Connection *client;
621 * Time the job was originally queued.
623 struct GNUNET_TIME_Absolute queue_time;
626 * Time the job was started last.
628 struct GNUNET_TIME_Absolute start_time;
631 * Total amount of time the job has been running (except for the
634 struct GNUNET_TIME_Relative run_time;
637 * How many blocks do the active downloads have?
642 * How often have we (re)started this download?
644 unsigned int start_times;
652 * Information we store for each search result.
654 struct GNUNET_FS_SearchResult
658 * Search context this result belongs to.
660 struct GNUNET_FS_SearchContext *sc;
663 * URI to which this search result refers to.
665 struct GNUNET_FS_Uri *uri;
668 * Metadata for the search result.
670 struct GNUNET_CONTAINER_MetaData *meta;
673 * Client info for this search result.
678 * ID of a job that is currently probing this results' availability
679 * (NULL if we are not currently probing).
681 struct GNUNET_FS_DownloadContext *probe_ctx;
684 * ID of an associated download based on this search result (or
687 struct GNUNET_FS_DownloadContext *download;
690 * If this search result triggered an update search, this field
691 * links to the update search.
693 struct GNUNET_FS_SearchContext *update_search;
696 * Name under which this search result is stored on disk.
701 * Key for the search result
706 * ID of the task that will clean up the probe_ctx should it not
707 * complete on time (and that will need to be cancelled if we clean
708 * up the search result before then).
710 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
713 * When did the current probe become active?
715 struct GNUNET_TIME_Absolute probe_active_time;
718 * How much longer should we run the current probe before giving up?
720 struct GNUNET_TIME_Relative remaining_probe_time;
723 * Number of mandatory keywords for which we have NOT yet found the
724 * search result; when this value hits zero, the search result is
725 * given to the callback.
727 uint32_t mandatory_missing;
730 * Number of optional keywords under which this result was also
733 uint32_t optional_support;
736 * Number of availability tests that have succeeded for this result.
738 uint32_t availability_success;
741 * Number of availability trials that we have performed for this
744 uint32_t availability_trials;
750 * Add a job to the queue.
752 * @param h handle to the overall FS state
753 * @param start function to call to begin the job
754 * @param stop function to call to pause the job, or on dequeue (if the job was running)
755 * @param cls closure for start and stop
756 * @param blocks number of blocks this download has
757 * @return queue handle
759 struct GNUNET_FS_QueueEntry *
760 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
761 GNUNET_FS_QueueStart start,
762 GNUNET_FS_QueueStop stop,
764 unsigned int blocks);
768 * Dequeue a job from the queue.
769 * @param qh handle for the job
772 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
776 * Function that provides data by reading from a file.
778 * @param cls closure (points to the file information)
779 * @param offset offset to read from; it is possible
780 * that the caller might need to go backwards
782 * @param max maximum number of bytes that should be
783 * copied to buf; readers are not allowed
784 * to provide less data unless there is an error;
785 * a value of "0" will be used at the end to allow
786 * the reader to clean up its internal state
787 * @param buf where the reader should write the data
788 * @param emsg location for the reader to store an error message
789 * @return number of bytes written, usually "max", 0 on error
792 GNUNET_FS_data_reader_file_(void *cls,
800 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
802 * @param filename file to read
803 * @return closure to use
806 GNUNET_FS_make_file_reader_context_ (const char *filename);
811 * Function that provides data by copying from a buffer.
813 * @param cls closure (points to the buffer)
814 * @param offset offset to read from; it is possible
815 * that the caller might need to go backwards
817 * @param max maximum number of bytes that should be
818 * copied to buf; readers are not allowed
819 * to provide less data unless there is an error;
820 * a value of "0" will be used at the end to allow
821 * the reader to clean up its internal state
822 * @param buf where the reader should write the data
823 * @param emsg location for the reader to store an error message
824 * @return number of bytes written, usually "max", 0 on error
827 GNUNET_FS_data_reader_copy_(void *cls,
834 * Notification of FS that a search probe has made progress.
835 * This function is used INSTEAD of the client's event handler
836 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
838 * @param cls closure, always NULL (!), actual closure
839 * is in the client-context of the info struct
840 * @param info details about the event, specifying the event type
841 * and various bits about the event
842 * @return client-context (for the next progress call
843 * for this operation; should be set to NULL for
844 * SUSPEND and STOPPED events). The value returned
845 * will be passed to future callbacks in the respective
846 * field in the GNUNET_FS_ProgressInfo struct.
849 GNUNET_FS_search_probe_progress_ (void *cls,
850 const struct GNUNET_FS_ProgressInfo *info);
854 * Main function that performs the upload.
856 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
857 * @param tc task context
860 GNUNET_FS_publish_main_ (void *cls,
861 const struct GNUNET_SCHEDULER_TaskContext *tc);
865 * Function called once the hash of the file
866 * that is being unindexed has been computed.
868 * @param cls closure, unindex context
869 * @param file_id computed hash, NULL on error
872 GNUNET_FS_unindex_process_hash_ (void *cls,
873 const GNUNET_HashCode *file_id);
877 * Fill in all of the generic fields for a publish event and call the
880 * @param pi structure to fill in
881 * @param sc overall publishing context
882 * @param p file information for the file being published
883 * @param offset where in the file are we so far
884 * @return value returned from callback
887 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
888 struct GNUNET_FS_PublishContext *sc,
889 const struct GNUNET_FS_FileInformation *p,
894 * Fill in all of the generic fields for a download event and call the
897 * @param pi structure to fill in
898 * @param dc overall download context
901 GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
902 struct GNUNET_FS_DownloadContext *dc);
906 * Fill in all of the generic fields for
907 * an unindex event and call the callback.
909 * @param pi structure to fill in
910 * @param uc overall unindex context
911 * @param offset where we are in the file (for progress)
914 GNUNET_FS_unindex_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
915 struct GNUNET_FS_UnindexContext *uc,
919 * Fill in all of the generic fields for a search event and
922 * @param pi structure to fill in
923 * @param sc overall search context
924 * @return value returned by the callback
927 GNUNET_FS_search_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
928 struct GNUNET_FS_SearchContext *sc);
932 * Connect to the datastore and remove the blocks.
934 * @param uc context for the unindex operation.
937 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc);
940 * Build the request and actually initiate the search using the
943 * @param sc search context
944 * @return GNUNET_OK on success, GNUNET_SYSERR on error
947 GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc);
950 * Start the downloading process (by entering the queue).
952 * @param dc our download context
955 GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc);
959 * Start download probes for the given search result.
961 * @param sr the search result
964 GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr);
967 * Remove serialization/deserialization file from disk.
969 * @param h master context
970 * @param ext component of the path
971 * @param ent entity identifier
974 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
980 * Remove serialization/deserialization directory from disk.
982 * @param h master context
983 * @param ext component of the path
984 * @param uni unique name of parent
987 GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h,
993 * Synchronize this file-information struct with its mirror
994 * on disk. Note that all internal FS-operations that change
995 * file information data should already call "sync" internally,
996 * so this function is likely not useful for clients.
998 * @param fi the struct to sync
1001 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
1004 * Synchronize this publishing struct with its mirror
1005 * on disk. Note that all internal FS-operations that change
1006 * publishing structs should already call "sync" internally,
1007 * so this function is likely not useful for clients.
1009 * @param pc the struct to sync
1012 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
1015 * Synchronize this unindex struct with its mirror
1016 * on disk. Note that all internal FS-operations that change
1017 * publishing structs should already call "sync" internally,
1018 * so this function is likely not useful for clients.
1020 * @param uc the struct to sync
1023 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc);
1026 * Synchronize this search struct with its mirror
1027 * on disk. Note that all internal FS-operations that change
1028 * publishing structs should already call "sync" internally,
1029 * so this function is likely not useful for clients.
1031 * @param sc the struct to sync
1034 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc);
1037 * Synchronize this search result with its mirror
1038 * on disk. Note that all internal FS-operations that change
1039 * publishing structs should already call "sync" internally,
1040 * so this function is likely not useful for clients.
1042 * @param sr the struct to sync
1045 GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr);
1048 * Synchronize this download struct with its mirror
1049 * on disk. Note that all internal FS-operations that change
1050 * publishing structs should already call "sync" internally,
1051 * so this function is likely not useful for clients.
1053 * @param dc the struct to sync
1056 GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc);
1059 * Create SUSPEND event for the given publish operation
1060 * and then clean up our state (without stop signal).
1062 * @param cls the 'struct GNUNET_FS_PublishContext' to signal for
1065 GNUNET_FS_publish_signal_suspend_ (void *cls);
1068 * Create SUSPEND event for the given search operation
1069 * and then clean up our state (without stop signal).
1071 * @param cls the 'struct GNUNET_FS_SearchContext' to signal for
1074 GNUNET_FS_search_signal_suspend_ (void *cls);
1077 * Create SUSPEND event for the given download operation
1078 * and then clean up our state (without stop signal).
1080 * @param cls the 'struct GNUNET_FS_DownloadContext' to signal for
1083 GNUNET_FS_download_signal_suspend_ (void *cls);
1086 * Create SUSPEND event for the given unindex operation
1087 * and then clean up our state (without stop signal).
1089 * @param cls the 'struct GNUNET_FS_UnindexContext' to signal for
1092 GNUNET_FS_unindex_signal_suspend_ (void *cls);
1095 * Function signature of the functions that can be called
1096 * to trigger suspend signals and clean-up for top-level
1099 * @param cls closure
1101 typedef void (*SuspendSignalFunction)(void *cls);
1104 * We track all of the top-level activities of FS
1105 * so that we can signal 'suspend' on shutdown.
1107 struct TopLevelActivity
1110 * This is a doubly-linked list.
1112 struct TopLevelActivity *next;
1115 * This is a doubly-linked list.
1117 struct TopLevelActivity *prev;
1120 * Function to call for suspend-signalling and clean up.
1122 SuspendSignalFunction ssf;
1125 * Closure for 'ssf' (some struct GNUNET_FS_XXXHandle*)
1132 * Create a top-level activity entry.
1134 * @param h global fs handle
1135 * @param ssf suspend signal function to use
1136 * @param ssf_cls closure for ssf
1137 * @return fresh top-level activity handle
1139 struct TopLevelActivity *
1140 GNUNET_FS_make_top (struct GNUNET_FS_Handle *h,
1141 SuspendSignalFunction ssf,
1146 * Destroy a top-level activity entry.
1148 * @param h global fs handle
1149 * @param top top level activity entry
1152 GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
1153 struct TopLevelActivity *top);
1158 * Master context for most FS operations.
1160 struct GNUNET_FS_Handle
1165 struct GNUNET_SCHEDULER_Handle *sched;
1168 * Configuration to use.
1170 const struct GNUNET_CONFIGURATION_Handle *cfg;
1173 * Name of our client.
1178 * Function to call with updates on our progress.
1180 GNUNET_FS_ProgressCallback upcb;
1188 * Head of DLL of top-level activities.
1190 struct TopLevelActivity *top_head;
1193 * Tail of DLL of top-level activities.
1195 struct TopLevelActivity *top_tail;
1198 * Head of DLL of running jobs.
1200 struct GNUNET_FS_QueueEntry *running_head;
1203 * Tail of DLL of running jobs.
1205 struct GNUNET_FS_QueueEntry *running_tail;
1208 * Head of DLL of pending jobs.
1210 struct GNUNET_FS_QueueEntry *pending_head;
1213 * Tail of DLL of pending jobs.
1215 struct GNUNET_FS_QueueEntry *pending_tail;
1218 * Task that processes the jobs in the running and pending queues
1219 * (and moves jobs around as needed).
1221 GNUNET_SCHEDULER_TaskIdentifier queue_job;
1224 * Average time we take for a single request to be satisfied.
1225 * FIXME: not yet calcualted properly...
1227 struct GNUNET_TIME_Relative avg_block_latency;
1230 * How many actual downloads do we have running right now?
1232 unsigned int active_downloads;
1235 * How many blocks do the active downloads have?
1237 unsigned int active_blocks;
1242 enum GNUNET_FS_Flags flags;
1245 * Maximum number of parallel downloads.
1247 unsigned int max_parallel_downloads;
1250 * Maximum number of parallel requests.
1252 unsigned int max_parallel_requests;
1258 * Handle for controlling a publication process.
1260 struct GNUNET_FS_PublishContext
1263 * Handle to the global fs context.
1265 struct GNUNET_FS_Handle *h;
1268 * Our top-level activity entry (if we are top-level, otherwise NULL).
1270 struct TopLevelActivity *top;
1273 * File-structure that is being shared.
1275 struct GNUNET_FS_FileInformation *fi;
1278 * Namespace that we are publishing in, NULL if we have no namespace.
1280 struct GNUNET_FS_Namespace *namespace;
1283 * ID of the content in the namespace, NULL if we have no namespace.
1288 * ID for future updates, NULL if we have no namespace or no updates.
1293 * Filename used for serializing information about this operation
1294 * (should be determined using 'mktemp').
1296 char *serialization;
1299 * Our own client handle for the FS service; only briefly used when
1300 * we start to index a file, otherwise NULL.
1302 struct GNUNET_CLIENT_Connection *client;
1305 * Current position in the file-tree for the upload.
1307 struct GNUNET_FS_FileInformation *fi_pos;
1310 * Non-null if we are currently hashing a file.
1312 struct GNUNET_CRYPTO_FileHashContext *fhc;
1315 * Connection to the datastore service.
1317 struct GNUNET_DATASTORE_Handle *dsh;
1320 * Queue entry for reservation/unreservation.
1322 struct GNUNET_DATASTORE_QueueEntry *qre;
1325 * ID of the task performing the upload. NO_TASK if the upload has
1328 GNUNET_SCHEDULER_TaskIdentifier upload_task;
1331 * Storage space to reserve for the operation.
1333 uint64_t reserve_space;
1336 * Overall number of entries to reserve for the
1337 * publish operation.
1339 uint32_t reserve_entries;
1342 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
1343 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
1344 * the datastore service (in which case this struct must not be
1345 * freed until we have that response). If someone tries to stop the
1346 * download for good during this period, "in_network_wait" is set to
1347 * GNUNET_SYSERR which will cause the struct to be destroyed right
1348 * after we have the reply (or timeout) from the datastore service.
1350 int in_network_wait;
1353 * Options for publishing.
1355 enum GNUNET_FS_PublishOptions options;
1358 * Space reservation ID with datastore service
1364 * Set to GNUNET_YES if all processing has completed.
1371 * Phases of unindex processing (state machine).
1376 * We're currently hashing the file.
1378 UNINDEX_STATE_HASHING = 0,
1381 * We're telling the datastore to delete
1382 * the respective entries.
1384 UNINDEX_STATE_DS_REMOVE = 1,
1387 * We're notifying the FS service about
1390 UNINDEX_STATE_FS_NOTIFY = 2,
1395 UNINDEX_STATE_COMPLETE = 3,
1398 * We've encountered a fatal error.
1400 UNINDEX_STATE_ERROR = 4
1406 * Handle for controlling an unindexing operation.
1408 struct GNUNET_FS_UnindexContext
1412 * Global FS context.
1414 struct GNUNET_FS_Handle *h;
1417 * Our top-level activity entry.
1419 struct TopLevelActivity *top;
1422 * Name of the file that we are unindexing.
1427 * Short name under which we are serializing the state of this operation.
1429 char *serialization;
1432 * Connection to the FS service, only valid during the
1433 * UNINDEX_STATE_FS_NOTIFY phase.
1435 struct GNUNET_CLIENT_Connection *client;
1438 * Connection to the datastore service, only valid during the
1439 * UNINDEX_STATE_DS_NOTIFY phase.
1441 struct GNUNET_DATASTORE_Handle *dsh;
1444 * Pointer kept for the client.
1449 * Merkle-ish tree encoder context.
1451 struct GNUNET_FS_TreeEncoder *tc;
1454 * Handle used to read the file.
1456 struct GNUNET_DISK_FileHandle *fh;
1459 * Error message, NULL on success.
1464 * Context for hashing of the file.
1466 struct GNUNET_CRYPTO_FileHashContext *fhc;
1469 * Overall size of the file.
1474 * When did we start?
1476 struct GNUNET_TIME_Absolute start_time;
1479 * Hash of the file's contents (once computed).
1481 GNUNET_HashCode file_id;
1484 * Current operatinonal phase.
1486 enum UnindexState state;
1492 * Information we keep for each keyword in
1495 struct SearchRequestEntry
1498 * Hash of the original keyword, also known as the
1499 * key (for decrypting the KBlock).
1501 GNUNET_HashCode key;
1504 * Hash of the public key, also known as the query.
1506 GNUNET_HashCode query;
1509 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1510 * was found under this keyword. Note that the entries will point
1511 * to the same locations as those in the master result map (in
1512 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1513 * The key for each entry is the XOR of the key and query in the CHK
1514 * URI (as a unique identifier for the search result).
1516 struct GNUNET_CONTAINER_MultiHashMap *results;
1519 * Is this keyword a mandatory keyword
1520 * (started with '+')?
1528 * Handle for controlling a search.
1530 struct GNUNET_FS_SearchContext
1533 * Handle to the global FS context.
1535 struct GNUNET_FS_Handle *h;
1538 * Our top-level activity entry (if we are top-level, otherwise NULL).
1540 struct TopLevelActivity *top;
1543 * List of keywords that we're looking for.
1545 struct GNUNET_FS_Uri *uri;
1548 * For update-searches, link to the search result that triggered
1549 * the update search; otherwise NULL.
1551 struct GNUNET_FS_SearchResult *psearch_result;
1554 * Connection to the FS service.
1556 struct GNUNET_CLIENT_Connection *client;
1559 * Pointer we keep for the client.
1564 * Name of the file on disk we use for persistence.
1566 char *serialization;
1569 * Error message (non-NULL if this operation failed).
1574 * Map that contains a "struct GNUNET_FS_SearchResult" for each result that
1575 * was found in the search. The key for each entry is the XOR of
1576 * the key and query in the CHK URI (as a unique identifier for the
1579 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1582 * Per-keyword information for a keyword search. This array will
1583 * have exactly as many entries as there were keywords.
1585 struct SearchRequestEntry *requests;
1588 * When did we start?
1590 struct GNUNET_TIME_Absolute start_time;
1593 * ID of a task that is using this struct and that must be cancelled
1594 * when the search is being stopped (if not
1595 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1596 * artificial delay when trying to reconnect to the FS service.
1598 GNUNET_SCHEDULER_TaskIdentifier task;
1601 * Anonymity level for the search.
1606 * Number of mandatory keywords in this query.
1608 uint32_t mandatory_count;
1611 * Options for the search.
1613 enum GNUNET_FS_SearchOptions options;
1618 * Information about an active download request.
1620 struct DownloadRequest
1623 * While pending, we keep all download requests in a linked list.
1625 struct DownloadRequest *next;
1628 * CHK for the request.
1630 struct ContentHashKey chk;
1633 * Offset of the corresponding block.
1638 * Depth of the corresponding block in the tree.
1643 * Set if this request is currently in the linked list of pending
1644 * requests. Needed in case we get a response for a request that we
1645 * have not yet send (i.e. due to two blocks with identical
1646 * content); in this case, we would need to remove the block from
1647 * the pending list (and need a fast way to check if the block is on
1656 * Context for controlling a download.
1658 struct GNUNET_FS_DownloadContext
1662 * Global FS context.
1664 struct GNUNET_FS_Handle *h;
1667 * Our top-level activity entry (if we are top-level, otherwise NULL).
1669 struct TopLevelActivity *top;
1672 * Connection to the FS service.
1674 struct GNUNET_CLIENT_Connection *client;
1677 * Parent download (used when downloading files
1680 struct GNUNET_FS_DownloadContext *parent;
1683 * Associated search (used when downloading files
1684 * based on search results), or NULL for none.
1686 struct GNUNET_FS_SearchResult *search;
1689 * Head of list of child downloads.
1691 struct GNUNET_FS_DownloadContext *child_head;
1694 * Tail of list of child downloads.
1696 struct GNUNET_FS_DownloadContext *child_tail;
1699 * Previous download belonging to the same parent.
1701 struct GNUNET_FS_DownloadContext *prev;
1704 * Next download belonging to the same parent.
1706 struct GNUNET_FS_DownloadContext *next;
1709 * Context kept for the client.
1714 * URI that identifies the file that
1715 * we are downloading.
1717 struct GNUNET_FS_Uri *uri;
1720 * Known meta-data for the file (can be NULL).
1722 struct GNUNET_CONTAINER_MetaData *meta;
1725 * Error message, NULL if we're doing OK.
1730 * Random portion of filename we use for syncing state of this
1733 char *serialization;
1736 * Where are we writing the data (name of the
1737 * file, can be NULL!).
1742 * Where are we writing the data temporarily (name of the
1743 * file, can be NULL!); used if we do not have a permanent
1744 * name and we are a directory and we do a recursive download.
1746 char *temp_filename;
1749 * Map of active requests (those waiting
1750 * for a response). The key is the hash
1751 * of the encryped block (aka query).
1753 struct GNUNET_CONTAINER_MultiHashMap *active;
1756 * Linked list of pending requests.
1758 struct DownloadRequest *pending;
1761 * Non-NULL if we are currently having a request for
1762 * transmission pending with the client handle.
1764 struct GNUNET_CLIENT_TransmitHandle *th;
1767 * Our entry in the job queue.
1769 struct GNUNET_FS_QueueEntry *job_queue;
1772 * Identity of the peer having the content, or all-zeros
1773 * if we don't know of such a peer.
1775 struct GNUNET_PeerIdentity target;
1778 * ID of a task that is using this struct
1779 * and that must be cancelled when the download
1780 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1781 * Used for the task that adds some artificial
1782 * delay when trying to reconnect to the FS
1785 GNUNET_SCHEDULER_TaskIdentifier task;
1788 * What was the size of the file on disk that we're downloading
1789 * before we started? Used to detect if there is a point in
1790 * checking an existing block on disk for matching the desired
1791 * content. 0 if the file did not exist already.
1793 uint64_t old_file_size;
1796 * What is the first offset that we're interested
1802 * How many bytes starting from offset are desired?
1803 * This is NOT the overall length of the file!
1808 * How many bytes have we already received within
1809 * the specified range (DBlocks only).
1814 * Time download was started.
1816 struct GNUNET_TIME_Absolute start_time;
1819 * Desired level of anonymity.
1824 * The depth of the file-tree.
1826 unsigned int treedepth;
1829 * Options for the download.
1831 enum GNUNET_FS_DownloadOptions options;
1834 * Flag set upon transitive completion (includes child downloads).
1835 * This flag is only set to GNUNET_YES for directories where all
1836 * child-downloads have also completed (and signalled completion).
1841 * Have we tried (and failed) to find matching full
1842 * data from the meta data yet?
1844 int tried_full_data;
1849 * Information about an (updateable) node in the
1852 struct NamespaceUpdateNode
1855 * Identifier for this node.
1860 * Identifier of children of this node.
1865 * Metadata for this entry.
1867 struct GNUNET_CONTAINER_MetaData *md;
1870 * URI of this entry in the namespace.
1872 struct GNUNET_FS_Uri *uri;
1875 * Namespace update generation ID. Used to ensure
1876 * freshness of the scc_id.
1881 * SCC this entry belongs to (if nug is current).
1883 unsigned int scc_id;
1888 struct GNUNET_FS_Namespace
1892 * Handle to the FS service context.
1894 struct GNUNET_FS_Handle *h;
1897 * Array with information about nodes in the namespace.
1899 struct NamespaceUpdateNode **update_nodes;
1902 * Private key for the namespace.
1904 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1907 * Hash map mapping identifiers of update nodes
1908 * to the update nodes (initialized on-demand).
1910 struct GNUNET_CONTAINER_MultiHashMap *update_map;
1913 * Name of the file with the private key.
1918 * Name of the namespace.
1923 * Size of the update nodes array.
1925 unsigned int update_node_count;
1928 * Reference counter.
1933 * Generator for unique nug numbers.
1935 unsigned int nug_gen;
1940 * Message sent from a GNUnet (fs) publishing activity to the
1941 * gnunet-fs-service to initiate indexing of a file. The service is
1942 * supposed to check if the specified file is available and has the
1943 * same cryptographic hash. It should then respond with either a
1944 * confirmation or a denial.
1946 * On OSes where this works, it is considered acceptable if the
1947 * service only checks that the path, device and inode match (it can
1948 * then be assumed that the hash will also match without actually
1949 * computing it; this is an optimization that should be safe given
1950 * that the client is not our adversary).
1952 struct IndexStartMessage
1956 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1958 struct GNUNET_MessageHeader header;
1963 uint32_t reserved GNUNET_PACKED;
1966 * ID of device containing the file, as seen by the client. This
1967 * device ID is obtained using a call like "statvfs" (and converting
1968 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1969 * OS does not support this, in which case the service must do a
1970 * full hash recomputation.
1972 uint64_t device GNUNET_PACKED;
1975 * Inode of the file on the given device, as seen by the client
1976 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1977 * support this, in which case the service must do a full hash
1980 uint64_t inode GNUNET_PACKED;
1983 * Hash of the file that we would like to index.
1985 GNUNET_HashCode file_id;
1987 /* this is followed by a 0-terminated
1988 filename of a file with the hash
1989 "file_id" as seen by the client */
1995 * Message send by FS service in response to a request
1996 * asking for a list of all indexed files.
1998 struct IndexInfoMessage
2001 * Message type will be
2002 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
2004 struct GNUNET_MessageHeader header;
2009 uint32_t reserved GNUNET_PACKED;
2012 * Hash of the indexed file.
2014 GNUNET_HashCode file_id;
2016 /* this is followed by a 0-terminated
2017 filename of a file with the hash
2018 "file_id" as seen by the client */
2024 * Message sent from a GNUnet (fs) unindexing activity to the
2025 * gnunet-service-fs to indicate that a file will be unindexed. The
2026 * service is supposed to remove the file from the list of indexed
2027 * files and response with a confirmation message (even if the file
2028 * was already not on the list).
2030 struct UnindexMessage
2034 * Message type will be
2035 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
2037 struct GNUNET_MessageHeader header;
2042 uint32_t reserved GNUNET_PACKED;
2045 * Hash of the file that we will unindex.
2047 GNUNET_HashCode file_id;
2053 * Message sent from a GNUnet (fs) search activity to the
2054 * gnunet-service-fs to start a search.
2056 struct SearchMessage
2060 * Message type will be
2061 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
2063 struct GNUNET_MessageHeader header;
2066 * Bitmask with options. Zero for no options, one for loopback-only.
2067 * Other bits are currently not defined.
2069 int32_t options GNUNET_PACKED;
2072 * Type of the content that we're looking for.
2074 uint32_t type GNUNET_PACKED;
2077 * Desired anonymity level, big-endian.
2079 uint32_t anonymity_level GNUNET_PACKED;
2082 * If the request is for a DBLOCK or IBLOCK, this is the identity of
2083 * the peer that is known to have a response. Set to all-zeros if
2084 * such a target is not known (note that even if OUR anonymity
2085 * level is >0 we may happen to know the responder's identity;
2086 * nevertheless, we should probably not use it for a DHT-lookup
2087 * or similar blunt actions in order to avoid exposing ourselves).
2089 * If the request is for an SBLOCK, this is the identity of the
2090 * pseudonym to which the SBLOCK belongs.
2092 * If the request is for a KBLOCK, "target" must be all zeros.
2094 GNUNET_HashCode target;
2097 * Hash of the keyword (aka query) for KBLOCKs; Hash of
2098 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
2099 * and hash of the identifier XORed with the target for
2100 * SBLOCKS (aka query).
2102 GNUNET_HashCode query;
2104 /* this is followed by the hash codes of already-known
2105 results (which should hence be excluded from what
2106 the service returns); naturally, this only applies
2107 to queries that can have multiple results, such as
2108 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
2113 * Only the (mandatory) query is included.
2115 #define GET_MESSAGE_BIT_QUERY_ONLY 0
2118 * The peer identity of a peer waiting for the
2119 * reply is included (used if the response
2120 * should be transmitted to someone other than
2121 * the sender of the GET).
2123 #define GET_MESSAGE_BIT_RETURN_TO 1
2126 * The hash of the public key of the target
2127 * namespace is included (for SKS queries).
2129 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
2132 * The peer identity of a peer that had claimed to have the content
2133 * previously is included (can be used if responder-anonymity is not
2134 * desired; note that the precursor presumably lacked a direct
2135 * connection to the specified peer; still, the receiver is in no way
2136 * required to limit forwarding only to the specified peer, it should
2137 * only prefer it somewhat if possible).
2139 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
2143 * Message sent between peers asking for FS-content.
2149 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
2151 struct GNUNET_MessageHeader header;
2154 * Type of the query (block type).
2156 uint32_t type GNUNET_PACKED;
2159 * How important is this request (network byte order)
2161 uint32_t priority GNUNET_PACKED;
2164 * Relative time to live in MILLISECONDS (network byte order)
2166 int32_t ttl GNUNET_PACKED;
2169 * The content hash should be mutated using this value
2170 * before checking against the bloomfilter (used to
2171 * get many different filters for the same hash codes).
2172 * The number should be in big-endian format when used
2175 int32_t filter_mutator GNUNET_PACKED;
2178 * Which of the optional hash codes are present at the end of the
2179 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
2180 * set, an additional GNUNET_HashCode with the respective content
2181 * (in order of the bits) will be appended to the end of the GET
2184 uint32_t hash_bitmap GNUNET_PACKED;
2187 * Hashcodes of the file(s) we're looking for.
2188 * Details depend on the query type.
2190 GNUNET_HashCode query GNUNET_PACKED;
2192 /* this is followed by hash codes
2193 as specified in the "hash_bitmap";
2194 after that, an optional bloomfilter
2195 (with bits set for replies that should
2196 be suppressed) can be present */
2201 * Response from FS service with a result for a previous FS search.
2202 * Note that queries for DBLOCKS and IBLOCKS that have received a
2203 * single response are considered done. This message is transmitted
2204 * between peers as well as between the service and a client.
2210 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
2212 struct GNUNET_MessageHeader header;
2215 * Type of the block (in big endian). Should never be zero.
2217 uint32_t type GNUNET_PACKED;
2220 * When does this result expire?
2222 struct GNUNET_TIME_AbsoluteNBO expiration;
2224 /* this is followed by the actual encrypted content */
2230 * Message send by a peer that wants to be excluded
2231 * from migration for a while.
2233 struct MigrationStopMessage
2236 * Message type will be
2237 * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
2239 struct GNUNET_MessageHeader header;
2244 uint32_t reserved GNUNET_PACKED;
2247 * How long should the block last?
2249 struct GNUNET_TIME_RelativeNBO duration;