From 99f22366b29bf928a4fb18c36a63bf4d3b122e88 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 14 Dec 2011 10:25:30 +0000 Subject: WAN/LAN for HTTP/S --- src/transport/plugin_transport_http.c | 29 ++++++++++++++++++++++------ src/transport/plugin_transport_http.h | 5 +++++ src/transport/plugin_transport_http_server.c | 6 +++++- src/transport/plugin_transport_tcp.c | 1 + 4 files changed, 34 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 502e26597..b290e5ba2 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -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); diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h index 6835beab4..84a92c284 100644 --- a/src/transport/plugin_transport_http.h +++ b/src/transport/plugin_transport_http.h @@ -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 */ diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 24c27aced..10c8268b1 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -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 (); diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index dfd4ccee0..347ff8d14 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -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]; -- cgit v1.2.3