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 filename name of the file or directory to publish
1564 * @param keywords under which keywords should this file be available
1565 * directly; can be NULL
1566 * @param meta metadata for the file
1567 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1568 * GNUNET_SYSERR for simulation
1569 * @param anonymity what is the desired anonymity level for sharing?
1570 * @param priority what is the priority for OUR node to
1571 * keep this file available? Use 0 for maximum anonymity and
1572 * minimum reliability...
1573 * @param expirationTime when should this content expire?
1574 * @return publish structure entry for the file
1576 struct GNUNET_FS_FileInformation *
1577 GNUNET_FS_file_information_create_from_file (void *client_info,
1578 const char *filename,
1579 const struct GNUNET_FS_Uri *keywords,
1580 const struct GNUNET_CONTAINER_MetaData *meta,
1584 struct GNUNET_TIME_Absolute expirationTime);
1588 * Create an entry for a file in a publish-structure.
1590 * @param length length of the file
1591 * @param data data for the file (should not be used afterwards by
1592 * the caller; callee will "free")
1593 * @param keywords under which keywords should this file be available
1594 * directly; can be NULL
1595 * @param meta metadata for the file
1596 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1597 * GNUNET_SYSERR for simulation
1598 * @param anonymity what is the desired anonymity level for sharing?
1599 * @param priority what is the priority for OUR node to
1600 * keep this file available? Use 0 for maximum anonymity and
1601 * minimum reliability...
1602 * @param expirationTime when should this content expire?
1603 * @return publish structure entry for the file
1605 struct GNUNET_FS_FileInformation *
1606 GNUNET_FS_file_information_create_from_data (void *client_info,
1609 const struct GNUNET_FS_Uri *keywords,
1610 const struct GNUNET_CONTAINER_MetaData *meta,
1614 struct GNUNET_TIME_Absolute expirationTime);
1618 * Function that provides data.
1620 * @param cls closure
1621 * @param offset offset to read from; it is possible
1622 * that the caller might need to go backwards
1624 * @param max maximum number of bytes that should be
1625 * copied to buf; readers are not allowed
1626 * to provide less data unless there is an error;
1627 * a value of "0" will be used at the end to allow
1628 * the reader to clean up its internal state
1629 * @param buf where the reader should write the data
1630 * @param emsg location for the reader to store an error message
1631 * @return number of bytes written, usually "max", 0 on error
1633 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1641 * Create an entry for a file in a publish-structure.
1643 * @param length length of the file
1644 * @param reader function that can be used to obtain the data for the file
1645 * @param reader_cls closure for "reader"
1646 * @param keywords under which keywords should this file be available
1647 * directly; can be NULL
1648 * @param meta metadata for the file
1649 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1650 * GNUNET_SYSERR for simulation
1651 * @param anonymity what is the desired anonymity level for sharing?
1652 * @param priority what is the priority for OUR node to
1653 * keep this file available? Use 0 for maximum anonymity and
1654 * minimum reliability...
1655 * @param expirationTime when should this content expire?
1656 * @return publish structure entry for the file
1658 struct GNUNET_FS_FileInformation *
1659 GNUNET_FS_file_information_create_from_reader (void *client_info,
1661 GNUNET_FS_DataReader reader,
1663 const struct GNUNET_FS_Uri *keywords,
1664 const struct GNUNET_CONTAINER_MetaData *meta,
1668 struct GNUNET_TIME_Absolute expirationTime);
1672 * Function that a "GNUNET_FS_DirectoryScanner" should call
1673 * for each entry in the directory.
1675 * @param cls closure
1676 * @param filename name of the file (including path); must end
1677 * in a "/" (even on W32) if this is a directory
1678 * @param fi information about the file (should not be
1679 * used henceforth by the caller)
1681 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1682 const char *filename,
1683 struct GNUNET_FS_FileInformation *fi);
1687 * Type of a function that will be used to scan a directory.
1689 * @param cls closure
1690 * @param dirname name of the directory to scan
1691 * @param do_index should files be indexed or inserted
1692 * @param anonymity desired anonymity level
1693 * @param priority priority for publishing
1694 * @param expirationTime expiration for publication
1695 * @param proc function to call on each entry
1696 * @param proc_cls closure for proc
1697 * @param emsg where to store an error message (on errors)
1698 * @return GNUNET_OK on success
1700 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1701 const char *dirname,
1705 struct GNUNET_TIME_Absolute expirationTime,
1706 GNUNET_FS_FileProcessor proc,
1713 * Simple, useful default implementation of a directory scanner
1714 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1715 * UNIX filename, will publish all files in the directory except hidden
1716 * files (those starting with a "."). Metadata will be extracted
1717 * using GNU libextractor; the specific list of plugins should be
1718 * specified in "cls", passing NULL will disable (!) metadata
1719 * extraction. Keywords will be derived from the metadata and be
1720 * subject to default canonicalization. This is strictly a
1721 * convenience function.
1723 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1724 * @param dirname name of the directory to scan
1725 * @param do_index should files be indexed or inserted
1726 * @param anonymity desired anonymity level
1727 * @param priority priority for publishing
1728 * @param expirationTime expiration for publication
1729 * @param proc function called on each entry
1730 * @param proc_cls closure for proc
1731 * @param emsg where to store an error message (on errors)
1732 * @return GNUNET_OK on success
1735 GNUNET_FS_directory_scanner_default (void *cls,
1736 const char *dirname,
1740 struct GNUNET_TIME_Absolute expirationTime,
1741 GNUNET_FS_FileProcessor proc,
1747 * Create a publish-structure from an existing file hierarchy, inferring
1748 * and organizing keywords and metadata as much as possible. This
1749 * function primarily performs the recursive build and re-organizes
1750 * keywords and metadata; for automatically getting metadata
1751 * extraction, scanning of directories and creation of the respective
1752 * GNUNET_FS_FileInformation entries the default scanner should be
1753 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1754 * convenience function.
1756 * @param filename name of the top-level file or directory
1757 * @param scanner function used to get a list of files in a directory
1758 * @param scanner_cls closure for scanner
1759 * @param do_index should files in the hierarchy be indexed?
1760 * @param anonymity what is the desired anonymity level for sharing?
1761 * @param priority what is the priority for OUR node to
1762 * keep this file available? Use 0 for maximum anonymity and
1763 * minimum reliability...
1764 * @param expirationTime when should this content expire?
1765 * @param emsg where to store an error message
1766 * @return publish structure entry for the directory, NULL on error
1768 struct GNUNET_FS_FileInformation *
1769 GNUNET_FS_file_information_create_from_directory (void *client_info,
1770 const char *filename,
1771 GNUNET_FS_DirectoryScanner scanner,
1776 struct GNUNET_TIME_Absolute expirationTime,
1781 * Create an entry for an empty directory in a publish-structure.
1782 * This function should be used by applications for which the
1783 * use of "GNUNET_FS_file_information_create_from_directory"
1784 * is not appropriate.
1786 * @param meta metadata for the directory
1787 * @param keywords under which keywords should this directory be available
1788 * directly; can be NULL
1789 * @param anonymity what is the desired anonymity level for sharing?
1790 * @param priority what is the priority for OUR node to
1791 * keep this file available? Use 0 for maximum anonymity and
1792 * minimum reliability...
1793 * @param expirationTime when should this content expire?
1794 * @return publish structure entry for the directory , NULL on error
1796 struct GNUNET_FS_FileInformation *
1797 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1798 const struct GNUNET_CONTAINER_MetaData *meta,
1799 const struct GNUNET_FS_Uri *keywords,
1802 struct GNUNET_TIME_Absolute expirationTime);
1806 * Add an entry to a directory in a publish-structure. Clients
1807 * should never modify publish structures that were passed to
1808 * "GNUNET_FS_publish_start" already.
1810 * @param dir the directory
1811 * @param ent the entry to add; the entry must not have been
1812 * added to any other directory at this point and
1813 * must not include "dir" in its structure
1814 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1817 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1818 struct GNUNET_FS_FileInformation *ent);
1822 * Inspect a file or directory in a publish-structure. Clients
1823 * should never modify publish structures that were passed to
1824 * "GNUNET_FS_publish_start" already. When called on a directory,
1825 * this function will FIRST call "proc" with information about
1826 * the directory itself and then for each of the files in the
1827 * directory (but not for files in subdirectories). When called
1828 * on a file, "proc" will be called exactly once (with information
1829 * about the specific file).
1831 * @param dir the directory
1832 * @param proc function to call on each entry
1833 * @param proc_cls closure for proc
1836 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1837 GNUNET_FS_FileInformationProcessor proc,
1842 * Destroy publish-structure. Clients should never destroy publish
1843 * structures that were passed to "GNUNET_FS_publish_start" already.
1845 * @param fi structure to destroy
1846 * @param cleaner function to call on each entry in the structure
1847 * (useful to clean up client_info); can be NULL; return
1848 * values are ignored
1849 * @param cleaner_cls closure for cleaner
1852 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1853 GNUNET_FS_FileInformationProcessor cleaner,
1858 * Options for publishing. Compatible options
1859 * can be OR'ed together.
1861 enum GNUNET_FS_PublishOptions
1864 * No options (use defaults for everything).
1866 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1869 * Simulate publishing. With this option, no data will be stored
1870 * in the datastore. Useful for computing URIs from files.
1872 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1876 * Publish a file or directory.
1878 * @param h handle to the file sharing subsystem
1879 * @param fi information about the file or directory structure to publish
1880 * @param namespace namespace to publish the file in, NULL for no namespace
1881 * @param nid identifier to use for the publishd content in the namespace
1882 * (can be NULL, must be NULL if namespace is NULL)
1883 * @param nuid update-identifier that will be used for future updates
1884 * (can be NULL, must be NULL if namespace or nid is NULL)
1885 * @param options options for the publication
1886 * @return context that can be used to control the publish operation
1888 struct GNUNET_FS_PublishContext *
1889 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1890 struct GNUNET_FS_FileInformation *fi,
1891 struct GNUNET_FS_Namespace *namespace,
1894 enum GNUNET_FS_PublishOptions options);
1898 * Stop an upload. Will abort incomplete uploads (but
1899 * not remove blocks that have already been publishd) or
1900 * simply clean up the state for completed uploads.
1901 * Must NOT be called from within the event callback!
1903 * @param sc context for the upload to stop
1906 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1910 * Signature of a function called as the continuation of a KBlock or
1911 * SBlock publication.
1913 * @param cls closure
1914 * @param uri URI under which the block is now available, NULL on error
1915 * @param emsg error message, NULL on success
1917 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1918 const struct GNUNET_FS_Uri *uri,
1923 * Publish a KBlock on GNUnet.
1925 * @param h handle to the file sharing subsystem
1926 * @param ksk_uri keywords to use
1927 * @param meta metadata to use
1928 * @param uri URI to refer to in the KBlock
1929 * @param expirationTime when the KBlock expires
1930 * @param anonymity anonymity level for the KBlock
1931 * @param priority priority for the KBlock
1932 * @param cont continuation
1933 * @param cont_cls closure for cont
1936 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1937 struct GNUNET_FS_Uri *ksk_uri,
1938 struct GNUNET_CONTAINER_MetaData *meta,
1939 struct GNUNET_FS_Uri *uri,
1940 struct GNUNET_TIME_Absolute expirationTime,
1943 enum GNUNET_FS_PublishOptions options,
1944 GNUNET_FS_PublishContinuation cont,
1949 * Publish an SBlock on GNUnet.
1951 * @param h handle to the file sharing subsystem
1952 * @param namespace namespace to publish in
1953 * @param identifier identifier to use
1954 * @param update update identifier to use
1955 * @param meta metadata to use
1956 * @param uri URI to refer to in the SBlock
1957 * @param expirationTime when the SBlock expires
1958 * @param anonymity anonymity level for the SBlock
1959 * @param priority priority for the SBlock
1960 * @param cont continuation
1961 * @param cont_cls closure for cont
1964 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1965 struct GNUNET_FS_Namespace *namespace,
1966 const char *identifier,
1968 struct GNUNET_CONTAINER_MetaData *meta,
1969 struct GNUNET_FS_Uri *uri,
1970 struct GNUNET_TIME_Absolute expirationTime,
1973 enum GNUNET_FS_PublishOptions options,
1974 GNUNET_FS_PublishContinuation cont,
1979 * Type of a function called by "GNUNET_FS_get_indexed_files".
1981 * @param cls closure
1982 * @param filename the name of the file
1983 * @param file_id hash of the contents of the indexed file
1984 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1986 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1987 const char *filename,
1988 const GNUNET_HashCode *file_id);
1992 * Iterate over all indexed files.
1994 * @param h handle to the file sharing subsystem
1995 * @param iterator function to call on each indexed file
1996 * @param iterator_cls closure for iterator
1997 * @param cont continuation to call when done;
1998 * reason should be "TIMEOUT" (on
1999 * error) or "PREREQ_DONE" (on success)
2000 * @param cont_cls closure for cont
2003 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2004 GNUNET_FS_IndexedFileProcessor iterator,
2006 GNUNET_SCHEDULER_Task cont,
2013 * @param h handle to the file sharing subsystem
2014 * @param filename file to unindex
2015 * @param cctx initial value for the client context
2016 * @return NULL on error, otherwise handle
2018 struct GNUNET_FS_UnindexContext *
2019 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2020 const char *filename,
2025 * Clean up after completion of an unindex operation.
2030 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2034 * Publish an advertismement for a namespace.
2036 * @param h handle to the file sharing subsystem
2037 * @param namespace handle for the namespace that should be advertised
2038 * @param meta meta-data for the namespace advertisement
2039 * @param anonymity for the namespace advertismement
2040 * @param priority for the namespace advertisement
2041 * @param expiration for the namespace advertisement
2042 * @param advertisementURI the keyword (!) URI to advertise the
2043 * namespace under (we will create a GNUNET_EC_KNBlock)
2044 * @param rootEntry name of the root entry in the namespace (for
2045 * the namespace advertisement)
2047 * @return uri of the advertisement
2049 struct GNUNET_FS_Uri *
2050 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2051 struct GNUNET_FS_Namespace *namespace,
2052 const struct GNUNET_CONTAINER_MetaData *meta,
2055 struct GNUNET_TIME_Absolute expiration,
2056 const struct GNUNET_FS_Uri *advertisementURI,
2057 const char *rootEntry);
2061 * Create a namespace with the given name; if one already
2062 * exists, return a handle to the existing namespace.
2064 * @param h handle to the file sharing subsystem
2065 * @param name name to use for the namespace
2066 * @return handle to the namespace, NULL on error
2068 struct GNUNET_FS_Namespace *
2069 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2074 * Delete a namespace handle. Can be used for a clean shutdown (free
2075 * memory) or also to freeze the namespace to prevent further
2076 * insertions by anyone.
2078 * @param namespace handle to the namespace that should be deleted / freed
2079 * @param freeze prevents future insertions; creating a namespace
2080 * with the same name again will create a fresh namespace instead
2082 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2085 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2090 * Callback with information about local (!) namespaces.
2091 * Contains the names of the local namespace and the global
2094 * @param cls closure
2095 * @param name human-readable identifier of the namespace
2096 * @param id hash identifier for the namespace
2098 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2100 const GNUNET_HashCode *id);
2104 * Build a list of all available local (!) namespaces The returned
2105 * names are only the nicknames since we only iterate over the local
2108 * @param h handle to the file sharing subsystem
2109 * @param cb function to call on each known namespace
2110 * @param cb_cls closure for cb
2113 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2114 GNUNET_FS_NamespaceInfoProcessor cb,
2119 * Function called on updateable identifiers.
2121 * @param cls closure
2122 * @param last_id last identifier
2123 * @param last_uri uri used for the content published under the last_id
2124 * @param last_meta metadata associated with last_uri
2125 * @param next_id identifier that should be used for updates
2128 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2129 const char *last_id,
2130 const struct GNUNET_FS_Uri *last_uri,
2131 const struct GNUNET_CONTAINER_MetaData *last_meta,
2132 const char *next_id);
2136 * List all of the identifiers in the namespace for
2137 * which we could produce an update.
2139 * @param namespace namespace to inspect for updateable content
2140 * @param ip function to call on each updateable identifier
2141 * @param ip_cls closure for ip
2144 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2145 GNUNET_FS_IdentifierProcessor ip,
2150 * Start search for content.
2152 * @param h handle to the file sharing subsystem
2153 * @param uri specifies the search parameters; can be
2154 * a KSK URI or an SKS URI.
2155 * @param anonymity desired level of anonymity
2156 * @param cctx initial value for the client context
2157 * @return context that can be used to control the search
2159 struct GNUNET_FS_SearchContext *
2160 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2161 const struct GNUNET_FS_Uri *uri,
2169 * @param sc context for the search that should be paused
2172 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2176 * Continue paused search.
2178 * @param sc context for the search that should be resumed
2181 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2185 * Stop search for content.
2187 * @param sc context for the search that should be stopped
2190 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2196 * Options for downloading. Compatible options
2197 * can be OR'ed together.
2199 enum GNUNET_FS_DownloadOptions
2202 * No options (use defaults for everything).
2204 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2207 * Do a recursive download (that is, automatically trigger the
2208 * download of files in directories).
2210 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2213 * Do not append temporary data to
2214 * the target file (for the IBlocks).
2216 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2223 * Download parts of a file. Note that this will store
2224 * the blocks at the respective offset in the given file. Also, the
2225 * download is still using the blocking of the underlying FS
2226 * encoding. As a result, the download may *write* outside of the
2227 * given boundaries (if offset and length do not match the 32k FS
2228 * block boundaries). <p>
2230 * The given range can be used to focus a download towards a
2231 * particular portion of the file (optimization), not to strictly
2232 * limit the download to exactly those bytes.
2234 * @param h handle to the file sharing subsystem
2235 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2236 * @param meta known metadata for the file (can be NULL)
2237 * @param filename where to store the file, maybe NULL (then no file is
2238 * created on disk and data must be grabbed from the callbacks)
2239 * @param offset at what offset should we start the download (typically 0)
2240 * @param length how many bytes should be downloaded starting at offset
2241 * @param anonymity anonymity level to use for the download
2242 * @param options various download options
2243 * @param cctx initial value for the client context for this download
2244 * @param parent parent download to associate this download with (use NULL
2245 * for top-level downloads; useful for manually-triggered recursive downloads)
2246 * @return context that can be used to control this download
2248 struct GNUNET_FS_DownloadContext *
2249 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2250 const struct GNUNET_FS_Uri *uri,
2251 const struct GNUNET_CONTAINER_MetaData *meta,
2252 const char *filename,
2256 enum GNUNET_FS_DownloadOptions options,
2258 struct GNUNET_FS_DownloadContext *parent);
2262 * Stop a download (aborts if download is incomplete).
2264 * @param dc handle for the download
2265 * @param do_delete delete files of incomplete downloads
2268 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2273 * Initialize collection.
2275 * @param h handle to the file sharing subsystem
2276 * @param namespace namespace to use for the collection
2277 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2278 * namespace is already set for our collection
2281 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2282 struct GNUNET_FS_Namespace *namespace);
2288 * @param h handle to the file sharing subsystem
2289 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2292 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2296 * Are we using a collection?
2298 * @param h handle to the file sharing subsystem
2299 * @return NULL if there is no collection,
2301 struct GNUNET_FS_Namespace *
2302 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2306 * Publish an update of the current collection information to the
2307 * network now. The function has no effect if the collection has not
2308 * changed since the last publication. If we are currently not
2309 * collecting, this function does nothing.
2311 * @param h handle to the file sharing subsystem
2313 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2317 * If we are currently building a collection, publish the given file
2318 * information in that collection. If we are currently not
2319 * collecting, this function does nothing.
2321 * @param h handle to the file sharing subsystem
2322 * @param uri uri to add to the collection
2323 * @param meta metadata for the uri
2325 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2326 const struct GNUNET_FS_Uri *uri,
2327 const struct GNUNET_CONTAINER_MetaData *meta);
2333 /* ******************** Directory API *********************** */
2336 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2337 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2338 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2341 * Does the meta-data claim that this is a directory?
2342 * Checks if the mime-type is that of a GNUnet directory.
2344 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2345 * we have no mime-type information (treat as 'GNUNET_NO')
2348 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2352 * Set the MIMETYPE information for the given
2353 * metadata to "application/gnunet-directory".
2355 * @param md metadata to add mimetype to
2358 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2362 * Function used to process entries in a directory.
2364 * @param cls closure
2365 * @param filename name of the file in the directory
2366 * @param uri URI of the file
2367 * @param metadata metadata for the file; metadata for
2368 * the directory if everything else is NULL/zero
2369 * @param length length of the available data for the file
2370 * (of type size_t since data must certainly fit
2371 * into memory; if files are larger than size_t
2372 * permits, then they will certainly not be
2373 * embedded with the directory itself).
2374 * @param data data available for the file (length bytes)
2376 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2377 const char *filename,
2378 const struct GNUNET_FS_Uri *uri,
2379 const struct GNUNET_CONTAINER_MetaData *meta,
2385 * Iterate over all entries in a directory. Note that directories
2386 * are structured such that it is possible to iterate over the
2387 * individual blocks as well as over the entire directory. Thus
2388 * a client can call this function on the buffer in the
2389 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2390 * include the contents of (small) files embedded in the directory
2391 * itself; for those files, the processor may be given the
2392 * contents of the file directly by this function.
2394 * @param size number of bytes in data
2395 * @param data pointer to the beginning of the directory
2396 * @param offset offset of data in the directory
2397 * @param dep function to call on each entry
2398 * @param dep_cls closure for dep
2401 GNUNET_FS_directory_list_contents (size_t size,
2404 GNUNET_FS_DirectoryEntryProcessor dep,
2409 * Opaque handle to a directory builder.
2411 struct GNUNET_FS_DirectoryBuilder;
2414 * Create a directory builder.
2416 * @param mdir metadata for the directory
2418 struct GNUNET_FS_DirectoryBuilder *
2419 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2423 * Add an entry to a directory.
2425 * @param bld directory to extend
2426 * @param uri uri of the entry (must not be a KSK)
2427 * @param md metadata of the entry
2428 * @param data raw data of the entry, can be NULL, otherwise
2429 * data must point to exactly the number of bytes specified
2433 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2434 const struct GNUNET_FS_Uri *uri,
2435 const struct GNUNET_CONTAINER_MetaData *md,
2440 * Finish building the directory. Frees the
2441 * builder context and returns the directory
2444 * @param bld directory to finish
2445 * @param rsize set to the number of bytes needed
2446 * @param rdata set to the encoded directory
2447 * @return GNUNET_OK on success
2450 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2455 #if 0 /* keep Emacsens' auto-indent happy */