2 This file is part of GNUnet
3 (C) 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.
21 * @file include/gnunet_fs_service.h
22 * @brief API for file-sharing via GNUnet
23 * @author Christian Grothoff
26 * - extend API with support for publish simulation (-s)
27 * and URI-argument binding to keyword/namespace (-u)
29 #ifndef GNUNET_FS_LIB_H
30 #define GNUNET_FS_LIB_H
32 #include "gnunet_util_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
43 * Version number of the implementation.
46 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
47 * 2.x.x: root node with mime-type, filename and version number
48 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
49 * 2.2.x: with directories
50 * 3.0.x: with namespaces
51 * 3.1.x: with namespace meta-data
52 * 3.2.x: with collections
53 * 4.0.x: with expiration, variable meta-data, kblocks
54 * 4.1.x: with new error and configuration handling
55 * 5.0.x: with location URIs
56 * 6.0.0: with support for OR in KSKs
57 * 6.1.x: with simplified namespace support
58 * 9.0.0: CPS-style integrated API
60 #define GNUNET_FS_VERSION 0x00090000
63 /* ******************** URI API *********************** */
65 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
66 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
67 #define GNUNET_FS_URI_SKS_INFIX "sks/"
68 #define GNUNET_FS_URI_CHK_INFIX "chk/"
69 #define GNUNET_FS_URI_LOC_INFIX "loc/"
73 * A Universal Resource Identifier (URI), opaque.
79 * Iterator over keywords
82 * @param keyword the keyword
83 * @param is_mandatory is the keyword mandatory (in a search)
84 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
86 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
91 * Get a unique key from a URI. This is for putting URIs
92 * into HashMaps. The key may change between FS implementations.
94 * @param uri uri to convert to a unique key
95 * @param key wherer to store the unique key
98 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
99 GNUNET_HashCode * key);
102 * Convert a URI to a UTF-8 String.
104 * @param uri uri to convert to a string
105 * @return the UTF-8 string
108 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
111 * Convert keyword URI to a human readable format
112 * (i.e. the search query that was used in the first place)
114 * @param uri ksk uri to convert to a string
115 * @return string with the keywords
118 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
122 * Convert a UTF-8 String to a URI.
124 * @param uri string to parse
125 * @param emsg where to store the parser error message (if any)
126 * @return NULL on error
128 struct GNUNET_FS_Uri *
129 GNUNET_FS_uri_parse (const char *uri,
135 * @param uri uri to free
138 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
142 * How many keywords are ANDed in this keyword URI?
144 * @param uri ksk uri to get the number of keywords from
145 * @return 0 if this is not a keyword URI
148 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
152 * Iterate over all keywords in this keyword URI.
154 * @param uri ksk uri to get the keywords from
155 * @param iterator function to call on each keyword
156 * @param iterator_cls closure for iterator
157 * @return -1 if this is not a keyword URI, otherwise number of
158 * keywords iterated over until iterator aborted
161 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
162 GNUNET_FS_KeywordIterator iterator,
167 * Obtain the identity of the peer offering the data
169 * @param uri the location URI to inspect
170 * @param peer where to store the identify of the peer (presumably) offering the content
171 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
174 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
175 struct GNUNET_PeerIdentity * peer);
179 * Obtain the URI of the content itself.
181 * @param uri location URI to get the content URI from
182 * @return NULL if argument is not a location URI
184 struct GNUNET_FS_Uri *
185 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
189 * Obtain the expiration of the LOC URI.
191 * @param uri location URI to get the expiration from
192 * @return expiration time of the URI
194 struct GNUNET_TIME_Absolute
195 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
199 * Construct a location URI (this peer will be used for the location).
201 * @param baseUri content offered by the sender
202 * @param cfg configuration information (used to find our hostkey)
203 * @param expiration_time how long will the content be offered?
204 * @return the location URI, NULL on error
206 struct GNUNET_FS_Uri *
207 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
208 struct GNUNET_CONFIGURATION_Handle *cfg,
209 struct GNUNET_TIME_Absolute expiration_time);
213 * Canonicalize keyword URI. Performs operations such
214 * as decapitalization and removal of certain characters.
215 * (useful for search).
217 * @param uri the URI to canonicalize
218 * @return canonicalized version of the URI, NULL on error
220 struct GNUNET_FS_Uri *
221 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
225 * Merge the sets of keywords from two KSK URIs.
226 * (useful for merging the canonicalized keywords with
227 * the original keywords for sharing).
229 * @param u1 first uri
230 * @param u2 second uri
231 * @return merged URI, NULL on error
233 struct GNUNET_FS_Uri *
234 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
235 const struct GNUNET_FS_Uri *u2);
241 * @param uri the URI to duplicate
242 * @return copy of the URI
244 struct GNUNET_FS_Uri *
245 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
249 * Create an FS URI from a single user-supplied string of keywords.
250 * The string is broken up at spaces into individual keywords.
251 * Keywords that start with "+" are mandatory. Double-quotes can
252 * be used to prevent breaking up strings at spaces (and also
253 * to specify non-mandatory keywords starting with "+").
255 * Keywords must contain a balanced number of double quotes and
256 * double quotes can not be used in the actual keywords (for
257 * example, the string '""foo bar""' will be turned into two
258 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
260 * @param keywords the keyword string
261 * @param emsg where to store an error message
262 * @return an FS URI for the given keywords, NULL
263 * if keywords is not legal (i.e. empty).
265 struct GNUNET_FS_Uri *
266 GNUNET_FS_uri_ksk_create (const char *keywords,
271 * Create an FS URI from a user-supplied command line of keywords.
272 * Arguments should start with "+" to indicate mandatory
275 * @param argc number of keywords
276 * @param argv keywords (double quotes are not required for
277 * keywords containing spaces; however, double
278 * quotes are required for keywords starting with
279 * "+"); there is no mechanism for having double
280 * quotes in the actual keywords (if the user
281 * did specifically specify double quotes, the
282 * caller should convert each double quote
283 * into two single quotes).
284 * @return an FS URI for the given keywords, NULL
285 * if keywords is not legal (i.e. empty).
287 struct GNUNET_FS_Uri *
288 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
293 * Test if two URIs are equal.
295 * @param u1 one of the URIs
296 * @param u2 the other URI
297 * @return GNUNET_YES if the URIs are equal
300 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
301 const struct GNUNET_FS_Uri *u2);
305 * Is this a namespace URI?
307 * @param uri the uri to check
308 * @return GNUNET_YES if this is an SKS uri
311 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
315 * Get the ID of a namespace from the given
318 * @param uri the uri to get the namespace ID from
319 * @param nsid where to store the ID of the namespace
320 * @return GNUNET_OK on success
323 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
324 GNUNET_HashCode * nsid);
328 * Get the content identifier of an SKS URI.
330 * @param uri the sks uri
331 * @return NULL on error (not a valid SKS URI)
334 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
338 * Convert namespace URI to a human readable format
339 * (using the namespace description, if available).
341 * @param cfg configuration to use
342 * @param uri SKS uri to convert
343 * @return NULL on error (not an SKS URI)
346 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
347 const struct GNUNET_FS_Uri *uri);
351 * Is this a keyword URI?
354 * @return GNUNET_YES if this is a KSK uri
357 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
361 * Is this a file (or directory) URI?
363 * @param uri the uri to check
364 * @return GNUNET_YES if this is a CHK uri
367 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
371 * What is the size of the file that this URI
374 * @param uri the CHK (or LOC) URI to inspect
375 * @return size of the file as specified in the CHK URI
378 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
382 * Is this a location URI?
384 * @param uri the uri to check
385 * @return GNUNET_YES if this is a LOC uri
388 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
392 * Construct a keyword-URI from meta-data (take all entries
393 * in the meta-data and construct one large keyword URI
394 * that lists all keywords that can be found in the meta-data).
396 * @param md metadata to use
397 * @return NULL on error, otherwise a KSK URI
399 struct GNUNET_FS_Uri *
400 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
403 /* ******************** command-line option parsing API *********************** */
406 * Command-line option parser function that allows the user
407 * to specify one or more '-k' options with keywords. Each
408 * specified keyword will be added to the URI. A pointer to
409 * the URI must be passed as the "scls" argument.
411 * @param ctx command line processor context
412 * @param scls must be of type "struct GNUNET_FS_Uri **"
413 * @param option name of the option (typically 'k')
414 * @param value command line argument given
415 * @return GNUNET_OK on success
418 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
425 * Command-line option parser function that allows the user to specify
426 * one or more '-m' options with metadata. Each specified entry of
427 * the form "type=value" will be added to the metadata. A pointer to
428 * the metadata must be passed as the "scls" argument.
430 * @param ctx command line processor context
431 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
432 * @param option name of the option (typically 'k')
433 * @param value command line argument given
434 * @return GNUNET_OK on success
437 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
444 /* ************************* sharing API ***************** */
448 * Possible status codes used in the callback for the
449 * various file-sharing operations. On each file (or search),
450 * the callback is guaranteed to be called once with "START"
451 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
452 * are optional and depend on the circumstances; parent operations
453 * will be STARTED before child-operations and STOPPED after
454 * their respective child-operations. START and STOP signals
455 * are typically generated either due to explicit client requests
456 * or because of suspend/resume operations.
458 enum GNUNET_FS_Status
461 * Notification that we have started to publish a file structure.
463 GNUNET_FS_STATUS_PUBLISH_START,
466 * Notification that we have resumed sharing a file structure.
468 GNUNET_FS_STATUS_PUBLISH_RESUME,
471 * Notification that we have suspended sharing a file structure.
473 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
476 * Notification that we are making progress sharing a file structure.
478 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
481 * Notification that an error was encountered sharing a file structure.
482 * The application will continue to receive resume/suspend events for
483 * this structure until "GNUNET_FS_publish_stop" is called.
485 GNUNET_FS_STATUS_PUBLISH_ERROR,
488 * Notification that we completed sharing a file structure.
489 * The application will continue to receive resume/suspend events for
490 * this structure until "GNUNET_FS_publish_stop" is called.
492 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
495 * Notification that we have stopped
496 * the process of uploading a file structure; no
497 * futher events will be generated for this action.
499 GNUNET_FS_STATUS_PUBLISH_STOPPED,
502 * Notification that we have started this download.
504 GNUNET_FS_STATUS_DOWNLOAD_START,
507 * Notification that this download is being resumed.
509 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
512 * Notification that this download was suspended.
514 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
517 * Notification about progress with this download.
519 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
522 * Notification that this download encountered an error.
524 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
527 * Notification that this download completed. Note that for
528 * directories, completion does not imply completion of all files in
531 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
534 * Notification that this download was stopped
535 * (final event with respect to this action).
537 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
540 * First event generated when a client requests
541 * a search to begin or when a namespace result
542 * automatically triggers the search for updates.
544 GNUNET_FS_STATUS_SEARCH_START,
547 * Last event when a search is being resumed;
548 * note that "GNUNET_FS_SEARCH_START" will not
549 * be generated in this case.
551 GNUNET_FS_STATUS_SEARCH_RESUME,
554 * Event generated for each search result
555 * when the respective search is resumed.
557 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
560 * Last event when a search is being suspended;
561 * note that "GNUNET_FS_SEARCH_STOPPED" will not
562 * be generated in this case.
564 GNUNET_FS_STATUS_SEARCH_SUSPEND,
567 * Event generated for each search result
568 * when the respective search is suspended.
570 GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
573 * This search has yielded a result.
575 GNUNET_FS_STATUS_SEARCH_RESULT,
578 * We have discovered a new namespace.
580 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
583 * We have additional data about the quality
584 * or availability of a search result.
586 GNUNET_FS_STATUS_SEARCH_UPDATE,
589 * Signals a problem with this search.
591 GNUNET_FS_STATUS_SEARCH_ERROR,
594 * Signals that this search was paused.
596 GNUNET_FS_STATUS_SEARCH_PAUSED,
599 * Signals that this search was continued (unpaused).
601 GNUNET_FS_STATUS_SEARCH_CONTINUED,
604 * Event generated for each search result
605 * when the respective search is stopped.
607 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
610 * Last message from a search; this signals
611 * that there will be no further events associated
614 GNUNET_FS_STATUS_SEARCH_STOPPED,
617 * Notification that we started to unindex a file.
619 GNUNET_FS_STATUS_UNINDEX_START,
622 * Notification that we resumed unindexing of a file.
624 GNUNET_FS_STATUS_UNINDEX_RESUME,
627 * Notification that we suspended unindexing a file.
629 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
632 * Notification that we made progress unindexing a file.
634 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
637 * Notification that we encountered an error unindexing
640 GNUNET_FS_STATUS_UNINDEX_ERROR,
643 * Notification that the unindexing of this file
646 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
649 * Notification that the unindexing of this file
650 * was stopped (final event for this action).
652 GNUNET_FS_STATUS_UNINDEX_STOPPED
658 * Handle to one of our namespaces.
660 struct GNUNET_FS_Namespace;
664 * Handle for controlling an upload.
666 struct GNUNET_FS_PublishContext;
670 * Handle for controlling an unindexing operation.
672 struct GNUNET_FS_UnindexContext;
676 * Handle for controlling a search.
678 struct GNUNET_FS_SearchContext;
682 * Context for controlling a download.
684 struct GNUNET_FS_DownloadContext;
688 * Handle for detail information about a file that is being publishd.
689 * Specifies metadata, keywords, how to get the contents of the file
690 * (i.e. data-buffer in memory, filename on disk) and other options.
692 struct GNUNET_FS_FileInformation;
696 * Argument given to the progress callback with
697 * information about what is going on.
699 struct GNUNET_FS_ProgressInfo
703 * Values that depend on the event type.
708 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
713 * Context for controlling the upload.
715 struct GNUNET_FS_PublishContext *sc;
718 * Information about the file that is being publishd.
720 const struct GNUNET_FS_FileInformation *fi;
723 * Client context pointer (set the last time by the client for
724 * this operation; initially NULL on START/RESUME events).
729 * Client context pointer for the parent operation
730 * (if this is a file in a directory or a subdirectory).
735 * Name of the file being published; can be NULL.
737 const char *filename;
740 * How large is the file overall? For directories,
741 * this is only the size of the directory itself,
742 * not of the other files contained within the
748 * At what time do we expect to finish the upload?
749 * (will be a value in the past for completed
752 struct GNUNET_TIME_Relative eta;
755 * How long has this upload been actively running
756 * (excludes times where the upload was suspended).
758 struct GNUNET_TIME_Relative duration;
761 * How many bytes have we completed?
766 * What anonymity level is used for this upload?
771 * Additional values for specific events.
776 * These values are only valid for
777 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
782 * Data block we just published.
787 * At what offset in the file is "data"?
792 * Length of the data block.
797 * Depth of the given block in the tree;
798 * 0 would be the highest level (the first
799 * call is guaranteed to be for the lowest
807 * These values are only valid for
808 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
813 * Error message, NULL if no error was encountered so far.
818 * URI of the file (if the download had been completed)
820 const struct GNUNET_FS_Uri *chk_uri;
825 * These values are only valid for
826 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
833 const struct GNUNET_FS_Uri *chk_uri;
838 * These values are only valid for
839 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
844 * Error message, never NULL.
856 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
861 * Context for controlling the download.
863 struct GNUNET_FS_DownloadContext *dc;
866 * Client context pointer (set the last time
867 * by the client for this operation; initially
868 * NULL on START/RESUME events).
873 * Client context pointer for the parent operation
874 * (if this is a file in a directory or a subdirectory).
879 * URI used for this download.
881 const struct GNUNET_FS_Uri *uri;
884 * Name of the file that we are downloading.
886 const char *filename;
889 * How large is the download overall? This
890 * is NOT necessarily the size from the
891 * URI since we may be doing a partial download.
896 * At what time do we expect to finish the download?
897 * (will be a value in the past for completed
900 struct GNUNET_TIME_Relative eta;
903 * How long has this download been active?
905 struct GNUNET_TIME_Relative duration;
908 * How many bytes have we completed?
913 * What anonymity level is used for this download?
918 * Additional values for specific events.
923 * These values are only valid for
924 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
929 * Data block we just obtained.
934 * At what offset in the file is "data"?
939 * Length of the data block.
944 * Depth of the given block in the tree;
945 * 0 would be the highest level (the first
946 * call is guaranteed to be for the lowest
954 * These values are only valid for
955 * GNUNET_FS_STATUS_DOWNLOAD_START events.
960 * Known metadata for the download.
962 const struct GNUNET_CONTAINER_MetaData *meta;
967 * These values are only valid for
968 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
973 * Known metadata for the download.
975 const struct GNUNET_CONTAINER_MetaData *meta;
978 * Error message, NULL if we have not encountered any error yet.
985 * These values are only valid for
986 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1002 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1007 * Context for controlling the search, NULL for
1008 * searches that were not explicitly triggered
1009 * by the client (i.e., searches for updates in
1012 struct GNUNET_FS_SearchContext *sc;
1015 * Client context pointer (set the last time by the client for
1016 * this operation; initially NULL on START/RESUME events). Note
1017 * that this value can only be set on START/RESUME; returning
1018 * non-NULL on RESULT/RESUME_RESULT will actually update the
1019 * private context for "UPDATE" events.
1024 * Client parent-context pointer; NULL for top-level searches,
1025 * non-NULL for automatically triggered searches for updates in
1031 * What query is used for this search
1032 * (list of keywords or SKS identifier).
1034 const struct GNUNET_FS_Uri *query;
1037 * How long has this search been actively running
1038 * (excludes times where the search was paused or
1041 struct GNUNET_TIME_Relative duration;
1044 * What anonymity level is used for this search?
1049 * Additional values for specific events.
1054 * These values are only valid for
1055 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1060 * Metadata for the search result.
1062 const struct GNUNET_CONTAINER_MetaData *meta;
1065 * URI for the search result.
1067 const struct GNUNET_FS_Uri *uri;
1072 * These values are only valid for
1073 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1078 * Metadata for the search result.
1080 const struct GNUNET_CONTAINER_MetaData *meta;
1083 * URI for the search result.
1085 const struct GNUNET_FS_Uri *uri;
1088 * Current availability rank (negative:
1089 * unavailable, positive: available)
1091 int32_t availability_rank;
1094 * On how many total queries is the given
1095 * availability_rank based?
1097 uint32_t availabiliy_certainty;
1100 * Updated applicability rank (the larger,
1101 * the better the result fits the search
1104 uint32_t applicabiliy_rank;
1109 * These values are only valid for
1110 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1115 * Private context set for for this result
1116 * during the "RESULT" event.
1121 * Metadata for the search result.
1123 const struct GNUNET_CONTAINER_MetaData *meta;
1126 * URI for the search result.
1128 const struct GNUNET_FS_Uri *uri;
1131 * Current availability rank (negative:
1132 * unavailable, positive: available)
1134 int32_t availability_rank;
1137 * On how many total queries is the given
1138 * availability_rank based?
1140 uint32_t availability_certainty;
1143 * Updated applicability rank (the larger,
1144 * the better the result fits the search
1147 uint32_t applicability_rank;
1152 * These values are only valid for
1153 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1154 * These events are automatically triggered for
1155 * each search result before the
1156 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1157 * happens primarily to give the client a chance
1158 * to clean up the "cctx" (if needed).
1163 * Private context set for for this result
1164 * during the "RESULT" event.
1169 * Metadata for the search result.
1171 const struct GNUNET_CONTAINER_MetaData *meta;
1174 * URI for the search result.
1176 const struct GNUNET_FS_Uri *uri;
1181 * These values are only valid for
1182 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1183 * These events are automatically triggered for
1184 * each search result before the
1185 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1186 * happens primarily to give the client a chance
1187 * to clean up the "cctx" (if needed).
1192 * Private context set for for this result
1193 * during the "RESULT" event.
1198 * Metadata for the search result.
1200 const struct GNUNET_CONTAINER_MetaData *meta;
1203 * URI for the search result.
1205 const struct GNUNET_FS_Uri *uri;
1210 * These values are only valid for
1211 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1216 * Error message, NULL if we have not encountered any error yet.
1218 const char *message;
1221 * Is this search currently paused?
1228 * These values are only valid for
1229 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1236 const char *message;
1241 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1246 * Handle to the namespace (NULL if it is not a local
1249 struct GNUNET_FS_Namespace *ns;
1252 * Short, human-readable name of the namespace.
1257 * Root identifier for the namespace, can be NULL.
1262 * Metadata for the namespace.
1264 const struct GNUNET_CONTAINER_MetaData *meta;
1267 * Hash-identifier for the namespace.
1278 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1283 * Context for controlling the unindexing.
1285 struct GNUNET_FS_UnindexContext *uc;
1288 * Client context pointer (set the last time
1289 * by the client for this operation; initially
1290 * NULL on START/RESUME events).
1295 * Name of the file that is being unindexed.
1297 const char *filename;
1300 * How large is the file overall?
1305 * At what time do we expect to finish unindexing?
1306 * (will be a value in the past for completed
1307 * unindexing opeations).
1309 struct GNUNET_TIME_Relative eta;
1312 * How long has this upload been actively running
1313 * (excludes times where the upload was suspended).
1315 struct GNUNET_TIME_Relative duration;
1318 * How many bytes have we completed?
1323 * Additional values for specific events.
1328 * These values are only valid for
1329 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1334 * Data block we just unindexed.
1339 * At what offset in the file is "data"?
1344 * Length of the data block.
1349 * Depth of the given block in the tree;
1350 * 0 would be the highest level (the first
1351 * call is guaranteed to be for the lowest
1359 * These values are only valid for
1360 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1365 * Error message, NULL if we have not encountered any error yet.
1367 const char *message;
1372 * These values are only valid for
1373 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1380 const char *message;
1391 * Specific status code (determines the event type).
1393 enum GNUNET_FS_Status status;
1399 * Notification of FS to a client about the progress of an
1400 * operation. Callbacks of this type will be used for uploads,
1401 * downloads and searches. Some of the arguments depend a bit
1402 * in their meaning on the context in which the callback is used.
1404 * @param cls closure
1405 * @param info details about the event, specifying the event type
1406 * and various bits about the event
1407 * @return client-context (for the next progress call
1408 * for this operation; should be set to NULL for
1409 * SUSPEND and STOPPED events). The value returned
1410 * will be passed to future callbacks in the respective
1411 * field in the GNUNET_FS_ProgressInfo struct.
1413 typedef void* (*GNUNET_FS_ProgressCallback)
1415 const struct GNUNET_FS_ProgressInfo *info);
1419 * General (global) option flags for file-sharing.
1421 enum GNUNET_FS_Flags
1424 * No special flags set.
1426 GNUNET_FS_FLAGS_NONE = 0,
1429 * Is persistence of operations desired?
1430 * (will create SUSPEND/RESUME events).
1432 GNUNET_FS_FLAGS_PERSISTENCE = 1
1437 * Options specified in the VARARGs
1438 * portion of GNUNET_FS_start.
1440 enum GNUNET_FS_OPTIONS
1444 * Last option in the VARARG list.
1446 GNUNET_FS_OPTIONS_END = 0,
1449 * Select the desired amount of parallelism (this option should be
1450 * followed by an "unsigned int" giving the desired maximum number
1451 * of parallel downloads).
1453 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1
1459 * Handle to the file-sharing service.
1461 struct GNUNET_FS_Handle;
1465 * Setup a connection to the file-sharing service.
1467 * @param sched scheduler to use
1468 * @param cfg configuration to use
1469 * @param client_name unique identifier for this client
1470 * @param upcb function to call to notify about FS actions
1471 * @param upcb_cls closure for upcb
1472 * @param flags specific attributes for fs-operations
1473 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1474 * @return NULL on error
1476 struct GNUNET_FS_Handle *
1477 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1478 const struct GNUNET_CONFIGURATION_Handle *cfg,
1479 const char *client_name,
1480 GNUNET_FS_ProgressCallback upcb,
1482 enum GNUNET_FS_Flags flags,
1487 * Close our connection with the file-sharing service.
1488 * The callback given to GNUNET_FS_start will no longer be
1489 * called after this function returns.
1491 * @param h handle that was returned from GNUNET_FS_start
1494 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1498 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1500 * @param cls closure
1501 * @param fi the entry in the publish-structure
1502 * @param length length of the file or directory
1503 * @param meta metadata for the file or directory (can be modified)
1504 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1505 * @param anonymity pointer to selected anonymity level (can be modified)
1506 * @param priority pointer to selected priority (can be modified)
1507 * @param expirationTime pointer to selected expiration time (can be modified)
1508 * @param client_info pointer to client context set upon creation (can be modified)
1509 * @return GNUNET_OK to continue, GNUNET_NO to remove
1510 * this entry from the directory, GNUNET_SYSERR
1511 * to abort the iteration
1513 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1514 struct GNUNET_FS_FileInformation *fi,
1516 struct GNUNET_CONTAINER_MetaData *meta,
1517 struct GNUNET_FS_Uri **uri,
1518 uint32_t *anonymity,
1520 struct GNUNET_TIME_Absolute *expirationTime,
1521 void **client_info);
1525 * Recover file information structure from disk.
1527 * @param fn filename for the structure on disk
1528 * @return NULL on error
1530 struct GNUNET_FS_FileInformation *
1531 GNUNET_FS_file_information_recover (const char *fn);
1535 * Obtain the name under which this file information
1536 * structure is stored on disk. Only works for top-level
1537 * file information structures.
1539 * @param s structure to get the filename for
1540 * @return NULL on error, otherwise filename that
1541 * can be passed to "GNUNET_FS_file_information_recover"
1542 * to read this fi-struct from disk.
1545 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1549 * Synchronize this file-information struct with its mirror
1550 * on disk. Note that all internal FS-operations that change
1551 * file information data should already call "sync" internally,
1552 * so this function is likely not useful for clients.
1554 * @param fi the struct to sync
1557 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *f);
1561 * Create an entry for a file in a publish-structure.
1563 * @param client_info initial client-info value for this entry
1564 * @param filename name of the file or directory to publish
1565 * @param keywords under which keywords should this file be available
1566 * directly; can be NULL
1567 * @param meta metadata for the file
1568 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1569 * GNUNET_SYSERR for simulation
1570 * @param anonymity what is the desired anonymity level for sharing?
1571 * @param priority what is the priority for OUR node to
1572 * keep this file available? Use 0 for maximum anonymity and
1573 * minimum reliability...
1574 * @param expirationTime when should this content expire?
1575 * @return publish structure entry for the file
1577 struct GNUNET_FS_FileInformation *
1578 GNUNET_FS_file_information_create_from_file (void *client_info,
1579 const char *filename,
1580 const struct GNUNET_FS_Uri *keywords,
1581 const struct GNUNET_CONTAINER_MetaData *meta,
1585 struct GNUNET_TIME_Absolute expirationTime);
1589 * Create an entry for a file in a publish-structure.
1591 * @param client_info initial client-info value for this entry
1592 * @param length length of the file
1593 * @param data data for the file (should not be used afterwards by
1594 * the caller; callee will "free")
1595 * @param keywords under which keywords should this file be available
1596 * directly; can be NULL
1597 * @param meta metadata for the file
1598 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1599 * GNUNET_SYSERR for simulation
1600 * @param anonymity what is the desired anonymity level for sharing?
1601 * @param priority what is the priority for OUR node to
1602 * keep this file available? Use 0 for maximum anonymity and
1603 * minimum reliability...
1604 * @param expirationTime when should this content expire?
1605 * @return publish structure entry for the file
1607 struct GNUNET_FS_FileInformation *
1608 GNUNET_FS_file_information_create_from_data (void *client_info,
1611 const struct GNUNET_FS_Uri *keywords,
1612 const struct GNUNET_CONTAINER_MetaData *meta,
1616 struct GNUNET_TIME_Absolute expirationTime);
1620 * Function that provides data.
1622 * @param cls closure
1623 * @param offset offset to read from; it is possible
1624 * that the caller might need to go backwards
1626 * @param max maximum number of bytes that should be
1627 * copied to buf; readers are not allowed
1628 * to provide less data unless there is an error;
1629 * a value of "0" will be used at the end to allow
1630 * the reader to clean up its internal state
1631 * @param buf where the reader should write the data
1632 * @param emsg location for the reader to store an error message
1633 * @return number of bytes written, usually "max", 0 on error
1635 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1643 * Create an entry for a file in a publish-structure.
1645 * @param client_info initial client-info value for this entry
1646 * @param length length of the file
1647 * @param reader function that can be used to obtain the data for the file
1648 * @param reader_cls closure for "reader"
1649 * @param keywords under which keywords should this file be available
1650 * directly; can be NULL
1651 * @param meta metadata for the file
1652 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1653 * GNUNET_SYSERR for simulation
1654 * @param anonymity what is the desired anonymity level for sharing?
1655 * @param priority what is the priority for OUR node to
1656 * keep this file available? Use 0 for maximum anonymity and
1657 * minimum reliability...
1658 * @param expirationTime when should this content expire?
1659 * @return publish structure entry for the file
1661 struct GNUNET_FS_FileInformation *
1662 GNUNET_FS_file_information_create_from_reader (void *client_info,
1664 GNUNET_FS_DataReader reader,
1666 const struct GNUNET_FS_Uri *keywords,
1667 const struct GNUNET_CONTAINER_MetaData *meta,
1671 struct GNUNET_TIME_Absolute expirationTime);
1675 * Function that a "GNUNET_FS_DirectoryScanner" should call
1676 * for each entry in the directory.
1678 * @param cls closure
1679 * @param filename name of the file (including path); must end
1680 * in a "/" (even on W32) if this is a directory
1681 * @param fi information about the file (should not be
1682 * used henceforth by the caller)
1684 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1685 const char *filename,
1686 struct GNUNET_FS_FileInformation *fi);
1690 * Type of a function that will be used to scan a directory.
1692 * @param cls closure
1693 * @param dirname name of the directory to scan
1694 * @param do_index should files be indexed or inserted
1695 * @param anonymity desired anonymity level
1696 * @param priority priority for publishing
1697 * @param expirationTime expiration for publication
1698 * @param proc function to call on each entry
1699 * @param proc_cls closure for proc
1700 * @param emsg where to store an error message (on errors)
1701 * @return GNUNET_OK on success
1703 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1704 const char *dirname,
1708 struct GNUNET_TIME_Absolute expirationTime,
1709 GNUNET_FS_FileProcessor proc,
1716 * Simple, useful default implementation of a directory scanner
1717 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1718 * UNIX filename, will publish all files in the directory except hidden
1719 * files (those starting with a "."). Metadata will be extracted
1720 * using GNU libextractor; the specific list of plugins should be
1721 * specified in "cls", passing NULL will disable (!) metadata
1722 * extraction. Keywords will be derived from the metadata and be
1723 * subject to default canonicalization. This is strictly a
1724 * convenience function.
1726 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1727 * @param dirname name of the directory to scan
1728 * @param do_index should files be indexed or inserted
1729 * @param anonymity desired anonymity level
1730 * @param priority priority for publishing
1731 * @param expirationTime expiration for publication
1732 * @param proc function called on each entry
1733 * @param proc_cls closure for proc
1734 * @param emsg where to store an error message (on errors)
1735 * @return GNUNET_OK on success
1738 GNUNET_FS_directory_scanner_default (void *cls,
1739 const char *dirname,
1743 struct GNUNET_TIME_Absolute expirationTime,
1744 GNUNET_FS_FileProcessor proc,
1750 * Create a publish-structure from an existing file hierarchy, inferring
1751 * and organizing keywords and metadata as much as possible. This
1752 * function primarily performs the recursive build and re-organizes
1753 * keywords and metadata; for automatically getting metadata
1754 * extraction, scanning of directories and creation of the respective
1755 * GNUNET_FS_FileInformation entries the default scanner should be
1756 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1757 * convenience function.
1759 * @param client_info initial client-info value for this entry
1760 * @param filename name of the top-level file or directory
1761 * @param scanner function used to get a list of files in a directory
1762 * @param scanner_cls closure for scanner
1763 * @param do_index should files in the hierarchy be indexed?
1764 * @param anonymity what is the desired anonymity level for sharing?
1765 * @param priority what is the priority for OUR node to
1766 * keep this file available? Use 0 for maximum anonymity and
1767 * minimum reliability...
1768 * @param expirationTime when should this content expire?
1769 * @param emsg where to store an error message
1770 * @return publish structure entry for the directory, NULL on error
1772 struct GNUNET_FS_FileInformation *
1773 GNUNET_FS_file_information_create_from_directory (void *client_info,
1774 const char *filename,
1775 GNUNET_FS_DirectoryScanner scanner,
1780 struct GNUNET_TIME_Absolute expirationTime,
1785 * Create an entry for an empty directory in a publish-structure.
1786 * This function should be used by applications for which the
1787 * use of "GNUNET_FS_file_information_create_from_directory"
1788 * is not appropriate.
1790 * @param client_info initial client-info value for this entry
1791 * @param keywords under which keywords should this directory be available
1792 * directly; can be NULL
1793 * @param meta metadata for the directory
1794 * @param anonymity what is the desired anonymity level for sharing?
1795 * @param priority what is the priority for OUR node to
1796 * keep this file available? Use 0 for maximum anonymity and
1797 * minimum reliability...
1798 * @param expirationTime when should this content expire?
1799 * @return publish structure entry for the directory , NULL on error
1801 struct GNUNET_FS_FileInformation *
1802 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1803 const struct GNUNET_FS_Uri *keywords,
1804 const struct GNUNET_CONTAINER_MetaData *meta,
1807 struct GNUNET_TIME_Absolute expirationTime);
1811 * Add an entry to a directory in a publish-structure. Clients
1812 * should never modify publish structures that were passed to
1813 * "GNUNET_FS_publish_start" already.
1815 * @param dir the directory
1816 * @param ent the entry to add; the entry must not have been
1817 * added to any other directory at this point and
1818 * must not include "dir" in its structure
1819 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1822 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1823 struct GNUNET_FS_FileInformation *ent);
1827 * Inspect a file or directory in a publish-structure. Clients
1828 * should never modify publish structures that were passed to
1829 * "GNUNET_FS_publish_start" already. When called on a directory,
1830 * this function will FIRST call "proc" with information about
1831 * the directory itself and then for each of the files in the
1832 * directory (but not for files in subdirectories). When called
1833 * on a file, "proc" will be called exactly once (with information
1834 * about the specific file).
1836 * @param dir the directory
1837 * @param proc function to call on each entry
1838 * @param proc_cls closure for proc
1841 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1842 GNUNET_FS_FileInformationProcessor proc,
1847 * Destroy publish-structure. Clients should never destroy publish
1848 * structures that were passed to "GNUNET_FS_publish_start" already.
1850 * @param fi structure to destroy
1851 * @param cleaner function to call on each entry in the structure
1852 * (useful to clean up client_info); can be NULL; return
1853 * values are ignored
1854 * @param cleaner_cls closure for cleaner
1857 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1858 GNUNET_FS_FileInformationProcessor cleaner,
1863 * Options for publishing. Compatible options
1864 * can be OR'ed together.
1866 enum GNUNET_FS_PublishOptions
1869 * No options (use defaults for everything).
1871 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1874 * Simulate publishing. With this option, no data will be stored
1875 * in the datastore. Useful for computing URIs from files.
1877 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1881 * Publish a file or directory.
1883 * @param h handle to the file sharing subsystem
1884 * @param fi information about the file or directory structure to publish
1885 * @param namespace namespace to publish the file in, NULL for no namespace
1886 * @param nid identifier to use for the publishd content in the namespace
1887 * (can be NULL, must be NULL if namespace is NULL)
1888 * @param nuid update-identifier that will be used for future updates
1889 * (can be NULL, must be NULL if namespace or nid is NULL)
1890 * @param options options for the publication
1891 * @return context that can be used to control the publish operation
1893 struct GNUNET_FS_PublishContext *
1894 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1895 struct GNUNET_FS_FileInformation *fi,
1896 struct GNUNET_FS_Namespace *namespace,
1899 enum GNUNET_FS_PublishOptions options);
1903 * Stop an upload. Will abort incomplete uploads (but
1904 * not remove blocks that have already been publishd) or
1905 * simply clean up the state for completed uploads.
1906 * Must NOT be called from within the event callback!
1908 * @param sc context for the upload to stop
1911 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1915 * Signature of a function called as the continuation of a KBlock or
1916 * SBlock publication.
1918 * @param cls closure
1919 * @param uri URI under which the block is now available, NULL on error
1920 * @param emsg error message, NULL on success
1922 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1923 const struct GNUNET_FS_Uri *uri,
1928 * Publish a KBlock on GNUnet.
1930 * @param h handle to the file sharing subsystem
1931 * @param ksk_uri keywords to use
1932 * @param meta metadata to use
1933 * @param uri URI to refer to in the KBlock
1934 * @param expirationTime when the KBlock expires
1935 * @param anonymity anonymity level for the KBlock
1936 * @param priority priority for the KBlock
1937 * @param cont continuation
1938 * @param cont_cls closure for cont
1941 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1942 const struct GNUNET_FS_Uri *ksk_uri,
1943 const struct GNUNET_CONTAINER_MetaData *meta,
1944 const struct GNUNET_FS_Uri *uri,
1945 struct GNUNET_TIME_Absolute expirationTime,
1948 enum GNUNET_FS_PublishOptions options,
1949 GNUNET_FS_PublishContinuation cont,
1954 * Publish an SBlock on GNUnet.
1956 * @param h handle to the file sharing subsystem
1957 * @param namespace namespace to publish in
1958 * @param identifier identifier to use
1959 * @param update update identifier to use
1960 * @param meta metadata to use
1961 * @param uri URI to refer to in the SBlock
1962 * @param expirationTime when the SBlock expires
1963 * @param anonymity anonymity level for the SBlock
1964 * @param priority priority for the SBlock
1965 * @param cont continuation
1966 * @param cont_cls closure for cont
1969 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1970 struct GNUNET_FS_Namespace *namespace,
1971 const char *identifier,
1973 struct GNUNET_CONTAINER_MetaData *meta,
1974 const struct GNUNET_FS_Uri *uri,
1975 struct GNUNET_TIME_Absolute expirationTime,
1978 enum GNUNET_FS_PublishOptions options,
1979 GNUNET_FS_PublishContinuation cont,
1984 * Type of a function called by "GNUNET_FS_get_indexed_files".
1986 * @param cls closure
1987 * @param filename the name of the file
1988 * @param file_id hash of the contents of the indexed file
1989 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1991 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1992 const char *filename,
1993 const GNUNET_HashCode *file_id);
1997 * Iterate over all indexed files.
1999 * @param h handle to the file sharing subsystem
2000 * @param iterator function to call on each indexed file
2001 * @param iterator_cls closure for iterator
2002 * @param cont continuation to call when done;
2003 * reason should be "TIMEOUT" (on
2004 * error) or "PREREQ_DONE" (on success)
2005 * @param cont_cls closure for cont
2008 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2009 GNUNET_FS_IndexedFileProcessor iterator,
2011 GNUNET_SCHEDULER_Task cont,
2018 * @param h handle to the file sharing subsystem
2019 * @param filename file to unindex
2020 * @param cctx initial value for the client context
2021 * @return NULL on error, otherwise handle
2023 struct GNUNET_FS_UnindexContext *
2024 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2025 const char *filename,
2030 * Clean up after completion of an unindex operation.
2035 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2039 * Publish an advertismement for a namespace.
2041 * @param h handle to the file sharing subsystem
2042 * @param namespace handle for the namespace that should be advertised
2043 * @param meta meta-data for the namespace advertisement
2044 * @param anonymity for the namespace advertismement
2045 * @param priority for the namespace advertisement
2046 * @param expiration for the namespace advertisement
2047 * @param rootEntry name of the root of the namespace
2048 * @param cont continuation
2049 * @param cont_cls closure for cont
2052 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2053 struct GNUNET_FS_Namespace *namespace,
2054 const struct GNUNET_CONTAINER_MetaData *meta,
2057 struct GNUNET_TIME_Absolute expiration,
2058 const char *rootEntry,
2059 GNUNET_FS_PublishContinuation cont,
2064 * Create a namespace with the given name; if one already
2065 * exists, return a handle to the existing namespace.
2067 * @param h handle to the file sharing subsystem
2068 * @param name name to use for the namespace
2069 * @return handle to the namespace, NULL on error
2071 struct GNUNET_FS_Namespace *
2072 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2077 * Delete a namespace handle. Can be used for a clean shutdown (free
2078 * memory) or also to freeze the namespace to prevent further
2079 * insertions by anyone.
2081 * @param namespace handle to the namespace that should be deleted / freed
2082 * @param freeze prevents future insertions; creating a namespace
2083 * with the same name again will create a fresh namespace instead
2085 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2088 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2093 * Callback with information about local (!) namespaces.
2094 * Contains the names of the local namespace and the global
2097 * @param cls closure
2098 * @param name human-readable identifier of the namespace
2099 * @param id hash identifier for the namespace
2101 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2103 const GNUNET_HashCode *id);
2107 * Build a list of all available local (!) namespaces The returned
2108 * names are only the nicknames since we only iterate over the local
2111 * @param h handle to the file sharing subsystem
2112 * @param cb function to call on each known namespace
2113 * @param cb_cls closure for cb
2116 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2117 GNUNET_FS_NamespaceInfoProcessor cb,
2122 * Function called on updateable identifiers.
2124 * @param cls closure
2125 * @param last_id last identifier
2126 * @param last_uri uri used for the content published under the last_id
2127 * @param last_meta metadata associated with last_uri
2128 * @param next_id identifier that should be used for updates
2131 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2132 const char *last_id,
2133 const struct GNUNET_FS_Uri *last_uri,
2134 const struct GNUNET_CONTAINER_MetaData *last_meta,
2135 const char *next_id);
2139 * List all of the identifiers in the namespace for
2140 * which we could produce an update.
2142 * @param namespace namespace to inspect for updateable content
2143 * @param ip function to call on each updateable identifier
2144 * @param ip_cls closure for ip
2147 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2148 GNUNET_FS_IdentifierProcessor ip,
2153 * Start search for content.
2155 * @param h handle to the file sharing subsystem
2156 * @param uri specifies the search parameters; can be
2157 * a KSK URI or an SKS URI.
2158 * @param anonymity desired level of anonymity
2159 * @param cctx initial value for the client context
2160 * @return context that can be used to control the search
2162 struct GNUNET_FS_SearchContext *
2163 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2164 const struct GNUNET_FS_Uri *uri,
2172 * @param sc context for the search that should be paused
2175 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2179 * Continue paused search.
2181 * @param sc context for the search that should be resumed
2184 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2188 * Stop search for content.
2190 * @param sc context for the search that should be stopped
2193 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2199 * Options for downloading. Compatible options
2200 * can be OR'ed together.
2202 enum GNUNET_FS_DownloadOptions
2205 * No options (use defaults for everything).
2207 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2210 * Do a recursive download (that is, automatically trigger the
2211 * download of files in directories).
2213 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2216 * Do not append temporary data to
2217 * the target file (for the IBlocks).
2219 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2226 * Download parts of a file. Note that this will store
2227 * the blocks at the respective offset in the given file. Also, the
2228 * download is still using the blocking of the underlying FS
2229 * encoding. As a result, the download may *write* outside of the
2230 * given boundaries (if offset and length do not match the 32k FS
2231 * block boundaries). <p>
2233 * The given range can be used to focus a download towards a
2234 * particular portion of the file (optimization), not to strictly
2235 * limit the download to exactly those bytes.
2237 * @param h handle to the file sharing subsystem
2238 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2239 * @param meta known metadata for the file (can be NULL)
2240 * @param filename where to store the file, maybe NULL (then no file is
2241 * created on disk and data must be grabbed from the callbacks)
2242 * @param offset at what offset should we start the download (typically 0)
2243 * @param length how many bytes should be downloaded starting at offset
2244 * @param anonymity anonymity level to use for the download
2245 * @param options various download options
2246 * @param cctx initial value for the client context for this download
2247 * @param parent parent download to associate this download with (use NULL
2248 * for top-level downloads; useful for manually-triggered recursive downloads)
2249 * @return context that can be used to control this download
2251 struct GNUNET_FS_DownloadContext *
2252 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2253 const struct GNUNET_FS_Uri *uri,
2254 const struct GNUNET_CONTAINER_MetaData *meta,
2255 const char *filename,
2259 enum GNUNET_FS_DownloadOptions options,
2261 struct GNUNET_FS_DownloadContext *parent);
2265 * Stop a download (aborts if download is incomplete).
2267 * @param dc handle for the download
2268 * @param do_delete delete files of incomplete downloads
2271 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2276 * Initialize collection.
2278 * @param h handle to the file sharing subsystem
2279 * @param namespace namespace to use for the collection
2280 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2281 * namespace is already set for our collection
2284 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2285 struct GNUNET_FS_Namespace *namespace);
2291 * @param h handle to the file sharing subsystem
2292 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2295 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2299 * Are we using a collection?
2301 * @param h handle to the file sharing subsystem
2302 * @return NULL if there is no collection,
2304 struct GNUNET_FS_Namespace *
2305 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2309 * Publish an update of the current collection information to the
2310 * network now. The function has no effect if the collection has not
2311 * changed since the last publication. If we are currently not
2312 * collecting, this function does nothing.
2314 * @param h handle to the file sharing subsystem
2316 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2320 * If we are currently building a collection, publish the given file
2321 * information in that collection. If we are currently not
2322 * collecting, this function does nothing.
2324 * @param h handle to the file sharing subsystem
2325 * @param uri uri to add to the collection
2326 * @param meta metadata for the uri
2328 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2329 const struct GNUNET_FS_Uri *uri,
2330 const struct GNUNET_CONTAINER_MetaData *meta);
2336 /* ******************** Directory API *********************** */
2339 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2340 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2341 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2344 * Does the meta-data claim that this is a directory?
2345 * Checks if the mime-type is that of a GNUnet directory.
2347 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2348 * we have no mime-type information (treat as 'GNUNET_NO')
2351 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2355 * Set the MIMETYPE information for the given
2356 * metadata to "application/gnunet-directory".
2358 * @param md metadata to add mimetype to
2361 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2365 * Function used to process entries in a directory.
2367 * @param cls closure
2368 * @param filename name of the file in the directory
2369 * @param uri URI of the file
2370 * @param metadata metadata for the file; metadata for
2371 * the directory if everything else is NULL/zero
2372 * @param length length of the available data for the file
2373 * (of type size_t since data must certainly fit
2374 * into memory; if files are larger than size_t
2375 * permits, then they will certainly not be
2376 * embedded with the directory itself).
2377 * @param data data available for the file (length bytes)
2379 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2380 const char *filename,
2381 const struct GNUNET_FS_Uri *uri,
2382 const struct GNUNET_CONTAINER_MetaData *meta,
2388 * Iterate over all entries in a directory. Note that directories
2389 * are structured such that it is possible to iterate over the
2390 * individual blocks as well as over the entire directory. Thus
2391 * a client can call this function on the buffer in the
2392 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2393 * include the contents of (small) files embedded in the directory
2394 * itself; for those files, the processor may be given the
2395 * contents of the file directly by this function.
2397 * @param size number of bytes in data
2398 * @param data pointer to the beginning of the directory
2399 * @param offset offset of data in the directory
2400 * @param dep function to call on each entry
2401 * @param dep_cls closure for dep
2404 GNUNET_FS_directory_list_contents (size_t size,
2407 GNUNET_FS_DirectoryEntryProcessor dep,
2412 * Opaque handle to a directory builder.
2414 struct GNUNET_FS_DirectoryBuilder;
2417 * Create a directory builder.
2419 * @param mdir metadata for the directory
2421 struct GNUNET_FS_DirectoryBuilder *
2422 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2426 * Add an entry to a directory.
2428 * @param bld directory to extend
2429 * @param uri uri of the entry (must not be a KSK)
2430 * @param md metadata of the entry
2431 * @param data raw data of the entry, can be NULL, otherwise
2432 * data must point to exactly the number of bytes specified
2436 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2437 const struct GNUNET_FS_Uri *uri,
2438 const struct GNUNET_CONTAINER_MetaData *md,
2443 * Finish building the directory. Frees the
2444 * builder context and returns the directory
2447 * @param bld directory to finish
2448 * @param rsize set to the number of bytes needed
2449 * @param rdata set to the encoded directory
2450 * @return GNUNET_OK on success
2453 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2458 #if 0 /* keep Emacsens' auto-indent happy */