diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index b19a15bc7..37cebb1c7 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -854,64 +854,76 @@ clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
854 | 854 | ||
855 | /** | 855 | /** |
856 | * Take the given address and append it to the set of results sent back to | 856 | * Take the given address and append it to the set of results sent back to |
857 | * the client. | 857 | * the client. This function may be called serveral times for a single |
858 | * conversion. The last invocation will be with a @a address of | ||
859 | * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion | ||
860 | * errors, the callback might be called first with @a address NULL and | ||
861 | * @a res being #GNUNET_SYSERR. In that case, there will still be a | ||
862 | * subsequent call later with @a address NULL and @a res #GNUNET_OK. | ||
858 | * | 863 | * |
859 | * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') | 864 | * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`) |
860 | * @param buf text to transmit | 865 | * @param buf text to transmit (contains the human-readable address, or NULL) |
861 | * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error | 866 | * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error, |
867 | * never #GNUNET_NO | ||
862 | */ | 868 | */ |
863 | static void | 869 | static void |
864 | transmit_address_to_client (void *cls, const char *buf, int res) | 870 | transmit_address_to_client (void *cls, |
871 | const char *buf, | ||
872 | int res) | ||
865 | { | 873 | { |
866 | struct AddressToStringContext *actx = cls; | 874 | struct AddressToStringContext *actx = cls; |
867 | struct AddressToStringResultMessage *atsm; | 875 | struct AddressToStringResultMessage *atsm; |
868 | size_t len; | 876 | size_t len; |
877 | size_t slen; | ||
869 | 878 | ||
879 | GNUNET_assert ( (GNUNET_OK == res) || | ||
880 | (GNUNET_SYSERR == res) ); | ||
870 | if (NULL == buf) | 881 | if (NULL == buf) |
871 | { | 882 | { |
872 | GNUNET_assert ((res == GNUNET_OK) || (res == GNUNET_SYSERR)); | ||
873 | |||
874 | len = sizeof (struct AddressToStringResultMessage); | 883 | len = sizeof (struct AddressToStringResultMessage); |
875 | atsm = GNUNET_malloc (len); | 884 | atsm = GNUNET_malloc (len); |
876 | atsm->header.size = ntohs (len); | 885 | atsm->header.size = ntohs (len); |
877 | atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | 886 | atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
878 | |||
879 | if (GNUNET_OK == res) | 887 | if (GNUNET_OK == res) |
880 | { | 888 | { |
881 | /* done, transmit */ | 889 | /* this was the last call, transmit */ |
882 | atsm->res = htonl (GNUNET_YES); | 890 | atsm->res = htonl (GNUNET_OK); |
883 | atsm->addr_len = htonl (0); | 891 | atsm->addr_len = htonl (0); |
884 | GNUNET_SERVER_transmit_context_append_message (actx->tc, | 892 | GNUNET_SERVER_transmit_context_append_message (actx->tc, |
885 | (const struct GNUNET_MessageHeader *) atsm); | 893 | (const struct GNUNET_MessageHeader *) atsm); |
886 | 894 | GNUNET_SERVER_transmit_context_run (actx->tc, | |
887 | GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL); | 895 | GNUNET_TIME_UNIT_FOREVER_REL); |
888 | GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); | 896 | GNUNET_CONTAINER_DLL_remove (a2s_head, |
897 | a2s_tail, | ||
898 | actx); | ||
889 | GNUNET_free (actx); | 899 | GNUNET_free (actx); |
890 | } | 900 | } |
891 | if (GNUNET_SYSERR == res) | 901 | if (GNUNET_SYSERR == res) |
892 | { | 902 | { |
893 | /* address conversion failed */ | 903 | /* address conversion failed, but there will be more callbacks */ |
894 | 904 | atsm->res = htonl (GNUNET_SYSERR); | |
895 | atsm->res = htonl (GNUNET_NO); | ||
896 | atsm->addr_len = htonl (0); | 905 | atsm->addr_len = htonl (0); |
897 | GNUNET_SERVER_transmit_context_append_message (actx->tc, | 906 | GNUNET_SERVER_transmit_context_append_message (actx->tc, |
898 | (const struct GNUNET_MessageHeader *) atsm); | 907 | (const struct GNUNET_MessageHeader *) atsm); |
899 | GNUNET_free (atsm); | 908 | GNUNET_free (atsm); |
900 | } | 909 | } |
901 | } | 910 | } |
902 | else | 911 | else |
903 | { | 912 | { |
904 | GNUNET_assert (res == GNUNET_OK); | 913 | GNUNET_assert (GNUNET_OK == res); |
905 | /* succesful conversion, append*/ | 914 | /* succesful conversion, append*/ |
906 | len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1; | 915 | slen = strlen (buf) + 1; |
916 | len = sizeof (struct AddressToStringResultMessage) + slen; | ||
907 | atsm = GNUNET_malloc (len); | 917 | atsm = GNUNET_malloc (len); |
908 | atsm->header.size = ntohs (len); | 918 | atsm->header.size = ntohs (len); |
909 | atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); | 919 | atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); |
910 | atsm->res = htonl (GNUNET_YES); | 920 | atsm->res = htonl (GNUNET_YES); |
911 | atsm->addr_len = htonl (strlen (buf) + 1); | 921 | atsm->addr_len = htonl (slen); |
912 | memcpy (&atsm[1], buf, strlen (buf) + 1); | 922 | memcpy (&atsm[1], |
923 | buf, | ||
924 | slen); | ||
913 | GNUNET_SERVER_transmit_context_append_message (actx->tc, | 925 | GNUNET_SERVER_transmit_context_append_message (actx->tc, |
914 | (const struct GNUNET_MessageHeader *) atsm); | 926 | (const struct GNUNET_MessageHeader *) atsm); |
915 | GNUNET_free (atsm); | 927 | GNUNET_free (atsm); |
916 | } | 928 | } |
917 | } | 929 | } |
@@ -983,8 +995,12 @@ clients_handle_address_to_string (void *cls, | |||
983 | actx->tc = tc; | 995 | actx->tc = tc; |
984 | GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); | 996 | GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); |
985 | GNUNET_SERVER_disable_receive_done_warning (client); | 997 | GNUNET_SERVER_disable_receive_done_warning (client); |
986 | papi->address_pretty_printer (papi->cls, plugin_name, address, address_len, | 998 | papi->address_pretty_printer (papi->cls, |
987 | numeric, rtimeout, &transmit_address_to_client, | 999 | plugin_name, |
1000 | address, address_len, | ||
1001 | numeric, | ||
1002 | rtimeout, | ||
1003 | &transmit_address_to_client, | ||
988 | actx); | 1004 | actx); |
989 | } | 1005 | } |
990 | 1006 | ||