More W32 resolver workarounds
[oweals/gnunet.git] / src / ats-tool / gnunet-ats.c
index 1e2d347e7d75784c9f0d7e28578c32f5dba203ab..553e9db7d208c088ceca8b727cd808ffd7fc7e71 100644 (file)
@@ -110,7 +110,7 @@ static struct PendingResolutions *head;
 static struct PendingResolutions *tail;
 
 
-static void 
+static void
 end (void *cls,
      const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -143,13 +143,13 @@ end (void *cls,
   }
   if (0 < pending)
     fprintf (stderr, _("%u address resolutions had a timeout\n"), pending);
-
-  fprintf (stderr, _("ATS returned results for %u addresses\n"), results);
+  if (op_list_used || op_list_all)
+       fprintf (stderr, _("ATS returned results for %u addresses\n"), results);
   ret = 0;
 }
 
 
-static void 
+static void
 transport_addr_to_str_cb (void *cls, const char *address)
 {
   struct PendingResolutions * pr = cls;
@@ -199,12 +199,17 @@ transport_addr_to_str_cb (void *cls, const char *address)
           GNUNET_free (ats_tmp);
         }
         GNUNET_free (ats_prop_value);
-               }
+    }
 
-    fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
-      GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address,
-      GNUNET_ATS_print_network_type(network),
-      ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str);
+    fprintf (stderr,
+             _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
+             GNUNET_i2s (&pr->address->peer),
+             pr->address->transport_name,
+             address,
+             GNUNET_ATS_print_network_type(network),
+             ntohl (pr->bandwidth_out.value__),
+             ntohl (pr->bandwidth_in.value__),
+             ats_str);
     GNUNET_free (ats_str);
   }
   else
@@ -226,7 +231,7 @@ transport_addr_to_str_cb (void *cls, const char *address)
 }
 
 
-static void 
+static void
 ats_perf_cb (void *cls,
             const struct GNUNET_HELLO_Address *address,
             int active,
@@ -250,7 +255,9 @@ ats_perf_cb (void *cls,
     pr->bandwidth_in = bandwidth_in;
     pr->bandwidth_out = bandwidth_out;
     pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(cfg, address,
-                      resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr);
+                      resolve_addresses_numeric,
+                                                         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
+                      transport_addr_to_str_cb, pr);
     GNUNET_CONTAINER_DLL_insert (head, tail, pr);
     results++;
     pending++;
@@ -350,7 +357,9 @@ testservice_ats (void *cls,
 
   if (NULL != pid_str)
   {
-    if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey))
+    if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str,
+                                                                   strlen (pid_str),
+                                                                   &pid.public_key))
     {
       FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str);
       return;
@@ -410,7 +419,7 @@ testservice_ats (void *cls,
     }
     else if (op_monitor)
     {
-        ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL);
+        ph = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL);
         if (NULL == ph)
           fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
         end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL);
@@ -420,9 +429,16 @@ testservice_ats (void *cls,
     {
                if (NULL == type_str)
                {
-                       fprintf (stderr, "No preference type given!\n");
+                       fprintf (stderr, _("No preference type given!\n"));
                        return;
                }
+               if (NULL == pid_str)
+               {
+                       fprintf (stderr, _("No peer given!\n"));
+                       return;
+               }
+
+
 
         for (c = 0; c<strlen(type_str); c++)
         {
@@ -436,7 +452,7 @@ testservice_ats (void *cls,
           type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
         else
         {
-          FPRINTF (stderr, "%s", _("Type required\n"));
+          FPRINTF (stderr, "%s", _("Valid type required\n"));
           return;
         }
 
@@ -445,7 +461,7 @@ testservice_ats (void *cls,
             if (NULL == ph)
               fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
 
-            GNUNET_ATS_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END);
+            GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END);
 
             end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
     }