gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32215 - gnunet/src/ats-tool


From: gnunet
Subject: [GNUnet-SVN] r32215 - gnunet/src/ats-tool
Date: Tue, 4 Feb 2014 17:33:44 +0100

Author: wachs
Date: 2014-02-04 17:33:44 +0100 (Tue, 04 Feb 2014)
New Revision: 32215

Modified:
   gnunet/src/ats-tool/gnunet-ats.c
Log:
filter ats information in non-verbose mode


Modified: gnunet/src/ats-tool/gnunet-ats.c
===================================================================
--- gnunet/src/ats-tool/gnunet-ats.c    2014-02-04 15:52:05 UTC (rev 32214)
+++ gnunet/src/ats-tool/gnunet-ats.c    2014-02-04 16:33:44 UTC (rev 32215)
@@ -87,6 +87,9 @@
 
 static GNUNET_SCHEDULER_TaskIdentifier end_task;
 
+static struct GNUNET_CONTAINER_MultiPeerMap *addresses;
+
+
 struct PendingResolutions
 {
   struct PendingResolutions *next;
@@ -102,10 +105,31 @@
   struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx;
 };
 
+struct ATSAddress
+{
+  struct GNUNET_HELLO_Address *address;
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
+  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
+};
+
+
+
 static struct PendingResolutions *head;
 
 static struct PendingResolutions *tail;
 
+static int
+free_addr_it (void *cls,
+    const struct GNUNET_PeerIdentity *key,
+    void *value)
+{
+  struct ATSAddress *a = value;
+  GNUNET_CONTAINER_multipeermap_remove (addresses, key, a);
+  GNUNET_HELLO_address_free (a->address);
+  GNUNET_free (a);
+  return GNUNET_OK;
+}
+
 static void
 end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -136,6 +160,10 @@
     GNUNET_free(pr);
     pending++;
   }
+
+  GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL);
+  GNUNET_CONTAINER_multipeermap_destroy(addresses);
+
   if (0 < pending)
     fprintf (stderr, _("%u address resolutions had a timeout\n"), pending);
   if (op_list_used || op_list_all)
@@ -169,7 +197,8 @@
 
       if (ats_type > GNUNET_ATS_PropertyCount)
       {
-        GNUNET_break(0);
+        fprintf (stderr, "Invalid ATS property type %u %u for address %s\n", 
ats_type, pr->ats[c].type,
+            address);
         continue;
       }
 
@@ -224,6 +253,30 @@
   }
 }
 
+
+struct AddressFindCtx
+{
+  const struct GNUNET_HELLO_Address *src;
+  struct ATSAddress *res;
+};
+
+static int
+find_address_it (void *cls,
+    const struct GNUNET_PeerIdentity *key,
+    void *value)
+{
+  struct AddressFindCtx *actx = cls;
+  struct ATSAddress *exist = value;
+
+  if (0 == GNUNET_HELLO_address_cmp (actx->src, exist->address))
+  {
+    actx->res = exist;
+    return GNUNET_NO;
+  }
+
+  return GNUNET_YES;
+}
+
 static void
 ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active,
     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
@@ -232,6 +285,36 @@
 {
   struct PendingResolutions * pr;
 
+  if ((GNUNET_YES == op_monitor) && (GNUNET_NO == verbose))
+  {
+    struct AddressFindCtx actx;
+
+    actx.src = address;
+    actx.res = NULL;
+
+    GNUNET_CONTAINER_multipeermap_iterate (addresses, find_address_it, &actx);
+    if ((actx.res != NULL))
+    {
+      if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
+          (bandwidth_out.value__ == actx.res->bandwidth_out.value__) )
+      {
+        return; /* Nothing to do here */
+      }
+      else
+      {
+        actx.res->bandwidth_in = bandwidth_in;
+        actx.res->bandwidth_out = bandwidth_out;
+      }
+    }
+
+    struct ATSAddress *a = GNUNET_new (struct ATSAddress);
+    a->address = GNUNET_HELLO_address_copy(address);
+    a->bandwidth_in = bandwidth_in;
+    a->bandwidth_out = bandwidth_out;
+    GNUNET_CONTAINER_multipeermap_put (addresses, &address->peer, a,
+        GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+  }
+
   if (NULL != address)
   {
     pr = GNUNET_malloc (sizeof (struct PendingResolutions) +
@@ -342,6 +425,8 @@
   unsigned int c;
   unsigned int type;
 
+  addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_YES);
+
   if (GNUNET_YES != result)
   {
     FPRINTF (stderr, _("Service `%s' is not running\n"), "ats");




reply via email to

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