guix-env: some update.
[oweals/gnunet.git] / src / ats / ats_api_scanner.c
index c213983f2043feda5a4819d98cfece2473513807..7015a31e8f93b6e0112dd34791c6e70d8bdc6328 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010-2015 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2010-2015 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.
 */
 /**
  * @file ats/ats_api_scanner.c
@@ -62,41 +62,38 @@ GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net)
 
 
 /**
- * Convert a ATS property to a string
+ * Convert ATS properties from host to network byte order.
  *
- * @param type the property type
- * @return a string or NULL if invalid
+ * @param nbo[OUT] value written
+ * @param hbo value read
  */
-const char *
-GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type)
+void
+GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
+                            const struct GNUNET_ATS_Properties *hbo)
 {
-  switch (type)
-  {
-  case GNUNET_ATS_ARRAY_TERMINATOR:
-    return "TERMINATOR";
-  case GNUNET_ATS_UTILIZATION_OUT:
-    return "UTILIZATION_UP";
-  case GNUNET_ATS_UTILIZATION_IN:
-    return "UTILIZATION_DOWN";
-  case GNUNET_ATS_UTILIZATION_PAYLOAD_OUT:
-    return "UTILIZATION_PAYLOAD_UP";
-  case GNUNET_ATS_UTILIZATION_PAYLOAD_IN:
-    return "UTILIZATION_PAYLOAD_DOWN";
-  case GNUNET_ATS_NETWORK_TYPE:
-    return "NETWORK_TYPE";
-  case GNUNET_ATS_QUALITY_NET_DELAY:
-    return "DELAY";
-  case GNUNET_ATS_QUALITY_NET_DISTANCE:
-    return "DISTANCE";
-  case GNUNET_ATS_COST_WAN:
-    return "COST_WAN";
-  case GNUNET_ATS_COST_LAN:
-    return "COST_LAN";
-  case GNUNET_ATS_COST_WLAN:
-    return "COST_WLAN";
-  default:
-    return NULL;
-  }
+  nbo->utilization_out = htonl (hbo->utilization_out);
+  nbo->utilization_in = htonl (hbo->utilization_in);
+  nbo->scope = htonl ((uint32_t) hbo->scope);
+  nbo->distance = htonl (hbo->distance);
+  nbo->delay = GNUNET_TIME_relative_hton (hbo->delay);
+}
+
+
+/**
+ * Convert ATS properties from network to host byte order.
+ *
+ * @param hbo[OUT] value written
+ * @param nbo value read
+ */
+void
+GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
+                            const struct GNUNET_ATS_PropertiesNBO *nbo)
+{
+  hbo->utilization_out = ntohl (nbo->utilization_out);
+  hbo->utilization_in = ntohl (nbo->utilization_in);
+  hbo->scope = ntohl ((uint32_t) nbo->scope);
+  hbo->distance = ntohl (nbo->distance);
+  hbo->delay = GNUNET_TIME_relative_ntoh (nbo->delay);
 }
 
 
@@ -242,8 +239,8 @@ interface_proc (void *cls,
 #endif
     network4.sin_addr.s_addr = (addr4->sin_addr.s_addr & netmask4->sin_addr.s_addr);
 
-    memcpy (net->netmask, netmask4, sizeof (struct sockaddr_in));
-    memcpy (net->network, &network4, sizeof (struct sockaddr_in));
+    GNUNET_memcpy (net->netmask, netmask4, sizeof (struct sockaddr_in));
+    GNUNET_memcpy (net->network, &network4, sizeof (struct sockaddr_in));
   }
 
   if (addr->sa_family == AF_INET6)
@@ -271,8 +268,8 @@ interface_proc (void *cls,
     for (c = 0; c < 4; c++)
       net_elem[c] = addr_elem[c] & mask_elem[c];
 
-    memcpy (net->netmask, netmask6, sizeof (struct sockaddr_in6));
-    memcpy (net->network, &network6, sizeof (struct sockaddr_in6));
+    GNUNET_memcpy (net->netmask, netmask6, sizeof (struct sockaddr_in6));
+    GNUNET_memcpy (net->network, &network6, sizeof (struct sockaddr_in6));
   }
   if (NULL == net)
     return GNUNET_OK; /* odd / unsupported address family */
@@ -280,11 +277,12 @@ interface_proc (void *cls,
   /* Store in list */
 #if VERBOSE_ATS
   char * netmask = GNUNET_strdup (GNUNET_a2s((struct sockaddr *) net->netmask, addrlen));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Adding network `%s', netmask `%s'\n",
-              GNUNET_a2s ((struct sockaddr *) net->network,
-                          addrlen),
-              netmask);
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                   "ats-scanner-api",
+                   "Adding network `%s', netmask `%s'\n",
+                   GNUNET_a2s ((struct sockaddr *) net->network,
+                               addrlen),
+                   netmask);
   GNUNET_free (netmask);
 #endif
   GNUNET_CONTAINER_DLL_insert (is->net_head,
@@ -299,11 +297,9 @@ interface_proc (void *cls,
  * Periodically get list of network addresses from our interfaces.
  *
  * @param cls closure
- * @param tc Task context
  */
 static void
-get_addresses (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_addresses (void *cls)
 {
   struct GNUNET_ATS_InterfaceScanner *is = cls;
 
@@ -401,7 +397,7 @@ GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
   if (type == GNUNET_ATS_NET_UNSPECIFIED)
     type = GNUNET_ATS_NET_WAN;
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
-                   "ats-scheduling-api",
+                   "ats-scanner-api",
                    "`%s' is in network `%s'\n",
                    GNUNET_a2s (addr,
                                addrlen),