[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29098 - in gnunet-gtk/src: fs identity
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29098 - in gnunet-gtk/src: fs identity |
Date: |
Sat, 7 Sep 2013 22:07:56 +0200 |
Author: grothoff
Date: 2013-09-07 22:07:56 +0200 (Sat, 07 Sep 2013)
New Revision: 29098
Added:
gnunet-gtk/src/identity/gnunet-identity-gtk.h
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
gnunet-gtk/src/identity/Makefile.am
gnunet-gtk/src/identity/gnunet-identity-gtk.c
gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c
gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.h
Log:
-first implementation of execute function for ego advertisement
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.c 2013-09-07 19:14:20 UTC (rev
29097)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.c 2013-09-07 20:07:56 UTC (rev
29098)
@@ -28,6 +28,7 @@
#include "gnunet-fs-gtk.h"
#include "gnunet-fs-gtk_event-handler.h"
+
/**
* Converts metadata specified by @a data of size @a data_len
* and saved in format @a format to UTF-8 encoded string.
@@ -196,13 +197,13 @@
/**
- * mmap the given file and run the GNUNET_FS_directory_list_contents
+ * mmap the given file and run the #GNUNET_FS_directory_list_contents
* function on it.
*
* @param filename name with the directory
* @param dep function to call on each entry
- * @param dep_cls closure for 'dep'
- * @return GNUNET_OK on success
+ * @param dep_cls closure for @a dep
+ * @return #GNUNET_OK on success
*/
int
GNUNET_FS_GTK_mmap_and_scan (const char *filename,
@@ -260,13 +261,13 @@
* the respective meta data.
*
* @param meta meta data to inspect
- * @param is_a_dup is set to GNUNET_YES if the result is a dup, and there was
- * no description to be found. GNUNET_NO otherwise.
+ * @param is_a_dup is set to #GNUNET_YES if the result is a dup, and there was
+ * no description to be found. #GNUNET_NO otherwise.
* @return description of the result in utf-8, never NULL
*/
char *
-GNUNET_FS_GTK_get_description_from_metadata (
- const struct GNUNET_CONTAINER_MetaData *meta, int *is_a_dup)
+GNUNET_FS_GTK_get_description_from_metadata (const struct
GNUNET_CONTAINER_MetaData *meta,
+ int *is_a_dup)
{
char *desc;
char *utf8_desc;
@@ -438,10 +439,11 @@
*
* @param rr row reference
* @param iter pointer to an iter structure to fill
- * @return GNUNET_OK if iter was filled, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK if iter was filled, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr, GtkTreeIter *iter)
+GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr,
+ GtkTreeIter *iter)
{
int result = GNUNET_SYSERR;
if (rr != NULL)
@@ -464,6 +466,7 @@
return result;
}
+
/**
* Creates a GtkTreeRowReference from a GtkTreeIter.
*
@@ -487,8 +490,29 @@
return result;
}
+
+/**
+ * Fills "next_iter" with iterator for an item that comes next in the tree
+ * after "iter".
+ * Next item is, in order of precedence:
+ * 1) First child of "iter", if "iter" has children and "allow_children"
+ * is enabled.
+ * 2) Next sibling of "iter", unless "iter" is the last sibling.
+ * If none of those are present, function recursively checks parents of
+ * "iter" until it finds next item or runs out of parents.
+ *
+ * @param model a model to reference
+ * @param iter an iter that points to current row in the model
+ * @param allow_children whether child of "iter" is considered to be next.
+ * @param next_iter will be filled with the next row in the model on success
+ * @return TRUE if next_iter is set to a valid iter,
+ * FALSE if ran out of parents
+ */
gboolean
-GNUNET_GTK_tree_model_get_next_flat_iter (GtkTreeModel *model, GtkTreeIter
*iter, gboolean allow_children, GtkTreeIter *next_iter)
+GNUNET_GTK_tree_model_get_next_flat_iter (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gboolean allow_children,
+ GtkTreeIter *next_iter)
{
GtkTreeIter current_iter = *iter;
while (TRUE)
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.h 2013-09-07 19:14:20 UTC (rev
29097)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.h 2013-09-07 20:07:56 UTC (rev
29098)
@@ -73,7 +73,7 @@
* @param filename name with the directory
* @param dep function to call on each entry
* @param dep_cls closure for @a dep
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
*/
int
GNUNET_FS_GTK_mmap_and_scan (const char *filename,
Modified: gnunet-gtk/src/identity/Makefile.am
===================================================================
--- gnunet-gtk/src/identity/Makefile.am 2013-09-07 19:14:20 UTC (rev 29097)
+++ gnunet-gtk/src/identity/Makefile.am 2013-09-07 20:07:56 UTC (rev 29098)
@@ -10,7 +10,7 @@
bin_PROGRAMS = gnunet-identity-gtk
gnunet_identity_gtk_SOURCES = \
- gnunet-identity-gtk.c \
+ gnunet-identity-gtk.c gnunet-identity-gtk.h \
gnunet-identity-gtk_about.c \
gnunet-identity-gtk_advertise.c gnunet-identity-gtk_advertise.h
gnunet_identity_gtk_LDADD = \
Modified: gnunet-gtk/src/identity/gnunet-identity-gtk.c
===================================================================
--- gnunet-gtk/src/identity/gnunet-identity-gtk.c 2013-09-07 19:14:20 UTC
(rev 29097)
+++ gnunet-gtk/src/identity/gnunet-identity-gtk.c 2013-09-07 20:07:56 UTC
(rev 29098)
@@ -108,10 +108,12 @@
/**
- * Get cfg.
+ * Get our configuration.
+ *
+ * @return configuration handle
*/
-static const struct GNUNET_CONFIGURATION_Handle *
-get_configuration ()
+const struct GNUNET_CONFIGURATION_Handle *
+GIG_get_configuration ()
{
return GNUNET_GTK_main_loop_get_configuration (ml);
}
@@ -384,6 +386,7 @@
{
struct OperationContext *oc;
+ GIG_advertise_shutdown_ ();
while (NULL != (oc = oc_head))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -527,7 +530,7 @@
gtk_widget_show (main_window);
gtk_window_present (GTK_WINDOW (main_window));
}
- identity = GNUNET_IDENTITY_connect (get_configuration (),
+ identity = GNUNET_IDENTITY_connect (GIG_get_configuration (),
&add_ego,
NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
Added: gnunet-gtk/src/identity/gnunet-identity-gtk.h
===================================================================
--- gnunet-gtk/src/identity/gnunet-identity-gtk.h
(rev 0)
+++ gnunet-gtk/src/identity/gnunet-identity-gtk.h 2013-09-07 20:07:56 UTC
(rev 29098)
@@ -0,0 +1,40 @@
+/*
+ This file is part of GNUnet
+ (C) 2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/identity/gnunet-identity-gtk.h
+ * @author Christian Grothoff
+ */
+#include <gnunet/gnunet_util_lib.h>
+
+
+#ifndef GNUNET_IDENTITY_GTK_H
+#define GNUNET_IDENTITY_GTK_H
+
+/**
+ * Get our configuration.
+ *
+ * @return configuration handle
+ */
+const struct GNUNET_CONFIGURATION_Handle *
+GIG_get_configuration (void);
+
+
+#endif
Modified: gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c
===================================================================
--- gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c 2013-09-07
19:14:20 UTC (rev 29097)
+++ gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.c 2013-09-07
20:07:56 UTC (rev 29098)
@@ -24,6 +24,7 @@
* @author Christian Grothoff
*/
#include "gnunet-identity-gtk_advertise.h"
+#include "gnunet-identity-gtk.h"
#include <gnunet/gnunet_fs_service.h>
@@ -148,8 +149,122 @@
};
+/**
+ * Context for the publishing operation.
+ */
+struct PublishContext
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct PublishContext *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct PublishContext *prev;
+
+ /**
+ * Handle to FS subsystem.
+ */
+ struct GNUNET_FS_Handle *fs;
+
+ /**
+ * Handle to the publish operation.
+ */
+ struct GNUNET_FS_PublishKskContext *pub;
+
+};
+
+
/**
+ * Kept in a DLL.
+ */
+static struct PublishContext *pc_head;
+
+/**
+ * Kept in a DLL.
+ */
+static struct PublishContext *pc_tail;
+
+
+/**
+ * Shutdown advertisement subsystem, this process is terminating.
+ */
+void
+GIG_advertise_shutdown_ ()
+{
+ struct PublishContext *pc;
+
+ while (NULL != (pc = pc_head))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Aborting advertising operation due to shutdown.\n"));
+ GNUNET_CONTAINER_DLL_remove (pc_head,
+ pc_tail,
+ pc);
+ GNUNET_FS_publish_ksk_cancel (pc->pub);
+ GNUNET_FS_stop (pc->fs);
+ GNUNET_free (pc);
+ }
+}
+
+
+/**
+ * Function called once we published the advertisement.
+ *
+ * @param cls closure with the `struct PublishContext`
+ * @param uri URI under which the block is now available, NULL on error
+ * @param emsg error message, NULL on success
+ */
+static void
+publish_continuation (void *cls,
+ const struct GNUNET_FS_Uri *uri,
+ const char *emsg)
+{
+ struct PublishContext *pc = cls;
+
+ pc->pub = NULL;
+ if (NULL == uri)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to advertise ego: %s\n"),
+ emsg);
+ /* FIXME: might want to output to GUI... */
+ }
+ GNUNET_FS_stop (pc->fs);
+ GNUNET_CONTAINER_DLL_remove (pc_head,
+ pc_tail,
+ pc);
+ GNUNET_free (pc);
+}
+
+
+/**
+ * Notification of FS to a client about the progress of an
+ * operation. Callbacks of this type will be used for uploads,
+ * downloads and searches. Some of the arguments depend a bit
+ * in their meaning on the context in which the callback is used.
+ *
+ * @param cls closure
+ * @param info details about the event, specifying the event type
+ * and various bits about the event
+ * @return client-context (for the next progress call
+ * for this operation; should be set to NULL for
+ * SUSPEND and STOPPED events). The value returned
+ * will be passed to future callbacks in the respective
+ * field in the `struct GNUNET_FS_ProgressInfo`.
+ */
+static void *
+progress_cb (void *cls,
+ const struct GNUNET_FS_ProgressInfo *info)
+{
+ return NULL;
+}
+
+
+/**
* The user terminated the dialog. Perform the appropriate action.
*
* @param dialog the advertisement dialog
@@ -162,12 +277,89 @@
gpointer user_data)
{
struct AdvertiseContext *ac = user_data;
+ struct GNUNET_FS_Uri *ksk_uri;
+ struct GNUNET_FS_Uri *uri;
+ gchar *keyword;
+ struct GNUNET_CONTAINER_MetaData *meta;
+ guint ntype;
+ gchar *value;
+ GtkTreeIter iter;
+ struct GNUNET_FS_BlockOptions bo;
+ struct GNUNET_CRYPTO_EccPublicKey pk;
+ struct PublishContext *pc;
- if (GTK_RESPONSE_OK == response_id)
+ if (GTK_RESPONSE_OK != response_id)
+ goto cleanup;
+ ksk_uri = NULL;
+ if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->keywords), &iter))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ do
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter,
+ KEYWORDS_MC_KEYWORD, &keyword,
+ -1);
+ if (NULL == ksk_uri)
+ ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **)
&keyword);
+ else
+ GNUNET_FS_uri_ksk_add_keyword (ksk_uri, keyword, GNUNET_NO);
+ g_free (keyword);
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->keywords), &iter));
+
+ meta = GNUNET_CONTAINER_meta_data_create ();
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->metadata),
+ &iter))
+ {
+ do
{
- GNUNET_break (0); // FIXME: not implemented
+ gtk_tree_model_get (GTK_TREE_MODEL (ac->metadata), &iter,
+ METADATA_MC_TYPE_AS_ENUM, &ntype,
+ METADATA_MC_VALUE, &value,
+ -1);
+ if (ntype > 0)
+ {
+ GNUNET_CONTAINER_meta_data_insert (meta, "<user>",
+ ntype,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain", value,
+ strlen (value) + 1);
+ }
+ g_free (value);
}
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter));
+ }
+ bo.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; /* FIXME: allow user to
specify */
+ bo.anonymity_level = 1; /* FIXME: allow user to specify */
+ bo.content_priority = 1000; /* FIXME: allow user to specify */
+ bo.replication_level = 5;
+ GNUNET_CRYPTO_ecc_key_get_public (&ac->priv,
+ &pk);
+ uri = GNUNET_FS_uri_sks_create (&pk,
+ "root"); /* FIXME: allow user to specify! */
+
+ pc = GNUNET_new (struct PublishContext);
+ pc->fs = GNUNET_FS_start (GIG_get_configuration (),
+ "gnunet-identity-gtk",
+ &progress_cb, pc,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
+ pc->pub = GNUNET_FS_publish_ksk (pc->fs,
+ ksk_uri,
+ meta,
+ uri,
+ &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE,
+ &publish_continuation, pc);
+ GNUNET_CONTAINER_DLL_insert (pc_head,
+ pc_tail,
+ pc);
+ GNUNET_FS_uri_destroy (uri);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ cleanup:
gtk_widget_destroy (ac->dialog);
g_object_unref (G_OBJECT (ac->builder));
GNUNET_free (ac);
Modified: gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.h
===================================================================
--- gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.h 2013-09-07
19:14:20 UTC (rev 29097)
+++ gnunet-gtk/src/identity/gnunet-identity-gtk_advertise.h 2013-09-07
20:07:56 UTC (rev 29098)
@@ -29,7 +29,15 @@
#include "gnunet_gtk.h"
+
/**
+ * Shutdown advertisement subsystem, this process is terminating.
+ */
+void
+GIG_advertise_shutdown_ ();
+
+
+/**
* Run the dialog for advertising a namespace.
*
* @param priv private key of the namespace to advertise
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29098 - in gnunet-gtk/src: fs identity,
gnunet <=