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,
107 * Get a unique key from a URI. This is for putting URIs
108 * into HashMaps. The key may change between FS implementations.
110 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key
112 * @return #GNUNET_OK on success
115 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
116 struct GNUNET_HashCode *key);
120 * Convert a URI to a UTF-8 String.
122 * @param uri uri to convert to a string
123 * @return the UTF-8 string
126 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
130 * Convert keyword URI to a human readable format
131 * (i.e. the search query that was used in the first place)
133 * @param uri ksk uri to convert to a string
134 * @return string with the keywords
137 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
141 * Add the given keyword to the set of keywords represented by the URI.
142 * Does nothing if the keyword is already present.
144 * @param uri ksk uri to modify
145 * @param keyword keyword to add
146 * @param is_mandatory is this keyword mandatory?
149 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
155 * Remove the given keyword from the set of keywords represented by the URI.
156 * Does nothing if the keyword is not present.
158 * @param uri ksk uri to modify
159 * @param keyword keyword to add
162 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
163 const char *keyword);
167 * Convert a UTF-8 String to a URI.
169 * @param uri string to parse
170 * @param emsg where to store the parser error message (if any)
171 * @return NULL on error
173 struct GNUNET_FS_Uri *
174 GNUNET_FS_uri_parse (const char *uri,
181 * @param uri uri to free
184 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
188 * How many keywords are ANDed in this keyword URI?
190 * @param uri ksk uri to get the number of keywords from
191 * @return 0 if this is not a keyword URI
194 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
198 * Iterate over all keywords in this keyword URI.
200 * @param uri ksk uri to get the keywords from
201 * @param iterator function to call on each keyword
202 * @param iterator_cls closure for @a iterator
203 * @return -1 if this is not a keyword URI, otherwise number of
204 * keywords iterated over until iterator aborted
207 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
208 GNUNET_FS_KeywordIterator iterator,
213 * Obtain the identity of the peer offering the data
215 * @param uri the location URI to inspect
216 * @param peer where to store the identify of the peer (presumably) offering the content
217 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
220 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
221 struct GNUNET_PeerIdentity *peer);
225 * Obtain the URI of the content itself.
227 * @param uri location URI to get the content URI from
228 * @return NULL if argument is not a location URI
230 struct GNUNET_FS_Uri *
231 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
235 * Obtain the expiration of the LOC URI.
237 * @param uri location URI to get the expiration from
238 * @return expiration time of the URI
240 struct GNUNET_TIME_Absolute
241 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
245 * Construct a location URI (this peer will be used for the location).
246 * This function should only be called from within gnunet-service-fs,
247 * as it requires the peer's private key which is generally unavailable
248 * to processes directly under the user's control. However, for
249 * testing and as it logically fits under URIs, it is in this API.
251 * @param base_uri content offered by the sender
252 * @param sign_key private key of the peer
253 * @param expiration_time how long will the content be offered?
254 * @return the location URI, NULL on error
256 struct GNUNET_FS_Uri *
257 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
258 const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
259 struct GNUNET_TIME_Absolute expiration_time);
263 * Merge the sets of keywords from two KSK URIs.
265 * @param u1 first uri
266 * @param u2 second uri
267 * @return merged URI, NULL on error
269 struct GNUNET_FS_Uri *
270 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
271 const struct GNUNET_FS_Uri *u2);
277 * @param uri the URI to duplicate
278 * @return copy of the URI
280 struct GNUNET_FS_Uri *
281 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
285 * Create an FS URI from a single user-supplied string of keywords.
286 * The string is broken up at spaces into individual keywords.
287 * Keywords that start with "+" are mandatory. Double-quotes can
288 * be used to prevent breaking up strings at spaces (and also
289 * to specify non-mandatory keywords starting with "+").
291 * Keywords must contain a balanced number of double quotes and
292 * double quotes can not be used in the actual keywords (for
293 * example, the string '""foo bar""' will be turned into two
294 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
296 * @param keywords the keyword string
297 * @param emsg where to store an error message
298 * @return an FS URI for the given keywords, NULL
299 * if keywords is not legal (i.e. empty).
301 struct GNUNET_FS_Uri *
302 GNUNET_FS_uri_ksk_create (const char *keywords,
307 * Create an FS URI from a user-supplied command line of keywords.
308 * Arguments should start with "+" to indicate mandatory
311 * @param argc number of keywords
312 * @param argv keywords (double quotes are not required for
313 * keywords containing spaces; however, double
314 * quotes are required for keywords starting with
315 * "+"); there is no mechanism for having double
316 * quotes in the actual keywords (if the user
317 * did specifically specify double quotes, the
318 * caller should convert each double quote
319 * into two single quotes).
320 * @return an FS URI for the given keywords, NULL
321 * if keywords is not legal (i.e. empty).
323 struct GNUNET_FS_Uri *
324 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
329 * Test if two URIs are equal.
331 * @param u1 one of the URIs
332 * @param u2 the other URI
333 * @return #GNUNET_YES if the URIs are equal
336 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
337 const struct GNUNET_FS_Uri *u2);
341 * Is this a namespace URI?
343 * @param uri the uri to check
344 * @return #GNUNET_YES if this is an SKS uri
347 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
351 * Create an SKS URI from a namespace ID and an identifier.
353 * @param ns pseudonym to use
354 * @param id identifier
355 * @return an FS URI for the given namespace and identifier
357 struct GNUNET_FS_Uri *
358 GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
363 * Get the public key of a namespace from the given
366 * @param uri the uri to get the namespace ID from
367 * @param pseudonym where to store the public key of the namespace
368 * @return #GNUNET_OK on success
371 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
372 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym);
376 * Get the content identifier of an SKS URI.
378 * @param uri the sks uri
379 * @return NULL on error (not a valid SKS URI)
382 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
386 * Is this a keyword URI?
389 * @return #GNUNET_YES if this is a KSK uri
392 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
396 * Is this a file (or directory) URI?
398 * @param uri the uri to check
399 * @return #GNUNET_YES if this is a CHK uri
402 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
406 * What is the size of the file that this URI
409 * @param uri the CHK (or LOC) URI to inspect
410 * @return size of the file as specified in the CHK URI
413 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
417 * Is this a location URI?
419 * @param uri the uri to check
420 * @return #GNUNET_YES if this is a LOC uri
423 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
427 * Construct a keyword-URI from meta-data (take all entries
428 * in the meta-data and construct one large keyword URI
429 * that lists all keywords that can be found in the meta-data).
431 * @param md metadata to use
432 * @return NULL on error, otherwise a KSK URI
434 struct GNUNET_FS_Uri *
435 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
439 /* ******************** command-line option parsing API *********************** */
442 * Allow user to specify keywords.
444 * @param shortName short name of the option
445 * @param name long name of the option
446 * @param argumentHelp help text for the option argument
447 * @param description long help text for the option
448 * @param[out] topKeywords set to the desired value
450 struct GNUNET_GETOPT_CommandLineOption
451 GNUNET_FS_GETOPT_KEYWORDS (char shortName,
453 const char *argumentHelp,
454 const char *description,
455 struct GNUNET_FS_Uri **topKeywords);
458 * Allow user to specify metadata.
460 * @param shortName short name of the option
461 * @param name long name of the option
462 * @param argumentHelp help text for the option argument
463 * @param description long help text for the option
464 * @param[out] metadata set to the desired value
466 struct GNUNET_GETOPT_CommandLineOption
467 GNUNET_FS_GETOPT_METADATA (char shortName,
469 const char *argumentHelp,
470 const char *description,
471 struct GNUNET_CONTAINER_MetaData **meta);
474 * Command-line option parser function that allows the user to specify
475 * one or more '-m' options with metadata. Each specified entry of
476 * the form "type=value" will be added to the metadata. A pointer to
477 * the metadata must be passed as the "scls" argument.
479 * @param ctx command line processor context
480 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
481 * @param option name of the option (typically 'k')
482 * @param value command line argument given
483 * @return #GNUNET_OK on success
486 GNUNET_FS_getopt_set_metadata (struct
487 GNUNET_GETOPT_CommandLineProcessorContext *ctx,
493 /* ************************* sharing API ***************** */
497 * Possible status codes used in the callback for the
498 * various file-sharing operations. On each file (or search),
499 * the callback is guaranteed to be called once with "START"
500 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
501 * are optional and depend on the circumstances; parent operations
502 * will be STARTED before child-operations and STOPPED after
503 * their respective child-operations. START and STOP signals
504 * are typically generated either due to explicit client requests
505 * or because of suspend/resume operations.
507 enum GNUNET_FS_Status
510 * Notification that we have started to publish a file structure.
512 GNUNET_FS_STATUS_PUBLISH_START = 0,
515 * Notification that we have resumed sharing a file structure.
517 GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
520 * Notification that we have suspended sharing a file structure.
522 GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
525 * Notification that we are making progress sharing a file structure.
527 GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
530 * Notification that an error was encountered sharing a file structure.
531 * The application will continue to receive resume/suspend events for
532 * this structure until "GNUNET_FS_publish_stop" is called.
534 GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
537 * Notification that we completed sharing a file structure.
538 * The application will continue to receive resume/suspend events for
539 * this structure until "GNUNET_FS_publish_stop" is called.
541 GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
544 * Notification that we have stopped
545 * the process of uploading a file structure; no
546 * futher events will be generated for this action.
548 GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
551 * Notification that we have started this download.
553 GNUNET_FS_STATUS_DOWNLOAD_START = 7,
556 * Notification that this download is being resumed.
558 GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
561 * Notification that this download was suspended.
563 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
566 * Notification about progress with this download.
568 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
571 * Notification that this download encountered an error.
573 GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
576 * Notification that this download completed. Note that for
577 * directories, completion does not imply completion of all files in
580 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
583 * Notification that this download was stopped
584 * (final event with respect to this action).
586 GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
589 * Notification that this download is now actively being
590 * pursued (as opposed to waiting in the queue).
592 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
595 * Notification that this download is no longer actively
596 * being pursued (back in the queue).
598 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
601 * Notification that this download is no longer part of a
602 * recursive download or search but now a 'stand-alone'
603 * download (and may thus need to be moved in the GUI
604 * into a different category).
606 GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
609 * First event generated when a client requests
610 * a search to begin or when a namespace result
611 * automatically triggers the search for updates.
613 GNUNET_FS_STATUS_SEARCH_START = 17,
616 * Last event when a search is being resumed;
617 * note that "GNUNET_FS_SEARCH_START" will not
618 * be generated in this case.
620 GNUNET_FS_STATUS_SEARCH_RESUME = 18,
623 * Event generated for each search result
624 * when the respective search is resumed.
626 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
629 * Last event when a search is being suspended;
630 * note that "GNUNET_FS_SEARCH_STOPPED" will not
631 * be generated in this case.
633 GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
636 * This search has yielded a result.
638 GNUNET_FS_STATUS_SEARCH_RESULT = 21,
641 * We have discovered a new namespace.
643 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
646 * We have additional data about the quality
647 * or availability of a search result.
649 GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
652 * Signals a problem with this search.
654 GNUNET_FS_STATUS_SEARCH_ERROR = 24,
657 * Signals that this search was paused.
659 GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
662 * Signals that this search was continued (unpaused).
664 GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
667 * Event generated for each search result
668 * when the respective search is stopped.
670 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
673 * Event generated for each search result
674 * when the respective search is suspended.
676 GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
679 * Last message from a search; this signals
680 * that there will be no further events associated
683 GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
686 * Notification that we started to unindex a file.
688 GNUNET_FS_STATUS_UNINDEX_START = 30,
691 * Notification that we resumed unindexing of a file.
693 GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
696 * Notification that we suspended unindexing a file.
698 GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
701 * Notification that we made progress unindexing a file.
703 GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
706 * Notification that we encountered an error unindexing
709 GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
712 * Notification that the unindexing of this file
715 GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
718 * Notification that the unindexing of this file
719 * was stopped (final event for this action).
721 GNUNET_FS_STATUS_UNINDEX_STOPPED = 36,
724 * Notification that we are making progress sharing a directory.
726 GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY = 37
731 * Handle for controlling an upload.
733 struct GNUNET_FS_PublishContext;
737 * Handle for controlling an unindexing operation.
739 struct GNUNET_FS_UnindexContext;
743 * Handle for controlling a search.
745 struct GNUNET_FS_SearchContext;
749 * Result from a search. Opaque handle to refer to the search
750 * (typically used when starting a download associated with the search
753 struct GNUNET_FS_SearchResult;
757 * Context for controlling a download.
759 struct GNUNET_FS_DownloadContext;
763 * Handle for detail information about a file that is being publishd.
764 * Specifies metadata, keywords, how to get the contents of the file
765 * (i.e. data-buffer in memory, filename on disk) and other options.
767 struct GNUNET_FS_FileInformation;
771 * Argument given to the progress callback with
772 * information about what is going on.
774 struct GNUNET_FS_ProgressInfo
777 * Values that depend on the event type.
782 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
787 * Context for controlling the upload.
789 struct GNUNET_FS_PublishContext *pc;
792 * Information about the file that is being publishd.
794 const struct GNUNET_FS_FileInformation *fi;
797 * Client context pointer (set the last time by the client for
798 * this operation; initially NULL on START/RESUME events).
803 * Client context pointer for the parent operation
804 * (if this is a file in a directory or a subdirectory).
809 * Name of the file being published; can be NULL.
811 const char *filename;
814 * How large is the file overall? For directories,
815 * this is only the size of the directory itself,
816 * not of the other files contained within the
822 * At what time do we expect to finish the upload?
823 * (will be a value in the past for completed
826 struct GNUNET_TIME_Relative eta;
829 * How long has this upload been actively running
830 * (excludes times where the upload was suspended).
832 struct GNUNET_TIME_Relative duration;
835 * How many bytes have we completed?
840 * What anonymity level is used for this upload?
845 * Additional values for specific events.
850 * These values are only valid for
851 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
856 * Data block we just published.
861 * At what offset in the file is "data"?
866 * Length of the data block.
871 * Depth of the given block in the tree;
872 * 0 would be the lowest level (DBLOCKs).
878 * These values are only valid for
879 * #GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY events.
884 * How far are we along in the overall directory?
889 * How big do we estimate the entire directory to be?
894 * At what time do we expect to finish the upload of the
895 * CONTENTS of the directory. (The direcory itself will take
896 * extra time, indicated with the "eta" member at the
897 * "publish"-level of this struct.)
899 struct GNUNET_TIME_Relative eta;
900 } progress_directory;
903 * These values are only valid for
904 * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
909 * Error message, NULL if no error was encountered so far.
914 * URI of the file (if the download had been completed)
916 const struct GNUNET_FS_Uri *chk_uri;
919 * SKS URI of the file (if the download had been completed)
921 const struct GNUNET_FS_Uri *sks_uri;
925 * These values are only valid for
926 * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
931 * CHK URI of the file.
933 const struct GNUNET_FS_Uri *chk_uri;
936 * SKS URI of the file (if the download had been completed)
938 const struct GNUNET_FS_Uri *sks_uri;
942 * These values are only valid for
943 * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
948 * Error message, never NULL.
957 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
962 * Context for controlling the download.
964 struct GNUNET_FS_DownloadContext *dc;
967 * Client context pointer (set the last time
968 * by the client for this operation; initially
969 * NULL on START/RESUME events).
974 * Client context pointer for the parent operation
975 * (if this is a file in a directory or a subdirectory).
980 * Client context pointer for the associated search operation
981 * (specifically, context pointer for the specific search
982 * result, not the overall search); only set if this
983 * download was started from a search result.
988 * URI used for this download.
990 const struct GNUNET_FS_Uri *uri;
993 * Name of the file that we are downloading.
995 const char *filename;
998 * How large is the download overall? This
999 * is NOT necessarily the size from the
1000 * URI since we may be doing a partial download.
1005 * At what time do we expect to finish the download?
1006 * (will be a value in the past for completed
1009 struct GNUNET_TIME_Relative eta;
1012 * How long has this download been active?
1014 struct GNUNET_TIME_Relative duration;
1017 * How many bytes have we completed?
1022 * What anonymity level is used for this download?
1027 * Is the download currently active.
1032 * Additional values for specific events.
1037 * These values are only valid for
1038 * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1043 * Data block we just obtained, can be NULL (even if
1044 * data_len > 0) if we found the entire block 'intact' on
1045 * disk. In this case, it is also possible for 'data_len'
1046 * to be larger than an individual (32k) block.
1051 * At what offset in the file is "data"?
1056 * Length of the data block.
1061 * How much time passed between us asking for this block and
1062 * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1064 struct GNUNET_TIME_Relative block_download_duration;
1067 * Depth of the given block in the tree;
1068 * 0 would be the lowest level (DBLOCKS).
1073 * How much respect did we offer for downloading this block? (estimate,
1074 * because we might have the same request pending for multiple clients,
1075 * and of course because a transmission may have failed at a lower
1078 uint32_t respect_offered;
1081 * How often did we transmit the request? (estimate,
1082 * because we might have the same request pending for multiple clients,
1083 * and of course because a transmission may have failed at a lower
1086 uint32_t num_transmissions;
1090 * These values are only valid for
1091 * #GNUNET_FS_STATUS_DOWNLOAD_START events.
1096 * Known metadata for the download.
1098 const struct GNUNET_CONTAINER_MetaData *meta;
1102 * These values are only valid for
1103 * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1108 * Known metadata for the download.
1110 const struct GNUNET_CONTAINER_MetaData *meta;
1113 * Error message, NULL if we have not encountered any error yet.
1115 const char *message;
1119 * These values are only valid for
1120 * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1127 const char *message;
1133 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1138 * Context for controlling the search, NULL for
1139 * searches that were not explicitly triggered
1140 * by the client (i.e., searches for updates in
1143 struct GNUNET_FS_SearchContext *sc;
1146 * Client context pointer (set the last time by the client for
1147 * this operation; initially NULL on START/RESUME events). Note
1148 * that this value can only be set on START/RESUME; returning
1149 * non-NULL on RESULT/RESUME_RESULT will actually update the
1150 * private context for "UPDATE" events.
1155 * Client parent-context pointer; NULL for top-level searches,
1156 * refers to the client context of the associated search result
1157 * for automatically triggered searches for updates in
1158 * namespaces. In this case, 'presult' refers to that search
1164 * What query is used for this search
1165 * (list of keywords or SKS identifier).
1167 const struct GNUNET_FS_Uri *query;
1170 * How long has this search been actively running
1171 * (excludes times where the search was paused or
1174 struct GNUNET_TIME_Relative duration;
1177 * What anonymity level is used for this search?
1182 * Additional values for specific events.
1187 * These values are only valid for
1188 * #GNUNET_FS_STATUS_SEARCH_RESULT events.
1193 * Metadata for the search result.
1195 const struct GNUNET_CONTAINER_MetaData *meta;
1198 * URI for the search result.
1200 const struct GNUNET_FS_Uri *uri;
1203 * Handle to the result (for starting downloads).
1205 struct GNUNET_FS_SearchResult *result;
1208 * Applicability rank (the larger, the better the result
1209 * fits the search criteria).
1211 uint32_t applicability_rank;
1215 * These values are only valid for
1216 * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1221 * Metadata for the search result.
1223 const struct GNUNET_CONTAINER_MetaData *meta;
1226 * URI for the search result.
1228 const struct GNUNET_FS_Uri *uri;
1231 * Handle to the result (for starting downloads).
1233 struct GNUNET_FS_SearchResult *result;
1236 * Current availability rank (negative:
1237 * unavailable, positive: available)
1239 int32_t availability_rank;
1242 * On how many total queries is the given
1243 * availability_rank based?
1245 uint32_t availability_certainty;
1248 * Updated applicability rank (the larger,
1249 * the better the result fits the search
1252 uint32_t applicability_rank;
1256 * These values are only valid for
1257 * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
1262 * Private context set for for this result
1263 * during the "RESULT" event.
1268 * Metadata for the search result.
1270 const struct GNUNET_CONTAINER_MetaData *meta;
1273 * URI for the search result.
1275 const struct GNUNET_FS_Uri *uri;
1278 * Current availability rank (negative:
1279 * unavailable, positive: available)
1281 int32_t availability_rank;
1284 * On how many total queries is the given
1285 * availability_rank based?
1287 uint32_t availability_certainty;
1290 * Updated applicability rank (the larger,
1291 * the better the result fits the search
1294 uint32_t applicability_rank;
1297 * How long has the current probe been active?
1299 struct GNUNET_TIME_Relative current_probe_time;
1303 * These values are only valid for
1304 * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1305 * These events are automatically triggered for
1306 * each search result before the
1307 * #GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1308 * happens primarily to give the client a chance
1309 * to clean up the "cctx" (if needed).
1314 * Private context set for for this result
1315 * during the "RESULT" event.
1320 * Metadata for the search result.
1322 const struct GNUNET_CONTAINER_MetaData *meta;
1325 * URI for the search result.
1327 const struct GNUNET_FS_Uri *uri;
1331 * These values are only valid for
1332 * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1333 * These events are automatically triggered for
1334 * each search result before the
1335 * #GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1336 * happens primarily to give the client a chance
1337 * to clean up the "cctx" (if needed).
1342 * Private context set for for this result
1343 * during the "RESULT" event.
1348 * Metadata for the search result.
1350 const struct GNUNET_CONTAINER_MetaData *meta;
1353 * URI for the search result.
1355 const struct GNUNET_FS_Uri *uri;
1359 * These values are only valid for
1360 * #GNUNET_FS_STATUS_SEARCH_RESUME events.
1365 * Error message, NULL if we have not encountered any error yet.
1367 const char *message;
1370 * Is this search currently paused?
1376 * These values are only valid for
1377 * #GNUNET_FS_STATUS_SEARCH_ERROR events.
1384 const char *message;
1388 * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
1393 * Short, human-readable name of the namespace.
1398 * Root identifier for the namespace, can be NULL.
1403 * Metadata for the namespace.
1405 const struct GNUNET_CONTAINER_MetaData *meta;
1408 * Public key of the namespace.
1410 struct GNUNET_CRYPTO_EcdsaPublicKey pseudonym;
1416 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1421 * Context for controlling the unindexing.
1423 struct GNUNET_FS_UnindexContext *uc;
1426 * Client context pointer (set the last time
1427 * by the client for this operation; initially
1428 * NULL on START/RESUME events).
1433 * Name of the file that is being unindexed.
1435 const char *filename;
1438 * How large is the file overall?
1443 * At what time do we expect to finish unindexing?
1444 * (will be a value in the past for completed
1445 * unindexing opeations).
1447 struct GNUNET_TIME_Relative eta;
1450 * How long has this upload been actively running
1451 * (excludes times where the upload was suspended).
1453 struct GNUNET_TIME_Relative duration;
1456 * How many bytes have we completed?
1461 * Additional values for specific events.
1466 * These values are only valid for
1467 * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1472 * Data block we just unindexed.
1477 * At what offset in the file is "data"?
1482 * Length of the data block.
1487 * Depth of the given block in the tree;
1488 * 0 would be the lowest level (DBLOCKS).
1494 * These values are only valid for
1495 * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
1500 * Error message, NULL if we have not encountered any error yet.
1502 const char *message;
1506 * These values are only valid for
1507 * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
1514 const char *message;
1521 * Specific status code (determines the event type).
1523 enum GNUNET_FS_Status status;
1526 * File-sharing handle that generated the event.
1528 struct GNUNET_FS_Handle *fsh;
1533 * Notification of FS to a client about the progress of an
1534 * operation. Callbacks of this type will be used for uploads,
1535 * downloads and searches. Some of the arguments depend a bit
1536 * in their meaning on the context in which the callback is used.
1538 * @param cls closure
1539 * @param info details about the event, specifying the event type
1540 * and various bits about the event
1541 * @return client-context (for the next progress call
1542 * for this operation; should be set to NULL for
1543 * SUSPEND and STOPPED events). The value returned
1544 * will be passed to future callbacks in the respective
1545 * field in the `struct GNUNET_FS_ProgressInfo`.
1548 (*GNUNET_FS_ProgressCallback) (void *cls,
1549 const struct GNUNET_FS_ProgressInfo *info);
1553 * General (global) option flags for file-sharing.
1555 enum GNUNET_FS_Flags
1558 * No special flags set.
1560 GNUNET_FS_FLAGS_NONE = 0,
1563 * Is persistence of operations desired?
1564 * (will create SUSPEND/RESUME events).
1566 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1569 * Should we automatically trigger probes for search results
1570 * to determine availability?
1571 * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
1573 GNUNET_FS_FLAGS_DO_PROBES = 2
1578 * Options specified in the VARARGs portion of GNUNET_FS_start.
1580 enum GNUNET_FS_OPTIONS
1583 * Last option in the VARARG list.
1585 GNUNET_FS_OPTIONS_END = 0,
1588 * Select the desired amount of parallelism (this option should be
1589 * followed by an "unsigned int" giving the desired maximum number
1590 * of parallel downloads).
1592 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1595 * Maximum number of requests that should be pending at a given
1596 * point in time (invidivual downloads may go above this, but
1597 * if we are above this threshold, we should not activate any
1598 * additional downloads.
1600 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1605 * Settings for publishing a block (which may of course also
1606 * apply to an entire directory or file).
1608 struct GNUNET_FS_BlockOptions
1611 * At what time should the block expire? Data blocks (DBLOCKS and
1612 * IBLOCKS) may still be used even if they are expired (however,
1613 * they'd be removed quickly from the datastore if we are short on
1614 * space), all other types of blocks will no longer be returned
1615 * after they expire.
1617 struct GNUNET_TIME_Absolute expiration_time;
1620 * At which anonymity level should the block be shared?
1621 * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1623 uint32_t anonymity_level;
1626 * How important is it for us to store the block? If we run
1627 * out of space, the highest-priority, non-expired blocks will
1630 uint32_t content_priority;
1633 * How often should we try to migrate the block to other peers?
1634 * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1635 * first push each block to other peers according to their
1636 * replication levels. Once each block has been pushed that many
1637 * times to other peers, blocks are chosen for migration at random.
1638 * Naturally, there is no guarantee that the other peers will keep
1639 * these blocks for any period of time (since they won't have any
1640 * priority or might be too busy to even store the block in the
1643 uint32_t replication_level;
1648 * Handle to the file-sharing service.
1650 struct GNUNET_FS_Handle;
1654 * Setup a connection to the file-sharing service.
1656 * @param cfg configuration to use
1657 * @param client_name unique identifier for this client
1658 * @param upcb function to call to notify about FS actions
1659 * @param upcb_cls closure for @a upcb
1660 * @param flags specific attributes for fs-operations
1661 * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
1662 * @return NULL on error
1664 struct GNUNET_FS_Handle *
1665 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1666 const char *client_name,
1667 GNUNET_FS_ProgressCallback upcb,
1669 enum GNUNET_FS_Flags flags,
1674 * Close our connection with the file-sharing service.
1675 * The callback given to #GNUNET_FS_start() will no longer be
1676 * called after this function returns.
1677 * This function MUST NOT be called from within the
1680 * @param h handle that was returned from #GNUNET_FS_start()
1683 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1687 * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
1689 * @param cls closure
1690 * @param fi the entry in the publish-structure
1691 * @param length length of the file or directory
1692 * @param meta metadata for the file or directory (can be modified)
1693 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1694 * @param bo block options (can be modified)
1695 * @param do_index should we index (can be modified)
1696 * @param client_info pointer to client context set upon creation (can be modified)
1697 * @return #GNUNET_OK to continue, #GNUNET_NO to remove
1698 * this entry from the directory, #GNUNET_SYSERR
1699 * to abort the iteration
1702 (*GNUNET_FS_FileInformationProcessor) (void *cls,
1703 struct GNUNET_FS_FileInformation *fi,
1705 struct GNUNET_CONTAINER_MetaData *meta,
1706 struct GNUNET_FS_Uri **uri,
1707 struct GNUNET_FS_BlockOptions *bo,
1709 void **client_info);
1713 * Obtain the name under which this file information
1714 * structure is stored on disk. Only works for top-level
1715 * file information structures.
1717 * @param s structure to get the filename for
1718 * @return NULL on error, otherwise filename that can be used
1719 * to read this fi-struct from disk.
1722 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1726 * Obtain the filename from the file information structure.
1728 * @param s structure to get the filename for
1729 * @return "filename" field of the structure (can be NULL)
1732 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1736 * Set the filename in the file information structure.
1737 * If filename was already set, frees it before setting the new one.
1738 * Makes a copy of the argument.
1740 * @param s structure to get the filename for
1741 * @param filename filename to set
1744 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1745 const char *filename);
1749 * Create an entry for a file in a publish-structure.
1751 * @param h handle to the file sharing subsystem
1752 * @param client_info initial client-info value for this entry
1753 * @param filename name of the file or directory to publish
1754 * @param keywords under which keywords should this file be available
1755 * directly; can be NULL
1756 * @param meta metadata for the file
1757 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1758 * #GNUNET_SYSERR for simulation
1759 * @param bo block options
1760 * @return publish structure entry for the file
1762 struct GNUNET_FS_FileInformation *
1763 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1765 const char *filename,
1767 GNUNET_FS_Uri *keywords,
1769 GNUNET_CONTAINER_MetaData *meta,
1772 GNUNET_FS_BlockOptions *bo);
1776 * Create an entry for a file in a publish-structure.
1778 * @param h handle to the file sharing subsystem
1779 * @param client_info initial client-info value for this entry
1780 * @param length length of the file
1781 * @param data data for the file (should not be used afterwards by
1782 * the caller; callee will "free")
1783 * @param keywords under which keywords should this file be available
1784 * directly; can be NULL
1785 * @param meta metadata for the file
1786 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1787 * #GNUNET_SYSERR for simulation
1788 * @param bo block options
1789 * @return publish structure entry for the file
1791 struct GNUNET_FS_FileInformation *
1792 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1797 GNUNET_FS_Uri *keywords,
1799 GNUNET_CONTAINER_MetaData *meta,
1802 GNUNET_FS_BlockOptions *bo);
1806 * Function that provides data.
1808 * @param cls closure
1809 * @param offset offset to read from; it is possible
1810 * that the caller might need to go backwards
1811 * a bit at times; set to UINT64_MAX to tell
1812 * the reader that we won't be reading for a while
1813 * (used to close the file descriptor but NOT fully
1814 * clean up the reader's state); in this case,
1815 * a value of '0' for max should be ignored
1816 * @param max maximum number of bytes that should be
1817 * copied to buf; readers are not allowed
1818 * to provide less data unless there is an error;
1819 * a value of "0" will be used at the end to allow
1820 * the reader to clean up its internal state
1821 * @param buf where the reader should write the data
1822 * @param emsg location for the reader to store an error message
1823 * @return number of bytes written, usually @a max, 0 on error
1826 (*GNUNET_FS_DataReader) (void *cls,
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 reader function that can be used to obtain the data for the file
1840 * @param reader_cls closure for @a reader
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_reader (struct GNUNET_FS_Handle *h,
1853 GNUNET_FS_DataReader reader,
1855 const struct GNUNET_FS_Uri
1858 GNUNET_CONTAINER_MetaData *meta,
1861 GNUNET_FS_BlockOptions *bo);
1865 * Create an entry for an empty directory in a publish-structure.
1867 * @param h handle to the file sharing subsystem
1868 * @param client_info initial client-info value for this entry
1869 * @param keywords under which keywords should this directory be available
1870 * directly; can be NULL
1871 * @param meta metadata for the directory
1872 * @param bo block options
1873 * @param filename name of the directory; can be NULL
1874 * @return publish structure entry for the directory , NULL on error
1876 struct GNUNET_FS_FileInformation *
1877 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1879 const struct GNUNET_FS_Uri
1882 GNUNET_CONTAINER_MetaData
1885 GNUNET_FS_BlockOptions *bo,
1886 const char *filename);
1890 * Test if a given entry represents a directory.
1892 * @param ent check if this FI represents a directory
1893 * @return #GNUNET_YES if so, #GNUNET_NO if not
1896 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1901 * Add an entry to a directory in a publish-structure. Clients
1902 * should never modify publish structures that were passed to
1903 * #GNUNET_FS_publish_start() already.
1905 * @param dir the directory
1906 * @param ent the entry to add; the entry must not have been
1907 * added to any other directory at this point and
1908 * must not include @a dir in its structure
1909 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1912 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1913 struct GNUNET_FS_FileInformation *ent);
1917 * Inspect a file or directory in a publish-structure. Clients
1918 * should never modify publish structures that were passed to
1919 * #GNUNET_FS_publish_start already. When called on a directory,
1920 * this function will FIRST call @a proc with information about
1921 * the directory itself and then for each of the files in the
1922 * directory (but not for files in subdirectories). When called
1923 * on a file, @a proc will be called exactly once (with information
1924 * about the specific file).
1926 * @param dir the directory
1927 * @param proc function to call on each entry
1928 * @param proc_cls closure for @a proc
1931 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1932 GNUNET_FS_FileInformationProcessor proc,
1937 * Destroy publish-structure. Clients should never destroy publish
1938 * structures that were passed to #GNUNET_FS_publish_start already.
1940 * @param fi structure to destroy
1941 * @param cleaner function to call on each entry in the structure
1942 * (useful to clean up client_info); can be NULL; return
1943 * values are ignored
1944 * @param cleaner_cls closure for @a cleaner
1947 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1948 GNUNET_FS_FileInformationProcessor cleaner,
1953 * Options for publishing. Compatible options
1954 * can be OR'ed together.
1956 enum GNUNET_FS_PublishOptions
1959 * No options (use defaults for everything).
1961 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1964 * Simulate publishing. With this option, no data will be stored
1965 * in the datastore. Useful for computing URIs from files.
1967 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1972 * Publish a file or directory.
1974 * @param h handle to the file sharing subsystem
1975 * @param fi information about the file or directory structure to publish
1976 * @param ns namespace to publish the file in, NULL for no namespace
1977 * @param nid identifier to use for the publishd content in the namespace
1978 * (can be NULL, must be NULL if namespace is NULL)
1979 * @param nuid update-identifier that will be used for future updates
1980 * (can be NULL, must be NULL if namespace or nid is NULL)
1981 * @param options options for the publication
1982 * @return context that can be used to control the publish operation
1984 struct GNUNET_FS_PublishContext *
1985 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1986 struct GNUNET_FS_FileInformation *fi,
1987 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
1990 enum GNUNET_FS_PublishOptions options);
1994 * Stop a publication. Will abort incomplete publications (but
1995 * not remove blocks that have already been published) or
1996 * simply clean up the state for completed publications.
1997 * Must NOT be called from within the event callback!
1999 * @param pc context for the publication to stop
2002 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2006 * Signature of a function called as the continuation of a KBlock or
2007 * SBlock publication.
2009 * @param cls closure
2010 * @param uri URI under which the block is now available, NULL on error
2011 * @param emsg error message, NULL on success
2014 (*GNUNET_FS_PublishContinuation) (void *cls,
2015 const struct GNUNET_FS_Uri *uri,
2020 * Handle to cancel publish KSK operation.
2022 struct GNUNET_FS_PublishKskContext;
2026 * Publish a KBlock on GNUnet.
2028 * @param h handle to the file sharing subsystem
2029 * @param ksk_uri keywords to use
2030 * @param meta metadata to use
2031 * @param uri URI to refer to in the KBlock
2032 * @param bo block options
2033 * @param options publication options
2034 * @param cont continuation
2035 * @param cont_cls closure for @a cont
2036 * @return NULL on error (@a cont will still be called)
2038 struct GNUNET_FS_PublishKskContext *
2039 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2040 const struct GNUNET_FS_Uri *ksk_uri,
2041 const struct GNUNET_CONTAINER_MetaData *meta,
2042 const struct GNUNET_FS_Uri *uri,
2043 const struct GNUNET_FS_BlockOptions *bo,
2044 enum GNUNET_FS_PublishOptions options,
2045 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2049 * Abort the KSK publishing operation.
2051 * @param pkc context of the operation to abort.
2054 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2058 * Handle to cancel publish SKS operation.
2060 struct GNUNET_FS_PublishSksContext;
2064 * Publish an SBlock on GNUnet.
2066 * @param h handle to the file sharing subsystem
2067 * @param ns namespace to publish in
2068 * @param identifier identifier to use
2069 * @param update update identifier to use
2070 * @param meta metadata to use
2071 * @param uri URI to refer to in the SBlock
2072 * @param bo block options
2073 * @param options publication options
2074 * @param cont continuation
2075 * @param cont_cls closure for @a cont
2076 * @return NULL on error (@a cont will still be called)
2078 struct GNUNET_FS_PublishSksContext *
2079 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2080 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2081 const char *identifier,
2083 const struct GNUNET_CONTAINER_MetaData *meta,
2084 const struct GNUNET_FS_Uri *uri,
2085 const struct GNUNET_FS_BlockOptions *bo,
2086 enum GNUNET_FS_PublishOptions options,
2087 GNUNET_FS_PublishContinuation cont, void *cont_cls);
2091 * Abort the SKS publishing operation.
2093 * @param psc context of the operation to abort.
2096 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2100 * Type of a function called by #GNUNET_FS_get_indexed_files.
2102 * @param cls closure
2103 * @param filename the name of the file, NULL for end of list
2104 * @param file_id hash of the contents of the indexed file
2105 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2108 (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2109 const char *filename,
2110 const struct GNUNET_HashCode *file_id);
2114 * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2116 struct GNUNET_FS_GetIndexedContext;
2120 * Iterate over all indexed files.
2122 * @param h handle to the file sharing subsystem
2123 * @param iterator function to call on each indexed file
2124 * @param iterator_cls closure for @a iterator
2125 * @return NULL on error (@a iterator is not called)
2127 struct GNUNET_FS_GetIndexedContext *
2128 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2129 GNUNET_FS_IndexedFileProcessor iterator,
2130 void *iterator_cls);
2134 * Cancel iteration over all indexed files.
2136 * @param gic operation to cancel
2139 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2145 * @param h handle to the file sharing subsystem
2146 * @param filename file to unindex
2147 * @param cctx initial value for the client context
2148 * @return NULL on error, otherwise handle
2150 struct GNUNET_FS_UnindexContext *
2151 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2152 const char *filename,
2157 * Clean up after completion of an unindex operation.
2162 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2166 * Function called on updateable identifiers.
2168 * @param cls closure
2169 * @param last_id last identifier
2170 * @param last_uri uri used for the content published under the @a last_id
2171 * @param last_meta metadata associated with @a last_uri
2172 * @param next_id identifier that should be used for updates
2174 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2175 const char *last_id,
2177 GNUNET_FS_Uri *last_uri,
2179 GNUNET_CONTAINER_MetaData *
2181 const char *next_id);
2185 * List all of the identifiers in the namespace for which we could
2186 * produce an update. Namespace updates form a graph where each node
2187 * has a name. Each node can have any number of URI/meta-data entries
2188 * which can each be linked to other nodes. Cycles are possible.
2190 * Calling this function with @a next_id NULL will cause the library to
2191 * call @a ip with a root for each strongly connected component of the
2192 * graph (a root being a node from which all other nodes in the Scc
2195 * Calling this function with @a next_id being the name of a node will
2196 * cause the library to call @a ip with all children of the node. Note
2197 * that cycles within an SCC are possible (including self-loops).
2199 * @param h fs handle to use
2200 * @param ns namespace to inspect for updateable content
2201 * @param next_id ID to look for; use NULL to look for SCC roots
2202 * @param ip function to call on each updateable identifier
2203 * @param ip_cls closure for @a ip
2206 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
2208 GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2209 const char *next_id,
2210 GNUNET_FS_IdentifierProcessor ip,
2215 * Options for searching. Compatible options
2216 * can be OR'ed together.
2218 enum GNUNET_FS_SearchOptions
2221 * No options (use defaults for everything).
2223 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2226 * Only search the local host, do not search remote systems (no P2P)
2228 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2233 * Start search for content.
2235 * @param h handle to the file sharing subsystem
2236 * @param uri specifies the search parameters; can be
2237 * a KSK URI or an SKS URI.
2238 * @param anonymity desired level of anonymity
2239 * @param options options for the search
2240 * @param cctx initial value for the client context
2241 * @return context that can be used to control the search
2243 struct GNUNET_FS_SearchContext *
2244 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2245 const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2246 enum GNUNET_FS_SearchOptions options, void *cctx);
2252 * @param sc context for the search that should be paused
2255 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2259 * Continue paused search.
2261 * @param sc context for the search that should be resumed
2264 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2268 * Stop search for content.
2270 * @param sc context for the search that should be stopped
2273 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2277 * Start download probes for the given search result.
2279 * @param h file-sharing handle to use for the operation
2280 * @param uri URI to probe
2281 * @param meta meta data associated with the URI
2282 * @param client_info client info pointer to use for associated events
2283 * @param anonymity anonymity level to use for the probes
2284 * @return the search result handle to access the probe activity
2286 struct GNUNET_FS_SearchResult *
2287 GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2288 const struct GNUNET_FS_Uri *uri,
2289 const struct GNUNET_CONTAINER_MetaData *meta,
2291 uint32_t anonymity);
2295 * Stop probe activity. Must ONLY be used on values
2296 * returned from #GNUNET_FS_probe.
2298 * @param sr search result to stop probing for (freed)
2299 * @return the value of the 'client_info' pointer
2302 GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2306 * Options for downloading. Compatible options
2307 * can be OR'ed together.
2309 enum GNUNET_FS_DownloadOptions
2312 * No options (use defaults for everything).
2314 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2317 * Only download from the local host, do not access remote systems (no P2P)
2319 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2322 * Do a recursive download (that is, automatically trigger the
2323 * download of files in directories).
2325 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2328 * Do not append temporary data to
2329 * the target file (for the IBlocks).
2331 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2334 * Internal option used to flag this download as a 'probe' for a
2335 * search result. Impacts the priority with which the download is
2336 * run and causes signalling callbacks to be done differently.
2337 * Also, probe downloads are not serialized on suspension. Normal
2338 * clients should not use this!
2340 GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2345 * Download parts of a file. Note that this will store
2346 * the blocks at the respective offset in the given file. Also, the
2347 * download is still using the blocking of the underlying FS
2348 * encoding. As a result, the download may *write* outside of the
2349 * given boundaries (if offset and length do not match the 32k FS
2350 * block boundaries).
2352 * The given range can be used to focus a download towards a
2353 * particular portion of the file (optimization), not to strictly
2354 * limit the download to exactly those bytes.
2356 * @param h handle to the file sharing subsystem
2357 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2358 * @param meta known metadata for the file (can be NULL)
2359 * @param filename where to store the file, maybe NULL (then no file is
2360 * created on disk and data must be grabbed from the callbacks)
2361 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2362 * can be NULL (in which case we will pick a name if needed); the temporary file
2363 * may already exist, in which case we will try to use the data that is there and
2364 * if it is not what is desired, will overwrite it
2365 * @param offset at what offset should we start the download (typically 0)
2366 * @param length how many bytes should be downloaded starting at offset
2367 * @param anonymity anonymity level to use for the download
2368 * @param options various download options
2369 * @param cctx initial value for the client context for this download
2370 * @param parent parent download to associate this download with (use NULL
2371 * for top-level downloads; useful for manually-triggered recursive downloads)
2372 * @return context that can be used to control this download
2374 struct GNUNET_FS_DownloadContext *
2375 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2376 const struct GNUNET_FS_Uri *uri,
2377 const struct GNUNET_CONTAINER_MetaData *meta,
2378 const char *filename, const char *tempname,
2379 uint64_t offset, uint64_t length, uint32_t anonymity,
2380 enum GNUNET_FS_DownloadOptions options, void *cctx,
2381 struct GNUNET_FS_DownloadContext *parent);
2385 * Download parts of a file based on a search result. The download
2386 * will be associated with the search result (and the association
2387 * will be preserved when serializing/deserializing the state).
2388 * If the search is stopped, the download will not be aborted but
2389 * be 'promoted' to a stand-alone download.
2391 * As with the other download function, this will store
2392 * the blocks at the respective offset in the given file. Also, the
2393 * download is still using the blocking of the underlying FS
2394 * encoding. As a result, the download may *write* outside of the
2395 * given boundaries (if offset and length do not match the 32k FS
2396 * block boundaries).
2398 * The given range can be used to focus a download towards a
2399 * particular portion of the file (optimization), not to strictly
2400 * limit the download to exactly those bytes.
2402 * @param h handle to the file sharing subsystem
2403 * @param sr the search result to use for the download (determines uri and
2404 * meta data and associations)
2405 * @param filename where to store the file, maybe NULL (then no file is
2406 * created on disk and data must be grabbed from the callbacks)
2407 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2408 * can be NULL (in which case we will pick a name if needed); the temporary file
2409 * may already exist, in which case we will try to use the data that is there and
2410 * if it is not what is desired, will overwrite it
2411 * @param offset at what offset should we start the download (typically 0)
2412 * @param length how many bytes should be downloaded starting at offset
2413 * @param anonymity anonymity level to use for the download
2414 * @param options various download options
2415 * @param cctx initial value for the client context for this download
2416 * @return context that can be used to control this download
2418 struct GNUNET_FS_DownloadContext *
2419 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2420 struct GNUNET_FS_SearchResult *sr,
2421 const char *filename,
2422 const char *tempname, uint64_t offset,
2423 uint64_t length, uint32_t anonymity,
2424 enum GNUNET_FS_DownloadOptions options,
2429 * Stop a download (aborts if download is incomplete).
2431 * @param dc handle for the download
2432 * @param do_delete delete files of incomplete downloads
2435 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2439 * Suspend a download.
2441 * @param dc handle for the download
2444 GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc);
2448 * Resume a suspended download.
2450 * @param dc handle for the download
2453 GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2456 /* ******************** Directory API *********************** */
2459 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2460 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2461 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2464 * Does the meta-data claim that this is a directory?
2465 * Checks if the mime-type is that of a GNUnet directory.
2467 * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
2468 * we have no mime-type information (treat as #GNUNET_NO)
2471 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2476 * Set the MIMETYPE information for the given
2477 * metadata to "application/gnunet-directory".
2479 * @param md metadata to add mimetype to
2482 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2486 * Suggest a filename based on given metadata.
2488 * @param md given meta data
2489 * @return NULL if meta data is useless for suggesting a filename
2492 GNUNET_FS_meta_data_suggest_filename (const struct
2493 GNUNET_CONTAINER_MetaData *md);
2497 * Function used to process entries in a directory.
2499 * @param cls closure
2500 * @param filename name of the file in the directory
2501 * @param uri URI of the file
2502 * @param metadata metadata for the file; metadata for
2503 * the directory if everything else is NULL/zero
2504 * @param length length of the available data for the file
2505 * (of type size_t since data must certainly fit
2506 * into memory; if files are larger than size_t
2507 * permits, then they will certainly not be
2508 * embedded with the directory itself).
2509 * @param data data available for the file (length bytes)
2511 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2512 const char *filename,
2513 const struct GNUNET_FS_Uri *
2516 GNUNET_CONTAINER_MetaData *
2517 meta, size_t length,
2522 * Iterate over all entries in a directory. Note that directories
2523 * are structured such that it is possible to iterate over the
2524 * individual blocks as well as over the entire directory. Thus
2525 * a client can call this function on the buffer in the
2526 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2527 * include the contents of (small) files embedded in the directory
2528 * itself; for those files, the processor may be given the
2529 * contents of the file directly by this function.
2531 * @param size number of bytes in data
2532 * @param data pointer to the beginning of the directory
2533 * @param offset offset of data in the directory
2534 * @param dep function to call on each entry
2535 * @param dep_cls closure for @a dep
2536 * @return #GNUNET_OK if this could be a block in a directory,
2537 * #GNUNET_NO if this could be part of a directory (but not 100% OK)
2538 * #GNUNET_SYSERR if 'data' does not represent a directory
2541 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2543 GNUNET_FS_DirectoryEntryProcessor dep,
2548 * Opaque handle to a directory builder.
2550 struct GNUNET_FS_DirectoryBuilder;
2554 * Create a directory builder.
2556 * @param mdir metadata for the directory
2558 struct GNUNET_FS_DirectoryBuilder *
2559 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2564 * Add an entry to a directory.
2566 * @param bld directory to extend
2567 * @param uri uri of the entry (must not be a KSK)
2568 * @param md metadata of the entry
2569 * @param data raw data of the entry, can be NULL, otherwise
2570 * data must point to exactly the number of bytes specified
2574 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2575 const struct GNUNET_FS_Uri *uri,
2576 const struct GNUNET_CONTAINER_MetaData *md,
2581 * Finish building the directory. Frees the
2582 * builder context and returns the directory
2585 * @param bld directory to finish
2586 * @param rsize set to the number of bytes needed
2587 * @param rdata set to the encoded directory
2588 * @return #GNUNET_OK on success
2591 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2592 size_t *rsize, void **rdata);
2595 /* ******************** DirScanner API *********************** */
2598 * Progress reasons of the directory scanner.
2600 enum GNUNET_FS_DirScannerProgressUpdateReason
2603 * We've started processing a file or directory.
2605 GNUNET_FS_DIRSCANNER_FILE_START = 0,
2608 * We're having trouble accessing a file (soft-error); it will
2611 GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2614 * We've found all files (in the pre-pass).
2616 GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2619 * We've finished extracting meta data from a file.
2621 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2624 * Last call to the progress function: we have finished scanning
2627 GNUNET_FS_DIRSCANNER_FINISHED,
2630 * There was an internal error. Application should abort the scan.
2632 GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2637 * Function called over time as the directory scanner makes
2638 * progress on the job at hand.
2640 * @param cls closure
2641 * @param filename which file we are making progress on
2642 * @param is_directory #GNUNET_YES if this is a directory,
2643 * #GNUNET_NO if this is a file
2644 * #GNUNET_SYSERR if it is neither (or unknown)
2645 * @param reason kind of progress we are making
2647 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2648 const char *filename,
2651 GNUNET_FS_DirScannerProgressUpdateReason
2656 * A node of a directory tree (produced by dirscanner)
2658 struct GNUNET_FS_ShareTreeItem
2661 * This is a doubly-linked list
2663 struct GNUNET_FS_ShareTreeItem *prev;
2666 * This is a doubly-linked list
2668 struct GNUNET_FS_ShareTreeItem *next;
2671 * This is a doubly-linked tree
2672 * NULL for top-level entries.
2674 struct GNUNET_FS_ShareTreeItem *parent;
2677 * This is a doubly-linked tree
2678 * NULL for files and empty directories
2680 struct GNUNET_FS_ShareTreeItem *children_head;
2683 * This is a doubly-linked tree
2684 * NULL for files and empty directories
2686 struct GNUNET_FS_ShareTreeItem *children_tail;
2689 * Metadata for this file or directory
2691 struct GNUNET_CONTAINER_MetaData *meta;
2694 * Keywords for this file or directory (derived from metadata).
2696 struct GNUNET_FS_Uri *ksk_uri;
2699 * Name of the file/directory
2704 * Base name of the file/directory.
2706 char *short_filename;
2709 * #GNUNET_YES if this is a directory
2716 * Opaque handle to an asynchronous directory scanning activity.
2718 struct GNUNET_FS_DirScanner;
2722 * Start a directory scanner.
2724 * @param filename name of the directory to scan
2725 * @param disable_extractor #GNUNET_YES to not run libextractor on files (only
2727 * @param ex if not NULL, must be a list of extra plugins for extractor
2728 * @param cb the callback to call when there are scanning progress messages
2729 * @param cb_cls closure for @a cb
2730 * @return directory scanner object to be used for controlling the scanner
2732 struct GNUNET_FS_DirScanner *
2733 GNUNET_FS_directory_scan_start (const char *filename,
2734 int disable_extractor,
2736 GNUNET_FS_DirScannerProgressCallback cb,
2741 * Abort the scan. Must not be called from within the progress_callback
2744 * @param ds directory scanner structure
2747 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2751 * Obtain the result of the scan after the scan has signalled
2752 * completion. Must not be called prior to completion. The @a ds is
2753 * freed as part of this call.
2755 * @param ds directory scanner structure
2756 * @return the results of the scan (a directory tree)
2758 struct GNUNET_FS_ShareTreeItem *
2759 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2763 * Process a share item tree, moving frequent keywords up and
2764 * copying frequent metadata up.
2766 * @param toplevel toplevel directory in the tree, returned by the scanner
2769 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2773 * Release memory of a share item tree.
2775 * @param toplevel toplevel of the tree to be freed
2778 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2781 #if 0 /* keep Emacsens' auto-indent happy */
2790 /** @} */ /* end of group */