2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 * @brief definitions for the entire fs module
24 * @author Igor Wronsky, Christian Grothoff
29 #include "gnunet_constants.h"
30 #include "gnunet_datastore_service.h"
31 #include "gnunet_fs_service.h"
32 #include "gnunet_block_lib.h"
35 * Size of the individual blocks used for file-sharing.
37 #define DBLOCK_SIZE (32*1024)
40 * Maximum legal size for a kblock.
42 #define MAX_KBLOCK_SIZE (60 * 1024)
45 * Maximum legal size for an sblock.
47 #define MAX_SBLOCK_SIZE (60 * 1024)
50 * Maximum legal size for an nblock.
52 #define MAX_NBLOCK_SIZE (60 * 1024)
55 * Pick a multiple of 2 here to achive 8-byte alignment!
56 * We also probably want DBlocks to have (roughly) the
57 * same size as IBlocks. With SHA-512, the optimal
58 * value is 32768 byte / 128 byte = 256
59 * (128 byte = 2 * 512 bits). DO NOT CHANGE!
61 #define CHK_PER_INODE 256
65 * Maximum size for a file to be considered for
66 * inlining in a directory.
68 #define MAX_INLINE_SIZE 65536
72 * Blocksize to use when hashing files
73 * for indexing (blocksize for IO, not for
74 * the DBlocks). Larger blocksizes can
75 * be more efficient but will be more disruptive
76 * as far as the scheduler is concerned.
78 #define HASHING_BLOCKSIZE (1024 * 1024)
81 * Number of bits we set per entry in the bloomfilter.
84 #define BLOOMFILTER_K 16
87 * Number of availability trials we perform per search result.
89 #define AVAILABILITY_TRIALS_MAX 8
92 * By how much (in ms) do we decrement the TTL
95 #define TTL_DECREMENT 5000
98 * Length of the P2P success tracker. Note that
99 * having a very long list can also hurt performance.
101 #define P2P_SUCCESS_LIST_SIZE 8
105 * Length of the CS-2-P success tracker. Note that
106 * having a very long list can also hurt performance.
108 #define CS2P_SUCCESS_LIST_SIZE 8
111 * How long are we willing to wait for the datastore to be ready to
112 * process a request for a query without priority?
114 #define BASIC_DATASTORE_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
118 * How long are we willing to wait for the core to be ready to
119 * transmit a reply to the target peer (if we can not transmit
120 * until then, we will discard the reply).
122 #define ACCEPTABLE_REPLY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
126 * Bandwidth value of an (effectively) 0-priority query.
128 #define QUERY_BANDWIDTH_VALUE 0.001
131 * Bandwidth value of a 0-priority content (must be
132 * fairly high compared to query since content is
133 * typically significantly larger -- and more valueable
134 * since it can take many queries to get one piece of
137 #define CONTENT_BANDWIDTH_VALUE 0.8
140 * By which amount do we decrement the TTL for simple forwarding /
141 * indirection of the query; in milli-seconds. Set somewhat in
142 * accordance to your network latency (above the time it'll take you
143 * to send a packet and get a reply).
145 #define TTL_DECREMENT 5000
148 * Until which load do we consider the peer idle and do not
149 * charge at all? (should be larger than GNUNET_IDLE_LOAD_THRESHOLD used
150 * by the rest of the code)!
152 #define IDLE_LOAD_THRESHOLD ((100 + GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD) / 2)
157 * @brief content hash key
159 struct ContentHashKey
162 GNUNET_HashCode query;
167 * @brief complete information needed
168 * to download a file.
170 struct FileIdentifier
174 * Total size of the file in bytes. (network byte order (!))
176 uint64_t file_length;
179 * Query and key of the top GNUNET_EC_IBlock.
181 struct ContentHashKey chk;
187 * Information about a file and its location
188 * (peer claiming to share the file).
193 * Information about the shared file.
195 struct FileIdentifier fi;
198 * Identity of the peer sharing the file.
200 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
203 * Time when this location URI expires.
205 struct GNUNET_TIME_Absolute expirationTime;
208 * RSA signature over the GNUNET_EC_FileIdentifier,
209 * GNUNET_hash of the peer and expiration time.
211 struct GNUNET_CRYPTO_RsaSignature contentSignature;
216 { chk, sks, ksk, loc };
219 * A Universal Resource Identifier (URI), opaque.
229 * Keywords start with a '+' if they are
230 * mandatory (in which case the '+' is NOT
231 * part of the keyword) and with a
232 * simple space if they are optional
233 * (in which case the space is ALSO not
234 * part of the actual keyword).
236 * Double-quotes to protect spaces and
237 * %-encoding are NOT used internally
238 * (only in URI-strings).
243 * Size of the keywords array.
245 unsigned int keywordCount;
251 * Hash of the public key for the namespace.
253 GNUNET_HashCode namespace;
256 * Human-readable identifier chosen for this
257 * entry in the namespace.
263 * Information needed to retrieve a file (content-hash-key
266 struct FileIdentifier chk;
269 * Information needed to retrieve a file including signed
270 * location (identity of a peer) of the content.
279 * Information for a file or directory that is
280 * about to be published.
282 struct GNUNET_FS_FileInformation
286 * Files in a directory are kept as a linked list.
288 struct GNUNET_FS_FileInformation *next;
291 * If this is a file in a directory, "dir" refers to
292 * the directory; otherwise NULL.
294 struct GNUNET_FS_FileInformation *dir;
297 * Handle to the master context.
299 struct GNUNET_FS_Handle *h;
302 * Pointer kept for the client.
307 * Metadata to use for the file.
309 struct GNUNET_CONTAINER_MetaData *meta;
312 * Keywords to use for KBlocks.
314 struct GNUNET_FS_Uri *keywords;
317 * CHK for this file or directory. NULL if
318 * we have not yet computed it.
320 struct GNUNET_FS_Uri *chk_uri;
323 * At what time should the content expire?
325 struct GNUNET_TIME_Absolute expirationTime;
328 * At what time did we start this upload?
330 struct GNUNET_TIME_Absolute start_time;
333 * Under what filename is this struct serialized
334 * (for operational persistence). Should be determined
340 * Encoder being used to publish this file.
342 struct GNUNET_FS_TreeEncoder *te;
345 * Error message (non-NULL if this operation
351 * Name of the file or directory (must be an absolute path).
356 * Data describing either the file or the directory.
367 * Function that can be used to read the data for the file.
369 GNUNET_FS_DataReader reader;
372 * Closure for reader.
377 * If this file is being indexed, this value is set to the hash
378 * over the entire file (when the indexing process is started).
379 * Otherwise this field is not used.
381 GNUNET_HashCode file_id;
384 * Size of the file (in bytes).
389 * Should the file be indexed or inserted?
394 * Is "file_id" already valid? Set to GNUNET_YES once the hash
395 * has been calculated.
400 * Has the service confirmed our INDEX_START request?
401 * GNUNET_YES if this step has been completed.
403 int index_start_confirmed;
408 * Data for a directory.
413 * Linked list of entries in the directory.
415 struct GNUNET_FS_FileInformation *entries;
418 * Size of the directory itself (in bytes); 0 if the
419 * size has not yet been calculated.
424 * Pointer to the data for the directory (or NULL if not
434 * Desired anonymity level.
439 * Desired priority (for keeping the content in the DB).
444 * Is this struct for a file or directory?
449 * Are we done publishing this file?
457 * The job is now ready to run and should use the given client
458 * handle to communicate with the FS service.
461 * @param client handle to use for FS communication
463 typedef void (*GNUNET_FS_QueueStart)(void *cls,
464 struct GNUNET_CLIENT_Connection *client);
468 * The job must now stop to run and should destry the client handle as
469 * soon as possible (ideally prior to returning).
471 typedef void (*GNUNET_FS_QueueStop)(void *cls);
475 * Entry in the job queue.
477 struct GNUNET_FS_QueueEntry
480 * This is a linked list.
482 struct GNUNET_FS_QueueEntry *next;
485 * This is a linked list.
487 struct GNUNET_FS_QueueEntry *prev;
490 * Function to call when the job is started.
492 GNUNET_FS_QueueStart start;
495 * Function to call when the job needs to stop (or is done / dequeued).
497 GNUNET_FS_QueueStop stop;
500 * Closure for start and stop.
505 * Handle to FS primary context.
507 struct GNUNET_FS_Handle *h;
510 * Client handle, or NULL if job is not running.
512 struct GNUNET_CLIENT_Connection *client;
515 * Time the job was originally queued.
517 struct GNUNET_TIME_Absolute queue_time;
520 * Time the job was started last.
522 struct GNUNET_TIME_Absolute start_time;
525 * Total amount of time the job has been running (except for the
528 struct GNUNET_TIME_Relative run_time;
531 * How many blocks do the active downloads have?
536 * How often have we (re)started this download?
538 unsigned int start_times;
546 * Add a job to the queue.
548 * @param h handle to the overall FS state
549 * @param start function to call to begin the job
550 * @param stop function to call to pause the job, or on dequeue (if the job was running)
551 * @param cls closure for start and stop
552 * @param blocks number of blocks this download has
553 * @return queue handle
555 struct GNUNET_FS_QueueEntry *
556 GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h,
557 GNUNET_FS_QueueStart start,
558 GNUNET_FS_QueueStop stop,
560 unsigned int blocks);
564 * Dequeue a job from the queue.
565 * @param qh handle for the job
568 GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qh);
572 * Function that provides data by reading from a file.
574 * @param cls closure (points to the file information)
575 * @param offset offset to read from; it is possible
576 * that the caller might need to go backwards
578 * @param max maximum number of bytes that should be
579 * copied to buf; readers are not allowed
580 * to provide less data unless there is an error;
581 * a value of "0" will be used at the end to allow
582 * the reader to clean up its internal state
583 * @param buf where the reader should write the data
584 * @param emsg location for the reader to store an error message
585 * @return number of bytes written, usually "max", 0 on error
588 GNUNET_FS_data_reader_file_(void *cls,
596 * Create the closure for the 'GNUNET_FS_data_reader_file_' callback.
598 * @param filename file to read
599 * @return closure to use
602 GNUNET_FS_make_file_reader_context_ (const char *filename);
607 * Function that provides data by copying from a buffer.
609 * @param cls closure (points to the buffer)
610 * @param offset offset to read from; it is possible
611 * that the caller might need to go backwards
613 * @param max maximum number of bytes that should be
614 * copied to buf; readers are not allowed
615 * to provide less data unless there is an error;
616 * a value of "0" will be used at the end to allow
617 * the reader to clean up its internal state
618 * @param buf where the reader should write the data
619 * @param emsg location for the reader to store an error message
620 * @return number of bytes written, usually "max", 0 on error
623 GNUNET_FS_data_reader_copy_(void *cls,
630 * Notification of FS that a search probe has made progress.
631 * This function is used INSTEAD of the client's event handler
632 * for downloads where the GNUNET_FS_DOWNLOAD_IS_PROBE flag is set.
634 * @param cls closure, always NULL (!), actual closure
635 * is in the client-context of the info struct
636 * @param info details about the event, specifying the event type
637 * and various bits about the event
638 * @return client-context (for the next progress call
639 * for this operation; should be set to NULL for
640 * SUSPEND and STOPPED events). The value returned
641 * will be passed to future callbacks in the respective
642 * field in the GNUNET_FS_ProgressInfo struct.
645 GNUNET_FS_search_probe_progress_ (void *cls,
646 const struct GNUNET_FS_ProgressInfo *info);
650 * Main function that performs the upload.
652 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload
653 * @param tc task context
656 GNUNET_FS_publish_main_ (void *cls,
657 const struct GNUNET_SCHEDULER_TaskContext *tc);
661 * Fill in all of the generic fields for a publish event and call the
664 * @param pi structure to fill in
665 * @param sc overall publishing context
666 * @param p file information for the file being published
667 * @param offset where in the file are we so far
668 * @return value returned from callback
671 GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
672 struct GNUNET_FS_PublishContext *sc,
673 const struct GNUNET_FS_FileInformation *p,
678 * Remove serialization/deserialization file from disk.
680 * @param h master context
681 * @param ext component of the path
682 * @param ent entity identifier
685 GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h,
691 * Synchronize this file-information struct with its mirror
692 * on disk. Note that all internal FS-operations that change
693 * file information data should already call "sync" internally,
694 * so this function is likely not useful for clients.
696 * @param fi the struct to sync
699 GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *f);
703 * Synchronize this publishing struct with its mirror
704 * on disk. Note that all internal FS-operations that change
705 * publishing structs should already call "sync" internally,
706 * so this function is likely not useful for clients.
708 * @param pc the struct to sync
711 GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc);
716 * Master context for most FS operations.
718 struct GNUNET_FS_Handle
723 struct GNUNET_SCHEDULER_Handle *sched;
726 * Configuration to use.
728 const struct GNUNET_CONFIGURATION_Handle *cfg;
731 * Name of our client.
736 * Function to call with updates on our progress.
738 GNUNET_FS_ProgressCallback upcb;
746 * Connection to the FS service.
748 struct GNUNET_CLIENT_Connection *client;
751 * Head of DLL of running jobs.
753 struct GNUNET_FS_QueueEntry *running_head;
756 * Tail of DLL of running jobs.
758 struct GNUNET_FS_QueueEntry *running_tail;
761 * Head of DLL of pending jobs.
763 struct GNUNET_FS_QueueEntry *pending_head;
766 * Tail of DLL of pending jobs.
768 struct GNUNET_FS_QueueEntry *pending_tail;
771 * Task that processes the jobs in the running and pending queues
772 * (and moves jobs around as needed).
774 GNUNET_SCHEDULER_TaskIdentifier queue_job;
777 * Average time we take for a single request to be satisfied.
778 * FIXME: not yet calcualted properly...
780 struct GNUNET_TIME_Relative avg_block_latency;
783 * How many actual downloads do we have running right now?
785 unsigned int active_downloads;
788 * How many blocks do the active downloads have?
790 unsigned int active_blocks;
795 enum GNUNET_FS_Flags flags;
798 * Maximum number of parallel downloads.
800 unsigned int max_parallel_downloads;
803 * Maximum number of parallel requests.
805 unsigned int max_parallel_requests;
811 * Handle for controlling a publication process.
813 struct GNUNET_FS_PublishContext
816 * Handle to the global fs context.
818 struct GNUNET_FS_Handle *h;
821 * File-structure that is being shared.
823 struct GNUNET_FS_FileInformation *fi;
826 * Namespace that we are publishing in, NULL if we have no namespace.
828 struct GNUNET_FS_Namespace *namespace;
831 * ID of the content in the namespace, NULL if we have no namespace.
836 * ID for future updates, NULL if we have no namespace or no updates.
841 * Filename used for serializing information about this operation
842 * (should be determined using 'mktemp').
847 * Our own client handle for the FS service; only briefly used when
848 * we start to index a file, otherwise NULL.
850 struct GNUNET_CLIENT_Connection *client;
853 * Current position in the file-tree for the upload.
855 struct GNUNET_FS_FileInformation *fi_pos;
858 * Connection to the datastore service.
860 struct GNUNET_DATASTORE_Handle *dsh;
863 * ID of the task performing the upload. NO_TASK if the upload has
866 GNUNET_SCHEDULER_TaskIdentifier upload_task;
869 * Typically GNUNET_NO. Set to GNUNET_YES if "upload_task" is
870 * GNUNET_SCHEDULER_NO_TASK and we're waiting for a response from
871 * the datastore service (in which case this struct must not be
872 * freed until we have that response). If someone tries to stop the
873 * download for good during this period, "in_network_wait" is set to
874 * GNUNET_SYSERR which will cause the struct to be destroyed right
875 * after we have the reply (or timeout) from the datastore service.
880 * Options for publishing.
882 enum GNUNET_FS_PublishOptions options;
885 * Space reservation ID with datastore service
891 * Set to GNUNET_YES if all processing has completed.
898 * Phases of unindex processing (state machine).
903 * We're currently hashing the file.
905 UNINDEX_STATE_HASHING = 0,
908 * We're notifying the FS service about
911 UNINDEX_STATE_FS_NOTIFY = 1,
914 * We're telling the datastore to delete
915 * the respective entries.
917 UNINDEX_STATE_DS_REMOVE = 2,
922 UNINDEX_STATE_COMPLETE = 3,
925 * We've encountered a fatal error.
927 UNINDEX_STATE_ERROR = 4,
930 * We've been aborted. The next callback should clean up the
933 UNINDEX_STATE_ABORTED = 5
938 * Handle for controlling an unindexing operation.
940 struct GNUNET_FS_UnindexContext
946 struct GNUNET_FS_Handle *h;
949 * Name of the file that we are unindexing.
954 * Short name under which we are serializing the state of this operation.
959 * Connection to the FS service, only valid during the
960 * UNINDEX_STATE_FS_NOTIFY phase.
962 struct GNUNET_CLIENT_Connection *client;
965 * Connection to the datastore service, only valid during the
966 * UNINDEX_STATE_DS_NOTIFY phase.
968 struct GNUNET_DATASTORE_Handle *dsh;
971 * Pointer kept for the client.
976 * Merkle-ish tree encoder context.
978 struct GNUNET_FS_TreeEncoder *tc;
981 * Handle used to read the file.
983 struct GNUNET_DISK_FileHandle *fh;
986 * Overall size of the file.
993 struct GNUNET_TIME_Absolute start_time;
996 * Hash of the file's contents (once computed).
998 GNUNET_HashCode file_id;
1001 * Current operatinonal phase.
1003 enum UnindexState state;
1009 * Information we store for each search result.
1015 * Search context this result belongs to.
1017 struct GNUNET_FS_SearchContext *sc;
1020 * URI to which this search result refers to.
1022 struct GNUNET_FS_Uri *uri;
1025 * Metadata for the search result.
1027 struct GNUNET_CONTAINER_MetaData *meta;
1030 * Client info for this search result.
1035 * ID of a job that is currently probing this results' availability
1036 * (NULL if we are not currently probing).
1038 struct GNUNET_FS_DownloadContext *probe_ctx;
1041 * ID of the task that will clean up the probe_ctx should it not
1042 * complete on time (and that will need to be cancelled if we clean
1043 * up the search result before then).
1045 GNUNET_SCHEDULER_TaskIdentifier probe_cancel_task;
1048 * When did the current probe become active?
1050 struct GNUNET_TIME_Absolute probe_active_time;
1053 * How much longer should we run the current probe before giving up?
1055 struct GNUNET_TIME_Relative remaining_probe_time;
1058 * Number of mandatory keywords for which we have NOT yet found the
1059 * search result; when this value hits zero, the search result is
1060 * given to the callback.
1062 uint32_t mandatory_missing;
1065 * Number of optional keywords under which this result was also
1068 uint32_t optional_support;
1071 * Number of availability tests that have succeeded for this result.
1073 uint32_t availability_success;
1076 * Number of availability trials that we have performed for this
1079 uint32_t availability_trials;
1085 * Information we keep for each keyword in
1088 struct SearchRequestEntry
1091 * Hash of the original keyword, also known as the
1092 * key (for decrypting the KBlock).
1094 GNUNET_HashCode key;
1097 * Hash of the public key, also known as the query.
1099 GNUNET_HashCode query;
1102 * Map that contains a "struct SearchResult" for each result that
1103 * was found under this keyword. Note that the entries will point
1104 * to the same locations as those in the master result map (in
1105 * "struct GNUNET_FS_SearchContext"), so they should not be freed.
1106 * The key for each entry is the XOR of the key and query in the CHK
1107 * URI (as a unique identifier for the search result).
1109 struct GNUNET_CONTAINER_MultiHashMap *results;
1112 * Is this keyword a mandatory keyword
1113 * (started with '+')?
1121 * Handle for controlling a search.
1123 struct GNUNET_FS_SearchContext
1126 * Handle to the global FS context.
1128 struct GNUNET_FS_Handle *h;
1131 * List of keywords that we're looking for.
1133 struct GNUNET_FS_Uri *uri;
1136 * For update-searches, link to the base-SKS search that triggered
1137 * the update search; otherwise NULL.
1139 struct GNUNET_FS_SearchContext *parent;
1142 * For update-searches, link to the first child search that
1143 * triggered the update search; otherwise NULL.
1145 struct GNUNET_FS_SearchContext *child_head;
1148 * For update-searches, link to the last child search that triggered
1149 * the update search; otherwise NULL.
1151 struct GNUNET_FS_SearchContext *child_tail;
1154 * For update-searches, link to the next child belonging to the same
1157 struct GNUNET_FS_SearchContext *next;
1160 * For update-searches, link to the previous child belonging to the
1163 struct GNUNET_FS_SearchContext *prev;
1166 * Connection to the FS service.
1168 struct GNUNET_CLIENT_Connection *client;
1171 * Pointer we keep for the client.
1176 * Map that contains a "struct SearchResult" for each result that
1177 * was found in the search. The key for each entry is the XOR of
1178 * the key and query in the CHK URI (as a unique identifier for the
1181 struct GNUNET_CONTAINER_MultiHashMap *master_result_map;
1184 * Per-keyword information for a keyword search. This array will
1185 * have exactly as many entries as there were keywords.
1187 struct SearchRequestEntry *requests;
1190 * When did we start?
1192 struct GNUNET_TIME_Absolute start_time;
1195 * ID of a task that is using this struct and that must be cancelled
1196 * when the search is being stopped (if not
1197 * GNUNET_SCHEDULER_NO_TASK). Used for the task that adds some
1198 * artificial delay when trying to reconnect to the FS service.
1200 GNUNET_SCHEDULER_TaskIdentifier task;
1203 * Anonymity level for the search.
1208 * Number of mandatory keywords in this query.
1210 uint32_t mandatory_count;
1213 * Options for the search.
1215 enum GNUNET_FS_SearchOptions options;
1220 * Information about an active download request.
1222 struct DownloadRequest
1225 * While pending, we keep all download requests in a linked list.
1227 struct DownloadRequest *next;
1230 * CHK for the request.
1232 struct ContentHashKey chk;
1235 * Offset of the corresponding block.
1240 * Depth of the corresponding block in the tree.
1245 * Set if this request is currently in the linked list of pending
1246 * requests. Needed in case we get a response for a request that we
1247 * have not yet send (due to FS bug or two blocks with identical
1248 * content); in this case, we would need to remove the block from
1249 * the pending list (and need a fast way to check if the block is on
1258 * Context for controlling a download.
1260 struct GNUNET_FS_DownloadContext
1264 * Global FS context.
1266 struct GNUNET_FS_Handle *h;
1269 * Connection to the FS service.
1271 struct GNUNET_CLIENT_Connection *client;
1274 * Parent download (used when downloading files
1277 struct GNUNET_FS_DownloadContext *parent;
1280 * Head of list of child downloads.
1282 struct GNUNET_FS_DownloadContext *child_head;
1285 * Tail of list of child downloads.
1287 struct GNUNET_FS_DownloadContext *child_tail;
1290 * Previous download belonging to the same parent.
1292 struct GNUNET_FS_DownloadContext *prev;
1295 * Next download belonging to the same parent.
1297 struct GNUNET_FS_DownloadContext *next;
1300 * Context kept for the client.
1305 * URI that identifies the file that
1306 * we are downloading.
1308 struct GNUNET_FS_Uri *uri;
1311 * Known meta-data for the file (can be NULL).
1313 struct GNUNET_CONTAINER_MetaData *meta;
1316 * Error message, NULL if we're doing OK.
1321 * Where are we writing the data (name of the
1322 * file, can be NULL!).
1327 * Where are we writing the data temporarily (name of the
1328 * file, can be NULL!); used if we do not have a permanent
1329 * name and we are a directory and we do a recursive download.
1331 char *temp_filename;
1334 * Map of active requests (those waiting
1335 * for a response). The key is the hash
1336 * of the encryped block (aka query).
1338 struct GNUNET_CONTAINER_MultiHashMap *active;
1341 * Linked list of pending requests.
1343 struct DownloadRequest *pending;
1346 * The file handle, NULL if we don't create
1349 struct GNUNET_DISK_FileHandle *handle;
1352 * Non-NULL if we are currently having a request for
1353 * transmission pending with the client handle.
1355 struct GNUNET_CLIENT_TransmitHandle *th;
1358 * Our entry in the job queue.
1360 struct GNUNET_FS_QueueEntry *job_queue;
1363 * Identity of the peer having the content, or all-zeros
1364 * if we don't know of such a peer.
1366 struct GNUNET_PeerIdentity target;
1369 * ID of a task that is using this struct
1370 * and that must be cancelled when the download
1371 * is being stopped (if not GNUNET_SCHEDULER_NO_TASK).
1372 * Used for the task that adds some artificial
1373 * delay when trying to reconnect to the FS
1376 GNUNET_SCHEDULER_TaskIdentifier task;
1379 * What was the size of the file on disk that we're downloading
1380 * before we started? Used to detect if there is a point in
1381 * checking an existing block on disk for matching the desired
1382 * content. 0 if the file did not exist already.
1384 uint64_t old_file_size;
1387 * What is the first offset that we're interested
1393 * How many bytes starting from offset are desired?
1394 * This is NOT the overall length of the file!
1399 * How many bytes have we already received within
1400 * the specified range (DBlocks only).
1405 * Time download was started.
1407 struct GNUNET_TIME_Absolute start_time;
1410 * Desired level of anonymity.
1415 * The depth of the file-tree.
1417 unsigned int treedepth;
1420 * Options for the download.
1422 enum GNUNET_FS_DownloadOptions options;
1425 * Flag set upon transitive completion (includes child downloads).
1426 * This flag is only set to GNUNET_YES for directories where all
1427 * child-downloads have also completed (and signalled completion).
1433 struct GNUNET_FS_Namespace
1437 * Private key for the namespace.
1439 struct GNUNET_CRYPTO_RsaPrivateKey *key;
1442 * Name of the file with the private key.
1447 * Name of the namespace.
1452 * Reference counter.
1459 * Message sent from a GNUnet (fs) publishing activity to the
1460 * gnunet-fs-service to initiate indexing of a file. The service is
1461 * supposed to check if the specified file is available and has the
1462 * same cryptographic hash. It should then respond with either a
1463 * confirmation or a denial.
1465 * On OSes where this works, it is considered acceptable if the
1466 * service only checks that the path, device and inode match (it can
1467 * then be assumed that the hash will also match without actually
1468 * computing it; this is an optimization that should be safe given
1469 * that the client is not our adversary).
1471 struct IndexStartMessage
1475 * Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_START.
1477 struct GNUNET_MessageHeader header;
1480 * ID of device containing the file, as seen by the client. This
1481 * device ID is obtained using a call like "statvfs" (and converting
1482 * the "f_fsid" field to a 32-bit big-endian number). Use 0 if the
1483 * OS does not support this, in which case the service must do a
1484 * full hash recomputation.
1486 uint32_t device GNUNET_PACKED;
1489 * Inode of the file on the given device, as seen by the client
1490 * ("st_ino" field from "struct stat"). Use 0 if the OS does not
1491 * support this, in which case the service must do a full hash
1494 uint64_t inode GNUNET_PACKED;
1497 * Hash of the file that we would like to index.
1499 GNUNET_HashCode file_id;
1501 /* this is followed by a 0-terminated
1502 filename of a file with the hash
1503 "file_id" as seen by the client */
1509 * Message send by FS service in response to a request
1510 * asking for a list of all indexed files.
1512 struct IndexInfoMessage
1515 * Message type will be
1516 * GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
1518 struct GNUNET_MessageHeader header;
1523 uint32_t reserved GNUNET_PACKED;
1526 * Hash of the indexed file.
1528 GNUNET_HashCode file_id;
1530 /* this is followed by a 0-terminated
1531 filename of a file with the hash
1532 "file_id" as seen by the client */
1538 * Message sent from a GNUnet (fs) unindexing activity to the
1539 * gnunet-service-fs to indicate that a file will be unindexed. The
1540 * service is supposed to remove the file from the list of indexed
1541 * files and response with a confirmation message (even if the file
1542 * was already not on the list).
1544 struct UnindexMessage
1548 * Message type will be
1549 * GNUNET_MESSAGE_TYPE_FS_UNINDEX.
1551 struct GNUNET_MessageHeader header;
1556 uint32_t reserved GNUNET_PACKED;
1559 * Hash of the file that we will unindex.
1561 GNUNET_HashCode file_id;
1567 * Message sent from a GNUnet (fs) search activity to the
1568 * gnunet-service-fs to start a search.
1570 struct SearchMessage
1574 * Message type will be
1575 * GNUNET_MESSAGE_TYPE_FS_START_SEARCH.
1577 struct GNUNET_MessageHeader header;
1580 * Bitmask with options. Zero for no options, one for loopback-only.
1581 * Other bits are currently not defined.
1583 int32_t options GNUNET_PACKED;
1586 * Type of the content that we're looking for.
1588 uint32_t type GNUNET_PACKED;
1591 * Desired anonymity level, big-endian.
1593 uint32_t anonymity_level GNUNET_PACKED;
1596 * If the request is for a DBLOCK or IBLOCK, this is the identity of
1597 * the peer that is known to have a response. Set to all-zeros if
1598 * such a target is not known (note that even if OUR anonymity
1599 * level is >0 we may happen to know the responder's identity;
1600 * nevertheless, we should probably not use it for a DHT-lookup
1601 * or similar blunt actions in order to avoid exposing ourselves).
1603 * If the request is for an SBLOCK, this is the identity of the
1604 * pseudonym to which the SBLOCK belongs.
1606 * If the request is for a KBLOCK, "target" must be all zeros.
1608 GNUNET_HashCode target;
1611 * Hash of the keyword (aka query) for KBLOCKs; Hash of
1612 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
1613 * and hash of the identifier XORed with the target for
1614 * SBLOCKS (aka query).
1616 GNUNET_HashCode query;
1618 /* this is followed by the hash codes of already-known
1619 results (which should hence be excluded from what
1620 the service returns); naturally, this only applies
1621 to queries that can have multiple results, such as
1622 those for KBLOCKS (KSK) and SBLOCKS (SKS) */
1627 * Only the (mandatory) query is included.
1629 #define GET_MESSAGE_BIT_QUERY_ONLY 0
1632 * The peer identity of a peer waiting for the
1633 * reply is included (used if the response
1634 * should be transmitted to someone other than
1635 * the sender of the GET).
1637 #define GET_MESSAGE_BIT_RETURN_TO 1
1640 * The hash of the public key of the target
1641 * namespace is included (for SKS queries).
1643 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
1646 * The peer identity of a peer that had claimed to have the content
1647 * previously is included (can be used if responder-anonymity is not
1648 * desired; note that the precursor presumably lacked a direct
1649 * connection to the specified peer; still, the receiver is in no way
1650 * required to limit forwarding only to the specified peer, it should
1651 * only prefer it somewhat if possible).
1653 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
1657 * Message sent between peers asking for FS-content.
1663 * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
1665 struct GNUNET_MessageHeader header;
1668 * Type of the query (block type).
1670 uint32_t type GNUNET_PACKED;
1673 * How important is this request (network byte order)
1675 uint32_t priority GNUNET_PACKED;
1678 * Relative time to live in MILLISECONDS (network byte order)
1680 int32_t ttl GNUNET_PACKED;
1683 * The content hash should be mutated using this value
1684 * before checking against the bloomfilter (used to
1685 * get many different filters for the same hash codes).
1686 * The number should be in big-endian format when used
1689 int32_t filter_mutator GNUNET_PACKED;
1692 * Which of the optional hash codes are present at the end of the
1693 * message? See GET_MESSAGE_BIT_xx constants. For each bit that is
1694 * set, an additional GNUNET_HashCode with the respective content
1695 * (in order of the bits) will be appended to the end of the GET
1698 uint32_t hash_bitmap GNUNET_PACKED;
1701 * Hashcodes of the file(s) we're looking for.
1702 * Details depend on the query type.
1704 GNUNET_HashCode query GNUNET_PACKED;
1706 /* this is followed by hash codes
1707 as specified in the "hash_bitmap";
1708 after that, an optional bloomfilter
1709 (with bits set for replies that should
1710 be suppressed) can be present */
1715 * Response from FS service with a result for a previous FS search.
1716 * Note that queries for DBLOCKS and IBLOCKS that have received a
1717 * single response are considered done. This message is transmitted
1718 * between peers as well as between the service and a client.
1724 * Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
1726 struct GNUNET_MessageHeader header;
1729 * Type of the block (in big endian). Should never be zero.
1731 uint32_t type GNUNET_PACKED;
1734 * When does this result expire?
1736 struct GNUNET_TIME_AbsoluteNBO expiration;
1738 /* this is followed by the actual encrypted content */