gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33477 - gnunet-gtk/src/conversation


From: gnunet
Subject: [GNUnet-SVN] r33477 - gnunet-gtk/src/conversation
Date: Mon, 2 Jun 2014 20:47:15 +0200

Author: grothoff
Date: 2014-06-02 20:47:15 +0200 (Mon, 02 Jun 2014)
New Revision: 33477

Modified:
   gnunet-gtk/src/conversation/gnunet-conversation-gtk.c
   gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c
Log:
adding logic to publish our phone record

Modified: gnunet-gtk/src/conversation/gnunet-conversation-gtk.c
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk.c       2014-06-02 
18:06:26 UTC (rev 33476)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk.c       2014-06-02 
18:47:15 UTC (rev 33477)
@@ -31,7 +31,9 @@
 #include "gnunet-conversation-gtk_history.h"
 #include "gnunet-conversation-gtk_import.h"
 #include "gnunet-conversation-gtk_phone.h"
+#include "gnunet-conversation-gtk_zones.h"
 
+
 /**
  * Handle to our main loop.
  */

Modified: gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c        
2014-06-02 18:06:26 UTC (rev 33476)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c        
2014-06-02 18:47:15 UTC (rev 33477)
@@ -28,6 +28,7 @@
 #include "gnunet-conversation-gtk.h"
 #include "gnunet-conversation-gtk_contacts.h"
 #include "gnunet-conversation-gtk_egos.h"
+#include "gnunet-conversation-gtk_import.h"
 
 /**
  * Handle to the namestore.
@@ -35,12 +36,53 @@
 static struct GNUNET_NAMESTORE_Handle *ns;
 
 /**
- * Queue entry for the 'add' operation.
+ * Queue entry for the 'add contact' operation.
  */
-static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
+static struct GNUNET_NAMESTORE_QueueEntry *add_contact_qe;
 
+/**
+ * Queue entry for the 'add phone' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *add_phone_qe;
 
 /**
+ * Queue entry for the 'remove phone' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *remove_phone_qe;
+
+/**
+ * Flag set to #GNUNET_YES if we are in shutdown.
+ */
+static int in_shutdown;
+
+/**
+ * Flag set to #GNUNET_YES if an 'add phone' operation is
+ * waiting for a 'remove phone' operation to complete first.
+ */
+static int add_waiting;
+
+/**
+ * Our current phone label.
+ */
+static char *phone_label;
+
+/**
+ * Current private key for the phone entry's zone.
+ */
+static struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey;
+
+/**
+ * Our current phone record.
+ */
+static struct GNUNET_GNSRECORD_Data my_rd;
+
+/**
+ * Binary data for the current phone record (`my_rd.data`).
+ */
+static char *my_rd_data;
+
+
+/**
  * Continuation called to notify client about result of the
  * operation.
  *
@@ -51,14 +93,14 @@
  * @param emsg NULL on success, otherwise an error message
  */
 static void
-add_continuation (void *cls,
-                  int32_t success,
-                  const char *emsg)
+add_contact_continuation (void *cls,
+                          int32_t success,
+                          const char *emsg)
 {
   if (GNUNET_YES != success)
     GCG_log (_("Adding contact failed: %s\n"),
              (GNUNET_NO == success) ? _("record exists") : emsg);
-  add_qe = NULL;
+  add_contact_qe = NULL;
 }
 
 
@@ -77,7 +119,7 @@
   struct GNUNET_IDENTITY_Ego *ego;
   const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey;
 
-  if (NULL != add_qe)
+  if (NULL != add_contact_qe)
   {
     GCG_log (_("Adding contact failed: %s\n"),
              _("previous operation still pending"));
@@ -107,16 +149,93 @@
   zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
   /* FIXME: we should check if the 'name' already exists,
      and not do this if it does... */
-  add_qe
+  add_contact_qe
     =  GNUNET_NAMESTORE_records_store (ns,
                                        zone_pkey,
                                        name,
                                        1, &rd,
-                                       &add_continuation, NULL);
+                                       &add_contact_continuation, NULL);
 }
 
 
 /**
+ * Continuation called to notify client about result of the
+ * add operation.  Finish 'add phone' operation.
+ *
+ * @param cls closure
+ * @param success #GNUNET_SYSERR on failure (including timeout/queue 
drop/failure to validate)
+ *                #GNUNET_NO if content was already there or not found
+ *                #GNUNET_YES (or other positive value) on success
+ * @param emsg NULL on success, otherwise an error message
+ */
+static void
+add_phone_continuation (void *cls,
+                           int32_t success,
+                           const char *emsg)
+{
+  add_phone_qe = NULL;
+  if (GNUNET_SYSERR == success)
+  {
+    GCG_log (_("Failed to publish my PHONE record: %s\n"),
+             emsg);
+    GNUNET_free (phone_label);
+    phone_label = NULL;
+  }
+}
+
+
+/**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure, NULL
+ * @param zone private key of the zone; NULL on disconnect
+ * @param label label of the records; NULL on disconnect
+ * @param rd_count number of entries in @a rd array, 0 if label was deleted
+ * @param rd array of records with data to store
+ */
+static void
+add_phone_handle_existing_records (void *cls,
+                                   const struct GNUNET_CRYPTO_EcdsaPrivateKey 
*zone,
+                                   const char *label,
+                                   unsigned int rd_count,
+                                   const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1];
+
+  add_phone_qe = NULL;
+  memcpy (rd_new, rd, sizeof (struct GNUNET_GNSRECORD_Data) * rd_count);
+  rd_new[rd_count] = my_rd;
+  add_phone_qe = GNUNET_NAMESTORE_records_store (ns,
+                                                 zone,
+                                                 label,
+                                                 rd_count + 1, rd_new,
+                                                 &add_phone_continuation,
+                                                 NULL);
+}
+
+
+/**
+ * Add the data from #my_rd under the #phone_label to the namestore.
+ */
+static void
+add_phone ()
+{
+  struct GNUNET_IDENTITY_Ego *ego;
+
+  GNUNET_assert (NULL == remove_phone_qe);
+  GNUNET_assert (NULL == add_phone_qe);
+  add_waiting = GNUNET_NO;
+  ego = GCG_EGOS_get_selected_ego ();
+  zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
+  add_phone_qe = GNUNET_NAMESTORE_records_lookup (ns,
+                                                  &zone_pkey,
+                                                  phone_label,
+                                                  
&add_phone_handle_existing_records,
+                                                  NULL);
+}
+
+
+/**
  * Add phone address to namestore.
  *
  * @param label label to use for the phone record
@@ -126,17 +245,125 @@
 GSC_add_phone (const gchar *label,
                const struct GNUNET_GNSRECORD_Data *rd)
 {
-  GNUNET_break (0); // FIXME: not implemented!
+  if (NULL != add_phone_qe)
+  {
+    GNUNET_NAMESTORE_cancel (add_phone_qe);
+    add_phone_qe = NULL;
+  }
+  if (NULL != phone_label)
+    GSC_remove_phone ();
+  GNUNET_break (NULL == phone_label);
+  GNUNET_free_non_null (my_rd_data);
+  phone_label = GNUNET_strdup (label);
+  my_rd = *rd;
+  my_rd.data = my_rd_data = GNUNET_malloc (rd->data_size);
+  memcpy (my_rd_data, rd->data, rd->data_size);
+  add_waiting = GNUNET_YES;
+  if (NULL != remove_phone_qe)
+    return; /* do not add another record until previous one is removed */
+  add_phone ();
 }
 
 
 /**
+ * Run last parts of shutdown operation (after last
+ * remove has completed).
+ */
+static void
+finish_shutdown ()
+{
+  if (NULL != ns)
+  {
+    GNUNET_NAMESTORE_disconnect (ns);
+    ns = NULL;
+  }
+  GNUNET_free_non_null (my_rd_data);
+  memset (&my_rd, 0, sizeof (my_rd));
+  GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
+}
+
+
+/**
+ * Continuation called to notify client about result of the
+ * remove operation.  Finish remove operation and continue
+ * with 'add phone' operation if one is pending.
+ *
+ * @param cls closure
+ * @param success #GNUNET_SYSERR on failure (including timeout/queue 
drop/failure to validate)
+ *                #GNUNET_NO if content was already there or not found
+ *                #GNUNET_YES (or other positive value) on success
+ * @param emsg NULL on success, otherwise an error message
+ */
+static void
+remove_phone_continuation (void *cls,
+                           int32_t success,
+                           const char *emsg)
+{
+  remove_phone_qe = NULL;
+  if (GNUNET_SYSERR == success)
+    GCG_log (_("Failed to remove PHONE record: %s\n"),
+             emsg);
+  if (GNUNET_YES == add_waiting)
+    add_phone ();
+  if (GNUNET_YES == in_shutdown)
+    finish_shutdown ();
+}
+
+
+/**
+ * Process records stored in the namestore.  Locates our
+ * PHONE record and removes it.
+ *
+ * @param cls closure, NULL
+ * @param zone private key of the zone; NULL on disconnect
+ * @param label label of the records; NULL on disconnect
+ * @param rd_count number of entries in @a rd array, 0 if label was deleted
+ * @param rd array of records with data to store
+ */
+static void
+remove_phone_handle_existing_records (void *cls,
+                                      const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                                      const char *label,
+                                      unsigned int rd_count,
+                                      const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct GNUNET_GNSRECORD_Data rd_left[rd_count];
+  unsigned int i;
+  unsigned int j;
+
+  remove_phone_qe = NULL;
+  j = 0;
+  for (i=0;i<rd_count;i++)
+  {
+    if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type)
+      continue;
+    rd_left[j++] = rd[i];
+  }
+  remove_phone_qe = GNUNET_NAMESTORE_records_store (ns,
+                                                    zone,
+                                                    label,
+                                                    j, rd_left,
+                                                    &remove_phone_continuation,
+                                                    NULL);
+}
+
+
+/**
  * Remove previously added phone address from namestore.
  */
 void
 GSC_remove_phone ()
 {
-  GNUNET_break (0); // FIXME: not implemented!
+  if (NULL == phone_label)
+    return;
+  GNUNET_assert (NULL == remove_phone_qe);
+  remove_phone_qe = GNUNET_NAMESTORE_records_lookup (ns,
+                                                     &zone_pkey,
+                                                     phone_label,
+                                                     
&remove_phone_handle_existing_records,
+                                                     NULL);
+  GNUNET_free (phone_label);
+  phone_label = NULL;
 }
 
 
@@ -156,17 +383,24 @@
 void
 GCG_IMPORT_shutdown ()
 {
-  if (NULL != add_qe)
+  if (NULL != add_contact_qe)
   {
-    GNUNET_NAMESTORE_cancel (add_qe);
-    add_qe = NULL;
+    GNUNET_NAMESTORE_cancel (add_contact_qe);
+    add_contact_qe = NULL;
   }
-  if (NULL != ns)
+  if (NULL != add_phone_qe)
   {
-    GNUNET_NAMESTORE_disconnect (ns);
-    ns = NULL;
+    GNUNET_NAMESTORE_cancel (add_phone_qe);
+    add_phone_qe = NULL;
   }
+  add_waiting = GNUNET_NO;
+  in_shutdown = GNUNET_YES;
+  GSC_remove_phone ();
+  if (NULL != remove_phone_qe)
+    return;
+  finish_shutdown ();
 }
 
+
 /* end of gnunet-conversation-gtk_import.c */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]