WAN/LAN for HTTP/S
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 14 Dec 2011 10:25:30 +0000 (10:25 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 14 Dec 2011 10:25:30 +0000 (10:25 +0000)
src/transport/plugin_transport_http.c
src/transport/plugin_transport_http.h
src/transport/plugin_transport_http_server.c
src/transport/plugin_transport_tcp.c

index 502e26597e1ac62b1313f19c175588f88f4b2f40..b290e5ba2a1dbf8b39ea8b128eeb5298ce895f9e 100644 (file)
@@ -264,16 +264,19 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
 {
   struct Session *s = cls;
   struct Plugin *plugin = s->plugin;
-  struct GNUNET_ATS_Information distance;
   struct GNUNET_TIME_Relative delay;
+  struct GNUNET_ATS_Information atsi[2];
 
-  distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  distance.value = htonl (1);
+  atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+  atsi[0].value = htonl (1);
+  atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+  atsi[1].value = session->ats_address_network_type;
+  GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
 
   delay =
       plugin->env->receive (plugin->env->cls, &s->target, message,
-                            (const struct GNUNET_ATS_Information *) &distance,
-                            1, s, s->addr, s->addrlen);
+                            (const struct GNUNET_ATS_Information *) &atsi,
+                            2, s, s->addr, s->addrlen);
   return delay;
 }
 
@@ -452,6 +455,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
   s->addrlen = addrlen;
   s->next = NULL;
   s->next_receive = GNUNET_TIME_absolute_get_zero ();
+  s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
   return s;
 }
 
@@ -564,10 +568,16 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
                      GNUNET_i2s (target));
 #endif
     int res = GNUNET_OK;
-
+    struct GNUNET_ATS_Information ats;
     if (addrlen == sizeof (struct IPv4HttpAddress))
     {
       struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
+      struct sockaddr_in s4;
+
+      s4.sin_family = AF_INET;
+      s4.sin_addr.s_addr = a4->ipv4_addr;
+      s4.sin_port = a4->u4_port;
+      ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
 
       if ((ntohs (a4->u4_port) == 0) || (plugin->ipv4 == GNUNET_NO))
         res = GNUNET_SYSERR;
@@ -575,6 +585,12 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     if (addrlen == sizeof (struct IPv6HttpAddress))
     {
       struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
+      struct sockaddr_in6 s6;
+
+      s6.sin6_family = AF_INET6;
+      s6.sin6_addr = a6->ipv6_addr;
+      s6.sin6_port = a6->u6_port;
+      ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
 
       if ((ntohs (a6->u6_port) == 0) || (plugin->ipv6 == GNUNET_NO))
         res = GNUNET_SYSERR;
@@ -582,6 +598,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     if (res == GNUNET_OK)
     {
       s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
+      s->ats_address_network_type = ats.value;
       GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
       // initiate new connection
       res = client_connect (s);
index 6835beab4bedd60c86b926096c42462df8aefe49..84a92c28426489f464777c971ed363032d440d66 100644 (file)
@@ -324,6 +324,11 @@ struct Session
    */
   size_t addrlen;
 
+  /**
+   * ATS network type in NBO
+   */
+  uint32_t ats_address_network_type;
+
   /**
    * To whom are we talking to
    */
index 24c27acedbf9f7b98ba35ce6756bae390770cfbf..10c8268b11ea078cfd3c58930cc9144a12585ded 100644 (file)
@@ -369,7 +369,7 @@ server_lookup_session (struct Plugin *plugin,
   struct Session *t;
   struct ServerConnection *sc = NULL;
   const union MHD_ConnectionInfo *conn_info;
-
+  struct GNUNET_ATS_Information ats;
   struct IPv4HttpAddress a4;
   struct IPv6HttpAddress a6;
   struct sockaddr_in *s4;
@@ -521,6 +521,7 @@ create:
                    GNUNET_i2s (&target));
 #endif
 
+
   switch (conn_info->client_addr->sa_family)
   {
   case (AF_INET):
@@ -529,6 +530,7 @@ create:
     memcpy (&a4.ipv4_addr, &s4->sin_addr, sizeof (struct in_addr));
     a = &a4;
     a_len = sizeof (struct IPv4HttpAddress);
+    ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) s4, sizeof (struct sockaddr_in));
     break;
   case (AF_INET6):
     s6 = ((struct sockaddr_in6 *) conn_info->client_addr);
@@ -536,12 +538,14 @@ create:
     memcpy (&a6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
     a = &a6;
     a_len = sizeof (struct IPv6HttpAddress);
+    ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) s6, sizeof (struct sockaddr_in6));
     break;
   default:
     GNUNET_break (0);
     goto error;
   }
   s = create_session (plugin, &target, a, a_len, NULL, NULL);
+  s->ats_address_network_type = ats.value;
 
   s->inbound = GNUNET_YES;
   s->next_receive = GNUNET_TIME_absolute_get_zero ();
index dfd4ccee038d45916f1dc5a781f553a11225a724..347ff8d14a7d62d2cc16df0d2042d17ed789544c 100644 (file)
@@ -581,6 +581,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
   ret->client = client;
   ret->target = *target;
   ret->expecting_welcome = GNUNET_YES;
+  ret->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
   pm = GNUNET_malloc (sizeof (struct PendingMessage) +
                       sizeof (struct WelcomeMessage));
   pm->msg = (const char *) &pm[1];