2 This file is part of GNUnet
3 (C) 2004--2013 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 3, 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
25 #ifndef GNUNET_FS_LIB_H
26 #define GNUNET_FS_LIB_H
28 #include "gnunet_util_lib.h"
33 #if 0 /* keep Emacsens' auto-indent happy */
39 * Version number of the implementation.
42 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
43 * 2.x.x: root node with mime-type, filename and version number
44 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
45 * 2.2.x: with directories
46 * 3.0.x: with namespaces
47 * 3.1.x: with namespace meta-data
48 * 3.2.x: with collections
49 * 4.0.x: with expiration, variable meta-data, kblocks
50 * 4.1.x: with new error and configuration handling
51 * 5.0.x: with location URIs
52 * 6.0.0: with support for OR in KSKs
53 * 6.1.x: with simplified namespace support
54 * 9.0.0: CPS-style integrated API
55 * 9.1.1: asynchronous directory scanning
56 * 9.2.0: unified K-Block and S-block format (#2564)
58 #define GNUNET_FS_VERSION 0x00090200
61 /* ******************** URI API *********************** */
63 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
64 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
65 #define GNUNET_FS_URI_SKS_INFIX "sks/"
66 #define GNUNET_FS_URI_CHK_INFIX "chk/"
67 #define GNUNET_FS_URI_LOC_INFIX "loc/"
71 * How often do we signal applications that a probe for a particular
72 * search result is running? (used to visualize probes).
74 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
77 * A Universal Resource Identifier (URI), opaque.
83 * Iterator over keywords
86 * @param keyword the keyword
87 * @param is_mandatory is the keyword mandatory (in a search)
88 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
90 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
96 * Get a unique key from a URI. This is for putting URIs
97 * into HashMaps. The key may change between FS implementations.
99 * @param uri uri to convert to a unique key
100 * @param key wherer to store the unique key
103 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
104 struct GNUNET_HashCode *key);
108 * Convert a URI to a UTF-8 String.
110 * @param uri uri to convert to a string
111 * @return the UTF-8 string
114 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
118 * Convert keyword URI to a human readable format
119 * (i.e. the search query that was used in the first place)
121 * @param uri ksk uri to convert to a string
122 * @return string with the keywords
125 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
129 * Add the given keyword to the set of keywords represented by the URI.
130 * Does nothing if the keyword is already present.
132 * @param uri ksk uri to modify
133 * @param keyword keyword to add
134 * @param is_mandatory is this keyword mandatory?
137 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
143 * Remove the given keyword from the set of keywords represented by the URI.
144 * Does nothing if the keyword is not present.
146 * @param uri ksk uri to modify
147 * @param keyword keyword to add
150 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
151 const char *keyword);
155 * Convert a UTF-8 String to a URI.
157 * @param uri string to parse
158 * @param emsg where to store the parser error message (if any)
159 * @return NULL on error
161 struct GNUNET_FS_Uri *
162 GNUNET_FS_uri_parse (const char *uri, char **emsg);
168 * @param uri uri to free
171 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
175 * How many keywords are ANDed in this keyword URI?
177 * @param uri ksk uri to get the number of keywords from
178 * @return 0 if this is not a keyword URI
181 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
185 * Iterate over all keywords in this keyword URI.
187 * @param uri ksk uri to get the keywords from
188 * @param iterator function to call on each keyword
189 * @param iterator_cls closure for @a iterator
190 * @return -1 if this is not a keyword URI, otherwise number of
191 * keywords iterated over until iterator aborted
194 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
195 GNUNET_FS_KeywordIterator iterator,
200 * Obtain the identity of the peer offering the data
202 * @param uri the location URI to inspect
203 * @param peer where to store the identify of the peer (presumably) offering the content
204 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
207 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
208 struct GNUNET_PeerIdentity *peer);
212 * Obtain the URI of the content itself.
214 * @param uri location URI to get the content URI from
215 * @return NULL if argument is not a location URI
217 struct GNUNET_FS_Uri *
218 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
222 * Obtain the expiration of the LOC URI.
224 * @param uri location URI to get the expiration from
225 * @return expiration time of the URI
227 struct GNUNET_TIME_Absolute
228 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
232 * Construct a location URI (this peer will be used for the location).
234 * @param baseUri content offered by the sender
235 * @param cfg configuration information (used to find our hostkey)
236 * @param expiration_time how long will the content be offered?
237 * @return the location URI, NULL on error
239 struct GNUNET_FS_Uri *
240 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
241 const struct GNUNET_CONFIGURATION_Handle *cfg,
242 struct GNUNET_TIME_Absolute expiration_time);
246 * Merge the sets of keywords from two KSK URIs.
248 * @param u1 first uri
249 * @param u2 second uri
250 * @return merged URI, NULL on error
252 struct GNUNET_FS_Uri *
253 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
254 const struct GNUNET_FS_Uri *u2);
260 * @param uri the URI to duplicate
261 * @return copy of the URI
263 struct GNUNET_FS_Uri *
264 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
268 * Create an FS URI from a single user-supplied string of keywords.
269 * The string is broken up at spaces into individual keywords.
270 * Keywords that start with "+" are mandatory. Double-quotes can
271 * be used to prevent breaking up strings at spaces (and also
272 * to specify non-mandatory keywords starting with "+").
274 * Keywords must contain a balanced number of double quotes and
275 * double quotes can not be used in the actual keywords (for
276 * example, the string '""foo bar""' will be turned into two
277 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
279 * @param keywords the keyword string
280 * @param emsg where to store an error message
281 * @return an FS URI for the given keywords, NULL
282 * if keywords is not legal (i.e. empty).
284 struct GNUNET_FS_Uri *
285 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
289 * Create an FS URI from a user-supplied command line of keywords.
290 * Arguments should start with "+" to indicate mandatory
293 * @param argc number of keywords
294 * @param argv keywords (double quotes are not required for
295 * keywords containing spaces; however, double
296 * quotes are required for keywords starting with
297 * "+"); there is no mechanism for having double
298 * quotes in the actual keywords (if the user
299 * did specifically specify double quotes, the
300 * caller should convert each double quote
301 * into two single quotes).
302 * @return an FS URI for the given keywords, NULL
303 * if keywords is not legal (i.e. empty).
305 struct GNUNET_FS_Uri *
306 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
311 * Test if two URIs are equal.
313 * @param u1 one of the URIs
314 * @param u2 the other URI
315 * @return #GNUNET_YES if the URIs are equal
318 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
319 const struct GNUNET_FS_Uri *u2);
323 * Is this a namespace URI?
325 * @param uri the uri to check
326 * @return #GNUNET_YES if this is an SKS uri
329 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
333 * Create an SKS URI from a namespace ID and an identifier.
335 * @param ns pseudonym to use
336 * @param id identifier
337 * @return an FS URI for the given namespace and identifier
339 struct GNUNET_FS_Uri *
340 GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EccPublicSignKey *ns,
345 * Get the public key of a namespace from the given
348 * @param uri the uri to get the namespace ID from
349 * @param pseudonym where to store the public key of the namespace
350 * @return #GNUNET_OK on success
353 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
354 struct GNUNET_CRYPTO_EccPublicSignKey *pseudonym);
358 * Get the content identifier of an SKS URI.
360 * @param uri the sks uri
361 * @return NULL on error (not a valid SKS URI)
364 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
368 * Is this a keyword URI?
371 * @return #GNUNET_YES if this is a KSK uri
374 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
378 * Is this a file (or directory) URI?
380 * @param uri the uri to check
381 * @return #GNUNET_YES if this is a CHK uri
384 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
388 * What is the size of the file that this URI
391 * @param uri the CHK (or LOC) URI to inspect
392 * @return size of the file as specified in the CHK URI
395 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
399 * Is this a location URI?
401 * @param uri the uri to check
402 * @return #GNUNET_YES if this is a LOC uri
405 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
409 * Construct a keyword-URI from meta-data (take all entries
410 * in the meta-data and construct one large keyword URI
411 * that lists all keywords that can be found in the meta-data).
413 * @param md metadata to use
414 * @return NULL on error, otherwise a KSK URI
416 struct GNUNET_FS_Uri *
417 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
421 /* ******************** command-line option parsing API *********************** */
424 * Command-line option parser function that allows the user
425 * to specify one or more '-k' options with keywords. Each
426 * specified keyword will be added to the URI. A pointer to
427 * the URI must be passed as the "scls" argument.
429 * @param ctx command line processor context
430 * @param scls must be of type "struct GNUNET_FS_Uri **"
431 * @param option name of the option (typically 'k')
432 * @param value command line argument given
433 * @return #GNUNET_OK on success
436 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
437 *ctx, void *scls, const char *option,
442 * Command-line option parser function that allows the user to specify
443 * one or more '-m' options with metadata. Each specified entry of
444 * the form "type=value" will be added to the metadata. A pointer to
445 * the metadata must be passed as the "scls" argument.
447 * @param ctx command line processor context
448 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
449 * @param option name of the option (typically 'k')
450 * @param value command line argument given
451 * @return #GNUNET_OK on success
454 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
455 *ctx, void *scls, const char *option,
460 /* ************************* sharing API ***************** */
464 * Possible status codes used in the callback for the
465 * various file-sharing operations. On each file (or search),
466 * the callback is guaranteed to be called once with "START"
467 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
468 * are optional and depend on the circumstances; parent operations
469 * will be STARTED before child-operations and STOPPED after
470 * their respective child-operations. START and STOP signals
471 * are typically generated either due to explicit client requests
472 * or because of suspend/resume operations.
474 enum GNUNET_FS_Status
477 * Notification that we have started to publish a file structure.
479 GNUNET_FS_STATUS_PUBLISH_START = 0,
482 * Notification that we have resumed sharing a file structure.
484 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
487 * Notification that we have suspended sharing a file structure.
489 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
492 * Notification that we are making progress sharing a file structure.
494 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
497 * Notification that an error was encountered sharing a file structure.
498 * The application will continue to receive resume/suspend events for
499 * this structure until "GNUNET_FS_publish_stop" is called.
501 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
504 * Notification that we completed sharing a file structure.
505 * The application will continue to receive resume/suspend events for
506 * this structure until "GNUNET_FS_publish_stop" is called.
508 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
511 * Notification that we have stopped
512 * the process of uploading a file structure; no
513 * futher events will be generated for this action.
515 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
518 * Notification that we have started this download.
520 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
523 * Notification that this download is being resumed.
525 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
528 * Notification that this download was suspended.
530 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
533 * Notification about progress with this download.
535 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
538 * Notification that this download encountered an error.
540 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
543 * Notification that this download completed. Note that for
544 * directories, completion does not imply completion of all files in
547 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
550 * Notification that this download was stopped
551 * (final event with respect to this action).
553 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
556 * Notification that this download is now actively being
557 * pursued (as opposed to waiting in the queue).
559 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
562 * Notification that this download is no longer actively
563 * being pursued (back in the queue).
565 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
568 * Notification that this download is no longer part of a
569 * recursive download or search but now a 'stand-alone'
570 * download (and may thus need to be moved in the GUI
571 * into a different category).
573 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
576 * First event generated when a client requests
577 * a search to begin or when a namespace result
578 * automatically triggers the search for updates.
580 GNUNET_FS_STATUS_SEARCH_START = 17,
583 * Last event when a search is being resumed;
584 * note that "GNUNET_FS_SEARCH_START" will not
585 * be generated in this case.
587 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
590 * Event generated for each search result
591 * when the respective search is resumed.
593 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
596 * Last event when a search is being suspended;
597 * note that "GNUNET_FS_SEARCH_STOPPED" will not
598 * be generated in this case.
600 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
603 * This search has yielded a result.
605 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
608 * We have discovered a new namespace.
610 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
613 * We have additional data about the quality
614 * or availability of a search result.
616 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
619 * Signals a problem with this search.
621 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
624 * Signals that this search was paused.
626 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
629 * Signals that this search was continued (unpaused).
631 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
634 * Event generated for each search result
635 * when the respective search is stopped.
637 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
640 * Event generated for each search result
641 * when the respective search is suspended.
643 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
646 * Last message from a search; this signals
647 * that there will be no further events associated
650 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
653 * Notification that we started to unindex a file.
655 GNUNET_FS_STATUS_UNINDEX_START = 30,
658 * Notification that we resumed unindexing of a file.
660 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
663 * Notification that we suspended unindexing a file.
665 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
668 * Notification that we made progress unindexing a file.
670 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
673 * Notification that we encountered an error unindexing
676 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
679 * Notification that the unindexing of this file
682 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
685 * Notification that the unindexing of this file
686 * was stopped (final event for this action).
688 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
693 * Handle for controlling an upload.
695 struct GNUNET_FS_PublishContext;
699 * Handle for controlling an unindexing operation.
701 struct GNUNET_FS_UnindexContext;
705 * Handle for controlling a search.
707 struct GNUNET_FS_SearchContext;
711 * Result from a search. Opaque handle to refer to the search
712 * (typically used when starting a download associated with the search
715 struct GNUNET_FS_SearchResult;
719 * Context for controlling a download.
721 struct GNUNET_FS_DownloadContext;
725 * Handle for detail information about a file that is being publishd.
726 * Specifies metadata, keywords, how to get the contents of the file
727 * (i.e. data-buffer in memory, filename on disk) and other options.
729 struct GNUNET_FS_FileInformation;
733 * Argument given to the progress callback with
734 * information about what is going on.
736 struct GNUNET_FS_ProgressInfo
740 * Values that depend on the event type.
746 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
752 * Context for controlling the upload.
754 struct GNUNET_FS_PublishContext *pc;
757 * Information about the file that is being publishd.
759 const struct GNUNET_FS_FileInformation *fi;
762 * Client context pointer (set the last time by the client for
763 * this operation; initially NULL on START/RESUME events).
768 * Client context pointer for the parent operation
769 * (if this is a file in a directory or a subdirectory).
774 * Name of the file being published; can be NULL.
776 const char *filename;
779 * How large is the file overall? For directories,
780 * this is only the size of the directory itself,
781 * not of the other files contained within the
787 * At what time do we expect to finish the upload?
788 * (will be a value in the past for completed
791 struct GNUNET_TIME_Relative eta;
794 * How long has this upload been actively running
795 * (excludes times where the upload was suspended).
797 struct GNUNET_TIME_Relative duration;
800 * How many bytes have we completed?
805 * What anonymity level is used for this upload?
810 * Additional values for specific events.
816 * These values are only valid for
817 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
823 * Data block we just published.
828 * At what offset in the file is "data"?
833 * Length of the data block.
838 * Depth of the given block in the tree;
839 * 0 would be the lowest level (DBLOCKs).
846 * These values are only valid for
847 * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
853 * Error message, NULL if no error was encountered so far.
858 * URI of the file (if the download had been completed)
860 const struct GNUNET_FS_Uri *chk_uri;
865 * These values are only valid for
866 * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
874 const struct GNUNET_FS_Uri *chk_uri;
879 * These values are only valid for
880 * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
886 * Error message, never NULL.
898 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
904 * Context for controlling the download.
906 struct GNUNET_FS_DownloadContext *dc;
909 * Client context pointer (set the last time
910 * by the client for this operation; initially
911 * NULL on START/RESUME events).
916 * Client context pointer for the parent operation
917 * (if this is a file in a directory or a subdirectory).
922 * Client context pointer for the associated search operation
923 * (specifically, context pointer for the specific search
924 * result, not the overall search); only set if this
925 * download was started from a search result.
930 * URI used for this download.
932 const struct GNUNET_FS_Uri *uri;
935 * Name of the file that we are downloading.
937 const char *filename;
940 * How large is the download overall? This
941 * is NOT necessarily the size from the
942 * URI since we may be doing a partial download.
947 * At what time do we expect to finish the download?
948 * (will be a value in the past for completed
951 struct GNUNET_TIME_Relative eta;
954 * How long has this download been active?
956 struct GNUNET_TIME_Relative duration;
959 * How many bytes have we completed?
964 * What anonymity level is used for this download?
969 * Is the download currently active.
974 * Additional values for specific events.
980 * These values are only valid for
981 * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
987 * Data block we just obtained, can be NULL (even if
988 * data_len > 0) if we found the entire block 'intact' on
989 * disk. In this case, it is also possible for 'data_len'
990 * to be larger than an individual (32k) block.
995 * At what offset in the file is "data"?
1000 * Length of the data block.
1005 * How much time passed between us asking for this block and
1006 * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1008 struct GNUNET_TIME_Relative block_download_duration;
1011 * Depth of the given block in the tree;
1012 * 0 would be the lowest level (DBLOCKS).
1017 * How much respect did we offer for downloading this block? (estimate,
1018 * because we might have the same request pending for multiple clients,
1019 * and of course because a transmission may have failed at a lower
1022 uint32_t respect_offered;
1025 * How often did we transmit the request? (estimate,
1026 * because we might have the same request pending for multiple clients,
1027 * and of course because a transmission may have failed at a lower
1030 uint32_t num_transmissions;
1035 * These values are only valid for
1036 * #GNUNET_FS_STATUS_DOWNLOAD_START events.
1042 * Known metadata for the download.
1044 const struct GNUNET_CONTAINER_MetaData *meta;
1049 * These values are only valid for
1050 * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1056 * Known metadata for the download.
1058 const struct GNUNET_CONTAINER_MetaData *meta;
1061 * Error message, NULL if we have not encountered any error yet.
1063 const char *message;
1068 * These values are only valid for
1069 * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1077 const char *message;
1086 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1092 * Context for controlling the search, NULL for
1093 * searches that were not explicitly triggered
1094 * by the client (i.e., searches for updates in
1097 struct GNUNET_FS_SearchContext *sc;
1100 * Client context pointer (set the last time by the client for
1101 * this operation; initially NULL on START/RESUME events). Note
1102 * that this value can only be set on START/RESUME; returning
1103 * non-NULL on RESULT/RESUME_RESULT will actually update the
1104 * private context for "UPDATE" events.
1109 * Client parent-context pointer; NULL for top-level searches,
1110 * refers to the client context of the associated search result
1111 * for automatically triggered searches for updates in
1112 * namespaces. In this case, 'presult' refers to that search
1118 * What query is used for this search
1119 * (list of keywords or SKS identifier).
1121 const struct GNUNET_FS_Uri *query;
1124 * How long has this search been actively running
1125 * (excludes times where the search was paused or
1128 struct GNUNET_TIME_Relative duration;
1131 * What anonymity level is used for this search?
1136 * Additional values for specific events.
1142 * These values are only valid for
1143 * #GNUNET_FS_STATUS_SEARCH_RESULT events.
1149 * Metadata for the search result.
1151 const struct GNUNET_CONTAINER_MetaData *meta;
1154 * URI for the search result.
1156 const struct GNUNET_FS_Uri *uri;
1159 * Handle to the result (for starting downloads).
1161 struct GNUNET_FS_SearchResult *result;
1164 * Applicability rank (the larger, the better the result
1165 * fits the search criteria).
1167 uint32_t applicability_rank;
1172 * These values are only valid for
1173 * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1179 * Metadata for the search result.
1181 const struct GNUNET_CONTAINER_MetaData *meta;
1184 * URI for the search result.
1186 const struct GNUNET_FS_Uri *uri;
1189 * Handle to the result (for starting downloads).
1191 struct GNUNET_FS_SearchResult *result;
1194 * Current availability rank (negative:
1195 * unavailable, positive: available)
1197 int32_t availability_rank;
1200 * On how many total queries is the given
1201 * availability_rank based?
1203 uint32_t availability_certainty;
1206 * Updated applicability rank (the larger,
1207 * the better the result fits the search
1210 uint32_t applicability_rank;
1215 * These values are only valid for
1216 * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
1222 * Private context set for for this result
1223 * during the "RESULT" event.
1228 * Metadata for the search result.
1230 const struct GNUNET_CONTAINER_MetaData *meta;
1233 * URI for the search result.
1235 const struct GNUNET_FS_Uri *uri;
1238 * Current availability rank (negative:
1239 * unavailable, positive: available)
1241 int32_t availability_rank;
1244 * On how many total queries is the given
1245 * availability_rank based?
1247 uint32_t availability_certainty;
1250 * Updated applicability rank (the larger,
1251 * the better the result fits the search
1254 uint32_t applicability_rank;
1257 * How long has the current probe been active?
1259 struct GNUNET_TIME_Relative current_probe_time;
1264 * These values are only valid for
1265 * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1266 * These events are automatically triggered for
1267 * each search result before the
1268 * #GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1269 * happens primarily to give the client a chance
1270 * to clean up the "cctx" (if needed).
1276 * Private context set for for this result
1277 * during the "RESULT" event.
1282 * Metadata for the search result.
1284 const struct GNUNET_CONTAINER_MetaData *meta;
1287 * URI for the search result.
1289 const struct GNUNET_FS_Uri *uri;
1294 * These values are only valid for
1295 * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1296 * These events are automatically triggered for
1297 * each search result before the
1298 * #GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1299 * happens primarily to give the client a chance
1300 * to clean up the "cctx" (if needed).
1306 * Private context set for for this result
1307 * during the "RESULT" event.
1312 * Metadata for the search result.
1314 const struct GNUNET_CONTAINER_MetaData *meta;
1317 * URI for the search result.
1319 const struct GNUNET_FS_Uri *uri;
1324 * These values are only valid for
1325 * #GNUNET_FS_STATUS_SEARCH_RESUME events.
1331 * Error message, NULL if we have not encountered any error yet.
1333 const char *message;
1336 * Is this search currently paused?
1343 * These values are only valid for
1344 * #GNUNET_FS_STATUS_SEARCH_ERROR events.
1352 const char *message;
1357 * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
1363 * Short, human-readable name of the namespace.
1368 * Root identifier for the namespace, can be NULL.
1373 * Metadata for the namespace.
1375 const struct GNUNET_CONTAINER_MetaData *meta;
1378 * Public key of the namespace.
1380 struct GNUNET_CRYPTO_EccPublicSignKey pseudonym;
1389 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1395 * Context for controlling the unindexing.
1397 struct GNUNET_FS_UnindexContext *uc;
1400 * Client context pointer (set the last time
1401 * by the client for this operation; initially
1402 * NULL on START/RESUME events).
1407 * Name of the file that is being unindexed.
1409 const char *filename;
1412 * How large is the file overall?
1417 * At what time do we expect to finish unindexing?
1418 * (will be a value in the past for completed
1419 * unindexing opeations).
1421 struct GNUNET_TIME_Relative eta;
1424 * How long has this upload been actively running
1425 * (excludes times where the upload was suspended).
1427 struct GNUNET_TIME_Relative duration;
1430 * How many bytes have we completed?
1435 * Additional values for specific events.
1441 * These values are only valid for
1442 * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1448 * Data block we just unindexed.
1453 * At what offset in the file is "data"?
1458 * Length of the data block.
1463 * Depth of the given block in the tree;
1464 * 0 would be the lowest level (DBLOCKS).
1471 * These values are only valid for
1472 * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
1478 * Error message, NULL if we have not encountered any error yet.
1480 const char *message;
1485 * These values are only valid for
1486 * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
1494 const char *message;
1505 * Specific status code (determines the event type).
1507 enum GNUNET_FS_Status status;
1510 * File-sharing handle that generated the event.
1512 struct GNUNET_FS_Handle *fsh;
1517 * Notification of FS to a client about the progress of an
1518 * operation. Callbacks of this type will be used for uploads,
1519 * downloads and searches. Some of the arguments depend a bit
1520 * in their meaning on the context in which the callback is used.
1522 * @param cls closure
1523 * @param info details about the event, specifying the event type
1524 * and various bits about the event
1525 * @return client-context (for the next progress call
1526 * for this operation; should be set to NULL for
1527 * SUSPEND and STOPPED events). The value returned
1528 * will be passed to future callbacks in the respective
1529 * field in the `struct GNUNET_FS_ProgressInfo`.
1531 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1532 const struct GNUNET_FS_ProgressInfo *info);
1536 * General (global) option flags for file-sharing.
1538 enum GNUNET_FS_Flags
1541 * No special flags set.
1543 GNUNET_FS_FLAGS_NONE = 0,
1546 * Is persistence of operations desired?
1547 * (will create SUSPEND/RESUME events).
1549 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1552 * Should we automatically trigger probes for search results
1553 * to determine availability?
1554 * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
1556 GNUNET_FS_FLAGS_DO_PROBES = 2
1561 * Options specified in the VARARGs portion of GNUNET_FS_start.
1563 enum GNUNET_FS_OPTIONS
1567 * Last option in the VARARG list.
1569 GNUNET_FS_OPTIONS_END = 0,
1572 * Select the desired amount of parallelism (this option should be
1573 * followed by an "unsigned int" giving the desired maximum number
1574 * of parallel downloads).
1576 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1579 * Maximum number of requests that should be pending at a given
1580 * point in time (invidivual downloads may go above this, but
1581 * if we are above this threshold, we should not activate any
1582 * additional downloads.
1584 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1589 * Settings for publishing a block (which may of course also
1590 * apply to an entire directory or file).
1592 struct GNUNET_FS_BlockOptions
1596 * At what time should the block expire? Data blocks (DBLOCKS and
1597 * IBLOCKS) may still be used even if they are expired (however,
1598 * they'd be removed quickly from the datastore if we are short on
1599 * space), all other types of blocks will no longer be returned
1600 * after they expire.
1602 struct GNUNET_TIME_Absolute expiration_time;
1605 * At which anonymity level should the block be shared?
1606 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1608 uint32_t anonymity_level;
1611 * How important is it for us to store the block? If we run
1612 * out of space, the highest-priority, non-expired blocks will
1615 uint32_t content_priority;
1618 * How often should we try to migrate the block to other peers?
1619 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1620 * first push each block to other peers according to their
1621 * replication levels. Once each block has been pushed that many
1622 * times to other peers, blocks are chosen for migration at random.
1623 * Naturally, there is no guarantee that the other peers will keep
1624 * these blocks for any period of time (since they won't have any
1625 * priority or might be too busy to even store the block in the
1628 uint32_t replication_level;
1634 * Handle to the file-sharing service.
1636 struct GNUNET_FS_Handle;
1640 * Setup a connection to the file-sharing service.
1642 * @param cfg configuration to use
1643 * @param client_name unique identifier for this client
1644 * @param upcb function to call to notify about FS actions
1645 * @param upcb_cls closure for @a upcb
1646 * @param flags specific attributes for fs-operations
1647 * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
1648 * @return NULL on error
1650 struct GNUNET_FS_Handle *
1651 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1652 const char *client_name, GNUNET_FS_ProgressCallback upcb,
1653 void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
1657 * Close our connection with the file-sharing service.
1658 * The callback given to GNUNET_FS_start will no longer be
1659 * called after this function returns.
1661 * @param h handle that was returned from GNUNET_FS_start
1664 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1668 * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
1670 * @param cls closure
1671 * @param fi the entry in the publish-structure
1672 * @param length length of the file or directory
1673 * @param meta metadata for the file or directory (can be modified)
1674 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1675 * @param bo block options (can be modified)
1676 * @param do_index should we index (can be modified)
1677 * @param client_info pointer to client context set upon creation (can be modified)
1678 * @return #GNUNET_OK to continue, #GNUNET_NO to remove
1679 * this entry from the directory, #GNUNET_SYSERR
1680 * to abort the iteration
1682 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
1684 GNUNET_FS_FileInformation *
1685 fi, uint64_t length,
1687 GNUNET_CONTAINER_MetaData *
1689 struct GNUNET_FS_Uri ** uri,
1690 struct GNUNET_FS_BlockOptions
1691 * bo, int *do_index,
1692 void **client_info);
1696 * Obtain the name under which this file information
1697 * structure is stored on disk. Only works for top-level
1698 * file information structures.
1700 * @param s structure to get the filename for
1701 * @return NULL on error, otherwise filename that can be used
1702 * to read this fi-struct from disk.
1705 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1709 * Obtain the filename from the file information structure.
1711 * @param s structure to get the filename for
1712 * @return "filename" field of the structure (can be NULL)
1715 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1719 * Set the filename in the file information structure.
1720 * If filename was already set, frees it before setting the new one.
1721 * Makes a copy of the argument.
1723 * @param s structure to get the filename for
1724 * @param filename filename to set
1727 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1728 const char *filename);
1732 * Create an entry for a file in a publish-structure.
1734 * @param h handle to the file sharing subsystem
1735 * @param client_info initial client-info value for this entry
1736 * @param filename name of the file or directory to publish
1737 * @param keywords under which keywords should this file be available
1738 * directly; can be NULL
1739 * @param meta metadata for the file
1740 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1741 * #GNUNET_SYSERR for simulation
1742 * @param bo block options
1743 * @return publish structure entry for the file
1745 struct GNUNET_FS_FileInformation *
1746 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1748 const char *filename,
1749 const struct GNUNET_FS_Uri
1752 GNUNET_CONTAINER_MetaData *meta,
1754 const struct GNUNET_FS_BlockOptions
1759 * Create an entry for a file in a publish-structure.
1761 * @param h handle to the file sharing subsystem
1762 * @param client_info initial client-info value for this entry
1763 * @param length length of the file
1764 * @param data data for the file (should not be used afterwards by
1765 * the caller; callee will "free")
1766 * @param keywords under which keywords should this file be available
1767 * directly; can be NULL
1768 * @param meta metadata for the file
1769 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1770 * #GNUNET_SYSERR for simulation
1771 * @param bo block options
1772 * @return publish structure entry for the file
1774 struct GNUNET_FS_FileInformation *
1775 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1776 void *client_info, uint64_t length,
1778 const struct GNUNET_FS_Uri
1781 GNUNET_CONTAINER_MetaData *meta,
1783 const struct GNUNET_FS_BlockOptions
1788 * Function that provides data.
1790 * @param cls closure
1791 * @param offset offset to read from; it is possible
1792 * that the caller might need to go backwards
1793 * a bit at times; set to UINT64_MAX to tell
1794 * the reader that we won't be reading for a while
1795 * (used to close the file descriptor but NOT fully
1796 * clean up the reader's state); in this case,
1797 * a value of '0' for max should be ignored
1798 * @param max maximum number of bytes that should be
1799 * copied to buf; readers are not allowed
1800 * to provide less data unless there is an error;
1801 * a value of "0" will be used at the end to allow
1802 * the reader to clean up its internal state
1803 * @param buf where the reader should write the data
1804 * @param emsg location for the reader to store an error message
1805 * @return number of bytes written, usually @a max, 0 on error
1807 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
1808 void *buf, char **emsg);
1812 * Create an entry for a file in a publish-structure.
1814 * @param h handle to the file sharing subsystem
1815 * @param client_info initial client-info value for this entry
1816 * @param length length of the file
1817 * @param reader function that can be used to obtain the data for the file
1818 * @param reader_cls closure for @a reader
1819 * @param keywords under which keywords should this file be available
1820 * directly; can be NULL
1821 * @param meta metadata for the file
1822 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1823 * #GNUNET_SYSERR for simulation
1824 * @param bo block options
1825 * @return publish structure entry for the file
1827 struct GNUNET_FS_FileInformation *
1828 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1831 GNUNET_FS_DataReader reader,
1833 const struct GNUNET_FS_Uri
1836 GNUNET_CONTAINER_MetaData *meta,
1839 GNUNET_FS_BlockOptions *bo);
1843 * Create an entry for an empty directory in a publish-structure.
1844 * This function should be used by applications for which the
1845 * use of #GNUNET_FS_file_information_create_from_directory
1846 * is not appropriate.
1848 * @param h handle to the file sharing subsystem
1849 * @param client_info initial client-info value for this entry
1850 * @param keywords under which keywords should this directory be available
1851 * directly; can be NULL
1852 * @param meta metadata for the directory
1853 * @param bo block options
1854 * @param filename name of the directory; can be NULL
1855 * @return publish structure entry for the directory , NULL on error
1857 struct GNUNET_FS_FileInformation *
1858 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1860 const struct GNUNET_FS_Uri
1863 GNUNET_CONTAINER_MetaData
1866 GNUNET_FS_BlockOptions *bo,
1867 const char *filename);
1871 * Test if a given entry represents a directory.
1873 * @param ent check if this FI represents a directory
1874 * @return #GNUNET_YES if so, #GNUNET_NO if not
1877 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1882 * Add an entry to a directory in a publish-structure. Clients
1883 * should never modify publish structures that were passed to
1884 * #GNUNET_FS_publish_start already.
1886 * @param dir the directory
1887 * @param ent the entry to add; the entry must not have been
1888 * added to any other directory at this point and
1889 * must not include @a dir in its structure
1890 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1893 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1894 struct GNUNET_FS_FileInformation *ent);
1898 * Inspect a file or directory in a publish-structure. Clients
1899 * should never modify publish structures that were passed to
1900 * #GNUNET_FS_publish_start already. When called on a directory,
1901 * this function will FIRST call @a proc with information about
1902 * the directory itself and then for each of the files in the
1903 * directory (but not for files in subdirectories). When called
1904 * on a file, @a proc will be called exactly once (with information
1905 * about the specific file).
1907 * @param dir the directory
1908 * @param proc function to call on each entry
1909 * @param proc_cls closure for @a proc
1912 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1913 GNUNET_FS_FileInformationProcessor proc,
1918 * Destroy publish-structure. Clients should never destroy publish
1919 * structures that were passed to #GNUNET_FS_publish_start already.
1921 * @param fi structure to destroy
1922 * @param cleaner function to call on each entry in the structure
1923 * (useful to clean up client_info); can be NULL; return
1924 * values are ignored
1925 * @param cleaner_cls closure for @a cleaner
1928 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1929 GNUNET_FS_FileInformationProcessor cleaner,
1934 * Options for publishing. Compatible options
1935 * can be OR'ed together.
1937 enum GNUNET_FS_PublishOptions
1940 * No options (use defaults for everything).
1942 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1945 * Simulate publishing. With this option, no data will be stored
1946 * in the datastore. Useful for computing URIs from files.
1948 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1953 * Publish a file or directory.
1955 * @param h handle to the file sharing subsystem
1956 * @param fi information about the file or directory structure to publish
1957 * @param ns namespace to publish the file in, NULL for no namespace
1958 * @param nid identifier to use for the publishd content in the namespace
1959 * (can be NULL, must be NULL if namespace is NULL)
1960 * @param nuid update-identifier that will be used for future updates
1961 * (can be NULL, must be NULL if namespace or nid is NULL)
1962 * @param options options for the publication
1963 * @return context that can be used to control the publish operation
1965 struct GNUNET_FS_PublishContext *
1966 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1967 struct GNUNET_FS_FileInformation *fi,
1968 const struct GNUNET_CRYPTO_EccPrivateKey *ns,
1971 enum GNUNET_FS_PublishOptions options);
1975 * Stop a publication. Will abort incomplete publications (but
1976 * not remove blocks that have already been published) or
1977 * simply clean up the state for completed publications.
1978 * Must NOT be called from within the event callback!
1980 * @param pc context for the publication to stop
1983 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
1987 * Signature of a function called as the continuation of a KBlock or
1988 * SBlock publication.
1990 * @param cls closure
1991 * @param uri URI under which the block is now available, NULL on error
1992 * @param emsg error message, NULL on success
1994 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
1995 const struct GNUNET_FS_Uri *uri,
2000 * Handle to cancel publish KSK operation.
2002 struct GNUNET_FS_PublishKskContext;
2006 * Publish a KBlock on GNUnet.
2008 * @param h handle to the file sharing subsystem
2009 * @param ksk_uri keywords to use
2010 * @param meta metadata to use
2011 * @param uri URI to refer to in the KBlock
2012 * @param bo block options
2013 * @param options publication options
2014 * @param cont continuation
2015 * @param cont_cls closure for @a cont
2016 * @return NULL on error (@a cont will still be called)
2018 struct GNUNET_FS_PublishKskContext *
2019 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2020 const struct GNUNET_FS_Uri *ksk_uri,
2021 const struct GNUNET_CONTAINER_MetaData *meta,
2022 const struct GNUNET_FS_Uri *uri,
2023 const struct GNUNET_FS_BlockOptions *bo,
2024 enum GNUNET_FS_PublishOptions options,
2025 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2029 * Abort the KSK publishing operation.
2031 * @param pkc context of the operation to abort.
2034 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2038 * Handle to cancel publish SKS operation.
2040 struct GNUNET_FS_PublishSksContext;
2044 * Publish an SBlock on GNUnet.
2046 * @param h handle to the file sharing subsystem
2047 * @param ns namespace to publish in
2048 * @param identifier identifier to use
2049 * @param update update identifier to use
2050 * @param meta metadata to use
2051 * @param uri URI to refer to in the SBlock
2052 * @param bo block options
2053 * @param options publication options
2054 * @param cont continuation
2055 * @param cont_cls closure for @a cont
2056 * @return NULL on error (@a cont will still be called)
2058 struct GNUNET_FS_PublishSksContext *
2059 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2060 const struct GNUNET_CRYPTO_EccPrivateKey *ns,
2061 const char *identifier,
2063 const struct GNUNET_CONTAINER_MetaData *meta,
2064 const struct GNUNET_FS_Uri *uri,
2065 const struct GNUNET_FS_BlockOptions *bo,
2066 enum GNUNET_FS_PublishOptions options,
2067 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2071 * Abort the SKS publishing operation.
2073 * @param psc context of the operation to abort.
2076 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2080 * Type of a function called by #GNUNET_FS_get_indexed_files.
2082 * @param cls closure
2083 * @param filename the name of the file, NULL for end of list
2084 * @param file_id hash of the contents of the indexed file
2085 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2087 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2088 const struct GNUNET_HashCode * file_id);
2092 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2094 struct GNUNET_FS_GetIndexedContext;
2098 * Iterate over all indexed files.
2100 * @param h handle to the file sharing subsystem
2101 * @param iterator function to call on each indexed file
2102 * @param iterator_cls closure for @a iterator
2103 * @return NULL on error (@a iterator is not called)
2105 struct GNUNET_FS_GetIndexedContext *
2106 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2107 GNUNET_FS_IndexedFileProcessor iterator,
2108 void *iterator_cls);
2112 * Cancel iteration over all indexed files.
2114 * @param gic operation to cancel
2117 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2123 * @param h handle to the file sharing subsystem
2124 * @param filename file to unindex
2125 * @param cctx initial value for the client context
2126 * @return NULL on error, otherwise handle
2128 struct GNUNET_FS_UnindexContext *
2129 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2130 const char *filename,
2135 * Clean up after completion of an unindex operation.
2140 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2144 * Function called on updateable identifiers.
2146 * @param cls closure
2147 * @param last_id last identifier
2148 * @param last_uri uri used for the content published under the @a last_id
2149 * @param last_meta metadata associated with @a last_uri
2150 * @param next_id identifier that should be used for updates
2152 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2153 const char *last_id,
2154 const struct GNUNET_FS_Uri *last_uri,
2155 const struct GNUNET_CONTAINER_MetaData *last_meta,
2156 const char *next_id);
2160 * List all of the identifiers in the namespace for which we could
2161 * produce an update. Namespace updates form a graph where each node
2162 * has a name. Each node can have any number of URI/meta-data entries
2163 * which can each be linked to other nodes. Cycles are possible.
2165 * Calling this function with @a next_id NULL will cause the library to
2166 * call @a ip with a root for each strongly connected component of the
2167 * graph (a root being a node from which all other nodes in the Scc
2170 * Calling this function with @a next_id being the name of a node will
2171 * cause the library to call @a ip with all children of the node. Note
2172 * that cycles within an SCC are possible (including self-loops).
2174 * @param h fs handle to use
2175 * @param ns namespace to inspect for updateable content
2176 * @param next_id ID to look for; use NULL to look for SCC roots
2177 * @param ip function to call on each updateable identifier
2178 * @param ip_cls closure for @a ip
2181 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
2182 const struct GNUNET_CRYPTO_EccPrivateKey *ns,
2183 const char *next_id,
2184 GNUNET_FS_IdentifierProcessor ip,
2189 * Options for searching. Compatible options
2190 * can be OR'ed together.
2192 enum GNUNET_FS_SearchOptions
2195 * No options (use defaults for everything).
2197 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2200 * Only search the local host, do not search remote systems (no P2P)
2202 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2207 * Start search for content.
2209 * @param h handle to the file sharing subsystem
2210 * @param uri specifies the search parameters; can be
2211 * a KSK URI or an SKS URI.
2212 * @param anonymity desired level of anonymity
2213 * @param options options for the search
2214 * @param cctx initial value for the client context
2215 * @return context that can be used to control the search
2217 struct GNUNET_FS_SearchContext *
2218 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2219 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2220 enum GNUNET_FS_SearchOptions options, void *cctx);
2226 * @param sc context for the search that should be paused
2229 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2233 * Continue paused search.
2235 * @param sc context for the search that should be resumed
2238 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2242 * Stop search for content.
2244 * @param sc context for the search that should be stopped
2247 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2251 * Start download probes for the given search result.
2253 * @param h file-sharing handle to use for the operation
2254 * @param uri URI to probe
2255 * @param meta meta data associated with the URI
2256 * @param client_info client info pointer to use for associated events
2257 * @param anonymity anonymity level to use for the probes
2258 * @return the search result handle to access the probe activity
2260 struct GNUNET_FS_SearchResult *
2261 GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2262 const struct GNUNET_FS_Uri *uri,
2263 const struct GNUNET_CONTAINER_MetaData *meta,
2265 uint32_t anonymity);
2269 * Stop probe activity. Must ONLY be used on values
2270 * returned from #GNUNET_FS_probe.
2272 * @param sr search result to stop probing for (freed)
2273 * @return the value of the 'client_info' pointer
2276 GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2280 * Options for downloading. Compatible options
2281 * can be OR'ed together.
2283 enum GNUNET_FS_DownloadOptions
2286 * No options (use defaults for everything).
2288 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2291 * Only download from the local host, do not access remote systems (no P2P)
2293 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2296 * Do a recursive download (that is, automatically trigger the
2297 * download of files in directories).
2299 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2302 * Do not append temporary data to
2303 * the target file (for the IBlocks).
2305 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2308 * Internal option used to flag this download as a 'probe' for a
2309 * search result. Impacts the priority with which the download is
2310 * run and causes signalling callbacks to be done differently.
2311 * Also, probe downloads are not serialized on suspension. Normal
2312 * clients should not use this!
2314 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2320 * Download parts of a file. Note that this will store
2321 * the blocks at the respective offset in the given file. Also, the
2322 * download is still using the blocking of the underlying FS
2323 * encoding. As a result, the download may *write* outside of the
2324 * given boundaries (if offset and length do not match the 32k FS
2325 * block boundaries).
2327 * The given range can be used to focus a download towards a
2328 * particular portion of the file (optimization), not to strictly
2329 * limit the download to exactly those bytes.
2331 * @param h handle to the file sharing subsystem
2332 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2333 * @param meta known metadata for the file (can be NULL)
2334 * @param filename where to store the file, maybe NULL (then no file is
2335 * created on disk and data must be grabbed from the callbacks)
2336 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2337 * can be NULL (in which case we will pick a name if needed); the temporary file
2338 * may already exist, in which case we will try to use the data that is there and
2339 * if it is not what is desired, will overwrite it
2340 * @param offset at what offset should we start the download (typically 0)
2341 * @param length how many bytes should be downloaded starting at offset
2342 * @param anonymity anonymity level to use for the download
2343 * @param options various download options
2344 * @param cctx initial value for the client context for this download
2345 * @param parent parent download to associate this download with (use NULL
2346 * for top-level downloads; useful for manually-triggered recursive downloads)
2347 * @return context that can be used to control this download
2349 struct GNUNET_FS_DownloadContext *
2350 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2351 const struct GNUNET_FS_Uri *uri,
2352 const struct GNUNET_CONTAINER_MetaData *meta,
2353 const char *filename, const char *tempname,
2354 uint64_t offset, uint64_t length, uint32_t anonymity,
2355 enum GNUNET_FS_DownloadOptions options, void *cctx,
2356 struct GNUNET_FS_DownloadContext *parent);
2360 * Download parts of a file based on a search result. The download
2361 * will be associated with the search result (and the association
2362 * will be preserved when serializing/deserializing the state).
2363 * If the search is stopped, the download will not be aborted but
2364 * be 'promoted' to a stand-alone download.
2366 * As with the other download function, this will store
2367 * the blocks at the respective offset in the given file. Also, the
2368 * download is still using the blocking of the underlying FS
2369 * encoding. As a result, the download may *write* outside of the
2370 * given boundaries (if offset and length do not match the 32k FS
2371 * block boundaries).
2373 * The given range can be used to focus a download towards a
2374 * particular portion of the file (optimization), not to strictly
2375 * limit the download to exactly those bytes.
2377 * @param h handle to the file sharing subsystem
2378 * @param sr the search result to use for the download (determines uri and
2379 * meta data and associations)
2380 * @param filename where to store the file, maybe NULL (then no file is
2381 * created on disk and data must be grabbed from the callbacks)
2382 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2383 * can be NULL (in which case we will pick a name if needed); the temporary file
2384 * may already exist, in which case we will try to use the data that is there and
2385 * if it is not what is desired, will overwrite it
2386 * @param offset at what offset should we start the download (typically 0)
2387 * @param length how many bytes should be downloaded starting at offset
2388 * @param anonymity anonymity level to use for the download
2389 * @param options various download options
2390 * @param cctx initial value for the client context for this download
2391 * @return context that can be used to control this download
2393 struct GNUNET_FS_DownloadContext *
2394 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2395 struct GNUNET_FS_SearchResult *sr,
2396 const char *filename,
2397 const char *tempname, uint64_t offset,
2398 uint64_t length, uint32_t anonymity,
2399 enum GNUNET_FS_DownloadOptions options,
2404 * Stop a download (aborts if download is incomplete).
2406 * @param dc handle for the download
2407 * @param do_delete delete files of incomplete downloads
2410 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2414 /* ******************** Directory API *********************** */
2417 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2418 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2419 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2422 * Does the meta-data claim that this is a directory?
2423 * Checks if the mime-type is that of a GNUnet directory.
2425 * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
2426 * we have no mime-type information (treat as #GNUNET_NO)
2429 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2434 * Set the MIMETYPE information for the given
2435 * metadata to "application/gnunet-directory".
2437 * @param md metadata to add mimetype to
2440 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2444 * Suggest a filename based on given metadata.
2446 * @param md given meta data
2447 * @return NULL if meta data is useless for suggesting a filename
2450 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
2454 * Function used to process entries in a directory.
2456 * @param cls closure
2457 * @param filename name of the file in the directory
2458 * @param uri URI of the file
2459 * @param metadata metadata for the file; metadata for
2460 * the directory if everything else is NULL/zero
2461 * @param length length of the available data for the file
2462 * (of type size_t since data must certainly fit
2463 * into memory; if files are larger than size_t
2464 * permits, then they will certainly not be
2465 * embedded with the directory itself).
2466 * @param data data available for the file (length bytes)
2468 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2469 const char *filename,
2470 const struct GNUNET_FS_Uri *
2473 GNUNET_CONTAINER_MetaData *
2474 meta, size_t length,
2479 * Iterate over all entries in a directory. Note that directories
2480 * are structured such that it is possible to iterate over the
2481 * individual blocks as well as over the entire directory. Thus
2482 * a client can call this function on the buffer in the
2483 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2484 * include the contents of (small) files embedded in the directory
2485 * itself; for those files, the processor may be given the
2486 * contents of the file directly by this function.
2488 * @param size number of bytes in data
2489 * @param data pointer to the beginning of the directory
2490 * @param offset offset of data in the directory
2491 * @param dep function to call on each entry
2492 * @param dep_cls closure for @a dep
2493 * @return #GNUNET_OK if this could be a block in a directory,
2494 * #GNUNET_NO if this could be part of a directory (but not 100% OK)
2495 * #GNUNET_SYSERR if 'data' does not represent a directory
2498 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2500 GNUNET_FS_DirectoryEntryProcessor dep,
2505 * Opaque handle to a directory builder.
2507 struct GNUNET_FS_DirectoryBuilder;
2511 * Create a directory builder.
2513 * @param mdir metadata for the directory
2515 struct GNUNET_FS_DirectoryBuilder *
2516 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2521 * Add an entry to a directory.
2523 * @param bld directory to extend
2524 * @param uri uri of the entry (must not be a KSK)
2525 * @param md metadata of the entry
2526 * @param data raw data of the entry, can be NULL, otherwise
2527 * data must point to exactly the number of bytes specified
2531 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2532 const struct GNUNET_FS_Uri *uri,
2533 const struct GNUNET_CONTAINER_MetaData *md,
2538 * Finish building the directory. Frees the
2539 * builder context and returns the directory
2542 * @param bld directory to finish
2543 * @param rsize set to the number of bytes needed
2544 * @param rdata set to the encoded directory
2545 * @return #GNUNET_OK on success
2548 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2549 size_t * rsize, void **rdata);
2552 /* ******************** DirScanner API *********************** */
2555 * Progress reasons of the directory scanner.
2557 enum GNUNET_FS_DirScannerProgressUpdateReason
2561 * We've started processing a file or directory.
2563 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2566 * We're having trouble accessing a file (soft-error); it will
2569 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2572 * We've found all files (in the pre-pass).
2574 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2577 * We've finished extracting meta data from a file.
2579 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2582 * Last call to the progress function: we have finished scanning
2585 GNUNET_FS_DIRSCANNER_FINISHED,
2588 * There was an internal error. Application should abort the scan.
2590 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2596 * Function called over time as the directory scanner makes
2597 * progress on the job at hand.
2599 * @param cls closure
2600 * @param filename which file we are making progress on
2601 * @param is_directory #GNUNET_YES if this is a directory,
2602 * #GNUNET_NO if this is a file
2603 * #GNUNET_SYSERR if it is neither (or unknown)
2604 * @param reason kind of progress we are making
2606 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2607 const char *filename,
2609 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
2613 * A node of a directory tree (produced by dirscanner)
2615 struct GNUNET_FS_ShareTreeItem
2618 * This is a doubly-linked list
2620 struct GNUNET_FS_ShareTreeItem *prev;
2623 * This is a doubly-linked list
2625 struct GNUNET_FS_ShareTreeItem *next;
2628 * This is a doubly-linked tree
2629 * NULL for top-level entries.
2631 struct GNUNET_FS_ShareTreeItem *parent;
2634 * This is a doubly-linked tree
2635 * NULL for files and empty directories
2637 struct GNUNET_FS_ShareTreeItem *children_head;
2640 * This is a doubly-linked tree
2641 * NULL for files and empty directories
2643 struct GNUNET_FS_ShareTreeItem *children_tail;
2646 * Metadata for this file or directory
2648 struct GNUNET_CONTAINER_MetaData *meta;
2651 * Keywords for this file or directory (derived from metadata).
2653 struct GNUNET_FS_Uri *ksk_uri;
2656 * Name of the file/directory
2661 * Base name of the file/directory.
2663 char *short_filename;
2666 * #GNUNET_YES if this is a directory
2674 * Opaqe handle to an asynchronous directory scanning activity.
2676 struct GNUNET_FS_DirScanner;
2680 * Start a directory scanner.
2682 * @param filename name of the directory to scan
2683 * @param disable_extractor #GNUNET_YES to not to run libextractor on files (only build a tree)
2684 * @param ex if not NULL, must be a list of extra plugins for extractor
2685 * @param cb the callback to call when there are scanning progress messages
2686 * @param cb_cls closure for @a cb
2687 * @return directory scanner object to be used for controlling the scanner
2689 struct GNUNET_FS_DirScanner *
2690 GNUNET_FS_directory_scan_start (const char *filename,
2691 int disable_extractor,
2693 GNUNET_FS_DirScannerProgressCallback cb,
2698 * Abort the scan. Must not be called from within the progress_callback
2701 * @param ds directory scanner structure
2704 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2708 * Obtain the result of the scan after the scan has signalled
2709 * completion. Must not be called prior to completion. The @a ds is
2710 * freed as part of this call.
2712 * @param ds directory scanner structure
2713 * @return the results of the scan (a directory tree)
2715 struct GNUNET_FS_ShareTreeItem *
2716 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2720 * Process a share item tree, moving frequent keywords up and
2721 * copying frequent metadata up.
2723 * @param toplevel toplevel directory in the tree, returned by the scanner
2726 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2730 * Release memory of a share item tree.
2732 * @param toplevel toplevel of the tree to be freed
2735 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2738 #if 0 /* keep Emacsens' auto-indent happy */