diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-21 11:15:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-21 11:15:10 +0000 |
commit | e7dea84a13da4c2a9bf6f70d57550c99de6538d1 (patch) | |
tree | ba96d8fe18fc97ced2afb584d098aadfbc923577 /src/transport/plugin_transport_http.c | |
parent | b7fe65e8a48aeb0f9ff51fa01ed2dd5ef5158f23 (diff) | |
download | gnunet-e7dea84a13da4c2a9bf6f70d57550c99de6538d1.tar.gz gnunet-e7dea84a13da4c2a9bf6f70d57550c99de6538d1.zip |
mod
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 75 |
1 files changed, 74 insertions, 1 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 | */ | ||
40 | struct 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 | */ | ||
1401 | static void | ||
1402 | notify_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 | ||
1376 | static int | 1426 | static int |
1377 | configure_plugin (struct Plugin *plugin) | 1427 | configure_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 (¬ify_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; |