aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_server.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-13 16:59:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-13 16:59:57 +0000
commit1257490cb630ade315a196a724d0233e662afb2c (patch)
tree0d9c01593a1aa73d8f6490127b640d67da69b54c /src/transport/plugin_transport_http_server.c
parent35d79cb1941c9f9607195b8760d8a14d836e6397 (diff)
downloadgnunet-1257490cb630ade315a196a724d0233e662afb2c.tar.gz
gnunet-1257490cb630ade315a196a724d0233e662afb2c.zip
implementing 0003268 to inbound information in HELLO addresses
All transport plugin functions are modified to use HELLO addresses instead of peer,address,address_length All plugins are modified to use HELLO addresses internally This commit can break transport functionality: core tests on my system still pass, but transport tests may still fail, errors messages may occurs or crashs Will be fixed asap
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r--src/transport/plugin_transport_http_server.c143
1 files changed, 72 insertions, 71 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 15c0323c6..bdc1074ed 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -113,12 +113,7 @@ struct Session
113 /** 113 /**
114 * Address 114 * Address
115 */ 115 */
116 void *addr; 116 struct GNUNET_HELLO_Address *address;
117
118 /**
119 * Address length
120 */
121 size_t addrlen;
122 117
123 /** 118 /**
124 * Unique HTTP/S connection tag for this connection 119 * Unique HTTP/S connection tag for this connection
@@ -263,7 +258,7 @@ struct HTTP_Server_Plugin
263 * External hostname the plugin can be connected to, can be different to 258 * External hostname the plugin can be connected to, can be different to
264 * the host's FQDN, used e.g. for reverse proxying 259 * the host's FQDN, used e.g. for reverse proxying
265 */ 260 */
266 struct HttpAddress *ext_addr; 261 struct GNUNET_HELLO_Address *ext_addr;
267 262
268 /** 263 /**
269 * Notify transport only about external address 264 * Notify transport only about external address
@@ -271,11 +266,6 @@ struct HTTP_Server_Plugin
271 unsigned int external_only; 266 unsigned int external_only;
272 267
273 /** 268 /**
274 * External address length
275 */
276 size_t ext_addr_len;
277
278 /**
279 * use IPv6 269 * use IPv6
280 */ 270 */
281 uint16_t use_ipv6; 271 uint16_t use_ipv6;
@@ -668,8 +658,8 @@ http_server_plugin_address_suggested (void *cls,
668 658
669 if ((NULL != plugin->ext_addr) && 659 if ((NULL != plugin->ext_addr) &&
670 GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, 660 GNUNET_YES == (http_common_cmp_addresses (addr, addrlen,
671 plugin->ext_addr, 661 plugin->ext_addr->address,
672 plugin->ext_addr_len))) 662 plugin->ext_addr->address_length)))
673 { 663 {
674 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ 664 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */
675 if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != 665 if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) !=
@@ -743,7 +733,7 @@ server_delete_session (void *cls,
743 GNUNET_SERVER_mst_destroy (s->msg_tk); 733 GNUNET_SERVER_mst_destroy (s->msg_tk);
744 s->msg_tk = NULL; 734 s->msg_tk = NULL;
745 } 735 }
746 GNUNET_free (s->addr); 736 GNUNET_HELLO_address_free (s->address);
747 GNUNET_free_non_null (s->server_recv); 737 GNUNET_free_non_null (s->server_recv);
748 GNUNET_free_non_null (s->server_send); 738 GNUNET_free_non_null (s->server_send);
749 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 739 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
@@ -1082,10 +1072,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1082 struct Session *s = NULL; 1072 struct Session *s = NULL;
1083 struct ServerConnection *sc = NULL; 1073 struct ServerConnection *sc = NULL;
1084 const union MHD_ConnectionInfo *conn_info; 1074 const union MHD_ConnectionInfo *conn_info;
1085 struct GNUNET_ATS_Information ats;
1086 struct HttpAddress *addr; 1075 struct HttpAddress *addr;
1087 size_t addr_len; 1076
1077 struct GNUNET_ATS_Information ats;
1088 struct GNUNET_PeerIdentity target; 1078 struct GNUNET_PeerIdentity target;
1079 size_t addr_len;
1089 uint32_t tag = 0; 1080 uint32_t tag = 0;
1090 int direction = GNUNET_SYSERR; 1081 int direction = GNUNET_SYSERR;
1091 unsigned int to; 1082 unsigned int to;
@@ -1175,8 +1166,8 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1175 s = GNUNET_new (struct Session); 1166 s = GNUNET_new (struct Session);
1176 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); 1167 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity));
1177 s->plugin = plugin; 1168 s->plugin = plugin;
1178 s->addr = addr; 1169 s->address = GNUNET_HELLO_address_allocate (&s->target, PLUGIN_NAME,
1179 s->addrlen = addr_len; 1170 addr, addr_len, GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1180 s->ats_address_network_type = ats.value; 1171 s->ats_address_network_type = ats.value;
1181 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; 1172 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS;
1182 s->tag = tag; 1173 s->tag = tag;
@@ -1212,7 +1203,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1212 if ((NULL != s->server_send) && (NULL != s->server_recv)) 1203 if ((NULL != s->server_send) && (NULL != s->server_recv))
1213 { 1204 {
1214 s->connect_in_progress = GNUNET_NO; /* PUT and GET are connected */ 1205 s->connect_in_progress = GNUNET_NO; /* PUT and GET are connected */
1215 plugin->env->session_start (NULL, &s->target, PLUGIN_NAME, NULL, 0 ,s, NULL, 0); 1206 plugin->env->session_start (NULL, s->address ,s, NULL, 0);
1216 } 1207 }
1217 1208
1218 if ((NULL == s->server_recv) || (NULL == s->server_send)) 1209 if ((NULL == s->server_recv) || (NULL == s->server_send))
@@ -1353,15 +1344,8 @@ server_receive_mst_cb (void *cls, void *client,
1353 atsi.value = s->ats_address_network_type; 1344 atsi.value = s->ats_address_network_type;
1354 GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); 1345 GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
1355 1346
1356 1347 delay = plugin->env->receive (plugin->env->cls, s->address, s, message);
1357 delay = plugin->env->receive (plugin->env->cls, 1348 plugin->env->update_address_metrics (plugin->env->cls, s->address, s, &atsi, 1);
1358 &s->target,
1359 message,
1360 s, NULL, 0);
1361
1362 plugin->env->update_address_metrics (plugin->env->cls,
1363 &s->target,
1364 NULL, 0, s, &atsi, 1);
1365 1349
1366 GNUNET_asprintf (&stat_txt, "# bytes received via %s_server", plugin->protocol); 1350 GNUNET_asprintf (&stat_txt, "# bytes received via %s_server", plugin->protocol);
1367 GNUNET_STATISTICS_update (plugin->env->stats, 1351 GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1376,8 +1360,8 @@ server_receive_mst_cb (void *cls, void *client,
1376 "Peer `%s' address `%s' next read delayed for %s\n", 1360 "Peer `%s' address `%s' next read delayed for %s\n",
1377 GNUNET_i2s (&s->target), 1361 GNUNET_i2s (&s->target),
1378 http_common_plugin_address_to_string (NULL, 1362 http_common_plugin_address_to_string (NULL,
1379 plugin->protocol, 1363 plugin->protocol, s->address->address,
1380 s->addr, s->addrlen), 1364 s->address->address_length),
1381 GNUNET_STRINGS_relative_time_to_string (delay, 1365 GNUNET_STRINGS_relative_time_to_string (delay,
1382 GNUNET_YES)); 1366 GNUNET_YES));
1383 } 1367 }
@@ -1485,9 +1469,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1485 s, sc, 1469 s, sc,
1486 GNUNET_i2s (&s->target), 1470 GNUNET_i2s (&s->target),
1487 http_common_plugin_address_to_string (NULL, 1471 http_common_plugin_address_to_string (NULL,
1488 plugin->protocol, 1472 plugin->protocol, s->address->address,
1489 s->addr, 1473 s->address->address_length));
1490 s->addrlen));
1491 sc->connected = GNUNET_YES; 1474 sc->connected = GNUNET_YES;
1492 return MHD_YES; 1475 return MHD_YES;
1493 } 1476 }
@@ -1499,9 +1482,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1499 s, sc, 1482 s, sc,
1500 GNUNET_i2s (&s->target), 1483 GNUNET_i2s (&s->target),
1501 http_common_plugin_address_to_string (NULL, 1484 http_common_plugin_address_to_string (NULL,
1502 plugin->protocol, 1485 plugin->protocol, s->address->address,
1503 s->addr, 1486 s->address->address_length));
1504 s->addrlen));
1505 sc->connected = GNUNET_NO; 1487 sc->connected = GNUNET_NO;
1506 /* Sent HTTP/1.1: 200 OK as PUT Response\ */ 1488 /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1507 response = MHD_create_response_from_data (strlen ("Thank you!"), 1489 response = MHD_create_response_from_data (strlen ("Thank you!"),
@@ -1519,9 +1501,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1519 s, sc, 1501 s, sc,
1520 GNUNET_i2s (&s->target), 1502 GNUNET_i2s (&s->target),
1521 http_common_plugin_address_to_string (NULL, 1503 http_common_plugin_address_to_string (NULL,
1522 plugin->protocol, 1504 plugin->protocol, s->address->address,
1523 s->addr, 1505 s->address->address_length),
1524 s->addrlen),
1525 *upload_data_size); 1506 *upload_data_size);
1526 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 1507 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1527 1508
@@ -1597,8 +1578,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1597 "Peer `%s' connection %p, GET on address `%s' disconnected\n", 1578 "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1598 GNUNET_i2s (&s->target), s->server_send, 1579 GNUNET_i2s (&s->target), s->server_send,
1599 http_common_plugin_address_to_string (NULL, 1580 http_common_plugin_address_to_string (NULL,
1600 plugin->protocol, 1581 plugin->protocol, s->address->address,
1601 s->addr, s->addrlen)); 1582 s->address->address_length));
1602 s->server_send = NULL; 1583 s->server_send = NULL;
1603 if (NULL != (s->server_recv)) 1584 if (NULL != (s->server_recv))
1604 { 1585 {
@@ -1617,8 +1598,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1617 "Peer `%s' connection %p PUT on address `%s' disconnected\n", 1598 "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1618 GNUNET_i2s (&s->target), s->server_recv, 1599 GNUNET_i2s (&s->target), s->server_recv,
1619 http_common_plugin_address_to_string (NULL, 1600 http_common_plugin_address_to_string (NULL,
1620 plugin->protocol, 1601 plugin->protocol, s->address->address,
1621 s->addr, s->addrlen)); 1602 s->address->address_length));
1622 s->server_recv = NULL; 1603 s->server_recv = NULL;
1623 /* Do not terminate session when PUT disconnects 1604 /* Do not terminate session when PUT disconnects
1624 if (NULL != (s->server_send)) 1605 if (NULL != (s->server_send))
@@ -1647,8 +1628,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1647 "Peer `%s' on address `%s' disconnected\n", 1628 "Peer `%s' on address `%s' disconnected\n",
1648 GNUNET_i2s (&s->target), 1629 GNUNET_i2s (&s->target),
1649 http_common_plugin_address_to_string (NULL, 1630 http_common_plugin_address_to_string (NULL,
1650 plugin->protocol, 1631 plugin->protocol, s->address->address,
1651 s->addr, s->addrlen)); 1632 s->address->address_length));
1652 1633
1653 if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) 1634 if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended))
1654 { 1635 {
@@ -2217,6 +2198,7 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
2217 socklen_t addrlen) 2198 socklen_t addrlen)
2218{ 2199{
2219 struct HTTP_Server_Plugin *plugin = cls; 2200 struct HTTP_Server_Plugin *plugin = cls;
2201 struct GNUNET_HELLO_Address *address;
2220 struct HttpAddressWrapper *w = NULL; 2202 struct HttpAddressWrapper *w = NULL;
2221 2203
2222 w = GNUNET_new (struct HttpAddressWrapper); 2204 w = GNUNET_new (struct HttpAddressWrapper);
@@ -2234,11 +2216,17 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
2234 http_common_plugin_address_to_string (NULL, 2216 http_common_plugin_address_to_string (NULL,
2235 plugin->protocol, 2217 plugin->protocol,
2236 w->address, w->addrlen)); 2218 w->address, w->addrlen));
2219 /* modify our published address list */
2237#if BUILD_HTTPS 2220#if BUILD_HTTPS
2238 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); 2221 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2222 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2239#else 2223#else
2240 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); 2224 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2225 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2241#endif 2226#endif
2227
2228 plugin->env->notify_address (plugin->env->cls, add_remove, address);
2229 GNUNET_HELLO_address_free (address);
2242} 2230}
2243 2231
2244 2232
@@ -2255,6 +2243,7 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
2255 socklen_t addrlen) 2243 socklen_t addrlen)
2256{ 2244{
2257 struct HTTP_Server_Plugin *plugin = cls; 2245 struct HTTP_Server_Plugin *plugin = cls;
2246 struct GNUNET_HELLO_Address *address;
2258 struct HttpAddressWrapper *w = plugin->addr_head; 2247 struct HttpAddressWrapper *w = plugin->addr_head;
2259 size_t saddr_len; 2248 size_t saddr_len;
2260 void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen); 2249 void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
@@ -2278,12 +2267,20 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
2278 http_common_plugin_address_to_string (NULL, 2267 http_common_plugin_address_to_string (NULL,
2279 plugin->protocol, 2268 plugin->protocol,
2280 w->address, w->addrlen)); 2269 w->address, w->addrlen));
2270
2271
2281 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); 2272 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
2273
2274 /* modify our published address list */
2282#if BUILD_HTTPS 2275#if BUILD_HTTPS
2283 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); 2276 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2277 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2284#else 2278#else
2285 plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); 2279 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2280 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2286#endif 2281#endif
2282 plugin->env->notify_address (plugin->env->cls, add_remove, address);
2283 GNUNET_HELLO_address_free (address);
2287 GNUNET_free (w->address); 2284 GNUNET_free (w->address);
2288 GNUNET_free (w); 2285 GNUNET_free (w);
2289} 2286}
@@ -2660,6 +2657,8 @@ static void
2660server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2657server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2661{ 2658{
2662 struct HTTP_Server_Plugin *plugin = cls; 2659 struct HTTP_Server_Plugin *plugin = cls;
2660 struct HttpAddress *ext_addr;
2661 size_t ext_addr_len;
2663 unsigned int urlen; 2662 unsigned int urlen;
2664 char *url; 2663 char *url;
2665 2664
@@ -2670,26 +2669,30 @@ server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskCo
2670 GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname); 2669 GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname);
2671 2670
2672 urlen = strlen (url) + 1; 2671 urlen = strlen (url) + 1;
2673 plugin->ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); 2672 ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
2674 plugin->ext_addr->options = htonl(plugin->options); 2673 ext_addr->options = htonl(plugin->options);
2675 plugin->ext_addr->urlen = htonl (urlen); 2674 ext_addr->urlen = htonl (urlen);
2676 plugin->ext_addr_len = sizeof (struct HttpAddress) + urlen; 2675 ext_addr_len = sizeof (struct HttpAddress) + urlen;
2677 memcpy (&plugin->ext_addr[1], url, urlen); 2676 memcpy (&ext_addr[1], url, urlen);
2678 GNUNET_free (url); 2677 GNUNET_free (url);
2678
2679 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 2679 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2680 "Notifying transport about external hostname address `%s'\n", plugin->external_hostname); 2680 "Notifying transport about external hostname address `%s'\n", plugin->external_hostname);
2681 2681
2682#if BUILD_HTTPS 2682#if BUILD_HTTPS
2683 if (GNUNET_YES == plugin->verify_external_hostname) 2683 if (GNUNET_YES == plugin->verify_external_hostname)
2684 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, 2684 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name,
2685 "Enabling SSL verification for external hostname address `%s'\n", plugin->external_hostname); 2685 "Enabling SSL verification for external hostname address `%s'\n",
2686 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, 2686 plugin->external_hostname);
2687 plugin->ext_addr, plugin->ext_addr_len, 2687 plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2688 "https_client"); 2688 "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
2689 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
2690 GNUNET_free (ext_addr);
2689#else 2691#else
2690 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, 2692 plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2691 plugin->ext_addr, plugin->ext_addr_len, 2693 "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
2692 "http_client"); 2694 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
2695 GNUNET_free (ext_addr);
2693#endif 2696#endif
2694} 2697}
2695 2698
@@ -3013,21 +3016,19 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3013 "Notifying transport to remove address `%s'\n", 3016 "Notifying transport to remove address `%s'\n",
3014 http_common_plugin_address_to_string (NULL, 3017 http_common_plugin_address_to_string (NULL,
3015 plugin->protocol, 3018 plugin->protocol,
3016 plugin->ext_addr, 3019 plugin->ext_addr->address,
3017 plugin->ext_addr_len)); 3020 plugin->ext_addr->address_length));
3018#if BUILD_HTTPS 3021#if BUILD_HTTPS
3019 plugin->env->notify_address (plugin->env->cls, 3022 plugin->env->notify_address (plugin->env->cls,
3020 GNUNET_NO, 3023 GNUNET_NO,
3021 plugin->ext_addr, 3024 plugin->ext_addr);
3022 plugin->ext_addr_len,
3023 "https_client");
3024#else 3025#else
3025 plugin->env->notify_address (plugin->env->cls, 3026 plugin->env->notify_address (plugin->env->cls,
3026 GNUNET_NO, 3027 GNUNET_NO,
3027 plugin->ext_addr, 3028 plugin->ext_addr);
3028 plugin->ext_addr_len,
3029 "http_client");
3030#endif 3029#endif
3030 GNUNET_HELLO_address_free (plugin->ext_addr);
3031 plugin->ext_addr = NULL;
3031 } 3032 }
3032 3033
3033 /* Stop to report addresses to transport service */ 3034 /* Stop to report addresses to transport service */