aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-21 11:15:10 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-21 11:15:10 +0000
commite7dea84a13da4c2a9bf6f70d57550c99de6538d1 (patch)
treeba96d8fe18fc97ced2afb584d098aadfbc923577 /src/transport
parentb7fe65e8a48aeb0f9ff51fa01ed2dd5ef5158f23 (diff)
downloadgnunet-e7dea84a13da4c2a9bf6f70d57550c99de6538d1.tar.gz
gnunet-e7dea84a13da4c2a9bf6f70d57550c99de6538d1.zip
mod
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_http.c75
-rw-r--r--src/transport/plugin_transport_http.h39
-rw-r--r--src/transport/test_transport_api_http_reverse_proxy.conf6
3 files changed, 116 insertions, 4 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index b3c463382..af0d9fcf8 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -33,6 +33,25 @@
33 */ 33 */
34#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) 34#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
35 35
36
37/**
38 * Wrapper to manage addresses
39 */
40struct HttpAddressWrapper
41{
42 /**
43 * Linked list next
44 */
45 struct HttpAddressWrapper *next;
46
47 /**
48 * Linked list previous
49 */
50 struct HttpAddressWrapper *prev;
51
52 struct HttpAddress *addr;
53};
54
36/** 55/**
37 * Wrapper to manage IPv4 addresses 56 * Wrapper to manage IPv4 addresses
38 */ 57 */
@@ -1372,6 +1391,37 @@ stop_report_addresses (struct Plugin *plugin)
1372 } 1391 }
1373} 1392}
1374 1393
1394/**
1395 * Function called when the service shuts down. Unloads our plugins
1396 * and cancels pending validations.
1397 *
1398 * @param cls closure, unused
1399 * @param tc task context (unused)
1400 */
1401static void
1402notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1403{
1404 struct Plugin *plugin = cls;
1405 struct HttpAddress *eaddr;
1406 size_t eaddr_len;
1407 size_t uri_len;
1408
1409 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
1410
1411 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1412 return;
1413
1414 uri_len = strlen (plugin->external_hostname) + 1;
1415 eaddr_len = sizeof (struct HttpAddress) + uri_len;
1416 eaddr = GNUNET_malloc (eaddr_len);
1417 eaddr->addr_len = htonl (strlen (plugin->external_hostname) + 1);
1418 eaddr->addr = (void *) &eaddr[1];
1419 memcpy (&eaddr->addr, plugin->external_hostname, uri_len);
1420 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, eaddr, eaddr_len);
1421 plugin->ext_addr = eaddr;
1422 plugin->ext_addr_len = eaddr_len;
1423}
1424
1375 1425
1376static int 1426static int
1377configure_plugin (struct Plugin *plugin) 1427configure_plugin (struct Plugin *plugin)
@@ -1461,7 +1511,6 @@ configure_plugin (struct Plugin *plugin)
1461 GNUNET_free (bind4_address); 1511 GNUNET_free (bind4_address);
1462 } 1512 }
1463 1513
1464
1465 char *bind6_address = NULL; 1514 char *bind6_address = NULL;
1466 1515
1467 if ((plugin->ipv6 == GNUNET_YES) && 1516 if ((plugin->ipv6 == GNUNET_YES) &&
@@ -1491,6 +1540,17 @@ configure_plugin (struct Plugin *plugin)
1491 GNUNET_free (bind6_address); 1540 GNUNET_free (bind6_address);
1492 } 1541 }
1493 1542
1543 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1544 "EXTERNAL_HOSTNAME", &plugin->external_hostname))
1545 {
1546 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1547 _("Using external hostname `%s'\n"), plugin->external_hostname);
1548 plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (&notify_external_hostname, plugin);
1549 }
1550 else
1551 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1552 _("No external hostname configured\n"));
1553
1494 1554
1495 /* Optional parameters */ 1555 /* Optional parameters */
1496 unsigned long long maxneigh; 1556 unsigned long long maxneigh;
@@ -1703,6 +1763,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1703 return NULL; 1763 return NULL;
1704 } 1764 }
1705 1765
1766 if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task)
1767 {
1768 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task);
1769 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
1770 }
1771
1772 if (NULL != plugin->ext_addr)
1773 {
1774 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, plugin->ext_addr, plugin->ext_addr_len);
1775 GNUNET_free (plugin->ext_addr);
1776 }
1777
1706 /* Stop reporting addresses to transport service */ 1778 /* Stop reporting addresses to transport service */
1707 stop_report_addresses (plugin); 1779 stop_report_addresses (plugin);
1708 1780
@@ -1732,6 +1804,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1732 "Plugin `%s' unloaded\n", plugin->name); 1804 "Plugin `%s' unloaded\n", plugin->name);
1733 GNUNET_free_non_null (plugin->server_addr_v4); 1805 GNUNET_free_non_null (plugin->server_addr_v4);
1734 GNUNET_free_non_null (plugin->server_addr_v6); 1806 GNUNET_free_non_null (plugin->server_addr_v6);
1807 GNUNET_free_non_null (plugin->external_hostname);
1735 GNUNET_free (plugin); 1808 GNUNET_free (plugin);
1736 GNUNET_free (api); 1809 GNUNET_free (api);
1737 return NULL; 1810 return NULL;
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h
index dc0f8bb01..1469fd8a9 100644
--- a/src/transport/plugin_transport_http.h
+++ b/src/transport/plugin_transport_http.h
@@ -119,6 +119,29 @@ struct Plugin
119 */ 119 */
120 120
121 /** 121 /**
122 * External hostname the plugin can be connected to, can be different to
123 * the host's FQDN, used e.g. for reverse proxying
124 */
125 char *external_hostname;
126
127 /**
128 * External hostname the plugin can be connected to, can be different to
129 * the host's FQDN, used e.g. for reverse proxying
130 */
131 struct HttpAddress *ext_addr;
132
133 /**
134 * External address length
135 */
136 size_t ext_addr_len;
137
138 /**
139 * Task calling transport service about external address
140 */
141 GNUNET_SCHEDULER_TaskIdentifier notify_ext_task;
142
143
144 /**
122 * Plugin name 145 * Plugin name
123 * Equals configuration section: transport-http, transport-https 146 * Equals configuration section: transport-http, transport-https
124 */ 147 */
@@ -284,6 +307,22 @@ struct Plugin
284GNUNET_NETWORK_STRUCT_BEGIN 307GNUNET_NETWORK_STRUCT_BEGIN
285 308
286/** 309/**
310 * HTTP addresses including a full URI
311 */
312struct HttpAddress
313{
314 /**
315 * Length of the address following in NBO
316 */
317 uint32_t addr_len GNUNET_PACKED;
318
319 /**
320 * Address following
321 */
322 void *addr GNUNET_PACKED;
323};
324
325/**
287 * IPv4 addresses 326 * IPv4 addresses
288 */ 327 */
289struct IPv4HttpAddress 328struct IPv4HttpAddress
diff --git a/src/transport/test_transport_api_http_reverse_proxy.conf b/src/transport/test_transport_api_http_reverse_proxy.conf
index 8e57cb11d..49fd9612e 100644
--- a/src/transport/test_transport_api_http_reverse_proxy.conf
+++ b/src/transport/test_transport_api_http_reverse_proxy.conf
@@ -1,7 +1,7 @@
1@INLINE@ template_cfg_peer1.conf 1INLINE@ template_cfg_peer1.conf
2[PATHS] 2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-http-p1/ 3SERVICEHOME = /tmp/test-transport/api-http-p1/
4DEFAULTCONFIG = test_transport_api_http_peer1.conf 4DEFAULTCONFIG = test_transport_api_http_reverse_proxy.conf
5 5
6[transport-http] 6[transport-http]
7PORT = 12080 7PORT = 12080
@@ -30,6 +30,6 @@ PORT = 12081
30PLUGINS = http 30PLUGINS = http
31#BINARY = .libs/gnunet-service-transport 31#BINARY = .libs/gnunet-service-transport
32UNIXPATH = /tmp/gnunet-p1-service-transport.sock 32UNIXPATH = /tmp/gnunet-p1-service-transport.sock
33#PREFIX = valgrind --leak-check=full 33PREFIX = valgrind --leak-check=full
34#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args 34#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
35 35