gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18375 - gnunet-gtk/src/peerinfo


From: gnunet
Subject: [GNUnet-SVN] r18375 - gnunet-gtk/src/peerinfo
Date: Tue, 29 Nov 2011 15:18:17 +0100

Author: grothoff
Date: 2011-11-29 15:18:17 +0100 (Tue, 29 Nov 2011)
New Revision: 18375

Modified:
   gnunet-gtk/src/peerinfo/gnunet-peerinfo-gtk.c
Log:
making code compile with new transport API, still crashes due to transport API 
bugs

Modified: gnunet-gtk/src/peerinfo/gnunet-peerinfo-gtk.c
===================================================================
--- gnunet-gtk/src/peerinfo/gnunet-peerinfo-gtk.c       2011-11-29 14:14:43 UTC 
(rev 18374)
+++ gnunet-gtk/src/peerinfo/gnunet-peerinfo-gtk.c       2011-11-29 14:18:17 UTC 
(rev 18375)
@@ -46,15 +46,10 @@
   struct GNUNET_TRANSPORT_PeerAddressLookupContext *palc;
 
   /**
-   * Location where we store all addresses that were found during the 'palc' 
iteration.
+   * Handle for address to string conversion.
    */
-  char *palc_accumulator;
+  struct GNUNET_TRANSPORT_AddressToStringContext *tos;
 
-  /**
-   * Total number of addresses found.
-   */
-  guint palc_counter;
-
 };
 
 
@@ -123,11 +118,14 @@
 
   if (NULL != info->palc)
   {
-    GNUNET_TRANSPORT_peer_address_lookup_cancel (info->palc);
+    GNUNET_TRANSPORT_peer_get_active_addresses_cancel (info->palc);
     info->palc = NULL;
-    GNUNET_free (info->palc_accumulator);
-    info->palc_accumulator = NULL;
   }
+  if (NULL != info->tos)
+  {
+    GNUNET_TRANSPORT_address_to_string_cancel (info->tos);
+    info->tos = NULL;
+  }
   gtk_tree_row_reference_free (info->rr);
   GNUNET_free (info);
   return GNUNET_OK;
@@ -159,57 +157,108 @@
 }
 
 
+
 /**
- * Function to call with a binary format of an address
+ * Function to call with the text format of an address
  *
  * @param cls the 'struct PeerInfo' for which this is a valid address
- * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
+ * @param address address as a string, NULL on error
  */
 static void
-peer_address_cb (void *cls, const char *address)
+peer_address_string_cb (void *cls,
+                       const char *address)
 {
   struct PeerInfo *info = cls;
-  char *tmp;
   GtkListStore *ls;
   GtkTreeModel *tm;
   GtkTreeIter iter;
   GtkTreePath *path;
+  char *country;
   const char *colon;
   const char *dot;
-  char *country;
 
-  if (NULL == address)
+  info->tos = NULL;
+  ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store"));
+  tm = GTK_TREE_MODEL (ls);
+  path = gtk_tree_row_reference_get_path (info->rr);
+  GNUNET_assert (NULL != path);
+  GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path));
+  gtk_tree_path_free (path); 
+  if (NULL == address)    
   {
+    /* error */
+    gtk_list_store_set (ls, &iter, 
+                       1, 1,
+                       2, NULL, 
+                       3, NULL, 
+                       6, "<error>",
+                       -1);
+  }
+  else
+  {
     /* last address, store information in model */
     country = NULL;
-    colon = strstr (info->palc_accumulator, ":");
+    colon = strstr (address, ":");
     if (NULL != colon)
     {
-      for (dot = colon - 1; dot != info->palc_accumulator; dot--)
+      for (dot = colon - 1; dot != address; dot--)
         if ('.' == *dot)
           break;
       if ('.' == *dot)
         country = GNUNET_strndup (&dot[1], (colon - dot) - 1);
     }
+    gtk_list_store_set (ls, &iter, 
+                       1, 1,
+                       2, country, 
+                       3, GNUNET_PEERINFO_GTK_get_flag (country), 
+                       6, address,
+                       -1);
+    GNUNET_free (country);
+  }
+}
+
+
+/**
+ * Function to call with a binary format of an address
+ *
+ * @param cls the 'struct PeerInfo' for which this is a valid address
+ * @param address NULL on disconnect, otherwise 0-terminated printable UTF-8 
string
+ */
+static void
+peer_address_cb (void *cls,
+                const struct GNUNET_HELLO_Address *address)
+{
+  struct PeerInfo *info = cls;
+  GtkListStore *ls;
+  GtkTreeModel *tm;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+
+  if (NULL == address)
+  {
+    /* disconnect */
     ls = GTK_LIST_STORE (get_object ("GNUNET_PEERINFO_GTK_list_store"));
     tm = GTK_TREE_MODEL (ls);
     path = gtk_tree_row_reference_get_path (info->rr);
     GNUNET_assert (NULL != path);
     GNUNET_assert (TRUE == gtk_tree_model_get_iter (tm, &iter, path));
     gtk_tree_path_free (path);
-    gtk_list_store_set (ls, &iter, 1, info->palc_counter, 2, country, 3,
-                        GNUNET_PEERINFO_GTK_get_flag (country), 6,
-                        &info->palc_accumulator[1], -1);
-    GNUNET_free_non_null (country);
-    info->palc = NULL;
-    GNUNET_free (info->palc_accumulator);
-    info->palc_accumulator = NULL;
+    gtk_list_store_set (ls, &iter, 
+                       1, 0,
+                       2, NULL, 
+                       3, NULL, 
+                       6, "<disconnected>",
+                       -1);
     return;
   }
-  GNUNET_asprintf (&tmp, "%s|%s", info->palc_accumulator, address);
-  GNUNET_free (info->palc_accumulator);
-  info->palc_accumulator = tmp;
-  info->palc_counter++;
+  if (NULL != info->tos)
+    GNUNET_TRANSPORT_address_to_string_cancel (info->tos);
+  info->tos = GNUNET_TRANSPORT_address_to_string (get_configuration (),
+                                                 address,
+                                                 GNUNET_NO,
+                                                 GNUNET_TIME_UNIT_FOREVER_REL,
+                                                 &peer_address_string_cb,
+                                                 info);
 }
 
 
@@ -266,14 +315,12 @@
   }
   if (NULL == info->palc)
   {
-    info->palc_accumulator = GNUNET_strdup ("|");
-    info->palc_counter = 0;
     info->palc =
-        GNUNET_TRANSPORT_peer_address_lookup (get_configuration (), peer,
-                                              GNUNET_TIME_UNIT_MINUTES,
-                                              &peer_address_cb, info);
+        GNUNET_TRANSPORT_peer_get_active_addresses (get_configuration (), peer,
+                                                   GNUNET_NO,
+                                                   
GNUNET_TIME_UNIT_FOREVER_REL,
+                                                   &peer_address_cb, info);
   }
-
 }
 
 




reply via email to

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