gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36472 - in gnunet/src: ats ats-tool dv include transport


From: gnunet
Subject: [GNUnet-SVN] r36472 - in gnunet/src: ats ats-tool dv include transport
Date: Wed, 7 Oct 2015 16:15:38 +0200

Author: grothoff
Date: 2015-10-07 16:15:38 +0200 (Wed, 07 Oct 2015)
New Revision: 36472

Modified:
   gnunet/src/ats-tool/gnunet-ats.c
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_performance.c
   gnunet/src/ats/gnunet-service-ats_scheduling.c
   gnunet/src/dv/plugin_transport_dv.c
   gnunet/src/include/gnunet_transport_plugin.h
   gnunet/src/transport/gnunet-service-transport_ats.c
   gnunet/src/transport/gnunet-service-transport_neighbours.c
   gnunet/src/transport/gnunet-service-transport_validation.c
   gnunet/src/transport/plugin_transport_http_client.c
   gnunet/src/transport/plugin_transport_http_common.c
   gnunet/src/transport/plugin_transport_http_common.h
   gnunet/src/transport/plugin_transport_http_server.c
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/plugin_transport_unix.c
   gnunet/src/transport/plugin_transport_wlan.c
Log:
determine network scope for ATS even if we do not yet have a session and only 
have an address

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2015-10-07 12:55:53 UTC (rev 36471)
+++ gnunet/src/ats/ats_api_scheduling.c 2015-10-07 14:15:38 UTC (rev 36472)
@@ -494,6 +494,7 @@
 
   if (NULL == sh->mq)
     return; /* disconnected, skip for now */
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ar->properties.scope);
   namelen = strlen (ar->address->transport_name) + 1;
   msize = ar->address->address_length + namelen;
   ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
@@ -672,6 +673,7 @@
     GNUNET_break (0);
     return NULL;
   }
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   namelen = strlen (address->transport_name) + 1;
   msize = address->address_length + namelen;
   if ((msize + sizeof (struct AddressUpdateMessage) >= 
GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
@@ -774,6 +776,7 @@
        ar->address->transport_name,
        ar->session,
        ar->slot);
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   GNUNET_ATS_properties_hton (&ar->properties,
                               prop);
   if (NULL == sh->mq)

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -225,6 +225,7 @@
     GNUNET_break (0);
     return;
   }
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   new_address = create_address (peer,
                                 plugin_name,
                                 plugin_addr,
@@ -294,7 +295,7 @@
               "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
               GNUNET_i2s (peer),
               (unsigned int) session_id);
-
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   /* Update address */
   aa->t_last_activity = GNUNET_TIME_absolute_get();
   aa->properties = *prop;

Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c     2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/ats/gnunet-service-ats_performance.c     2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -85,6 +85,7 @@
   struct GNUNET_SERVER_NotificationContext *nc;
   char *addrp;
 
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
   msg = (struct PeerInformationMessage *) buf;
   msg->header.size = htons (msize);
@@ -159,6 +160,7 @@
                                     struct GNUNET_BANDWIDTH_Value32NBO 
bandwidth_out,
                                     struct GNUNET_BANDWIDTH_Value32NBO 
bandwidth_in)
 {
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   notify_client (NULL,
                  peer,
                  plugin_name,
@@ -212,6 +214,7 @@
               plugin_name,
               (unsigned int) ntohl (bandwidth_out.value__),
               (unsigned int) ntohl (bandwidth_in.value__));
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   notify_client (client,
                  id,
                  plugin_name,

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -176,6 +176,7 @@
                             GNUNET_NO);
   GNUNET_ATS_properties_ntoh (&prop,
                               &m->properties);
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop.scope);
   GAS_addresses_add (&m->peer,
                      plugin_name,
                      address,

Modified: gnunet/src/ats-tool/gnunet-ats.c
===================================================================
--- gnunet/src/ats-tool/gnunet-ats.c    2015-10-07 12:55:53 UTC (rev 36471)
+++ gnunet/src/ats-tool/gnunet-ats.c    2015-10-07 14:15:38 UTC (rev 36472)
@@ -647,7 +647,7 @@
                GNUNET_ATS_print_network_type (c));
       GNUNET_asprintf (&quota_out_str, "-");
     }
-    GNUNET_free(entry_out);
+    GNUNET_free (entry_out);
 
     /* quota in */
     if (GNUNET_OK ==
@@ -660,7 +660,7 @@
           || (GNUNET_SYSERR ==
               GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
         quota_in = UINT32_MAX;
-      GNUNET_free(quota_in_str);
+      GNUNET_free (quota_in_str);
       GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
     }
     else

Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2015-10-07 12:55:53 UTC (rev 36471)
+++ gnunet/src/dv/plugin_transport_dv.c 2015-10-07 14:15:38 UTC (rev 36472)
@@ -860,6 +860,21 @@
 
 
 /**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+dv_plugin_get_network_for_address (void *cls,
+                                   const struct GNUNET_HELLO_Address *address)
+{
+  return GNUNET_ATS_NET_WAN; /* FOR NOW */
+}
+
+
+/**
  * Function that is called to get the keepalive factor.
  * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
  * calculate the interval between keepalive packets.
@@ -975,6 +990,7 @@
   api->query_keepalive_factor = &dv_plugin_query_keepalive_factor;
   api->get_session = &dv_get_session;
   api->get_network = &dv_get_network;
+  api->get_network_for_address = &dv_get_network_for_address;
   api->update_session_timeout = &dv_plugin_update_session_timeout;
   api->setup_monitor = &dv_plugin_setup_monitor;
   return api;

Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h        2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/include/gnunet_transport_plugin.h        2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -499,6 +499,7 @@
                                         struct Session *session,
                                         struct GNUNET_TIME_Relative delay);
 
+
 /**
  * Function called for a quick conversion of the binary address to
  * a numeric address.  Note that the caller must not free the
@@ -549,6 +550,18 @@
 
 
 /**
+ * Function to obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+typedef enum GNUNET_ATS_Network_Type
+(*GNUNET_TRANSPORT_GetNetworkTypeForAddress) (void *cls,
+                                              const struct 
GNUNET_HELLO_Address *address);
+
+
+/**
  * Function called by the plugin with information about the
  * current sessions managed by the plugin (for monitoring).
  *
@@ -680,6 +693,11 @@
   GNUNET_TRANSPORT_GetNetworkType get_network;
 
   /**
+   * Function to obtain the network type for an address
+   */
+  GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address;
+
+  /**
    * Function to monitor the sessions managed by the plugin.
    */
   GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor;

Modified: gnunet/src/transport/gnunet-service-transport_ats.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats.c 2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/gnunet-service-transport_ats.c 2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -478,6 +478,7 @@
                                                     
GNUNET_HELLO_ADDRESS_INFO_INBOUND));
   ai = find_ai_no_session (address);
   GNUNET_assert (NULL == ai);
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   LOG (GNUNET_ERROR_TYPE_INFO,
        "Notifying ATS about peer `%s''s new address `%s'\n",
        GNUNET_i2s (&address->peer),

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c  2015-10-07 
12:55:53 UTC (rev 36471)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c  2015-10-07 
14:15:38 UTC (rev 36472)
@@ -3530,7 +3530,7 @@
 
   if ( ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) &&
         (ACK_SEND_ACK != n->ack_state) ) ||
-       (NULL == n->primary_address.address) ) 
+       (NULL == n->primary_address.address) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Received unexpected ACK message from peer `%s' in state 
%s/%s\n",
@@ -3850,10 +3850,11 @@
  * Iterate over all connected neighbours.
  *
  * @param cb function to call
- * @param cb_cls closure for cb
+ * @param cb_cls closure for @a cb
  */
 void
-GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
+GST_neighbours_iterate (GST_NeighbourIterator cb,
+                        void *cb_cls)
 {
   struct IteratorContext ic;
 
@@ -3930,7 +3931,7 @@
  *
  * @param cls unused
  * @param key hash of neighbour's public key (not used)
- * @param value the 'struct NeighbourMapEntry' of the neighbour
+ * @param value the `struct NeighbourMapEntry` of the neighbour
  * @return #GNUNET_OK (continue to iterate)
  */
 static int

Modified: gnunet/src/transport/gnunet-service-transport_validation.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_validation.c  2015-10-07 
12:55:53 UTC (rev 36471)
+++ gnunet/src/transport/gnunet-service-transport_validation.c  2015-10-07 
14:15:38 UTC (rev 36472)
@@ -789,7 +789,9 @@
   ve->in_use = GNUNET_SYSERR; /* not defined */
   ve->address = GNUNET_HELLO_address_copy (address);
   ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
-  memset (&ve->pong_sig_cache, '\0', sizeof (struct 
GNUNET_CRYPTO_EddsaSignature));
+  memset (&ve->pong_sig_cache,
+          '\0',
+          sizeof (struct GNUNET_CRYPTO_EddsaSignature));
   ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
   ve->challenge =
       GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
@@ -828,6 +830,7 @@
   struct ValidationEntry *ve;
   struct GNUNET_PeerIdentity pid;
   struct GNUNET_ATS_Properties prop;
+  struct GNUNET_TRANSPORT_PluginFunctions *papi;
 
   if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
     return GNUNET_OK;           /* expired */
@@ -836,14 +839,26 @@
     GNUNET_break (0);
     return GNUNET_OK;           /* invalid HELLO !? */
   }
-  if (NULL == GST_plugins_find (address->transport_name))
+  if (NULL == (papi = GST_plugins_find (address->transport_name)))
   {
     /* might have been valid in the past, but we don't have that
        plugin loaded right now */
     return GNUNET_OK;
   }
+  if (NULL ==
+      papi->address_to_string (papi->cls,
+                               address->address,
+                               address->address_length))
+  {
+    /* Why do we try to add an ill-formed address? */
+    GNUNET_break (0);
+    return GNUNET_OK;
+  }
 
   ve = find_validation_entry (address);
+  ve->network = papi->get_network_for_address (papi->cls,
+                                               address);
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
   ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
                                               expiration);
   if (NULL == ve->revalidation_task)
@@ -857,6 +872,7 @@
   validation_entry_changed (ve,
                             GNUNET_TRANSPORT_VS_UPDATE);
   memset (&prop, 0, sizeof (prop));
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
   prop.scope = ve->network;
   prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
   if (GNUNET_YES != ve->known_to_ats)
@@ -1506,6 +1522,7 @@
       struct GNUNET_ATS_Properties prop;
 
       memset (&prop, 0, sizeof (prop));
+      GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
       prop.scope = ve->network;
       prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
       GNUNET_assert (GNUNET_NO ==

Modified: gnunet/src/transport/plugin_transport_http_client.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_client.c 2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_http_client.c 2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -1942,6 +1942,24 @@
 
 
 /**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+http_client_plugin_get_network_for_address (void *cls,
+                                            const struct GNUNET_HELLO_Address 
*address)
+{
+  struct HTTP_Client_Plugin *plugin = cls;
+
+  return http_common_get_network_for_address (plugin->env,
+                                              address);
+}
+
+
+/**
  * Session was idle, so disconnect it
  *
  * @param cls the `struct Session` of the idle session
@@ -2469,6 +2487,7 @@
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
   api->get_network = &http_client_plugin_get_network;
+  api->get_network_for_address = &http_client_plugin_get_network_for_address;
   api->update_session_timeout = &http_client_plugin_update_session_timeout;
   api->update_inbound_delay = &http_client_plugin_update_inbound_delay;
   api->setup_monitor = &http_client_plugin_setup_monitor;

Modified: gnunet/src/transport/plugin_transport_http_common.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.c 2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_http_common.c 2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -854,8 +854,10 @@
  * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error
  */
 size_t
-http_common_cmp_addresses (const void *addr1, size_t addrlen1,
-    const void *addr2, size_t addrlen2)
+http_common_cmp_addresses (const void *addr1,
+                           size_t addrlen1,
+                           const void *addr2,
+                           size_t addrlen2)
 {
   const char *a1 = addr1;
   const char *a2 = addr2;
@@ -888,4 +890,49 @@
   return GNUNET_NO;
 }
 
+
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param env the environment
+ * @param address the address
+ * @return the network type
+ */
+enum GNUNET_ATS_Network_Type
+http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment 
*env,
+                                     const struct GNUNET_HELLO_Address 
*address)
+{
+
+  struct sockaddr *sa;
+  enum GNUNET_ATS_Network_Type net_type;
+  size_t salen = 0;
+  int res;
+
+  net_type = GNUNET_ATS_NET_UNSPECIFIED;
+  sa = http_common_socket_from_address (address->address,
+                                        address->address_length,
+                                        &res);
+  if (GNUNET_SYSERR == res)
+    return net_type;
+  if (GNUNET_YES == res)
+  {
+    GNUNET_assert (NULL != sa);
+    if (AF_INET == sa->sa_family)
+    {
+      salen = sizeof (struct sockaddr_in);
+    }
+    else if (AF_INET6 == sa->sa_family)
+    {
+      salen = sizeof (struct sockaddr_in6);
+    }
+    net_type = env->get_address_type (env->cls,
+                                      sa,
+                                      salen);
+    GNUNET_free (sa);
+  }
+  return net_type;
+}
+
+
+
 /* end of plugin_transport_http_common.c */

Modified: gnunet/src/transport/plugin_transport_http_common.h
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.h 2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_http_common.h 2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -247,4 +247,17 @@
                            const void *addr2,
                            size_t addrlen2);
 
+
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param env the environment
+ * @param address the address
+ * @return the network type
+ */
+enum GNUNET_ATS_Network_Type
+http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment 
*env,
+                                     const struct GNUNET_HELLO_Address 
*address);
+
+
 /* end of plugin_transport_http_common.h */

Modified: gnunet/src/transport/plugin_transport_http_server.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_server.c 2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_http_server.c 2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -3251,7 +3251,7 @@
 /**
  * Function obtain the network type for a session
  *
- * @param cls closure ('struct HTTP_Server_Plugin*')
+ * @param cls closure (`struct HTTP_Server_Plugin *`)
  * @param session the session
  * @return the network type in HBO or #GNUNET_SYSERR
  */
@@ -3264,6 +3264,24 @@
 
 
 /**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+http_server_plugin_get_network_for_address (void *cls,
+                                            const struct GNUNET_HELLO_Address 
*address)
+{
+  struct HTTP_Server_Plugin *plugin = cls;
+
+  return http_common_get_network_for_address (plugin->env,
+                                              address);
+}
+
+
+/**
  * Function that will be called whenever the transport service wants to
  * notify the plugin that the inbound quota changed and that the plugin
  * should update it's delay for the next receive value
@@ -3393,6 +3411,7 @@
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
   api->get_network = &http_server_plugin_get_network;
+  api->get_network_for_address = &http_server_plugin_get_network_for_address;
   api->update_session_timeout = &http_server_plugin_update_session_timeout;
   api->update_inbound_delay = &http_server_plugin_update_inbound_delay;
   api->setup_monitor = &http_server_plugin_setup_monitor;

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2015-10-07 12:55:53 UTC (rev 
36471)
+++ gnunet/src/transport/plugin_transport_tcp.c 2015-10-07 14:15:38 UTC (rev 
36472)
@@ -2734,6 +2734,66 @@
 
 
 /**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+tcp_plugin_get_network_for_address (void *cls,
+                                    const struct GNUNET_HELLO_Address *address)
+{
+  struct Plugin *plugin = cls;
+  size_t addrlen;
+  struct sockaddr_in a4;
+  struct sockaddr_in6 a6;
+  const struct IPv4TcpAddress *t4;
+  const struct IPv6TcpAddress *t6;
+  const void *sb;
+  size_t sbs;
+
+  addrlen = address->address_length;
+  if (addrlen == sizeof(struct IPv6TcpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    t6 = address->address;
+    memset (&a6, 0, sizeof(a6));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a6.sin6_len = sizeof (a6);
+#endif
+    a6.sin6_family = AF_INET6;
+    a6.sin6_port = t6->t6_port;
+    memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+    sb = &a6;
+    sbs = sizeof(a6);
+  }
+  else if (addrlen == sizeof(struct IPv4TcpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    t4 = address->address;
+    memset (&a4, 0, sizeof(a4));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a4.sin_len = sizeof (a4);
+#endif
+    a4.sin_family = AF_INET;
+    a4.sin_port = t4->t4_port;
+    a4.sin_addr.s_addr = t4->ipv4_addr;
+    sb = &a4;
+    sbs = sizeof(a4);
+  }
+  else
+  {
+    GNUNET_break (0);
+    return GNUNET_ATS_NET_UNSPECIFIED;
+  }
+  return plugin->env->get_address_type (plugin->env->cls,
+                                        sb,
+                                        sbs);
+}
+
+
+/**
  * Return information about the given session to the
  * monitor callback.
  *
@@ -2991,6 +3051,7 @@
   api->address_to_string = &tcp_plugin_address_to_string;
   api->string_to_address = &tcp_plugin_string_to_address;
   api->get_network = &tcp_plugin_get_network;
+  api->get_network_for_address = &tcp_plugin_get_network_for_address;
   api->update_session_timeout = &tcp_plugin_update_session_timeout;
   api->update_inbound_delay = &tcp_plugin_update_inbound_delay;
   api->setup_monitor = &tcp_plugin_setup_monitor;

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2015-10-07 12:55:53 UTC (rev 
36471)
+++ gnunet/src/transport/plugin_transport_udp.c 2015-10-07 14:15:38 UTC (rev 
36472)
@@ -614,13 +614,73 @@
  * @return the network type
  */
 static enum GNUNET_ATS_Network_Type
-udp_get_network (void *cls,
-                 struct Session *session)
+udp_plugin_get_network (void *cls,
+                        struct Session *session)
 {
   return session->scope;
 }
 
 
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+udp_plugin_get_network_for_address (void *cls,
+                                    const struct GNUNET_HELLO_Address *address)
+{
+  struct Plugin *plugin = cls;
+  size_t addrlen;
+  struct sockaddr_in a4;
+  struct sockaddr_in6 a6;
+  const struct IPv4UdpAddress *u4;
+  const struct IPv6UdpAddress *u6;
+  const void *sb;
+  size_t sbs;
+
+  addrlen = address->address_length;
+  if (addrlen == sizeof(struct IPv6UdpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    u6 = address->address;
+    memset (&a6, 0, sizeof(a6));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a6.sin6_len = sizeof (a6);
+#endif
+    a6.sin6_family = AF_INET6;
+    a6.sin6_port = u6->u6_port;
+    memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
+    sb = &a6;
+    sbs = sizeof(a6);
+  }
+  else if (addrlen == sizeof(struct IPv4UdpAddress))
+  {
+    GNUNET_assert (NULL != address->address); /* make static analysis happy */
+    u4 = address->address;
+    memset (&a4, 0, sizeof(a4));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+    a4.sin_len = sizeof (a4);
+#endif
+    a4.sin_family = AF_INET;
+    a4.sin_port = u4->u4_port;
+    a4.sin_addr.s_addr = u4->ipv4_addr;
+    sb = &a4;
+    sbs = sizeof(a4);
+  }
+  else
+  {
+    GNUNET_break (0);
+    return GNUNET_ATS_NET_UNSPECIFIED;
+  }
+  return plugin->env->get_address_type (plugin->env->cls,
+                                        sb,
+                                        sbs);
+}
+
+
 /* ******************* Event loop ******************** */
 
 /**
@@ -3766,7 +3826,8 @@
   api->check_address = &udp_plugin_check_address;
   api->get_session = &udp_plugin_get_session;
   api->send = &udp_plugin_send;
-  api->get_network = &udp_get_network;
+  api->get_network = &udp_plugin_get_network;
+  api->get_network_for_address = &udp_plugin_get_network_for_address;
   api->update_session_timeout = &udp_plugin_update_session_timeout;
   api->setup_monitor = &udp_plugin_setup_monitor;
   return api;

Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c        2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_unix.c        2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -805,6 +805,22 @@
 
 
 /**
+ * Function obtain the network type for a session
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+unix_plugin_get_network_for_address (void *cls,
+                                     const struct GNUNET_HELLO_Address 
*address)
+
+{
+  return GNUNET_ATS_NET_LOOPBACK;
+}
+
+
+/**
  * Creates a new outbound session the transport service will use to send data 
to the
  * peer
  *
@@ -1798,6 +1814,7 @@
   api->check_address = &unix_plugin_check_address;
   api->string_to_address = &unix_plugin_string_to_address;
   api->get_network = &unix_plugin_get_network;
+  api->get_network_for_address = &unix_plugin_get_network_for_address;
   api->update_session_timeout = &unix_plugin_update_session_timeout;
   api->setup_monitor = &unix_plugin_setup_monitor;
   sockets_created = unix_transport_server_start (plugin);

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2015-10-07 12:55:53 UTC 
(rev 36471)
+++ gnunet/src/transport/plugin_transport_wlan.c        2015-10-07 14:15:38 UTC 
(rev 36472)
@@ -1292,6 +1292,25 @@
 
 
 /**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+wlan_plugin_get_network_for_address (void *cls,
+                                    const struct GNUNET_HELLO_Address *address)
+{
+#if BUILD_WLAN
+  return GNUNET_ATS_NET_WLAN;
+#else
+  return GNUNET_ATS_NET_BT;
+#endif
+}
+
+
+/**
  * Creates a new outbound session the transport service will use to
  * send data to the peer
  *
@@ -2332,6 +2351,7 @@
   api->address_to_string = &wlan_plugin_address_to_string;
   api->string_to_address = &wlan_plugin_string_to_address;
   api->get_network = &wlan_plugin_get_network;
+  api->get_network_for_address = &wlan_plugin_get_network_for_address;
   api->update_session_timeout = &wlan_plugin_update_session_timeout;
   api->update_inbound_delay = &wlan_plugin_update_inbound_delay;
   api->setup_monitor = &wlan_plugin_setup_monitor;




reply via email to

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