+/**
+ * Initialize a tree encoder. This function will call @a proc and
+ * "progress" on each block in the tree. Once all blocks have been
+ * processed, "cont" will be scheduled. The @a reader will be called
+ * to obtain the (plaintext) blocks for the file. Note that this
+ * function will not actually call @a proc. The client must
+ * call #GNUNET_FS_tree_encoder_next to trigger encryption (and
+ * calling of @a proc) for the each block.
+ *
+ * @param h the global FS context
+ * @param size overall size of the file to encode
+ * @param cls closure for reader, proc, progress and cont
+ * @param reader function to call to read plaintext data
+ * @param proc function to call on each encrypted block
+ * @param progress function to call with progress information
+ * @param cont function to call when done
+ */
+struct GNUNET_FS_TreeEncoder *
+GNUNET_FS_tree_encoder_create (struct GNUNET_FS_Handle *h, uint64_t size,
+ void *cls,
+ GNUNET_FS_DataReader reader,
+ GNUNET_FS_TreeBlockProcessor proc,
+ GNUNET_FS_TreeProgressCallback progress,
+ GNUNET_SCHEDULER_TaskCallback cont)
+{
+ struct GNUNET_FS_TreeEncoder *te;
+
+ te = GNUNET_new (struct GNUNET_FS_TreeEncoder);
+ te->h = h;
+ te->size = size;
+ te->cls = cls;
+ te->reader = reader;
+ te->proc = proc;
+ te->progress = progress;
+ te->cont = cont;
+ te->chk_tree_depth = GNUNET_FS_compute_depth (size);
+ te->chk_tree
+ = GNUNET_new_array (te->chk_tree_depth * CHK_PER_INODE,
+ struct ContentHashKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created tree encoder for file with %llu bytes and depth %u\n",
+ (unsigned long long) size,
+ te->chk_tree_depth);
+ return te;
+}
+
+