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