guix-env: some update.
[oweals/gnunet.git] / src / ats / ats_api_scanner.c
index 64c02acf6ac664c78238347215367a0f522a7bdc..7015a31e8f93b6e0112dd34791c6e70d8bdc6328 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (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,32 +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_NETWORK_TYPE:
-    return "NETWORK_TYPE";
-  case GNUNET_ATS_QUALITY_NET_DELAY:
-    return "DELAY";
-  case GNUNET_ATS_QUALITY_NET_DISTANCE:
-    return "DISTANCE";
-  default:
-    GNUNET_break (0);
-    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);
 }
 
 
@@ -233,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)
@@ -262,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 */
@@ -291,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;