From 85172474808b86fb0b11d1f2a63a88d3741d5ecb Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 26 Aug 2009 09:13:06 +0000 Subject: [PATCH] hxing --- src/fs/Makefile.am | 3 ++ src/fs/fs.h | 75 +++++++++++++++++++++++++++ src/fs/fs_download.c | 75 +++++++++++++++++++++++---- src/fs/fs_publish.c | 89 +++++++++++++++++++++++++++++++++ src/fs/fs_search.c | 69 ++++++++++++++++++++++--- src/fs/fs_unindex.c | 61 ++++++++++++++++++---- src/fs/{fs_test.c => test_fs.c} | 0 src/include/gnunet_fs_service.h | 10 ++-- 8 files changed, 348 insertions(+), 34 deletions(-) rename src/fs/{fs_test.c => test_fs.c} (100%) diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index db9567fb1..5aca42ac2 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -16,10 +16,13 @@ libgnunetfs_la_SOURCES = \ fs.c \ fs_collection.c \ fs_directory.c \ + fs_download.c \ fs_file_information.c \ fs_getopt.c \ fs_publish.c \ fs_namespace.c \ + fs_search.c \ + fs_unindex.c \ fs_uri.c libgnunetfs_la_LIBADD = \ diff --git a/src/fs/fs.h b/src/fs/fs.h index 1a8a6b0f7..4743a594b 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -318,4 +318,79 @@ struct GNUNET_FS_Handle }; +/** + * Handle for controlling an upload. + */ +struct GNUNET_FS_PublishContext +{ + /** + * Handle to the global fs context. + */ + struct GNUNET_FS_Handle *h; + + /** + * Argument to pass to the client in callbacks. + */ + void *client_ctx; + + /** + * File-structure that is being shared. + */ + struct GNUNET_FS_FileInformation *fi; + + /** + * Namespace that we are publishing in, NULL if we have no namespace. + */ + struct GNUNET_FS_Namespace *namespace; + + /** + * ID of the content in the namespace, NULL if we have no namespace. + */ + char *nid; + + /** + * ID for future updates, NULL if we have no namespace or no updates. + */ + char *nuid; + + /** + * ID of the task performing the upload. NO_TASK + * if the upload has completed. + */ + GNUNET_SCHEDULER_TaskIdentifier upload_task; +}; + + +/** + * Handle for controlling an unindexing operation. + */ +struct GNUNET_FS_UnindexContext +{ +}; + + +/** + * Handle for controlling a search. + */ +struct GNUNET_FS_SearchContext +{ +}; + + +/** + * Context for controlling a download. + */ +struct GNUNET_FS_DownloadContext +{ +}; + +struct GNUNET_FS_Namespace +{ + /** + * Reference counter. + */ + unsigned int rc; +}; + + #endif diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index cb3b39995..f1954ea89 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -18,22 +18,75 @@ Boston, MA 02111-1307, USA. */ /** - * @file applications/fs/ecrs/download.c + * @file fs/fs_download.c * @brief DOWNLOAD helper methods (which do the real work). * @author Christian Grothoff */ #include "platform.h" -#include "gnunet_protocols.h" -#include "gnunet_ecrs_lib.h" -#include "gnunet_fs_lib.h" -#include "gnunet_identity_lib.h" -#include "ecrs_core.h" -#include "ecrs.h" +#include "gnunet_fs_service.h" #include "fs.h" -#include "tree.h" -#define DEBUG_DOWNLOAD GNUNET_NO +#define DEBUG_DOWNLOAD GNUNET_YES + + + +/** + * Download parts of a file. Note that this will store + * the blocks at the respective offset in the given file. Also, the + * download is still using the blocking of the underlying FS + * encoding. As a result, the download may *write* outside of the + * given boundaries (if offset and length do not match the 32k FS + * block boundaries).

+ * + * This function should be used to focus a download towards a + * particular portion of the file (optimization), not to strictly + * limit the download to exactly those bytes. + * + * @param h handle to the file sharing subsystem + * @param uri the URI of the file (determines what to download); CHK or LOC URI + * @param filename where to store the file, maybe NULL (then no file is + * created on disk and data must be grabbed from the callbacks) + * @param offset at what offset should we start the download (typically 0) + * @param length how many bytes should be downloaded starting at offset + * @param anonymity anonymity level to use for the download + * @param no_temporaries set to GNUNET_YES to disallow generation of temporary files + * @param recursive should this be a recursive download (useful for directories + * to automatically trigger download of files in the directories) + * @param parent parent download to associate this download with (use NULL + * for top-level downloads; useful for manually-triggered recursive downloads) + * @return context that can be used to control this download + */ +struct GNUNET_FS_DownloadContext * +GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + const char *filename, + unsigned long long offset, + unsigned long long length, + unsigned int anonymity, + int no_temporaries, + int recursive, + struct GNUNET_FS_DownloadContext *parent) +{ + return NULL; +} + +/** + * Stop a download (aborts if download is incomplete). + * + * @param rm handle for the download + * @param do_delete delete files of incomplete downloads + */ +void +GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm, + int do_delete) +{ +} + + + + +#if 0 /** * Node-specific data (not shared, keep small!). 152 bytes. @@ -920,4 +973,6 @@ GNUNET_ECRS_file_download (struct GNUNET_GE_Context *ectx, dpcb, dpcbClosure, tt, ttClosure); } -/* end of download.c */ +#endif + +/* end of fs_download.c */ diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index ac71c8f21..7696dd940 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -34,6 +34,95 @@ #define DEBUG_PUBLISH GNUNET_YES +/** + * Main function that performs the upload. + * @param cls "struct GNUNET_FS_PublishContext" identifies the upload + * @param tc task context + */ +static void +do_upload (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_FS_PublishContext *sc = cls; + + sc->upload_task = GNUNET_SCHEDULER_NO_TASK; + + // FIXME: find next block, process, schedule + // transmission to FS service +} + + +/** + * Publish a file or directory. + * + * @param h handle to the file sharing subsystem + * @param ctx initial value to use for the '*ctx' + * in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event). + * @param fi information about the file or directory structure to publish + * @param namespace namespace to publish the file in, NULL for no namespace + * @param nid identifier to use for the publishd content in the namespace + * (can be NULL, must be NULL if namespace is NULL) + * @param nuid update-identifier that will be used for future updates + * (can be NULL, must be NULL if namespace or nid is NULL) + * @return context that can be used to control the publish operation + */ +struct GNUNET_FS_PublishContext * +GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, + void *ctx, + struct GNUNET_FS_FileInformation *fi, + struct GNUNET_FS_Namespace *namespace, + const char *nid, + const char *nuid) +{ + struct GNUNET_FS_PublishContext *ret; + + ret = GNUNET_malloc (sizeof (struct GNUNET_FS_PublishContext)); + ret->h = h; + ret->client_ctx = ctx; + ret->fi = fi; + ret->namespace = namespace; + if (namespace != NULL) + { + namespace->rc++; + GNUNET_assert (NULL != nid); + ret->nid = GNUNET_strdup (nid); + if (NULL != nuid) + ret->nuid = GNUNET_strdup (nuid); + } + // FIXME: make upload persistent! + ret->upload_task + = GNUNET_SCHEDULER_add_delayed (h->sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_UNIT_ZERO, + &do_upload, + ret); + return ret; +} + + +/** + * Stop an upload. Will abort incomplete uploads (but + * not remove blocks that have already been publishd) or + * simply clean up the state for completed uploads. + * + * @param sc context for the upload to stop + */ +void +GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc) +{ + if (GNUNET_SCHEDULER_NO_TASK != sc->upload_task) + GNUNET_SCHEDULER_cancel (sc->h->sched, sc->upload_task); + // FIXME: remove from persistence DB (?) --- think more about + // shutdown / persistent-resume APIs!!! + GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL); + GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); + GNUNET_free_non_null (sc->nid); + GNUNET_free_non_null (sc->nuid); + GNUNET_free (sc); +} + #if 0 diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 56240af69..51d1fbc1f 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -19,19 +19,71 @@ */ /** - * @file applications/fs/ecrs/search.c + * @file fs/fs_search.c * @brief Helper functions for searching. * @author Christian Grothoff */ #include "platform.h" -#include "gnunet_protocols.h" -#include "gnunet_fs_lib.h" -#include "gnunet_ecrs_lib.h" -#include "ecrs_core.h" -#include "ecrs.h" +#include "gnunet_fs_service.h" +#include "fs.h" + +#define DEBUG_SEARCH GNUNET_YES + + +/** + * Start search for content. + * + * @param h handle to the file sharing subsystem + * @param uri specifies the search parameters; can be + * a KSK URI or an SKS URI. + * @param anonymity desired level of anonymity + * @return context that can be used to control the search + */ +struct GNUNET_FS_SearchContext * +GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + unsigned int anonymity) +{ + return NULL; +} + + +/** + * Pause search. + * + * @param sc context for the search that should be paused + */ +void +GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc) +{ +} + +/** + * Continue paused search. + * + * @param sc context for the search that should be resumed + */ +void +GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc) +{ +} -#define DEBUG_SEARCH GNUNET_NO + +/** + * Stop search for content. + * + * @param sc context for the search that should be stopped + */ +void +GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc) +{ +} + + + + +#if 0 /** * Context for an individual search. Followed @@ -568,5 +620,6 @@ GNUNET_ECRS_search (struct GNUNET_GE_Context *ectx, return GNUNET_OK; } +#endif -/* end of search.c */ +/* end of fs_search.c */ diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index ef63e798e..8fb13a644 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -19,25 +19,62 @@ */ /** - * @file applications/fs/ecrs/unindex.c + * @file fs/fs_unindex.c * @author Krista Bennett * @author Christian Grothoff - * - * Unindex file. + * @brief Unindex file. * * TODO: * - code cleanup (share more with upload.c) */ #include "platform.h" -#include "gnunet_protocols.h" -#include "gnunet_ecrs_lib.h" -#include "gnunet_fs_lib.h" -#include "gnunet_getoption_lib.h" -#include "ecrs_core.h" -#include "ecrs.h" +#include "gnunet_fs_service.h" #include "fs.h" -#include "tree.h" + +/** + * Iterate over all indexed files. + * + * @param h handle to the file sharing subsystem + * @param iterator function to call on each indexed file + * @param iterator_cls closure for iterator + */ +void +GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, + GNUNET_FS_IndexedFileProcessor iterator, + void *iterator_cls) +{ +} + + +/** + * Unindex a file. + * + * @param h handle to the file sharing subsystem + * @param filename file to unindex + * @return NULL on error, otherwise handle + */ +struct GNUNET_FS_UnindexContext * +GNUNET_FS_unindex (struct GNUNET_FS_Handle *h, + const char *filename) +{ + return NULL; +} + + +/** + * Clean up after completion of an unindex operation. + * + * @param uc handle + */ +void +GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) +{ +} + + + +#if 0 #define STRICT_CHECKS GNUNET_NO @@ -391,4 +428,6 @@ FAILURE: return GNUNET_SYSERR; } -/* end of unindex.c */ +#endif + +/* end of fs_unindex.c */ diff --git a/src/fs/fs_test.c b/src/fs/test_fs.c similarity index 100% rename from src/fs/fs_test.c rename to src/fs/test_fs.c diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 7c6fc0549..4664c4cee 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -1763,11 +1763,11 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, */ struct GNUNET_FS_PublishContext * GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, - void *ctx, - const struct GNUNET_FS_FileInformation *fi, - struct GNUNET_FS_Namespace *namespace, - const char *nid, - const char *nuid); + void *ctx, + struct GNUNET_FS_FileInformation *fi, + struct GNUNET_FS_Namespace *namespace, + const char *nid, + const char *nuid); /** -- 2.25.1