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
724 * by the client for this operation; initially
725 * NULL on START/RESUME events).
730 * Client context pointer for the parent operation
731 * (if this is a file in a directory or a subdirectory).
736 * Name of the file being published; can be NULL.
738 const char *filename;
741 * How large is the file overall? For directories,
742 * this is only the size of the directory itself,
743 * not of the other files contained within the
749 * At what time do we expect to finish the upload?
750 * (will be a value in the past for completed
753 struct GNUNET_TIME_Relative eta;
756 * How long has this upload been actively running
757 * (excludes times where the upload was suspended).
759 struct GNUNET_TIME_Relative duration;
762 * How many bytes have we completed?
767 * What anonymity level is used for this upload?
772 * Additional values for specific events.
777 * These values are only valid for
778 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
783 * Data block we just published.
788 * At what offset in the file is "data"?
793 * Length of the data block.
798 * Depth of the given block in the tree;
799 * 0 would be the highest level (the first
800 * call is guaranteed to be for the lowest
808 * These values are only valid for
809 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
814 * Error message, NULL if no error was encountered so far.
819 * URI of the file (if the download had been completed)
821 const struct GNUNET_FS_Uri *chk_uri;
826 * These values are only valid for
827 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
834 const struct GNUNET_FS_Uri *chk_uri;
839 * These values are only valid for
840 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
845 * Error message, never NULL.
857 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
862 * Context for controlling the download.
864 struct GNUNET_FS_DownloadContext *dc;
867 * Client context pointer (set the last time
868 * by the client for this operation; initially
869 * NULL on START/RESUME events).
874 * Client context pointer for the parent operation
875 * (if this is a file in a directory or a subdirectory).
880 * URI used for this download.
882 const struct GNUNET_FS_Uri *uri;
885 * Name of the file that we are downloading.
887 const char *filename;
890 * How large is the download overall? This
891 * is NOT necessarily the size from the
892 * URI since we may be doing a partial download.
897 * At what time do we expect to finish the download?
898 * (will be a value in the past for completed
901 struct GNUNET_TIME_Relative eta;
904 * How long has this download been active?
906 struct GNUNET_TIME_Relative duration;
909 * How many bytes have we completed?
914 * What anonymity level is used for this download?
919 * Additional values for specific events.
924 * These values are only valid for
925 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
930 * Data block we just obtained.
935 * At what offset in the file is "data"?
940 * Length of the data block.
945 * Depth of the given block in the tree;
946 * 0 would be the highest level (the first
947 * call is guaranteed to be for the lowest
955 * These values are only valid for
956 * GNUNET_FS_STATUS_DOWNLOAD_START events.
961 * Known metadata for the download.
963 const struct GNUNET_CONTAINER_MetaData *meta;
968 * These values are only valid for
969 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
974 * Known metadata for the download.
976 const struct GNUNET_CONTAINER_MetaData *meta;
979 * Error message, NULL if we have not encountered any error yet.
986 * These values are only valid for
987 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1003 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1008 * Context for controlling the search, NULL for
1009 * searches that were not explicitly triggered
1010 * by the client (i.e., searches for updates in
1013 struct GNUNET_FS_SearchContext *sc;
1016 * Client context pointer (set the last time by the client for
1017 * this operation; initially NULL on START/RESUME events). Note
1018 * that this value can only be set on START/RESUME; returning
1019 * non-NULL on RESULT/RESUME_RESULT will actually update the
1020 * private context for "UPDATE" events.
1025 * Client parent-context pointer; NULL for top-level searches,
1026 * non-NULL for automatically triggered searches for updates in
1032 * What query is used for this search
1033 * (list of keywords or SKS identifier).
1035 const struct GNUNET_FS_Uri *query;
1038 * How long has this search been actively running
1039 * (excludes times where the search was paused or
1042 struct GNUNET_TIME_Relative duration;
1045 * What anonymity level is used for this search?
1050 * Additional values for specific events.
1055 * These values are only valid for
1056 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1061 * Metadata for the search result.
1063 const struct GNUNET_CONTAINER_MetaData *meta;
1066 * URI for the search result.
1068 const struct GNUNET_FS_Uri *uri;
1073 * These values are only valid for
1074 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1079 * Metadata for the search result.
1081 const struct GNUNET_CONTAINER_MetaData *meta;
1084 * URI for the search result.
1086 const struct GNUNET_FS_Uri *uri;
1089 * Current availability rank (negative:
1090 * unavailable, positive: available)
1092 int32_t availability_rank;
1095 * On how many total queries is the given
1096 * availability_rank based?
1098 uint32_t availabiliy_certainty;
1101 * Updated applicability rank (the larger,
1102 * the better the result fits the search
1105 uint32_t applicabiliy_rank;
1110 * These values are only valid for
1111 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1116 * Private context set for for this result
1117 * during the "RESULT" event.
1122 * Metadata for the search result.
1124 const struct GNUNET_CONTAINER_MetaData *meta;
1127 * URI for the search result.
1129 const struct GNUNET_FS_Uri *uri;
1132 * Current availability rank (negative:
1133 * unavailable, positive: available)
1135 int32_t availability_rank;
1138 * On how many total queries is the given
1139 * availability_rank based?
1141 uint32_t availability_certainty;
1144 * Updated applicability rank (the larger,
1145 * the better the result fits the search
1148 uint32_t applicability_rank;
1153 * These values are only valid for
1154 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1155 * These events are automatically triggered for
1156 * each search result before the
1157 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1158 * happens primarily to give the client a chance
1159 * to clean up the "cctx" (if needed).
1164 * Private context set for for this result
1165 * during the "RESULT" event.
1170 * Metadata for the search result.
1172 const struct GNUNET_CONTAINER_MetaData *meta;
1175 * URI for the search result.
1177 const struct GNUNET_FS_Uri *uri;
1182 * These values are only valid for
1183 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1184 * These events are automatically triggered for
1185 * each search result before the
1186 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1187 * happens primarily to give the client a chance
1188 * to clean up the "cctx" (if needed).
1193 * Private context set for for this result
1194 * during the "RESULT" event.
1199 * Metadata for the search result.
1201 const struct GNUNET_CONTAINER_MetaData *meta;
1204 * URI for the search result.
1206 const struct GNUNET_FS_Uri *uri;
1211 * These values are only valid for
1212 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1217 * Error message, NULL if we have not encountered any error yet.
1219 const char *message;
1222 * Is this search currently paused?
1229 * These values are only valid for
1230 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1237 const char *message;
1242 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1247 * Handle to the namespace (NULL if it is not a local
1250 struct GNUNET_FS_Namespace *ns;
1253 * Short, human-readable name of the namespace.
1258 * Root identifier for the namespace, can be NULL.
1263 * Metadata for the namespace.
1265 const struct GNUNET_CONTAINER_MetaData *meta;
1268 * Hash-identifier for the namespace.
1279 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1284 * Context for controlling the unindexing.
1286 struct GNUNET_FS_UnindexContext *uc;
1289 * Client context pointer (set the last time
1290 * by the client for this operation; initially
1291 * NULL on START/RESUME events).
1296 * Name of the file that is being unindexed.
1298 const char *filename;
1301 * How large is the file overall?
1306 * At what time do we expect to finish unindexing?
1307 * (will be a value in the past for completed
1308 * unindexing opeations).
1310 struct GNUNET_TIME_Relative eta;
1313 * How long has this upload been actively running
1314 * (excludes times where the upload was suspended).
1316 struct GNUNET_TIME_Relative duration;
1319 * How many bytes have we completed?
1324 * Additional values for specific events.
1329 * These values are only valid for
1330 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1335 * Data block we just unindexed.
1340 * At what offset in the file is "data"?
1345 * Length of the data block.
1350 * Depth of the given block in the tree;
1351 * 0 would be the highest level (the first
1352 * call is guaranteed to be for the lowest
1360 * These values are only valid for
1361 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1366 * Error message, NULL if we have not encountered any error yet.
1368 const char *message;
1373 * These values are only valid for
1374 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1381 const char *message;
1392 * Specific status code (determines the event type).
1394 enum GNUNET_FS_Status status;
1400 * Notification of FS to a client about the progress of an
1401 * operation. Callbacks of this type will be used for uploads,
1402 * downloads and searches. Some of the arguments depend a bit
1403 * in their meaning on the context in which the callback is used.
1405 * @param cls closure
1406 * @param info details about the event, specifying the event type
1407 * and various bits about the event
1408 * @return client-context (for the next progress call
1409 * for this operation; should be set to NULL for
1410 * SUSPEND and STOPPED events). The value returned
1411 * will be passed to future callbacks in the respective
1412 * field in the GNUNET_FS_ProgressInfo struct.
1414 typedef void* (*GNUNET_FS_ProgressCallback)
1416 const struct GNUNET_FS_ProgressInfo *info);
1420 * General (global) option flags for file-sharing.
1422 enum GNUNET_FS_Flags
1425 * No special flags set.
1427 GNUNET_FS_FLAGS_NONE = 0,
1430 * Is persistence of operations desired?
1431 * (will create SUSPEND/RESUME events).
1433 GNUNET_FS_FLAGS_PERSISTENCE = 1
1438 * Options specified in the VARARGs
1439 * portion of GNUNET_FS_start.
1441 enum GNUNET_FS_OPTIONS
1445 * Last option in the VARARG list.
1447 GNUNET_FS_OPTIONS_END = 0,
1450 * Select the desired amount of parallelism (this option should be
1451 * followed by an "unsigned int" giving the desired maximum number
1452 * of parallel downloads).
1454 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1
1460 * Handle to the file-sharing service.
1462 struct GNUNET_FS_Handle;
1466 * Setup a connection to the file-sharing service.
1468 * @param sched scheduler to use
1469 * @param cfg configuration to use
1470 * @param client_name unique identifier for this client
1471 * @param upcb function to call to notify about FS actions
1472 * @param upcb_cls closure for upcb
1473 * @param flags specific attributes for fs-operations
1474 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1475 * @return NULL on error
1477 struct GNUNET_FS_Handle *
1478 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1479 const struct GNUNET_CONFIGURATION_Handle *cfg,
1480 const char *client_name,
1481 GNUNET_FS_ProgressCallback upcb,
1483 enum GNUNET_FS_Flags flags,
1488 * Close our connection with the file-sharing service.
1489 * The callback given to GNUNET_FS_start will no longer be
1490 * called after this function returns.
1492 * @param h handle that was returned from GNUNET_FS_start
1495 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1499 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1501 * @param cls closure
1502 * @param fi the entry in the publish-structure
1503 * @param length length of the file or directory
1504 * @param meta metadata for the file or directory (can be modified)
1505 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1506 * @param anonymity pointer to selected anonymity level (can be modified)
1507 * @param priority pointer to selected priority (can be modified)
1508 * @param expirationTime pointer to selected expiration time (can be modified)
1509 * @param client_info pointer to client context set upon creation (can be modified)
1510 * @return GNUNET_OK to continue, GNUNET_NO to remove
1511 * this entry from the directory, GNUNET_SYSERR
1512 * to abort the iteration
1514 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1515 struct GNUNET_FS_FileInformation *fi,
1517 struct GNUNET_CONTAINER_MetaData *meta,
1518 struct GNUNET_FS_Uri **uri,
1519 uint32_t *anonymity,
1521 struct GNUNET_TIME_Absolute *expirationTime,
1522 void **client_info);
1526 * Recover file information structure from disk.
1528 * @param fn filename for the structure on disk
1529 * @return NULL on error
1531 struct GNUNET_FS_FileInformation *
1532 GNUNET_FS_file_information_recover (const char *fn);
1536 * Obtain the name under which this file information
1537 * structure is stored on disk. Only works for top-level
1538 * file information structures.
1540 * @param s structure to get the filename for
1541 * @return NULL on error, otherwise filename that
1542 * can be passed to "GNUNET_FS_file_information_recover"
1543 * to read this fi-struct from disk.
1546 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1550 * Synchronize this file-information struct with its mirror
1551 * on disk. Note that all internal FS-operations that change
1552 * file information data should already call "sync" internally,
1553 * so this function is likely not useful for clients.
1555 * @param fi the struct to sync
1558 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *f);
1562 * Create an entry for a file in a publish-structure.
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 length length of the file
1592 * @param data data for the file (should not be used afterwards by
1593 * the caller; caller will "free")
1594 * @param keywords under which keywords should this file be available
1595 * directly; can be NULL
1596 * @param meta metadata for the file
1597 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1598 * GNUNET_SYSERR for simulation
1599 * @param anonymity what is the desired anonymity level for sharing?
1600 * @param priority what is the priority for OUR node to
1601 * keep this file available? Use 0 for maximum anonymity and
1602 * minimum reliability...
1603 * @param expirationTime when should this content expire?
1604 * @return publish structure entry for the file
1606 struct GNUNET_FS_FileInformation *
1607 GNUNET_FS_file_information_create_from_data (void *client_info,
1610 const struct GNUNET_FS_Uri *keywords,
1611 const struct GNUNET_CONTAINER_MetaData *meta,
1615 struct GNUNET_TIME_Absolute expirationTime);
1619 * Function that provides data.
1621 * @param cls closure
1622 * @param offset offset to read from; it is possible
1623 * that the caller might need to go backwards
1625 * @param max maximum number of bytes that should be
1626 * copied to buf; readers are not allowed
1627 * to provide less data unless there is an error;
1628 * a value of "0" will be used at the end to allow
1629 * the reader to clean up its internal state
1630 * @param buf where the reader should write the data
1631 * @param emsg location for the reader to store an error message
1632 * @return number of bytes written, usually "max", 0 on error
1634 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1642 * Create an entry for a file in a publish-structure.
1644 * @param length length of the file
1645 * @param reader function that can be used to obtain the data for the file
1646 * @param reader_cls closure for "reader"
1647 * @param keywords under which keywords should this file be available
1648 * directly; can be NULL
1649 * @param meta metadata for the file
1650 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1651 * GNUNET_SYSERR for simulation
1652 * @param anonymity what is the desired anonymity level for sharing?
1653 * @param priority what is the priority for OUR node to
1654 * keep this file available? Use 0 for maximum anonymity and
1655 * minimum reliability...
1656 * @param expirationTime when should this content expire?
1657 * @return publish structure entry for the file
1659 struct GNUNET_FS_FileInformation *
1660 GNUNET_FS_file_information_create_from_reader (void *client_info,
1662 GNUNET_FS_DataReader reader,
1664 const struct GNUNET_FS_Uri *keywords,
1665 const struct GNUNET_CONTAINER_MetaData *meta,
1669 struct GNUNET_TIME_Absolute expirationTime);
1673 * Function that a "GNUNET_FS_DirectoryScanner" should call
1674 * for each entry in the directory.
1676 * @param cls closure
1677 * @param filename name of the file (including path); must end
1678 * in a "/" (even on W32) if this is a directory
1679 * @param fi information about the file (should not be
1680 * used henceforth by the caller)
1682 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1683 const char *filename,
1684 struct GNUNET_FS_FileInformation *fi);
1688 * Type of a function that will be used to scan a directory.
1690 * @param cls closure
1691 * @param dirname name of the directory to scan
1692 * @param do_index should files be indexed or inserted
1693 * @param anonymity desired anonymity level
1694 * @param priority priority for publishing
1695 * @param expirationTime expiration for publication
1696 * @param proc function to call on each entry
1697 * @param proc_cls closure for proc
1698 * @param emsg where to store an error message (on errors)
1699 * @return GNUNET_OK on success
1701 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1702 const char *dirname,
1706 struct GNUNET_TIME_Absolute expirationTime,
1707 GNUNET_FS_FileProcessor proc,
1714 * Simple, useful default implementation of a directory scanner
1715 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1716 * UNIX filename, will publish all files in the directory except hidden
1717 * files (those starting with a "."). Metadata will be extracted
1718 * using GNU libextractor; the specific list of plugins should be
1719 * specified in "cls", passing NULL will disable (!) metadata
1720 * extraction. Keywords will be derived from the metadata and be
1721 * subject to default canonicalization. This is strictly a
1722 * convenience function.
1724 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1725 * @param dirname name of the directory to scan
1726 * @param do_index should files be indexed or inserted
1727 * @param anonymity desired anonymity level
1728 * @param priority priority for publishing
1729 * @param expirationTime expiration for publication
1730 * @param proc function called on each entry
1731 * @param proc_cls closure for proc
1732 * @param emsg where to store an error message (on errors)
1733 * @return GNUNET_OK on success
1736 GNUNET_FS_directory_scanner_default (void *cls,
1737 const char *dirname,
1741 struct GNUNET_TIME_Absolute expirationTime,
1742 GNUNET_FS_FileProcessor proc,
1748 * Create a publish-structure from an existing file hierarchy, inferring
1749 * and organizing keywords and metadata as much as possible. This
1750 * function primarily performs the recursive build and re-organizes
1751 * keywords and metadata; for automatically getting metadata
1752 * extraction, scanning of directories and creation of the respective
1753 * GNUNET_FS_FileInformation entries the default scanner should be
1754 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1755 * convenience function.
1757 * @param filename name of the top-level file or directory
1758 * @param scanner function used to get a list of files in a directory
1759 * @param scanner_cls closure for scanner
1760 * @param do_index should files in the hierarchy be indexed?
1761 * @param anonymity what is the desired anonymity level for sharing?
1762 * @param priority what is the priority for OUR node to
1763 * keep this file available? Use 0 for maximum anonymity and
1764 * minimum reliability...
1765 * @param expirationTime when should this content expire?
1766 * @param emsg where to store an error message
1767 * @return publish structure entry for the directory, NULL on error
1769 struct GNUNET_FS_FileInformation *
1770 GNUNET_FS_file_information_create_from_directory (void *client_info,
1771 const char *filename,
1772 GNUNET_FS_DirectoryScanner scanner,
1777 struct GNUNET_TIME_Absolute expirationTime,
1782 * Create an entry for an empty directory in a publish-structure.
1783 * This function should be used by applications for which the
1784 * use of "GNUNET_FS_file_information_create_from_directory"
1785 * is not appropriate.
1787 * @param meta metadata for the directory
1788 * @param keywords under which keywords should this directory be available
1789 * directly; can be NULL
1790 * @param anonymity what is the desired anonymity level for sharing?
1791 * @param priority what is the priority for OUR node to
1792 * keep this file available? Use 0 for maximum anonymity and
1793 * minimum reliability...
1794 * @param expirationTime when should this content expire?
1795 * @return publish structure entry for the directory , NULL on error
1797 struct GNUNET_FS_FileInformation *
1798 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1799 const struct GNUNET_CONTAINER_MetaData *meta,
1800 const struct GNUNET_FS_Uri *keywords,
1803 struct GNUNET_TIME_Absolute expirationTime);
1807 * Add an entry to a directory in a publish-structure. Clients
1808 * should never modify publish structures that were passed to
1809 * "GNUNET_FS_publish_start" already.
1811 * @param dir the directory
1812 * @param ent the entry to add; the entry must not have been
1813 * added to any other directory at this point and
1814 * must not include "dir" in its structure
1815 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1818 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1819 struct GNUNET_FS_FileInformation *ent);
1823 * Inspect a file or directory in a publish-structure. Clients
1824 * should never modify publish structures that were passed to
1825 * "GNUNET_FS_publish_start" already. When called on a directory,
1826 * this function will FIRST call "proc" with information about
1827 * the directory itself and then for each of the files in the
1828 * directory (but not for files in subdirectories). When called
1829 * on a file, "proc" will be called exactly once (with information
1830 * about the specific file).
1832 * @param dir the directory
1833 * @param proc function to call on each entry
1834 * @param proc_cls closure for proc
1837 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1838 GNUNET_FS_FileInformationProcessor proc,
1843 * Destroy publish-structure. Clients should never destroy publish
1844 * structures that were passed to "GNUNET_FS_publish_start" already.
1846 * @param fi structure to destroy
1847 * @param cleaner function to call on each entry in the structure
1848 * (useful to clean up client_info); can be NULL; return
1849 * values are ignored
1850 * @param cleaner_cls closure for cleaner
1853 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1854 GNUNET_FS_FileInformationProcessor cleaner,
1859 * Options for publishing. Compatible options
1860 * can be OR'ed together.
1862 enum GNUNET_FS_PublishOptions
1865 * No options (use defaults for everything).
1867 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1870 * Simulate publishing. With this option, no data will be stored
1871 * in the datastore. Useful for computing URIs from files.
1873 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1877 * Publish a file or directory.
1879 * @param h handle to the file sharing subsystem
1880 * @param ctx initial value to use for the '*ctx'
1881 * in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1882 * @param fi information about the file or directory structure to publish
1883 * @param namespace namespace to publish the file in, NULL for no namespace
1884 * @param nid identifier to use for the publishd content in the namespace
1885 * (can be NULL, must be NULL if namespace is NULL)
1886 * @param nuid update-identifier that will be used for future updates
1887 * (can be NULL, must be NULL if namespace or nid is NULL)
1888 * @param options options for the publication
1889 * @return context that can be used to control the publish operation
1891 struct GNUNET_FS_PublishContext *
1892 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1894 struct GNUNET_FS_FileInformation *fi,
1895 struct GNUNET_FS_Namespace *namespace,
1898 enum GNUNET_FS_PublishOptions options);
1902 * Stop an upload. Will abort incomplete uploads (but
1903 * not remove blocks that have already been publishd) or
1904 * simply clean up the state for completed uploads.
1906 * @param sc context for the upload to stop
1909 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1913 * Signature of a function called as the continuation of a KBlock or
1914 * SBlock publication.
1916 * @param cls closure
1917 * @param uri URI under which the block is now available, NULL on error
1918 * @param emsg error message, NULL on success
1920 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1921 const struct GNUNET_FS_Uri *uri,
1926 * Publish a KBlock on GNUnet.
1928 * @param h handle to the file sharing subsystem
1929 * @param ksk_uri keywords to use
1930 * @param meta metadata to use
1931 * @param uri URI to refer to in the KBlock
1932 * @param expirationTime when the KBlock expires
1933 * @param anonymity anonymity level for the KBlock
1934 * @param priority priority for the KBlock
1935 * @param cont continuation
1936 * @param cont_cls closure for cont
1939 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1940 struct GNUNET_FS_Uri *ksk_uri,
1941 struct GNUNET_CONTAINER_MetaData *meta,
1942 struct GNUNET_FS_Uri *uri,
1943 struct GNUNET_TIME_Absolute expirationTime,
1946 enum GNUNET_FS_PublishOptions options,
1947 GNUNET_FS_PublishContinuation cont,
1952 * Publish an SBlock on GNUnet.
1954 * @param h handle to the file sharing subsystem
1955 * @param namespace namespace to publish in
1956 * @param identifier identifier to use
1957 * @param update update identifier to use
1958 * @param meta metadata to use
1959 * @param uri URI to refer to in the SBlock
1960 * @param expirationTime when the SBlock expires
1961 * @param anonymity anonymity level for the SBlock
1962 * @param priority priority for the SBlock
1963 * @param cont continuation
1964 * @param cont_cls closure for cont
1967 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1968 struct GNUNET_FS_Namespace *namespace,
1969 const char *identifier,
1971 struct GNUNET_CONTAINER_MetaData *meta,
1972 struct GNUNET_FS_Uri *uri,
1973 struct GNUNET_TIME_Absolute expirationTime,
1976 enum GNUNET_FS_PublishOptions options,
1977 GNUNET_FS_PublishContinuation cont,
1982 * Type of a function called by "GNUNET_FS_get_indexed_files".
1984 * @param cls closure
1985 * @param filename the name of the file
1986 * @param file_id hash of the contents of the indexed file
1987 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1989 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1990 const char *filename,
1991 const GNUNET_HashCode *file_id);
1995 * Iterate over all indexed files.
1997 * @param h handle to the file sharing subsystem
1998 * @param iterator function to call on each indexed file
1999 * @param iterator_cls closure for iterator
2000 * @param cont continuation to call when done;
2001 * reason should be "TIMEOUT" (on
2002 * error) or "PREREQ_DONE" (on success)
2003 * @param cont_cls closure for cont
2006 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2007 GNUNET_FS_IndexedFileProcessor iterator,
2009 GNUNET_SCHEDULER_Task cont,
2016 * @param h handle to the file sharing subsystem
2017 * @param filename file to unindex
2018 * @return NULL on error, otherwise handle
2020 struct GNUNET_FS_UnindexContext *
2021 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
2022 const char *filename);
2026 * Clean up after completion of an unindex operation.
2031 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2035 * Publish an advertismement for a namespace.
2037 * @param h handle to the file sharing subsystem
2038 * @param namespace handle for the namespace that should be advertised
2039 * @param meta meta-data for the namespace advertisement
2040 * @param anonymity for the namespace advertismement
2041 * @param priority for the namespace advertisement
2042 * @param expiration for the namespace advertisement
2043 * @param advertisementURI the keyword (!) URI to advertise the
2044 * namespace under (we will create a GNUNET_EC_KNBlock)
2045 * @param rootEntry name of the root entry in the namespace (for
2046 * the namespace advertisement)
2048 * @return uri of the advertisement
2050 struct GNUNET_FS_Uri *
2051 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2052 struct GNUNET_FS_Namespace *namespace,
2053 const struct GNUNET_CONTAINER_MetaData *meta,
2056 struct GNUNET_TIME_Absolute expiration,
2057 const struct GNUNET_FS_Uri *advertisementURI,
2058 const char *rootEntry);
2062 * Create a namespace with the given name; if one already
2063 * exists, return a handle to the existing namespace.
2065 * @param h handle to the file sharing subsystem
2066 * @param name name to use for the namespace
2067 * @return handle to the namespace, NULL on error
2069 struct GNUNET_FS_Namespace *
2070 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2075 * Delete a namespace handle. Can be used for a clean shutdown (free
2076 * memory) or also to freeze the namespace to prevent further
2077 * insertions by anyone.
2079 * @param namespace handle to the namespace that should be deleted / freed
2080 * @param freeze prevents future insertions; creating a namespace
2081 * with the same name again will create a fresh namespace instead
2083 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2086 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2091 * Callback with information about local (!) namespaces.
2092 * Contains the names of the local namespace and the global
2095 * @param cls closure
2096 * @param name human-readable identifier of the namespace
2097 * @param id hash identifier for the namespace
2099 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2101 const GNUNET_HashCode *id);
2105 * Build a list of all available local (!) namespaces The returned
2106 * names are only the nicknames since we only iterate over the local
2109 * @param h handle to the file sharing subsystem
2110 * @param cb function to call on each known namespace
2111 * @param cb_cls closure for cb
2114 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2115 GNUNET_FS_NamespaceInfoProcessor cb,
2120 * Function called on updateable identifiers.
2122 * @param cls closure
2123 * @param last_id last identifier
2124 * @param last_uri uri used for the content published under the last_id
2125 * @param last_meta metadata associated with last_uri
2126 * @param next_id identifier that should be used for updates
2129 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2130 const char *last_id,
2131 const struct GNUNET_FS_Uri *last_uri,
2132 const struct GNUNET_CONTAINER_MetaData *last_meta,
2133 const char *next_id);
2137 * List all of the identifiers in the namespace for
2138 * which we could produce an update.
2140 * @param namespace namespace to inspect for updateable content
2141 * @param ip function to call on each updateable identifier
2142 * @param ip_cls closure for ip
2145 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2146 GNUNET_FS_IdentifierProcessor ip,
2151 * Start search for content.
2153 * @param h handle to the file sharing subsystem
2154 * @param uri specifies the search parameters; can be
2155 * a KSK URI or an SKS URI.
2156 * @param anonymity desired level of anonymity
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,
2162 uint32_t anonymity);
2168 * @param sc context for the search that should be paused
2171 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2175 * Continue paused search.
2177 * @param sc context for the search that should be resumed
2180 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2184 * Stop search for content.
2186 * @param sc context for the search that should be stopped
2189 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2195 * Options for downloading. Compatible options
2196 * can be OR'ed together.
2198 enum GNUNET_FS_DownloadOptions
2201 * No options (use defaults for everything).
2203 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2206 * Do a recursive download (that is, automatically trigger the
2207 * download of files in directories).
2209 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2212 * Do not append temporary data to
2213 * the target file (for the IBlocks).
2215 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2222 * Download parts of a file. Note that this will store
2223 * the blocks at the respective offset in the given file. Also, the
2224 * download is still using the blocking of the underlying FS
2225 * encoding. As a result, the download may *write* outside of the
2226 * given boundaries (if offset and length do not match the 32k FS
2227 * block boundaries). <p>
2229 * The given range can be used to focus a download towards a
2230 * particular portion of the file (optimization), not to strictly
2231 * limit the download to exactly those bytes.
2233 * @param h handle to the file sharing subsystem
2234 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2235 * @param meta known metadata for the file (can be NULL)
2236 * @param filename where to store the file, maybe NULL (then no file is
2237 * created on disk and data must be grabbed from the callbacks)
2238 * @param offset at what offset should we start the download (typically 0)
2239 * @param length how many bytes should be downloaded starting at offset
2240 * @param anonymity anonymity level to use for the download
2241 * @param options various download options
2242 * @param parent parent download to associate this download with (use NULL
2243 * for top-level downloads; useful for manually-triggered recursive downloads)
2244 * @return context that can be used to control this download
2246 struct GNUNET_FS_DownloadContext *
2247 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
2248 const struct GNUNET_FS_Uri *uri,
2249 const struct GNUNET_CONTAINER_MetaData *meta,
2250 const char *filename,
2254 enum GNUNET_FS_DownloadOptions options,
2255 struct GNUNET_FS_DownloadContext *parent);
2259 * Stop a download (aborts if download is incomplete).
2261 * @param dc handle for the download
2262 * @param do_delete delete files of incomplete downloads
2265 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *dc,
2270 * Initialize collection.
2272 * @param h handle to the file sharing subsystem
2273 * @param namespace namespace to use for the collection
2274 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2275 * namespace is already set for our collection
2278 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2279 struct GNUNET_FS_Namespace *namespace);
2285 * @param h handle to the file sharing subsystem
2286 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2289 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2293 * Are we using a collection?
2295 * @param h handle to the file sharing subsystem
2296 * @return NULL if there is no collection,
2298 struct GNUNET_FS_Namespace *
2299 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2303 * Publish an update of the current collection information to the
2304 * network now. The function has no effect if the collection has not
2305 * changed since the last publication. If we are currently not
2306 * collecting, this function does nothing.
2308 * @param h handle to the file sharing subsystem
2310 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2314 * If we are currently building a collection, publish the given file
2315 * information in that collection. If we are currently not
2316 * collecting, this function does nothing.
2318 * @param h handle to the file sharing subsystem
2319 * @param uri uri to add to the collection
2320 * @param meta metadata for the uri
2322 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2323 const struct GNUNET_FS_Uri *uri,
2324 const struct GNUNET_CONTAINER_MetaData *meta);
2330 /* ******************** Directory API *********************** */
2333 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2334 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2335 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2338 * Does the meta-data claim that this is a directory?
2339 * Checks if the mime-type is that of a GNUnet directory.
2341 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2342 * we have no mime-type information (treat as 'GNUNET_NO')
2345 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2349 * Set the MIMETYPE information for the given
2350 * metadata to "application/gnunet-directory".
2352 * @param md metadata to add mimetype to
2355 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2359 * Function used to process entries in a directory.
2361 * @param cls closure
2362 * @param filename name of the file in the directory
2363 * @param uri URI of the file
2364 * @param metadata metadata for the file; metadata for
2365 * the directory if everything else is NULL/zero
2366 * @param length length of the available data for the file
2367 * (of type size_t since data must certainly fit
2368 * into memory; if files are larger than size_t
2369 * permits, then they will certainly not be
2370 * embedded with the directory itself).
2371 * @param data data available for the file (length bytes)
2373 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2374 const char *filename,
2375 const struct GNUNET_FS_Uri *uri,
2376 const struct GNUNET_CONTAINER_MetaData *meta,
2382 * Iterate over all entries in a directory. Note that directories
2383 * are structured such that it is possible to iterate over the
2384 * individual blocks as well as over the entire directory. Thus
2385 * a client can call this function on the buffer in the
2386 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2387 * include the contents of (small) files embedded in the directory
2388 * itself; for those files, the processor may be given the
2389 * contents of the file directly by this function.
2391 * @param size number of bytes in data
2392 * @param data pointer to the beginning of the directory
2393 * @param offset offset of data in the directory
2394 * @param dep function to call on each entry
2395 * @param dep_cls closure for dep
2398 GNUNET_FS_directory_list_contents (size_t size,
2401 GNUNET_FS_DirectoryEntryProcessor dep,
2406 * Opaque handle to a directory builder.
2408 struct GNUNET_FS_DirectoryBuilder;
2411 * Create a directory builder.
2413 * @param mdir metadata for the directory
2415 struct GNUNET_FS_DirectoryBuilder *
2416 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2420 * Add an entry to a directory.
2422 * @param bld directory to extend
2423 * @param uri uri of the entry (must not be a KSK)
2424 * @param md metadata of the entry
2425 * @param data raw data of the entry, can be NULL, otherwise
2426 * data must point to exactly the number of bytes specified
2430 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2431 const struct GNUNET_FS_Uri *uri,
2432 const struct GNUNET_CONTAINER_MetaData *md,
2437 * Finish building the directory. Frees the
2438 * builder context and returns the directory
2441 * @param bld directory to finish
2442 * @param rsize set to the number of bytes needed
2443 * @param rdata set to the encoded directory
2444 * @return GNUNET_OK on success
2447 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2452 #if 0 /* keep Emacsens' auto-indent happy */