diff options
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 198 |
1 files changed, 100 insertions, 98 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index ed3ecbc6b..ca90d461d 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1,21 +1,21 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002--2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2002--2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/plugin_transport_tcp.c | 21 | * @file transport/plugin_transport_tcp.c |
@@ -562,13 +562,15 @@ tcp_address_to_string (void *cls, | |||
562 | sb = &a4; | 562 | sb = &a4; |
563 | break; | 563 | break; |
564 | default: | 564 | default: |
565 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"), | 565 | LOG (GNUNET_ERROR_TYPE_WARNING, |
566 | (unsigned int ) addrlen); | 566 | _("Unexpected address length: %u bytes\n"), |
567 | (unsigned int ) addrlen); | ||
567 | return NULL ; | 568 | return NULL ; |
568 | } | 569 | } |
569 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) | 570 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) |
570 | { | 571 | { |
571 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 572 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
573 | "inet_ntop"); | ||
572 | return NULL ; | 574 | return NULL ; |
573 | } | 575 | } |
574 | GNUNET_snprintf (rbuf, sizeof(rbuf), | 576 | GNUNET_snprintf (rbuf, sizeof(rbuf), |
@@ -816,9 +818,11 @@ tcp_disconnect_session (void *cls, | |||
816 | 818 | ||
817 | while (NULL != (pm = session->pending_messages_head)) | 819 | while (NULL != (pm = session->pending_messages_head)) |
818 | { | 820 | { |
819 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 821 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
820 | pm->transmit_cont != NULL ? "Could not deliver message to `%4s'.\n" : "Could not deliver message to `%4s', notifying.\n", | 822 | (NULL != pm->transmit_cont) |
821 | GNUNET_i2s (&session->target)); | 823 | ? "Could not deliver message to `%4s'.\n" |
824 | : "Could not deliver message to `%4s', notifying.\n", | ||
825 | GNUNET_i2s (&session->target)); | ||
822 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 826 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
823 | gettext_noop ("# bytes currently in TCP buffers"), | 827 | gettext_noop ("# bytes currently in TCP buffers"), |
824 | -(int64_t) pm->message_size, GNUNET_NO); | 828 | -(int64_t) pm->message_size, GNUNET_NO); |
@@ -1651,7 +1655,8 @@ static struct PrettyPrinterContext *ppc_dll_head; | |||
1651 | static struct PrettyPrinterContext *ppc_dll_tail; | 1655 | static struct PrettyPrinterContext *ppc_dll_tail; |
1652 | 1656 | ||
1653 | /** | 1657 | /** |
1654 | * Context for address to string conversion. | 1658 | * Context for address to string conversion, closure |
1659 | * for #append_port(). | ||
1655 | */ | 1660 | */ |
1656 | struct PrettyPrinterContext | 1661 | struct PrettyPrinterContext |
1657 | { | 1662 | { |
@@ -1681,7 +1686,7 @@ struct PrettyPrinterContext | |||
1681 | GNUNET_TRANSPORT_AddressStringCallback asc; | 1686 | GNUNET_TRANSPORT_AddressStringCallback asc; |
1682 | 1687 | ||
1683 | /** | 1688 | /** |
1684 | * Clsoure for 'asc'. | 1689 | * Clsoure for @e asc. |
1685 | */ | 1690 | */ |
1686 | void *asc_cls; | 1691 | void *asc_cls; |
1687 | 1692 | ||
@@ -1701,64 +1706,54 @@ struct PrettyPrinterContext | |||
1701 | uint32_t options; | 1706 | uint32_t options; |
1702 | }; | 1707 | }; |
1703 | 1708 | ||
1704 | static void | ||
1705 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1706 | { | ||
1707 | struct PrettyPrinterContext *ppc = cls; | ||
1708 | |||
1709 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1710 | if (NULL != ppc->resolver_handle) | ||
1711 | { | ||
1712 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); | ||
1713 | ppc->resolver_handle = NULL; | ||
1714 | } | ||
1715 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); | ||
1716 | GNUNET_free(ppc); | ||
1717 | } | ||
1718 | 1709 | ||
1719 | /** | 1710 | /** |
1720 | * Append our port and forward the result. | 1711 | * Append our port and forward the result. |
1721 | * | 1712 | * |
1722 | * @param cls the 'struct PrettyPrinterContext*' | 1713 | * @param cls the `struct PrettyPrinterContext *` |
1723 | * @param hostname hostname part of the address | 1714 | * @param hostname hostname part of the address |
1724 | */ | 1715 | */ |
1725 | static void | 1716 | static void |
1726 | append_port (void *cls, const char *hostname) | 1717 | append_port (void *cls, |
1718 | const char *hostname) | ||
1727 | { | 1719 | { |
1728 | struct PrettyPrinterContext *ppc = cls; | 1720 | struct PrettyPrinterContext *ppc = cls; |
1729 | struct PrettyPrinterContext *cur; | ||
1730 | char *ret; | 1721 | char *ret; |
1731 | 1722 | ||
1732 | if (NULL == hostname) | 1723 | if (NULL == hostname) |
1733 | { | 1724 | { |
1734 | ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */ | 1725 | /* Final call, done */ |
1735 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | ||
1736 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | ||
1737 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1738 | ppc->resolver_handle = NULL; | 1726 | ppc->resolver_handle = NULL; |
1739 | GNUNET_free(ppc); | 1727 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, |
1728 | ppc_dll_tail, | ||
1729 | ppc); | ||
1730 | ppc->asc (ppc->asc_cls, | ||
1731 | NULL, | ||
1732 | GNUNET_OK); | ||
1733 | GNUNET_free (ppc); | ||
1740 | return; | 1734 | return; |
1741 | } | 1735 | } |
1742 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | ||
1743 | if (cur == ppc) | ||
1744 | break; | ||
1745 | if (NULL == cur) | ||
1746 | { | ||
1747 | ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR); | ||
1748 | GNUNET_break(0); | ||
1749 | return; | ||
1750 | } | ||
1751 | |||
1752 | if (GNUNET_YES == ppc->ipv6) | 1736 | if (GNUNET_YES == ppc->ipv6) |
1753 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, | 1737 | GNUNET_asprintf (&ret, |
1754 | ppc->port); | 1738 | "%s.%u.[%s]:%d", |
1739 | PLUGIN_NAME, | ||
1740 | ppc->options, | ||
1741 | hostname, | ||
1742 | ppc->port); | ||
1755 | else | 1743 | else |
1756 | GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, | 1744 | GNUNET_asprintf (&ret, |
1757 | ppc->port); | 1745 | "%s.%u.%s:%d", |
1758 | ppc->asc (ppc->asc_cls, ret, GNUNET_OK); | 1746 | PLUGIN_NAME, |
1759 | GNUNET_free(ret); | 1747 | ppc->options, |
1748 | hostname, | ||
1749 | ppc->port); | ||
1750 | ppc->asc (ppc->asc_cls, | ||
1751 | ret, | ||
1752 | GNUNET_OK); | ||
1753 | GNUNET_free (ret); | ||
1760 | } | 1754 | } |
1761 | 1755 | ||
1756 | |||
1762 | /** | 1757 | /** |
1763 | * Convert the transports address to a nice, human-readable | 1758 | * Convert the transports address to a nice, human-readable |
1764 | * format. | 1759 | * format. |
@@ -1767,18 +1762,21 @@ append_port (void *cls, const char *hostname) | |||
1767 | * @param type name of the transport that generated the address | 1762 | * @param type name of the transport that generated the address |
1768 | * @param addr one of the addresses of the host, NULL for the last address | 1763 | * @param addr one of the addresses of the host, NULL for the last address |
1769 | * the specific address format depends on the transport | 1764 | * the specific address format depends on the transport |
1770 | * @param addrlen length of the address | 1765 | * @param addrlen length of the @a addr |
1771 | * @param numeric should (IP) addresses be displayed in numeric form? | 1766 | * @param numeric should (IP) addresses be displayed in numeric form? |
1772 | * @param timeout after how long should we give up? | 1767 | * @param timeout after how long should we give up? |
1773 | * @param asc function to call on each string | 1768 | * @param asc function to call on each string |
1774 | * @param asc_cls closure for asc | 1769 | * @param asc_cls closure for @a asc |
1775 | * | ||
1776 | */ | 1770 | */ |
1777 | static void | 1771 | static void |
1778 | tcp_plugin_address_pretty_printer (void *cls, const char *type, | 1772 | tcp_plugin_address_pretty_printer (void *cls, |
1779 | const void *addr, size_t addrlen, int numeric, | 1773 | const char *type, |
1780 | struct GNUNET_TIME_Relative timeout, | 1774 | const void *addr, |
1781 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) | 1775 | size_t addrlen, |
1776 | int numeric, | ||
1777 | struct GNUNET_TIME_Relative timeout, | ||
1778 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
1779 | void *asc_cls) | ||
1782 | { | 1780 | { |
1783 | struct PrettyPrinterContext *ppc; | 1781 | struct PrettyPrinterContext *ppc; |
1784 | const void *sb; | 1782 | const void *sb; |
@@ -1790,7 +1788,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1790 | uint16_t port; | 1788 | uint16_t port; |
1791 | uint32_t options; | 1789 | uint32_t options; |
1792 | 1790 | ||
1793 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 1791 | if (sizeof(struct IPv6TcpAddress) == addrlen) |
1794 | { | 1792 | { |
1795 | t6 = addr; | 1793 | t6 = addr; |
1796 | memset (&a6, 0, sizeof(a6)); | 1794 | memset (&a6, 0, sizeof(a6)); |
@@ -1802,7 +1800,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1802 | sb = &a6; | 1800 | sb = &a6; |
1803 | sbs = sizeof(a6); | 1801 | sbs = sizeof(a6); |
1804 | } | 1802 | } |
1805 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | 1803 | else if (sizeof(struct IPv4TcpAddress) == addrlen) |
1806 | { | 1804 | { |
1807 | t4 = addr; | 1805 | t4 = addr; |
1808 | memset (&a4, 0, sizeof(a4)); | 1806 | memset (&a4, 0, sizeof(a4)); |
@@ -1830,21 +1828,23 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1830 | ppc->asc_cls = asc_cls; | 1828 | ppc->asc_cls = asc_cls; |
1831 | ppc->port = port; | 1829 | ppc->port = port; |
1832 | ppc->options = options; | 1830 | ppc->options = options; |
1833 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( | 1831 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, |
1834 | GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); | 1832 | sbs, |
1835 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, | 1833 | ! numeric, |
1836 | timeout, &append_port, ppc); | 1834 | timeout, |
1837 | if (NULL != ppc->resolver_handle) | 1835 | &append_port, ppc); |
1836 | if (NULL == ppc->resolver_handle) | ||
1838 | { | 1837 | { |
1839 | GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); | 1838 | GNUNET_break (0); |
1840 | } | 1839 | GNUNET_free (ppc); |
1841 | else | 1840 | return; |
1842 | { | ||
1843 | GNUNET_break(0); | ||
1844 | GNUNET_free(ppc); | ||
1845 | } | 1841 | } |
1842 | GNUNET_CONTAINER_DLL_insert (ppc_dll_head, | ||
1843 | ppc_dll_tail, | ||
1844 | ppc); | ||
1846 | } | 1845 | } |
1847 | 1846 | ||
1847 | |||
1848 | /** | 1848 | /** |
1849 | * Check if the given port is plausible (must be either our listen | 1849 | * Check if the given port is plausible (must be either our listen |
1850 | * port or our advertised port), or any port if we are behind NAT | 1850 | * port or our advertised port), or any port if we are behind NAT |
@@ -2496,12 +2496,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2496 | aport = 0; | 2496 | aport = 0; |
2497 | if (bport != 0) | 2497 | if (bport != 0) |
2498 | { | 2498 | { |
2499 | service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, | 2499 | service = GNUNET_SERVICE_start ("transport-tcp", |
2500 | GNUNET_SERVICE_OPTION_NONE); | 2500 | env->cfg, |
2501 | if (service == NULL ) | 2501 | GNUNET_SERVICE_OPTION_NONE); |
2502 | if (service == NULL) | ||
2502 | { | 2503 | { |
2503 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); | 2504 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2504 | return NULL ; | 2505 | _("Failed to start service.\n")); |
2506 | return NULL; | ||
2505 | } | 2507 | } |
2506 | } | 2508 | } |
2507 | else | 2509 | else |
@@ -2555,7 +2557,6 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2555 | api->cls = plugin; | 2557 | api->cls = plugin; |
2556 | api->send = &tcp_plugin_send; | 2558 | api->send = &tcp_plugin_send; |
2557 | api->get_session = &tcp_plugin_get_session; | 2559 | api->get_session = &tcp_plugin_get_session; |
2558 | |||
2559 | api->disconnect_session = &tcp_disconnect_session; | 2560 | api->disconnect_session = &tcp_disconnect_session; |
2560 | api->query_keepalive_factor = &tcp_query_keepalive_factor; | 2561 | api->query_keepalive_factor = &tcp_query_keepalive_factor; |
2561 | api->disconnect_peer = &tcp_plugin_disconnect; | 2562 | api->disconnect_peer = &tcp_plugin_disconnect; |
@@ -2588,9 +2589,10 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2588 | GNUNET_free(api); | 2589 | GNUNET_free(api); |
2589 | return NULL; | 2590 | return NULL; |
2590 | } | 2591 | } |
2591 | plugin->server = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, | 2592 | plugin->server |
2592 | plugin, NULL, | 2593 | = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, |
2593 | idle_timeout, GNUNET_YES); | 2594 | plugin, NULL, |
2595 | idle_timeout, GNUNET_YES); | ||
2594 | } | 2596 | } |
2595 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); | 2597 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); |
2596 | memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); | 2598 | memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); |
@@ -2656,13 +2658,13 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2656 | next = ppc_dll_head; | 2658 | next = ppc_dll_head; |
2657 | for (cur = next; NULL != cur; cur = next) | 2659 | for (cur = next; NULL != cur; cur = next) |
2658 | { | 2660 | { |
2661 | GNUNET_break (0); | ||
2659 | next = cur->next; | 2662 | next = cur->next; |
2660 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); | 2663 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, |
2661 | if (NULL != cur->resolver_handle) | 2664 | ppc_dll_tail, |
2662 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 2665 | cur); |
2663 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | 2666 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
2664 | GNUNET_free(cur); | 2667 | GNUNET_free (cur); |
2665 | GNUNET_break(0); | ||
2666 | } | 2668 | } |
2667 | 2669 | ||
2668 | if (NULL != plugin->service) | 2670 | if (NULL != plugin->service) |