- expire old keys adaptively
[oweals/gnunet.git] / src / ats-tool / gnunet-ats.c
index 6a34f4e1506a880c6949e54d0403fdcb55052a88..0c7b19790f72dac870039378d8e08b41e16e5a44 100644 (file)
@@ -209,6 +209,12 @@ struct ATSAddress
    * Current inbound bandwidth.
    */
   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
+
+  /**
+   * Is this an active address?
+   */
+  int active;
+
 };
 
 
@@ -375,7 +381,7 @@ transport_addr_to_str_cb (void *cls,
     return;
   }
 
-  ats_str = GNUNET_strdup ("");
+  ats_str = GNUNET_strdup (pr->active ? _("active ") : _("inactive "));
   network = GNUNET_ATS_NET_UNSPECIFIED;
   for (c = 0; c < pr->ats_count; c++)
   {
@@ -432,7 +438,7 @@ transport_addr_to_str_cb (void *cls,
            ntohl (pr->bandwidth_out.value__),
            ntohl (pr->bandwidth_in.value__),
            ats_str);
-  GNUNET_free(ats_str);
+  GNUNET_free (ats_str);
 }
 
 
@@ -484,8 +490,10 @@ find_address_it (void *cls,
  *
  * @param cls closure (NULL)
  * @param address the address, NULL if ATS service was disconnected
- * @param address_active is this address actively used to maintain a connection
-          to a peer
+ * @param active #GNUNET_YES if this address is actively used
+ *        to maintain a connection to a peer;
+ *        #GNUNET_NO if the address is not actively used;
+ *        #GNUNET_SYSERR if this address is no longer available for ATS
  * @param bandwidth_out assigned outbound bandwidth for the connection
  * @param bandwidth_in assigned inbound bandwidth for the connection
  * @param ats performance data for the address (as far as known)
@@ -522,6 +530,34 @@ ats_perf_mon_cb (void *cls,
                                            NULL);
     return;
   }
+  if (GNUNET_SYSERR == active)
+  {
+    /* remove address */
+    struct AddressFindCtx actx;
+
+    actx.src = address;
+    actx.res = NULL;
+    GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
+                                                &address->peer,
+                                                &find_address_it,
+                                                &actx);
+    if (NULL == actx.res)
+    {
+      GNUNET_break (0);
+      return;
+    }
+    GNUNET_break (GNUNET_OK ==
+                  GNUNET_CONTAINER_multipeermap_remove (addresses,
+                                                        &address->peer,
+                                                        actx.res));
+    FPRINTF (stderr,
+             _("Removed address of peer `%s' with plugin `%s'\n"),
+             GNUNET_i2s (&address->peer),
+             actx.res->address->transport_name);
+    GNUNET_HELLO_address_free (actx.res);
+    GNUNET_free (actx.res);
+    return;
+  }
 
   if (GNUNET_NO == verbose)
   {
@@ -530,7 +566,6 @@ ats_perf_mon_cb (void *cls,
 
     actx.src = address;
     actx.res = NULL;
-
     GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
                                                 &address->peer,
                                                 &find_address_it,
@@ -538,7 +573,8 @@ ats_perf_mon_cb (void *cls,
     if ((NULL != actx.res))
     {
       if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
-          (bandwidth_out.value__ == actx.res->bandwidth_out.value__))
+          (bandwidth_out.value__ == actx.res->bandwidth_out.value__) &&
+          (active == actx.res->active))
       {
         return; /* Nothing to do here */
       }
@@ -551,9 +587,11 @@ ats_perf_mon_cb (void *cls,
     else
     {
       a = GNUNET_new (struct ATSAddress);
+
       a->address = GNUNET_HELLO_address_copy(address);
       a->bandwidth_in = bandwidth_in;
       a->bandwidth_out = bandwidth_out;
+      a->active = active;
       GNUNET_CONTAINER_multipeermap_put (addresses,
                                          &address->peer,
                                          a,
@@ -571,6 +609,7 @@ ats_perf_mon_cb (void *cls,
   pr->address = GNUNET_HELLO_address_copy (address);
   pr->bandwidth_in = bandwidth_in;
   pr->bandwidth_out = bandwidth_out;
+  pr->active = active;
   pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address,
                                                      resolve_addresses_numeric,
                                                      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
@@ -802,7 +841,9 @@ testservice_ats (void *cls,
     }
 
     alh = GNUNET_ATS_performance_list_addresses (ph,
-        (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL);
+                                                 (NULL == pid_str) ? NULL : &pid,
+                                                 GNUNET_YES,
+                                                 &ats_perf_cb, NULL);
     if (NULL == alh)
     {
       FPRINTF (stderr,
@@ -824,7 +865,11 @@ testservice_ats (void *cls,
                _("Cannot connect to ATS service, exiting...\n"));
 
     alh = GNUNET_ATS_performance_list_addresses (ph,
-        (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL);
+                                                 (NULL == pid_str)
+                                                 ? NULL
+                                                 : &pid,
+                                                 GNUNET_NO,
+                                                 &ats_perf_cb, NULL);
     if (NULL == alh)
     {
       FPRINTF (stderr,