aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-14 15:24:01 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-14 15:24:01 +0000
commitf83ef0e823c657c6bdb0b8e98b16b234b49777f3 (patch)
tree8f43555dfb55e962800497782dc1debd78db658c /src
parentea58fb0d848465e40c8b2a56ac482a4afabfa7d4 (diff)
downloadgnunet-f83ef0e823c657c6bdb0b8e98b16b234b49777f3.tar.gz
gnunet-f83ef0e823c657c6bdb0b8e98b16b234b49777f3.zip
LRN: new threaded directory metadata scanner
Diffstat (limited to 'src')
-rw-r--r--src/fs/Makefile.am1
-rw-r--r--src/include/gnunet_fs_service.h148
2 files changed, 149 insertions, 0 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index cbf63f335..2a8a8c896 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -27,6 +27,7 @@ noinst_LIBRARIES = libgnunetfstest.a
27libgnunetfs_la_SOURCES = \ 27libgnunetfs_la_SOURCES = \
28 fs_api.c fs_api.h fs.h \ 28 fs_api.c fs_api.h fs.h \
29 fs_directory.c \ 29 fs_directory.c \
30 fs_dirmetascan.c \
30 fs_download.c \ 31 fs_download.c \
31 fs_file_information.c \ 32 fs_file_information.c \
32 fs_getopt.c \ 33 fs_getopt.c \
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index cd9093a8e..ec353de8e 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -26,6 +26,7 @@
26#define GNUNET_FS_LIB_H 26#define GNUNET_FS_LIB_H
27 27
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_scheduler_lib.h"
29 30
30#ifdef __cplusplus 31#ifdef __cplusplus
31extern "C" 32extern "C"
@@ -70,6 +71,7 @@ extern "C"
70 */ 71 */
71struct GNUNET_FS_Uri; 72struct GNUNET_FS_Uri;
72 73
74struct GNUNET_FS_DirScanner;
73 75
74/** 76/**
75 * Iterator over keywords 77 * Iterator over keywords
@@ -2688,6 +2690,152 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2688 size_t * rsize, void **rdata); 2690 size_t * rsize, void **rdata);
2689 2691
2690 2692
2693/* ******************** DirScanner API *********************** */
2694
2695enum GNUNET_DirScannerProgressUpdateReason
2696{
2697 GNUNET_DIR_SCANNER_FIRST = 0,
2698 GNUNET_DIR_SCANNER_NEW_FILE = 1,
2699 GNUNET_DIR_SCANNER_DOES_NOT_EXIST = 2,
2700 GNUNET_DIR_SCANNER_ASKED_TO_STOP = 3,
2701 GNUNET_DIR_SCANNER_FINISHED = 4,
2702 GNUNET_DIR_SCANNER_PROTOCOL_ERROR = 5,
2703 GNUNET_DIR_SCANNER_SHUTDOWN = 6,
2704 GNUNET_DIR_SCANNER_LAST = 7
2705};
2706
2707
2708typedef int (* GNUNET_FS_DirScannerProgressCallback) (
2709 void *cls, struct GNUNET_FS_DirScanner *ds, const char *filename,
2710 char is_directory, enum GNUNET_DirScannerProgressUpdateReason reason);
2711
2712/**
2713 * A node of a directory tree (produced by dirscanner)
2714 */
2715struct ShareTreeItem
2716{
2717 /**
2718 * This is a doubly-linked list
2719 */
2720 struct ShareTreeItem *prev;
2721
2722 /**
2723 * This is a doubly-linked list
2724 */
2725 struct ShareTreeItem *next;
2726
2727 /**
2728 * This is a doubly-linked tree
2729 * NULL for top-level entries.
2730 */
2731 struct ShareTreeItem *parent;
2732
2733 /**
2734 * This is a doubly-linked tree
2735 * NULL for files and empty directories
2736 */
2737 struct ShareTreeItem *children_head;
2738
2739 /**
2740 * This is a doubly-linked tree
2741 * NULL for files and empty directories
2742 */
2743 struct ShareTreeItem *children_tail;
2744
2745 /**
2746 * Metadata for this file or directory
2747 */
2748 struct GNUNET_CONTAINER_MetaData *meta;
2749
2750 /**
2751 * Keywords for this file or directory (derived from metadata).
2752 */
2753 struct GNUNET_FS_Uri *ksk_uri;
2754
2755 /**
2756 * Name of the file/directory
2757 */
2758 char *filename;
2759
2760 /**
2761 * Base name of the file/directory
2762 */
2763 char *short_filename;
2764
2765 /**
2766 * 1 if this is a directory
2767 */
2768 char is_directory;
2769
2770 /**
2771 * Size of the file (if it's a file), in bytes
2772 */
2773 uint64_t file_size;
2774};
2775
2776/* opaqe */
2777struct GNUNET_FS_DirScanner;
2778
2779/**
2780 * Signals the scanner to finish the scan as fast as possible.
2781 * Does not block.
2782 * Can close the pipe if asked to, but that is only used by the
2783 * internal call to this function during cleanup. The client
2784 * must understand the consequences of closing the pipe too early.
2785 *
2786 * @param ds directory scanner structure
2787 * @param close_pipe GNUNET_YES to close
2788 */
2789void
2790GNUNET_FS_directory_scan_finish (struct GNUNET_FS_DirScanner *ds,
2791 int close_pipe);
2792
2793/**
2794 * Signals the scanner thread to finish (in case it isn't finishing
2795 * already) and joins the scanner thread. Closes the pipes, frees the
2796 * scanner contexts (both of them), returns the results of the scan.
2797 * Results are valid (and have to be freed) even if the scanner had
2798 * an error or was rushed to finish prematurely.
2799 * Blocks until the scanner is finished.
2800 *
2801 * @param ds directory scanner structure
2802 * @return the results of the scan (a directory tree)
2803 */
2804struct ShareTreeItem *
2805GNUNET_FS_directory_scan_cleanup (struct GNUNET_FS_DirScanner *ds);
2806
2807/**
2808 * Start a directory scanner thread.
2809 *
2810 * @param filename name of the directory to scan
2811 * @param GNUNET_YES to not to run libextractor on files (only build a tree)
2812 * @param ex if not NULL, must be a list of extra plugins for extractor
2813 * @param cb the callback to call when there are scanning progress messages
2814 * @param cls closure for 'cb'
2815 * @return directory scanner object to be used for controlling the scanner
2816 */
2817struct GNUNET_FS_DirScanner *
2818GNUNET_FS_directory_scan_start (const char *filename,
2819 int disable_extractor, const char *ex,
2820 GNUNET_FS_DirScannerProgressCallback cb, void *cls);
2821
2822
2823/* opaque */
2824struct ProcessMetadataContext;
2825
2826/**
2827 * Process a share item tree, moving frequent keywords up and
2828 * copying frequent metadata up.
2829 *
2830 * @param toplevel toplevel directory in the tree, returned by the scanner
2831 * @param cb called after processing is done
2832 * @param cls closure for 'cb'
2833 */
2834struct ProcessMetadataContext *
2835GNUNET_FS_trim_share_tree (struct ShareTreeItem *toplevel,
2836 GNUNET_SCHEDULER_Task cb, void *cls);
2837
2838
2691#if 0 /* keep Emacsens' auto-indent happy */ 2839#if 0 /* keep Emacsens' auto-indent happy */
2692{ 2840{
2693#endif 2841#endif