From 1dd22b0d681848af9980e5202e38b1a307cf2094 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jun 2014 22:04:11 +0000 Subject: clarify prettyprinter API and protocols, make sure implementations are consistent in their implemenation, doxygen fixes, indentation fixes, subtle semantic fixes --- src/transport/gnunet-service-transport_clients.c | 66 ++-- src/transport/gnunet-transport.c | 381 +++++++++++++++-------- src/transport/plugin_transport_bluetooth.c | 77 +++-- src/transport/plugin_transport_http_client.c | 25 +- src/transport/plugin_transport_http_common.c | 24 +- src/transport/plugin_transport_tcp.c | 198 ++++++------ src/transport/plugin_transport_udp.c | 96 +++--- src/transport/plugin_transport_unix.c | 81 +++-- src/transport/plugin_transport_wlan.c | 87 +++--- src/transport/transport.h | 40 ++- src/transport/transport_api_address_to_string.c | 128 ++++---- 11 files changed, 703 insertions(+), 500 deletions(-) (limited to 'src/transport') 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, /** * Take the given address and append it to the set of results sent back to - * the client. + * the client. This function may be called serveral times for a single + * conversion. The last invocation will be with a @a address of + * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion + * errors, the callback might be called first with @a address NULL and + * @a res being #GNUNET_SYSERR. In that case, there will still be a + * subsequent call later with @a address NULL and @a res #GNUNET_OK. * - * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') - * @param buf text to transmit - * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error + * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`) + * @param buf text to transmit (contains the human-readable address, or NULL) + * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error, + * never #GNUNET_NO */ static void -transmit_address_to_client (void *cls, const char *buf, int res) +transmit_address_to_client (void *cls, + const char *buf, + int res) { struct AddressToStringContext *actx = cls; struct AddressToStringResultMessage *atsm; size_t len; + size_t slen; + GNUNET_assert ( (GNUNET_OK == res) || + (GNUNET_SYSERR == res) ); if (NULL == buf) { - GNUNET_assert ((res == GNUNET_OK) || (res == GNUNET_SYSERR)); - len = sizeof (struct AddressToStringResultMessage); atsm = GNUNET_malloc (len); atsm->header.size = ntohs (len); atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); - if (GNUNET_OK == res) { - /* done, transmit */ - atsm->res = htonl (GNUNET_YES); + /* this was the last call, transmit */ + atsm->res = htonl (GNUNET_OK); atsm->addr_len = htonl (0); GNUNET_SERVER_transmit_context_append_message (actx->tc, - (const struct GNUNET_MessageHeader *) atsm); - - GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL); - GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx); + (const struct GNUNET_MessageHeader *) atsm); + GNUNET_SERVER_transmit_context_run (actx->tc, + GNUNET_TIME_UNIT_FOREVER_REL); + GNUNET_CONTAINER_DLL_remove (a2s_head, + a2s_tail, + actx); GNUNET_free (actx); } if (GNUNET_SYSERR == res) { - /* address conversion failed */ - - atsm->res = htonl (GNUNET_NO); + /* address conversion failed, but there will be more callbacks */ + atsm->res = htonl (GNUNET_SYSERR); atsm->addr_len = htonl (0); GNUNET_SERVER_transmit_context_append_message (actx->tc, - (const struct GNUNET_MessageHeader *) atsm); + (const struct GNUNET_MessageHeader *) atsm); GNUNET_free (atsm); } } else { - GNUNET_assert (res == GNUNET_OK); + GNUNET_assert (GNUNET_OK == res); /* succesful conversion, append*/ - len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1; + slen = strlen (buf) + 1; + len = sizeof (struct AddressToStringResultMessage) + slen; atsm = GNUNET_malloc (len); atsm->header.size = ntohs (len); atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); atsm->res = htonl (GNUNET_YES); - atsm->addr_len = htonl (strlen (buf) + 1); - memcpy (&atsm[1], buf, strlen (buf) + 1); + atsm->addr_len = htonl (slen); + memcpy (&atsm[1], + buf, + slen); GNUNET_SERVER_transmit_context_append_message (actx->tc, - (const struct GNUNET_MessageHeader *) atsm); + (const struct GNUNET_MessageHeader *) atsm); GNUNET_free (atsm); } } @@ -983,8 +995,12 @@ clients_handle_address_to_string (void *cls, actx->tc = tc; GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); GNUNET_SERVER_disable_receive_done_warning (client); - papi->address_pretty_printer (papi->cls, plugin_name, address, address_len, - numeric, rtimeout, &transmit_address_to_client, + papi->address_pretty_printer (papi->cls, + plugin_name, + address, address_len, + numeric, + rtimeout, + &transmit_address_to_client, actx); } diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index edc253dae..8cd606f81 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -561,92 +561,119 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id, enum GNUNET_TRANSPORT_ValidationState state); + +/** + * Function to call with a textual representation of an address. This + * function will be called several times with different possible + * textual representations, and a last time with @address being NULL + * to signal the end of the iteration. Note that @address NULL + * always is the last call, regardless of the value in @a res. + * + * @param cls closure + * @param address NULL on end of iteration, + * otherwise 0-terminated printable UTF-8 string, + * in particular an empty string if @a res is #GNUNET_NO + * @param res result of the address to string conversion: + * if #GNUNET_OK: conversion successful + * if #GNUNET_NO: address was invalid (or not supported) + * if #GNUNET_SYSERR: communication error (IPC error) + */ static void -process_validation_string (void *cls, const char *address, int res) +process_validation_string (void *cls, + const char *address, + int res) { struct ValidationResolutionContext *vc = cls; char *s_valid; char *s_last; char *s_next; - if (address != NULL ) + if (NULL != address) { if (GNUNET_SYSERR == res) { - FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", - GNUNET_i2s (&vc->id), - vc->addrcp->transport_name, - vc->addrcp->address_length); + FPRINTF (stderr, + "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", + GNUNET_i2s (&vc->id), + vc->addrcp->transport_name, + vc->addrcp->address_length); } if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us) - s_valid = GNUNET_strdup("never"); + s_valid = GNUNET_strdup ("never"); else - s_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->valid_until)); + s_valid = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->valid_until)); if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us) - s_last = GNUNET_strdup("never"); + s_last = GNUNET_strdup ("never"); else - s_last = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->last_validation)); + s_last = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->last_validation)); if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us) - s_next = GNUNET_strdup("never"); + s_next = GNUNET_strdup ("never"); else - s_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); + s_next = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (vc->next_validation)); FPRINTF (stdout, - _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), - GNUNET_i2s (&vc->id), - (GNUNET_OK == res) ? address : "", - (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", - "Valid until : ", s_valid, - "Last validation: ",s_last, - "Next validation: ", s_next); + _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"), + GNUNET_i2s (&vc->id), + (GNUNET_OK == res) ? address : "", + (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "", + "Valid until : ", s_valid, + "Last validation: ",s_last, + "Next validation: ", s_next); GNUNET_free (s_valid); GNUNET_free (s_last); GNUNET_free (s_next); vc->printed = GNUNET_YES; + return; } - else + /* last call, we are done */ + GNUNET_assert (address_resolutions > 0); + address_resolutions--; + if ( (GNUNET_SYSERR == res) && + (GNUNET_NO == vc->printed) ) { - /* done */ - - GNUNET_assert(address_resolutions > 0); - address_resolutions--; - if ((GNUNET_SYSERR == res) && (GNUNET_NO == vc->printed)) + if (numeric == GNUNET_NO) { - if (numeric == GNUNET_NO) - { - /* Failed to resolve address, try numeric lookup */ - resolve_validation_address (&vc->id, vc->addrcp, GNUNET_NO, - vc->last_validation, vc->valid_until, vc->next_validation, - vc->state); - } - else - { - FPRINTF (stdout, _("Peer `%s' %s `%s' \n"), - GNUNET_i2s (&vc->id), "", - GNUNET_TRANSPORT_vs2s (vc->state)); - } + /* Failed to resolve address, try numeric lookup + (note: this should be unnecessary, as + transport should fallback to numeric lookup + internally if DNS takes too long anyway) */ + resolve_validation_address (&vc->id, + vc->addrcp, + GNUNET_NO, + vc->last_validation, + vc->valid_until, + vc->next_validation, + vc->state); } - GNUNET_free (vc->transport); - GNUNET_free (vc->addrcp); - GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, vc); - GNUNET_free(vc); - if ((0 == address_resolutions) && (iterate_validation)) + else { - if (GNUNET_SCHEDULER_NO_TASK != end) - { - GNUNET_SCHEDULER_cancel (end); - end = GNUNET_SCHEDULER_NO_TASK; - } - if (GNUNET_SCHEDULER_NO_TASK != op_timeout) - { - GNUNET_SCHEDULER_cancel (op_timeout); - op_timeout = GNUNET_SCHEDULER_NO_TASK; - } - ret = 0; - end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL ); + FPRINTF (stdout, + _("Peer `%s' %s `%s' \n"), + GNUNET_i2s (&vc->id), + "", + GNUNET_TRANSPORT_vs2s (vc->state)); + } + } + GNUNET_free (vc->transport); + GNUNET_free (vc->addrcp); + GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, vc); + GNUNET_free (vc); + if ((0 == address_resolutions) && (iterate_validation)) + { + if (GNUNET_SCHEDULER_NO_TASK != end) + { + GNUNET_SCHEDULER_cancel (end); + end = GNUNET_SCHEDULER_NO_TASK; + } + if (GNUNET_SCHEDULER_NO_TASK != op_timeout) + { + GNUNET_SCHEDULER_cancel (op_timeout); + op_timeout = GNUNET_SCHEDULER_NO_TASK; } + ret = 0; + end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } } @@ -654,11 +681,12 @@ process_validation_string (void *cls, const char *address, int res) static void resolve_validation_address (const struct GNUNET_PeerIdentity *id, - const struct GNUNET_HELLO_Address *address, int numeric, - struct GNUNET_TIME_Absolute last_validation, - struct GNUNET_TIME_Absolute valid_until, - struct GNUNET_TIME_Absolute next_validation, - enum GNUNET_TRANSPORT_ValidationState state) + const struct GNUNET_HELLO_Address *address, + int numeric, + struct GNUNET_TIME_Absolute last_validation, + struct GNUNET_TIME_Absolute valid_until, + struct GNUNET_TIME_Absolute next_validation, + enum GNUNET_TRANSPORT_ValidationState state) { struct ValidationResolutionContext *vc; @@ -677,8 +705,11 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id, vc->next_validation = next_validation; /* Resolve address to string */ - vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, - RESOLUTION_TIMEOUT, &process_validation_string, vc); + vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, + address, + numeric, + RESOLUTION_TIMEOUT, + &process_validation_string, vc); } @@ -910,7 +941,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) * @param peer the peer that disconnected */ static void -notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) +notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer) { if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) return; @@ -957,14 +989,19 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) * @param peer the peer that connected */ static void -monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) +monitor_notify_connect (void *cls, + const struct GNUNET_PeerIdentity *peer) { monitor_connect_counter++; struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); - FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str, - _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter); + FPRINTF (stdout, + _("%24s: %-17s %4s (%u connections in total)\n"), + now_str, + _("Connected to"), + GNUNET_i2s (peer), + monitor_connect_counter); } @@ -976,7 +1013,8 @@ monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) * @param peer the peer that disconnected */ static void -monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) +monitor_notify_disconnect (void *cls, + const struct GNUNET_PeerIdentity *peer) { struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); @@ -984,8 +1022,12 @@ monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) GNUNET_assert(monitor_connect_counter > 0); monitor_connect_counter--; - FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str, - _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter); + FPRINTF (stdout, + _("%24s: %-17s %4s (%u connections in total)\n"), + now_str, + _("Disconnected from"), + GNUNET_i2s (peer), + monitor_connect_counter); } @@ -1006,8 +1048,10 @@ notify_receive (void *cls, if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type)) return; if (verbosity > 0) - FPRINTF (stdout, _("Received %u bytes from %s\n"), - (unsigned int) ntohs (message->size), GNUNET_i2s (peer)); + FPRINTF (stdout, + _("Received %u bytes from %s\n"), + (unsigned int) ntohs (message->size), + GNUNET_i2s (peer)); if (traffic_received == 0) start_time = GNUNET_TIME_absolute_get (); @@ -1036,83 +1080,125 @@ print_info (const struct GNUNET_PeerIdentity *id, if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || (GNUNET_YES == monitor_connections) ) { - FPRINTF (stdout, _("Peer `%s': %s %s in state `%s' until %s\n"), - GNUNET_i2s (id), - (NULL == transport) ? "" : transport, - (NULL == transport) ? "" : addr, - GNUNET_TRANSPORT_ps2s (state), - GNUNET_STRINGS_absolute_time_to_string (state_timeout)); + FPRINTF (stdout, + _("Peer `%s': %s %s in state `%s' until %s\n"), + GNUNET_i2s (id), + (NULL == transport) ? "" : transport, + (NULL == transport) ? "" : addr, + GNUNET_TRANSPORT_ps2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); } else if ( (GNUNET_YES == iterate_connections) && (GNUNET_TRANSPORT_is_connected(state)) ) { /* Only connected peers, skip state */ - FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (id), transport, addr); + FPRINTF (stdout, + _("Peer `%s': %s %s\n"), + GNUNET_i2s (id), + transport, + addr); } } +/** + * Function called with a textual representation of an address. This + * function will be called several times with different possible + * textual representations, and a last time with @address being NULL + * to signal the end of the iteration. Note that @address NULL + * always is the last call, regardless of the value in @a res. + * + * @param cls closure + * @param address NULL on end of iteration, + * otherwise 0-terminated printable UTF-8 string, + * in particular an empty string if @a res is #GNUNET_NO + * @param res result of the address to string conversion: + * if #GNUNET_OK: conversion successful + * if #GNUNET_NO: address was invalid (or not supported) + * if #GNUNET_SYSERR: communication error (IPC error) + */ static void -process_peer_string (void *cls, const char *address, int res) +process_peer_string (void *cls, + const char *address, + int res) { struct PeerResolutionContext *rc = cls; - if (GNUNET_SYSERR == res) + if (NULL != address) { - FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", - GNUNET_i2s (&rc->id), - rc->addrcp->transport_name, - rc->addrcp->address_length); - print_info (&rc->id, rc->transport, NULL, rc->state, rc->state_timeout); - rc->printed = GNUNET_YES; + if (GNUNET_SYSERR == res) + { + FPRINTF (stderr, + "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n", + GNUNET_i2s (&rc->id), + rc->addrcp->transport_name, + rc->addrcp->address_length); + print_info (&rc->id, + rc->transport, + NULL, + rc->state, + rc->state_timeout); + rc->printed = GNUNET_YES; + return; + } + if (GNUNET_OK == res) + { + print_info (&rc->id, + rc->transport, + address, + rc->state, + rc->state_timeout); + rc->printed = GNUNET_YES; + return; /* Wait for done call */ + } + /* GNUNET_NO == res: ignore, was simply not supported */ return; } + /* NULL == address, last call, we are done */ - if ((GNUNET_OK == res) && (address != NULL)) + GNUNET_assert (address_resolutions > 0); + address_resolutions--; + if (GNUNET_NO == rc->printed) { - print_info (&rc->id, rc->transport, address, rc->state, rc->state_timeout); - rc->printed = GNUNET_YES; - return; /* Wait for done call */ + if (numeric == GNUNET_NO) + { + /* Failed to resolve address, try numeric lookup + (note: this should not be needed, as transport + should fallback to numeric conversion if DNS takes + too long) */ + resolve_peer_address (&rc->id, + rc->addrcp, + GNUNET_YES, + rc->state, + rc->state_timeout); + } + else + { + print_info (&rc->id, + rc->transport, + NULL, + rc->state, + rc->state_timeout); + } } - - if (NULL == address) + GNUNET_free (rc->transport); + GNUNET_free (rc->addrcp); + GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); + GNUNET_free (rc); + if ((0 == address_resolutions) && (iterate_connections)) { - /* done */ - GNUNET_assert(address_resolutions > 0); - address_resolutions--; - if (GNUNET_NO == rc->printed) + if (GNUNET_SCHEDULER_NO_TASK != end) { - if (numeric == GNUNET_NO) - { - /* Failed to resolve address, try numeric lookup */ - resolve_peer_address (&rc->id, rc->addrcp, GNUNET_YES, - rc->state, rc->state_timeout); - } - else - { - print_info (&rc->id, rc->transport, NULL, - rc->state, rc->state_timeout); - } + GNUNET_SCHEDULER_cancel (end); + end = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_free (rc->transport); - GNUNET_free (rc->addrcp); - GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc); - GNUNET_free(rc); - if ((0 == address_resolutions) && (iterate_connections)) + if (GNUNET_SCHEDULER_NO_TASK != op_timeout) { - if (GNUNET_SCHEDULER_NO_TASK != end) - { - GNUNET_SCHEDULER_cancel (end); - end = GNUNET_SCHEDULER_NO_TASK; - } - if (GNUNET_SCHEDULER_NO_TASK != op_timeout) - { - GNUNET_SCHEDULER_cancel (op_timeout); - op_timeout = GNUNET_SCHEDULER_NO_TASK; - } - ret = 0; - end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL ); + GNUNET_SCHEDULER_cancel (op_timeout); + op_timeout = GNUNET_SCHEDULER_NO_TASK; } + ret = 0; + end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL ); } } @@ -1138,8 +1224,11 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id, rc->state = state; rc->state_timeout = state_timeout; /* Resolve address to string */ - rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric, - RESOLUTION_TIMEOUT, &process_peer_string, rc); + rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, + address, + numeric, + RESOLUTION_TIMEOUT, + &process_peer_string, rc); } @@ -1177,12 +1266,14 @@ process_peer_iteration_cb (void *cls, if (GNUNET_SCHEDULER_NO_TASK != op_timeout) GNUNET_SCHEDULER_cancel (op_timeout); - op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, + op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, + &operation_timeout, NULL); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Received address for peer `%s': %s\n", - GNUNET_i2s (peer), address->transport_name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received address for peer `%s': %s\n", + GNUNET_i2s (peer), + address->transport_name); if (NULL != address) resolve_peer_address (peer, address, numeric, state, state_timeout); @@ -1221,7 +1312,8 @@ process_peer_monitoring_cb (void *cls, if (GNUNET_SCHEDULER_NO_TASK != op_timeout) GNUNET_SCHEDULER_cancel (op_timeout); - op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, + op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, + &operation_timeout, NULL); if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) @@ -1254,15 +1346,26 @@ process_peer_monitoring_cb (void *cls, m->state_timeout = state_timeout; if (NULL != address) - resolve_peer_address (peer, m->address, numeric, m->state, m->state_timeout); + resolve_peer_address (peer, + m->address, + numeric, + m->state, + m->state_timeout); else - print_info (peer, NULL, NULL, m->state, m->state_timeout); + print_info (peer, + NULL, + NULL, + m->state, + m->state_timeout); } + static void -try_connect_cb (void *cls, const int result) +try_connect_cb (void *cls, + const int result) { static int retries = 0; + if (GNUNET_OK == result) { tc_handle = NULL; @@ -1274,8 +1377,9 @@ try_connect_cb (void *cls, const int result) NULL ); else { - FPRINTF (stderr, "%s", - _("Failed to send connect request to transport service\n") ); + FPRINTF (stderr, + "%s", + _("Failed to send connect request to transport service\n") ); if (GNUNET_SCHEDULER_NO_TASK != end) GNUNET_SCHEDULER_cancel (end); ret = 1; @@ -1284,8 +1388,10 @@ try_connect_cb (void *cls, const int result) } } + static void -try_disconnect_cb (void *cls, const int result) +try_disconnect_cb (void *cls, + const int result) { static int retries = 0; if (GNUNET_OK == result) @@ -1309,6 +1415,7 @@ try_disconnect_cb (void *cls, const int result) } } + /** * Function called with the result of the check if the 'transport' * service is running. diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c index aad96cf69..8ab64b15c 100644 --- a/src/transport/plugin_transport_bluetooth.c +++ b/src/transport/plugin_transport_bluetooth.c @@ -504,7 +504,9 @@ struct MacAndSession * @return string representing the same address */ static const char * -bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen); +bluetooth_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen); /** * Print MAC addresses nicely. @@ -1055,7 +1057,9 @@ create_macendpoint (struct Plugin *plugin, 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", - bluetooth_plugin_address_to_string(NULL, addr, sizeof (struct WlanAddress))); + bluetooth_plugin_address_to_string(NULL, + addr, + sizeof (struct WlanAddress))); return pos; } @@ -1119,8 +1123,11 @@ bluetooth_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Service asked to create session for peer `%s' with MAC `%s'\n", GNUNET_i2s (&address->peer), - bluetooth_plugin_address_to_string(NULL, address->address, address->address_length)); - endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address); + bluetooth_plugin_address_to_string(NULL, + address->address, + address->address_length)); + endpoint = create_macendpoint (plugin, + (struct WlanAddress *) address->address); return get_session (endpoint, &address->peer); } @@ -1300,8 +1307,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", (unsigned int) msize, GNUNET_i2s (&tmpsource), - bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, - sizeof (mas->endpoint->addr))); + bluetooth_plugin_address_to_string (NULL, + &mas->endpoint->addr, + sizeof (mas->endpoint->addr))); GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO messages received via Bluetooth"), 1, @@ -1325,10 +1333,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing %u bytes of FRAGMENT from MAC %s\n", (unsigned int) msize, - bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, - sizeof (mas->endpoint->addr))); + bluetooth_plugin_address_to_string (NULL, + &mas->endpoint->addr, + sizeof (mas->endpoint->addr))); GNUNET_STATISTICS_update (plugin->env->stats, - _("# fragments received via Bluetooth"), 1, GNUNET_NO); + _("# fragments received via Bluetooth"), + 1, + GNUNET_NO); (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, hdr); break; @@ -1347,8 +1358,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Got last ACK, finished message transmission to `%s' (%p)\n", - bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, - sizeof (mas->endpoint->addr)), + bluetooth_plugin_address_to_string (NULL, + &mas->endpoint->addr, + sizeof (mas->endpoint->addr)), fm); mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); if (NULL != fm->cont) @@ -1363,15 +1375,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK, message transmission to `%s' not yet finished\n", - bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, - sizeof (mas->endpoint->addr))); + bluetooth_plugin_address_to_string (NULL, + &mas->endpoint->addr, + sizeof (mas->endpoint->addr))); break; } } LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK not matched against any active fragmentation with MAC `%s'\n", - bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, - sizeof (mas->endpoint->addr))); + bluetooth_plugin_address_to_string (NULL, + &mas->endpoint->addr, + sizeof (mas->endpoint->addr))); break; case GNUNET_MESSAGE_TYPE_WLAN_DATA: if (NULL == mas->endpoint) @@ -1675,7 +1689,9 @@ bluetooth_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) * @return string representing the same address */ static const char * -bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) +bluetooth_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; static char macstr[36]; @@ -1686,9 +1702,12 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) return NULL; } mac = &((struct WlanAddress *) addr)->mac; - GNUNET_snprintf (macstr, sizeof (macstr), "%s.%u.%s", - PLUGIN_NAME, ntohl (((struct WlanAddress *) addr)->options), - mac_to_string (mac)); + GNUNET_snprintf (macstr, + sizeof (macstr), + "%s.%u.%s", + PLUGIN_NAME, + ntohl (((struct WlanAddress *) addr)->options), + mac_to_string (mac)); return macstr; } @@ -1704,7 +1723,7 @@ bluetooth_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string - * @param asc_cls closure for asc + * @param asc_cls closure for @a asc */ static void bluetooth_plugin_address_pretty_printer (void *cls, const char *type, @@ -1714,19 +1733,15 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) { - char *ret; + const char *ret; - if (sizeof (struct WlanAddress) != addrlen) - { - /* invalid address */ - asc (asc_cls, NULL, GNUNET_SYSERR); - } + if (sizeof (struct WlanAddress) == addrlen) + ret = bluetooth_plugin_address_to_string(NULL, addr, addrlen); else - { - ret = GNUNET_strdup (bluetooth_plugin_address_to_string(NULL, addr, addrlen)); - asc (asc_cls, ret, GNUNET_OK); - GNUNET_free (ret); - } + ret = NULL; + asc (asc_cls, + ret, + (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); asc (asc_cls, NULL, GNUNET_OK); } diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 15150b3dc..d853cc7f7 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -1190,20 +1190,25 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if ((0 != msg->data.result) || (http_statuscode != 200)) { - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n", - s, msg->easy_handle, GNUNET_i2s (&s->target), - http_statuscode, - msg->data.result, - curl_easy_strerror (msg->data.result)); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + plugin->name, + "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n", + s, msg->easy_handle, + GNUNET_i2s (&s->target), + http_statuscode, + msg->data.result, + curl_easy_strerror (msg->data.result)); } else - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, - "Session %p/connection %p: PUT connection to `%s' ended normal\n", - s, msg->easy_handle, GNUNET_i2s (&s->target)); - if (s->client_get == NULL) + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + plugin->name, + "Session %p/connection %p: PUT connection to `%s' ended normal\n", + s, msg->easy_handle, + GNUNET_i2s (&s->target)); + if (NULL == s->client_get) { /* Disconnect other transmission direction and tell transport */ + /* FIXME? */ } curl_multi_remove_handle (plugin->curl_multi_handle, easy_h); curl_easy_cleanup (easy_h); diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index f5712db58..02129f37d 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c @@ -207,18 +207,24 @@ http_common_plugin_address_pretty_printer (void *cls, void *asc_cls) { const struct HttpAddress *address = addr; - - if (NULL - == http_common_plugin_address_to_string (NULL, type, address, addrlen)) - asc (asc_cls, NULL, GNUNET_SYSERR); - else - asc (asc_cls, - http_common_plugin_address_to_string (NULL, type, address, addrlen), - GNUNET_OK); - asc (asc_cls, NULL, GNUNET_OK); + const char *ret; + + ret = http_common_plugin_address_to_string (NULL, + type, + address, + addrlen); + asc (asc_cls, + NULL, + (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); + asc (asc_cls, + NULL, + GNUNET_OK); } +/** + * FIXME. + */ const char * http_common_plugin_address_to_url (void *cls, const void *addr, 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 @@ /* - This file is part of GNUnet - (C) 2002--2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + This file is part of GNUnet + (C) 2002--2014 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ /** * @file transport/plugin_transport_tcp.c @@ -562,13 +562,15 @@ tcp_address_to_string (void *cls, sb = &a4; break; default: - LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"), - (unsigned int ) addrlen); + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Unexpected address length: %u bytes\n"), + (unsigned int ) addrlen); return NULL ; } if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) { - GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, + "inet_ntop"); return NULL ; } GNUNET_snprintf (rbuf, sizeof(rbuf), @@ -816,9 +818,11 @@ tcp_disconnect_session (void *cls, while (NULL != (pm = session->pending_messages_head)) { - LOG(GNUNET_ERROR_TYPE_DEBUG, - pm->transmit_cont != NULL ? "Could not deliver message to `%4s'.\n" : "Could not deliver message to `%4s', notifying.\n", - GNUNET_i2s (&session->target)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + (NULL != pm->transmit_cont) + ? "Could not deliver message to `%4s'.\n" + : "Could not deliver message to `%4s', notifying.\n", + GNUNET_i2s (&session->target)); GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) pm->message_size, GNUNET_NO); @@ -1651,7 +1655,8 @@ static struct PrettyPrinterContext *ppc_dll_head; static struct PrettyPrinterContext *ppc_dll_tail; /** - * Context for address to string conversion. + * Context for address to string conversion, closure + * for #append_port(). */ struct PrettyPrinterContext { @@ -1681,7 +1686,7 @@ struct PrettyPrinterContext GNUNET_TRANSPORT_AddressStringCallback asc; /** - * Clsoure for 'asc'. + * Clsoure for @e asc. */ void *asc_cls; @@ -1701,64 +1706,54 @@ struct PrettyPrinterContext uint32_t options; }; -static void -ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct PrettyPrinterContext *ppc = cls; - - ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; - if (NULL != ppc->resolver_handle) - { - GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); - ppc->resolver_handle = NULL; - } - GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); - GNUNET_free(ppc); -} /** * Append our port and forward the result. * - * @param cls the 'struct PrettyPrinterContext*' + * @param cls the `struct PrettyPrinterContext *` * @param hostname hostname part of the address */ static void -append_port (void *cls, const char *hostname) +append_port (void *cls, + const char *hostname) { struct PrettyPrinterContext *ppc = cls; - struct PrettyPrinterContext *cur; char *ret; if (NULL == hostname) { - ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */ - GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); - GNUNET_SCHEDULER_cancel (ppc->timeout_task); - ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; + /* Final call, done */ ppc->resolver_handle = NULL; - GNUNET_free(ppc); + GNUNET_CONTAINER_DLL_remove (ppc_dll_head, + ppc_dll_tail, + ppc); + ppc->asc (ppc->asc_cls, + NULL, + GNUNET_OK); + GNUNET_free (ppc); return; } - for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) - if (cur == ppc) - break; - if (NULL == cur) - { - ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR); - GNUNET_break(0); - return; - } - if (GNUNET_YES == ppc->ipv6) - GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, - ppc->port); + GNUNET_asprintf (&ret, + "%s.%u.[%s]:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); else - GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, - ppc->port); - ppc->asc (ppc->asc_cls, ret, GNUNET_OK); - GNUNET_free(ret); + GNUNET_asprintf (&ret, + "%s.%u.%s:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); + ppc->asc (ppc->asc_cls, + ret, + GNUNET_OK); + GNUNET_free (ret); } + /** * Convert the transports address to a nice, human-readable * format. @@ -1767,18 +1762,21 @@ append_port (void *cls, const char *hostname) * @param type name of the transport that generated the address * @param addr one of the addresses of the host, NULL for the last address * the specific address format depends on the transport - * @param addrlen length of the address + * @param addrlen length of the @a addr * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string - * @param asc_cls closure for asc - * + * @param asc_cls closure for @a asc */ static void -tcp_plugin_address_pretty_printer (void *cls, const char *type, - const void *addr, size_t addrlen, int numeric, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) +tcp_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressStringCallback asc, + void *asc_cls) { struct PrettyPrinterContext *ppc; const void *sb; @@ -1790,7 +1788,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, uint16_t port; uint32_t options; - if (addrlen == sizeof(struct IPv6TcpAddress)) + if (sizeof(struct IPv6TcpAddress) == addrlen) { t6 = addr; memset (&a6, 0, sizeof(a6)); @@ -1802,7 +1800,7 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, sb = &a6; sbs = sizeof(a6); } - else if (addrlen == sizeof(struct IPv4TcpAddress)) + else if (sizeof(struct IPv4TcpAddress) == addrlen) { t4 = addr; memset (&a4, 0, sizeof(a4)); @@ -1830,21 +1828,23 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, ppc->asc_cls = asc_cls; ppc->port = port; ppc->options = options; - ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); - ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, - timeout, &append_port, ppc); - if (NULL != ppc->resolver_handle) + ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, + sbs, + ! numeric, + timeout, + &append_port, ppc); + if (NULL == ppc->resolver_handle) { - GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); - } - else - { - GNUNET_break(0); - GNUNET_free(ppc); + GNUNET_break (0); + GNUNET_free (ppc); + return; } + GNUNET_CONTAINER_DLL_insert (ppc_dll_head, + ppc_dll_tail, + ppc); } + /** * Check if the given port is plausible (must be either our listen * port or our advertised port), or any port if we are behind NAT @@ -2496,12 +2496,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) aport = 0; if (bport != 0) { - service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, - GNUNET_SERVICE_OPTION_NONE); - if (service == NULL ) + service = GNUNET_SERVICE_start ("transport-tcp", + env->cfg, + GNUNET_SERVICE_OPTION_NONE); + if (service == NULL) { - LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); - return NULL ; + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Failed to start service.\n")); + return NULL; } } else @@ -2555,7 +2557,6 @@ libgnunet_plugin_transport_tcp_init (void *cls) api->cls = plugin; api->send = &tcp_plugin_send; api->get_session = &tcp_plugin_get_session; - api->disconnect_session = &tcp_disconnect_session; api->query_keepalive_factor = &tcp_query_keepalive_factor; api->disconnect_peer = &tcp_plugin_disconnect; @@ -2588,9 +2589,10 @@ libgnunet_plugin_transport_tcp_init (void *cls) GNUNET_free(api); return NULL; } - plugin->server = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, - plugin, NULL, - idle_timeout, GNUNET_YES); + plugin->server + = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, + plugin, NULL, + idle_timeout, GNUNET_YES); } plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); @@ -2656,13 +2658,13 @@ libgnunet_plugin_transport_tcp_done (void *cls) next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) { + GNUNET_break (0); next = cur->next; - GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); - if (NULL != cur->resolver_handle) - GNUNET_RESOLVER_request_cancel (cur->resolver_handle); - GNUNET_SCHEDULER_cancel (cur->timeout_task); - GNUNET_free(cur); - GNUNET_break(0); + GNUNET_CONTAINER_DLL_remove (ppc_dll_head, + ppc_dll_tail, + cur); + GNUNET_RESOLVER_request_cancel (cur->resolver_handle); + GNUNET_free (cur); } if (NULL != plugin->service) diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 9bf2d8181..08a532aed 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -75,7 +75,7 @@ static struct PrettyPrinterContext *ppc_dll_tail; /** - * Closure for 'append_port'. + * Closure for #append_port(). */ struct PrettyPrinterContext { @@ -717,23 +717,6 @@ udp_string_to_address (void *cls, } -static void -ppc_cancel_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct PrettyPrinterContext *ppc = cls; - - ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; - if (NULL != ppc->resolver_handle) - { - GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); - ppc->resolver_handle = NULL; - } - GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); - GNUNET_free(ppc); -} - - /** * Append our port and forward the result. * @@ -744,37 +727,39 @@ static void append_port (void *cls, const char *hostname) { struct PrettyPrinterContext *ppc = cls; - struct PrettyPrinterContext *cur; char *ret; - if (hostname == NULL ) + if (NULL == hostname) { - ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); /* Final call, done */ - GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); - GNUNET_SCHEDULER_cancel (ppc->timeout_task); - ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; + /* Final call, done */ + ppc->asc (ppc->asc_cls, + NULL, + GNUNET_OK); + GNUNET_CONTAINER_DLL_remove (ppc_dll_head, + ppc_dll_tail, + ppc); ppc->resolver_handle = NULL; - GNUNET_free(ppc); + GNUNET_free (ppc); return; } - for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) - if (cur == ppc) - break; - if (NULL == cur) - { - ppc->asc (ppc->asc_cls, NULL, GNUNET_SYSERR); - GNUNET_break(0); - return; - } - if (GNUNET_YES == ppc->ipv6) - GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, - ppc->port); + GNUNET_asprintf (&ret, + "%s.%u.[%s]:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); else - GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, - ppc->port); - ppc->asc (ppc->asc_cls, ret, GNUNET_OK); - GNUNET_free(ret); + GNUNET_asprintf (&ret, + "%s.%u.%s:%d", + PLUGIN_NAME, + ppc->options, + hostname, + ppc->port); + ppc->asc (ppc->asc_cls, + ret, + GNUNET_OK); + GNUNET_free (ret); } @@ -845,7 +830,7 @@ udp_plugin_address_pretty_printer (void *cls, else { /* invalid address */ - GNUNET_break_op(0); + GNUNET_break_op (0); asc (asc_cls, NULL , GNUNET_SYSERR); asc (asc_cls, NULL, GNUNET_OK); return; @@ -859,11 +844,15 @@ udp_plugin_address_pretty_printer (void *cls, ppc->ipv6 = GNUNET_YES; else ppc->ipv6 = GNUNET_NO; - ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); - GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); - ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, - timeout, &append_port, ppc); + GNUNET_CONTAINER_DLL_insert (ppc_dll_head, + ppc_dll_tail, + ppc); + ppc->resolver_handle + = GNUNET_RESOLVER_hostname_get (sb, + sbs, + ! numeric, + timeout, + &append_port, ppc); } @@ -3313,8 +3302,8 @@ libgnunet_plugin_transport_udp_done (void *cls) } /* Clean up sessions */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up sessions\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up sessions\n"); GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); @@ -3322,12 +3311,13 @@ libgnunet_plugin_transport_udp_done (void *cls) next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) { + GNUNET_break(0); next = cur->next; - GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); + GNUNET_CONTAINER_DLL_remove (ppc_dll_head, + ppc_dll_tail, + cur); GNUNET_RESOLVER_request_cancel (cur->resolver_handle); - GNUNET_SCHEDULER_cancel (cur->timeout_task); - GNUNET_free(cur); - GNUNET_break(0); + GNUNET_free (cur); } GNUNET_free (plugin); GNUNET_free (api); diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 792d7718e..03c38f4e1 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -64,9 +64,9 @@ GNUNET_NETWORK_STRUCT_BEGIN struct UnixAddress { - uint32_t options GNUNET_PACKED; + uint32_t options GNUNET_PACKED; - uint32_t addrlen GNUNET_PACKED; + uint32_t addrlen GNUNET_PACKED; }; @@ -340,6 +340,7 @@ reschedule_session_timeout (struct Session *s); static void unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); + static struct sockaddr_un * unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) @@ -372,11 +373,13 @@ unix_address_to_sockaddr (const char *unixpath, * * @param cls closure * @param addr binary address - * @param addrlen length of the address + * @param addrlen length of the @a addr * @return string representing the same address */ static const char * -unix_address_to_string (void *cls, const void *addr, size_t addrlen) +unix_address_to_string (void *cls, + const void *addr, + size_t addrlen) { static char rbuf[1024]; struct UnixAddress *ua = (struct UnixAddress *) addr; @@ -387,7 +390,7 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen) if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) { GNUNET_break(0); - return NULL ; + return NULL; } addrstr = (char *) &ua[1]; addr_str_len = ntohl (ua->addrlen); @@ -395,39 +398,36 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen) if (addr_str_len != addrlen - sizeof(struct UnixAddress)) { GNUNET_break(0); - return NULL ; + return NULL; } if ('\0' != addrstr[addr_str_len - 1]) { GNUNET_break(0); - return NULL ; + return NULL; } if (strlen (addrstr) + 1 != addr_str_len) { GNUNET_break(0); - return NULL ; + return NULL; } off = 0; if ('\0' == addrstr[0]) off++; memset (rbuf, 0, sizeof (rbuf)); - GNUNET_snprintf (rbuf, sizeof (rbuf) - 1, "%s.%u.%s%.*s", - PLUGIN_NAME, - ntohl (ua->options), - (off == 1) ? "@" : "", - (int) (addr_str_len - off), - &addrstr[off]); -/* - GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, - ntohl (ua->options), addrstr);*/ + GNUNET_snprintf (rbuf, + sizeof (rbuf) - 1, + "%s.%u.%s%.*s", + PLUGIN_NAME, + ntohl (ua->options), + (off == 1) ? "@" : "", + (int) (addr_str_len - off), + &addrstr[off]); return rbuf; } - - /** * Re-schedule the main 'select' callback (unix_plugin_select) * for this plugin. @@ -547,7 +547,9 @@ unix_session_disconnect (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting session for peer `%s' `%s'\n", GNUNET_i2s (&s->target), - unix_address_to_string (NULL, s->address->address, s->address->address_length) ); + unix_address_to_string (NULL, + s->address->address, + s->address->address_length)); plugin->env->session_end (plugin->env->cls, s->address, s); removed = GNUNET_NO; next = plugin->msg_head; @@ -870,7 +872,8 @@ unix_plugin_get_session (void *cls, &get_session_it, &gsi); if (NULL != gsi.res) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n", + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Found existing session %p for address `%s'\n", gsi.res, unix_address_to_string (NULL, address->address, address->address_length)); return gsi.res; @@ -887,7 +890,10 @@ unix_plugin_get_session (void *cls, s); LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating a new session %p for address `%s'\n", - s, unix_address_to_string (NULL, address->address, address->address_length)); + s, + unix_address_to_string (NULL, + address->address, + address->address_length)); (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, &address->peer, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); @@ -961,8 +967,9 @@ unix_plugin_send (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session for peer `%s' `%s'\n", GNUNET_i2s (&session->target), - unix_address_to_string(NULL, session->address->address, - session->address->address_length)); + unix_address_to_string(NULL, + session->address->address, + session->address->address_length)); GNUNET_break (0); return GNUNET_SYSERR; } @@ -970,8 +977,9 @@ unix_plugin_send (void *cls, "Sending %u bytes with session for peer `%s' `%s'\n", msgbuf_size, GNUNET_i2s (&session->target), - unix_address_to_string(NULL, session->address->address, - session->address->address_length)); + unix_address_to_string (NULL, + session->address->address, + session->address->address_length)); ssize = sizeof (struct UNIXMessage) + msgbuf_size; message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); message->header.size = htons (ssize); @@ -1024,7 +1032,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n", - unix_address_to_string(NULL, ua, ua_len)); + unix_address_to_string (NULL, ua, ua_len)); GNUNET_STATISTICS_update (plugin->env->stats, "# bytes received via UNIX", ntohs (currhdr->size), @@ -1419,12 +1427,17 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) { - if ((NULL != addr) && (addrlen > 0)) - { - asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK); - } + const char *ret; + + if ( (NULL != addr) && (addrlen > 0)) + ret = unix_address_to_string (NULL, + addr, + addrlen); else - asc (asc_cls, NULL, GNUNET_SYSERR); + ret = NULL; + asc (asc_cls, + ret, + (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); asc (asc_cls, NULL, GNUNET_OK); } @@ -1433,7 +1446,7 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, * Function called to convert a string address to * a binary address. * - * @param cls closure ('struct Plugin*') + * @param cls closure (`struct Plugin *`) * @param addr string address * @param addrlen length of the @a addr (strlen(addr) + '\0') * @param buf location to store the buffer @@ -1573,7 +1586,7 @@ reschedule_session_timeout (struct Session *s) * * @param cls the plugin * @param key peer identity (unused) - * @param value the 'struct Session' to disconnect + * @param value the `struct Session *` to disconnect * @return #GNUNET_YES (always, continue to iterate) */ static int diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index f0197feb8..6da3365eb 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1073,7 +1073,9 @@ create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac) if (0 == memcmp (mac, &pos->wlan_addr, sizeof (pos->wlan_addr))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing MAC endpoint `%s'\n", - wlan_plugin_address_to_string(NULL, &pos->wlan_addr.mac, sizeof (pos->wlan_addr))); + wlan_plugin_address_to_string (NULL, + &pos->wlan_addr.mac, + sizeof (pos->wlan_addr))); return pos; } } @@ -1097,8 +1099,11 @@ create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac) plugin->mac_count++; GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), 1, GNUNET_NO); - LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", - wlan_plugin_address_to_string(NULL, &pos->wlan_addr, sizeof (struct WlanAddress))); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "New MAC endpoint `%s'\n", + wlan_plugin_address_to_string (NULL, + &pos->wlan_addr, + sizeof (struct WlanAddress))); return pos; } @@ -1144,7 +1149,9 @@ wlan_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Service asked to create session for peer `%s' with MAC `%s'\n", GNUNET_i2s (&address->peer), - wlan_plugin_address_to_string(NULL, address->address, address->address_length)); + wlan_plugin_address_to_string (NULL, + address->address, + address->address_length)); endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address); return get_session (endpoint, &address->peer); } @@ -1295,8 +1302,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", (unsigned int) msize, GNUNET_i2s (&tmpsource), - wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, - sizeof (mas->endpoint->wlan_addr))); + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof (mas->endpoint->wlan_addr))); GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO messages received via WLAN"), 1, @@ -1320,8 +1328,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing %u bytes of FRAGMENT from MAC %s\n", (unsigned int) msize, - wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, - sizeof (mas->endpoint->wlan_addr))); + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof (mas->endpoint->wlan_addr))); GNUNET_STATISTICS_update (plugin->env->stats, _("# fragments received via WLAN"), 1, GNUNET_NO); (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, @@ -1342,8 +1351,9 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Got last ACK, finished message transmission to `%s' (%p)\n", - wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, - sizeof (mas->endpoint->wlan_addr)), + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof (mas->endpoint->wlan_addr)), fm); mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); if (NULL != fm->cont) @@ -1358,15 +1368,17 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK, message transmission to `%s' not yet finished\n", - wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, - sizeof (mas->endpoint->wlan_addr))); + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof (mas->endpoint->wlan_addr))); break; } } LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK not matched against any active fragmentation with MAC `%s'\n", - wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, - sizeof (mas->endpoint->wlan_addr))); + wlan_plugin_address_to_string (NULL, + &mas->endpoint->wlan_addr, + sizeof (mas->endpoint->wlan_addr))); break; case GNUNET_MESSAGE_TYPE_WLAN_DATA: if (NULL == mas->endpoint) @@ -1681,7 +1693,9 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) * @return string representing the same address */ static const char * -wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) +wlan_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; static char macstr[36]; @@ -1692,9 +1706,12 @@ wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) return NULL; } mac = &((struct WlanAddress *) addr)->mac; - GNUNET_snprintf (macstr, sizeof (macstr), "%s.%u.%s", - PLUGIN_NAME, ntohl (((struct WlanAddress *) addr)->options), - mac_to_string (mac)); + GNUNET_snprintf (macstr, + sizeof (macstr), + "%s.%u.%s", + PLUGIN_NAME, + ntohl (((struct WlanAddress *) addr)->options), + mac_to_string (mac)); return macstr; } @@ -1710,29 +1727,29 @@ wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string - * @param asc_cls closure for asc + * @param asc_cls closure for @a asc */ static void -wlan_plugin_address_pretty_printer (void *cls, const char *type, - const void *addr, size_t addrlen, +wlan_plugin_address_pretty_printer (void *cls, + const char *type, + const void *addr, + size_t addrlen, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) { - char *ret; + const char *ret; - if (sizeof (struct WlanAddress) != addrlen) - { - /* invalid address */ - asc (asc_cls, NULL, GNUNET_SYSERR); - } + if (sizeof (struct WlanAddress) == addrlen) + ret = wlan_plugin_address_to_string (NULL, + addr, + addrlen); else - { - ret = GNUNET_strdup (wlan_plugin_address_to_string(NULL, addr, addrlen)); - asc (asc_cls, ret, GNUNET_OK); - GNUNET_free (ret); - } + ret = NULL; + asc (asc_cls, + ret, + (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); asc (asc_cls, NULL, GNUNET_OK); } @@ -1815,13 +1832,13 @@ libgnunet_plugin_transport_wlan_done (void *cls) * Function called to convert a string address to * a binary address. * - * @param cls closure ('struct Plugin*') + * @param cls closure (`struct Plugin *`) * @param addr string address * @param addrlen length of the address * @param buf location to store the buffer * @param added location to store the number of bytes in the buffer. - * If the function returns GNUNET_SYSERR, its contents are undefined. - * @return GNUNET_OK on success, GNUNET_SYSERR on failure + * If the function returns #GNUNET_SYSERR, its contents are undefined. + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen, diff --git a/src/transport/transport.h b/src/transport/transport.h index 68c685c29..cbbefb7e1 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -278,31 +278,32 @@ struct SendOkMessage /** * Message used to notify the transport API about an address to string - * conversion. Message is followed by the string with length strlen + * conversion. Message is followed by the string with the humand-readable + * address. For each lookup, multiple results may be returned. The + * last message must have a @e res of #GNUNET_OK and an @e addr_len + * of zero. */ struct AddressToStringResultMessage { /** - * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK + * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY */ struct GNUNET_MessageHeader header; /** - * GNUNET_OK if the conversion succeeded, - * GNUNET_SYSERR if it failed + * #GNUNET_OK if the conversion succeeded, + * #GNUNET_SYSERR if it failed */ uint32_t res GNUNET_PACKED; /** - * Length of the following string + * Length of the following string, zero if @e is #GNUNET_SYSERR */ uint32_t addr_len GNUNET_PACKED; }; - - /** * Message used to notify the transport service about a message * to be transmitted to another peer. The actual message follows. @@ -342,7 +343,7 @@ struct AddressLookupMessage { /** - * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING + * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING */ struct GNUNET_MessageHeader header; @@ -358,11 +359,11 @@ struct AddressLookupMessage uint16_t addrlen GNUNET_PACKED; /** - * timeout to give up. + * timeout to give up (for DNS resolution timeout mostly) */ struct GNUNET_TIME_RelativeNBO timeout; - /* followed by 'addrlen' bytes of the actual address, then + /* followed by @e addrlen bytes of the actual address, then * followed by the 0-terminated name of the transport */ }; @@ -414,10 +415,19 @@ struct ValidationIterateResponseMessage */ uint32_t state GNUNET_PACKED; + /** + * FIXME + */ struct GNUNET_TIME_AbsoluteNBO last_validation; + /** + * FIXME + */ struct GNUNET_TIME_AbsoluteNBO valid_until; + /** + * FIXME + */ struct GNUNET_TIME_AbsoluteNBO next_validation; }; @@ -476,7 +486,7 @@ struct PeerMonitorMessage struct TrafficMetricMessage { /** - * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC + * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC */ struct GNUNET_MessageHeader header; @@ -535,7 +545,7 @@ struct PeerIterateResponseMessage uint32_t local_address_info GNUNET_PACKED; /** - * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element + * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState` */ uint32_t state GNUNET_PACKED; @@ -560,13 +570,13 @@ struct BlacklistMessage { /** - * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or - * GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. + * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or + * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. */ struct GNUNET_MessageHeader header; /** - * 0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed) + * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed) * for the response. */ uint32_t is_allowed GNUNET_PACKED; diff --git a/src/transport/transport_api_address_to_string.c b/src/transport/transport_api_address_to_string.c index d881f9a08..afd0c7deb 100644 --- a/src/transport/transport_api_address_to_string.c +++ b/src/transport/transport_api_address_to_string.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2009, 2010 Christian Grothoff (and other contributing authors) + (C) 2009-2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -17,6 +17,11 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/** + * @file transport/transport_api_address_to_string.c + * @author Christian Grothoff + * @brief enable clients to convert addresses to human readable strings + */ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_arm_service.h" @@ -36,7 +41,7 @@ struct GNUNET_TRANSPORT_AddressToStringContext GNUNET_TRANSPORT_AddressToStringCallback cb; /** - * Closure for cb. + * Closure for @e cb. */ void *cb_cls; @@ -45,10 +50,6 @@ struct GNUNET_TRANSPORT_AddressToStringContext */ struct GNUNET_CLIENT_Connection *client; - /** - * When should this operation time out? - */ - struct GNUNET_TIME_Absolute timeout; }; @@ -64,18 +65,17 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; - struct AddressToStringResultMessage *atsm; + const struct AddressToStringResultMessage *atsm; const char *address; uint16_t size; - uint32_t result; + int result; uint32_t addr_len; - char *empty_str = ""; if (NULL == msg) { alucb->cb (alucb->cb_cls, NULL, - GNUNET_OK); + GNUNET_SYSERR); GNUNET_CLIENT_disconnect (alucb->client); GNUNET_free (alucb); return; @@ -86,54 +86,72 @@ address_response_processor (void *cls, size = ntohs (msg->size); if (size < sizeof (struct AddressToStringResultMessage)) { - alucb->cb (alucb->cb_cls, NULL, GNUNET_OK); + GNUNET_break (0); + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_SYSERR); GNUNET_CLIENT_disconnect (alucb->client); GNUNET_free (alucb); return; } - atsm = (struct AddressToStringResultMessage *) msg; - - result = ntohl (atsm->res); + atsm = (const struct AddressToStringResultMessage *) msg; + result = (int) ntohl (atsm->res); addr_len = ntohl (atsm->addr_len); - - if (size == (sizeof (struct AddressToStringResultMessage))) + if (GNUNET_SYSERR == result) { - /* done, success depends on result */ - alucb->cb (alucb->cb_cls, NULL, result); - GNUNET_CLIENT_disconnect (alucb->client); - GNUNET_free (alucb); + /* expect more replies; as this is not the last + call, we must pass the empty string for the address */ + alucb->cb (alucb->cb_cls, + "", + GNUNET_NO); + GNUNET_CLIENT_receive (alucb->client, + &address_response_processor, + alucb, + GNUNET_TIME_UNIT_FOREVER_REL); return; } - - if (GNUNET_NO == result) + if (size == (sizeof (struct AddressToStringResultMessage))) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p failed to resolve address \n", - alucb->client); - GNUNET_break (0); - alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR); - - /* expect more replies */ - GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, - GNUNET_TIME_absolute_get_remaining (alucb->timeout)); + if (GNUNET_OK != result) + { + GNUNET_break (0); + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_SYSERR); + GNUNET_CLIENT_disconnect (alucb->client); + GNUNET_free (alucb); + return; + } + /* we are done (successfully, without communication errors) */ + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_OK); + GNUNET_CLIENT_disconnect (alucb->client); + GNUNET_free (alucb); return; } - address = (const char *) &atsm[1]; if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) || (address[addr_len -1] != '\0') ) { /* invalid reply */ GNUNET_break (0); - alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR); + alucb->cb (alucb->cb_cls, + NULL, + GNUNET_SYSERR); GNUNET_CLIENT_disconnect (alucb->client); GNUNET_free (alucb); return; } - /* expect more replies */ - GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, - GNUNET_TIME_absolute_get_remaining (alucb->timeout)); - alucb->cb (alucb->cb_cls, address, GNUNET_OK); + GNUNET_CLIENT_receive (alucb->client, + &address_response_processor, + alucb, + GNUNET_TIME_UNIT_FOREVER_REL); + /* return normal reply to caller */ + alucb->cb (alucb->cb_cls, + address, + GNUNET_OK); } @@ -146,17 +164,16 @@ address_response_processor (void *cls, * (otherwise do reverse DNS lookup) * @param timeout how long is the lookup allowed to take at most * @param aluc function to call with the results - * @param aluc_cls closure for aluc + * @param aluc_cls closure for @a aluc * @return handle to cancel the operation, NULL on error */ struct GNUNET_TRANSPORT_AddressToStringContext * -GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle - *cfg, +GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_AddressToStringCallback - aluc, void *aluc_cls) + GNUNET_TRANSPORT_AddressToStringCallback aluc, + void *aluc_cls) { size_t len; size_t alen; @@ -166,7 +183,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle struct GNUNET_CLIENT_Connection *client; char *addrbuf; - GNUNET_assert (address != NULL); + GNUNET_assert (NULL != address); alen = address->address_length; slen = strlen (address->transport_name) + 1; len = sizeof (struct AddressLookupMessage) + alen + slen; @@ -178,8 +195,11 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle client = GNUNET_CLIENT_connect ("transport", cfg); if (NULL == client) return NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client %p tries to resolve for peer `%s'address len %u \n", - client, GNUNET_i2s (&address->peer), address->address_length); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Client %p tries to resolve for peer `%s'address len %u \n", + client, + GNUNET_i2s (&address->peer), + address->address_length); msg = GNUNET_malloc (len); msg->header.size = htons (len); @@ -188,17 +208,21 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle msg->addrlen = htons ((uint16_t) alen); msg->timeout = GNUNET_TIME_relative_hton (timeout); addrbuf = (char *) &msg[1]; - memcpy (addrbuf, address->address, alen); - memcpy (&addrbuf[alen], address->transport_name, slen); - + memcpy (addrbuf, + address->address, + alen); + memcpy (&addrbuf[alen], + address->transport_name, + slen); alc = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext); alc->cb = aluc; alc->cb_cls = aluc_cls; - alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); alc->client = client; GNUNET_assert (GNUNET_OK == - GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, - timeout, GNUNET_YES, + GNUNET_CLIENT_transmit_and_get_response (client, + &msg->header, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &address_response_processor, alc)); GNUNET_free (msg); @@ -212,9 +236,7 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle * @param pic the context handle */ void -GNUNET_TRANSPORT_address_to_string_cancel (struct - GNUNET_TRANSPORT_AddressToStringContext - *pic) +GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic) { GNUNET_CLIENT_disconnect (pic->client); GNUNET_free (pic); -- cgit v1.2.3