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/>.
19 * @author Christian Grothoff
22 * API for file sharing via GNUnet
24 * @defgroup fs FS service
27 * @see [Documentation](https://gnunet.org/file-sharing-service)
31 #ifndef GNUNET_FS_LIB_H
32 #define GNUNET_FS_LIB_H
34 #include "gnunet_util_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
45 * Version number of the implementation.
48 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
49 * 2.x.x: root node with mime-type, filename and version number
50 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
51 * 2.2.x: with directories
52 * 3.0.x: with namespaces
53 * 3.1.x: with namespace meta-data
54 * 3.2.x: with collections
55 * 4.0.x: with expiration, variable meta-data, kblocks
56 * 4.1.x: with new error and configuration handling
57 * 5.0.x: with location URIs
58 * 6.0.0: with support for OR in KSKs
59 * 6.1.x: with simplified namespace support
60 * 9.0.0: CPS-style integrated API
61 * 9.1.1: asynchronous directory scanning
62 * 9.2.0: unified K-Block and S-block format (#2564)
63 * 9.3.0: base32crockford encoded URLs
65 #define GNUNET_FS_VERSION 0x00090300
68 /* ******************** URI API *********************** */
70 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
71 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
72 #define GNUNET_FS_URI_SKS_INFIX "sks/"
73 #define GNUNET_FS_URI_CHK_INFIX "chk/"
74 #define GNUNET_FS_URI_LOC_INFIX "loc/"
78 * How often do we signal applications that a probe for a particular
79 * search result is running? (used to visualize probes).
81 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
84 * A Universal Resource Identifier (URI), opaque.
90 * Iterator over keywords
93 * @param keyword the keyword
94 * @param is_mandatory is the keyword mandatory (in a search)
95 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
98 (*GNUNET_FS_KeywordIterator) (void *cls,
105 * Get a unique key from a URI. This is for putting URIs
106 * into HashMaps. The key may change between FS implementations.
108 * @param uri uri to convert to a unique key
109 * @param key wherer to store the unique key
110 * @return #GNUNET_OK on success
113 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
114 struct GNUNET_HashCode *key);
118 * Convert a URI to a UTF-8 String.
120 * @param uri uri to convert to a string
121 * @return the UTF-8 string
124 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
128 * Convert keyword URI to a human readable format
129 * (i.e. the search query that was used in the first place)
131 * @param uri ksk uri to convert to a string
132 * @return string with the keywords
135 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
139 * Add the given keyword to the set of keywords represented by the URI.
140 * Does nothing if the keyword is already present.
142 * @param uri ksk uri to modify
143 * @param keyword keyword to add
144 * @param is_mandatory is this keyword mandatory?
147 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
153 * Remove the given keyword from the set of keywords represented by the URI.
154 * Does nothing if the keyword is not present.
156 * @param uri ksk uri to modify
157 * @param keyword keyword to add
160 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
161 const char *keyword);
165 * Convert a UTF-8 String to a URI.
167 * @param uri string to parse
168 * @param emsg where to store the parser error message (if any)
169 * @return NULL on error
171 struct GNUNET_FS_Uri *
172 GNUNET_FS_uri_parse (const char *uri,
179 * @param uri uri to free
182 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
186 * How many keywords are ANDed in this keyword URI?
188 * @param uri ksk uri to get the number of keywords from
189 * @return 0 if this is not a keyword URI
192 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
196 * Iterate over all keywords in this keyword URI.
198 * @param uri ksk uri to get the keywords from
199 * @param iterator function to call on each keyword
200 * @param iterator_cls closure for @a iterator
201 * @return -1 if this is not a keyword URI, otherwise number of
202 * keywords iterated over until iterator aborted
205 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
206 GNUNET_FS_KeywordIterator iterator,
211 * Obtain the identity of the peer offering the data
213 * @param uri the location URI to inspect
214 * @param peer where to store the identify of the peer (presumably) offering the content
215 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
218 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
219 struct GNUNET_PeerIdentity *peer);
223 * Obtain the URI of the content itself.
225 * @param uri location URI to get the content URI from
226 * @return NULL if argument is not a location URI
228 struct GNUNET_FS_Uri *
229 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
233 * Obtain the expiration of the LOC URI.
235 * @param uri location URI to get the expiration from
236 * @return expiration time of the URI
238 struct GNUNET_TIME_Absolute
239 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
243 * Construct a location URI (this peer will be used for the location).
244 * This function should only be called from within gnunet-service-fs,
245 * as it requires the peer's private key which is generally unavailable
246 * to processes directly under the user's control. However, for
247 * testing and as it logically fits under URIs, it is in this API.
249 * @param base_uri content offered by the sender
250 * @param sign_key private key of the peer
251 * @param expiration_time how long will the content be offered?
252 * @return the location URI, NULL on error
254 struct GNUNET_FS_Uri *
255 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
256 const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
257 struct GNUNET_TIME_Absolute expiration_time);
261 * Merge the sets of keywords from two KSK URIs.
263 * @param u1 first uri
264 * @param u2 second uri
265 * @return merged URI, NULL on error
267 struct GNUNET_FS_Uri *
268 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
269 const struct GNUNET_FS_Uri *u2);
275 * @param uri the URI to duplicate
276 * @return copy of the URI
278 struct GNUNET_FS_Uri *
279 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
283 * Create an FS URI from a single user-supplied string of keywords.
284 * The string is broken up at spaces into individual keywords.
285 * Keywords that start with "+" are mandatory. Double-quotes can
286 * be used to prevent breaking up strings at spaces (and also
287 * to specify non-mandatory keywords starting with "+").
289 * Keywords must contain a balanced number of double quotes and
290 * double quotes can not be used in the actual keywords (for
291 * example, the string '""foo bar""' will be turned into two
292 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
294 * @param keywords the keyword string
295 * @param emsg where to store an error message
296 * @return an FS URI for the given keywords, NULL
297 * if keywords is not legal (i.e. empty).
299 struct GNUNET_FS_Uri *
300 GNUNET_FS_uri_ksk_create (const char *keywords,
305 * Create an FS URI from a user-supplied command line of keywords.
306 * Arguments should start with "+" to indicate mandatory
309 * @param argc number of keywords
310 * @param argv keywords (double quotes are not required for
311 * keywords containing spaces; however, double
312 * quotes are required for keywords starting with
313 * "+"); there is no mechanism for having double
314 * quotes in the actual keywords (if the user
315 * did specifically specify double quotes, the
316 * caller should convert each double quote
317 * into two single quotes).
318 * @return an FS URI for the given keywords, NULL
319 * if keywords is not legal (i.e. empty).
321 struct GNUNET_FS_Uri *
322 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
327 * Test if two URIs are equal.
329 * @param u1 one of the URIs
330 * @param u2 the other URI
331 * @return #GNUNET_YES if the URIs are equal
334 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
335 const struct GNUNET_FS_Uri *u2);
339 * Is this a namespace URI?
341 * @param uri the uri to check
342 * @return #GNUNET_YES if this is an SKS uri
345 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
349 * Create an SKS URI from a namespace ID and an identifier.
351 * @param ns pseudonym to use
352 * @param id identifier
353 * @return an FS URI for the given namespace and identifier
355 struct GNUNET_FS_Uri *
356 GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
361 * Get the public key of a namespace from the given
364 * @param uri the uri to get the namespace ID from
365 * @param pseudonym where to store the public key of the namespace
366 * @return #GNUNET_OK on success
369 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
370 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym);
374 * Get the content identifier of an SKS URI.
376 * @param uri the sks uri
377 * @return NULL on error (not a valid SKS URI)
380 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
384 * Is this a keyword URI?
387 * @return #GNUNET_YES if this is a KSK uri
390 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
394 * Is this a file (or directory) URI?
396 * @param uri the uri to check
397 * @return #GNUNET_YES if this is a CHK uri
400 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
404 * What is the size of the file that this URI
407 * @param uri the CHK (or LOC) URI to inspect
408 * @return size of the file as specified in the CHK URI
411 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
415 * Is this a location URI?
417 * @param uri the uri to check
418 * @return #GNUNET_YES if this is a LOC uri
421 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
425 * Construct a keyword-URI from meta-data (take all entries
426 * in the meta-data and construct one large keyword URI
427 * that lists all keywords that can be found in the meta-data).
429 * @param md metadata to use
430 * @return NULL on error, otherwise a KSK URI
432 struct GNUNET_FS_Uri *
433 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
437 /* ******************** command-line option parsing API *********************** */
440 * Allow user to specify keywords.
442 * @param shortName short name of the option
443 * @param name long name of the option
444 * @param argumentHelp help text for the option argument
445 * @param description long help text for the option
446 * @param[out] topKeywords set to the desired value
448 struct GNUNET_GETOPT_CommandLineOption
449 GNUNET_FS_GETOPT_KEYWORDS (char shortName,
451 const char *argumentHelp,
452 const char *description,
453 struct GNUNET_FS_Uri **topKeywords);
456 * Allow user to specify metadata.
458 * @param shortName short name of the option
459 * @param name long name of the option
460 * @param argumentHelp help text for the option argument
461 * @param description long help text for the option
462 * @param[out] metadata set to the desired value
464 struct GNUNET_GETOPT_CommandLineOption
465 GNUNET_FS_GETOPT_METADATA (char shortName,
467 const char *argumentHelp,
468 const char *description,
469 struct GNUNET_CONTAINER_MetaData **meta);
472 * Command-line option parser function that allows the user to specify
473 * one or more '-m' options with metadata. Each specified entry of
474 * the form "type=value" will be added to the metadata. A pointer to
475 * the metadata must be passed as the "scls" argument.
477 * @param ctx command line processor context
478 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
479 * @param option name of the option (typically 'k')
480 * @param value command line argument given
481 * @return #GNUNET_OK on success
484 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
491 /* ************************* sharing API ***************** */
495 * Possible status codes used in the callback for the
496 * various file-sharing operations. On each file (or search),
497 * the callback is guaranteed to be called once with "START"
498 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
499 * are optional and depend on the circumstances; parent operations
500 * will be STARTED before child-operations and STOPPED after
501 * their respective child-operations. START and STOP signals
502 * are typically generated either due to explicit client requests
503 * or because of suspend/resume operations.
505 enum GNUNET_FS_Status
508 * Notification that we have started to publish a file structure.
510 GNUNET_FS_STATUS_PUBLISH_START = 0,
513 * Notification that we have resumed sharing a file structure.
515 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
518 * Notification that we have suspended sharing a file structure.
520 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
523 * Notification that we are making progress sharing a file structure.
525 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
528 * Notification that an error was encountered sharing a file structure.
529 * The application will continue to receive resume/suspend events for
530 * this structure until "GNUNET_FS_publish_stop" is called.
532 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
535 * Notification that we completed sharing a file structure.
536 * The application will continue to receive resume/suspend events for
537 * this structure until "GNUNET_FS_publish_stop" is called.
539 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
542 * Notification that we have stopped
543 * the process of uploading a file structure; no
544 * futher events will be generated for this action.
546 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
549 * Notification that we have started this download.
551 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
554 * Notification that this download is being resumed.
556 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
559 * Notification that this download was suspended.
561 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
564 * Notification about progress with this download.
566 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
569 * Notification that this download encountered an error.
571 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
574 * Notification that this download completed. Note that for
575 * directories, completion does not imply completion of all files in
578 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
581 * Notification that this download was stopped
582 * (final event with respect to this action).
584 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
587 * Notification that this download is now actively being
588 * pursued (as opposed to waiting in the queue).
590 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
593 * Notification that this download is no longer actively
594 * being pursued (back in the queue).
596 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
599 * Notification that this download is no longer part of a
600 * recursive download or search but now a 'stand-alone'
601 * download (and may thus need to be moved in the GUI
602 * into a different category).
604 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
607 * First event generated when a client requests
608 * a search to begin or when a namespace result
609 * automatically triggers the search for updates.
611 GNUNET_FS_STATUS_SEARCH_START = 17,
614 * Last event when a search is being resumed;
615 * note that "GNUNET_FS_SEARCH_START" will not
616 * be generated in this case.
618 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
621 * Event generated for each search result
622 * when the respective search is resumed.
624 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
627 * Last event when a search is being suspended;
628 * note that "GNUNET_FS_SEARCH_STOPPED" will not
629 * be generated in this case.
631 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
634 * This search has yielded a result.
636 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
639 * We have discovered a new namespace.
641 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
644 * We have additional data about the quality
645 * or availability of a search result.
647 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
650 * Signals a problem with this search.
652 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
655 * Signals that this search was paused.
657 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
660 * Signals that this search was continued (unpaused).
662 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
665 * Event generated for each search result
666 * when the respective search is stopped.
668 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
671 * Event generated for each search result
672 * when the respective search is suspended.
674 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
677 * Last message from a search; this signals
678 * that there will be no further events associated
681 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
684 * Notification that we started to unindex a file.
686 GNUNET_FS_STATUS_UNINDEX_START = 30,
689 * Notification that we resumed unindexing of a file.
691 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
694 * Notification that we suspended unindexing a file.
696 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
699 * Notification that we made progress unindexing a file.
701 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
704 * Notification that we encountered an error unindexing
707 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
710 * Notification that the unindexing of this file
713 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
716 * Notification that the unindexing of this file
717 * was stopped (final event for this action).
719 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36,
722 * Notification that we are making progress sharing a directory.
724 GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY = 37
730 * Handle for controlling an upload.
732 struct GNUNET_FS_PublishContext;
736 * Handle for controlling an unindexing operation.
738 struct GNUNET_FS_UnindexContext;
742 * Handle for controlling a search.
744 struct GNUNET_FS_SearchContext;
748 * Result from a search. Opaque handle to refer to the search
749 * (typically used when starting a download associated with the search
752 struct GNUNET_FS_SearchResult;
756 * Context for controlling a download.
758 struct GNUNET_FS_DownloadContext;
762 * Handle for detail information about a file that is being publishd.
763 * Specifies metadata, keywords, how to get the contents of the file
764 * (i.e. data-buffer in memory, filename on disk) and other options.
766 struct GNUNET_FS_FileInformation;
770 * Argument given to the progress callback with
771 * information about what is going on.
773 struct GNUNET_FS_ProgressInfo
777 * Values that depend on the event type.
783 * 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.
853 * These values are only valid for
854 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
860 * Data block we just published.
865 * At what offset in the file is "data"?
870 * Length of the data block.
875 * Depth of the given block in the tree;
876 * 0 would be the lowest level (DBLOCKs).
883 * These values are only valid for
884 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY events.
890 * How far are we along in the overall directory?
895 * How big do we estimate the entire directory to be?
900 * At what time do we expect to finish the upload of the
901 * CONTENTS of the directory. (The direcory itself will take
902 * extra time, indicated with the "eta" member at the
903 * "publish"-level of this struct.)
905 struct GNUNET_TIME_Relative eta;
907 } progress_directory;
910 * These values are only valid for
911 * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
917 * Error message, NULL if no error was encountered so far.
922 * URI of the file (if the download had been completed)
924 const struct GNUNET_FS_Uri *chk_uri;
927 * SKS URI of the file (if the download had been completed)
929 const struct GNUNET_FS_Uri *sks_uri;
934 * These values are only valid for
935 * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
941 * CHK URI of the file.
943 const struct GNUNET_FS_Uri *chk_uri;
946 * SKS URI of the file (if the download had been completed)
948 const struct GNUNET_FS_Uri *sks_uri;
953 * These values are only valid for
954 * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
960 * Error message, never NULL.
972 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
978 * Context for controlling the download.
980 struct GNUNET_FS_DownloadContext *dc;
983 * Client context pointer (set the last time
984 * by the client for this operation; initially
985 * NULL on START/RESUME events).
990 * Client context pointer for the parent operation
991 * (if this is a file in a directory or a subdirectory).
996 * Client context pointer for the associated search operation
997 * (specifically, context pointer for the specific search
998 * result, not the overall search); only set if this
999 * download was started from a search result.
1004 * URI used for this download.
1006 const struct GNUNET_FS_Uri *uri;
1009 * Name of the file that we are downloading.
1011 const char *filename;
1014 * How large is the download overall? This
1015 * is NOT necessarily the size from the
1016 * URI since we may be doing a partial download.
1021 * At what time do we expect to finish the download?
1022 * (will be a value in the past for completed
1025 struct GNUNET_TIME_Relative eta;
1028 * How long has this download been active?
1030 struct GNUNET_TIME_Relative duration;
1033 * How many bytes have we completed?
1038 * What anonymity level is used for this download?
1043 * Is the download currently active.
1048 * Additional values for specific events.
1054 * These values are only valid for
1055 * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1061 * Data block we just obtained, can be NULL (even if
1062 * data_len > 0) if we found the entire block 'intact' on
1063 * disk. In this case, it is also possible for 'data_len'
1064 * to be larger than an individual (32k) block.
1069 * At what offset in the file is "data"?
1074 * Length of the data block.
1079 * How much time passed between us asking for this block and
1080 * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1082 struct GNUNET_TIME_Relative block_download_duration;
1085 * Depth of the given block in the tree;
1086 * 0 would be the lowest level (DBLOCKS).
1091 * How much respect did we offer for downloading this block? (estimate,
1092 * because we might have the same request pending for multiple clients,
1093 * and of course because a transmission may have failed at a lower
1096 uint32_t respect_offered;
1099 * How often did we transmit the request? (estimate,
1100 * because we might have the same request pending for multiple clients,
1101 * and of course because a transmission may have failed at a lower
1104 uint32_t num_transmissions;
1109 * These values are only valid for
1110 * #GNUNET_FS_STATUS_DOWNLOAD_START events.
1116 * Known metadata for the download.
1118 const struct GNUNET_CONTAINER_MetaData *meta;
1123 * These values are only valid for
1124 * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1130 * Known metadata for the download.
1132 const struct GNUNET_CONTAINER_MetaData *meta;
1135 * Error message, NULL if we have not encountered any error yet.
1137 const char *message;
1142 * These values are only valid for
1143 * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1151 const char *message;
1160 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1166 * Context for controlling the search, NULL for
1167 * searches that were not explicitly triggered
1168 * by the client (i.e., searches for updates in
1171 struct GNUNET_FS_SearchContext *sc;
1174 * Client context pointer (set the last time by the client for
1175 * this operation; initially NULL on START/RESUME events). Note
1176 * that this value can only be set on START/RESUME; returning
1177 * non-NULL on RESULT/RESUME_RESULT will actually update the
1178 * private context for "UPDATE" events.
1183 * Client parent-context pointer; NULL for top-level searches,
1184 * refers to the client context of the associated search result
1185 * for automatically triggered searches for updates in
1186 * namespaces. In this case, 'presult' refers to that search
1192 * What query is used for this search
1193 * (list of keywords or SKS identifier).
1195 const struct GNUNET_FS_Uri *query;
1198 * How long has this search been actively running
1199 * (excludes times where the search was paused or
1202 struct GNUNET_TIME_Relative duration;
1205 * What anonymity level is used for this search?
1210 * Additional values for specific events.
1216 * These values are only valid for
1217 * #GNUNET_FS_STATUS_SEARCH_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 * Applicability rank (the larger, the better the result
1239 * fits the search criteria).
1241 uint32_t applicability_rank;
1246 * These values are only valid for
1247 * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1253 * Metadata for the search result.
1255 const struct GNUNET_CONTAINER_MetaData *meta;
1258 * URI for the search result.
1260 const struct GNUNET_FS_Uri *uri;
1263 * Handle to the result (for starting downloads).
1265 struct GNUNET_FS_SearchResult *result;
1268 * Current availability rank (negative:
1269 * unavailable, positive: available)
1271 int32_t availability_rank;
1274 * On how many total queries is the given
1275 * availability_rank based?
1277 uint32_t availability_certainty;
1280 * Updated applicability rank (the larger,
1281 * the better the result fits the search
1284 uint32_t applicability_rank;
1289 * These values are only valid for
1290 * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
1296 * Private context set for for this result
1297 * during the "RESULT" event.
1302 * Metadata for the search result.
1304 const struct GNUNET_CONTAINER_MetaData *meta;
1307 * URI for the search result.
1309 const struct GNUNET_FS_Uri *uri;
1312 * Current availability rank (negative:
1313 * unavailable, positive: available)
1315 int32_t availability_rank;
1318 * On how many total queries is the given
1319 * availability_rank based?
1321 uint32_t availability_certainty;
1324 * Updated applicability rank (the larger,
1325 * the better the result fits the search
1328 uint32_t applicability_rank;
1331 * How long has the current probe been active?
1333 struct GNUNET_TIME_Relative current_probe_time;
1338 * These values are only valid for
1339 * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1340 * These events are automatically triggered for
1341 * each search result before the
1342 * #GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1343 * happens primarily to give the client a chance
1344 * to clean up the "cctx" (if needed).
1350 * Private context set for for this result
1351 * during the "RESULT" event.
1356 * Metadata for the search result.
1358 const struct GNUNET_CONTAINER_MetaData *meta;
1361 * URI for the search result.
1363 const struct GNUNET_FS_Uri *uri;
1368 * These values are only valid for
1369 * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1370 * These events are automatically triggered for
1371 * each search result before the
1372 * #GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1373 * happens primarily to give the client a chance
1374 * to clean up the "cctx" (if needed).
1380 * Private context set for for this result
1381 * during the "RESULT" event.
1386 * Metadata for the search result.
1388 const struct GNUNET_CONTAINER_MetaData *meta;
1391 * URI for the search result.
1393 const struct GNUNET_FS_Uri *uri;
1398 * These values are only valid for
1399 * #GNUNET_FS_STATUS_SEARCH_RESUME events.
1405 * Error message, NULL if we have not encountered any error yet.
1407 const char *message;
1410 * Is this search currently paused?
1417 * These values are only valid for
1418 * #GNUNET_FS_STATUS_SEARCH_ERROR events.
1426 const char *message;
1431 * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
1437 * Short, human-readable name of the namespace.
1442 * Root identifier for the namespace, can be NULL.
1447 * Metadata for the namespace.
1449 const struct GNUNET_CONTAINER_MetaData *meta;
1452 * Public key of the namespace.
1454 struct GNUNET_CRYPTO_EcdsaPublicKey pseudonym;
1463 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1469 * Context for controlling the unindexing.
1471 struct GNUNET_FS_UnindexContext *uc;
1474 * Client context pointer (set the last time
1475 * by the client for this operation; initially
1476 * NULL on START/RESUME events).
1481 * Name of the file that is being unindexed.
1483 const char *filename;
1486 * How large is the file overall?
1491 * At what time do we expect to finish unindexing?
1492 * (will be a value in the past for completed
1493 * unindexing opeations).
1495 struct GNUNET_TIME_Relative eta;
1498 * How long has this upload been actively running
1499 * (excludes times where the upload was suspended).
1501 struct GNUNET_TIME_Relative duration;
1504 * How many bytes have we completed?
1509 * Additional values for specific events.
1515 * These values are only valid for
1516 * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1522 * Data block we just unindexed.
1527 * At what offset in the file is "data"?
1532 * Length of the data block.
1537 * Depth of the given block in the tree;
1538 * 0 would be the lowest level (DBLOCKS).
1545 * These values are only valid for
1546 * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
1552 * Error message, NULL if we have not encountered any error yet.
1554 const char *message;
1559 * These values are only valid for
1560 * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
1568 const char *message;
1579 * Specific status code (determines the event type).
1581 enum GNUNET_FS_Status status;
1584 * File-sharing handle that generated the event.
1586 struct GNUNET_FS_Handle *fsh;
1591 * Notification of FS to a client about the progress of an
1592 * operation. Callbacks of this type will be used for uploads,
1593 * downloads and searches. Some of the arguments depend a bit
1594 * in their meaning on the context in which the callback is used.
1596 * @param cls closure
1597 * @param info details about the event, specifying the event type
1598 * and various bits about the event
1599 * @return client-context (for the next progress call
1600 * for this operation; should be set to NULL for
1601 * SUSPEND and STOPPED events). The value returned
1602 * will be passed to future callbacks in the respective
1603 * field in the `struct GNUNET_FS_ProgressInfo`.
1606 (*GNUNET_FS_ProgressCallback) (void *cls,
1607 const struct GNUNET_FS_ProgressInfo *info);
1611 * General (global) option flags for file-sharing.
1613 enum GNUNET_FS_Flags
1616 * No special flags set.
1618 GNUNET_FS_FLAGS_NONE = 0,
1621 * Is persistence of operations desired?
1622 * (will create SUSPEND/RESUME events).
1624 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1627 * Should we automatically trigger probes for search results
1628 * to determine availability?
1629 * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
1631 GNUNET_FS_FLAGS_DO_PROBES = 2
1636 * Options specified in the VARARGs portion of GNUNET_FS_start.
1638 enum GNUNET_FS_OPTIONS
1642 * Last option in the VARARG list.
1644 GNUNET_FS_OPTIONS_END = 0,
1647 * Select the desired amount of parallelism (this option should be
1648 * followed by an "unsigned int" giving the desired maximum number
1649 * of parallel downloads).
1651 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1654 * Maximum number of requests that should be pending at a given
1655 * point in time (invidivual downloads may go above this, but
1656 * if we are above this threshold, we should not activate any
1657 * additional downloads.
1659 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1664 * Settings for publishing a block (which may of course also
1665 * apply to an entire directory or file).
1667 struct GNUNET_FS_BlockOptions
1671 * At what time should the block expire? Data blocks (DBLOCKS and
1672 * IBLOCKS) may still be used even if they are expired (however,
1673 * they'd be removed quickly from the datastore if we are short on
1674 * space), all other types of blocks will no longer be returned
1675 * after they expire.
1677 struct GNUNET_TIME_Absolute expiration_time;
1680 * At which anonymity level should the block be shared?
1681 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1683 uint32_t anonymity_level;
1686 * How important is it for us to store the block? If we run
1687 * out of space, the highest-priority, non-expired blocks will
1690 uint32_t content_priority;
1693 * How often should we try to migrate the block to other peers?
1694 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1695 * first push each block to other peers according to their
1696 * replication levels. Once each block has been pushed that many
1697 * times to other peers, blocks are chosen for migration at random.
1698 * Naturally, there is no guarantee that the other peers will keep
1699 * these blocks for any period of time (since they won't have any
1700 * priority or might be too busy to even store the block in the
1703 uint32_t replication_level;
1709 * Handle to the file-sharing service.
1711 struct GNUNET_FS_Handle;
1715 * Setup a connection to the file-sharing service.
1717 * @param cfg configuration to use
1718 * @param client_name unique identifier for this client
1719 * @param upcb function to call to notify about FS actions
1720 * @param upcb_cls closure for @a upcb
1721 * @param flags specific attributes for fs-operations
1722 * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
1723 * @return NULL on error
1725 struct GNUNET_FS_Handle *
1726 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1727 const char *client_name,
1728 GNUNET_FS_ProgressCallback upcb,
1730 enum GNUNET_FS_Flags flags,
1735 * Close our connection with the file-sharing service.
1736 * The callback given to #GNUNET_FS_start() will no longer be
1737 * called after this function returns.
1738 * This function MUST NOT be called from within the
1741 * @param h handle that was returned from #GNUNET_FS_start()
1744 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1748 * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
1750 * @param cls closure
1751 * @param fi the entry in the publish-structure
1752 * @param length length of the file or directory
1753 * @param meta metadata for the file or directory (can be modified)
1754 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1755 * @param bo block options (can be modified)
1756 * @param do_index should we index (can be modified)
1757 * @param client_info pointer to client context set upon creation (can be modified)
1758 * @return #GNUNET_OK to continue, #GNUNET_NO to remove
1759 * this entry from the directory, #GNUNET_SYSERR
1760 * to abort the iteration
1763 (*GNUNET_FS_FileInformationProcessor) (void *cls,
1764 struct GNUNET_FS_FileInformation *fi,
1766 struct GNUNET_CONTAINER_MetaData *meta,
1767 struct GNUNET_FS_Uri ** uri,
1768 struct GNUNET_FS_BlockOptions *bo,
1770 void **client_info);
1774 * Obtain the name under which this file information
1775 * structure is stored on disk. Only works for top-level
1776 * file information structures.
1778 * @param s structure to get the filename for
1779 * @return NULL on error, otherwise filename that can be used
1780 * to read this fi-struct from disk.
1783 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1787 * Obtain the filename from the file information structure.
1789 * @param s structure to get the filename for
1790 * @return "filename" field of the structure (can be NULL)
1793 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1797 * Set the filename in the file information structure.
1798 * If filename was already set, frees it before setting the new one.
1799 * Makes a copy of the argument.
1801 * @param s structure to get the filename for
1802 * @param filename filename to set
1805 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1806 const char *filename);
1810 * Create an entry for a file in a publish-structure.
1812 * @param h handle to the file sharing subsystem
1813 * @param client_info initial client-info value for this entry
1814 * @param filename name of the file or directory to publish
1815 * @param keywords under which keywords should this file be available
1816 * directly; can be NULL
1817 * @param meta metadata for the file
1818 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1819 * #GNUNET_SYSERR for simulation
1820 * @param bo block options
1821 * @return publish structure entry for the file
1823 struct GNUNET_FS_FileInformation *
1824 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1826 const char *filename,
1827 const struct GNUNET_FS_Uri *keywords,
1828 const struct GNUNET_CONTAINER_MetaData *meta,
1830 const struct GNUNET_FS_BlockOptions *bo);
1834 * Create an entry for a file in a publish-structure.
1836 * @param h handle to the file sharing subsystem
1837 * @param client_info initial client-info value for this entry
1838 * @param length length of the file
1839 * @param data data for the file (should not be used afterwards by
1840 * the caller; callee will "free")
1841 * @param keywords under which keywords should this file be available
1842 * directly; can be NULL
1843 * @param meta metadata for the file
1844 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1845 * #GNUNET_SYSERR for simulation
1846 * @param bo block options
1847 * @return publish structure entry for the file
1849 struct GNUNET_FS_FileInformation *
1850 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1854 const struct GNUNET_FS_Uri *keywords,
1855 const struct GNUNET_CONTAINER_MetaData *meta,
1857 const struct GNUNET_FS_BlockOptions *bo);
1861 * Function that provides data.
1863 * @param cls closure
1864 * @param offset offset to read from; it is possible
1865 * that the caller might need to go backwards
1866 * a bit at times; set to UINT64_MAX to tell
1867 * the reader that we won't be reading for a while
1868 * (used to close the file descriptor but NOT fully
1869 * clean up the reader's state); in this case,
1870 * a value of '0' for max should be ignored
1871 * @param max maximum number of bytes that should be
1872 * copied to buf; readers are not allowed
1873 * to provide less data unless there is an error;
1874 * a value of "0" will be used at the end to allow
1875 * the reader to clean up its internal state
1876 * @param buf where the reader should write the data
1877 * @param emsg location for the reader to store an error message
1878 * @return number of bytes written, usually @a max, 0 on error
1881 (*GNUNET_FS_DataReader) (void *cls,
1889 * Create an entry for a file in a publish-structure.
1891 * @param h handle to the file sharing subsystem
1892 * @param client_info initial client-info value for this entry
1893 * @param length length of the file
1894 * @param reader function that can be used to obtain the data for the file
1895 * @param reader_cls closure for @a reader
1896 * @param keywords under which keywords should this file be available
1897 * directly; can be NULL
1898 * @param meta metadata for the file
1899 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1900 * #GNUNET_SYSERR for simulation
1901 * @param bo block options
1902 * @return publish structure entry for the file
1904 struct GNUNET_FS_FileInformation *
1905 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1908 GNUNET_FS_DataReader reader,
1910 const struct GNUNET_FS_Uri
1913 GNUNET_CONTAINER_MetaData *meta,
1916 GNUNET_FS_BlockOptions *bo);
1920 * Create an entry for an empty directory in a publish-structure.
1922 * @param h handle to the file sharing subsystem
1923 * @param client_info initial client-info value for this entry
1924 * @param keywords under which keywords should this directory be available
1925 * directly; can be NULL
1926 * @param meta metadata for the directory
1927 * @param bo block options
1928 * @param filename name of the directory; can be NULL
1929 * @return publish structure entry for the directory , NULL on error
1931 struct GNUNET_FS_FileInformation *
1932 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1934 const struct GNUNET_FS_Uri
1937 GNUNET_CONTAINER_MetaData
1940 GNUNET_FS_BlockOptions *bo,
1941 const char *filename);
1945 * Test if a given entry represents a directory.
1947 * @param ent check if this FI represents a directory
1948 * @return #GNUNET_YES if so, #GNUNET_NO if not
1951 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1956 * Add an entry to a directory in a publish-structure. Clients
1957 * should never modify publish structures that were passed to
1958 * #GNUNET_FS_publish_start() already.
1960 * @param dir the directory
1961 * @param ent the entry to add; the entry must not have been
1962 * added to any other directory at this point and
1963 * must not include @a dir in its structure
1964 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1967 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1968 struct GNUNET_FS_FileInformation *ent);
1972 * Inspect a file or directory in a publish-structure. Clients
1973 * should never modify publish structures that were passed to
1974 * #GNUNET_FS_publish_start already. When called on a directory,
1975 * this function will FIRST call @a proc with information about
1976 * the directory itself and then for each of the files in the
1977 * directory (but not for files in subdirectories). When called
1978 * on a file, @a proc will be called exactly once (with information
1979 * about the specific file).
1981 * @param dir the directory
1982 * @param proc function to call on each entry
1983 * @param proc_cls closure for @a proc
1986 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1987 GNUNET_FS_FileInformationProcessor proc,
1992 * Destroy publish-structure. Clients should never destroy publish
1993 * structures that were passed to #GNUNET_FS_publish_start already.
1995 * @param fi structure to destroy
1996 * @param cleaner function to call on each entry in the structure
1997 * (useful to clean up client_info); can be NULL; return
1998 * values are ignored
1999 * @param cleaner_cls closure for @a cleaner
2002 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2003 GNUNET_FS_FileInformationProcessor cleaner,
2008 * Options for publishing. Compatible options
2009 * can be OR'ed together.
2011 enum GNUNET_FS_PublishOptions
2014 * No options (use defaults for everything).
2016 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2019 * Simulate publishing. With this option, no data will be stored
2020 * in the datastore. Useful for computing URIs from files.
2022 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2027 * Publish a file or directory.
2029 * @param h handle to the file sharing subsystem
2030 * @param fi information about the file or directory structure to publish
2031 * @param ns namespace to publish the file in, NULL for no namespace
2032 * @param nid identifier to use for the publishd content in the namespace
2033 * (can be NULL, must be NULL if namespace is NULL)
2034 * @param nuid update-identifier that will be used for future updates
2035 * (can be NULL, must be NULL if namespace or nid is NULL)
2036 * @param options options for the publication
2037 * @return context that can be used to control the publish operation
2039 struct GNUNET_FS_PublishContext *
2040 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2041 struct GNUNET_FS_FileInformation *fi,
2042 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2045 enum GNUNET_FS_PublishOptions options);
2049 * Stop a publication. Will abort incomplete publications (but
2050 * not remove blocks that have already been published) or
2051 * simply clean up the state for completed publications.
2052 * Must NOT be called from within the event callback!
2054 * @param pc context for the publication to stop
2057 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2061 * Signature of a function called as the continuation of a KBlock or
2062 * SBlock publication.
2064 * @param cls closure
2065 * @param uri URI under which the block is now available, NULL on error
2066 * @param emsg error message, NULL on success
2069 (*GNUNET_FS_PublishContinuation) (void *cls,
2070 const struct GNUNET_FS_Uri *uri,
2075 * Handle to cancel publish KSK operation.
2077 struct GNUNET_FS_PublishKskContext;
2081 * Publish a KBlock on GNUnet.
2083 * @param h handle to the file sharing subsystem
2084 * @param ksk_uri keywords to use
2085 * @param meta metadata to use
2086 * @param uri URI to refer to in the KBlock
2087 * @param bo block options
2088 * @param options publication options
2089 * @param cont continuation
2090 * @param cont_cls closure for @a cont
2091 * @return NULL on error (@a cont will still be called)
2093 struct GNUNET_FS_PublishKskContext *
2094 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2095 const struct GNUNET_FS_Uri *ksk_uri,
2096 const struct GNUNET_CONTAINER_MetaData *meta,
2097 const struct GNUNET_FS_Uri *uri,
2098 const struct GNUNET_FS_BlockOptions *bo,
2099 enum GNUNET_FS_PublishOptions options,
2100 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2104 * Abort the KSK publishing operation.
2106 * @param pkc context of the operation to abort.
2109 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2113 * Handle to cancel publish SKS operation.
2115 struct GNUNET_FS_PublishSksContext;
2119 * Publish an SBlock on GNUnet.
2121 * @param h handle to the file sharing subsystem
2122 * @param ns namespace to publish in
2123 * @param identifier identifier to use
2124 * @param update update identifier to use
2125 * @param meta metadata to use
2126 * @param uri URI to refer to in the SBlock
2127 * @param bo block options
2128 * @param options publication options
2129 * @param cont continuation
2130 * @param cont_cls closure for @a cont
2131 * @return NULL on error (@a cont will still be called)
2133 struct GNUNET_FS_PublishSksContext *
2134 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2135 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2136 const char *identifier,
2138 const struct GNUNET_CONTAINER_MetaData *meta,
2139 const struct GNUNET_FS_Uri *uri,
2140 const struct GNUNET_FS_BlockOptions *bo,
2141 enum GNUNET_FS_PublishOptions options,
2142 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2146 * Abort the SKS publishing operation.
2148 * @param psc context of the operation to abort.
2151 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2155 * Type of a function called by #GNUNET_FS_get_indexed_files.
2157 * @param cls closure
2158 * @param filename the name of the file, NULL for end of list
2159 * @param file_id hash of the contents of the indexed file
2160 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2163 (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2164 const char *filename,
2165 const struct GNUNET_HashCode *file_id);
2169 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2171 struct GNUNET_FS_GetIndexedContext;
2175 * Iterate over all indexed files.
2177 * @param h handle to the file sharing subsystem
2178 * @param iterator function to call on each indexed file
2179 * @param iterator_cls closure for @a iterator
2180 * @return NULL on error (@a iterator is not called)
2182 struct GNUNET_FS_GetIndexedContext *
2183 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2184 GNUNET_FS_IndexedFileProcessor iterator,
2185 void *iterator_cls);
2189 * Cancel iteration over all indexed files.
2191 * @param gic operation to cancel
2194 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2200 * @param h handle to the file sharing subsystem
2201 * @param filename file to unindex
2202 * @param cctx initial value for the client context
2203 * @return NULL on error, otherwise handle
2205 struct GNUNET_FS_UnindexContext *
2206 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2207 const char *filename,
2212 * Clean up after completion of an unindex operation.
2217 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2221 * Function called on updateable identifiers.
2223 * @param cls closure
2224 * @param last_id last identifier
2225 * @param last_uri uri used for the content published under the @a last_id
2226 * @param last_meta metadata associated with @a last_uri
2227 * @param next_id identifier that should be used for updates
2229 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2230 const char *last_id,
2231 const struct GNUNET_FS_Uri *last_uri,
2232 const struct GNUNET_CONTAINER_MetaData *last_meta,
2233 const char *next_id);
2237 * List all of the identifiers in the namespace for which we could
2238 * produce an update. Namespace updates form a graph where each node
2239 * has a name. Each node can have any number of URI/meta-data entries
2240 * which can each be linked to other nodes. Cycles are possible.
2242 * Calling this function with @a next_id NULL will cause the library to
2243 * call @a ip with a root for each strongly connected component of the
2244 * graph (a root being a node from which all other nodes in the Scc
2247 * Calling this function with @a next_id being the name of a node will
2248 * cause the library to call @a ip with all children of the node. Note
2249 * that cycles within an SCC are possible (including self-loops).
2251 * @param h fs handle to use
2252 * @param ns namespace to inspect for updateable content
2253 * @param next_id ID to look for; use NULL to look for SCC roots
2254 * @param ip function to call on each updateable identifier
2255 * @param ip_cls closure for @a ip
2258 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
2259 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2260 const char *next_id,
2261 GNUNET_FS_IdentifierProcessor ip,
2266 * Options for searching. Compatible options
2267 * can be OR'ed together.
2269 enum GNUNET_FS_SearchOptions
2272 * No options (use defaults for everything).
2274 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2277 * Only search the local host, do not search remote systems (no P2P)
2279 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2284 * Start search for content.
2286 * @param h handle to the file sharing subsystem
2287 * @param uri specifies the search parameters; can be
2288 * a KSK URI or an SKS URI.
2289 * @param anonymity desired level of anonymity
2290 * @param options options for the search
2291 * @param cctx initial value for the client context
2292 * @return context that can be used to control the search
2294 struct GNUNET_FS_SearchContext *
2295 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2296 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2297 enum GNUNET_FS_SearchOptions options, void *cctx);
2303 * @param sc context for the search that should be paused
2306 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2310 * Continue paused search.
2312 * @param sc context for the search that should be resumed
2315 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2319 * Stop search for content.
2321 * @param sc context for the search that should be stopped
2324 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2328 * Start download probes for the given search result.
2330 * @param h file-sharing handle to use for the operation
2331 * @param uri URI to probe
2332 * @param meta meta data associated with the URI
2333 * @param client_info client info pointer to use for associated events
2334 * @param anonymity anonymity level to use for the probes
2335 * @return the search result handle to access the probe activity
2337 struct GNUNET_FS_SearchResult *
2338 GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2339 const struct GNUNET_FS_Uri *uri,
2340 const struct GNUNET_CONTAINER_MetaData *meta,
2342 uint32_t anonymity);
2346 * Stop probe activity. Must ONLY be used on values
2347 * returned from #GNUNET_FS_probe.
2349 * @param sr search result to stop probing for (freed)
2350 * @return the value of the 'client_info' pointer
2353 GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2357 * Options for downloading. Compatible options
2358 * can be OR'ed together.
2360 enum GNUNET_FS_DownloadOptions
2363 * No options (use defaults for everything).
2365 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2368 * Only download from the local host, do not access remote systems (no P2P)
2370 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2373 * Do a recursive download (that is, automatically trigger the
2374 * download of files in directories).
2376 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2379 * Do not append temporary data to
2380 * the target file (for the IBlocks).
2382 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2385 * Internal option used to flag this download as a 'probe' for a
2386 * search result. Impacts the priority with which the download is
2387 * run and causes signalling callbacks to be done differently.
2388 * Also, probe downloads are not serialized on suspension. Normal
2389 * clients should not use this!
2391 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2397 * Download parts of a file. Note that this will store
2398 * the blocks at the respective offset in the given file. Also, the
2399 * download is still using the blocking of the underlying FS
2400 * encoding. As a result, the download may *write* outside of the
2401 * given boundaries (if offset and length do not match the 32k FS
2402 * block boundaries).
2404 * The given range can be used to focus a download towards a
2405 * particular portion of the file (optimization), not to strictly
2406 * limit the download to exactly those bytes.
2408 * @param h handle to the file sharing subsystem
2409 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2410 * @param meta known metadata for the file (can be NULL)
2411 * @param filename where to store the file, maybe NULL (then no file is
2412 * created on disk and data must be grabbed from the callbacks)
2413 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2414 * can be NULL (in which case we will pick a name if needed); the temporary file
2415 * may already exist, in which case we will try to use the data that is there and
2416 * if it is not what is desired, will overwrite it
2417 * @param offset at what offset should we start the download (typically 0)
2418 * @param length how many bytes should be downloaded starting at offset
2419 * @param anonymity anonymity level to use for the download
2420 * @param options various download options
2421 * @param cctx initial value for the client context for this download
2422 * @param parent parent download to associate this download with (use NULL
2423 * for top-level downloads; useful for manually-triggered recursive downloads)
2424 * @return context that can be used to control this download
2426 struct GNUNET_FS_DownloadContext *
2427 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2428 const struct GNUNET_FS_Uri *uri,
2429 const struct GNUNET_CONTAINER_MetaData *meta,
2430 const char *filename, const char *tempname,
2431 uint64_t offset, uint64_t length, uint32_t anonymity,
2432 enum GNUNET_FS_DownloadOptions options, void *cctx,
2433 struct GNUNET_FS_DownloadContext *parent);
2437 * Download parts of a file based on a search result. The download
2438 * will be associated with the search result (and the association
2439 * will be preserved when serializing/deserializing the state).
2440 * If the search is stopped, the download will not be aborted but
2441 * be 'promoted' to a stand-alone download.
2443 * As with the other download function, this will store
2444 * the blocks at the respective offset in the given file. Also, the
2445 * download is still using the blocking of the underlying FS
2446 * encoding. As a result, the download may *write* outside of the
2447 * given boundaries (if offset and length do not match the 32k FS
2448 * block boundaries).
2450 * The given range can be used to focus a download towards a
2451 * particular portion of the file (optimization), not to strictly
2452 * limit the download to exactly those bytes.
2454 * @param h handle to the file sharing subsystem
2455 * @param sr the search result to use for the download (determines uri and
2456 * meta data and associations)
2457 * @param filename where to store the file, maybe NULL (then no file is
2458 * created on disk and data must be grabbed from the callbacks)
2459 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2460 * can be NULL (in which case we will pick a name if needed); the temporary file
2461 * may already exist, in which case we will try to use the data that is there and
2462 * if it is not what is desired, will overwrite it
2463 * @param offset at what offset should we start the download (typically 0)
2464 * @param length how many bytes should be downloaded starting at offset
2465 * @param anonymity anonymity level to use for the download
2466 * @param options various download options
2467 * @param cctx initial value for the client context for this download
2468 * @return context that can be used to control this download
2470 struct GNUNET_FS_DownloadContext *
2471 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2472 struct GNUNET_FS_SearchResult *sr,
2473 const char *filename,
2474 const char *tempname, uint64_t offset,
2475 uint64_t length, uint32_t anonymity,
2476 enum GNUNET_FS_DownloadOptions options,
2481 * Stop a download (aborts if download is incomplete).
2483 * @param dc handle for the download
2484 * @param do_delete delete files of incomplete downloads
2487 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2491 * Suspend a download.
2493 * @param dc handle for the download
2496 GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc);
2500 * Resume a suspended download.
2502 * @param dc handle for the download
2505 GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2509 /* ******************** Directory API *********************** */
2512 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2513 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2514 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2517 * Does the meta-data claim that this is a directory?
2518 * Checks if the mime-type is that of a GNUnet directory.
2520 * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
2521 * we have no mime-type information (treat as #GNUNET_NO)
2524 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2529 * Set the MIMETYPE information for the given
2530 * metadata to "application/gnunet-directory".
2532 * @param md metadata to add mimetype to
2535 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2539 * Suggest a filename based on given metadata.
2541 * @param md given meta data
2542 * @return NULL if meta data is useless for suggesting a filename
2545 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
2549 * Function used to process entries in a directory.
2551 * @param cls closure
2552 * @param filename name of the file in the directory
2553 * @param uri URI of the file
2554 * @param metadata metadata for the file; metadata for
2555 * the directory if everything else is NULL/zero
2556 * @param length length of the available data for the file
2557 * (of type size_t since data must certainly fit
2558 * into memory; if files are larger than size_t
2559 * permits, then they will certainly not be
2560 * embedded with the directory itself).
2561 * @param data data available for the file (length bytes)
2563 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2564 const char *filename,
2565 const struct GNUNET_FS_Uri *
2568 GNUNET_CONTAINER_MetaData *
2569 meta, size_t length,
2574 * Iterate over all entries in a directory. Note that directories
2575 * are structured such that it is possible to iterate over the
2576 * individual blocks as well as over the entire directory. Thus
2577 * a client can call this function on the buffer in the
2578 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2579 * include the contents of (small) files embedded in the directory
2580 * itself; for those files, the processor may be given the
2581 * contents of the file directly by this function.
2583 * @param size number of bytes in data
2584 * @param data pointer to the beginning of the directory
2585 * @param offset offset of data in the directory
2586 * @param dep function to call on each entry
2587 * @param dep_cls closure for @a dep
2588 * @return #GNUNET_OK if this could be a block in a directory,
2589 * #GNUNET_NO if this could be part of a directory (but not 100% OK)
2590 * #GNUNET_SYSERR if 'data' does not represent a directory
2593 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2595 GNUNET_FS_DirectoryEntryProcessor dep,
2600 * Opaque handle to a directory builder.
2602 struct GNUNET_FS_DirectoryBuilder;
2606 * Create a directory builder.
2608 * @param mdir metadata for the directory
2610 struct GNUNET_FS_DirectoryBuilder *
2611 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2616 * Add an entry to a directory.
2618 * @param bld directory to extend
2619 * @param uri uri of the entry (must not be a KSK)
2620 * @param md metadata of the entry
2621 * @param data raw data of the entry, can be NULL, otherwise
2622 * data must point to exactly the number of bytes specified
2626 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2627 const struct GNUNET_FS_Uri *uri,
2628 const struct GNUNET_CONTAINER_MetaData *md,
2633 * Finish building the directory. Frees the
2634 * builder context and returns the directory
2637 * @param bld directory to finish
2638 * @param rsize set to the number of bytes needed
2639 * @param rdata set to the encoded directory
2640 * @return #GNUNET_OK on success
2643 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2644 size_t * rsize, void **rdata);
2647 /* ******************** DirScanner API *********************** */
2650 * Progress reasons of the directory scanner.
2652 enum GNUNET_FS_DirScannerProgressUpdateReason
2656 * We've started processing a file or directory.
2658 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2661 * We're having trouble accessing a file (soft-error); it will
2664 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2667 * We've found all files (in the pre-pass).
2669 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2672 * We've finished extracting meta data from a file.
2674 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2677 * Last call to the progress function: we have finished scanning
2680 GNUNET_FS_DIRSCANNER_FINISHED,
2683 * There was an internal error. Application should abort the scan.
2685 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2691 * Function called over time as the directory scanner makes
2692 * progress on the job at hand.
2694 * @param cls closure
2695 * @param filename which file we are making progress on
2696 * @param is_directory #GNUNET_YES if this is a directory,
2697 * #GNUNET_NO if this is a file
2698 * #GNUNET_SYSERR if it is neither (or unknown)
2699 * @param reason kind of progress we are making
2701 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2702 const char *filename,
2704 enum GNUNET_FS_DirScannerProgressUpdateReason reason);
2708 * A node of a directory tree (produced by dirscanner)
2710 struct GNUNET_FS_ShareTreeItem
2713 * This is a doubly-linked list
2715 struct GNUNET_FS_ShareTreeItem *prev;
2718 * This is a doubly-linked list
2720 struct GNUNET_FS_ShareTreeItem *next;
2723 * This is a doubly-linked tree
2724 * NULL for top-level entries.
2726 struct GNUNET_FS_ShareTreeItem *parent;
2729 * This is a doubly-linked tree
2730 * NULL for files and empty directories
2732 struct GNUNET_FS_ShareTreeItem *children_head;
2735 * This is a doubly-linked tree
2736 * NULL for files and empty directories
2738 struct GNUNET_FS_ShareTreeItem *children_tail;
2741 * Metadata for this file or directory
2743 struct GNUNET_CONTAINER_MetaData *meta;
2746 * Keywords for this file or directory (derived from metadata).
2748 struct GNUNET_FS_Uri *ksk_uri;
2751 * Name of the file/directory
2756 * Base name of the file/directory.
2758 char *short_filename;
2761 * #GNUNET_YES if this is a directory
2769 * Opaque handle to an asynchronous directory scanning activity.
2771 struct GNUNET_FS_DirScanner;
2775 * Start a directory scanner.
2777 * @param filename name of the directory to scan
2778 * @param disable_extractor #GNUNET_YES to not run libextractor on files (only
2780 * @param ex if not NULL, must be a list of extra plugins for extractor
2781 * @param cb the callback to call when there are scanning progress messages
2782 * @param cb_cls closure for @a cb
2783 * @return directory scanner object to be used for controlling the scanner
2785 struct GNUNET_FS_DirScanner *
2786 GNUNET_FS_directory_scan_start (const char *filename,
2787 int disable_extractor,
2789 GNUNET_FS_DirScannerProgressCallback cb,
2794 * Abort the scan. Must not be called from within the progress_callback
2797 * @param ds directory scanner structure
2800 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2804 * Obtain the result of the scan after the scan has signalled
2805 * completion. Must not be called prior to completion. The @a ds is
2806 * freed as part of this call.
2808 * @param ds directory scanner structure
2809 * @return the results of the scan (a directory tree)
2811 struct GNUNET_FS_ShareTreeItem *
2812 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2816 * Process a share item tree, moving frequent keywords up and
2817 * copying frequent metadata up.
2819 * @param toplevel toplevel directory in the tree, returned by the scanner
2822 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2826 * Release memory of a share item tree.
2828 * @param toplevel toplevel of the tree to be freed
2831 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2834 #if 0 /* keep Emacsens' auto-indent happy */
2843 /** @} */ /* end of group */