From 5c2efc1952243768786f67d9fe8733cba1be0c2b Mon Sep 17 00:00:00 2001 From: LRN Date: Sun, 3 Mar 2013 01:57:19 +0000 Subject: Be able to open existing namespaces --- src/fs/fs_namespace.c | 43 +++++++++++++++++++++++++++++++++++++++++ src/include/gnunet_fs_service.h | 13 +++++++++++++ 2 files changed, 56 insertions(+) (limited to 'src') diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 177af7efc..3558b0ae6 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c @@ -304,6 +304,49 @@ GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name) } +/** + * Open the namespace with the given name; if it does not exist, + * or the key file is corrupted, the function fails. + * + * @param h handle to the file sharing subsystem + * @param name name of the namespace + * @return handle to the namespace, + * NULL on error (i.e. invalid filename, non-existent filename) + */ +struct GNUNET_FS_Namespace * +GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name) +{ + char *dn; + char *fn; + struct GNUNET_FS_Namespace *ret; + + dn = get_namespace_directory (h); + if (NULL == dn) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Can't determine where namespace directory is\n")); + return NULL; + } + GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name); + GNUNET_free (dn); + ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); + ret->h = h; + ret->rc = 1; + ret->key = GNUNET_CRYPTO_rsa_key_create_from_existing_file (fn); + if (NULL == ret->key) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read private key for namespace `%s'\n"), name); + GNUNET_free (ret); + GNUNET_free (fn); + return NULL; + } + ret->name = GNUNET_strdup (name); + ret->filename = fn; + return ret; +} + + /** * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_start'. * diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 1cb5028b3..5b0217a19 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -2239,6 +2239,19 @@ struct GNUNET_FS_Namespace * GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name); +/** + * Open the namespace with the given name; if it does not exist, + * or the key file is corrupted, the function fails. + * + * @param h handle to the file sharing subsystem + * @param name name of the namespace + * @return handle to the namespace, + * NULL on error (i.e. invalid filename, non-existent filename) + */ +struct GNUNET_FS_Namespace * +GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name); + + /** * Context for creating a namespace asynchronously. */ -- cgit v1.2.3