convert fs publish to MQ
[oweals/gnunet.git] / src / peerinfo-tool / gnunet-peerinfo.c
index f6601977591da0532699a2f90ccf657c0ac00c60..b6aa224fd3ac54e0a0bfc3824886d9da8b0b0cbd 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001-2014 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -32,7 +32,7 @@
 #include "gnunet-peerinfo_plugins.h"
 
 /**
- * How long until we time out during peerinfo iterations?
+ * How long until we time out during address lookup?
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 
@@ -175,7 +175,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Main state machine task (if active).
  */
-static GNUNET_SCHEDULER_TaskIdentifier tt;
+static struct GNUNET_SCHEDULER_Task * tt;
 
 /**
  * Pending #GNUNET_TRANSPORT_get_hello() operation.
@@ -210,7 +210,7 @@ static struct PrintContext *pc_tail;
 /**
  * Handle to current #GNUNET_PEERINFO_add_peer() operation.
  */
-static struct GNUNET_PEERINFO_AddContext *ac;
+static struct GNUNET_MQ_Envelope *ac;
 
 /**
  * Hello of this peer (if initialized).
@@ -223,11 +223,9 @@ static struct GNUNET_HELLO_Message *my_hello;
  * runs the next requested function.
  *
  * @param cls unused
- * @param tc unused
  */
 static void
-state_machine (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc);
+state_machine (void *cls);
 
 
 /* ********************* 'get_info' ******************* */
@@ -291,15 +289,19 @@ process_resolved_address (void *cls,
 
   if (NULL != address)
   {
-    if (NULL == ar->result)
+    if (0 != strlen (address))
+    {
+      if (NULL != ar->result)
+        GNUNET_free (ar->result);
       ar->result = GNUNET_strdup (address);
+    }
     return;
   }
   ar->atsc = NULL;
   if (GNUNET_SYSERR == res)
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             _("Failure: Cannot convert address to string for peer `%s'\n"),
-             GNUNET_i2s (&ar->pc->peer));
+                _("Failure: Cannot convert address to string for peer `%s'\n"),
+                GNUNET_i2s (&ar->pc->peer));
   pc->num_addresses++;
   if (pc->num_addresses == pc->address_list_size)
     dump_pc (pc);
@@ -346,6 +348,11 @@ print_address (void *cls,
   ar = &pc->address_list[--pc->off];
   ar->pc = pc;
   ar->expiration = expiration;
+  GNUNET_asprintf (&ar->result,
+                   "%s:%u:%u",
+                   address->transport_name,
+                   address->address_length,
+                   address->local_info);
   ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
                                                  address,
                                                  no_resolve,
@@ -554,17 +561,11 @@ print_my_uri (void *cls,
  * Continuation called from #GNUNET_PEERINFO_add_peer()
  *
  * @param cls closure, NULL
- * @param emsg error message, NULL on success
  */
 static void
-add_continuation (void *cls,
-                 const char *emsg)
+add_continuation (void *cls)
 {
   ac = NULL;
-  if (NULL != emsg)
-    fprintf (stderr,
-            _("Failure adding HELLO: %s\n"),
-            emsg);
   tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
 }
 
@@ -592,7 +593,8 @@ parse_hello_uri (const char *put_uri)
   {
     /* WARNING: this adds the address from URI WITHOUT verification! */
     if (GNUNET_OK == ret)
-      ac = GNUNET_PEERINFO_add_peer (peerinfo, hello,
+      ac = GNUNET_PEERINFO_add_peer (peerinfo,
+                                     hello,
                                      &add_continuation,
                                      NULL);
     else
@@ -611,11 +613,9 @@ parse_hello_uri (const char *put_uri)
  * runs the next requested function.
  *
  * @param cls unused
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   struct PrintContext *pc;
   struct AddressRecord *ar;
@@ -623,13 +623,13 @@ shutdown_task (void *cls,
 
   if (NULL != ac)
   {
-    GNUNET_PEERINFO_add_peer_cancel (ac);
+    GNUNET_MQ_send_cancel (ac);
     ac = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != tt)
+  if (NULL != tt)
   {
     GNUNET_SCHEDULER_cancel (tt);
-    tt = GNUNET_SCHEDULER_NO_TASK;
+    tt = NULL;
   }
   if (NULL != pic)
   {
@@ -698,7 +698,7 @@ hello_callback (void *cls,
   }
   my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id (hello,
+                 GNUNET_HELLO_get_id (my_hello,
                                       &my_peer_identity));
   GNUNET_TRANSPORT_get_hello_cancel (gh);
   gh = NULL;
@@ -752,9 +752,8 @@ testservice_task (void *cls,
   {
     tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
   }
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
 }
 
 
@@ -800,13 +799,11 @@ run (void *cls,
  * runs the next requested function.
  *
  * @param cls unused
- * @param tc scheduler context
  */
 static void
-state_machine (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+state_machine (void *cls)
 {
-  tt = GNUNET_SCHEDULER_NO_TASK;
+  tt = NULL;
 
   if (NULL != put_uri)
   {
@@ -828,7 +825,6 @@ state_machine (void *cls,
     pic = GNUNET_PEERINFO_iterate (peerinfo,
                                    include_friend_only,
                                    NULL,
-                                  TIMEOUT,
                                   &print_peer_info, NULL);
   }
   else if (GNUNET_YES == get_self)
@@ -848,7 +844,6 @@ state_machine (void *cls,
     pic = GNUNET_PEERINFO_iterate (peerinfo,
                                    include_friend_only,
                                    &my_peer_identity,
-                                  TIMEOUT,
                                    &print_my_uri, NULL);
     get_uri = GNUNET_NO;
   }