gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27893 - gnunet-gtk/src/setup


From: gnunet
Subject: [GNUnet-SVN] r27893 - gnunet-gtk/src/setup
Date: Wed, 10 Jul 2013 17:53:47 +0200

Author: grothoff
Date: 2013-07-10 17:53:47 +0200 (Wed, 10 Jul 2013)
New Revision: 27893

Modified:
   gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-fix #2931

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2013-07-10 15:36:24 UTC (rev 
27892)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2013-07-10 15:53:47 UTC (rev 
27893)
@@ -182,7 +182,7 @@
 
 
 /**
- * Closure for 'check_name_validity_and_remove_proc'.
+ * Closure for 'operation_done_cont'.
  */
 struct OperationContext
 {
@@ -206,6 +206,50 @@
 
 
 /**
+ * Closure for 'merge_with_existing_records'.
+ */
+struct MoveOperationContext
+{
+
+  /**
+   * Kept in a DLL.
+   */
+  struct MoveOperationContext *next;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct MoveOperationContext *prev;
+
+  /**
+   * Associated namestore operation.
+   */
+  struct GNUNET_NAMESTORE_QueueEntry *qe;
+
+  /**
+   * Info from editing dialog.
+   */
+  struct EditDialogContext *edc;
+
+  /**
+   * Private key of target zone.
+   */
+  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+
+  /**
+   * Data to free.
+   */
+  void *data;
+
+  /**
+   * Record to merge.
+   */
+  struct GNUNET_NAMESTORE_RecordData rd;
+
+};
+
+
+/**
  * Information we keep per name.
  */
 struct RecordInfo
@@ -264,6 +308,16 @@
 static struct OperationContext *oc_tail;
 
 /**
+ * Head of linked list of active operations.
+ */
+static struct MoveOperationContext *moc_head;
+
+/**
+ * Tail of linked list of active operations.
+ */
+static struct MoveOperationContext *moc_tail;
+
+/**
  * Name of our zone as a string.
  */
 static char *zone_as_string;
@@ -557,11 +611,39 @@
 
 
 /**
+ * Release the record info.
+ *
+ * @param cls NULL
+ * @param key unused
+ * @param value a RecordInfo to release
+ * @return GNUNET_OK (continue to iterate)
+ */
+static int
+release_ri (void *cls,
+           const struct GNUNET_HashCode *key,
+           void *value)
+{
+  struct RecordInfo *ri = value;
+
+  gtk_tree_row_reference_free (ri->rr);
+  GNUNET_free_non_null (ri->data);
+  GNUNET_free (ri->name);
+  GNUNET_break (GNUNET_YES ==
+               GNUNET_CONTAINER_multihashmap_remove (n2r, key, ri));
+  GNUNET_free (ri);
+  return GNUNET_OK;
+}
+
+
+/**
  * Clear all entries in the zone view and hide the tree view.
  */
 static void
 clear_zone_view ()
 {
+  GNUNET_CONTAINER_multihashmap_iterate (n2r,
+                                        &release_ri,
+                                        NULL);
   gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_zone_selection_hbuttonbox")));
   gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_status_label")));
   gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_main_scrolledwindow")));
@@ -626,7 +708,57 @@
 }
 
 
+
 /**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure
+ * @param zone_key public key of the zone
+ * @param freshness when does the corresponding block in the DHT expire (until
+ *               when should we never do a DHT lookup for the same name 
again)?; 
+ *               GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type 
in the namestore,
+ *               or the expiration time of the block in the namestore (even if 
there are zero
+ *               records matching the desired record type)
+ * @param name name that is being mapped (at most 255 characters long)
+ * @param rd_count number of entries in 'rd' array
+ * @param rd array of records with data to store
+ * @param signature signature of the record block, NULL if signature is 
unavailable (i.e. 
+ *        because the user queried for a particular record type only)
+ */
+static void
+merge_with_existing_records (void *cls,
+                            const struct 
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
+                            struct GNUNET_TIME_Absolute freshness,             
            
+                            const char *name,
+                            unsigned int rd_count,
+                            const struct GNUNET_NAMESTORE_RecordData *rd,
+                            const struct GNUNET_CRYPTO_EccSignature *signature)
+{
+  struct MoveOperationContext *moc = cls;
+  struct EditDialogContext *edc = moc->edc;
+  struct GNUNET_NAMESTORE_RecordData rd_new[rd_count + 1];
+  struct OperationContext *oc;
+
+  GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc);
+  memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
+  rd_new[rd_count] = moc->rd;
+  /* FIXME: sanity-check merge... */
+  oc = GNUNET_new (struct OperationContext);
+  GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
+  oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 
+                                                    moc->pk,
+                                                    edc->name,
+                                                    rd_count + 1,
+                                                    rd_new,
+                                                    &operation_done_cont, oc);
+  GNUNET_CRYPTO_ecc_key_free (moc->pk);
+  GNUNET_free (moc->data);
+  GNUNET_free (moc);
+  free_edit_dialog_context (edc);
+}
+
+
+/**
  * The edit dialog completed; update the namestore and the 
  * view based on the new values in 'edc'.
  *
@@ -745,26 +877,11 @@
     {
       char *keyfile;
       struct GNUNET_CRYPTO_EccPrivateKey *pk;
-
-      /* zone changed, remove record from old zone, add to new zone! */
-      if (GNUNET_YES == edc->old_record_in_namestore)
-      {
-       /* remove item from tree view and namestore */  
-       struct GNUNET_NAMESTORE_RecordData rd_new[rd_count - 1];
-       
-       GNUNET_assert (NULL != ri);
-       memcpy (rd_new, rd_old, (rd_count - 1) * sizeof (struct 
GNUNET_NAMESTORE_RecordData));
-       rd_new[edc->off] = rd_old[rd_count - 1];
-       oc = GNUNET_new (struct OperationContext);
-       GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
-       oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 
-                                                          pkey, edc->name,
-                                                          rd_count + 1,
-                                                          rd_new,
-                                                          
&operation_done_cont, oc);
-      }
-
-      /* now add item to target zone */
+      struct MoveOperationContext *moc;
+      struct GNUNET_CRYPTO_ShortHashCode target_zone_hash;
+      struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pubkey;
+      
+      /* determine target zone */
       if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
                                                                "gns",
                                                                
edc->new_zone_option,
@@ -787,10 +904,41 @@
                            NULL);
        break;
       }
-      GNUNET_break (0); // not implemented
-      /* FIXME: get target zone records, merge with new one, commit! */
-      GNUNET_CRYPTO_ecc_key_free (pk);
-      break;
+      GNUNET_CRYPTO_ecc_key_get_public (pk, &pubkey);
+      GNUNET_CRYPTO_short_hash (&pubkey,
+                               sizeof (struct 
GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
+                               &target_zone_hash);
+      moc = GNUNET_new (struct MoveOperationContext);
+      moc->data = data;
+      moc->rd = rd;
+      moc->edc = edc;
+      moc->pk = pk;
+      GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc);
+      moc->qe = GNUNET_NAMESTORE_lookup_record (namestore, 
+                                               &target_zone_hash,
+                                               edc->name,
+                                               0 /* all */,
+                                               &merge_with_existing_records,
+                                               moc);      
+      /* zone changed, remove record from old zone, add to new zone! */
+      if (GNUNET_YES == edc->old_record_in_namestore)
+      {
+       /* remove item from tree view and namestore */  
+       struct GNUNET_NAMESTORE_RecordData rd_new[rd_count - 1];
+       
+       GNUNET_assert (NULL != ri);
+       memcpy (rd_new, rd_old, (rd_count - 1) * sizeof (struct 
GNUNET_NAMESTORE_RecordData));
+       rd_new[edc->off] = rd_old[rd_count - 1];
+       oc = GNUNET_new (struct OperationContext);
+       GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
+       oc->qe = GNUNET_NAMESTORE_record_put_by_authority (namestore, 
+                                                          pkey, edc->name,
+                                                          rd_count - 1,
+                                                          rd_new,
+                                                          
&operation_done_cont, oc);
+
+      }
+      return;
     }
     break;
   default:
@@ -840,6 +988,10 @@
     edc->n_exp_time = rd_old[off].expiration_time;
     edc->old_record_in_namestore = GNUNET_YES;
   }
+  else
+  {
+    edc->n_exp_time = 1000LL * (time (NULL) + 365 * 24 * 60 * 60); /* + 1y */
+  }
   edc->ri = ri;
   edc->off = off;
   edc->name = GNUNET_strdup (name);
@@ -1794,29 +1946,6 @@
 
 
 /**
- * Release the record info.
- *
- * @param cls NULL
- * @param key unused
- * @param value a RecordInfo to release
- * @return GNUNET_OK (continue to iterate)
- */
-static int
-release_ri (void *cls,
-           const struct GNUNET_HashCode *key,
-           void *value)
-{
-  struct RecordInfo *ri = value;
-
-  gtk_tree_row_reference_free (ri->rr);
-  GNUNET_free_non_null (ri->data);
-  GNUNET_free (ri->name);
-  GNUNET_free (ri);
-  return GNUNET_OK;
-}
-
-
-/**
  * Disconnect from the namestore and clean up the main
  * GNS tree view.
  */
@@ -1824,6 +1953,7 @@
 GNUNET_SETUP_gns_done ()
 {
   struct OperationContext *oc;
+  struct MoveOperationContext *moc;
 
   gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_status_label")));
   gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_main_scrolledwindow")));
@@ -1840,6 +1970,17 @@
     GNUNET_NAMESTORE_cancel (oc->qe);
     GNUNET_free (oc);
   }
+  while (NULL != (moc = moc_head))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("A pending namestore operation was not transmitted to the 
namestore.\n"));
+    GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc);
+    GNUNET_NAMESTORE_cancel (moc->qe);
+    GNUNET_CRYPTO_ecc_key_free (moc->pk);
+    free_edit_dialog_context (moc->edc);
+    GNUNET_free (moc->data);
+    GNUNET_free (moc);
+  }
   if (NULL != n2r)
   {
     GNUNET_CONTAINER_multihashmap_iterate (n2r,




reply via email to

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