aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-06-02 09:40:12 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-06-02 09:40:12 +0000
commit800c3b54ba9a67ad995d6b5c1ecbffe224f4676d (patch)
tree43347995315ca4cdd5b6d1a8dd2f0e7cf0a71134 /src/transport
parentda3d84fb0f3e5a681976b53d43275b2d9b401886 (diff)
downloadgnunet-800c3b54ba9a67ad995d6b5c1ecbffe224f4676d.tar.gz
gnunet-800c3b54ba9a67ad995d6b5c1ecbffe224f4676d.zip
fix semantic for address_to_string
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_clients.c62
-rw-r--r--src/transport/plugin_transport_bluetooth.c16
-rw-r--r--src/transport/plugin_transport_http_common.c19
-rw-r--r--src/transport/plugin_transport_tcp.c11
-rw-r--r--src/transport/plugin_transport_template.c7
-rw-r--r--src/transport/plugin_transport_udp.c12
-rw-r--r--src/transport/plugin_transport_unix.c13
-rw-r--r--src/transport/plugin_transport_wlan.c16
-rw-r--r--src/transport/transport_api_address_to_string.c2
9 files changed, 81 insertions, 77 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 943c5679d..b19a15bc7 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -858,48 +858,62 @@ clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
858 * 858 *
859 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') 859 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
860 * @param buf text to transmit 860 * @param buf text to transmit
861 * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error
861 */ 862 */
862static void 863static void
863transmit_address_to_client (void *cls, const char *buf) 864transmit_address_to_client (void *cls, const char *buf, int res)
864{ 865{
865 struct AddressToStringContext *actx = cls; 866 struct AddressToStringContext *actx = cls;
866 struct AddressToStringResultMessage *atsm; 867 struct AddressToStringResultMessage *atsm;
867 size_t len; 868 size_t len;
868 869
869 if (NULL != buf) 870 if (NULL == buf)
870 { 871 {
871 len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1; 872 GNUNET_assert ((res == GNUNET_OK) || (res == GNUNET_SYSERR));
873
874 len = sizeof (struct AddressToStringResultMessage);
872 atsm = GNUNET_malloc (len); 875 atsm = GNUNET_malloc (len);
873 atsm->header.size = ntohs (len); 876 atsm->header.size = ntohs (len);
874 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 877 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
875 atsm->res = htonl (GNUNET_YES); 878
876 atsm->addr_len = htonl (strlen (buf) + 1); 879 if (GNUNET_OK == res)
877 memcpy (&atsm[1], buf, strlen (buf) + 1); 880 {
881 /* done, transmit */
882 atsm->res = htonl (GNUNET_YES);
883 atsm->addr_len = htonl (0);
884 GNUNET_SERVER_transmit_context_append_message (actx->tc,
885 (const struct GNUNET_MessageHeader *) atsm);
886
887 GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL);
888 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
889 GNUNET_free (actx);
890 }
891 if (GNUNET_SYSERR == res)
892 {
893 /* address conversion failed */
894
895 atsm->res = htonl (GNUNET_NO);
896 atsm->addr_len = htonl (0);
897 GNUNET_SERVER_transmit_context_append_message (actx->tc,
898 (const struct GNUNET_MessageHeader *) atsm);
899 GNUNET_free (atsm);
900 }
878 } 901 }
879 else 902 else
880 { 903 {
881 len = sizeof (struct AddressToStringResultMessage); 904 GNUNET_assert (res == GNUNET_OK);
882 905 /* succesful conversion, append*/
906 len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1;
883 atsm = GNUNET_malloc (len); 907 atsm = GNUNET_malloc (len);
884 atsm->header.size = ntohs (len); 908 atsm->header.size = ntohs (len);
885 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 909 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
886 atsm->res = htonl (GNUNET_NO); 910 atsm->res = htonl (GNUNET_YES);
887 atsm->addr_len = htonl (0); 911 atsm->addr_len = htonl (strlen (buf) + 1);
888 912 memcpy (&atsm[1], buf, strlen (buf) + 1);
889 /* BUG HUNTING */ 913 GNUNET_SERVER_transmit_context_append_message (actx->tc,
890 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to convert address for client %p\n", actx->tc); 914 (const struct GNUNET_MessageHeader *) atsm);
891 } 915 GNUNET_free (atsm);
892
893 if (NULL == buf)
894 {
895 /* Address could not be converted */
896 GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct GNUNET_MessageHeader *)atsm);
897 GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL);
898 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
899 GNUNET_free (actx);
900 return;
901 } 916 }
902 GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct GNUNET_MessageHeader *) atsm);
903} 917}
904 918
905 919
diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c
index c131645a4..aad96cf69 100644
--- a/src/transport/plugin_transport_bluetooth.c
+++ b/src/transport/plugin_transport_bluetooth.c
@@ -1719,15 +1719,15 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type,
1719 if (sizeof (struct WlanAddress) != addrlen) 1719 if (sizeof (struct WlanAddress) != addrlen)
1720 { 1720 {
1721 /* invalid address */ 1721 /* invalid address */
1722 LOG (GNUNET_ERROR_TYPE_WARNING, 1722 asc (asc_cls, NULL, GNUNET_SYSERR);
1723 _("Bluetooth address with invalid size encountered\n")); 1723 }
1724 asc (asc_cls, NULL); 1724 else
1725 return; 1725 {
1726 ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, addrlen));
1727 asc (asc_cls, ret, GNUNET_OK);
1728 GNUNET_free (ret);
1726 } 1729 }
1727 ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, addrlen)); 1730 asc (asc_cls, NULL, GNUNET_OK);
1728 asc (asc_cls, ret);
1729 GNUNET_free (ret);
1730 asc (asc_cls, NULL);
1731} 1731}
1732 1732
1733 1733
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 131624f16..f5712db58 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -208,17 +208,14 @@ http_common_plugin_address_pretty_printer (void *cls,
208{ 208{
209 const struct HttpAddress *address = addr; 209 const struct HttpAddress *address = addr;
210 210
211 if (NULL == 211 if (NULL
212 http_common_plugin_address_to_string (NULL, type, 212 == http_common_plugin_address_to_string (NULL, type, address, addrlen))
213 address, addrlen)) 213 asc (asc_cls, NULL, GNUNET_SYSERR);
214 { 214 else
215 asc (asc_cls, NULL); 215 asc (asc_cls,
216 return; 216 http_common_plugin_address_to_string (NULL, type, address, addrlen),
217 } 217 GNUNET_OK);
218 asc (asc_cls, http_common_plugin_address_to_string (NULL, 218 asc (asc_cls, NULL, GNUNET_OK);
219 type,
220 address, addrlen));
221 asc (asc_cls, NULL);
222} 219}
223 220
224 221
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 50fe02f0a..eda6bd23e 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1690,8 +1690,8 @@ append_port (void *cls, const char *hostname)
1690 1690
1691 if (NULL == hostname) 1691 if (NULL == hostname)
1692 { 1692 {
1693 ppc->asc (ppc->asc_cls, NULL ); 1693 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */
1694 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); 1694 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc);
1695 GNUNET_SCHEDULER_cancel (ppc->timeout_task); 1695 GNUNET_SCHEDULER_cancel (ppc->timeout_task);
1696 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1696 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1697 ppc->resolver_handle = NULL; 1697 ppc->resolver_handle = NULL;
@@ -1703,6 +1703,7 @@ append_port (void *cls, const char *hostname)
1703 break; 1703 break;
1704 if (NULL == cur) 1704 if (NULL == cur)
1705 { 1705 {
1706 ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
1706 GNUNET_break(0); 1707 GNUNET_break(0);
1707 return; 1708 return;
1708 } 1709 }
@@ -1713,7 +1714,7 @@ append_port (void *cls, const char *hostname)
1713 else 1714 else
1714 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, 1715 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname,
1715 ppc->port); 1716 ppc->port);
1716 ppc->asc (ppc->asc_cls, ret); 1717 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
1717 GNUNET_free(ret); 1718 GNUNET_free(ret);
1718} 1719}
1719 1720
@@ -1730,6 +1731,7 @@ append_port (void *cls, const char *hostname)
1730 * @param timeout after how long should we give up? 1731 * @param timeout after how long should we give up?
1731 * @param asc function to call on each string 1732 * @param asc function to call on each string
1732 * @param asc_cls closure for asc 1733 * @param asc_cls closure for asc
1734 *
1733 */ 1735 */
1734static void 1736static void
1735tcp_plugin_address_pretty_printer (void *cls, const char *type, 1737tcp_plugin_address_pretty_printer (void *cls, const char *type,
@@ -1774,7 +1776,8 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
1774 else 1776 else
1775 { 1777 {
1776 /* invalid address */ 1778 /* invalid address */
1777 asc (asc_cls, NULL ); 1779 asc (asc_cls, NULL, GNUNET_SYSERR);
1780 asc (asc_cls, NULL, GNUNET_OK);
1778 return; 1781 return;
1779 } 1782 }
1780 ppc = GNUNET_new (struct PrettyPrinterContext); 1783 ppc = GNUNET_new (struct PrettyPrinterContext);
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index f39db3e79..a7abca210 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -276,11 +276,8 @@ template_plugin_address_pretty_printer (void *cls, const char *type,
276 GNUNET_TRANSPORT_AddressStringCallback 276 GNUNET_TRANSPORT_AddressStringCallback
277 asc, void *asc_cls) 277 asc, void *asc_cls)
278{ 278{
279 if (0 == addrlen) 279 asc (asc_cls, "converted address", GNUNET_OK); /* return address */
280 { 280 asc (asc_cls, NULL, GNUNET_OK); /* done */
281 asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
282 }
283 asc (asc_cls, NULL);
284} 281}
285 282
286 283
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index d1cfbc620..86751d4e5 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -749,7 +749,7 @@ append_port (void *cls, const char *hostname)
749 749
750 if (hostname == NULL ) 750 if (hostname == NULL )
751 { 751 {
752 ppc->asc (ppc->asc_cls, NULL ); 752 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */
753 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); 753 GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc);
754 GNUNET_SCHEDULER_cancel (ppc->timeout_task); 754 GNUNET_SCHEDULER_cancel (ppc->timeout_task);
755 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 755 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -758,13 +758,12 @@ append_port (void *cls, const char *hostname)
758 return; 758 return;
759 } 759 }
760 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) 760 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
761 {
762 if (cur == ppc) 761 if (cur == ppc)
763 break; 762 break;
764 }
765 if (NULL == cur) 763 if (NULL == cur)
766 { 764 {
767 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); 765 ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR);
766 GNUNET_break(0);
768 return; 767 return;
769 } 768 }
770 769
@@ -774,7 +773,7 @@ append_port (void *cls, const char *hostname)
774 else 773 else
775 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, 774 GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname,
776 ppc->port); 775 ppc->port);
777 ppc->asc (ppc->asc_cls, ret); 776 ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
778 GNUNET_free(ret); 777 GNUNET_free(ret);
779} 778}
780 779
@@ -847,7 +846,8 @@ udp_plugin_address_pretty_printer (void *cls,
847 { 846 {
848 /* invalid address */ 847 /* invalid address */
849 GNUNET_break_op(0); 848 GNUNET_break_op(0);
850 asc (asc_cls, NULL ); 849 asc (asc_cls, NULL , GNUNET_SYSERR);
850 asc (asc_cls, NULL, GNUNET_OK);
851 return; 851 return;
852 } 852 }
853 ppc = GNUNET_new (struct PrettyPrinterContext); 853 ppc = GNUNET_new (struct PrettyPrinterContext);
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 94c160144..792d7718e 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -1421,18 +1421,11 @@ unix_plugin_address_pretty_printer (void *cls, const char *type,
1421{ 1421{
1422 if ((NULL != addr) && (addrlen > 0)) 1422 if ((NULL != addr) && (addrlen > 0))
1423 { 1423 {
1424 asc (asc_cls, unix_address_to_string (NULL, addr, addrlen)); 1424 asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK);
1425 }
1426 else if (0 == addrlen)
1427 {
1428 asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
1429 } 1425 }
1430 else 1426 else
1431 { 1427 asc (asc_cls, NULL, GNUNET_SYSERR);
1432 GNUNET_break (0); 1428 asc (asc_cls, NULL, GNUNET_OK);
1433 asc (asc_cls, "<invalid UNIX address>");
1434 }
1435 asc (asc_cls, NULL);
1436} 1429}
1437 1430
1438 1431
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 124594e90..f0197feb8 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -1725,15 +1725,15 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type,
1725 if (sizeof (struct WlanAddress) != addrlen) 1725 if (sizeof (struct WlanAddress) != addrlen)
1726 { 1726 {
1727 /* invalid address */ 1727 /* invalid address */
1728 LOG (GNUNET_ERROR_TYPE_WARNING, 1728 asc (asc_cls, NULL, GNUNET_SYSERR);
1729 _("WLAN address with invalid size encountered\n")); 1729 }
1730 asc (asc_cls, NULL); 1730 else
1731 return; 1731 {
1732 ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen));
1733 asc (asc_cls, ret, GNUNET_OK);
1734 GNUNET_free (ret);
1732 } 1735 }
1733 ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen)); 1736 asc (asc_cls, NULL, GNUNET_OK);
1734 asc (asc_cls, ret);
1735 GNUNET_free (ret);
1736 asc (asc_cls, NULL);
1737} 1737}
1738 1738
1739 1739
diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c
index 932085f8c..a56616ea8 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -106,7 +106,7 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
106 { 106 {
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p failed to resolve address \n", 107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p failed to resolve address \n",
108 alucb->client); 108 alucb->client);
109 109 GNUNET_break (0);
110 alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR); 110 alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR);
111 111
112 /* expect more replies */ 112 /* expect more replies */