2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_fs_service.h
22 * @brief API for file-sharing via GNUnet
23 * @author Christian Grothoff
26 * - extend API with support for publish simulation (-s)
27 * and URI-argument binding to keyword/namespace (-u)
29 #ifndef GNUNET_FS_LIB_H
30 #define GNUNET_FS_LIB_H
32 #include "gnunet_util_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
43 * Version number of the implementation.
46 * 1.x.x: initial version with triple GNUNET_hash and merkle tree
47 * 2.x.x: root node with mime-type, filename and version number
48 * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
49 * 2.2.x: with directories
50 * 3.0.x: with namespaces
51 * 3.1.x: with namespace meta-data
52 * 3.2.x: with collections
53 * 4.0.x: with expiration, variable meta-data, kblocks
54 * 4.1.x: with new error and configuration handling
55 * 5.0.x: with location URIs
56 * 6.0.0: with support for OR in KSKs
57 * 6.1.x: with simplified namespace support
58 * 9.0.0: CPS-style integrated API
60 #define GNUNET_FS_VERSION 0x00090000
63 /* ******************** URI API *********************** */
65 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
66 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
67 #define GNUNET_FS_URI_SKS_INFIX "sks/"
68 #define GNUNET_FS_URI_CHK_INFIX "chk/"
69 #define GNUNET_FS_URI_LOC_INFIX "loc/"
73 * A Universal Resource Identifier (URI), opaque.
79 * Iterator over keywords
82 * @param keyword the keyword
83 * @param is_mandatory is the keyword mandatory (in a search)
84 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
86 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
91 * Get a unique key from a URI. This is for putting URIs
92 * into HashMaps. The key may change between FS implementations.
94 * @param uri uri to convert to a unique key
95 * @param key wherer to store the unique key
98 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
99 GNUNET_HashCode * key);
102 * Convert a URI to a UTF-8 String.
104 * @param uri uri to convert to a string
105 * @return the UTF-8 string
108 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
111 * Convert keyword URI to a human readable format
112 * (i.e. the search query that was used in the first place)
114 * @param uri ksk uri to convert to a string
115 * @return string with the keywords
118 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
122 * Convert a UTF-8 String to a URI.
124 * @param uri string to parse
125 * @param emsg where to store the parser error message (if any)
126 * @return NULL on error
128 struct GNUNET_FS_Uri *
129 GNUNET_FS_uri_parse (const char *uri,
135 * @param uri uri to free
138 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
142 * How many keywords are ANDed in this keyword URI?
144 * @param uri ksk uri to get the number of keywords from
145 * @return 0 if this is not a keyword URI
148 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
152 * Iterate over all keywords in this keyword URI.
154 * @param uri ksk uri to get the keywords from
155 * @param iterator function to call on each keyword
156 * @param iterator_cls closure for iterator
157 * @return -1 if this is not a keyword URI, otherwise number of
158 * keywords iterated over until iterator aborted
161 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
162 GNUNET_FS_KeywordIterator iterator,
167 * Obtain the identity of the peer offering the data
169 * @param uri the location URI to inspect
170 * @param peer where to store the identify of the peer (presumably) offering the content
171 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
174 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
175 struct GNUNET_PeerIdentity * peer);
179 * Obtain the URI of the content itself.
181 * @param uri location URI to get the content URI from
182 * @return NULL if argument is not a location URI
184 struct GNUNET_FS_Uri *
185 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
189 * Obtain the expiration of the LOC URI.
191 * @param uri location URI to get the expiration from
192 * @return expiration time of the URI
194 struct GNUNET_TIME_Absolute
195 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
199 * Construct a location URI (this peer will be used for the location).
201 * @param baseUri content offered by the sender
202 * @param cfg configuration information (used to find our hostkey)
203 * @param expiration_time how long will the content be offered?
204 * @return the location URI, NULL on error
206 struct GNUNET_FS_Uri *
207 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
208 struct GNUNET_CONFIGURATION_Handle *cfg,
209 struct GNUNET_TIME_Absolute expiration_time);
213 * Canonicalize keyword URI. Performs operations such
214 * as decapitalization and removal of certain characters.
215 * (useful for search).
217 * @param uri the URI to canonicalize
218 * @return canonicalized version of the URI, NULL on error
220 struct GNUNET_FS_Uri *
221 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
225 * Merge the sets of keywords from two KSK URIs.
226 * (useful for merging the canonicalized keywords with
227 * the original keywords for sharing).
229 * @param u1 first uri
230 * @param u2 second uri
231 * @return merged URI, NULL on error
233 struct GNUNET_FS_Uri *
234 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
235 const struct GNUNET_FS_Uri *u2);
241 * @param uri the URI to duplicate
242 * @return copy of the URI
244 struct GNUNET_FS_Uri *
245 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
249 * Create an FS URI from a single user-supplied string of keywords.
250 * The string is broken up at spaces into individual keywords.
251 * Keywords that start with "+" are mandatory. Double-quotes can
252 * be used to prevent breaking up strings at spaces (and also
253 * to specify non-mandatory keywords starting with "+").
255 * Keywords must contain a balanced number of double quotes and
256 * double quotes can not be used in the actual keywords (for
257 * example, the string '""foo bar""' will be turned into two
258 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
260 * @param keywords the keyword string
261 * @param emsg where to store an error message
262 * @return an FS URI for the given keywords, NULL
263 * if keywords is not legal (i.e. empty).
265 struct GNUNET_FS_Uri *
266 GNUNET_FS_uri_ksk_create (const char *keywords,
271 * Create an FS URI from a user-supplied command line of keywords.
272 * Arguments should start with "+" to indicate mandatory
275 * @param argc number of keywords
276 * @param argv keywords (double quotes are not required for
277 * keywords containing spaces; however, double
278 * quotes are required for keywords starting with
279 * "+"); there is no mechanism for having double
280 * quotes in the actual keywords (if the user
281 * did specifically specify double quotes, the
282 * caller should convert each double quote
283 * into two single quotes).
284 * @return an FS URI for the given keywords, NULL
285 * if keywords is not legal (i.e. empty).
287 struct GNUNET_FS_Uri *
288 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
293 * Test if two URIs are equal.
295 * @param u1 one of the URIs
296 * @param u2 the other URI
297 * @return GNUNET_YES if the URIs are equal
300 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
301 const struct GNUNET_FS_Uri *u2);
305 * Is this a namespace URI?
307 * @param uri the uri to check
308 * @return GNUNET_YES if this is an SKS uri
311 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
315 * Handle to one of our namespaces.
317 struct GNUNET_FS_Namespace;
321 * Create an SKS URI from a namespace and an identifier.
323 * @param ns namespace
324 * @param id identifier
325 * @param emsg where to store an error message
326 * @return an FS URI for the given namespace and identifier
328 struct GNUNET_FS_Uri *
329 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
335 * Get the ID of a namespace from the given
338 * @param uri the uri to get the namespace ID from
339 * @param nsid where to store the ID of the namespace
340 * @return GNUNET_OK on success
343 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
344 GNUNET_HashCode * nsid);
348 * Get the content identifier of an SKS URI.
350 * @param uri the sks uri
351 * @return NULL on error (not a valid SKS URI)
354 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
358 * Convert namespace URI to a human readable format
359 * (using the namespace description, if available).
361 * @param cfg configuration to use
362 * @param uri SKS uri to convert
363 * @return NULL on error (not an SKS URI)
366 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
367 const struct GNUNET_FS_Uri *uri);
371 * Is this a keyword URI?
374 * @return GNUNET_YES if this is a KSK uri
377 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
381 * Is this a file (or directory) URI?
383 * @param uri the uri to check
384 * @return GNUNET_YES if this is a CHK uri
387 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
391 * What is the size of the file that this URI
394 * @param uri the CHK (or LOC) URI to inspect
395 * @return size of the file as specified in the CHK URI
398 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
402 * Is this a location URI?
404 * @param uri the uri to check
405 * @return GNUNET_YES if this is a LOC uri
408 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
412 * Construct a keyword-URI from meta-data (take all entries
413 * in the meta-data and construct one large keyword URI
414 * that lists all keywords that can be found in the meta-data).
416 * @param md metadata to use
417 * @return NULL on error, otherwise a KSK URI
419 struct GNUNET_FS_Uri *
420 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
423 /* ******************** command-line option parsing API *********************** */
426 * Command-line option parser function that allows the user
427 * to specify one or more '-k' options with keywords. Each
428 * specified keyword will be added to the URI. A pointer to
429 * the URI must be passed as the "scls" argument.
431 * @param ctx command line processor context
432 * @param scls must be of type "struct GNUNET_FS_Uri **"
433 * @param option name of the option (typically 'k')
434 * @param value command line argument given
435 * @return GNUNET_OK on success
438 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
445 * Command-line option parser function that allows the user to specify
446 * one or more '-m' options with metadata. Each specified entry of
447 * the form "type=value" will be added to the metadata. A pointer to
448 * the metadata must be passed as the "scls" argument.
450 * @param ctx command line processor context
451 * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
452 * @param option name of the option (typically 'k')
453 * @param value command line argument given
454 * @return GNUNET_OK on success
457 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx,
464 /* ************************* sharing API ***************** */
468 * Possible status codes used in the callback for the
469 * various file-sharing operations. On each file (or search),
470 * the callback is guaranteed to be called once with "START"
471 * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
472 * are optional and depend on the circumstances; parent operations
473 * will be STARTED before child-operations and STOPPED after
474 * their respective child-operations. START and STOP signals
475 * are typically generated either due to explicit client requests
476 * or because of suspend/resume operations.
478 enum GNUNET_FS_Status
481 * Notification that we have started to publish a file structure.
483 GNUNET_FS_STATUS_PUBLISH_START,
486 * Notification that we have resumed sharing a file structure.
488 GNUNET_FS_STATUS_PUBLISH_RESUME,
491 * Notification that we have suspended sharing a file structure.
493 GNUNET_FS_STATUS_PUBLISH_SUSPEND,
496 * Notification that we are making progress sharing a file structure.
498 GNUNET_FS_STATUS_PUBLISH_PROGRESS,
501 * Notification that an error was encountered sharing a file structure.
502 * The application will continue to receive resume/suspend events for
503 * this structure until "GNUNET_FS_publish_stop" is called.
505 GNUNET_FS_STATUS_PUBLISH_ERROR,
508 * Notification that we completed sharing a file structure.
509 * The application will continue to receive resume/suspend events for
510 * this structure until "GNUNET_FS_publish_stop" is called.
512 GNUNET_FS_STATUS_PUBLISH_COMPLETED,
515 * Notification that we have stopped
516 * the process of uploading a file structure; no
517 * futher events will be generated for this action.
519 GNUNET_FS_STATUS_PUBLISH_STOPPED,
522 * Notification that we have started this download.
524 GNUNET_FS_STATUS_DOWNLOAD_START,
527 * Notification that this download is being resumed.
529 GNUNET_FS_STATUS_DOWNLOAD_RESUME,
532 * Notification that this download was suspended.
534 GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
537 * Notification about progress with this download.
539 GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
542 * Notification that this download encountered an error.
544 GNUNET_FS_STATUS_DOWNLOAD_ERROR,
547 * Notification that this download completed. Note that for
548 * directories, completion does not imply completion of all files in
551 GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
554 * Notification that this download was stopped
555 * (final event with respect to this action).
557 GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
560 * Notification that this download is now actively being
561 * pursued (as opposed to waiting in the queue).
563 GNUNET_FS_STATUS_DOWNLOAD_ACTIVE,
566 * Notification that this download is no longer actively
567 * being pursued (back in the queue).
569 GNUNET_FS_STATUS_DOWNLOAD_INACTIVE,
572 * First event generated when a client requests
573 * a search to begin or when a namespace result
574 * automatically triggers the search for updates.
576 GNUNET_FS_STATUS_SEARCH_START,
579 * Last event when a search is being resumed;
580 * note that "GNUNET_FS_SEARCH_START" will not
581 * be generated in this case.
583 GNUNET_FS_STATUS_SEARCH_RESUME,
586 * Event generated for each search result
587 * when the respective search is resumed.
589 GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
592 * Last event when a search is being suspended;
593 * note that "GNUNET_FS_SEARCH_STOPPED" will not
594 * be generated in this case.
596 GNUNET_FS_STATUS_SEARCH_SUSPEND,
599 * Event generated for each search result
600 * when the respective search is suspended.
602 GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
605 * This search has yielded a result.
607 GNUNET_FS_STATUS_SEARCH_RESULT,
610 * We have discovered a new namespace.
612 GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
615 * We have additional data about the quality
616 * or availability of a search result.
618 GNUNET_FS_STATUS_SEARCH_UPDATE,
621 * Signals a problem with this search.
623 GNUNET_FS_STATUS_SEARCH_ERROR,
626 * Signals that this search was paused.
628 GNUNET_FS_STATUS_SEARCH_PAUSED,
631 * Signals that this search was continued (unpaused).
633 GNUNET_FS_STATUS_SEARCH_CONTINUED,
636 * Event generated for each search result
637 * when the respective search is stopped.
639 GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
642 * Last message from a search; this signals
643 * that there will be no further events associated
646 GNUNET_FS_STATUS_SEARCH_STOPPED,
649 * Notification that we started to unindex a file.
651 GNUNET_FS_STATUS_UNINDEX_START,
654 * Notification that we resumed unindexing of a file.
656 GNUNET_FS_STATUS_UNINDEX_RESUME,
659 * Notification that we suspended unindexing a file.
661 GNUNET_FS_STATUS_UNINDEX_SUSPEND,
664 * Notification that we made progress unindexing a file.
666 GNUNET_FS_STATUS_UNINDEX_PROGRESS,
669 * Notification that we encountered an error unindexing
672 GNUNET_FS_STATUS_UNINDEX_ERROR,
675 * Notification that the unindexing of this file
678 GNUNET_FS_STATUS_UNINDEX_COMPLETED,
681 * Notification that the unindexing of this file
682 * was stopped (final event for this action).
684 GNUNET_FS_STATUS_UNINDEX_STOPPED
690 * Handle for controlling an upload.
692 struct GNUNET_FS_PublishContext;
696 * Handle for controlling an unindexing operation.
698 struct GNUNET_FS_UnindexContext;
702 * Handle for controlling a search.
704 struct GNUNET_FS_SearchContext;
708 * Context for controlling a download.
710 struct GNUNET_FS_DownloadContext;
714 * Handle for detail information about a file that is being publishd.
715 * Specifies metadata, keywords, how to get the contents of the file
716 * (i.e. data-buffer in memory, filename on disk) and other options.
718 struct GNUNET_FS_FileInformation;
722 * Argument given to the progress callback with
723 * information about what is going on.
725 struct GNUNET_FS_ProgressInfo
729 * Values that depend on the event type.
734 * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
739 * Context for controlling the upload.
741 struct GNUNET_FS_PublishContext *sc;
744 * Information about the file that is being publishd.
746 const struct GNUNET_FS_FileInformation *fi;
749 * Client context pointer (set the last time by the client for
750 * this operation; initially NULL on START/RESUME events).
755 * Client context pointer for the parent operation
756 * (if this is a file in a directory or a subdirectory).
761 * Name of the file being published; can be NULL.
763 const char *filename;
766 * How large is the file overall? For directories,
767 * this is only the size of the directory itself,
768 * not of the other files contained within the
774 * At what time do we expect to finish the upload?
775 * (will be a value in the past for completed
778 struct GNUNET_TIME_Relative eta;
781 * How long has this upload been actively running
782 * (excludes times where the upload was suspended).
784 struct GNUNET_TIME_Relative duration;
787 * How many bytes have we completed?
792 * What anonymity level is used for this upload?
797 * Additional values for specific events.
802 * These values are only valid for
803 * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
808 * Data block we just published.
813 * At what offset in the file is "data"?
818 * Length of the data block.
823 * Depth of the given block in the tree;
824 * 0 would be the highest level (the first
825 * call is guaranteed to be for the lowest
833 * These values are only valid for
834 * GNUNET_FS_STATUS_PUBLISH_RESUME events.
839 * Error message, NULL if no error was encountered so far.
844 * URI of the file (if the download had been completed)
846 const struct GNUNET_FS_Uri *chk_uri;
851 * These values are only valid for
852 * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
859 const struct GNUNET_FS_Uri *chk_uri;
864 * These values are only valid for
865 * GNUNET_FS_STATUS_PUBLISH_ERROR events.
870 * Error message, never NULL.
882 * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
887 * Context for controlling the download.
889 struct GNUNET_FS_DownloadContext *dc;
892 * Client context pointer (set the last time
893 * by the client for this operation; initially
894 * NULL on START/RESUME events).
899 * Client context pointer for the parent operation
900 * (if this is a file in a directory or a subdirectory).
905 * URI used for this download.
907 const struct GNUNET_FS_Uri *uri;
910 * Name of the file that we are downloading.
912 const char *filename;
915 * How large is the download overall? This
916 * is NOT necessarily the size from the
917 * URI since we may be doing a partial download.
922 * At what time do we expect to finish the download?
923 * (will be a value in the past for completed
926 struct GNUNET_TIME_Relative eta;
929 * How long has this download been active?
931 struct GNUNET_TIME_Relative duration;
934 * How many bytes have we completed?
939 * What anonymity level is used for this download?
944 * Additional values for specific events.
949 * These values are only valid for
950 * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
955 * Data block we just obtained.
960 * At what offset in the file is "data"?
965 * Length of the data block.
970 * Depth of the given block in the tree;
971 * 0 would be the highest level (the first
972 * call is guaranteed to be for the lowest
980 * These values are only valid for
981 * GNUNET_FS_STATUS_DOWNLOAD_START events.
986 * Known metadata for the download.
988 const struct GNUNET_CONTAINER_MetaData *meta;
993 * These values are only valid for
994 * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
999 * Known metadata for the download.
1001 const struct GNUNET_CONTAINER_MetaData *meta;
1004 * Error message, NULL if we have not encountered any error yet.
1006 const char *message;
1011 * These values are only valid for
1012 * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1019 const char *message;
1028 * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1033 * Context for controlling the search, NULL for
1034 * searches that were not explicitly triggered
1035 * by the client (i.e., searches for updates in
1038 struct GNUNET_FS_SearchContext *sc;
1041 * Client context pointer (set the last time by the client for
1042 * this operation; initially NULL on START/RESUME events). Note
1043 * that this value can only be set on START/RESUME; returning
1044 * non-NULL on RESULT/RESUME_RESULT will actually update the
1045 * private context for "UPDATE" events.
1050 * Client parent-context pointer; NULL for top-level searches,
1051 * non-NULL for automatically triggered searches for updates in
1057 * What query is used for this search
1058 * (list of keywords or SKS identifier).
1060 const struct GNUNET_FS_Uri *query;
1063 * How long has this search been actively running
1064 * (excludes times where the search was paused or
1067 struct GNUNET_TIME_Relative duration;
1070 * What anonymity level is used for this search?
1075 * Additional values for specific events.
1080 * These values are only valid for
1081 * GNUNET_FS_STATUS_SEARCH_RESULT events.
1086 * Metadata for the search result.
1088 const struct GNUNET_CONTAINER_MetaData *meta;
1091 * URI for the search result.
1093 const struct GNUNET_FS_Uri *uri;
1098 * These values are only valid for
1099 * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1104 * Metadata for the search result.
1106 const struct GNUNET_CONTAINER_MetaData *meta;
1109 * URI for the search result.
1111 const struct GNUNET_FS_Uri *uri;
1114 * Current availability rank (negative:
1115 * unavailable, positive: available)
1117 int32_t availability_rank;
1120 * On how many total queries is the given
1121 * availability_rank based?
1123 uint32_t availabiliy_certainty;
1126 * Updated applicability rank (the larger,
1127 * the better the result fits the search
1130 uint32_t applicabiliy_rank;
1135 * These values are only valid for
1136 * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1141 * Private context set for for this result
1142 * during the "RESULT" event.
1147 * Metadata for the search result.
1149 const struct GNUNET_CONTAINER_MetaData *meta;
1152 * URI for the search result.
1154 const struct GNUNET_FS_Uri *uri;
1157 * Current availability rank (negative:
1158 * unavailable, positive: available)
1160 int32_t availability_rank;
1163 * On how many total queries is the given
1164 * availability_rank based?
1166 uint32_t availability_certainty;
1169 * Updated applicability rank (the larger,
1170 * the better the result fits the search
1173 uint32_t applicability_rank;
1178 * These values are only valid for
1179 * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1180 * These events are automatically triggered for
1181 * each search result before the
1182 * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This
1183 * happens primarily to give the client a chance
1184 * to clean up the "cctx" (if needed).
1189 * Private context set for for this result
1190 * during the "RESULT" event.
1195 * Metadata for the search result.
1197 const struct GNUNET_CONTAINER_MetaData *meta;
1200 * URI for the search result.
1202 const struct GNUNET_FS_Uri *uri;
1207 * These values are only valid for
1208 * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1209 * These events are automatically triggered for
1210 * each search result before the
1211 * GNUNET_FS_STATUS_SEARCH_STOPPED event. This
1212 * happens primarily to give the client a chance
1213 * to clean up the "cctx" (if needed).
1218 * Private context set for for this result
1219 * during the "RESULT" event.
1224 * Metadata for the search result.
1226 const struct GNUNET_CONTAINER_MetaData *meta;
1229 * URI for the search result.
1231 const struct GNUNET_FS_Uri *uri;
1236 * These values are only valid for
1237 * GNUNET_FS_STATUS_SEARCH_RESUME events.
1242 * Error message, NULL if we have not encountered any error yet.
1244 const char *message;
1247 * Is this search currently paused?
1254 * These values are only valid for
1255 * GNUNET_FS_STATUS_SEARCH_ERROR events.
1262 const char *message;
1267 * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1272 * Handle to the namespace (NULL if it is not a local
1275 struct GNUNET_FS_Namespace *ns;
1278 * Short, human-readable name of the namespace.
1283 * Root identifier for the namespace, can be NULL.
1288 * Metadata for the namespace.
1290 const struct GNUNET_CONTAINER_MetaData *meta;
1293 * Hash-identifier for the namespace.
1304 * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1309 * Context for controlling the unindexing.
1311 struct GNUNET_FS_UnindexContext *uc;
1314 * Client context pointer (set the last time
1315 * by the client for this operation; initially
1316 * NULL on START/RESUME events).
1321 * Name of the file that is being unindexed.
1323 const char *filename;
1326 * How large is the file overall?
1331 * At what time do we expect to finish unindexing?
1332 * (will be a value in the past for completed
1333 * unindexing opeations).
1335 struct GNUNET_TIME_Relative eta;
1338 * How long has this upload been actively running
1339 * (excludes times where the upload was suspended).
1341 struct GNUNET_TIME_Relative duration;
1344 * How many bytes have we completed?
1349 * Additional values for specific events.
1354 * These values are only valid for
1355 * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1360 * Data block we just unindexed.
1365 * At what offset in the file is "data"?
1370 * Length of the data block.
1375 * Depth of the given block in the tree;
1376 * 0 would be the highest level (the first
1377 * call is guaranteed to be for the lowest
1385 * These values are only valid for
1386 * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1391 * Error message, NULL if we have not encountered any error yet.
1393 const char *message;
1398 * These values are only valid for
1399 * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1406 const char *message;
1417 * Specific status code (determines the event type).
1419 enum GNUNET_FS_Status status;
1425 * Notification of FS to a client about the progress of an
1426 * operation. Callbacks of this type will be used for uploads,
1427 * downloads and searches. Some of the arguments depend a bit
1428 * in their meaning on the context in which the callback is used.
1430 * @param cls closure
1431 * @param info details about the event, specifying the event type
1432 * and various bits about the event
1433 * @return client-context (for the next progress call
1434 * for this operation; should be set to NULL for
1435 * SUSPEND and STOPPED events). The value returned
1436 * will be passed to future callbacks in the respective
1437 * field in the GNUNET_FS_ProgressInfo struct.
1439 typedef void* (*GNUNET_FS_ProgressCallback)
1441 const struct GNUNET_FS_ProgressInfo *info);
1445 * General (global) option flags for file-sharing.
1447 enum GNUNET_FS_Flags
1450 * No special flags set.
1452 GNUNET_FS_FLAGS_NONE = 0,
1455 * Is persistence of operations desired?
1456 * (will create SUSPEND/RESUME events).
1458 GNUNET_FS_FLAGS_PERSISTENCE = 1,
1461 * Should we automatically trigger probes for search results
1462 * to determine availability?
1463 * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1465 GNUNET_FS_FLAGS_DO_PROBES = 2
1470 * Options specified in the VARARGs portion of GNUNET_FS_start.
1472 enum GNUNET_FS_OPTIONS
1476 * Last option in the VARARG list.
1478 GNUNET_FS_OPTIONS_END = 0,
1481 * Select the desired amount of parallelism (this option should be
1482 * followed by an "unsigned int" giving the desired maximum number
1483 * of parallel downloads).
1485 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1488 * Maximum number of requests that should be pending at a given
1489 * point in time (invidivual downloads may go above this, but
1490 * if we are above this threshold, we should not activate any
1491 * additional downloads.
1493 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1499 * Handle to the file-sharing service.
1501 struct GNUNET_FS_Handle;
1505 * Setup a connection to the file-sharing service.
1507 * @param sched scheduler to use
1508 * @param cfg configuration to use
1509 * @param client_name unique identifier for this client
1510 * @param upcb function to call to notify about FS actions
1511 * @param upcb_cls closure for upcb
1512 * @param flags specific attributes for fs-operations
1513 * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1514 * @return NULL on error
1516 struct GNUNET_FS_Handle *
1517 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1518 const struct GNUNET_CONFIGURATION_Handle *cfg,
1519 const char *client_name,
1520 GNUNET_FS_ProgressCallback upcb,
1522 enum GNUNET_FS_Flags flags,
1527 * Close our connection with the file-sharing service.
1528 * The callback given to GNUNET_FS_start will no longer be
1529 * called after this function returns.
1531 * @param h handle that was returned from GNUNET_FS_start
1534 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1538 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1540 * @param cls closure
1541 * @param fi the entry in the publish-structure
1542 * @param length length of the file or directory
1543 * @param meta metadata for the file or directory (can be modified)
1544 * @param uri pointer to the keywords that will be used for this entry (can be modified)
1545 * @param anonymity pointer to selected anonymity level (can be modified)
1546 * @param priority pointer to selected priority (can be modified)
1547 * @param expirationTime pointer to selected expiration time (can be modified)
1548 * @param client_info pointer to client context set upon creation (can be modified)
1549 * @return GNUNET_OK to continue, GNUNET_NO to remove
1550 * this entry from the directory, GNUNET_SYSERR
1551 * to abort the iteration
1553 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1554 struct GNUNET_FS_FileInformation *fi,
1556 struct GNUNET_CONTAINER_MetaData *meta,
1557 struct GNUNET_FS_Uri **uri,
1558 uint32_t *anonymity,
1560 struct GNUNET_TIME_Absolute *expirationTime,
1561 void **client_info);
1565 * Obtain the name under which this file information
1566 * structure is stored on disk. Only works for top-level
1567 * file information structures.
1569 * @param s structure to get the filename for
1570 * @return NULL on error, otherwise filename that
1571 * can be passed to "GNUNET_FS_file_information_recover"
1572 * to read this fi-struct from disk.
1575 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1580 * Create an entry for a file in a publish-structure.
1582 * @param h handle to the file sharing subsystem
1583 * @param client_info initial client-info value for this entry
1584 * @param filename name of the file or directory to publish
1585 * @param keywords under which keywords should this file be available
1586 * directly; can be NULL
1587 * @param meta metadata for the file
1588 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1589 * GNUNET_SYSERR for simulation
1590 * @param anonymity what is the desired anonymity level for sharing?
1591 * @param priority what is the priority for OUR node to
1592 * keep this file available? Use 0 for maximum anonymity and
1593 * minimum reliability...
1594 * @param expirationTime when should this content expire?
1595 * @return publish structure entry for the file
1597 struct GNUNET_FS_FileInformation *
1598 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1600 const char *filename,
1601 const struct GNUNET_FS_Uri *keywords,
1602 const struct GNUNET_CONTAINER_MetaData *meta,
1606 struct GNUNET_TIME_Absolute expirationTime);
1610 * Create an entry for a file in a publish-structure.
1612 * @param h handle to the file sharing subsystem
1613 * @param client_info initial client-info value for this entry
1614 * @param length length of the file
1615 * @param data data for the file (should not be used afterwards by
1616 * the caller; callee will "free")
1617 * @param keywords under which keywords should this file be available
1618 * directly; can be NULL
1619 * @param meta metadata for the file
1620 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1621 * GNUNET_SYSERR for simulation
1622 * @param anonymity what is the desired anonymity level for sharing?
1623 * @param priority what is the priority for OUR node to
1624 * keep this file available? Use 0 for maximum anonymity and
1625 * minimum reliability...
1626 * @param expirationTime when should this content expire?
1627 * @return publish structure entry for the file
1629 struct GNUNET_FS_FileInformation *
1630 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1634 const struct GNUNET_FS_Uri *keywords,
1635 const struct GNUNET_CONTAINER_MetaData *meta,
1639 struct GNUNET_TIME_Absolute expirationTime);
1643 * Function that provides data.
1645 * @param cls closure
1646 * @param offset offset to read from; it is possible
1647 * that the caller might need to go backwards
1649 * @param max maximum number of bytes that should be
1650 * copied to buf; readers are not allowed
1651 * to provide less data unless there is an error;
1652 * a value of "0" will be used at the end to allow
1653 * the reader to clean up its internal state
1654 * @param buf where the reader should write the data
1655 * @param emsg location for the reader to store an error message
1656 * @return number of bytes written, usually "max", 0 on error
1658 typedef size_t (*GNUNET_FS_DataReader)(void *cls,
1666 * Create an entry for a file in a publish-structure.
1668 * @param h handle to the file sharing subsystem
1669 * @param client_info initial client-info value for this entry
1670 * @param length length of the file
1671 * @param reader function that can be used to obtain the data for the file
1672 * @param reader_cls closure for "reader"
1673 * @param keywords under which keywords should this file be available
1674 * directly; can be NULL
1675 * @param meta metadata for the file
1676 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1677 * GNUNET_SYSERR for simulation
1678 * @param anonymity what is the desired anonymity level for sharing?
1679 * @param priority what is the priority for OUR node to
1680 * keep this file available? Use 0 for maximum anonymity and
1681 * minimum reliability...
1682 * @param expirationTime when should this content expire?
1683 * @return publish structure entry for the file
1685 struct GNUNET_FS_FileInformation *
1686 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1689 GNUNET_FS_DataReader reader,
1691 const struct GNUNET_FS_Uri *keywords,
1692 const struct GNUNET_CONTAINER_MetaData *meta,
1696 struct GNUNET_TIME_Absolute expirationTime);
1700 * Function that a "GNUNET_FS_DirectoryScanner" should call
1701 * for each entry in the directory.
1703 * @param cls closure
1704 * @param filename name of the file (including path); must end
1705 * in a "/" (even on W32) if this is a directory
1706 * @param fi information about the file (should not be
1707 * used henceforth by the caller)
1709 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1710 const char *filename,
1711 struct GNUNET_FS_FileInformation *fi);
1715 * Type of a function that will be used to scan a directory.
1717 * @param cls closure
1718 * @param h handle to the file sharing subsystem
1719 * @param dirname name of the directory to scan
1720 * @param do_index should files be indexed or inserted
1721 * @param anonymity desired anonymity level
1722 * @param priority priority for publishing
1723 * @param expirationTime expiration for publication
1724 * @param proc function to call on each entry
1725 * @param proc_cls closure for proc
1726 * @param emsg where to store an error message (on errors)
1727 * @return GNUNET_OK on success
1729 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1730 struct GNUNET_FS_Handle *h,
1731 const char *dirname,
1735 struct GNUNET_TIME_Absolute expirationTime,
1736 GNUNET_FS_FileProcessor proc,
1743 * Simple, useful default implementation of a directory scanner
1744 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
1745 * UNIX filename, will publish all files in the directory except hidden
1746 * files (those starting with a "."). Metadata will be extracted
1747 * using GNU libextractor; the specific list of plugins should be
1748 * specified in "cls", passing NULL will disable (!) metadata
1749 * extraction. Keywords will be derived from the metadata and be
1750 * subject to default canonicalization. This is strictly a
1751 * convenience function.
1753 * @param cls must be of type "struct EXTRACTOR_Extractor*"
1754 * @param h handle to the file sharing subsystem
1755 * @param dirname name of the directory to scan
1756 * @param do_index should files be indexed or inserted
1757 * @param anonymity desired anonymity level
1758 * @param priority priority for publishing
1759 * @param expirationTime expiration for publication
1760 * @param proc function called on each entry
1761 * @param proc_cls closure for proc
1762 * @param emsg where to store an error message (on errors)
1763 * @return GNUNET_OK on success
1766 GNUNET_FS_directory_scanner_default (void *cls,
1767 struct GNUNET_FS_Handle *h,
1768 const char *dirname,
1772 struct GNUNET_TIME_Absolute expirationTime,
1773 GNUNET_FS_FileProcessor proc,
1779 * Create a publish-structure from an existing file hierarchy, inferring
1780 * and organizing keywords and metadata as much as possible. This
1781 * function primarily performs the recursive build and re-organizes
1782 * keywords and metadata; for automatically getting metadata
1783 * extraction, scanning of directories and creation of the respective
1784 * GNUNET_FS_FileInformation entries the default scanner should be
1785 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
1786 * convenience function.
1788 * @param h handle to the file sharing subsystem
1789 * @param client_info initial client-info value for this entry
1790 * @param filename name of the top-level file or directory
1791 * @param scanner function used to get a list of files in a directory
1792 * @param scanner_cls closure for scanner
1793 * @param do_index should files in the hierarchy be indexed?
1794 * @param anonymity what is the desired anonymity level for sharing?
1795 * @param priority what is the priority for OUR node to
1796 * keep this file available? Use 0 for maximum anonymity and
1797 * minimum reliability...
1798 * @param expirationTime when should this content expire?
1799 * @param emsg where to store an error message
1800 * @return publish structure entry for the directory, NULL on error
1802 struct GNUNET_FS_FileInformation *
1803 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
1805 const char *filename,
1806 GNUNET_FS_DirectoryScanner scanner,
1811 struct GNUNET_TIME_Absolute expirationTime,
1816 * Create an entry for an empty directory in a publish-structure.
1817 * This function should be used by applications for which the
1818 * use of "GNUNET_FS_file_information_create_from_directory"
1819 * is not appropriate.
1821 * @param h handle to the file sharing subsystem
1822 * @param client_info initial client-info value for this entry
1823 * @param keywords under which keywords should this directory be available
1824 * directly; can be NULL
1825 * @param meta metadata for the directory
1826 * @param anonymity what is the desired anonymity level for sharing?
1827 * @param priority what is the priority for OUR node to
1828 * keep this file available? Use 0 for maximum anonymity and
1829 * minimum reliability...
1830 * @param expirationTime when should this content expire?
1831 * @return publish structure entry for the directory , NULL on error
1833 struct GNUNET_FS_FileInformation *
1834 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1836 const struct GNUNET_FS_Uri *keywords,
1837 const struct GNUNET_CONTAINER_MetaData *meta,
1840 struct GNUNET_TIME_Absolute expirationTime);
1844 * Add an entry to a directory in a publish-structure. Clients
1845 * should never modify publish structures that were passed to
1846 * "GNUNET_FS_publish_start" already.
1848 * @param dir the directory
1849 * @param ent the entry to add; the entry must not have been
1850 * added to any other directory at this point and
1851 * must not include "dir" in its structure
1852 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1855 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1856 struct GNUNET_FS_FileInformation *ent);
1860 * Inspect a file or directory in a publish-structure. Clients
1861 * should never modify publish structures that were passed to
1862 * "GNUNET_FS_publish_start" already. When called on a directory,
1863 * this function will FIRST call "proc" with information about
1864 * the directory itself and then for each of the files in the
1865 * directory (but not for files in subdirectories). When called
1866 * on a file, "proc" will be called exactly once (with information
1867 * about the specific file).
1869 * @param dir the directory
1870 * @param proc function to call on each entry
1871 * @param proc_cls closure for proc
1874 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1875 GNUNET_FS_FileInformationProcessor proc,
1880 * Destroy publish-structure. Clients should never destroy publish
1881 * structures that were passed to "GNUNET_FS_publish_start" already.
1883 * @param fi structure to destroy
1884 * @param cleaner function to call on each entry in the structure
1885 * (useful to clean up client_info); can be NULL; return
1886 * values are ignored
1887 * @param cleaner_cls closure for cleaner
1890 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1891 GNUNET_FS_FileInformationProcessor cleaner,
1896 * Options for publishing. Compatible options
1897 * can be OR'ed together.
1899 enum GNUNET_FS_PublishOptions
1902 * No options (use defaults for everything).
1904 GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1907 * Simulate publishing. With this option, no data will be stored
1908 * in the datastore. Useful for computing URIs from files.
1910 GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1914 * Publish a file or directory.
1916 * @param h handle to the file sharing subsystem
1917 * @param fi information about the file or directory structure to publish
1918 * @param namespace namespace to publish the file in, NULL for no namespace
1919 * @param nid identifier to use for the publishd content in the namespace
1920 * (can be NULL, must be NULL if namespace is NULL)
1921 * @param nuid update-identifier that will be used for future updates
1922 * (can be NULL, must be NULL if namespace or nid is NULL)
1923 * @param options options for the publication
1924 * @return context that can be used to control the publish operation
1926 struct GNUNET_FS_PublishContext *
1927 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1928 struct GNUNET_FS_FileInformation *fi,
1929 struct GNUNET_FS_Namespace *namespace,
1932 enum GNUNET_FS_PublishOptions options);
1936 * Stop a publication. Will abort incomplete publications (but
1937 * not remove blocks that have already been published) or
1938 * simply clean up the state for completed publications.
1939 * Must NOT be called from within the event callback!
1941 * @param pc context for the publication to stop
1944 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
1948 * Signature of a function called as the continuation of a KBlock or
1949 * SBlock publication.
1951 * @param cls closure
1952 * @param uri URI under which the block is now available, NULL on error
1953 * @param emsg error message, NULL on success
1955 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1956 const struct GNUNET_FS_Uri *uri,
1961 * Publish a KBlock on GNUnet.
1963 * @param h handle to the file sharing subsystem
1964 * @param ksk_uri keywords to use
1965 * @param meta metadata to use
1966 * @param uri URI to refer to in the KBlock
1967 * @param expirationTime when the KBlock expires
1968 * @param anonymity anonymity level for the KBlock
1969 * @param priority priority for the KBlock
1970 * @param cont continuation
1971 * @param cont_cls closure for cont
1974 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1975 const struct GNUNET_FS_Uri *ksk_uri,
1976 const struct GNUNET_CONTAINER_MetaData *meta,
1977 const struct GNUNET_FS_Uri *uri,
1978 struct GNUNET_TIME_Absolute expirationTime,
1981 enum GNUNET_FS_PublishOptions options,
1982 GNUNET_FS_PublishContinuation cont,
1987 * Publish an SBlock on GNUnet.
1989 * @param h handle to the file sharing subsystem
1990 * @param namespace namespace to publish in
1991 * @param identifier identifier to use
1992 * @param update update identifier to use
1993 * @param meta metadata to use
1994 * @param uri URI to refer to in the SBlock
1995 * @param expirationTime when the SBlock expires
1996 * @param anonymity anonymity level for the SBlock
1997 * @param priority priority for the SBlock
1998 * @param cont continuation
1999 * @param cont_cls closure for cont
2002 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2003 struct GNUNET_FS_Namespace *namespace,
2004 const char *identifier,
2006 const struct GNUNET_CONTAINER_MetaData *meta,
2007 const struct GNUNET_FS_Uri *uri,
2008 struct GNUNET_TIME_Absolute expirationTime,
2011 enum GNUNET_FS_PublishOptions options,
2012 GNUNET_FS_PublishContinuation cont,
2017 * Type of a function called by "GNUNET_FS_get_indexed_files".
2019 * @param cls closure
2020 * @param filename the name of the file
2021 * @param file_id hash of the contents of the indexed file
2022 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2024 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2025 const char *filename,
2026 const GNUNET_HashCode *file_id);
2030 * Iterate over all indexed files.
2032 * @param h handle to the file sharing subsystem
2033 * @param iterator function to call on each indexed file
2034 * @param iterator_cls closure for iterator
2035 * @param cont continuation to call when done;
2036 * reason should be "TIMEOUT" (on
2037 * error) or "PREREQ_DONE" (on success)
2038 * @param cont_cls closure for cont
2041 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2042 GNUNET_FS_IndexedFileProcessor iterator,
2044 GNUNET_SCHEDULER_Task cont,
2051 * @param h handle to the file sharing subsystem
2052 * @param filename file to unindex
2053 * @param cctx initial value for the client context
2054 * @return NULL on error, otherwise handle
2056 struct GNUNET_FS_UnindexContext *
2057 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2058 const char *filename,
2063 * Clean up after completion of an unindex operation.
2068 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2072 * Publish an advertismement for a namespace.
2074 * @param h handle to the file sharing subsystem
2075 * @param ksk_uri keywords to use for advertisment
2076 * @param namespace handle for the namespace that should be advertised
2077 * @param meta meta-data for the namespace advertisement
2078 * @param anonymity for the namespace advertismement
2079 * @param priority for the namespace advertisement
2080 * @param expiration for the namespace advertisement
2081 * @param rootEntry name of the root of the namespace
2082 * @param cont continuation
2083 * @param cont_cls closure for cont
2086 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2087 struct GNUNET_FS_Uri *ksk_uri,
2088 struct GNUNET_FS_Namespace *namespace,
2089 const struct GNUNET_CONTAINER_MetaData *meta,
2092 struct GNUNET_TIME_Absolute expiration,
2093 const char *rootEntry,
2094 GNUNET_FS_PublishContinuation cont,
2099 * Create a namespace with the given name; if one already
2100 * exists, return a handle to the existing namespace.
2102 * @param h handle to the file sharing subsystem
2103 * @param name name to use for the namespace
2104 * @return handle to the namespace, NULL on error
2106 struct GNUNET_FS_Namespace *
2107 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2112 * Delete a namespace handle. Can be used for a clean shutdown (free
2113 * memory) or also to freeze the namespace to prevent further
2114 * insertions by anyone.
2116 * @param namespace handle to the namespace that should be deleted / freed
2117 * @param freeze prevents future insertions; creating a namespace
2118 * with the same name again will create a fresh namespace instead
2120 * @return GNUNET_OK on success, GNUNET_SYSERR on error
2123 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2128 * Callback with information about local (!) namespaces.
2129 * Contains the names of the local namespace and the global
2132 * @param cls closure
2133 * @param name human-readable identifier of the namespace
2134 * @param id hash identifier for the namespace
2136 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2138 const GNUNET_HashCode *id);
2142 * Build a list of all available local (!) namespaces The returned
2143 * names are only the nicknames since we only iterate over the local
2146 * @param h handle to the file sharing subsystem
2147 * @param cb function to call on each known namespace
2148 * @param cb_cls closure for cb
2151 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2152 GNUNET_FS_NamespaceInfoProcessor cb,
2157 * Function called on updateable identifiers.
2159 * @param cls closure
2160 * @param last_id last identifier
2161 * @param last_uri uri used for the content published under the last_id
2162 * @param last_meta metadata associated with last_uri
2163 * @param next_id identifier that should be used for updates
2166 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2167 const char *last_id,
2168 const struct GNUNET_FS_Uri *last_uri,
2169 const struct GNUNET_CONTAINER_MetaData *last_meta,
2170 const char *next_id);
2174 * List all of the identifiers in the namespace for
2175 * which we could produce an update.
2177 * @param namespace namespace to inspect for updateable content
2178 * @param ip function to call on each updateable identifier
2179 * @param ip_cls closure for ip
2182 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2183 GNUNET_FS_IdentifierProcessor ip,
2188 * Options for searching. Compatible options
2189 * can be OR'ed together.
2191 enum GNUNET_FS_SearchOptions
2194 * No options (use defaults for everything).
2196 GNUNET_FS_SEARCH_OPTION_NONE = 0,
2199 * Only search the local host, do not search remote systems (no P2P)
2201 GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2207 * Start search for content.
2209 * @param h handle to the file sharing subsystem
2210 * @param uri specifies the search parameters; can be
2211 * a KSK URI or an SKS URI.
2212 * @param anonymity desired level of anonymity
2213 * @param options options for the search
2214 * @param cctx initial value for the client context
2215 * @return context that can be used to control the search
2217 struct GNUNET_FS_SearchContext *
2218 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2219 const struct GNUNET_FS_Uri *uri,
2221 enum GNUNET_FS_SearchOptions options,
2228 * @param sc context for the search that should be paused
2231 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2235 * Continue paused search.
2237 * @param sc context for the search that should be resumed
2240 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2244 * Stop search for content.
2246 * @param sc context for the search that should be stopped
2249 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2255 * Options for downloading. Compatible options
2256 * can be OR'ed together.
2258 enum GNUNET_FS_DownloadOptions
2261 * No options (use defaults for everything).
2263 GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2266 * Only download from the local host, do not access remote systems (no P2P)
2268 GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2271 * Do a recursive download (that is, automatically trigger the
2272 * download of files in directories).
2274 GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2277 * Do not append temporary data to
2278 * the target file (for the IBlocks).
2280 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2283 * Internal option used to flag this download as a 'probe' for a
2284 * search result. Impacts the priority with which the download is
2285 * run and causes signalling callbacks to be done differently.
2286 * Also, probe downloads are not serialized on suspension. Normal
2287 * clients should not use this!
2289 GNUNET_FS_DOWNLOAD_IS_PROBE = (1<<31)
2296 * Download parts of a file. Note that this will store
2297 * the blocks at the respective offset in the given file. Also, the
2298 * download is still using the blocking of the underlying FS
2299 * encoding. As a result, the download may *write* outside of the
2300 * given boundaries (if offset and length do not match the 32k FS
2301 * block boundaries). <p>
2303 * The given range can be used to focus a download towards a
2304 * particular portion of the file (optimization), not to strictly
2305 * limit the download to exactly those bytes.
2307 * @param h handle to the file sharing subsystem
2308 * @param uri the URI of the file (determines what to download); CHK or LOC URI
2309 * @param meta known metadata for the file (can be NULL)
2310 * @param filename where to store the file, maybe NULL (then no file is
2311 * created on disk and data must be grabbed from the callbacks)
2312 * @param tempname where to store temporary file data, not used if filename is non-NULL;
2313 * can be NULL (in which case we will pick a name if needed); the temporary file
2314 * may already exist, in which case we will try to use the data that is there and
2315 * if it is not what is desired, will overwrite it
2316 * @param offset at what offset should we start the download (typically 0)
2317 * @param length how many bytes should be downloaded starting at offset
2318 * @param anonymity anonymity level to use for the download
2319 * @param options various download options
2320 * @param cctx initial value for the client context for this download
2321 * @param parent parent download to associate this download with (use NULL
2322 * for top-level downloads; useful for manually-triggered recursive downloads)
2323 * @return context that can be used to control this download
2325 struct GNUNET_FS_DownloadContext *
2326 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2327 const struct GNUNET_FS_Uri *uri,
2328 const struct GNUNET_CONTAINER_MetaData *meta,
2329 const char *filename,
2330 const char *tempname,
2334 enum GNUNET_FS_DownloadOptions options,
2336 struct GNUNET_FS_DownloadContext *parent);
2340 * Stop a download (aborts if download is incomplete).
2342 * @param dc handle for the download
2343 * @param do_delete delete files of incomplete downloads
2346 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2351 * Initialize collection.
2353 * @param h handle to the file sharing subsystem
2354 * @param namespace namespace to use for the collection
2355 * @return GNUNET_OK on success, GNUNET_SYSERR if another
2356 * namespace is already set for our collection
2359 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2360 struct GNUNET_FS_Namespace *namespace);
2366 * @param h handle to the file sharing subsystem
2367 * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2370 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2374 * Are we using a collection?
2376 * @param h handle to the file sharing subsystem
2377 * @return NULL if there is no collection,
2379 struct GNUNET_FS_Namespace *
2380 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2384 * Publish an update of the current collection information to the
2385 * network now. The function has no effect if the collection has not
2386 * changed since the last publication. If we are currently not
2387 * collecting, this function does nothing.
2389 * @param h handle to the file sharing subsystem
2391 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2395 * If we are currently building a collection, publish the given file
2396 * information in that collection. If we are currently not
2397 * collecting, this function does nothing.
2399 * @param h handle to the file sharing subsystem
2400 * @param uri uri to add to the collection
2401 * @param meta metadata for the uri
2403 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2404 const struct GNUNET_FS_Uri *uri,
2405 const struct GNUNET_CONTAINER_MetaData *meta);
2411 /* ******************** Directory API *********************** */
2414 #define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory"
2415 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2416 #define GNUNET_FS_DIRECTORY_EXT ".gnd"
2419 * Does the meta-data claim that this is a directory?
2420 * Checks if the mime-type is that of a GNUnet directory.
2422 * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2423 * we have no mime-type information (treat as 'GNUNET_NO')
2426 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2430 * Set the MIMETYPE information for the given
2431 * metadata to "application/gnunet-directory".
2433 * @param md metadata to add mimetype to
2436 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2440 * Suggest a filename based on given metadata.
2442 * @param md given meta data
2443 * @return NULL if meta data is useless for suggesting a filename
2446 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData *md);
2450 * Function used to process entries in a directory.
2452 * @param cls closure
2453 * @param filename name of the file in the directory
2454 * @param uri URI of the file
2455 * @param metadata metadata for the file; metadata for
2456 * the directory if everything else is NULL/zero
2457 * @param length length of the available data for the file
2458 * (of type size_t since data must certainly fit
2459 * into memory; if files are larger than size_t
2460 * permits, then they will certainly not be
2461 * embedded with the directory itself).
2462 * @param data data available for the file (length bytes)
2464 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2465 const char *filename,
2466 const struct GNUNET_FS_Uri *uri,
2467 const struct GNUNET_CONTAINER_MetaData *meta,
2473 * Iterate over all entries in a directory. Note that directories
2474 * are structured such that it is possible to iterate over the
2475 * individual blocks as well as over the entire directory. Thus
2476 * a client can call this function on the buffer in the
2477 * GNUNET_FS_ProgressCallback. Also, directories can optionally
2478 * include the contents of (small) files embedded in the directory
2479 * itself; for those files, the processor may be given the
2480 * contents of the file directly by this function.
2482 * @param size number of bytes in data
2483 * @param data pointer to the beginning of the directory
2484 * @param offset offset of data in the directory
2485 * @param dep function to call on each entry
2486 * @param dep_cls closure for dep
2489 GNUNET_FS_directory_list_contents (size_t size,
2492 GNUNET_FS_DirectoryEntryProcessor dep,
2497 * Opaque handle to a directory builder.
2499 struct GNUNET_FS_DirectoryBuilder;
2502 * Create a directory builder.
2504 * @param mdir metadata for the directory
2506 struct GNUNET_FS_DirectoryBuilder *
2507 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2511 * Add an entry to a directory.
2513 * @param bld directory to extend
2514 * @param uri uri of the entry (must not be a KSK)
2515 * @param md metadata of the entry
2516 * @param data raw data of the entry, can be NULL, otherwise
2517 * data must point to exactly the number of bytes specified
2521 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2522 const struct GNUNET_FS_Uri *uri,
2523 const struct GNUNET_CONTAINER_MetaData *md,
2528 * Finish building the directory. Frees the
2529 * builder context and returns the directory
2532 * @param bld directory to finish
2533 * @param rsize set to the number of bytes needed
2534 * @param rdata set to the encoded directory
2535 * @return GNUNET_OK on success
2538 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2543 #if 0 /* keep Emacsens' auto-indent happy */