Clean up and renaming
[oweals/gnunet.git] / src / include / gnunet_fs_service.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2004--2013 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 /**
21  * @author Christian Grothoff
22  *
23  * @file
24  * API for file sharing via GNUnet
25  *
26  * @defgroup fs FS service
27  * File sharing
28  *
29  * @see [Documentation](https://gnunet.org/file-sharing-service)
30  *
31  * @{
32  */
33 #ifndef GNUNET_FS_LIB_H
34 #define GNUNET_FS_LIB_H
35
36 #include "gnunet_util_lib.h"
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0                           /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45
46 /**
47  * Version number of the implementation.
48  * History:
49  *
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
66  */
67 #define GNUNET_FS_VERSION 0x00090300
68
69
70 /* ******************** URI API *********************** */
71
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/"
77
78
79 /**
80  * How often do we signal applications that a probe for a particular
81  * search result is running? (used to visualize probes).
82  */
83 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply ( \
84     GNUNET_TIME_UNIT_MILLISECONDS, 250)
85
86 /**
87  * A Universal Resource Identifier (URI), opaque.
88  */
89 struct GNUNET_FS_Uri;
90
91
92 /**
93  * Iterator over keywords
94  *
95  * @param cls closure
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
99  */
100 typedef int
101 (*GNUNET_FS_KeywordIterator) (void *cls,
102                               const char *keyword,
103                               int is_mandatory);
104
105
106
107 /**
108  * Get a unique key from a URI.  This is for putting URIs
109  * into HashMaps.  The key may change between FS implementations.
110  *
111  * @param uri uri to convert to a unique key
112  * @param key wherer to store the unique key
113  * @return #GNUNET_OK on success
114  */
115 int
116 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
117                       struct GNUNET_HashCode *key);
118
119
120 /**
121  * Convert a URI to a UTF-8 String.
122  *
123  * @param uri uri to convert to a string
124  * @return the UTF-8 string
125  */
126 char *
127 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
128
129
130 /**
131  * Convert keyword URI to a human readable format
132  * (i.e. the search query that was used in the first place)
133  *
134  * @param uri ksk uri to convert to a string
135  * @return string with the keywords
136  */
137 char *
138 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
139
140
141 /**
142  * Add the given keyword to the set of keywords represented by the URI.
143  * Does nothing if the keyword is already present.
144  *
145  * @param uri ksk uri to modify
146  * @param keyword keyword to add
147  * @param is_mandatory is this keyword mandatory?
148  */
149 void
150 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
151                                const char *keyword,
152                                int is_mandatory);
153
154
155 /**
156  * Remove the given keyword from the set of keywords represented by the URI.
157  * Does nothing if the keyword is not present.
158  *
159  * @param uri ksk uri to modify
160  * @param keyword keyword to add
161  */
162 void
163 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
164                                   const char *keyword);
165
166
167 /**
168  * Convert a UTF-8 String to a URI.
169  *
170  * @param uri string to parse
171  * @param emsg where to store the parser error message (if any)
172  * @return NULL on error
173  */
174 struct GNUNET_FS_Uri *
175 GNUNET_FS_uri_parse (const char *uri,
176                      char **emsg);
177
178
179 /**
180  * Free URI.
181  *
182  * @param uri uri to free
183  */
184 void
185 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
186
187
188 /**
189  * How many keywords are ANDed in this keyword URI?
190  *
191  * @param uri ksk uri to get the number of keywords from
192  * @return 0 if this is not a keyword URI
193  */
194 unsigned int
195 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
196
197
198 /**
199  * Iterate over all keywords in this keyword URI.
200  *
201  * @param uri ksk uri to get the keywords from
202  * @param iterator function to call on each keyword
203  * @param iterator_cls closure for @a iterator
204  * @return -1 if this is not a keyword URI, otherwise number of
205  *   keywords iterated over until iterator aborted
206  */
207 int
208 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
209                                 GNUNET_FS_KeywordIterator iterator,
210                                 void *iterator_cls);
211
212
213 /**
214  * Obtain the identity of the peer offering the data
215  *
216  * @param uri the location URI to inspect
217  * @param peer where to store the identify of the peer (presumably) offering the content
218  * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
219  */
220 int
221 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
222                                      struct GNUNET_PeerIdentity *peer);
223
224
225 /**
226  * Obtain the URI of the content itself.
227  *
228  * @param uri location URI to get the content URI from
229  * @return NULL if argument is not a location URI
230  */
231 struct GNUNET_FS_Uri *
232 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
233
234
235 /**
236  * Obtain the expiration of the LOC URI.
237  *
238  * @param uri location URI to get the expiration from
239  * @return expiration time of the URI
240  */
241 struct GNUNET_TIME_Absolute
242 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
243
244
245 /**
246  * Construct a location URI (this peer will be used for the location).
247  * This function should only be called from within gnunet-service-fs,
248  * as it requires the peer's private key which is generally unavailable
249  * to processes directly under the user's control.  However, for
250  * testing and as it logically fits under URIs, it is in this API.
251  *
252  * @param base_uri content offered by the sender
253  * @param sign_key private key of the peer
254  * @param expiration_time how long will the content be offered?
255  * @return the location URI, NULL on error
256  */
257 struct GNUNET_FS_Uri *
258 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
259                           const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
260                           struct GNUNET_TIME_Absolute expiration_time);
261
262
263 /**
264  * Merge the sets of keywords from two KSK URIs.
265  *
266  * @param u1 first uri
267  * @param u2 second uri
268  * @return merged URI, NULL on error
269  */
270 struct GNUNET_FS_Uri *
271 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
272                          const struct GNUNET_FS_Uri *u2);
273
274
275 /**
276  * Duplicate URI.
277  *
278  * @param uri the URI to duplicate
279  * @return copy of the URI
280  */
281 struct GNUNET_FS_Uri *
282 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
283
284
285 /**
286  * Create an FS URI from a single user-supplied string of keywords.
287  * The string is broken up at spaces into individual keywords.
288  * Keywords that start with "+" are mandatory.  Double-quotes can
289  * be used to prevent breaking up strings at spaces (and also
290  * to specify non-mandatory keywords starting with "+").
291  *
292  * Keywords must contain a balanced number of double quotes and
293  * double quotes can not be used in the actual keywords (for
294  * example, the string '""foo bar""' will be turned into two
295  * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
296  *
297  * @param keywords the keyword string
298  * @param emsg where to store an error message
299  * @return an FS URI for the given keywords, NULL
300  *  if keywords is not legal (i.e. empty).
301  */
302 struct GNUNET_FS_Uri *
303 GNUNET_FS_uri_ksk_create (const char *keywords,
304                           char **emsg);
305
306
307 /**
308  * Create an FS URI from a user-supplied command line of keywords.
309  * Arguments should start with "+" to indicate mandatory
310  * keywords.
311  *
312  * @param argc number of keywords
313  * @param argv keywords (double quotes are not required for
314  *             keywords containing spaces; however, double
315  *             quotes are required for keywords starting with
316  *             "+"); there is no mechanism for having double
317  *             quotes in the actual keywords (if the user
318  *             did specifically specify double quotes, the
319  *             caller should convert each double quote
320  *             into two single quotes).
321  * @return an FS URI for the given keywords, NULL
322  *  if keywords is not legal (i.e. empty).
323  */
324 struct GNUNET_FS_Uri *
325 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
326                                     const char **argv);
327
328
329 /**
330  * Test if two URIs are equal.
331  *
332  * @param u1 one of the URIs
333  * @param u2 the other URI
334  * @return #GNUNET_YES if the URIs are equal
335  */
336 int
337 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
338                           const struct GNUNET_FS_Uri *u2);
339
340
341 /**
342  * Is this a namespace URI?
343  *
344  * @param uri the uri to check
345  * @return #GNUNET_YES if this is an SKS uri
346  */
347 int
348 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
349
350
351 /**
352  * Create an SKS URI from a namespace ID and an identifier.
353  *
354  * @param ns pseudonym to use
355  * @param id identifier
356  * @return an FS URI for the given namespace and identifier
357  */
358 struct GNUNET_FS_Uri *
359 GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
360                           const char *id);
361
362
363 /**
364  * Get the public key of a namespace from the given
365  * namespace URI.
366  *
367  * @param uri the uri to get the namespace ID from
368  * @param pseudonym where to store the public key of the namespace
369  * @return #GNUNET_OK on success
370  */
371 int
372 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
373                                  struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym);
374
375
376 /**
377  * Get the content identifier of an SKS URI.
378  *
379  * @param uri the sks uri
380  * @return NULL on error (not a valid SKS URI)
381  */
382 char *
383 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
384
385
386 /**
387  * Is this a keyword URI?
388  *
389  * @param uri the uri
390  * @return #GNUNET_YES if this is a KSK uri
391  */
392 int
393 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
394
395
396 /**
397  * Is this a file (or directory) URI?
398  *
399  * @param uri the uri to check
400  * @return #GNUNET_YES if this is a CHK uri
401  */
402 int
403 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
404
405
406 /**
407  * What is the size of the file that this URI
408  * refers to?
409  *
410  * @param uri the CHK (or LOC) URI to inspect
411  * @return size of the file as specified in the CHK URI
412  */
413 uint64_t
414 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
415
416
417 /**
418  * Is this a location URI?
419  *
420  * @param uri the uri to check
421  * @return #GNUNET_YES if this is a LOC uri
422  */
423 int
424 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
425
426
427 /**
428  * Construct a keyword-URI from meta-data (take all entries
429  * in the meta-data and construct one large keyword URI
430  * that lists all keywords that can be found in the meta-data).
431  *
432  * @param md metadata to use
433  * @return NULL on error, otherwise a KSK URI
434  */
435 struct GNUNET_FS_Uri *
436 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
437                                          *md);
438
439
440 /* ******************** command-line option parsing API *********************** */
441
442 /**
443  * Allow user to specify keywords.
444  *
445  * @param shortName short name of the option
446  * @param name long name of the option
447  * @param argumentHelp help text for the option argument
448  * @param description long help text for the option
449  * @param[out] topKeywords set to the desired value
450  */
451 struct GNUNET_GETOPT_CommandLineOption
452 GNUNET_FS_GETOPT_KEYWORDS (char shortName,
453                            const char *name,
454                            const char *argumentHelp,
455                            const char *description,
456                            struct GNUNET_FS_Uri **topKeywords);
457
458 /**
459  * Allow user to specify metadata.
460  *
461  * @param shortName short name of the option
462  * @param name long name of the option
463  * @param argumentHelp help text for the option argument
464  * @param description long help text for the option
465  * @param[out] metadata set to the desired value
466  */
467 struct GNUNET_GETOPT_CommandLineOption
468 GNUNET_FS_GETOPT_METADATA (char shortName,
469                            const char *name,
470                            const char *argumentHelp,
471                            const char *description,
472                            struct GNUNET_CONTAINER_MetaData **meta);
473
474 /**
475  * Command-line option parser function that allows the user to specify
476  * one or more '-m' options with metadata.  Each specified entry of
477  * the form "type=value" will be added to the metadata.  A pointer to
478  * the metadata must be passed as the "scls" argument.
479  *
480  * @param ctx command line processor context
481  * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **`
482  * @param option name of the option (typically 'k')
483  * @param value command line argument given
484  * @return #GNUNET_OK on success
485  */
486 int
487 GNUNET_FS_getopt_set_metadata (struct
488                                GNUNET_GETOPT_CommandLineProcessorContext *ctx,
489                                void *scls,
490                                const char *option,
491                                const char *value);
492
493
494
495 /* ************************* sharing API ***************** */
496
497
498 /**
499  * Possible status codes used in the callback for the
500  * various file-sharing operations.  On each file (or search),
501  * the callback is guaranteed to be called once with "START"
502  * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
503  * are optional and depend on the circumstances; parent operations
504  * will be STARTED before child-operations and STOPPED after
505  * their respective child-operations.  START and STOP signals
506  * are typically generated either due to explicit client requests
507  * or because of suspend/resume operations.
508  */
509 enum GNUNET_FS_Status
510 {
511   /**
512    * Notification that we have started to publish a file structure.
513    */
514   GNUNET_FS_STATUS_PUBLISH_START = 0,
515
516   /**
517    * Notification that we have resumed sharing a file structure.
518    */
519   GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
520
521   /**
522    * Notification that we have suspended sharing a file structure.
523    */
524   GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
525
526   /**
527    * Notification that we are making progress sharing a file structure.
528    */
529   GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
530
531   /**
532    * Notification that an error was encountered  sharing a file structure.
533    * The application will continue to receive resume/suspend events for
534    * this structure until "GNUNET_FS_publish_stop" is called.
535    */
536   GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
537
538   /**
539    * Notification that we completed sharing a file structure.
540    * The application will continue to receive resume/suspend events for
541    * this structure until "GNUNET_FS_publish_stop" is called.
542    */
543   GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
544
545   /**
546    * Notification that we have stopped
547    * the process of uploading a file structure; no
548    * futher events will be generated for this action.
549    */
550   GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
551
552   /**
553    * Notification that we have started this download.
554    */
555   GNUNET_FS_STATUS_DOWNLOAD_START = 7,
556
557   /**
558    * Notification that this download is being resumed.
559    */
560   GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
561
562   /**
563    * Notification that this download was suspended.
564    */
565   GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
566
567   /**
568    * Notification about progress with this download.
569    */
570   GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
571
572   /**
573    * Notification that this download encountered an error.
574    */
575   GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
576
577   /**
578    * Notification that this download completed.  Note that for
579    * directories, completion does not imply completion of all files in
580    * the directory.
581    */
582   GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
583
584   /**
585    * Notification that this download was stopped
586    * (final event with respect to this action).
587    */
588   GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
589
590   /**
591    * Notification that this download is now actively being
592    * pursued (as opposed to waiting in the queue).
593    */
594   GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
595
596   /**
597    * Notification that this download is no longer actively
598    * being pursued (back in the queue).
599    */
600   GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
601
602   /**
603    * Notification that this download is no longer part of a
604    * recursive download or search but now a 'stand-alone'
605    * download (and may thus need to be moved in the GUI
606    * into a different category).
607    */
608   GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
609
610   /**
611    * First event generated when a client requests
612    * a search to begin or when a namespace result
613    * automatically triggers the search for updates.
614    */
615   GNUNET_FS_STATUS_SEARCH_START = 17,
616
617   /**
618    * Last event when a search is being resumed;
619    * note that "GNUNET_FS_SEARCH_START" will not
620    * be generated in this case.
621    */
622   GNUNET_FS_STATUS_SEARCH_RESUME = 18,
623
624   /**
625    * Event generated for each search result
626    * when the respective search is resumed.
627    */
628   GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
629
630   /**
631    * Last event when a search is being suspended;
632    * note that "GNUNET_FS_SEARCH_STOPPED" will not
633    * be generated in this case.
634    */
635   GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
636
637   /**
638    * This search has yielded a result.
639    */
640   GNUNET_FS_STATUS_SEARCH_RESULT = 21,
641
642   /**
643    * We have discovered a new namespace.
644    */
645   GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
646
647   /**
648    * We have additional data about the quality
649    * or availability of a search result.
650    */
651   GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
652
653   /**
654    * Signals a problem with this search.
655    */
656   GNUNET_FS_STATUS_SEARCH_ERROR = 24,
657
658   /**
659    * Signals that this search was paused.
660    */
661   GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
662
663   /**
664    * Signals that this search was continued (unpaused).
665    */
666   GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
667
668   /**
669    * Event generated for each search result
670    * when the respective search is stopped.
671    */
672   GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
673
674   /**
675    * Event generated for each search result
676    * when the respective search is suspended.
677    */
678   GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
679
680   /**
681    * Last message from a search; this signals
682    * that there will be no further events associated
683    * with this search.
684    */
685   GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
686
687   /**
688    * Notification that we started to unindex a file.
689    */
690   GNUNET_FS_STATUS_UNINDEX_START = 30,
691
692   /**
693    * Notification that we resumed unindexing of a file.
694    */
695   GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
696
697   /**
698    * Notification that we suspended unindexing a file.
699    */
700   GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
701
702   /**
703    * Notification that we made progress unindexing a file.
704    */
705   GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
706
707   /**
708    * Notification that we encountered an error unindexing
709    * a file.
710    */
711   GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
712
713   /**
714    * Notification that the unindexing of this file
715    * was completed.
716    */
717   GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
718
719   /**
720    * Notification that the unindexing of this file
721    * was stopped (final event for this action).
722    */
723   GNUNET_FS_STATUS_UNINDEX_STOPPED = 36,
724
725   /**
726    * Notification that we are making progress sharing a directory.
727    */
728   GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY = 37
729 };
730
731
732 /**
733  * Handle for controlling an upload.
734  */
735 struct GNUNET_FS_PublishContext;
736
737
738 /**
739  * Handle for controlling an unindexing operation.
740  */
741 struct GNUNET_FS_UnindexContext;
742
743
744 /**
745  * Handle for controlling a search.
746  */
747 struct GNUNET_FS_SearchContext;
748
749
750 /**
751  * Result from a search.  Opaque handle to refer to the search
752  * (typically used when starting a download associated with the search
753  * result).
754  */
755 struct GNUNET_FS_SearchResult;
756
757
758 /**
759  * Context for controlling a download.
760  */
761 struct GNUNET_FS_DownloadContext;
762
763
764 /**
765  * Handle for detail information about a file that is being publishd.
766  * Specifies metadata, keywords, how to get the contents of the file
767  * (i.e. data-buffer in memory, filename on disk) and other options.
768  */
769 struct GNUNET_FS_FileInformation;
770
771
772 /**
773  * Argument given to the progress callback with
774  * information about what is going on.
775  */
776 struct GNUNET_FS_ProgressInfo
777 {
778   /**
779    * Values that depend on the event type.
780    */
781   union
782   {
783     /**
784      * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
785      */
786     struct
787     {
788       /**
789        * Context for controlling the upload.
790        */
791       struct GNUNET_FS_PublishContext *pc;
792
793       /**
794        * Information about the file that is being publishd.
795        */
796       const struct GNUNET_FS_FileInformation *fi;
797
798       /**
799        * Client context pointer (set the last time by the client for
800        * this operation; initially NULL on START/RESUME events).
801        */
802       void *cctx;
803
804       /**
805        * Client context pointer for the parent operation
806        * (if this is a file in a directory or a subdirectory).
807        */
808       void *pctx;
809
810       /**
811        * Name of the file being published; can be NULL.
812        */
813       const char *filename;
814
815       /**
816        * How large is the file overall?  For directories,
817        * this is only the size of the directory itself,
818        * not of the other files contained within the
819        * directory.
820        */
821       uint64_t size;
822
823       /**
824        * At what time do we expect to finish the upload?
825        * (will be a value in the past for completed
826        * uploads).
827        */
828       struct GNUNET_TIME_Relative eta;
829
830       /**
831        * How long has this upload been actively running
832        * (excludes times where the upload was suspended).
833        */
834       struct GNUNET_TIME_Relative duration;
835
836       /**
837        * How many bytes have we completed?
838        */
839       uint64_t completed;
840
841       /**
842        * What anonymity level is used for this upload?
843        */
844       uint32_t anonymity;
845
846       /**
847        * Additional values for specific events.
848        */
849       union
850       {
851         /**
852          * These values are only valid for
853          * #GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
854          */
855         struct
856         {
857           /**
858            * Data block we just published.
859            */
860           const void *data;
861
862           /**
863            * At what offset in the file is "data"?
864            */
865           uint64_t offset;
866
867           /**
868            * Length of the data block.
869            */
870           uint64_t data_len;
871
872           /**
873            * Depth of the given block in the tree;
874            * 0 would be the lowest level (DBLOCKs).
875            */
876           unsigned int depth;
877         } progress;
878
879         /**
880          * These values are only valid for
881          * #GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY events.
882          */
883         struct
884         {
885           /**
886            * How far are we along in the overall directory?
887            */
888           uint64_t completed;
889
890           /**
891            * How big do we estimate the entire directory to be?
892            */
893           uint64_t total;
894
895           /**
896            * At what time do we expect to finish the upload of the
897            * CONTENTS of the directory. (The direcory itself will take
898            * extra time, indicated with the "eta" member at the
899            * "publish"-level of this struct.)
900            */
901           struct GNUNET_TIME_Relative eta;
902         } progress_directory;
903
904         /**
905          * These values are only valid for
906          * #GNUNET_FS_STATUS_PUBLISH_RESUME events.
907          */
908         struct
909         {
910           /**
911            * Error message, NULL if no error was encountered so far.
912            */
913           const char *message;
914
915           /**
916            * URI of the file (if the download had been completed)
917            */
918           const struct GNUNET_FS_Uri *chk_uri;
919
920           /**
921            * SKS URI of the file (if the download had been completed)
922            */
923           const struct GNUNET_FS_Uri *sks_uri;
924         } resume;
925
926         /**
927          * These values are only valid for
928          * #GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
929          */
930         struct
931         {
932           /**
933            * CHK URI of the file.
934            */
935           const struct GNUNET_FS_Uri *chk_uri;
936
937           /**
938            * SKS URI of the file (if the download had been completed)
939            */
940           const struct GNUNET_FS_Uri *sks_uri;
941         } completed;
942
943         /**
944          * These values are only valid for
945          * #GNUNET_FS_STATUS_PUBLISH_ERROR events.
946          */
947         struct
948         {
949           /**
950            * Error message, never NULL.
951            */
952           const char *message;
953         } error;
954       } specifics;
955     } publish;
956
957
958     /**
959      * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
960      */
961     struct
962     {
963       /**
964        * Context for controlling the download.
965        */
966       struct GNUNET_FS_DownloadContext *dc;
967
968       /**
969        * Client context pointer (set the last time
970        * by the client for this operation; initially
971        * NULL on START/RESUME events).
972        */
973       void *cctx;
974
975       /**
976        * Client context pointer for the parent operation
977        * (if this is a file in a directory or a subdirectory).
978        */
979       void *pctx;
980
981       /**
982        * Client context pointer for the associated search operation
983        * (specifically, context pointer for the specific search
984        * result, not the overall search); only set if this
985        * download was started from a search result.
986        */
987       void *sctx;
988
989       /**
990        * URI used for this download.
991        */
992       const struct GNUNET_FS_Uri *uri;
993
994       /**
995        * Name of the file that we are downloading.
996        */
997       const char *filename;
998
999       /**
1000        * How large is the download overall?  This
1001        * is NOT necessarily the size from the
1002        * URI since we may be doing a partial download.
1003        */
1004       uint64_t size;
1005
1006       /**
1007        * At what time do we expect to finish the download?
1008        * (will be a value in the past for completed
1009        * uploads).
1010        */
1011       struct GNUNET_TIME_Relative eta;
1012
1013       /**
1014        * How long has this download been active?
1015        */
1016       struct GNUNET_TIME_Relative duration;
1017
1018       /**
1019        * How many bytes have we completed?
1020        */
1021       uint64_t completed;
1022
1023       /**
1024        * What anonymity level is used for this download?
1025        */
1026       uint32_t anonymity;
1027
1028       /**
1029        * Is the download currently active.
1030        */
1031       int is_active;
1032
1033       /**
1034        * Additional values for specific events.
1035        */
1036       union
1037       {
1038         /**
1039          * These values are only valid for
1040          * #GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1041          */
1042         struct
1043         {
1044           /**
1045            * Data block we just obtained, can be NULL (even if
1046            * data_len > 0) if we found the entire block 'intact' on
1047            * disk.  In this case, it is also possible for 'data_len'
1048            * to be larger than an individual (32k) block.
1049            */
1050           const void *data;
1051
1052           /**
1053            * At what offset in the file is "data"?
1054            */
1055           uint64_t offset;
1056
1057           /**
1058            * Length of the data block.
1059            */
1060           uint64_t data_len;
1061
1062           /**
1063            * How much time passed between us asking for this block and
1064            * actually getting it? #GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1065            */
1066           struct GNUNET_TIME_Relative block_download_duration;
1067
1068           /**
1069            * Depth of the given block in the tree;
1070            * 0 would be the lowest level (DBLOCKS).
1071            */
1072           unsigned int depth;
1073
1074           /**
1075            * How much respect did we offer for downloading this block? (estimate,
1076            * because we might have the same request pending for multiple clients,
1077            * and of course because a transmission may have failed at a lower
1078            * layer).
1079            */
1080           uint32_t respect_offered;
1081
1082           /**
1083            * How often did we transmit the request? (estimate,
1084            * because we might have the same request pending for multiple clients,
1085            * and of course because a transmission may have failed at a lower
1086            * layer).
1087            */
1088           uint32_t num_transmissions;
1089         } progress;
1090
1091         /**
1092          * These values are only valid for
1093          * #GNUNET_FS_STATUS_DOWNLOAD_START events.
1094          */
1095         struct
1096         {
1097           /**
1098            * Known metadata for the download.
1099            */
1100           const struct GNUNET_CONTAINER_MetaData *meta;
1101         } start;
1102
1103         /**
1104          * These values are only valid for
1105          * #GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1106          */
1107         struct
1108         {
1109           /**
1110            * Known metadata for the download.
1111            */
1112           const struct GNUNET_CONTAINER_MetaData *meta;
1113
1114           /**
1115            * Error message, NULL if we have not encountered any error yet.
1116            */
1117           const char *message;
1118         } resume;
1119
1120         /**
1121          * These values are only valid for
1122          * #GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1123          */
1124         struct
1125         {
1126           /**
1127            * Error message.
1128            */
1129           const char *message;
1130         } error;
1131       } specifics;
1132     } download;
1133
1134     /**
1135      * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1136      */
1137     struct
1138     {
1139       /**
1140        * Context for controlling the search, NULL for
1141        * searches that were not explicitly triggered
1142        * by the client (i.e., searches for updates in
1143        * namespaces).
1144        */
1145       struct GNUNET_FS_SearchContext *sc;
1146
1147       /**
1148        * Client context pointer (set the last time by the client for
1149        * this operation; initially NULL on START/RESUME events).  Note
1150        * that this value can only be set on START/RESUME; returning
1151        * non-NULL on RESULT/RESUME_RESULT will actually update the
1152        * private context for "UPDATE" events.
1153        */
1154       void *cctx;
1155
1156       /**
1157        * Client parent-context pointer; NULL for top-level searches,
1158        * refers to the client context of the associated search result
1159        * for automatically triggered searches for updates in
1160        * namespaces.  In this case, 'presult' refers to that search
1161        * result.
1162        */
1163       void *pctx;
1164
1165       /**
1166        * What query is used for this search
1167        * (list of keywords or SKS identifier).
1168        */
1169       const struct GNUNET_FS_Uri *query;
1170
1171       /**
1172        * How long has this search been actively running
1173        * (excludes times where the search was paused or
1174        * suspended).
1175        */
1176       struct GNUNET_TIME_Relative duration;
1177
1178       /**
1179        * What anonymity level is used for this search?
1180        */
1181       uint32_t anonymity;
1182
1183       /**
1184        * Additional values for specific events.
1185        */
1186       union
1187       {
1188         /**
1189          * These values are only valid for
1190          * #GNUNET_FS_STATUS_SEARCH_RESULT events.
1191          */
1192         struct
1193         {
1194           /**
1195            * Metadata for the search result.
1196            */
1197           const struct GNUNET_CONTAINER_MetaData *meta;
1198
1199           /**
1200            * URI for the search result.
1201            */
1202           const struct GNUNET_FS_Uri *uri;
1203
1204           /**
1205            * Handle to the result (for starting downloads).
1206            */
1207           struct GNUNET_FS_SearchResult *result;
1208
1209           /**
1210            * Applicability rank (the larger, the better the result
1211            * fits the search criteria).
1212            */
1213           uint32_t applicability_rank;
1214         } result;
1215
1216         /**
1217          * These values are only valid for
1218          * #GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1219          */
1220         struct
1221         {
1222           /**
1223            * Metadata for the search result.
1224            */
1225           const struct GNUNET_CONTAINER_MetaData *meta;
1226
1227           /**
1228            * URI for the search result.
1229            */
1230           const struct GNUNET_FS_Uri *uri;
1231
1232           /**
1233            * Handle to the result (for starting downloads).
1234            */
1235           struct GNUNET_FS_SearchResult *result;
1236
1237           /**
1238            * Current availability rank (negative:
1239            * unavailable, positive: available)
1240            */
1241           int32_t availability_rank;
1242
1243           /**
1244            * On how many total queries is the given
1245            * availability_rank based?
1246            */
1247           uint32_t availability_certainty;
1248
1249           /**
1250            * Updated applicability rank (the larger,
1251            * the better the result fits the search
1252            * criteria).
1253            */
1254           uint32_t applicability_rank;
1255         } resume_result;
1256
1257         /**
1258          * These values are only valid for
1259          * #GNUNET_FS_STATUS_SEARCH_UPDATE events.
1260          */
1261         struct
1262         {
1263           /**
1264            * Private context set for for this result
1265            * during the "RESULT" event.
1266            */
1267           void *cctx;
1268
1269           /**
1270            * Metadata for the search result.
1271            */
1272           const struct GNUNET_CONTAINER_MetaData *meta;
1273
1274           /**
1275            * URI for the search result.
1276            */
1277           const struct GNUNET_FS_Uri *uri;
1278
1279           /**
1280            * Current availability rank (negative:
1281            * unavailable, positive: available)
1282            */
1283           int32_t availability_rank;
1284
1285           /**
1286            * On how many total queries is the given
1287            * availability_rank based?
1288            */
1289           uint32_t availability_certainty;
1290
1291           /**
1292            * Updated applicability rank (the larger,
1293            * the better the result fits the search
1294            * criteria).
1295            */
1296           uint32_t applicability_rank;
1297
1298           /**
1299            * How long has the current probe been active?
1300            */
1301           struct GNUNET_TIME_Relative current_probe_time;
1302         } update;
1303
1304         /**
1305          * These values are only valid for
1306          * #GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1307          * These events are automatically triggered for
1308          * each search result before the
1309          * #GNUNET_FS_STATUS_SEARCH_SUSPEND event.  This
1310          * happens primarily to give the client a chance
1311          * to clean up the "cctx" (if needed).
1312          */
1313         struct
1314         {
1315           /**
1316            * Private context set for for this result
1317            * during the "RESULT" event.
1318            */
1319           void *cctx;
1320
1321           /**
1322            * Metadata for the search result.
1323            */
1324           const struct GNUNET_CONTAINER_MetaData *meta;
1325
1326           /**
1327            * URI for the search result.
1328            */
1329           const struct GNUNET_FS_Uri *uri;
1330         } result_suspend;
1331
1332         /**
1333          * These values are only valid for
1334          * #GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1335          * These events are automatically triggered for
1336          * each search result before the
1337          * #GNUNET_FS_STATUS_SEARCH_STOPPED event.  This
1338          * happens primarily to give the client a chance
1339          * to clean up the "cctx" (if needed).
1340          */
1341         struct
1342         {
1343           /**
1344            * Private context set for for this result
1345            * during the "RESULT" event.
1346            */
1347           void *cctx;
1348
1349           /**
1350            * Metadata for the search result.
1351            */
1352           const struct GNUNET_CONTAINER_MetaData *meta;
1353
1354           /**
1355            * URI for the search result.
1356            */
1357           const struct GNUNET_FS_Uri *uri;
1358         } result_stopped;
1359
1360         /**
1361          * These values are only valid for
1362          * #GNUNET_FS_STATUS_SEARCH_RESUME events.
1363          */
1364         struct
1365         {
1366           /**
1367            * Error message, NULL if we have not encountered any error yet.
1368            */
1369           const char *message;
1370
1371           /**
1372            * Is this search currently paused?
1373            */
1374           int is_paused;
1375         } resume;
1376
1377         /**
1378          * These values are only valid for
1379          * #GNUNET_FS_STATUS_SEARCH_ERROR events.
1380          */
1381         struct
1382         {
1383           /**
1384            * Error message.
1385            */
1386           const char *message;
1387         } error;
1388
1389         /**
1390          * Values for #GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE events.
1391          */
1392         struct
1393         {
1394           /**
1395            * Short, human-readable name of the namespace.
1396            */
1397           const char *name;
1398
1399           /**
1400            * Root identifier for the namespace, can be NULL.
1401            */
1402           const char *root;
1403
1404           /**
1405            * Metadata for the namespace.
1406            */
1407           const struct GNUNET_CONTAINER_MetaData *meta;
1408
1409           /**
1410            * Public key of the namespace.
1411            */
1412           struct GNUNET_CRYPTO_EcdsaPublicKey pseudonym;
1413         } ns;
1414       } specifics;
1415     } search;
1416
1417     /**
1418      * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1419      */
1420     struct
1421     {
1422       /**
1423        * Context for controlling the unindexing.
1424        */
1425       struct GNUNET_FS_UnindexContext *uc;
1426
1427       /**
1428        * Client context pointer (set the last time
1429        * by the client for this operation; initially
1430        * NULL on START/RESUME events).
1431        */
1432       void *cctx;
1433
1434       /**
1435        * Name of the file that is being unindexed.
1436        */
1437       const char *filename;
1438
1439       /**
1440        * How large is the file overall?
1441        */
1442       uint64_t size;
1443
1444       /**
1445        * At what time do we expect to finish unindexing?
1446        * (will be a value in the past for completed
1447        * unindexing opeations).
1448        */
1449       struct GNUNET_TIME_Relative eta;
1450
1451       /**
1452        * How long has this upload been actively running
1453        * (excludes times where the upload was suspended).
1454        */
1455       struct GNUNET_TIME_Relative duration;
1456
1457       /**
1458        * How many bytes have we completed?
1459        */
1460       uint64_t completed;
1461
1462       /**
1463        * Additional values for specific events.
1464        */
1465       union
1466       {
1467         /**
1468          * These values are only valid for
1469          * #GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1470          */
1471         struct
1472         {
1473           /**
1474            * Data block we just unindexed.
1475            */
1476           const void *data;
1477
1478           /**
1479            * At what offset in the file is "data"?
1480            */
1481           uint64_t offset;
1482
1483           /**
1484            * Length of the data block.
1485            */
1486           uint64_t data_len;
1487
1488           /**
1489            * Depth of the given block in the tree;
1490            * 0 would be the lowest level (DBLOCKS).
1491            */
1492           unsigned int depth;
1493         } progress;
1494
1495         /**
1496          * These values are only valid for
1497          * #GNUNET_FS_STATUS_UNINDEX_RESUME events.
1498          */
1499         struct
1500         {
1501           /**
1502            * Error message, NULL if we have not encountered any error yet.
1503            */
1504           const char *message;
1505         } resume;
1506
1507         /**
1508          * These values are only valid for
1509          * #GNUNET_FS_STATUS_UNINDEX_ERROR events.
1510          */
1511         struct
1512         {
1513           /**
1514            * Error message.
1515            */
1516           const char *message;
1517         } error;
1518       } specifics;
1519     } unindex;
1520   } value;
1521
1522   /**
1523    * Specific status code (determines the event type).
1524    */
1525   enum GNUNET_FS_Status status;
1526
1527   /**
1528    * File-sharing handle that generated the event.
1529    */
1530   struct GNUNET_FS_Handle *fsh;
1531 };
1532
1533
1534 /**
1535  * Notification of FS to a client about the progress of an
1536  * operation.  Callbacks of this type will be used for uploads,
1537  * downloads and searches.  Some of the arguments depend a bit
1538  * in their meaning on the context in which the callback is used.
1539  *
1540  * @param cls closure
1541  * @param info details about the event, specifying the event type
1542  *        and various bits about the event
1543  * @return client-context (for the next progress call
1544  *         for this operation; should be set to NULL for
1545  *         SUSPEND and STOPPED events).  The value returned
1546  *         will be passed to future callbacks in the respective
1547  *         field in the `struct GNUNET_FS_ProgressInfo`.
1548  */
1549 typedef void *
1550 (*GNUNET_FS_ProgressCallback) (void *cls,
1551                                const struct GNUNET_FS_ProgressInfo *info);
1552
1553
1554 /**
1555  * General (global) option flags for file-sharing.
1556  */
1557 enum GNUNET_FS_Flags
1558 {
1559   /**
1560    * No special flags set.
1561    */
1562   GNUNET_FS_FLAGS_NONE = 0,
1563
1564   /**
1565    * Is persistence of operations desired?
1566    * (will create SUSPEND/RESUME events).
1567    */
1568   GNUNET_FS_FLAGS_PERSISTENCE = 1,
1569
1570   /**
1571    * Should we automatically trigger probes for search results
1572    * to determine availability?
1573    * (will create #GNUNET_FS_STATUS_SEARCH_UPDATE events).
1574    */
1575   GNUNET_FS_FLAGS_DO_PROBES = 2
1576 };
1577
1578
1579 /**
1580  * Options specified in the VARARGs portion of GNUNET_FS_start.
1581  */
1582 enum GNUNET_FS_OPTIONS
1583 {
1584   /**
1585    * Last option in the VARARG list.
1586    */
1587   GNUNET_FS_OPTIONS_END = 0,
1588
1589   /**
1590    * Select the desired amount of parallelism (this option should be
1591    * followed by an "unsigned int" giving the desired maximum number
1592    * of parallel downloads).
1593    */
1594   GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1595
1596   /**
1597    * Maximum number of requests that should be pending at a given
1598    * point in time (invidivual downloads may go above this, but
1599    * if we are above this threshold, we should not activate any
1600    * additional downloads.
1601    */
1602   GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1603 };
1604
1605
1606 /**
1607  * Settings for publishing a block (which may of course also
1608  * apply to an entire directory or file).
1609  */
1610 struct GNUNET_FS_BlockOptions
1611 {
1612   /**
1613    * At what time should the block expire?  Data blocks (DBLOCKS and
1614    * IBLOCKS) may still be used even if they are expired (however,
1615    * they'd be removed quickly from the datastore if we are short on
1616    * space), all other types of blocks will no longer be returned
1617    * after they expire.
1618    */
1619   struct GNUNET_TIME_Absolute expiration_time;
1620
1621   /**
1622    * At which anonymity level should the block be shared?
1623    * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
1624    */
1625   uint32_t anonymity_level;
1626
1627   /**
1628    * How important is it for us to store the block?  If we run
1629    * out of space, the highest-priority, non-expired blocks will
1630    * be kept.
1631    */
1632   uint32_t content_priority;
1633
1634   /**
1635    * How often should we try to migrate the block to other peers?
1636    * Only used if "CONTENT_PUSHING" is set to YES, in which case we
1637    * first push each block to other peers according to their
1638    * replication levels.  Once each block has been pushed that many
1639    * times to other peers, blocks are chosen for migration at random.
1640    * Naturally, there is no guarantee that the other peers will keep
1641    * these blocks for any period of time (since they won't have any
1642    * priority or might be too busy to even store the block in the
1643    * first place).
1644    */
1645   uint32_t replication_level;
1646 };
1647
1648
1649 /**
1650  * Handle to the file-sharing service.
1651  */
1652 struct GNUNET_FS_Handle;
1653
1654
1655 /**
1656  * Setup a connection to the file-sharing service.
1657  *
1658  * @param cfg configuration to use
1659  * @param client_name unique identifier for this client
1660  * @param upcb function to call to notify about FS actions
1661  * @param upcb_cls closure for @a upcb
1662  * @param flags specific attributes for fs-operations
1663  * @param ... list of optional options, terminated with #GNUNET_FS_OPTIONS_END
1664  * @return NULL on error
1665  */
1666 struct GNUNET_FS_Handle *
1667 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1668                  const char *client_name,
1669                  GNUNET_FS_ProgressCallback upcb,
1670                  void *upcb_cls,
1671                  enum GNUNET_FS_Flags flags,
1672                  ...);
1673
1674
1675 /**
1676  * Close our connection with the file-sharing service.
1677  * The callback given to #GNUNET_FS_start() will no longer be
1678  * called after this function returns.
1679  * This function MUST NOT be called from within the
1680  * callback itself.
1681  *
1682  * @param h handle that was returned from #GNUNET_FS_start()
1683  */
1684 void
1685 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1686
1687
1688 /**
1689  * Function called on entries in a `struct GNUNET_FS_FileInformation` iteration.
1690  *
1691  * @param cls closure
1692  * @param fi the entry in the publish-structure
1693  * @param length length of the file or directory
1694  * @param meta metadata for the file or directory (can be modified)
1695  * @param uri pointer to the keywords that will be used for this entry (can be modified)
1696  * @param bo block options (can be modified)
1697  * @param do_index should we index (can be modified)
1698  * @param client_info pointer to client context set upon creation (can be modified)
1699  * @return #GNUNET_OK to continue, #GNUNET_NO to remove
1700  *         this entry from the directory, #GNUNET_SYSERR
1701  *         to abort the iteration
1702  */
1703 typedef int
1704 (*GNUNET_FS_FileInformationProcessor) (void *cls,
1705                                        struct GNUNET_FS_FileInformation *fi,
1706                                        uint64_t length,
1707                                        struct GNUNET_CONTAINER_MetaData *meta,
1708                                        struct GNUNET_FS_Uri **uri,
1709                                        struct GNUNET_FS_BlockOptions *bo,
1710                                        int *do_index,
1711                                        void **client_info);
1712
1713
1714 /**
1715  * Obtain the name under which this file information
1716  * structure is stored on disk.  Only works for top-level
1717  * file information structures.
1718  *
1719  * @param s structure to get the filename for
1720  * @return NULL on error, otherwise filename that can be used
1721  *         to read this fi-struct from disk.
1722  */
1723 const char *
1724 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1725
1726
1727 /**
1728  * Obtain the filename from the file information structure.
1729  *
1730  * @param s structure to get the filename for
1731  * @return "filename" field of the structure (can be NULL)
1732  */
1733 const char *
1734 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
1735
1736
1737 /**
1738  * Set the filename in the file information structure.
1739  * If filename was already set, frees it before setting the new one.
1740  * Makes a copy of the argument.
1741  *
1742  * @param s structure to get the filename for
1743  * @param filename filename to set
1744  */
1745 void
1746 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
1747                                          const char *filename);
1748
1749
1750 /**
1751  * Create an entry for a file in a publish-structure.
1752  *
1753  * @param h handle to the file sharing subsystem
1754  * @param client_info initial client-info value for this entry
1755  * @param filename name of the file or directory to publish
1756  * @param keywords under which keywords should this file be available
1757  *         directly; can be NULL
1758  * @param meta metadata for the file
1759  * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1760  *                #GNUNET_SYSERR for simulation
1761  * @param bo block options
1762  * @return publish structure entry for the file
1763  */
1764 struct GNUNET_FS_FileInformation *
1765 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1766                                              void *client_info,
1767                                              const char *filename,
1768                                              const struct
1769                                              GNUNET_FS_Uri *keywords,
1770                                              const struct
1771                                              GNUNET_CONTAINER_MetaData *meta,
1772                                              int do_index,
1773                                              const struct
1774                                              GNUNET_FS_BlockOptions *bo);
1775
1776
1777 /**
1778  * Create an entry for a file in a publish-structure.
1779  *
1780  * @param h handle to the file sharing subsystem
1781  * @param client_info initial client-info value for this entry
1782  * @param length length of the file
1783  * @param data data for the file (should not be used afterwards by
1784  *        the caller; callee will "free")
1785  * @param keywords under which keywords should this file be available
1786  *         directly; can be NULL
1787  * @param meta metadata for the file
1788  * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1789  *                #GNUNET_SYSERR for simulation
1790  * @param bo block options
1791  * @return publish structure entry for the file
1792  */
1793 struct GNUNET_FS_FileInformation *
1794 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1795                                              void *client_info,
1796                                              uint64_t length,
1797                                              void *data,
1798                                              const struct
1799                                              GNUNET_FS_Uri *keywords,
1800                                              const struct
1801                                              GNUNET_CONTAINER_MetaData *meta,
1802                                              int do_index,
1803                                              const struct
1804                                              GNUNET_FS_BlockOptions *bo);
1805
1806
1807 /**
1808  * Function that provides data.
1809  *
1810  * @param cls closure
1811  * @param offset offset to read from; it is possible
1812  *            that the caller might need to go backwards
1813  *            a bit at times; set to UINT64_MAX to tell
1814  *            the reader that we won't be reading for a while
1815  *            (used to close the file descriptor but NOT fully
1816  *             clean up the reader's state); in this case,
1817  *            a value of '0' for max should be ignored
1818  * @param max maximum number of bytes that should be
1819  *            copied to buf; readers are not allowed
1820  *            to provide less data unless there is an error;
1821  *            a value of "0" will be used at the end to allow
1822  *            the reader to clean up its internal state
1823  * @param buf where the reader should write the data
1824  * @param emsg location for the reader to store an error message
1825  * @return number of bytes written, usually @a max, 0 on error
1826  */
1827 typedef size_t
1828 (*GNUNET_FS_DataReader) (void *cls,
1829                          uint64_t offset,
1830                          size_t max,
1831                          void *buf,
1832                          char **emsg);
1833
1834
1835 /**
1836  * Create an entry for a file in a publish-structure.
1837  *
1838  * @param h handle to the file sharing subsystem
1839  * @param client_info initial client-info value for this entry
1840  * @param length length of the file
1841  * @param reader function that can be used to obtain the data for the file
1842  * @param reader_cls closure for @a reader
1843  * @param keywords under which keywords should this file be available
1844  *         directly; can be NULL
1845  * @param meta metadata for the file
1846  * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
1847  *                #GNUNET_SYSERR for simulation
1848  * @param bo block options
1849  * @return publish structure entry for the file
1850  */
1851 struct GNUNET_FS_FileInformation *
1852 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1853                                                void *client_info,
1854                                                uint64_t length,
1855                                                GNUNET_FS_DataReader reader,
1856                                                void *reader_cls,
1857                                                const struct GNUNET_FS_Uri
1858                                                *keywords,
1859                                                const struct
1860                                                GNUNET_CONTAINER_MetaData *meta,
1861                                                int do_index,
1862                                                const struct
1863                                                GNUNET_FS_BlockOptions *bo);
1864
1865
1866 /**
1867  * Create an entry for an empty directory in a publish-structure.
1868  *
1869  * @param h handle to the file sharing subsystem
1870  * @param client_info initial client-info value for this entry
1871  * @param keywords under which keywords should this directory be available
1872  *         directly; can be NULL
1873  * @param meta metadata for the directory
1874  * @param bo block options
1875  * @param filename name of the directory; can be NULL
1876  * @return publish structure entry for the directory , NULL on error
1877  */
1878 struct GNUNET_FS_FileInformation *
1879 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1880                                                    void *client_info,
1881                                                    const struct GNUNET_FS_Uri
1882                                                    *keywords,
1883                                                    const struct
1884                                                    GNUNET_CONTAINER_MetaData
1885                                                    *meta,
1886                                                    const struct
1887                                                    GNUNET_FS_BlockOptions *bo,
1888                                                    const char *filename);
1889
1890
1891 /**
1892  * Test if a given entry represents a directory.
1893  *
1894  * @param ent check if this FI represents a directory
1895  * @return #GNUNET_YES if so, #GNUNET_NO if not
1896  */
1897 int
1898 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
1899                                          *ent);
1900
1901
1902 /**
1903  * Add an entry to a directory in a publish-structure.  Clients
1904  * should never modify publish structures that were passed to
1905  * #GNUNET_FS_publish_start() already.
1906  *
1907  * @param dir the directory
1908  * @param ent the entry to add; the entry must not have been
1909  *            added to any other directory at this point and
1910  *            must not include @a dir in its structure
1911  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1912  */
1913 int
1914 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1915                                 struct GNUNET_FS_FileInformation *ent);
1916
1917
1918 /**
1919  * Inspect a file or directory in a publish-structure.  Clients
1920  * should never modify publish structures that were passed to
1921  * #GNUNET_FS_publish_start already.  When called on a directory,
1922  * this function will FIRST call @a proc with information about
1923  * the directory itself and then for each of the files in the
1924  * directory (but not for files in subdirectories).  When called
1925  * on a file, @a proc will be called exactly once (with information
1926  * about the specific file).
1927  *
1928  * @param dir the directory
1929  * @param proc function to call on each entry
1930  * @param proc_cls closure for @a proc
1931  */
1932 void
1933 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1934                                     GNUNET_FS_FileInformationProcessor proc,
1935                                     void *proc_cls);
1936
1937
1938 /**
1939  * Destroy publish-structure.  Clients should never destroy publish
1940  * structures that were passed to #GNUNET_FS_publish_start already.
1941  *
1942  * @param fi structure to destroy
1943  * @param cleaner function to call on each entry in the structure
1944  *        (useful to clean up client_info); can be NULL; return
1945  *        values are ignored
1946  * @param cleaner_cls closure for @a cleaner
1947  */
1948 void
1949 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1950                                     GNUNET_FS_FileInformationProcessor cleaner,
1951                                     void *cleaner_cls);
1952
1953
1954 /**
1955  * Options for publishing.  Compatible options
1956  * can be OR'ed together.
1957  */
1958 enum GNUNET_FS_PublishOptions
1959 {
1960   /**
1961    * No options (use defaults for everything).
1962    */
1963   GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1964
1965   /**
1966    * Simulate publishing.  With this option, no data will be stored
1967    * in the datastore.  Useful for computing URIs from files.
1968    */
1969   GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1970 };
1971
1972
1973 /**
1974  * Publish a file or directory.
1975  *
1976  * @param h handle to the file sharing subsystem
1977  * @param fi information about the file or directory structure to publish
1978  * @param ns namespace to publish the file in, NULL for no namespace
1979  * @param nid identifier to use for the publishd content in the namespace
1980  *        (can be NULL, must be NULL if namespace is NULL)
1981  * @param nuid update-identifier that will be used for future updates
1982  *        (can be NULL, must be NULL if namespace or nid is NULL)
1983  * @param options options for the publication
1984  * @return context that can be used to control the publish operation
1985  */
1986 struct GNUNET_FS_PublishContext *
1987 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1988                          struct GNUNET_FS_FileInformation *fi,
1989                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
1990                          const char *nid,
1991                          const char *nuid,
1992                          enum GNUNET_FS_PublishOptions options);
1993
1994
1995 /**
1996  * Stop a publication.  Will abort incomplete publications (but
1997  * not remove blocks that have already been published) or
1998  * simply clean up the state for completed publications.
1999  * Must NOT be called from within the event callback!
2000  *
2001  * @param pc context for the publication to stop
2002  */
2003 void
2004 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2005
2006
2007 /**
2008  * Signature of a function called as the continuation of a KBlock or
2009  * SBlock publication.
2010  *
2011  * @param cls closure
2012  * @param uri URI under which the block is now available, NULL on error
2013  * @param emsg error message, NULL on success
2014  */
2015 typedef void
2016 (*GNUNET_FS_PublishContinuation) (void *cls,
2017                                   const struct GNUNET_FS_Uri *uri,
2018                                   const char *emsg);
2019
2020
2021 /**
2022  * Handle to cancel publish KSK operation.
2023  */
2024 struct GNUNET_FS_PublishKskContext;
2025
2026
2027 /**
2028  * Publish a KBlock on GNUnet.
2029  *
2030  * @param h handle to the file sharing subsystem
2031  * @param ksk_uri keywords to use
2032  * @param meta metadata to use
2033  * @param uri URI to refer to in the KBlock
2034  * @param bo block options
2035  * @param options publication options
2036  * @param cont continuation
2037  * @param cont_cls closure for @a cont
2038  * @return NULL on error (@a cont will still be called)
2039  */
2040 struct GNUNET_FS_PublishKskContext *
2041 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2042                        const struct GNUNET_FS_Uri *ksk_uri,
2043                        const struct GNUNET_CONTAINER_MetaData *meta,
2044                        const struct GNUNET_FS_Uri *uri,
2045                        const struct GNUNET_FS_BlockOptions *bo,
2046                        enum GNUNET_FS_PublishOptions options,
2047                        GNUNET_FS_PublishContinuation cont, void *cont_cls);
2048
2049
2050 /**
2051  * Abort the KSK publishing operation.
2052  *
2053  * @param pkc context of the operation to abort.
2054  */
2055 void
2056 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2057
2058
2059 /**
2060  * Handle to cancel publish SKS operation.
2061  */
2062 struct GNUNET_FS_PublishSksContext;
2063
2064
2065 /**
2066  * Publish an SBlock on GNUnet.
2067  *
2068  * @param h handle to the file sharing subsystem
2069  * @param ns namespace to publish in
2070  * @param identifier identifier to use
2071  * @param update update identifier to use
2072  * @param meta metadata to use
2073  * @param uri URI to refer to in the SBlock
2074  * @param bo block options
2075  * @param options publication options
2076  * @param cont continuation
2077  * @param cont_cls closure for @a cont
2078  * @return NULL on error (@a cont will still be called)
2079  */
2080 struct GNUNET_FS_PublishSksContext *
2081 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2082                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2083                        const char *identifier,
2084                        const char *update,
2085                        const struct GNUNET_CONTAINER_MetaData *meta,
2086                        const struct GNUNET_FS_Uri *uri,
2087                        const struct GNUNET_FS_BlockOptions *bo,
2088                        enum GNUNET_FS_PublishOptions options,
2089                        GNUNET_FS_PublishContinuation cont, void *cont_cls);
2090
2091
2092 /**
2093  * Abort the SKS publishing operation.
2094  *
2095  * @param psc context of the operation to abort.
2096  */
2097 void
2098 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2099
2100
2101 /**
2102  * Type of a function called by #GNUNET_FS_get_indexed_files.
2103  *
2104  * @param cls closure
2105  * @param filename the name of the file, NULL for end of list
2106  * @param file_id hash of the contents of the indexed file
2107  * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2108  */
2109 typedef int
2110 (*GNUNET_FS_IndexedFileProcessor) (void *cls,
2111                                    const char *filename,
2112                                    const struct GNUNET_HashCode *file_id);
2113
2114
2115 /**
2116  * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2117  */
2118 struct GNUNET_FS_GetIndexedContext;
2119
2120
2121 /**
2122  * Iterate over all indexed files.
2123  *
2124  * @param h handle to the file sharing subsystem
2125  * @param iterator function to call on each indexed file
2126  * @param iterator_cls closure for @a iterator
2127  * @return NULL on error (@a iterator is not called)
2128  */
2129 struct GNUNET_FS_GetIndexedContext *
2130 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2131                              GNUNET_FS_IndexedFileProcessor iterator,
2132                              void *iterator_cls);
2133
2134
2135 /**
2136  * Cancel iteration over all indexed files.
2137  *
2138  * @param gic operation to cancel
2139  */
2140 void
2141 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2142
2143
2144 /**
2145  * Unindex a file.
2146  *
2147  * @param h handle to the file sharing subsystem
2148  * @param filename file to unindex
2149  * @param cctx initial value for the client context
2150  * @return NULL on error, otherwise handle
2151  */
2152 struct GNUNET_FS_UnindexContext *
2153 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2154                          const char *filename,
2155                          void *cctx);
2156
2157
2158 /**
2159  * Clean up after completion of an unindex operation.
2160  *
2161  * @param uc handle
2162  */
2163 void
2164 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2165
2166
2167 /**
2168  * Function called on updateable identifiers.
2169  *
2170  * @param cls closure
2171  * @param last_id last identifier
2172  * @param last_uri uri used for the content published under the @a last_id
2173  * @param last_meta metadata associated with @a last_uri
2174  * @param next_id identifier that should be used for updates
2175  */
2176 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2177                                                const char *last_id,
2178                                                const struct
2179                                                GNUNET_FS_Uri *last_uri,
2180                                                const struct
2181                                                GNUNET_CONTAINER_MetaData *
2182                                                last_meta,
2183                                                const char *next_id);
2184
2185
2186 /**
2187  * List all of the identifiers in the namespace for which we could
2188  * produce an update.  Namespace updates form a graph where each node
2189  * has a name.  Each node can have any number of URI/meta-data entries
2190  * which can each be linked to other nodes.  Cycles are possible.
2191  *
2192  * Calling this function with @a next_id NULL will cause the library to
2193  * call @a ip with a root for each strongly connected component of the
2194  * graph (a root being a node from which all other nodes in the Scc
2195  * are reachable).
2196  *
2197  * Calling this function with @a next_id being the name of a node will
2198  * cause the library to call @a ip with all children of the node.  Note
2199  * that cycles within an SCC are possible (including self-loops).
2200  *
2201  * @param h fs handle to use
2202  * @param ns namespace to inspect for updateable content
2203  * @param next_id ID to look for; use NULL to look for SCC roots
2204  * @param ip function to call on each updateable identifier
2205  * @param ip_cls closure for @a ip
2206  */
2207 void
2208 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
2209                                      const struct
2210                                      GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2211                                      const char *next_id,
2212                                      GNUNET_FS_IdentifierProcessor ip,
2213                                      void *ip_cls);
2214
2215
2216 /**
2217  * Options for searching.  Compatible options
2218  * can be OR'ed together.
2219  */
2220 enum GNUNET_FS_SearchOptions
2221 {
2222   /**
2223    * No options (use defaults for everything).
2224    */
2225   GNUNET_FS_SEARCH_OPTION_NONE = 0,
2226
2227   /**
2228    * Only search the local host, do not search remote systems (no P2P)
2229    */
2230   GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2231 };
2232
2233
2234 /**
2235  * Start search for content.
2236  *
2237  * @param h handle to the file sharing subsystem
2238  * @param uri specifies the search parameters; can be
2239  *        a KSK URI or an SKS URI.
2240  * @param anonymity desired level of anonymity
2241  * @param options options for the search
2242  * @param cctx initial value for the client context
2243  * @return context that can be used to control the search
2244  */
2245 struct GNUNET_FS_SearchContext *
2246 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2247                         const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2248                         enum GNUNET_FS_SearchOptions options, void *cctx);
2249
2250
2251 /**
2252  * Pause search.
2253  *
2254  * @param sc context for the search that should be paused
2255  */
2256 void
2257 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2258
2259
2260 /**
2261  * Continue paused search.
2262  *
2263  * @param sc context for the search that should be resumed
2264  */
2265 void
2266 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2267
2268
2269 /**
2270  * Stop search for content.
2271  *
2272  * @param sc context for the search that should be stopped
2273  */
2274 void
2275 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2276
2277
2278 /**
2279  * Start download probes for the given search result.
2280  *
2281  * @param h file-sharing handle to use for the operation
2282  * @param uri URI to probe
2283  * @param meta meta data associated with the URI
2284  * @param client_info client info pointer to use for associated events
2285  * @param anonymity anonymity level to use for the probes
2286  * @return the search result handle to access the probe activity
2287  */
2288 struct GNUNET_FS_SearchResult *
2289 GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2290                  const struct GNUNET_FS_Uri *uri,
2291                  const struct GNUNET_CONTAINER_MetaData *meta,
2292                  void *client_info,
2293                  uint32_t anonymity);
2294
2295
2296 /**
2297  * Stop probe activity.  Must ONLY be used on values
2298  * returned from #GNUNET_FS_probe.
2299  *
2300  * @param sr search result to stop probing for (freed)
2301  * @return the value of the 'client_info' pointer
2302  */
2303 void *
2304 GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2305
2306
2307 /**
2308  * Options for downloading.  Compatible options
2309  * can be OR'ed together.
2310  */
2311 enum GNUNET_FS_DownloadOptions
2312 {
2313   /**
2314    * No options (use defaults for everything).
2315    */
2316   GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2317
2318   /**
2319    * Only download from the local host, do not access remote systems (no P2P)
2320    */
2321   GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2322
2323   /**
2324    * Do a recursive download (that is, automatically trigger the
2325    * download of files in directories).
2326    */
2327   GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2328
2329   /**
2330    * Do not append temporary data to
2331    * the target file (for the IBlocks).
2332    */
2333   GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2334
2335   /**
2336    * Internal option used to flag this download as a 'probe' for a
2337    * search result.  Impacts the priority with which the download is
2338    * run and causes signalling callbacks to be done differently.
2339    * Also, probe downloads are not serialized on suspension.  Normal
2340    * clients should not use this!
2341    */
2342   GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2343 };
2344
2345
2346
2347 /**
2348  * Download parts of a file.  Note that this will store
2349  * the blocks at the respective offset in the given file.  Also, the
2350  * download is still using the blocking of the underlying FS
2351  * encoding.  As a result, the download may *write* outside of the
2352  * given boundaries (if offset and length do not match the 32k FS
2353  * block boundaries).
2354  *
2355  * The given range can be used to focus a download towards a
2356  * particular portion of the file (optimization), not to strictly
2357  * limit the download to exactly those bytes.
2358  *
2359  * @param h handle to the file sharing subsystem
2360  * @param uri the URI of the file (determines what to download); CHK or LOC URI
2361  * @param meta known metadata for the file (can be NULL)
2362  * @param filename where to store the file, maybe NULL (then no file is
2363  *        created on disk and data must be grabbed from the callbacks)
2364  * @param tempname where to store temporary file data, not used if filename is non-NULL;
2365  *        can be NULL (in which case we will pick a name if needed); the temporary file
2366  *        may already exist, in which case we will try to use the data that is there and
2367  *        if it is not what is desired, will overwrite it
2368  * @param offset at what offset should we start the download (typically 0)
2369  * @param length how many bytes should be downloaded starting at offset
2370  * @param anonymity anonymity level to use for the download
2371  * @param options various download options
2372  * @param cctx initial value for the client context for this download
2373  * @param parent parent download to associate this download with (use NULL
2374  *        for top-level downloads; useful for manually-triggered recursive downloads)
2375  * @return context that can be used to control this download
2376  */
2377 struct GNUNET_FS_DownloadContext *
2378 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2379                           const struct GNUNET_FS_Uri *uri,
2380                           const struct GNUNET_CONTAINER_MetaData *meta,
2381                           const char *filename, const char *tempname,
2382                           uint64_t offset, uint64_t length, uint32_t anonymity,
2383                           enum GNUNET_FS_DownloadOptions options, void *cctx,
2384                           struct GNUNET_FS_DownloadContext *parent);
2385
2386
2387 /**
2388  * Download parts of a file based on a search result.  The download
2389  * will be associated with the search result (and the association
2390  * will be preserved when serializing/deserializing the state).
2391  * If the search is stopped, the download will not be aborted but
2392  * be 'promoted' to a stand-alone download.
2393  *
2394  * As with the other download function, this will store
2395  * the blocks at the respective offset in the given file.  Also, the
2396  * download is still using the blocking of the underlying FS
2397  * encoding.  As a result, the download may *write* outside of the
2398  * given boundaries (if offset and length do not match the 32k FS
2399  * block boundaries).
2400  *
2401  * The given range can be used to focus a download towards a
2402  * particular portion of the file (optimization), not to strictly
2403  * limit the download to exactly those bytes.
2404  *
2405  * @param h handle to the file sharing subsystem
2406  * @param sr the search result to use for the download (determines uri and
2407  *        meta data and associations)
2408  * @param filename where to store the file, maybe NULL (then no file is
2409  *        created on disk and data must be grabbed from the callbacks)
2410  * @param tempname where to store temporary file data, not used if filename is non-NULL;
2411  *        can be NULL (in which case we will pick a name if needed); the temporary file
2412  *        may already exist, in which case we will try to use the data that is there and
2413  *        if it is not what is desired, will overwrite it
2414  * @param offset at what offset should we start the download (typically 0)
2415  * @param length how many bytes should be downloaded starting at offset
2416  * @param anonymity anonymity level to use for the download
2417  * @param options various download options
2418  * @param cctx initial value for the client context for this download
2419  * @return context that can be used to control this download
2420  */
2421 struct GNUNET_FS_DownloadContext *
2422 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2423                                       struct GNUNET_FS_SearchResult *sr,
2424                                       const char *filename,
2425                                       const char *tempname, uint64_t offset,
2426                                       uint64_t length, uint32_t anonymity,
2427                                       enum GNUNET_FS_DownloadOptions options,
2428                                       void *cctx);
2429
2430
2431 /**
2432  * Stop a download (aborts if download is incomplete).
2433  *
2434  * @param dc handle for the download
2435  * @param do_delete delete files of incomplete downloads
2436  */
2437 void
2438 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2439
2440
2441 /**
2442  * Suspend a download.
2443  *
2444  * @param dc handle for the download
2445  */
2446 void
2447 GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc);
2448
2449
2450 /**
2451  * Resume a suspended download.
2452  *
2453  * @param dc handle for the download
2454  */
2455 void
2456 GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2457
2458
2459
2460 /* ******************** Directory API *********************** */
2461
2462
2463 #define GNUNET_FS_DIRECTORY_MIME  "application/gnunet-directory"
2464 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2465 #define GNUNET_FS_DIRECTORY_EXT   ".gnd"
2466
2467 /**
2468  * Does the meta-data claim that this is a directory?
2469  * Checks if the mime-type is that of a GNUnet directory.
2470  *
2471  * @return #GNUNET_YES if it is, #GNUNET_NO if it is not, #GNUNET_SYSERR if
2472  *  we have no mime-type information (treat as #GNUNET_NO)
2473  */
2474 int
2475 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2476                                         *md);
2477
2478
2479 /**
2480  * Set the MIMETYPE information for the given
2481  * metadata to "application/gnunet-directory".
2482  *
2483  * @param md metadata to add mimetype to
2484  */
2485 void
2486 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2487
2488
2489 /**
2490  * Suggest a filename based on given metadata.
2491  *
2492  * @param md given meta data
2493  * @return NULL if meta data is useless for suggesting a filename
2494  */
2495 char *
2496 GNUNET_FS_meta_data_suggest_filename (const struct
2497                                       GNUNET_CONTAINER_MetaData *md);
2498
2499
2500 /**
2501  * Function used to process entries in a directory.
2502  *
2503  * @param cls closure
2504  * @param filename name of the file in the directory
2505  * @param uri URI of the file
2506  * @param metadata metadata for the file; metadata for
2507  *        the directory if everything else is NULL/zero
2508  * @param length length of the available data for the file
2509  *           (of type size_t since data must certainly fit
2510  *            into memory; if files are larger than size_t
2511  *            permits, then they will certainly not be
2512  *            embedded with the directory itself).
2513  * @param data data available for the file (length bytes)
2514  */
2515 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2516                                                    const char *filename,
2517                                                    const struct GNUNET_FS_Uri *
2518                                                    uri,
2519                                                    const struct
2520                                                    GNUNET_CONTAINER_MetaData *
2521                                                    meta, size_t length,
2522                                                    const void *data);
2523
2524
2525 /**
2526  * Iterate over all entries in a directory.  Note that directories
2527  * are structured such that it is possible to iterate over the
2528  * individual blocks as well as over the entire directory.  Thus
2529  * a client can call this function on the buffer in the
2530  * GNUNET_FS_ProgressCallback.  Also, directories can optionally
2531  * include the contents of (small) files embedded in the directory
2532  * itself; for those files, the processor may be given the
2533  * contents of the file directly by this function.
2534  *
2535  * @param size number of bytes in data
2536  * @param data pointer to the beginning of the directory
2537  * @param offset offset of data in the directory
2538  * @param dep function to call on each entry
2539  * @param dep_cls closure for @a dep
2540  * @return #GNUNET_OK if this could be a block in a directory,
2541  *         #GNUNET_NO if this could be part of a directory (but not 100% OK)
2542  *         #GNUNET_SYSERR if 'data' does not represent a directory
2543  */
2544 int
2545 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2546                                    uint64_t offset,
2547                                    GNUNET_FS_DirectoryEntryProcessor dep,
2548                                    void *dep_cls);
2549
2550
2551 /**
2552  * Opaque handle to a directory builder.
2553  */
2554 struct GNUNET_FS_DirectoryBuilder;
2555
2556
2557 /**
2558  * Create a directory builder.
2559  *
2560  * @param mdir metadata for the directory
2561  */
2562 struct GNUNET_FS_DirectoryBuilder *
2563 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2564                                     *mdir);
2565
2566
2567 /**
2568  * Add an entry to a directory.
2569  *
2570  * @param bld directory to extend
2571  * @param uri uri of the entry (must not be a KSK)
2572  * @param md metadata of the entry
2573  * @param data raw data of the entry, can be NULL, otherwise
2574  *        data must point to exactly the number of bytes specified
2575  *        by the uri
2576  */
2577 void
2578 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2579                                  const struct GNUNET_FS_Uri *uri,
2580                                  const struct GNUNET_CONTAINER_MetaData *md,
2581                                  const void *data);
2582
2583
2584 /**
2585  * Finish building the directory.  Frees the
2586  * builder context and returns the directory
2587  * in-memory.
2588  *
2589  * @param bld directory to finish
2590  * @param rsize set to the number of bytes needed
2591  * @param rdata set to the encoded directory
2592  * @return #GNUNET_OK on success
2593  */
2594 int
2595 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2596                                     size_t *rsize, void **rdata);
2597
2598
2599 /* ******************** DirScanner API *********************** */
2600
2601 /**
2602  * Progress reasons of the directory scanner.
2603  */
2604 enum GNUNET_FS_DirScannerProgressUpdateReason
2605 {
2606   /**
2607    * We've started processing a file or directory.
2608    */
2609   GNUNET_FS_DIRSCANNER_FILE_START = 0,
2610
2611   /**
2612    * We're having trouble accessing a file (soft-error); it will
2613    * be ignored.
2614    */
2615   GNUNET_FS_DIRSCANNER_FILE_IGNORED,
2616
2617   /**
2618    * We've found all files (in the pre-pass).
2619    */
2620   GNUNET_FS_DIRSCANNER_ALL_COUNTED,
2621
2622   /**
2623    * We've finished extracting meta data from a file.
2624    */
2625   GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
2626
2627   /**
2628    * Last call to the progress function: we have finished scanning
2629    * the directory.
2630    */
2631   GNUNET_FS_DIRSCANNER_FINISHED,
2632
2633   /**
2634    * There was an internal error.  Application should abort the scan.
2635    */
2636   GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
2637 };
2638
2639
2640 /**
2641  * Function called over time as the directory scanner makes
2642  * progress on the job at hand.
2643  *
2644  * @param cls closure
2645  * @param filename which file we are making progress on
2646  * @param is_directory #GNUNET_YES if this is a directory,
2647  *                     #GNUNET_NO if this is a file
2648  *                     #GNUNET_SYSERR if it is neither (or unknown)
2649  * @param reason kind of progress we are making
2650  */
2651 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
2652                                                       const char *filename,
2653                                                       int is_directory,
2654                                                       enum
2655                                                       GNUNET_FS_DirScannerProgressUpdateReason
2656                                                       reason);
2657
2658
2659 /**
2660  * A node of a directory tree (produced by dirscanner)
2661  */
2662 struct GNUNET_FS_ShareTreeItem
2663 {
2664   /**
2665    * This is a doubly-linked list
2666    */
2667   struct GNUNET_FS_ShareTreeItem *prev;
2668
2669   /**
2670    * This is a doubly-linked list
2671    */
2672   struct GNUNET_FS_ShareTreeItem *next;
2673
2674   /**
2675    * This is a doubly-linked tree
2676    * NULL for top-level entries.
2677    */
2678   struct GNUNET_FS_ShareTreeItem *parent;
2679
2680   /**
2681    * This is a doubly-linked tree
2682    * NULL for files and empty directories
2683    */
2684   struct GNUNET_FS_ShareTreeItem *children_head;
2685
2686   /**
2687    * This is a doubly-linked tree
2688    * NULL for files and empty directories
2689    */
2690   struct GNUNET_FS_ShareTreeItem *children_tail;
2691
2692   /**
2693    * Metadata for this file or directory
2694    */
2695   struct GNUNET_CONTAINER_MetaData *meta;
2696
2697   /**
2698    * Keywords for this file or directory (derived from metadata).
2699    */
2700   struct GNUNET_FS_Uri *ksk_uri;
2701
2702   /**
2703    * Name of the file/directory
2704    */
2705   char *filename;
2706
2707   /**
2708    * Base name of the file/directory.
2709    */
2710   char *short_filename;
2711
2712   /**
2713    * #GNUNET_YES if this is a directory
2714    */
2715   int is_directory;
2716 };
2717
2718
2719 /**
2720  * Opaque handle to an asynchronous directory scanning activity.
2721  */
2722 struct GNUNET_FS_DirScanner;
2723
2724
2725 /**
2726  * Start a directory scanner.
2727  *
2728  * @param filename name of the directory to scan
2729  * @param disable_extractor #GNUNET_YES to not run libextractor on files (only
2730  *        build a tree)
2731  * @param ex if not NULL, must be a list of extra plugins for extractor
2732  * @param cb the callback to call when there are scanning progress messages
2733  * @param cb_cls closure for @a cb
2734  * @return directory scanner object to be used for controlling the scanner
2735  */
2736 struct GNUNET_FS_DirScanner *
2737 GNUNET_FS_directory_scan_start (const char *filename,
2738                                 int disable_extractor,
2739                                 const char *ex,
2740                                 GNUNET_FS_DirScannerProgressCallback cb,
2741                                 void *cb_cls);
2742
2743
2744 /**
2745  * Abort the scan. Must not be called from within the progress_callback
2746  * function.
2747  *
2748  * @param ds directory scanner structure
2749  */
2750 void
2751 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
2752
2753
2754 /**
2755  * Obtain the result of the scan after the scan has signalled
2756  * completion.  Must not be called prior to completion.  The @a ds is
2757  * freed as part of this call.
2758  *
2759  * @param ds directory scanner structure
2760  * @return the results of the scan (a directory tree)
2761  */
2762 struct GNUNET_FS_ShareTreeItem *
2763 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
2764
2765
2766 /**
2767  * Process a share item tree, moving frequent keywords up and
2768  * copying frequent metadata up.
2769  *
2770  * @param toplevel toplevel directory in the tree, returned by the scanner
2771  */
2772 void
2773 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2774
2775
2776 /**
2777  * Release memory of a share item tree.
2778  *
2779  * @param toplevel toplevel of the tree to be freed
2780  */
2781 void
2782 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2783
2784
2785 #if 0                           /* keep Emacsens' auto-indent happy */
2786 {
2787 #endif
2788 #ifdef __cplusplus
2789 }
2790 #endif
2791
2792 #endif
2793
2794 /** @} */  /* end of group */