gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35080 - in gnunet/src: ats include transport


From: gnunet
Subject: [GNUnet-SVN] r35080 - in gnunet/src: ats include transport
Date: Tue, 3 Feb 2015 15:27:56 +0100

Author: grothoff
Date: 2015-02-03 15:27:56 +0100 (Tue, 03 Feb 2015)
New Revision: 35080

Modified:
   gnunet/src/ats/Makefile.am
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/include/gnunet_ats_service.h
   gnunet/src/transport/gnunet-service-transport.c
Log:
separate ATS interface scanning logic from ATS scheduling logic

Modified: gnunet/src/ats/Makefile.am
===================================================================
--- gnunet/src/ats/Makefile.am  2015-02-03 14:11:03 UTC (rev 35079)
+++ gnunet/src/ats/Makefile.am  2015-02-03 14:27:56 UTC (rev 35080)
@@ -52,6 +52,7 @@
 
 libgnunetats_la_SOURCES = \
   ats_api_connectivity.c \
+  ats_api_scanner.c \
   ats_api_scheduling.c \
   ats_api_performance.c
 libgnunetats_la_LIBADD = \

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2015-02-03 14:11:03 UTC (rev 35079)
+++ gnunet/src/ats/ats_api_scheduling.c 2015-02-03 14:27:56 UTC (rev 35080)
@@ -108,44 +108,6 @@
 
 
 /**
- * We keep a list of our local networks so we can answer
- * LAN vs. WAN questions.  Note: WLAN is not detected yet.
- * (maybe we can do that heuristically based on interface
- * name in the future?).
- *
- * FIXME: should this be part of the ATS scheduling API?
- * Seems to be more generic and independent of ATS.
- */
-struct ATS_Network
-{
-  /**
-   * Kept in a DLL.
-   */
-  struct ATS_Network *next;
-
-  /**
-   * Kept in a DLL.
-   */
-  struct ATS_Network *prev;
-
-  /**
-   * Network address.
-   */
-  struct sockaddr *network;
-
-  /**
-   * Netmask to determine what is in the LAN.
-   */
-  struct sockaddr *netmask;
-
-  /**
-   * How long are @e network and @e netmask?
-   */
-  socklen_t length;
-};
-
-
-/**
  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
  */
 struct GNUNET_ATS_SchedulingHandle
@@ -177,16 +139,6 @@
   struct GNUNET_MQ_Handle *mq;
 
   /**
-   * Head of LAN networks list.
-   */
-  struct ATS_Network *net_head;
-
-  /**
-   * Tail of LAN networks list.
-   */
-  struct ATS_Network *net_tail;
-
-  /**
    * Array of session objects (we need to translate them to numbers and back
    * for the protocol; the offset in the array is the session number on the
    * network).  Index 0 is always NULL and reserved to represent the NULL 
pointer.
@@ -200,11 +152,6 @@
   struct GNUNET_SCHEDULER_Task *task;
 
   /**
-   * Task for periodically refreshing our LAN network list.
-   */
-  struct GNUNET_SCHEDULER_Task *interface_task;
-
-  /**
    * Size of the @e session_array.
    */
   unsigned int session_array_size;
@@ -644,325 +591,6 @@
 
 
 /**
- * Delete all entries from the current network list.
- *
- * @param sh scheduling handle to clean up
- */
-static void
-delete_networks (struct GNUNET_ATS_SchedulingHandle *sh)
-{
-  struct ATS_Network *cur;
-
-  while (NULL != (cur = sh->net_head))
-  {
-    GNUNET_CONTAINER_DLL_remove (sh->net_head,
-                                 sh->net_tail,
-                                 cur);
-    GNUNET_free (cur);
-  }
-}
-
-
-/**
- * Function invoked for each interface found.  Adds the interface's
- * network addresses to the respective DLL, so we can distinguish
- * between LAN and WAN.
- *
- * @param cls closure
- * @param name name of the interface (can be NULL for unknown)
- * @param isDefault is this presumably the default interface
- * @param addr address of this interface (can be NULL for unknown or 
unassigned)
- * @param broadcast_addr the broadcast address (can be NULL for unknown or 
unassigned)
- * @param netmask the network mask (can be NULL for unknown or unassigned)
- * @param addrlen length of the address
- * @return #GNUNET_OK to continue iteration
- */
-static int
-interface_proc (void *cls,
-                const char *name,
-                int isDefault,
-                const struct sockaddr *addr,
-                const struct sockaddr *broadcast_addr,
-                const struct sockaddr *netmask,
-                socklen_t addrlen)
-{
-  struct GNUNET_ATS_SchedulingHandle *sh = cls;
-  /* Calculate network */
-  struct ATS_Network *net = NULL;
-
-  /* Skipping IPv4 loopback addresses since we have special check  */
-  if  (addr->sa_family == AF_INET)
-  {
-    const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
-
-    if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000))
-       return GNUNET_OK;
-  }
-  /* Skipping IPv6 loopback addresses since we have special check  */
-  if  (addr->sa_family == AF_INET6)
-  {
-    const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
-    if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
-      return GNUNET_OK;
-  }
-
-  if (addr->sa_family == AF_INET)
-  {
-    const struct sockaddr_in *addr4 = (const struct sockaddr_in *) addr;
-    const struct sockaddr_in *netmask4 = (const struct sockaddr_in *) netmask;
-    struct sockaddr_in *tmp;
-    struct sockaddr_in network4;
-
-    net = GNUNET_malloc (sizeof (struct ATS_Network) + 2 * sizeof (struct 
sockaddr_in));
-    tmp = (struct sockaddr_in *) &net[1];
-    net->network = (struct sockaddr *) &tmp[0];
-    net->netmask = (struct sockaddr *) &tmp[1];
-    net->length = addrlen;
-
-    memset (&network4, 0, sizeof (network4));
-    network4.sin_family = AF_INET;
-#if HAVE_SOCKADDR_IN_SIN_LEN
-    network4.sin_len = sizeof (network4);
-#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));
-  }
-
-  if (addr->sa_family == AF_INET6)
-  {
-    const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *) addr;
-    const struct sockaddr_in6 *netmask6 = (const struct sockaddr_in6 *) 
netmask;
-    struct sockaddr_in6 * tmp;
-    struct sockaddr_in6 network6;
-
-    net = GNUNET_malloc (sizeof (struct ATS_Network) + 2 * sizeof (struct 
sockaddr_in6));
-    tmp = (struct sockaddr_in6 *) &net[1];
-    net->network = (struct sockaddr *) &tmp[0];
-    net->netmask = (struct sockaddr *) &tmp[1];
-    net->length = addrlen;
-
-    memset (&network6, 0, sizeof (network6));
-    network6.sin6_family = AF_INET6;
-#if HAVE_SOCKADDR_IN_SIN_LEN
-    network6.sin6_len = sizeof (network6);
-#endif
-    unsigned int c = 0;
-    uint32_t *addr_elem = (uint32_t *) &addr6->sin6_addr;
-    uint32_t *mask_elem = (uint32_t *) &netmask6->sin6_addr;
-    uint32_t *net_elem = (uint32_t *) &network6.sin6_addr;
-    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));
-  }
-  if (NULL == net)
-    return GNUNET_OK; /* odd / unsupported address family */
-
-  /* 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_free (netmask);
-#endif
-  GNUNET_CONTAINER_DLL_insert (sh->net_head,
-                               sh->net_tail,
-                               net);
-
-  return GNUNET_OK;
-}
-
-
-/**
- * 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)
-{
-  struct GNUNET_ATS_SchedulingHandle *sh = cls;
-
-  sh->interface_task = NULL;
-  delete_networks (sh);
-  GNUNET_OS_network_interfaces_list (&interface_proc,
-                                     sh);
-  sh->interface_task = GNUNET_SCHEDULER_add_delayed 
(INTERFACE_PROCESSING_INTERVAL,
-                                                     &get_addresses,
-                                                     sh);
-}
-
-
-/**
- * Convert a `enum GNUNET_ATS_Network_Type` to a string
- *
- * @param net the network type
- * @return a string or NULL if invalid
- */
-const char *
-GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net)
-{
-  switch (net)
-    {
-    case GNUNET_ATS_NET_UNSPECIFIED:
-      return "UNSPECIFIED";
-    case GNUNET_ATS_NET_LOOPBACK:
-      return "LOOPBACK";
-    case GNUNET_ATS_NET_LAN:
-      return "LAN";
-    case GNUNET_ATS_NET_WAN:
-      return "WAN";
-    case GNUNET_ATS_NET_WLAN:
-      return "WLAN";
-    case GNUNET_ATS_NET_BT:
-      return "BLUETOOTH";
-    default:
-      return NULL;
-    }
-}
-
-
-/**
- * Convert a ATS property to a string
- *
- * @param type the property type
- * @return a string or NULL if invalid
- */
-const char *
-GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type)
-{
-  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;
-  }
-}
-
-
-/**
- * Returns where the address is located: LAN or WAN or ...
- *
- * @param sh the scheduling handle
- * @param addr address
- * @param addrlen address length
- * @return type of the network the address belongs to
- */
-enum GNUNET_ATS_Network_Type
-GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
-                             const struct sockaddr *addr,
-                             socklen_t addrlen)
-{
-  struct ATS_Network *cur = sh->net_head;
-  enum GNUNET_ATS_NetworkType type = GNUNET_ATS_NET_UNSPECIFIED;
-
-  switch (addr->sa_family)
-    {
-    case AF_UNIX:
-      type = GNUNET_ATS_NET_LOOPBACK;
-      break;
-    case AF_INET:
-      {
-        const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
-
-        if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000))
-          type = GNUNET_ATS_NET_LOOPBACK;
-        break;
-      }
-    case AF_INET6:
-      {
-        const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
-
-        if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
-          type = GNUNET_ATS_NET_LOOPBACK;
-        break;
-      }
-    default:
-      GNUNET_break (0);
-      break;
-   }
-
-  /* Check local networks */
-  while ((NULL != cur) && (GNUNET_ATS_NET_UNSPECIFIED == type))
-  {
-    if (addrlen != cur->length)
-    {
-      cur = cur->next;
-      continue;
-    }
-    if (addr->sa_family == AF_INET)
-    {
-      const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
-      const struct sockaddr_in *net4 = (const struct sockaddr_in *) 
cur->network;
-      const struct sockaddr_in *mask4 = (const struct sockaddr_in *) 
cur->netmask;
-
-      if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) == 
net4->sin_addr.s_addr)
-        type = GNUNET_ATS_NET_LAN;
-    }
-    if (addr->sa_family == AF_INET6)
-    {
-      const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
-      const struct sockaddr_in6 *net6 = (const struct sockaddr_in6 *) 
cur->network;
-      const struct sockaddr_in6 *mask6 = (const struct sockaddr_in6 *) 
cur->netmask;
-
-      int res = GNUNET_YES;
-      int c = 0;
-      uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
-      uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
-      uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
-      for (c = 0; c < 4; c++)
-        if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
-          res = GNUNET_NO;
-
-      if (res == GNUNET_YES)
-        type = GNUNET_ATS_NET_LAN;
-    }
-    cur = cur->next;
-  }
-
-  /* no local network found for this address, default: WAN */
-  if (type == GNUNET_ATS_NET_UNSPECIFIED)
-    type = GNUNET_ATS_NET_WAN;
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
-                   "ats-scheduling-api",
-                   "`%s' is in network `%s'\n",
-                   GNUNET_a2s (addr,
-                               addrlen),
-                   GNUNET_ATS_print_network_type (type));
-  return type;
-}
-
-
-/**
  * Initialize the ATS subsystem.
  *
  * @param cfg configuration to use
@@ -984,11 +612,6 @@
   GNUNET_array_grow (sh->session_array,
                      sh->session_array_size,
                      4);
-  GNUNET_OS_network_interfaces_list (&interface_proc,
-                                     sh);
-  sh->interface_task = GNUNET_SCHEDULER_add_delayed 
(INTERFACE_PROCESSING_INTERVAL,
-                                                     &get_addresses,
-                                                     sh);
   reconnect (sh);
   return sh;
 }
@@ -1017,12 +640,6 @@
     GNUNET_SCHEDULER_cancel (sh->task);
     sh->task = NULL;
   }
-  if (NULL != sh->interface_task)
-  {
-    GNUNET_SCHEDULER_cancel (sh->interface_task);
-    sh->interface_task = NULL;
-  }
-  delete_networks (sh);
   GNUNET_array_grow (sh->session_array,
                      sh->session_array_size,
                      0);

Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h     2015-02-03 14:11:03 UTC (rev 
35079)
+++ gnunet/src/include/gnunet_ats_service.h     2015-02-03 14:27:56 UTC (rev 
35080)
@@ -305,6 +305,68 @@
 GNUNET_NETWORK_STRUCT_END
 
 
+/* ********************* LAN Characterization library ************************ 
*/
+/* Note: these functions do not really communicate with the ATS service */
+
+/**
+ * Convert a ATS property to a string
+ *
+ * @param type the property type
+ * @return a string or NULL if invalid
+ */
+const char *
+GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
+
+
+/**
+ * Convert a `enum GNUNET_ATS_Network_Type` to a string
+ *
+ * @param net the network type
+ * @return a string or NULL if invalid
+ */
+const char *
+GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
+
+
+/**
+ * Handle for the LAN Characterization library.
+ */
+struct GNUNET_ATS_InterfaceScanner;
+
+
+/**
+ * Returns where the address is located: loopback, LAN or WAN.
+ *
+ * @param is handle from #GNUNET_ATS_interface_scanner_init()
+ * @param addr address
+ * @param addrlen address length
+ * @return type of the network the address belongs to
+ */
+enum GNUNET_ATS_Network_Type
+GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
+                                     const struct sockaddr *addr,
+                                     socklen_t addrlen);
+
+
+/**
+ * Initialize the ATS address characterization client handle.
+ *
+ * @return scanner handle, NULL on error
+ */
+struct GNUNET_ATS_InterfaceScanner *
+GNUNET_ATS_scanner_init (void);
+
+
+/**
+ * Terminate interface scanner.
+ *
+ * @param is scanner we are done with
+ */
+void
+GNUNET_ATS_scanner_done (struct GNUNET_ATS_InterfaceScanner *is);
+
+
+
 /* ********************Connection Suggestion API ***************************** 
*/
 
 /**
@@ -403,7 +465,8 @@
  */
 struct GNUNET_ATS_SchedulingHandle *
 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
-    GNUNET_ATS_AddressSuggestionCallback suggest_cb, void *suggest_cb_cls);
+                            GNUNET_ATS_AddressSuggestionCallback suggest_cb,
+                            void *suggest_cb_cls);
 
 
 /**
@@ -428,40 +491,6 @@
 
 
 /**
- * Convert a ATS property to a string
- *
- * @param type the property type
- * @return a string or NULL if invalid
- */
-const char *
-GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
-
-
-/**
- * Convert a `enum GNUNET_ATS_Network_Type` to a string
- *
- * @param net the network type
- * @return a string or NULL if invalid
- */
-const char *
-GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
-
-
-/**
- * Returns where the address is located: loopback, LAN or WAN.
- *
- * @param sh the `struct GNUNET_ATS_SchedulingHandle` handle
- * @param addr address
- * @param addrlen address length
- * @return type of the network the address belongs to
- */
-enum GNUNET_ATS_Network_Type
-GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
-                             const struct sockaddr *addr,
-                             socklen_t addrlen);
-
-
-/**
  * Test if a address and a session is known to ATS.
  *
  * @param sh the scheduling handle

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2015-02-03 14:11:03 UTC 
(rev 35079)
+++ gnunet/src/transport/gnunet-service-transport.c     2015-02-03 14:27:56 UTC 
(rev 35080)
@@ -147,6 +147,11 @@
 static struct SessionKiller *sk_tail;
 
 /**
+ * Interface scanner determines our LAN address range(s).
+ */
+static struct GNUNET_ATS_InterfaceScanner *is;
+
+/**
  * FIXME
  */
 struct BlacklistCheckContext *bc_head;
@@ -659,9 +664,9 @@
     GNUNET_break(0);
     return GNUNET_ATS_NET_UNSPECIFIED;
   }
-  return GNUNET_ATS_address_get_type (GST_ats,
-                                      addr,
-                                      addrlen);
+  return GNUNET_ATS_scanner_address_get_type (is,
+                                              addr,
+                                              addrlen);
 }
 
 
@@ -864,6 +869,8 @@
   GST_ats = NULL;
   GNUNET_ATS_connectivity_done (GST_ats_connect);
   GST_ats_connect = NULL;
+  GNUNET_ATS_scanner_done (is);
+  is = NULL;
   GST_clients_stop ();
   GST_blacklist_stop ();
   GST_hello_stop ();
@@ -993,6 +1000,7 @@
   GST_hello_start (friend_only, &process_hello_update, NULL );
   GNUNET_assert(NULL != GST_hello_get());
   GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity);
+  is = GNUNET_ATS_scanner_init ();
   GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
   GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
                                         &ats_request_address_change,




reply via email to

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