2 This file is part of GNUnet
3 Copyright (C) 2004--2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @author Christian Grothoff
24 * API for file sharing via GNUnet
26 * @defgroup fs FS service
29 * @see [Documentation](https://gnunet.org/file-sharing-service)
33 #ifndef GNUNET_FS_LIB_H
34 #define GNUNET_FS_LIB_H
36 #include "gnunet_util_lib.h"
41 #if 0 /* keep Emacsens' auto-indent happy */
47 * Version number of the implementation.
50 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
51 * 2.x.x: root node with mime-type, filename and version number
52 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
53 * 2.2.x: with directories
54 * 3.0.x: with namespaces
55 * 3.1.x: with namespace meta-data
56 * 3.2.x: with collections
57 * 4.0.x: with expiration, variable meta-data, kblocks
58 * 4.1.x: with new error and configuration handling
59 * 5.0.x: with location URIs
60 * 6.0.0: with support for OR in KSKs
61 * 6.1.x: with simplified namespace support
62 * 9.0.0: CPS-style integrated API
63 * 9.1.1: asynchronous directory scanning
64 * 9.2.0: unified K-Block and S-block format (#2564)
65 * 9.3.0: base32crockford encoded URLs
67 #define GNUNET_FS_VERSION 0x00090300
70 /* ******************** URI API *********************** */
72 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
73 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
74 #define GNUNET_FS_URI_SKS_INFIX "sks/"
75 #define GNUNET_FS_URI_CHK_INFIX "chk/"
76 #define GNUNET_FS_URI_LOC_INFIX "loc/"
80 * How often do we signal applications that a probe for a particular
81 * search result is running? (used to visualize probes).
83 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply ( \
84 GNUNET_TIME_UNIT_MILLISECONDS, 250)
87 * A Universal Resource Identifier (URI), opaque.
93 * Iterator over keywords
96 * @param keyword the keyword
97 * @param is_mandatory is the keyword mandatory (in a search)
98 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
101 (*GNUNET_FS_KeywordIterator) (void *cls,
108 * Get a unique key from a URI. This is for putting URIs
109 * into HashMaps. The key may change between FS implementations.
111 * @param uri uri to convert to a unique key
112 * @param key wherer to store the unique key
113 * @return #GNUNET_OK on success
116 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
117 struct GNUNET_HashCode *key);
121 * Convert a URI to a UTF-8 String.
123 * @param uri uri to convert to a string
124 * @return the UTF-8 string
127 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
131 * Convert keyword URI to a human readable format
132 * (i.e. the search query that was used in the first place)
134 * @param uri ksk uri to convert to a string
135 * @return string with the keywords
138 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
142 * Add the given keyword to the set of keywords represented by the URI.
143 * Does nothing if the keyword is already present.
145 * @param uri ksk uri to modify
146 * @param keyword keyword to add
147 * @param is_mandatory is this keyword mandatory?
150 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
156 * Remove the given keyword from the set of keywords represented by the URI.
157 * Does nothing if the keyword is not present.
159 * @param uri ksk uri to modify
160 * @param keyword keyword to add
163 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
164 const char *keyword);
168 * Convert a UTF-8 String to a URI.
170 * @param uri string to parse
171 * @param emsg where to store the parser error message (if any)
172 * @return NULL on error
174 struct GNUNET_FS_Uri *
175 GNUNET_FS_uri_parse (const char *uri,
182 * @param uri uri to free
185 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
189 * How many keywords are ANDed in this keyword URI?
191 * @param uri ksk uri to get the number of keywords from
192 * @return 0 if this is not a keyword URI
195 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
199 * Iterate over all keywords in this keyword URI.
201 * @param uri ksk uri to get the keywords from
202 * @param iterator function to call on each keyword
203 * @param iterator_cls closure for @a iterator
204 * @return -1 if this is not a keyword URI, otherwise number of
205 * keywords iterated over until iterator aborted
208 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
209 GNUNET_FS_KeywordIterator iterator,
214 * Obtain the identity of the peer offering the data
216 * @param uri the location URI to inspect
217 * @param peer where to store the identify of the peer (presumably) offering the content
218 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
221 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
222 struct GNUNET_PeerIdentity *peer);
226 * Obtain the URI of the content itself.
228 * @param uri location URI to get the content URI from
229 * @return NULL if argument is not a location URI
231 struct GNUNET_FS_Uri *
232 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
236 * Obtain the expiration of the LOC URI.
238 * @param uri location URI to get the expiration from
239 * @return expiration time of the URI
241 struct GNUNET_TIME_Absolute
242 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
246 * Construct a location URI (this peer will be used for the location).
247 * This function should only be called from within gnunet-service-fs,
248 * as it requires the peer's private key which is generally unavailable
249 * to processes directly under the user's control. However, for
250 * testing and as it logically fits under URIs, it is in this API.
252 * @param base_uri content offered by the sender
253 * @param sign_key private key of the peer
254 * @param expiration_time how long will the content be offered?
255 * @return the location URI, NULL on error
257 struct GNUNET_FS_Uri *
258 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
259 const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
260 struct GNUNET_TIME_Absolute expiration_time);
264 * Merge the sets of keywords from two KSK URIs.
266 * @param u1 first uri
267 * @param u2 second uri
268 * @return merged URI, NULL on error
270 struct GNUNET_FS_Uri *
271 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
272 const struct GNUNET_FS_Uri *u2);
278 * @param uri the URI to duplicate
279 * @return copy of the URI
281 struct GNUNET_FS_Uri *
282 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
286 * Create an FS URI from a single user-supplied string of keywords.
287 * The string is broken up at spaces into individual keywords.
288 * Keywords that start with "+" are mandatory. Double-quotes can
289 * be used to prevent breaking up strings at spaces (and also
290 * to specify non-mandatory keywords starting with "+").
292 * Keywords must contain a balanced number of double quotes and
293 * double quotes can not be used in the actual keywords (for
294 * example, the string '""foo bar""' will be turned into two
295 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
297 * @param keywords the keyword string
298 * @param emsg where to store an error message
299 * @return an FS URI for the given keywords, NULL
300 * if keywords is not legal (i.e. empty).
302 struct GNUNET_FS_Uri *
303 GNUNET_FS_uri_ksk_create (const char *keywords,
308 * Create an FS URI from a user-supplied command line of keywords.
309 * Arguments should start with "+" to indicate mandatory
312 * @param argc number of keywords
313 * @param argv keywords (double quotes are not required for
314 * keywords containing spaces; however, double
315 * quotes are required for keywords starting with
316 * "+"); there is no mechanism for having double
317 * quotes in the actual keywords (if the user
318 * did specifically specify double quotes, the
319 * caller should convert each double quote
320 * into two single quotes).
321 * @return an FS URI for the given keywords, NULL
322 * if keywords is not legal (i.e. empty).
324 struct GNUNET_FS_Uri *
325 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
330 * Test if two URIs are equal.
332 * @param u1 one of the URIs
333 * @param u2 the other URI
334 * @return #GNUNET_YES if the URIs are equal
337 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
338 const struct GNUNET_FS_Uri *u2);
342 * Is this a namespace URI?
344 * @param uri the uri to check
345 * @return #GNUNET_YES if this is an SKS uri
348 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
352 * Create an SKS URI from a namespace ID and an identifier.
354 * @param ns pseudonym to use
355 * @param id identifier
356 * @return an FS URI for the given namespace and identifier
358 struct GNUNET_FS_Uri *
359 GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
364 * Get the public key of a namespace from the given
367 * @param uri the uri to get the namespace ID from
368 * @param pseudonym where to store the public key of the namespace
369 * @return #GNUNET_OK on success
372 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
373 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym);
377 * Get the content identifier of an SKS URI.
379 * @param uri the sks uri
380 * @return NULL on error (not a valid SKS URI)
383 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
387 * Is this a keyword URI?
390 * @return #GNUNET_YES if this is a KSK uri
393 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
397 * Is this a file (or directory) URI?
399 * @param uri the uri to check
400 * @return #GNUNET_YES if this is a CHK uri
403 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
407 * What is the size of the file that this URI
410 * @param uri the CHK (or LOC) URI to inspect
411 * @return size of the file as specified in the CHK URI
414 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
418 * Is this a location URI?
420 * @param uri the uri to check
421 * @return #GNUNET_YES if this is a LOC uri
424 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
428 * Construct a keyword-URI from meta-data (take all entries
429 * in the meta-data and construct one large keyword URI
430 * that lists all keywords that can be found in the meta-data).
432 * @param md metadata to use
433 * @return NULL on error, otherwise a KSK URI
435 struct GNUNET_FS_Uri *
436 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
440 /* ******************** command-line option parsing API *********************** */
443 * Allow user to specify keywords.
445 * @param shortName short name of the option
446 * @param name long name of the option
447 * @param argumentHelp help text for the option argument
448 * @param description long help text for the option
449 * @param[out] topKeywords set to the desired value
451 struct GNUNET_GETOPT_CommandLineOption
452 GNUNET_FS_GETOPT_KEYWORDS (char shortName,
454 const char *argumentHelp,
455 const char *description,
456 struct GNUNET_FS_Uri **topKeywords);
459 * Allow user to specify metadata.
461 * @param shortName short name of the option
462 * @param name long name of the option
463 * @param argumentHelp help text for the option argument
464 * @param description long help text for the option
465 * @param[out] metadata set to the desired value
467 struct GNUNET_GETOPT_CommandLineOption
468 GNUNET_FS_GETOPT_METADATA (char shortName,
470 const char *argumentHelp,
471 const char *description,
472 struct GNUNET_CONTAINER_MetaData **meta);
475 * Command-line option parser function that allows the user to specify
476 * one or more '-m' options with metadata. Each specified entry of
477 * the form "type=value" will be added to the metadata. A pointer to
478 * the metadata must be passed as the "scls" argument.
480 * @param ctx command line processor context
481 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
482 * @param option name of the option (typically 'k')
483 * @param value command line argument given
484 * @return #GNUNET_OK on success
487 GNUNET_FS_getopt_set_metadata (struct
488 GNUNET_GETOPT_CommandLineProcessorContext *ctx,
495 /* ************************* sharing API ***************** */
499 * Possible status codes used in the callback for the
500 * various file-sharing operations. On each file (or search),
501 * the callback is guaranteed to be called once with "START"
502 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
503 * are optional and depend on the circumstances; parent operations
504 * will be STARTED before child-operations and STOPPED after
505 * their respective child-operations. START and STOP signals
506 * are typically generated either due to explicit client requests
507 * or because of suspend/resume operations.
509 enum GNUNET_FS_Status
512 * Notification that we have started to publish a file structure.
514 GNUNET_FS_STATUS_PUBLISH_START = 0,
517 * Notification that we have resumed sharing a file structure.
519 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
522 * Notification that we have suspended sharing a file structure.
524 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
527 * Notification that we are making progress sharing a file structure.
529 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
532 * Notification that an error was encountered sharing a file structure.
533 * The application will continue to receive resume/suspend events for
534 * this structure until "GNUNET_FS_publish_stop" is called.
536 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
539 * Notification that we completed sharing a file structure.
540 * The application will continue to receive resume/suspend events for
541 * this structure until "GNUNET_FS_publish_stop" is called.
543 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
546 * Notification that we have stopped
547 * the process of uploading a file structure; no
548 * futher events will be generated for this action.
550 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
553 * Notification that we have started this download.
555 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
558 * Notification that this download is being resumed.
560 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
563 * Notification that this download was suspended.
565 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
568 * Notification about progress with this download.
570 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
573 * Notification that this download encountered an error.
575 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
578 * Notification that this download completed. Note that for
579 * directories, completion does not imply completion of all files in
582 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
585 * Notification that this download was stopped
586 * (final event with respect to this action).
588 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
591 * Notification that this download is now actively being
592 * pursued (as opposed to waiting in the queue).
594 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
597 * Notification that this download is no longer actively
598 * being pursued (back in the queue).
600 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
603 * Notification that this download is no longer part of a
604 * recursive download or search but now a 'stand-alone'
605 * download (and may thus need to be moved in the GUI
606 * into a different category).
608 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
611 * First event generated when a client requests
612 * a search to begin or when a namespace result
613 * automatically triggers the search for updates.
615 GNUNET_FS_STATUS_SEARCH_START = 17,
618 * Last event when a search is being resumed;
619 * note that "GNUNET_FS_SEARCH_START" will not
620 * be generated in this case.
622 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
625 * Event generated for each search result
626 * when the respective search is resumed.
628 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
631 * Last event when a search is being suspended;
632 * note that "GNUNET_FS_SEARCH_STOPPED" will not
633 * be generated in this case.
635 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
638 * This search has yielded a result.
640 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
643 * We have discovered a new namespace.
645 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
648 * We have additional data about the quality
649 * or availability of a search result.
651 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
654 * Signals a problem with this search.
656 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
659 * Signals that this search was paused.
661 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
664 * Signals that this search was continued (unpaused).
666 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
669 * Event generated for each search result
670 * when the respective search is stopped.
672 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
675 * Event generated for each search result
676 * when the respective search is suspended.
678 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
681 * Last message from a search; this signals
682 * that there will be no further events associated
685 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
688 * Notification that we started to unindex a file.
690 GNUNET_FS_STATUS_UNINDEX_START = 30,
693 * Notification that we resumed unindexing of a file.
695 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
698 * Notification that we suspended unindexing a file.
700 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
703 * Notification that we made progress unindexing a file.
705 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
708 * Notification that we encountered an error unindexing
711 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
714 * Notification that the unindexing of this file
717 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
720 * Notification that the unindexing of this file
721 * was stopped (final event for this action).
723 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36,
726 * Notification that we are making progress sharing a directory.
728 GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY = 37
733 * Handle for controlling an upload.
735 struct GNUNET_FS_PublishContext;
739 * Handle for controlling an unindexing operation.
741 struct GNUNET_FS_UnindexContext;
745 * Handle for controlling a search.
747 struct GNUNET_FS_SearchContext;
751 * Result from a search. Opaque handle to refer to the search
752 * (typically used when starting a download associated with the search
755 struct GNUNET_FS_SearchResult;
759 * Context for controlling a download.
761 struct GNUNET_FS_DownloadContext;
765 * Handle for detail information about a file that is being publishd.
766 * Specifies metadata, keywords, how to get the contents of the file
767 * (i.e. data-buffer in memory, filename on disk) and other options.
769 struct GNUNET_FS_FileInformation;
773 * Argument given to the progress callback with
774 * information about what is going on.
776 struct GNUNET_FS_ProgressInfo
779 * Values that depend on the event type.
784 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
789 * Context for controlling the upload.
791 struct GNUNET_FS_PublishContext *pc;
794 * Information about the file that is being publishd.
796 const struct GNUNET_FS_FileInformation *fi;
799 * Client context pointer (set the last time by the client for
800 * this operation; initially NULL on START/RESUME events).
805 * Client context pointer for the parent operation
806 * (if this is a file in a directory or a subdirectory).
811 * Name of the file being published; can be NULL.
813 const char *filename;
816 * How large is the file overall? For directories,
817 * this is only the size of the directory itself,
818 * not of the other files contained within the
824 * At what time do we expect to finish the upload?
825 * (will be a value in the past for completed
828 struct GNUNET_TIME_Relative eta;
831 * How long has this upload been actively running
832 * (excludes times where the upload was suspended).
834 struct GNUNET_TIME_Relative duration;
837 * How many bytes have we completed?
842 * What anonymity level is used for this upload?
847 * Additional values for specific events.
852 * These values are only valid for
853 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
858 * Data block we just published.
863 * At what offset in the file is "data"?
868 * Length of the data block.
873 * Depth of the given block in the tree;
874 * 0 would be the lowest level (DBLOCKs).
880 * These values are only valid for
881 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY events.
886 * How far are we along in the overall directory?
891 * How big do we estimate the entire directory to be?
896 * At what time do we expect to finish the upload of the
897 * CONTENTS of the directory. (The direcory itself will take
898 * extra time, indicated with the "eta" member at the
899 * "publish"-level of this struct.)
901 struct GNUNET_TIME_Relative eta;
902 } progress_directory;
905 * These values are only valid for
906 * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
911 * Error message, NULL if no error was encountered so far.
916 * URI of the file (if the download had been completed)
918 const struct GNUNET_FS_Uri *chk_uri;
921 * SKS URI of the file (if the download had been completed)
923 const struct GNUNET_FS_Uri *sks_uri;
927 * These values are only valid for
928 * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
933 * CHK URI of the file.
935 const struct GNUNET_FS_Uri *chk_uri;
938 * SKS URI of the file (if the download had been completed)
940 const struct GNUNET_FS_Uri *sks_uri;
944 * These values are only valid for
945 * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
950 * Error message, never NULL.
959 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
964 * Context for controlling the download.
966 struct GNUNET_FS_DownloadContext *dc;
969 * Client context pointer (set the last time
970 * by the client for this operation; initially
971 * NULL on START/RESUME events).
976 * Client context pointer for the parent operation
977 * (if this is a file in a directory or a subdirectory).
982 * Client context pointer for the associated search operation
983 * (specifically, context pointer for the specific search
984 * result, not the overall search); only set if this
985 * download was started from a search result.
990 * URI used for this download.
992 const struct GNUNET_FS_Uri *uri;
995 * Name of the file that we are downloading.
997 const char *filename;
1000 * How large is the download overall? This
1001 * is NOT necessarily the size from the
1002 * URI since we may be doing a partial download.
1007 * At what time do we expect to finish the download?
1008 * (will be a value in the past for completed
1011 struct GNUNET_TIME_Relative eta;
1014 * How long has this download been active?
1016 struct GNUNET_TIME_Relative duration;
1019 * How many bytes have we completed?
1024 * What anonymity level is used for this download?
1029 * Is the download currently active.
1034 * Additional values for specific events.
1039 * These values are only valid for
1040 * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1045 * Data block we just obtained, can be NULL (even if
1046 * data_len > 0) if we found the entire block 'intact' on
1047 * disk. In this case, it is also possible for 'data_len'
1048 * to be larger than an individual (32k) block.
1053 * At what offset in the file is "data"?
1058 * Length of the data block.
1063 * How much time passed between us asking for this block and
1064 * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1066 struct GNUNET_TIME_Relative block_download_duration;
1069 * Depth of the given block in the tree;
1070 * 0 would be the lowest level (DBLOCKS).
1075 * How much respect did we offer for downloading this block? (estimate,
1076 * because we might have the same request pending for multiple clients,
1077 * and of course because a transmission may have failed at a lower
1080 uint32_t respect_offered;
1083 * How often did we transmit the request? (estimate,
1084 * because we might have the same request pending for multiple clients,
1085 * and of course because a transmission may have failed at a lower
1088 uint32_t num_transmissions;
1092 * These values are only valid for
1093 * #GNUNET_FS_STATUS_DOWNLOAD_START events.
1098 * Known metadata for the download.
1100 const struct GNUNET_CONTAINER_MetaData *meta;
1104 * These values are only valid for
1105 * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1110 * Known metadata for the download.
1112 const struct GNUNET_CONTAINER_MetaData *meta;
1115 * Error message, NULL if we have not encountered any error yet.
1117 const char *message;
1121 * These values are only valid for
1122 * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1129 const char *message;
1135 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1140 * Context for controlling the search, NULL for
1141 * searches that were not explicitly triggered
1142 * by the client (i.e., searches for updates in
1145 struct GNUNET_FS_SearchContext *sc;
1148 * Client context pointer (set the last time by the client for
1149 * this operation; initially NULL on START/RESUME events). Note
1150 * that this value can only be set on START/RESUME; returning
1151 * non-NULL on RESULT/RESUME_RESULT will actually update the
1152 * private context for "UPDATE" events.
1157 * Client parent-context pointer; NULL for top-level searches,
1158 * refers to the client context of the associated search result
1159 * for automatically triggered searches for updates in
1160 * namespaces. In this case, 'presult' refers to that search
1166 * What query is used for this search
1167 * (list of keywords or SKS identifier).
1169 const struct GNUNET_FS_Uri *query;
1172 * How long has this search been actively running
1173 * (excludes times where the search was paused or
1176 struct GNUNET_TIME_Relative duration;
1179 * What anonymity level is used for this search?
1184 * Additional values for specific events.
1189 * These values are only valid for
1190 * #GNUNET_FS_STATUS_SEARCH_RESULT events.
1195 * Metadata for the search result.
1197 const struct GNUNET_CONTAINER_MetaData *meta;
1200 * URI for the search result.
1202 const struct GNUNET_FS_Uri *uri;
1205 * Handle to the result (for starting downloads).
1207 struct GNUNET_FS_SearchResult *result;
1210 * Applicability rank (the larger, the better the result
1211 * fits the search criteria).
1213 uint32_t applicability_rank;
1217 * These values are only valid for
1218 * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1223 * Metadata for the search result.
1225 const struct GNUNET_CONTAINER_MetaData *meta;
1228 * URI for the search result.
1230 const struct GNUNET_FS_Uri *uri;
1233 * Handle to the result (for starting downloads).
1235 struct GNUNET_FS_SearchResult *result;
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;
1258 * These values are only valid for
1259 * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
1264 * Private context set for for this result
1265 * during the "RESULT" event.
1270 * Metadata for the search result.
1272 const struct GNUNET_CONTAINER_MetaData *meta;
1275 * URI for the search result.
1277 const struct GNUNET_FS_Uri *uri;
1280 * Current availability rank (negative:
1281 * unavailable, positive: available)
1283 int32_t availability_rank;
1286 * On how many total queries is the given
1287 * availability_rank based?
1289 uint32_t availability_certainty;
1292 * Updated applicability rank (the larger,
1293 * the better the result fits the search
1296 uint32_t applicability_rank;
1299 * How long has the current probe been active?
1301 struct GNUNET_TIME_Relative current_probe_time;
1305 * These values are only valid for
1306 * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1307 * These events are automatically triggered for
1308 * each search result before the
1309 * #GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1310 * happens primarily to give the client a chance
1311 * to clean up the "cctx" (if needed).
1316 * Private context set for for this result
1317 * during the "RESULT" event.
1322 * Metadata for the search result.
1324 const struct GNUNET_CONTAINER_MetaData *meta;
1327 * URI for the search result.
1329 const struct GNUNET_FS_Uri *uri;
1333 * These values are only valid for
1334 * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1335 * These events are automatically triggered for
1336 * each search result before the
1337 * #GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1338 * happens primarily to give the client a chance
1339 * to clean up the "cctx" (if needed).
1344 * Private context set for for this result
1345 * during the "RESULT" event.
1350 * Metadata for the search result.
1352 const struct GNUNET_CONTAINER_MetaData *meta;
1355 * URI for the search result.
1357 const struct GNUNET_FS_Uri *uri;
1361 * These values are only valid for
1362 * #GNUNET_FS_STATUS_SEARCH_RESUME events.
1367 * Error message, NULL if we have not encountered any error yet.
1369 const char *message;
1372 * Is this search currently paused?
1378 * These values are only valid for
1379 * #GNUNET_FS_STATUS_SEARCH_ERROR events.
1386 const char *message;
1390 * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
1395 * Short, human-readable name of the namespace.
1400 * Root identifier for the namespace, can be NULL.
1405 * Metadata for the namespace.
1407 const struct GNUNET_CONTAINER_MetaData *meta;
1410 * Public key of the namespace.
1412 struct GNUNET_CRYPTO_EcdsaPublicKey pseudonym;
1418 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1423 * Context for controlling the unindexing.
1425 struct GNUNET_FS_UnindexContext *uc;
1428 * Client context pointer (set the last time
1429 * by the client for this operation; initially
1430 * NULL on START/RESUME events).
1435 * Name of the file that is being unindexed.
1437 const char *filename;
1440 * How large is the file overall?
1445 * At what time do we expect to finish unindexing?
1446 * (will be a value in the past for completed
1447 * unindexing opeations).
1449 struct GNUNET_TIME_Relative eta;
1452 * How long has this upload been actively running
1453 * (excludes times where the upload was suspended).
1455 struct GNUNET_TIME_Relative duration;
1458 * How many bytes have we completed?
1463 * Additional values for specific events.
1468 * These values are only valid for
1469 * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1474 * Data block we just unindexed.
1479 * At what offset in the file is "data"?
1484 * Length of the data block.
1489 * Depth of the given block in the tree;
1490 * 0 would be the lowest level (DBLOCKS).
1496 * These values are only valid for
1497 * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
1502 * Error message, NULL if we have not encountered any error yet.
1504 const char *message;
1508 * These values are only valid for
1509 * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
1516 const char *message;
1523 * Specific status code (determines the event type).
1525 enum GNUNET_FS_Status status;
1528 * File-sharing handle that generated the event.
1530 struct GNUNET_FS_Handle *fsh;
1535 * Notification of FS to a client about the progress of an
1536 * operation. Callbacks of this type will be used for uploads,
1537 * downloads and searches. Some of the arguments depend a bit
1538 * in their meaning on the context in which the callback is used.
1540 * @param cls closure
1541 * @param info details about the event, specifying the event type
1542 * and various bits about the event
1543 * @return client-context (for the next progress call
1544 * for this operation; should be set to NULL for
1545 * SUSPEND and STOPPED events). The value returned
1546 * will be passed to future callbacks in the respective
1547 * field in the `struct GNUNET_FS_ProgressInfo`.
1550 (*GNUNET_FS_ProgressCallback) (void *cls,
1551 const struct GNUNET_FS_ProgressInfo *info);
1555 * General (global) option flags for file-sharing.
1557 enum GNUNET_FS_Flags
1560 * No special flags set.
1562 GNUNET_FS_FLAGS_NONE = 0,
1565 * Is persistence of operations desired?
1566 * (will create SUSPEND/RESUME events).
1568 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1571 * Should we automatically trigger probes for search results
1572 * to determine availability?
1573 * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
1575 GNUNET_FS_FLAGS_DO_PROBES = 2
1580 * Options specified in the VARARGs portion of GNUNET_FS_start.
1582 enum GNUNET_FS_OPTIONS
1585 * Last option in the VARARG list.
1587 GNUNET_FS_OPTIONS_END = 0,
1590 * Select the desired amount of parallelism (this option should be
1591 * followed by an "unsigned int" giving the desired maximum number
1592 * of parallel downloads).
1594 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1597 * Maximum number of requests that should be pending at a given
1598 * point in time (invidivual downloads may go above this, but
1599 * if we are above this threshold, we should not activate any
1600 * additional downloads.
1602 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1607 * Settings for publishing a block (which may of course also
1608 * apply to an entire directory or file).
1610 struct GNUNET_FS_BlockOptions
1613 * At what time should the block expire? Data blocks (DBLOCKS and
1614 * IBLOCKS) may still be used even if they are expired (however,
1615 * they'd be removed quickly from the datastore if we are short on
1616 * space), all other types of blocks will no longer be returned
1617 * after they expire.
1619 struct GNUNET_TIME_Absolute expiration_time;
1622 * At which anonymity level should the block be shared?
1623 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1625 uint32_t anonymity_level;
1628 * How important is it for us to store the block? If we run
1629 * out of space, the highest-priority, non-expired blocks will
1632 uint32_t content_priority;
1635 * How often should we try to migrate the block to other peers?
1636 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1637 * first push each block to other peers according to their
1638 * replication levels. Once each block has been pushed that many
1639 * times to other peers, blocks are chosen for migration at random.
1640 * Naturally, there is no guarantee that the other peers will keep
1641 * these blocks for any period of time (since they won't have any
1642 * priority or might be too busy to even store the block in the
1645 uint32_t replication_level;
1650 * Handle to the file-sharing service.
1652 struct GNUNET_FS_Handle;
1656 * Setup a connection to the file-sharing service.
1658 * @param cfg configuration to use
1659 * @param client_name unique identifier for this client
1660 * @param upcb function to call to notify about FS actions
1661 * @param upcb_cls closure for @a upcb
1662 * @param flags specific attributes for fs-operations
1663 * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
1664 * @return NULL on error
1666 struct GNUNET_FS_Handle *
1667 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1668 const char *client_name,
1669 GNUNET_FS_ProgressCallback upcb,
1671 enum GNUNET_FS_Flags flags,
1676 * Close our connection with the file-sharing service.
1677 * The callback given to #GNUNET_FS_start() will no longer be
1678 * called after this function returns.
1679 * This function MUST NOT be called from within the
1682 * @param h handle that was returned from #GNUNET_FS_start()
1685 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1689 * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
1691 * @param cls closure
1692 * @param fi the entry in the publish-structure
1693 * @param length length of the file or directory
1694 * @param meta metadata for the file or directory (can be modified)
1695 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1696 * @param bo block options (can be modified)
1697 * @param do_index should we index (can be modified)
1698 * @param client_info pointer to client context set upon creation (can be modified)
1699 * @return #GNUNET_OK to continue, #GNUNET_NO to remove
1700 * this entry from the directory, #GNUNET_SYSERR
1701 * to abort the iteration
1704 (*GNUNET_FS_FileInformationProcessor) (void *cls,
1705 struct GNUNET_FS_FileInformation *fi,
1707 struct GNUNET_CONTAINER_MetaData *meta,
1708 struct GNUNET_FS_Uri **uri,
1709 struct GNUNET_FS_BlockOptions *bo,
1711 void **client_info);
1715 * Obtain the name under which this file information
1716 * structure is stored on disk. Only works for top-level
1717 * file information structures.
1719 * @param s structure to get the filename for
1720 * @return NULL on error, otherwise filename that can be used
1721 * to read this fi-struct from disk.
1724 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1728 * Obtain the filename from the file information structure.
1730 * @param s structure to get the filename for
1731 * @return "filename" field of the structure (can be NULL)
1734 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1738 * Set the filename in the file information structure.
1739 * If filename was already set, frees it before setting the new one.
1740 * Makes a copy of the argument.
1742 * @param s structure to get the filename for
1743 * @param filename filename to set
1746 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1747 const char *filename);
1751 * Create an entry for a file in a publish-structure.
1753 * @param h handle to the file sharing subsystem
1754 * @param client_info initial client-info value for this entry
1755 * @param filename name of the file or directory to publish
1756 * @param keywords under which keywords should this file be available
1757 * directly; can be NULL
1758 * @param meta metadata for the file
1759 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1760 * #GNUNET_SYSERR for simulation
1761 * @param bo block options
1762 * @return publish structure entry for the file
1764 struct GNUNET_FS_FileInformation *
1765 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1767 const char *filename,
1769 GNUNET_FS_Uri *keywords,
1771 GNUNET_CONTAINER_MetaData *meta,
1774 GNUNET_FS_BlockOptions *bo);
1778 * Create an entry for a file in a publish-structure.
1780 * @param h handle to the file sharing subsystem
1781 * @param client_info initial client-info value for this entry
1782 * @param length length of the file
1783 * @param data data for the file (should not be used afterwards by
1784 * the caller; callee will "free")
1785 * @param keywords under which keywords should this file be available
1786 * directly; can be NULL
1787 * @param meta metadata for the file
1788 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1789 * #GNUNET_SYSERR for simulation
1790 * @param bo block options
1791 * @return publish structure entry for the file
1793 struct GNUNET_FS_FileInformation *
1794 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1799 GNUNET_FS_Uri *keywords,
1801 GNUNET_CONTAINER_MetaData *meta,
1804 GNUNET_FS_BlockOptions *bo);
1808 * Function that provides data.
1810 * @param cls closure
1811 * @param offset offset to read from; it is possible
1812 * that the caller might need to go backwards
1813 * a bit at times; set to UINT64_MAX to tell
1814 * the reader that we won't be reading for a while
1815 * (used to close the file descriptor but NOT fully
1816 * clean up the reader's state); in this case,
1817 * a value of '0' for max should be ignored
1818 * @param max maximum number of bytes that should be
1819 * copied to buf; readers are not allowed
1820 * to provide less data unless there is an error;
1821 * a value of "0" will be used at the end to allow
1822 * the reader to clean up its internal state
1823 * @param buf where the reader should write the data
1824 * @param emsg location for the reader to store an error message
1825 * @return number of bytes written, usually @a max, 0 on error
1828 (*GNUNET_FS_DataReader) (void *cls,
1836 * Create an entry for a file in a publish-structure.
1838 * @param h handle to the file sharing subsystem
1839 * @param client_info initial client-info value for this entry
1840 * @param length length of the file
1841 * @param reader function that can be used to obtain the data for the file
1842 * @param reader_cls closure for @a reader
1843 * @param keywords under which keywords should this file be available
1844 * directly; can be NULL
1845 * @param meta metadata for the file
1846 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1847 * #GNUNET_SYSERR for simulation
1848 * @param bo block options
1849 * @return publish structure entry for the file
1851 struct GNUNET_FS_FileInformation *
1852 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1855 GNUNET_FS_DataReader reader,
1857 const struct GNUNET_FS_Uri
1860 GNUNET_CONTAINER_MetaData *meta,
1863 GNUNET_FS_BlockOptions *bo);
1867 * Create an entry for an empty directory in a publish-structure.
1869 * @param h handle to the file sharing subsystem
1870 * @param client_info initial client-info value for this entry
1871 * @param keywords under which keywords should this directory be available
1872 * directly; can be NULL
1873 * @param meta metadata for the directory
1874 * @param bo block options
1875 * @param filename name of the directory; can be NULL
1876 * @return publish structure entry for the directory , NULL on error
1878 struct GNUNET_FS_FileInformation *
1879 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1881 const struct GNUNET_FS_Uri
1884 GNUNET_CONTAINER_MetaData
1887 GNUNET_FS_BlockOptions *bo,
1888 const char *filename);
1892 * Test if a given entry represents a directory.
1894 * @param ent check if this FI represents a directory
1895 * @return #GNUNET_YES if so, #GNUNET_NO if not
1898 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1903 * Add an entry to a directory in a publish-structure. Clients
1904 * should never modify publish structures that were passed to
1905 * #GNUNET_FS_publish_start() already.
1907 * @param dir the directory
1908 * @param ent the entry to add; the entry must not have been
1909 * added to any other directory at this point and
1910 * must not include @a dir in its structure
1911 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1914 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1915 struct GNUNET_FS_FileInformation *ent);
1919 * Inspect a file or directory in a publish-structure. Clients
1920 * should never modify publish structures that were passed to
1921 * #GNUNET_FS_publish_start already. When called on a directory,
1922 * this function will FIRST call @a proc with information about
1923 * the directory itself and then for each of the files in the
1924 * directory (but not for files in subdirectories). When called
1925 * on a file, @a proc will be called exactly once (with information
1926 * about the specific file).
1928 * @param dir the directory
1929 * @param proc function to call on each entry
1930 * @param proc_cls closure for @a proc
1933 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1934 GNUNET_FS_FileInformationProcessor proc,
1939 * Destroy publish-structure. Clients should never destroy publish
1940 * structures that were passed to #GNUNET_FS_publish_start already.
1942 * @param fi structure to destroy
1943 * @param cleaner function to call on each entry in the structure
1944 * (useful to clean up client_info); can be NULL; return
1945 * values are ignored
1946 * @param cleaner_cls closure for @a cleaner
1949 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1950 GNUNET_FS_FileInformationProcessor cleaner,
1955 * Options for publishing. Compatible options
1956 * can be OR'ed together.
1958 enum GNUNET_FS_PublishOptions
1961 * No options (use defaults for everything).
1963 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1966 * Simulate publishing. With this option, no data will be stored
1967 * in the datastore. Useful for computing URIs from files.
1969 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1974 * Publish a file or directory.
1976 * @param h handle to the file sharing subsystem
1977 * @param fi information about the file or directory structure to publish
1978 * @param ns namespace to publish the file in, NULL for no namespace
1979 * @param nid identifier to use for the publishd content in the namespace
1980 * (can be NULL, must be NULL if namespace is NULL)
1981 * @param nuid update-identifier that will be used for future updates
1982 * (can be NULL, must be NULL if namespace or nid is NULL)
1983 * @param options options for the publication
1984 * @return context that can be used to control the publish operation
1986 struct GNUNET_FS_PublishContext *
1987 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1988 struct GNUNET_FS_FileInformation *fi,
1989 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
1992 enum GNUNET_FS_PublishOptions options);
1996 * Stop a publication. Will abort incomplete publications (but
1997 * not remove blocks that have already been published) or
1998 * simply clean up the state for completed publications.
1999 * Must NOT be called from within the event callback!
2001 * @param pc context for the publication to stop
2004 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2008 * Signature of a function called as the continuation of a KBlock or
2009 * SBlock publication.
2011 * @param cls closure
2012 * @param uri URI under which the block is now available, NULL on error
2013 * @param emsg error message, NULL on success
2016 (*GNUNET_FS_PublishContinuation) (void *cls,
2017 const struct GNUNET_FS_Uri *uri,
2022 * Handle to cancel publish KSK operation.
2024 struct GNUNET_FS_PublishKskContext;
2028 * Publish a KBlock on GNUnet.
2030 * @param h handle to the file sharing subsystem
2031 * @param ksk_uri keywords to use
2032 * @param meta metadata to use
2033 * @param uri URI to refer to in the KBlock
2034 * @param bo block options
2035 * @param options publication options
2036 * @param cont continuation
2037 * @param cont_cls closure for @a cont
2038 * @return NULL on error (@a cont will still be called)
2040 struct GNUNET_FS_PublishKskContext *
2041 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2042 const struct GNUNET_FS_Uri *ksk_uri,
2043 const struct GNUNET_CONTAINER_MetaData *meta,
2044 const struct GNUNET_FS_Uri *uri,
2045 const struct GNUNET_FS_BlockOptions *bo,
2046 enum GNUNET_FS_PublishOptions options,
2047 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2051 * Abort the KSK publishing operation.
2053 * @param pkc context of the operation to abort.
2056 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2060 * Handle to cancel publish SKS operation.
2062 struct GNUNET_FS_PublishSksContext;
2066 * Publish an SBlock on GNUnet.
2068 * @param h handle to the file sharing subsystem
2069 * @param ns namespace to publish in
2070 * @param identifier identifier to use
2071 * @param update update identifier to use
2072 * @param meta metadata to use
2073 * @param uri URI to refer to in the SBlock
2074 * @param bo block options
2075 * @param options publication options
2076 * @param cont continuation
2077 * @param cont_cls closure for @a cont
2078 * @return NULL on error (@a cont will still be called)
2080 struct GNUNET_FS_PublishSksContext *
2081 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2082 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2083 const char *identifier,
2085 const struct GNUNET_CONTAINER_MetaData *meta,
2086 const struct GNUNET_FS_Uri *uri,
2087 const struct GNUNET_FS_BlockOptions *bo,
2088 enum GNUNET_FS_PublishOptions options,
2089 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2093 * Abort the SKS publishing operation.
2095 * @param psc context of the operation to abort.
2098 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2102 * Type of a function called by #GNUNET_FS_get_indexed_files.
2104 * @param cls closure
2105 * @param filename the name of the file, NULL for end of list
2106 * @param file_id hash of the contents of the indexed file
2107 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2110 (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2111 const char *filename,
2112 const struct GNUNET_HashCode *file_id);
2116 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2118 struct GNUNET_FS_GetIndexedContext;
2122 * Iterate over all indexed files.
2124 * @param h handle to the file sharing subsystem
2125 * @param iterator function to call on each indexed file
2126 * @param iterator_cls closure for @a iterator
2127 * @return NULL on error (@a iterator is not called)
2129 struct GNUNET_FS_GetIndexedContext *
2130 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2131 GNUNET_FS_IndexedFileProcessor iterator,
2132 void *iterator_cls);
2136 * Cancel iteration over all indexed files.
2138 * @param gic operation to cancel
2141 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2147 * @param h handle to the file sharing subsystem
2148 * @param filename file to unindex
2149 * @param cctx initial value for the client context
2150 * @return NULL on error, otherwise handle
2152 struct GNUNET_FS_UnindexContext *
2153 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2154 const char *filename,
2159 * Clean up after completion of an unindex operation.
2164 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2168 * Function called on updateable identifiers.
2170 * @param cls closure
2171 * @param last_id last identifier
2172 * @param last_uri uri used for the content published under the @a last_id
2173 * @param last_meta metadata associated with @a last_uri
2174 * @param next_id identifier that should be used for updates
2176 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2177 const char *last_id,
2179 GNUNET_FS_Uri *last_uri,
2181 GNUNET_CONTAINER_MetaData *
2183 const char *next_id);
2187 * List all of the identifiers in the namespace for which we could
2188 * produce an update. Namespace updates form a graph where each node
2189 * has a name. Each node can have any number of URI/meta-data entries
2190 * which can each be linked to other nodes. Cycles are possible.
2192 * Calling this function with @a next_id NULL will cause the library to
2193 * call @a ip with a root for each strongly connected component of the
2194 * graph (a root being a node from which all other nodes in the Scc
2197 * Calling this function with @a next_id being the name of a node will
2198 * cause the library to call @a ip with all children of the node. Note
2199 * that cycles within an SCC are possible (including self-loops).
2201 * @param h fs handle to use
2202 * @param ns namespace to inspect for updateable content
2203 * @param next_id ID to look for; use NULL to look for SCC roots
2204 * @param ip function to call on each updateable identifier
2205 * @param ip_cls closure for @a ip
2208 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
2210 GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2211 const char *next_id,
2212 GNUNET_FS_IdentifierProcessor ip,
2217 * Options for searching. Compatible options
2218 * can be OR'ed together.
2220 enum GNUNET_FS_SearchOptions
2223 * No options (use defaults for everything).
2225 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2228 * Only search the local host, do not search remote systems (no P2P)
2230 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2235 * Start search for content.
2237 * @param h handle to the file sharing subsystem
2238 * @param uri specifies the search parameters; can be
2239 * a KSK URI or an SKS URI.
2240 * @param anonymity desired level of anonymity
2241 * @param options options for the search
2242 * @param cctx initial value for the client context
2243 * @return context that can be used to control the search
2245 struct GNUNET_FS_SearchContext *
2246 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2247 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2248 enum GNUNET_FS_SearchOptions options, void *cctx);
2254 * @param sc context for the search that should be paused
2257 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2261 * Continue paused search.
2263 * @param sc context for the search that should be resumed
2266 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2270 * Stop search for content.
2272 * @param sc context for the search that should be stopped
2275 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2279 * Start download probes for the given search result.
2281 * @param h file-sharing handle to use for the operation
2282 * @param uri URI to probe
2283 * @param meta meta data associated with the URI
2284 * @param client_info client info pointer to use for associated events
2285 * @param anonymity anonymity level to use for the probes
2286 * @return the search result handle to access the probe activity
2288 struct GNUNET_FS_SearchResult *
2289 GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2290 const struct GNUNET_FS_Uri *uri,
2291 const struct GNUNET_CONTAINER_MetaData *meta,
2293 uint32_t anonymity);
2297 * Stop probe activity. Must ONLY be used on values
2298 * returned from #GNUNET_FS_probe.
2300 * @param sr search result to stop probing for (freed)
2301 * @return the value of the 'client_info' pointer
2304 GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2308 * Options for downloading. Compatible options
2309 * can be OR'ed together.
2311 enum GNUNET_FS_DownloadOptions
2314 * No options (use defaults for everything).
2316 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2319 * Only download from the local host, do not access remote systems (no P2P)
2321 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2324 * Do a recursive download (that is, automatically trigger the
2325 * download of files in directories).
2327 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2330 * Do not append temporary data to
2331 * the target file (for the IBlocks).
2333 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2336 * Internal option used to flag this download as a 'probe' for a
2337 * search result. Impacts the priority with which the download is
2338 * run and causes signalling callbacks to be done differently.
2339 * Also, probe downloads are not serialized on suspension. Normal
2340 * clients should not use this!
2342 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2348 * Download parts of a file. Note that this will store
2349 * the blocks at the respective offset in the given file. Also, the
2350 * download is still using the blocking of the underlying FS
2351 * encoding. As a result, the download may *write* outside of the
2352 * given boundaries (if offset and length do not match the 32k FS
2353 * block boundaries).
2355 * The given range can be used to focus a download towards a
2356 * particular portion of the file (optimization), not to strictly
2357 * limit the download to exactly those bytes.
2359 * @param h handle to the file sharing subsystem
2360 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2361 * @param meta known metadata for the file (can be NULL)
2362 * @param filename where to store the file, maybe NULL (then no file is
2363 * created on disk and data must be grabbed from the callbacks)
2364 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2365 * can be NULL (in which case we will pick a name if needed); the temporary file
2366 * may already exist, in which case we will try to use the data that is there and
2367 * if it is not what is desired, will overwrite it
2368 * @param offset at what offset should we start the download (typically 0)
2369 * @param length how many bytes should be downloaded starting at offset
2370 * @param anonymity anonymity level to use for the download
2371 * @param options various download options
2372 * @param cctx initial value for the client context for this download
2373 * @param parent parent download to associate this download with (use NULL
2374 * for top-level downloads; useful for manually-triggered recursive downloads)
2375 * @return context that can be used to control this download
2377 struct GNUNET_FS_DownloadContext *
2378 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2379 const struct GNUNET_FS_Uri *uri,
2380 const struct GNUNET_CONTAINER_MetaData *meta,
2381 const char *filename, const char *tempname,
2382 uint64_t offset, uint64_t length, uint32_t anonymity,
2383 enum GNUNET_FS_DownloadOptions options, void *cctx,
2384 struct GNUNET_FS_DownloadContext *parent);
2388 * Download parts of a file based on a search result. The download
2389 * will be associated with the search result (and the association
2390 * will be preserved when serializing/deserializing the state).
2391 * If the search is stopped, the download will not be aborted but
2392 * be 'promoted' to a stand-alone download.
2394 * As with the other download function, this will store
2395 * the blocks at the respective offset in the given file. Also, the
2396 * download is still using the blocking of the underlying FS
2397 * encoding. As a result, the download may *write* outside of the
2398 * given boundaries (if offset and length do not match the 32k FS
2399 * block boundaries).
2401 * The given range can be used to focus a download towards a
2402 * particular portion of the file (optimization), not to strictly
2403 * limit the download to exactly those bytes.
2405 * @param h handle to the file sharing subsystem
2406 * @param sr the search result to use for the download (determines uri and
2407 * meta data and associations)
2408 * @param filename where to store the file, maybe NULL (then no file is
2409 * created on disk and data must be grabbed from the callbacks)
2410 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2411 * can be NULL (in which case we will pick a name if needed); the temporary file
2412 * may already exist, in which case we will try to use the data that is there and
2413 * if it is not what is desired, will overwrite it
2414 * @param offset at what offset should we start the download (typically 0)
2415 * @param length how many bytes should be downloaded starting at offset
2416 * @param anonymity anonymity level to use for the download
2417 * @param options various download options
2418 * @param cctx initial value for the client context for this download
2419 * @return context that can be used to control this download
2421 struct GNUNET_FS_DownloadContext *
2422 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2423 struct GNUNET_FS_SearchResult *sr,
2424 const char *filename,
2425 const char *tempname, uint64_t offset,
2426 uint64_t length, uint32_t anonymity,
2427 enum GNUNET_FS_DownloadOptions options,
2432 * Stop a download (aborts if download is incomplete).
2434 * @param dc handle for the download
2435 * @param do_delete delete files of incomplete downloads
2438 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2442 * Suspend a download.
2444 * @param dc handle for the download
2447 GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc);
2451 * Resume a suspended download.
2453 * @param dc handle for the download
2456 GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2460 /* ******************** Directory API *********************** */
2463 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2464 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2465 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2468 * Does the meta-data claim that this is a directory?
2469 * Checks if the mime-type is that of a GNUnet directory.
2471 * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
2472 * we have no mime-type information (treat as #GNUNET_NO)
2475 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2480 * Set the MIMETYPE information for the given
2481 * metadata to "application/gnunet-directory".
2483 * @param md metadata to add mimetype to
2486 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2490 * Suggest a filename based on given metadata.
2492 * @param md given meta data
2493 * @return NULL if meta data is useless for suggesting a filename
2496 GNUNET_FS_meta_data_suggest_filename (const struct
2497 GNUNET_CONTAINER_MetaData *md);
2501 * Function used to process entries in a directory.
2503 * @param cls closure
2504 * @param filename name of the file in the directory
2505 * @param uri URI of the file
2506 * @param metadata metadata for the file; metadata for
2507 * the directory if everything else is NULL/zero
2508 * @param length length of the available data for the file
2509 * (of type size_t since data must certainly fit
2510 * into memory; if files are larger than size_t
2511 * permits, then they will certainly not be
2512 * embedded with the directory itself).
2513 * @param data data available for the file (length bytes)
2515 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2516 const char *filename,
2517 const struct GNUNET_FS_Uri *
2520 GNUNET_CONTAINER_MetaData *
2521 meta, size_t length,
2526 * Iterate over all entries in a directory. Note that directories
2527 * are structured such that it is possible to iterate over the
2528 * individual blocks as well as over the entire directory. Thus
2529 * a client can call this function on the buffer in the
2530 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2531 * include the contents of (small) files embedded in the directory
2532 * itself; for those files, the processor may be given the
2533 * contents of the file directly by this function.
2535 * @param size number of bytes in data
2536 * @param data pointer to the beginning of the directory
2537 * @param offset offset of data in the directory
2538 * @param dep function to call on each entry
2539 * @param dep_cls closure for @a dep
2540 * @return #GNUNET_OK if this could be a block in a directory,
2541 * #GNUNET_NO if this could be part of a directory (but not 100% OK)
2542 * #GNUNET_SYSERR if 'data' does not represent a directory
2545 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2547 GNUNET_FS_DirectoryEntryProcessor dep,
2552 * Opaque handle to a directory builder.
2554 struct GNUNET_FS_DirectoryBuilder;
2558 * Create a directory builder.
2560 * @param mdir metadata for the directory
2562 struct GNUNET_FS_DirectoryBuilder *
2563 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2568 * Add an entry to a directory.
2570 * @param bld directory to extend
2571 * @param uri uri of the entry (must not be a KSK)
2572 * @param md metadata of the entry
2573 * @param data raw data of the entry, can be NULL, otherwise
2574 * data must point to exactly the number of bytes specified
2578 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2579 const struct GNUNET_FS_Uri *uri,
2580 const struct GNUNET_CONTAINER_MetaData *md,
2585 * Finish building the directory. Frees the
2586 * builder context and returns the directory
2589 * @param bld directory to finish
2590 * @param rsize set to the number of bytes needed
2591 * @param rdata set to the encoded directory
2592 * @return #GNUNET_OK on success
2595 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2596 size_t *rsize, void **rdata);
2599 /* ******************** DirScanner API *********************** */
2602 * Progress reasons of the directory scanner.
2604 enum GNUNET_FS_DirScannerProgressUpdateReason
2607 * We've started processing a file or directory.
2609 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2612 * We're having trouble accessing a file (soft-error); it will
2615 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2618 * We've found all files (in the pre-pass).
2620 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2623 * We've finished extracting meta data from a file.
2625 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2628 * Last call to the progress function: we have finished scanning
2631 GNUNET_FS_DIRSCANNER_FINISHED,
2634 * There was an internal error. Application should abort the scan.
2636 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2641 * Function called over time as the directory scanner makes
2642 * progress on the job at hand.
2644 * @param cls closure
2645 * @param filename which file we are making progress on
2646 * @param is_directory #GNUNET_YES if this is a directory,
2647 * #GNUNET_NO if this is a file
2648 * #GNUNET_SYSERR if it is neither (or unknown)
2649 * @param reason kind of progress we are making
2651 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2652 const char *filename,
2655 GNUNET_FS_DirScannerProgressUpdateReason
2660 * A node of a directory tree (produced by dirscanner)
2662 struct GNUNET_FS_ShareTreeItem
2665 * This is a doubly-linked list
2667 struct GNUNET_FS_ShareTreeItem *prev;
2670 * This is a doubly-linked list
2672 struct GNUNET_FS_ShareTreeItem *next;
2675 * This is a doubly-linked tree
2676 * NULL for top-level entries.
2678 struct GNUNET_FS_ShareTreeItem *parent;
2681 * This is a doubly-linked tree
2682 * NULL for files and empty directories
2684 struct GNUNET_FS_ShareTreeItem *children_head;
2687 * This is a doubly-linked tree
2688 * NULL for files and empty directories
2690 struct GNUNET_FS_ShareTreeItem *children_tail;
2693 * Metadata for this file or directory
2695 struct GNUNET_CONTAINER_MetaData *meta;
2698 * Keywords for this file or directory (derived from metadata).
2700 struct GNUNET_FS_Uri *ksk_uri;
2703 * Name of the file/directory
2708 * Base name of the file/directory.
2710 char *short_filename;
2713 * #GNUNET_YES if this is a directory
2720 * Opaque handle to an asynchronous directory scanning activity.
2722 struct GNUNET_FS_DirScanner;
2726 * Start a directory scanner.
2728 * @param filename name of the directory to scan
2729 * @param disable_extractor #GNUNET_YES to not run libextractor on files (only
2731 * @param ex if not NULL, must be a list of extra plugins for extractor
2732 * @param cb the callback to call when there are scanning progress messages
2733 * @param cb_cls closure for @a cb
2734 * @return directory scanner object to be used for controlling the scanner
2736 struct GNUNET_FS_DirScanner *
2737 GNUNET_FS_directory_scan_start (const char *filename,
2738 int disable_extractor,
2740 GNUNET_FS_DirScannerProgressCallback cb,
2745 * Abort the scan. Must not be called from within the progress_callback
2748 * @param ds directory scanner structure
2751 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2755 * Obtain the result of the scan after the scan has signalled
2756 * completion. Must not be called prior to completion. The @a ds is
2757 * freed as part of this call.
2759 * @param ds directory scanner structure
2760 * @return the results of the scan (a directory tree)
2762 struct GNUNET_FS_ShareTreeItem *
2763 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2767 * Process a share item tree, moving frequent keywords up and
2768 * copying frequent metadata up.
2770 * @param toplevel toplevel directory in the tree, returned by the scanner
2773 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2777 * Release memory of a share item tree.
2779 * @param toplevel toplevel of the tree to be freed
2782 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2785 #if 0 /* keep Emacsens' auto-indent happy */
2794 /** @} */ /* end of group */